示例#1
0
/**
 * Replaces author role rewrite tag with the role of the user.
 *
 * If the user has more than one role, the first role listed in the WP_User::$roles
 * array will be used.
 *
 * @since 1.0.0
 *
 * @param string $link    The author link with user role as author base.
 * @param int    $user_id The user id.
 *
 * @return string Author archive link.
 */
function ba_eas_author_link($link = '', $user_id = 0)
{
    // Add a role slug if we're doing role based author bases.
    if (ba_eas_do_role_based_author_base() && false !== strpos($link, '%ba_eas_author_role%')) {
        // Setup the user.
        $user = get_userdata($user_id);
        // Grab the first listed role.
        $role = ba_eas_get_user_role($user->roles, $user_id);
        // Make sure we have a valid slug.
        $slug = empty(ba_eas()->role_slugs[$role]['slug']) ? ba_eas()->author_base : ba_eas()->role_slugs[$role]['slug'];
        // Add the role slug to the link.
        $link = str_replace('%ba_eas_author_role%', $slug, $link);
    }
    // Remove front if applicable.
    if (ba_eas_has_front() && ba_eas_remove_front()) {
        $link = str_replace($GLOBALS['wp_rewrite']->front, '/', $link);
    }
    // Return the link.
    return $link;
}
示例#2
0
文件: admin.php 项目: ashenkar/sanga
/**
 * Add Author Base settings settings page.
 *
 * @since 0.9.0
 */
function ba_eas_register_admin_settings()
{
    // Add the Author Base section.
    add_settings_section('ba_eas_author_base', __('Author Base', 'edit-author-slug'), 'ba_eas_admin_setting_callback_author_base_section', 'edit-author-slug');
    // Author Base setting.
    add_settings_field('_ba_eas_author_base', __('Author Base', 'edit-author-slug'), 'ba_eas_admin_setting_callback_author_base', 'edit-author-slug', 'ba_eas_author_base', array('label_for' => '_ba_eas_author_base'));
    register_setting('edit-author-slug', '_ba_eas_author_base', 'ba_eas_sanitize_author_base');
    // Remove front setting.
    if (ba_eas_has_front()) {
        add_settings_field('_ba_eas_remove_front', __('Remove Front', 'edit-author-slug'), 'ba_eas_admin_setting_callback_remove_front', 'edit-author-slug', 'ba_eas_author_base', array('label_for' => '_ba_eas_remove_front'));
        register_setting('edit-author-slug', '_ba_eas_remove_front', 'intval');
    }
    // Role-Based Author Base setting.
    add_settings_field('_ba_eas_do_role_based', __('Role-Based Author Base', 'edit-author-slug'), 'ba_eas_admin_setting_callback_do_role_based', 'edit-author-slug', 'ba_eas_author_base', array('label_for' => '_ba_eas_do_role_based'));
    register_setting('edit-author-slug', '_ba_eas_do_role_based', 'intval');
    // Role-Based Author Base slugs.
    add_settings_field('_ba_eas_role_slugs', __('Role Slugs', 'edit-author-slug'), 'ba_eas_admin_setting_callback_role_slugs', 'edit-author-slug', 'ba_eas_author_base');
    register_setting('edit-author-slug', '_ba_eas_role_slugs', 'ba_eas_admin_setting_sanitize_callback_role_slugs');
    // Add the default user nicename section.
    add_settings_section('ba_eas_auto_update', __('Automatic Author Slug Creation', 'edit-author-slug'), 'ba_eas_admin_setting_callback_auto_update_section', 'edit-author-slug');
    // Auto-update on/off.
    add_settings_field('_ba_eas_do_auto_update', __('Automatically Update', 'edit-author-slug'), 'ba_eas_admin_setting_callback_do_auto_update', 'edit-author-slug', 'ba_eas_auto_update', array('label_for' => '_ba_eas_do_auto_update'));
    register_setting('edit-author-slug', '_ba_eas_do_auto_update', 'intval');
    // Default user nicename setting.
    add_settings_field('_ba_eas_default_user_nicename', __('Author Slug Structure', 'edit-author-slug'), 'ba_eas_admin_setting_callback_default_user_nicename', 'edit-author-slug', 'ba_eas_auto_update', array('label_for' => '_ba_eas_default_user_nicename'));
    register_setting('edit-author-slug', '_ba_eas_default_user_nicename', 'sanitize_key');
    // Add the Bulk Update section.
    add_settings_section('ba_eas_bulk_update', __('Bulk Update Author Slugs', 'edit-author-slug'), 'ba_eas_admin_setting_callback_bulk_update_section', 'edit-author-slug');
    // Bulk update.
    add_settings_field('_ba_eas_bulk_update', __('Bulk Update', 'edit-author-slug'), 'ba_eas_admin_setting_callback_bulk_update', 'edit-author-slug', 'ba_eas_bulk_update', array('label_for' => '_ba_eas_bulk_update'));
    register_setting('edit-author-slug', '_ba_eas_bulk_update', 'ba_eas_auto_update_user_nicename_bulk');
    // Bulk update.
    add_settings_field('_ba_eas_bulk_update_structure', __('Author Slug Structure', 'edit-author-slug'), 'ba_eas_admin_setting_callback_bulk_update_structure', 'edit-author-slug', 'ba_eas_bulk_update', array('label_for' => '_ba_eas_bulk_update_structure'));
    register_setting('edit-author-slug', '_ba_eas_bulk_update_structure', '__return_false');
}