Exemple #1
0
 /**
  * Add the Edit Author Slug rewrite tags
  *
  * @since 1.0.0
  *
  * @return void
  */
 public function add_rewrite_tags()
 {
     // Should we be here?
     if (!ba_eas_do_role_based_author_base()) {
         return;
     }
     // Get the role slugs to add the rewrite tag.
     $role_slugs = wp_list_pluck($this->role_slugs, 'slug');
     $role_slugs = array_filter(array_values($role_slugs));
     // Add the author base as a fallback.
     $role_slugs[] = ba_eas()->author_base;
     // Add the role-based rewrite tag, and the expected role slugs.
     add_rewrite_tag('%ba_eas_author_role%', '(' . implode('|', array_unique($role_slugs)) . ')');
 }
/**
 * Upgrade Edit Author Slug.
 *
 * Just cleans up some options for now.
 *
 * @since 0.8.0
 *
 * @global object WPDB object.
 * @uses WPDB::update() To rename the old Edit Author Slug options array.
 * @uses ba_eas() BA_Edit_Author_Slug object.
 * @uses add_option() To add new Edit Author Slug options.
 * @uses update_option() To update Edit Author Slug options.
 * @uses ba_eas_flush_rewrite_rules() To flush rewrite rules after version bump.
 */
function ba_eas_upgrade()
{
    // Edit Author Slug instance
    $ba_eas = ba_eas();
    // We're up-to-date, so let's move on
    if ($ba_eas->current_db_version === $ba_eas->db_version) {
        return;
    }
    // 1.0.0
    if ($ba_eas->current_db_version < 133) {
        add_option('_ba_eas_do_auto_update', $ba_eas->do_auto_update);
        add_option('_ba_eas_default_user_nicename', $ba_eas->default_user_nicename);
        add_option('_ba_eas_do_role_based', $ba_eas->do_role_based);
        add_option('_ba_eas_role_slugs', $ba_eas->role_slugs);
    }
    // 0.8.0
    if ($ba_eas->current_db_version < 132) {
        // Add new options
        add_option('_ba_eas_author_base', $ba_eas->author_base);
        // Rename the old option for safe keeping
        global $wpdb;
        $wpdb->update($wpdb->options, array('option_name' => '_ba_eas_old_options'), array('option_name' => 'ba_edit_author_slug'));
    }
    // Version bump
    update_option('_ba_eas_db_version', $ba_eas->db_version);
    // Courtesy flush
    ba_eas_flush_rewrite_rules();
}
/**
 * Allow author templates to be based on role.
 *
 * Instead of only using author-{user_nicename}.php, author-{ID}.php, and author.php
 * for templates, this allows author-{role}.php or author-{role-slug}.php to be used as well.
 *
 * @since 1.0.0
 *
 * @param string $template Current template according to template hierarchy
 *
 * @uses get_queried_object() To get the queried object (should be WP_User object).
 * @uses ba_eas() BA_Edit_Author_Slug object
 * @uses locate_template() To see if we have role-based templates.
 *
 * @return string Author archive link
 */
function ba_eas_template_include($template)
{
    // Bail if we're not doing role-based author bases
    if (!ba_eas_do_role_based_author_base()) {
        return $template;
    }
    // Get queried object, should be a WP_User object
    $author = get_queried_object();
    // Make sure we have a WP_User object
    if (!is_a($author, 'WP_User')) {
        return $template;
    }
    // nicename and ID templates should take priority, so we need to check for their existence
    $nicename_template = strpos($template, "author-{$author->user_nicename}.php");
    $id_template = strpos($template, "author-{$author->ID}.php");
    // If they don't exist, search for a role based template
    if (false === $nicename_template && false === $id_template) {
        // Grab the first listed role
        if (!empty($author->roles) && is_array($author->roles)) {
            $role = array_shift($author->roles);
        }
        // Get the role slug
        $role_slug = ba_eas()->role_slugs[$role]['slug'];
        // Set the templates array
        $templates = array(empty($role) ? false : "author-{$role}.php", empty($role_slug) ? false : "author-{$role_slug}.php");
        // Check for the template
        $new_template = locate_template($templates);
        // If we have a role-based template, let's set it to be loaded
        if ('' != $new_template) {
            $template = $new_template;
        }
    }
    return $template;
}
Exemple #4
0
/**
 * Upgrade Edit Author Slug.
 *
 * Just cleans up some options for now.
 *
 * @since 0.8.0
 */
function ba_eas_upgrade()
{
    // Edit Author Slug instance.
    $ba_eas = ba_eas();
    // We're up-to-date, so let's move on.
    if ($ba_eas->current_db_version === $ba_eas->db_version) {
        return;
    }
    // < 0.8.0.
    if ($ba_eas->current_db_version < 132) {
        // Add new options.
        add_option('_ba_eas_author_base', $ba_eas->author_base);
        // Rename the old option for safe keeping.
        update_option('_ba_eas_old_options', get_option('ba_edit_author_slug'));
        delete_option('ba_edit_author_slug');
    }
    // < 1.0.0.
    if ($ba_eas->current_db_version < 133) {
        add_option('_ba_eas_do_auto_update', (int) $ba_eas->do_auto_update);
        add_option('_ba_eas_default_user_nicename', $ba_eas->default_user_nicename);
        add_option('_ba_eas_do_role_based', (int) $ba_eas->do_role_based);
        add_option('_ba_eas_role_slugs', $ba_eas->role_slugs);
    }
    // < 1.2.0.
    if ($ba_eas->current_db_version < 411) {
        add_option('_ba_eas_remove_front', (int) $ba_eas->remove_front);
    }
    // Version bump.
    update_option('_ba_eas_db_version', $ba_eas->db_version);
    // Courtesy flush.
    ba_eas_flush_rewrite_rules();
}