Created
June 2, 2014 05:25
-
-
Save imvision/5c01b61b459d60b29d75 to your computer and use it in GitHub Desktop.
Wordpress plug-in test pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpcw_gg_RunTests() { | |
global $wpdb; | |
echo "<h3>Running Tests...</h3>"; | |
$course_id = wpcw_gg_getFirstCourseId(); | |
gg_OK($course_id, "First Course Id: {$course_id}"); | |
$unit_url = wpcw_gg_getFirstUnitLink($course_id); | |
gg_OK($unit_url!="", "Unit url is {$unit_url}"); | |
} | |
function wpcw_gg_getFirstCourseId() { | |
global $wpdb; | |
$tbl = $wpdb->prefix . 'wpcw_courses'; | |
return $wpdb->get_var("SELECT course_id FROM $tbl ORDER BY course_id ASC LIMIT 0,1"); | |
} | |
function gg_OK($result, $msg) { | |
if($result) { | |
echo "<br>{$msg}<br>"; | |
} else { | |
echo "Test Failed -> {$msg}"; | |
} | |
} | |
function gg_NO($result, $msg) { | |
if( !$result ) { | |
echo "<br>{$msg}<br>"; | |
} else { | |
echo "<br>Test Failed -> {$msg}<br>"; | |
} | |
} | |
//// | |
add_action("admin_menu", "wpcw_groups_grading_menu"); | |
function wpcw_groups_grading_menu() { | |
add_menu_page('Groups Grading', 'Groups Grading', 'publish_posts', 'wpcw-groups-grading-2', 'wpcw_groups_grading_manage', WP_PLUGIN_URL . '/wpcw-groups-grading-2/icon.png'); | |
add_submenu_page('wpcw-groups-grading-2', "Plugin Tests", "Plugin Tests", "manage_options", "wpcw_gg_RunTests", "wpcw_gg_RunTests"); | |
} | |
// Hide Plugin tests item from menu | |
add_action( 'admin_head', 'wpcw_gg_AdjustMenu', 999 ); | |
function wpcw_gg_AdjustMenu() { | |
$status = remove_submenu_page('wpcw-groups-grading-2', 'wpcw_gg_RunTests'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment