Esempio n. 1
0
 /**
  * Set up the admin hooks, actions and filters
  *
  * @since Achievements (3.0)
  */
 private function setup_actions()
 {
     // Bail to prevent interfering with the deactivation process
     if (dpa_is_deactivation()) {
         return;
     }
     // If the plugin's been activated network-wide, only load the admin stuff on the DPA_DATA_STORE site
     if (is_multisite() && dpa_is_running_networkwide() && get_current_blog_id() !== DPA_DATA_STORE) {
         return;
     }
     // General Actions
     add_action('dpa_admin_menu', array($this, 'admin_menus'));
     add_action('admin_bar_menu', array(__CLASS__, 'admin_bar_about_link'), 15);
     add_filter('manage_achievement_posts_columns', 'dpa_achievement_posts_columns');
     add_action('manage_posts_custom_column', 'dpa_achievement_custom_column', 10, 2);
     add_filter('manage_edit-achievement_sortable_columns', 'dpa_achievement_sortable_columns');
     add_action('save_post', 'dpa_achievement_metabox_save');
     add_action('load-edit.php', 'dpa_achievement_index_contextual_help');
     add_action('load-post-new.php', 'dpa_achievement_new_contextual_help');
     add_action('load-post.php', 'dpa_achievement_new_contextual_help');
     add_action('load-settings_page_achievements', 'dpa_admin_settings_contextual_help');
     add_filter('post_updated_messages', 'dpa_achievement_feedback_messages');
     add_action('dpa_register_admin_settings', array(__CLASS__, 'register_admin_settings'));
     add_filter('dpa_map_meta_caps', array(__CLASS__, 'map_settings_meta_caps'), 10, 4);
     add_filter('plugin_action_links', array(__CLASS__, 'modify_plugin_action_links'), 10, 2);
     add_filter('network_admin_plugin_action_links', array(__CLASS__, 'modify_plugin_action_links'), 10, 2);
     // Allow plugins to modify these actions
     do_action_ref_array('dpa_admin_loaded', array(&$this));
 }
Esempio n. 2
0
/**
 * Attempt to load a custom Achievements functions file, similar to a theme's functions.php file.
 *
 * @global string $pagenow
 * @since Achievements (3.0)
 */
function dpa_load_theme_functions()
{
    global $pagenow;
    // If Achievements is being deactivated, do not load any more files
    if (dpa_is_deactivation()) {
        return;
    }
    if (!defined('WP_INSTALLING') || !empty($pagenow) && 'wp-activate.php' !== $pagenow) {
        dpa_locate_template('achievements-functions.php', true);
        if (class_exists('DPA_Default')) {
            achievements()->theme_functions = new DPA_Default();
        }
    }
}
Esempio n. 3
0
/**
 * Achievement actions are stored in a custom taxonomy. This function queries that taxonomy to find
 * items and, with those items' slugs (which are the name of a WordPress action), registers them to a
 * handler action that contains the next part of the main logic. The user needs to be logged in for
 * this to hapen.
 *
 * Posts in trash are returned by get_terms() even if hide_empty is set. We double-check the post status
 * before we actually give the award.
 *
 * This function is invoked on every page load but as get_terms() provides built-in caching, we don't
 * have to worry too much. For multisite with the network-wide option enabled, we store the events
 * in a global cache object to avoid a call to switch_to_blog.
 *
 * @since Achievements (3.0)
 */
function dpa_register_events()
{
    // If Achievements is being deactivated, bail out
    if (dpa_is_deactivation(achievements()->basename)) {
        return;
    }
    // Only do things if the user is active (logged in and not a spammer) and is not doing an import.
    if (defined('WP_IMPORTING') && WP_IMPORTING || !apply_filters('dpa_maybe_register_events', dpa_is_user_active())) {
        return;
    }
    $events = false;
    // If multisite and running network-wide, see if the terms have previously been cached.
    if (is_multisite() && dpa_is_running_networkwide()) {
        $events = wp_cache_get('dpa_registered_events', 'achievements_events');
    }
    // No cache. Get events.
    if ($events === false) {
        // If multisite and running network-wide, switch_to_blog to the data store site
        if (is_multisite() && dpa_is_running_networkwide()) {
            switch_to_blog(DPA_DATA_STORE);
        }
        // Get all valid events from the event taxononmy. A valid event is one associated with a post type.
        $events = get_terms(achievements()->event_tax_id, array('hide_empty' => true));
        // No items were found. Bail out.
        if (is_wp_error($events) || empty($events)) {
            // If multisite and running network-wide, undo the switch_to_blog
            if (is_multisite() && dpa_is_running_networkwide()) {
                restore_current_blog();
            }
            return;
            // Items were found! If network-wide, cache the results and undo the switch_to_blog.
        } elseif (is_multisite() && dpa_is_running_networkwide()) {
            restore_current_blog();
            wp_cache_add('dpa_registered_events', $events, 'achievements_events');
        }
    }
    // Get terms' slugs
    $events = wp_list_pluck((array) $events, 'slug');
    $events = array_unique((array) apply_filters('dpa_filter_events', $events));
    // For each event, add a handler function to the action.
    foreach ((array) $events as $event) {
        add_action($event, 'dpa_handle_event', 12, 10);
    }
    // Priority 12 in case object modified by other plugins
    // Allow other plugins to register extra events
    do_action('dpa_register_events', $events);
}
Esempio n. 4
0
 /**
  * Set up the default hooks and actions
  *
  * @since Achievements (3.0)
  */
 private function setup_actions()
 {
     // Plugin activation and deactivation hooks
     add_action('activate_' . $this->basename, 'dpa_activation');
     add_action('deactivate_' . $this->basename, 'dpa_deactivation');
     // If Achievements is being deactivated, don't add any more actions
     if (dpa_is_deactivation($this->basename)) {
         return;
     }
     // Add the core actions
     $actions = array('setup_theme', 'register_post_types', 'register_post_statuses', 'register_taxonomies', 'register_shortcodes', 'register_theme_packages', 'load_textdomain', 'constants', 'register_endpoints', 'admin_bar_menu', 'register_image_sizes');
     foreach ($actions as $class_action) {
         add_action('dpa_' . $class_action, array($this, $class_action), 5);
     }
     // All Achievements actions are setup (includes core/actions.php)
     do_action_ref_array('dpa_after_setup_actions', array(&$this));
 }
Esempio n. 5
0
 /**
  * Set up the default hooks and actions
  *
  * @since 3.0
  */
 private function setup_actions()
 {
     // Plugin activation and deactivation hooks
     add_action('activate_' . $this->basename, 'dpa_activation');
     add_action('deactivate_' . $this->basename, 'dpa_deactivation');
     // If Achievements is being deactivated, don't add any more actions
     if (dpa_is_deactivation($this->basename)) {
         return;
     }
     // Add the core actions
     $actions = array('load_textdomain', 'register_post_types', 'register_taxonomies', 'setup_current_user');
     foreach ($actions as $class_action) {
         add_action('dpa_' . $class_action, array($this, $class_action), 5);
     }
 }