Beispiel #1
0
/**
 * Initialisation functions for plugin.
 */
function WPCW_plugin_init()
{
    // Load translation support
    $domain = 'wp_courseware';
    // This is the translation locale.
    // Check the WordPress language directory for /wp-content/languages/wp_courseware/wp_courseware-en_US.mo first
    $locale = apply_filters('plugin_locale', get_locale(), $domain);
    load_textdomain($domain, WP_LANG_DIR . '/wp_courseware/' . $domain . '-' . $locale . '.mo');
    // Then load the plugin version
    load_plugin_textdomain($domain, FALSE, dirname(plugin_basename(__FILE__)) . '/language/');
    // Run setup
    WPCW_plugin_setup(false);
    // ### Admin
    if (is_admin()) {
        // Menus
        add_action('admin_menu', 'WPCW_menu_MainMenu');
        add_action('admin_head', 'WPCW_menu_MainMenu_cleanUnwantedEntries');
        // Network Only
        //add_action('network_admin_menu', 						'WPCW_menu_MainMenu_NetworkOnly');
        // Scripts and styles
        add_action('admin_print_scripts', 'WPCW_addCustomScripts_BackEnd');
        add_action('admin_print_styles', 'WPCW_addCustomCSS_BackEnd');
        // See if export has been requested
        WPCW_Export::tryExportCourse();
        // Post Related
        add_action('save_post', 'WPCW_units_saveUnitPostMetaData', 10, 2);
        // User Related
        add_action('manage_users_columns', 'WPCW_users_manageColumns');
        add_action('manage_users_custom_column', 'WPCW_users_addCustomColumnContent', 10, 3);
        // Unit Related
        add_filter('manage_course_unit_posts_columns', 'WPCW_units_manageColumns', 10);
        add_action('manage_course_unit_posts_custom_column', 'WPCW_units_addCustomColumnContent', 10, 2);
        // Unit Deletion
        add_filter('delete_post', 'WPCW_units_deleteUnitHandler');
        // Meta boxes
        add_action('add_meta_boxes', 'WPCW_units_showEditScreenMetaBoxes');
        // AJAX - Admin
        add_action('wp_ajax_wpcw_handle_unit_ordering_saving', 'WPCW_AJAX_handleUnitOrderingSaving');
        add_action('wp_ajax_wpcw_handle_unit_duplication', 'WPCW_AJAX_handleUnitDuplication');
        add_action('wp_ajax_wpcw_handle_question_new_tag', 'WPCW_AJAX_handleQuestionNewTag');
        add_action('wp_ajax_wpcw_handle_question_remove_tag', 'WPCW_AJAX_handleQuestionRemoveTag');
        add_action('wp_ajax_wpcw_handle_tb_action_question_pool', 'WPCW_AJAX_handleThickboxAction_QuestionPool');
        add_action('wp_ajax_wpcw_handle_tb_action_add_question', 'WPCW_AJAX_handleThickboxAction_QuestionPool_addQuestion');
        // AJAX - Frontend (yeah, WP requires they go here)
        add_action('wp_ajax_wpcw_handle_unit_track_progress', 'WPCW_AJAX_units_handleUserProgress');
        add_action('wp_ajax_wpcw_handle_unit_quiz_response', 'WPCW_AJAX_units_handleQuizResponse');
        add_action('wp_ajax_wpcw_handle_unit_quiz_retake_request', 'WPCW_AJAX_units_handleQuizRetakeRequest');
        add_action('wp_ajax_wpcw_handle_unit_quiz_jump_question', 'WPCW_AJAX_units_handleQuizJumpQuestion');
        add_action('wp_ajax_wpcw_handle_unit_quiz_timer_begin', 'WPCW_AJAX_units_handleQuizTimerBegin');
        // Notices about permalinks
        add_action('admin_notices', 'WPCW_plugin_permalinkCheck');
        // Notice about MS - Now disabled.
        //add_action('admin_notices', 							'WPCW_plugin_multisiteCheck');
        // CSV Export
        add_action('wp_loaded', 'WPCW_data_handleDataExport');
        // User - Global reset functionality
        add_action('load-users.php', 'WPCW_users_processUserResetAbility');
        add_action('admin_head', 'WPCW_users_processUserResetAbility_showSuccess');
        add_action('restrict_manage_users', 'WPCW_users_showUserResetAbility');
    } else {
        // Scripts and styles
        WPCW_addCustomScripts_FrontEnd();
        // Shortcodes
        add_shortcode('wpcourse', 'WPCW_shortcodes_showTrainingCourse');
        add_shortcode('wpcourse_progress', 'WPCW_shortcodes_showTrainingCourseProgress');
        // Post Content
        add_filter('the_content', 'WPCW_units_processUnitContent');
        // Templates - Course Units
        add_filter('single_template', 'WPCW_templates_units_filterTemplateForUnit');
    }
    // Action when admin has updated the course details.
    add_action('wpcw_course_details_updated', 'WPCW_actions_courses_courseDetailsUpdated');
    // Action when user has completed a unit/module/course
    add_action('wpcw_user_completed_unit', 'WPCW_actions_users_unitCompleted', 10, 3);
    add_action('wpcw_user_completed_module', 'WPCW_actions_users_moduleCompleted', 10, 3);
    add_action('wpcw_user_completed_course', 'WPCW_actions_users_courseCompleted', 10, 3);
    // Modified modules - when a module is created or edited
    add_action('wpcw_modules_modified', 'WPCW_actions_modules_modulesModified');
    // Action called when user has been created, and we check to see if that user should be added to
    // any of the defined courses.
    add_action('user_register', 'WPCW_actions_users_newUserCreated');
    // Action called when user has been deleted
    add_action('delete_user', 'WPCW_actions_users_userDeleted');
    // Action called when quiz has been completed and needs grading or needs attention as user is blocked.
    add_action('wpcw_quiz_needs_grading', 'WPCW_actions_userQuizNeedsGrading_notifyAdmin', 10, 2);
    add_action('wpcw_quiz_user_needs_unblocking', 'WPCW_actions_userQuizUserNeedsUnblocking_notifyAdmin', 10, 2);
    // Action called when quiz has been graded or needs attention
    add_action('wpcw_quiz_graded', 'WPCW_actions_userQuizGraded_notifyUser', 10, 4);
    // Common
    WPCW_plugin_registerCustomPostTypes();
    // Create correct URL for unit
    add_filter('post_type_link', 'WPCW_units_createCorrectUnitURL', 1, 3);
    // Create permalink for course units
    global $wp_rewrite;
    $unit_structure = '/%module_number%/%course_unit%/';
    // Handle module and course unit tags
    $wp_rewrite->add_rewrite_tag("%module_number%", '(module-[^/]+)', "module_number=");
    $wp_rewrite->add_rewrite_tag("%course_unit%", '([^/]+)', "course_unit=");
    // Make it happen to format links automatically for course units.
    $wp_rewrite->add_permastruct('course_unit', $unit_structure, false);
    // Ensure the URLs are flushed for the first time
    $flushRules = get_option('wpcw_flush_rules');
    if (!$flushRules) {
        update_option('wpcw_flush_rules', 'done');
        $wp_rewrite->flush_rules();
    }
    // Now load any extensions
    do_action('wpcw_extensions_load');
}
Beispiel #2
0
/**
 * Initialisation functions for plugin.
 */
function WPCW_plugin_init()
{
    // Load translation support
    $plugin_dir = basename(dirname(__FILE__)) . '/language/';
    load_plugin_textdomain('wp_courseware', false, $plugin_dir);
    // Run setup
    WPCW_plugin_setup(false);
    // Change preferences for updater
    if (WPCW_plugin_hasAdminRights()) {
        global $updater_wpcw;
        $updater_wpcw->setAccessKey(TidySettings_getSettingSingle(WPCW_DATABASE_SETTINGS_KEY, 'licence_key'));
        //$updater_wpcw->plugin_msg_blocked = false; // No message if blocked licence.
        $updater_wpcw->plugin_msg_expired = __('Your licence key has expired. Please visit <a href="http://www.flyplugins.com" target="_blank">FlyPlugins.com</a> to renew your licence.', 'wp_courseware');
        $updater_wpcw->plugin_msg_invalid = __('Please enter a valid licence key or visit <a href="http://www.flyplugins.com" target="_blank">FlyPlugins.com</a> to purchase a licence.', 'wp_courseware');
        $updater_wpcw->plugin_msg_limit_reached = __('You\'ve reached the maximum number of websites for this licence. Please visit <a href="http://www.flyplugins.com" target="_blank">FlyPlugins.com</a> to upgrade your licence.', 'wp_courseware');
    }
    // ### Admin
    if (is_admin()) {
        // Menus
        add_action('admin_menu', 'WPCW_menu_MainMenu');
        add_action('admin_head', 'WPCW_menu_MainMenu_cleanUnwantedEntries');
        // Network Only
        //add_action('network_admin_menu', 						'WPCW_menu_MainMenu_NetworkOnly');
        // Scripts and styles
        add_action('admin_print_scripts', 'WPCW_addCustomScripts_BackEnd');
        add_action('admin_print_styles', 'WPCW_addCustomCSS_BackEnd');
        // See if export has been requested
        WPCW_Export::tryExportCourse();
        // Post Related
        add_action('save_post', 'WPCW_units_saveUnitPostMetaData', 10, 2);
        // User Related
        add_action('manage_users_columns', 'WPCW_users_manageColumns');
        add_action('manage_users_custom_column', 'WPCW_users_addCustomColumnContent', 10, 3);
        // Unit Related
        add_filter('manage_course_unit_posts_columns', 'WPCW_units_manageColumns', 10);
        add_action('manage_course_unit_posts_custom_column', 'WPCW_units_addCustomColumnContent', 10, 2);
        // Unit Deletion
        add_filter('delete_post', 'WPCW_units_deleteUnitHandler');
        // Meta boxes
        add_action('add_meta_boxes', 'WPCW_units_showConversionMetaBox');
        // AJAX - Admin
        add_action('wp_ajax_wpcw_handle_unit_ordering_saving', 'WPCW_AJAX_handleUnitOrderingSaving');
        // AJAX - Frontend (yeah, WP requires they go here)
        add_action('wp_ajax_wpcw_handle_unit_track_progress', 'WPCW_AJAX_units_handleUserProgress');
        add_action('wp_ajax_wpcw_handle_unit_quiz_response', 'WPCW_AJAX_units_handleQuizResponse');
        // Notices about permalinks
        add_action('admin_notices', 'WPCW_plugin_permalinkCheck');
        add_action('admin_notices', 'WPCW_plugin_multisiteCheck');
        // CSV Export
        add_action('wp_loaded', 'WPCW_data_handleDataExport');
    } else {
        // Scripts and styles
        WPCW_addCustomScripts_FrontEnd();
        // Shortcodes
        add_shortcode('wpcourse', 'WPCW_shortcodes_showTrainingCourse');
        // Post Content
        add_filter('the_content', 'WPCW_units_processUnitContent');
    }
    // Action when admin has updated the course details.
    add_action('wpcw_course_details_updated', 'WPCW_actions_courses_courseDetailsUpdated');
    // Action when user has completed a unit/module/course
    add_action('wpcw_user_completed_unit', 'WPCW_actions_users_unitCompleted', 10, 3);
    add_action('wpcw_user_completed_module', 'WPCW_actions_users_moduleCompleted', 10, 3);
    add_action('wpcw_user_completed_course', 'WPCW_actions_users_courseCompleted', 10, 3);
    // Modified modules - when a module is created or edited
    add_action('wpcw_modules_modified', 'WPCW_actions_modules_modulesModified');
    // Action called when user has been created, and we check to see if that user should be added to
    // any of the defined courses.
    add_action('user_register', 'WPCW_actions_users_newUserCreated');
    // Action called when user has been deleted
    add_action('delete_user', 'WPCW_actions_users_userDeleted');
    // Action called when quiz has been completed and needs grading.
    add_action('wpcw_quiz_needs_grading', 'WPCW_actions_userQuizNeedsGrading_notifyAdmin', 10, 2);
    // Action called when quiz has been graded.
    add_action('wpcw_quiz_graded', 'WPCW_actions_userQuizGraded_notifyUser', 10, 4);
    // Common
    WPCW_plugin_registerCustomPostTypes();
    // Create correct URL for unit
    add_filter('post_type_link', 'WPCW_units_createCorrectUnitURL', 1, 3);
    // Create permalink for course units
    global $wp_rewrite;
    $unit_structure = '/%module_number%/%course_unit%/';
    // Handle module and course unit tags
    $wp_rewrite->add_rewrite_tag("%module_number%", '(module-[^/]+)', "module_number=");
    $wp_rewrite->add_rewrite_tag("%course_unit%", '([^/]+)', "course_unit=");
    // Make it happen to format links automatically for course units.
    $wp_rewrite->add_permastruct('course_unit', $unit_structure, false);
    // Ensure the URLs are flushed for the first time
    $flushRules = get_option('wpcw_flush_rules');
    if (!$flushRules) {
        update_option('wpcw_flush_rules', 'done');
        $wp_rewrite->flush_rules();
    }
    // Now load any extensions
    //do_action('wpcw_extensions_load');
}