コード例 #1
1
ファイル: post.php プロジェクト: SayenkoDesign/ividf
/**
 * Register a post type. Do not use before init.
 *
 * A function for creating or modifying a post type based on the
 * parameters given. The function will accept an array (second optional
 * parameter), along with a string for the post type name.
 *
 * @since 2.9.0
 * @since 3.0.0 The `show_ui` argument is now enforced on the new post screen.
 * @since 4.4.0 The `show_ui` argument is now enforced on the post type listing screen and post editing screen.
 *
 * @global array      $wp_post_types List of post types.
 * @global WP_Rewrite $wp_rewrite    Used for default feeds.
 * @global WP         $wp            Used to add query vars.
 *
 * @param string $post_type Post type key, must not exceed 20 characters.
 * @param array|string $args {
 *     Array or string of arguments for registering a post type.
 *
 *     @type string      $label                Name of the post type shown in the menu. Usually plural.
 *                                             Default is value of $labels['name'].
 *     @type array       $labels               An array of labels for this post type. If not set, post
 *                                             labels are inherited for non-hierarchical types and page
 *                                             labels for hierarchical ones. {@see get_post_type_labels()}.
 *     @type string      $description          A short descriptive summary of what the post type is.
 *                                             Default empty.
 *     @type bool        $public               Whether a post type is intended for use publicly either via
 *                                             the admin interface or by front-end users. While the default
 *                                             settings of $exclude_from_search, $publicly_queryable, $show_ui,
 *                                             and $show_in_nav_menus are inherited from public, each does not
 *                                             rely on this relationship and controls a very specific intention.
 *                                             Default false.
 *     @type bool        $hierarchical         Whether the post type is hierarchical (e.g. page). Default false.
 *     @type bool        $exclude_from_search  Whether to exclude posts with this post type from front end search
 *                                             results. Default is the opposite value of $public.
 *     @type bool        $publicly_queryable   Whether queries can be performed on the front end for the post type
 *                                             as part of {@see parse_request()}. Endpoints would include:
 *                                             * ?post_type={post_type_key}
 *                                             * ?{post_type_key}={single_post_slug}
 *                                             * ?{post_type_query_var}={single_post_slug}
 *                                             If not set, the default is inherited from $public.
 *     @type bool        $show_ui              Whether to generate and allow a UI for managing this post type in the
 *                                             admin. Default is value of $public.
 *     @type bool        $show_in_menu         Where to show the post type in the admin menu. To work, $show_ui
 *                                             must be true. If true, the post type is shown in its own top level
 *                                             menu. If false, no menu is shown. If a string of an existing top
 *                                             level menu (eg. 'tools.php' or 'edit.php?post_type=page'), the post
 *                                             type will be placed as a sub-menu of that.
 *                                             Default is value of $show_ui.
 *     @type bool        $show_in_nav_menus    Makes this post type available for selection in navigation menus.
 *                                             Default is value $public.
 *     @type bool        $show_in_admin_bar    Makes this post type available via the admin bar. Default is value
 *                                             of $show_in_menu.
 *     @type int         $menu_position        The position in the menu order the post type should appear. To work,
 *                                             $show_in_menu must be true. Default null (at the bottom).
 *     @type string      $menu_icon            The url to the icon to be used for this menu. Pass a base64-encoded
 *                                             SVG using a data URI, which will be colored to match the color scheme
 *                                             -- this should begin with 'data:image/svg+xml;base64,'. Pass the name
 *                                             of a Dashicons helper class to use a font icon, e.g.
 *                                             'dashicons-chart-pie'. Pass 'none' to leave div.wp-menu-image empty
 *                                             so an icon can be added via CSS. Defaults to use the posts icon.
 *     @type string      $capability_type      The string to use to build the read, edit, and delete capabilities.
 *                                             May be passed as an array to allow for alternative plurals when using
 *                                             this argument as a base to construct the capabilities, e.g.
 *                                             array('story', 'stories'). Default 'post'.
 *     @type array       $capabilities         Array of capabilities for this post type. $capability_type is used
 *                                             as a base to construct capabilities by default.
 *                                             {@see get_post_type_capabilities()}.
 *     @type bool        $map_meta_cap         Whether to use the internal default meta capability handling.
 *                                             Default false.
 *     @type array       $supports             An alias for calling {@see add_post_type_support()} directly.
 *                                             Defaults to array containing 'title' & 'editor'.
 *     @type callable    $register_meta_box_cb Provide a callback function that sets up the meta boxes for the
 *                                             edit form. Do remove_meta_box() and add_meta_box() calls in the
 *                                             callback. Default null.
 *     @type array       $taxonomies           An array of taxonomy identifiers that will be registered for the
 *                                             post type. Taxonomies can be registered later with
 *                                             {@see register_taxonomy()} or {@see register_taxonomy_for_object_type()}.
 *                                             Default empty array.
 *     @type bool|string $has_archive          Whether there should be post type archives, or if a string, the
 *                                             archive slug to use. Will generate the proper rewrite rules if
 *                                             $rewrite is enabled. Default false.
 *     @type bool|array  $rewrite              {
 *         Triggers the handling of rewrites for this post type. To prevent rewrite, set to false.
 *         Defaults to true, using $post_type as slug. To specify rewrite rules, an array can be
 *         passed with any of these keys:
 *
 *         @type string $slug       Customize the permastruct slug. Defaults to $post_type key.
 *         @type bool   $with_front Whether the permastruct should be prepended with WP_Rewrite::$front.
 *                                  Default true.
 *         @type bool   $feeds      Whether the feed permastruct should be built for this post type.
 *                                  Default is value of $has_archive.
 *         @type bool   $pages      Whether the permastruct should provide for pagination. Default true.
 *         @type const  $ep_mask    Endpoint mask to assign. If not specified and permalink_epmask is set,
 *                                  inherits from $permalink_epmask. If not specified and permalink_epmask
 *                                  is not set, defaults to EP_PERMALINK.
 *     }
 *     @type string|bool $query_var            Sets the query_var key for this post type. Defaults to $post_type
 *                                             key. If false, a post type cannot be loaded at
 *                                             ?{query_var}={post_slug}. If specified as a string, the query
 *                                             ?{query_var_string}={post_slug} will be valid.
 *     @type bool        $can_export           Whether to allow this post type to be exported. Default true.
 *     @type bool        $delete_with_user     Whether to delete posts of this type when deleting a user. If true,
 *                                             posts of this type belonging to the user will be moved to trash
 *                                             when then user is deleted. If false, posts of this type belonging
 *                                             to the user will *not* be trashed or deleted. If not set (the default),
 *                                             posts are trashed if post_type_supports('author'). Otherwise posts
 *                                             are not trashed or deleted. Default null.
 *     @type bool        $_builtin             FOR INTERNAL USE ONLY! True if this post type is a native or
 *                                             "built-in" post_type. Default false.
 *     @type string      $_edit_link           FOR INTERNAL USE ONLY! URL segment to use for edit link of
 *                                             this post type. Default 'post.php?post=%d'.
 * }
 * @return object|WP_Error The registered post type object, or an error object.
 */
function register_post_type($post_type, $args = array())
{
    global $wp_post_types, $wp_rewrite, $wp;
    if (!is_array($wp_post_types)) {
        $wp_post_types = array();
    }
    // Sanitize post type name
    $post_type = sanitize_key($post_type);
    $args = wp_parse_args($args);
    /**
     * Filter the arguments for registering a post type.
     *
     * @since 4.4.0
     *
     * @param array  $args      Array of arguments for registering a post type.
     * @param string $post_type Post type key.
     */
    $args = apply_filters('register_post_type_args', $args, $post_type);
    $has_edit_link = !empty($args['_edit_link']);
    // Args prefixed with an underscore are reserved for internal use.
    $defaults = array('labels' => array(), 'description' => '', 'public' => false, 'hierarchical' => false, 'exclude_from_search' => null, 'publicly_queryable' => null, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_in_admin_bar' => null, 'menu_position' => null, 'menu_icon' => null, 'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'has_archive' => false, 'rewrite' => true, 'query_var' => true, 'can_export' => true, 'delete_with_user' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d');
    $args = array_merge($defaults, $args);
    $args = (object) $args;
    $args->name = $post_type;
    if (empty($post_type) || strlen($post_type) > 20) {
        _doing_it_wrong(__FUNCTION__, __('Post type names must be between 1 and 20 characters in length.'), '4.2');
        return new WP_Error('post_type_length_invalid', __('Post type names must be between 1 and 20 characters in length.'));
    }
    // If not set, default to the setting for public.
    if (null === $args->publicly_queryable) {
        $args->publicly_queryable = $args->public;
    }
    // If not set, default to the setting for public.
    if (null === $args->show_ui) {
        $args->show_ui = $args->public;
    }
    // If not set, default to the setting for show_ui.
    if (null === $args->show_in_menu || !$args->show_ui) {
        $args->show_in_menu = $args->show_ui;
    }
    // If not set, default to the whether the full UI is shown.
    if (null === $args->show_in_admin_bar) {
        $args->show_in_admin_bar = (bool) $args->show_in_menu;
    }
    // If not set, default to the setting for public.
    if (null === $args->show_in_nav_menus) {
        $args->show_in_nav_menus = $args->public;
    }
    // If not set, default to true if not public, false if public.
    if (null === $args->exclude_from_search) {
        $args->exclude_from_search = !$args->public;
    }
    // Back compat with quirky handling in version 3.0. #14122.
    if (empty($args->capabilities) && null === $args->map_meta_cap && in_array($args->capability_type, array('post', 'page'))) {
        $args->map_meta_cap = true;
    }
    // If not set, default to false.
    if (null === $args->map_meta_cap) {
        $args->map_meta_cap = false;
    }
    // If there's no specified edit link and no UI, remove the edit link.
    if (!$args->show_ui && !$has_edit_link) {
        $args->_edit_link = '';
    }
    $args->cap = get_post_type_capabilities($args);
    unset($args->capabilities);
    if (is_array($args->capability_type)) {
        $args->capability_type = $args->capability_type[0];
    }
    if (!empty($args->supports)) {
        add_post_type_support($post_type, $args->supports);
        unset($args->supports);
    } elseif (false !== $args->supports) {
        // Add default features
        add_post_type_support($post_type, array('title', 'editor'));
    }
    if (false !== $args->query_var) {
        if (true === $args->query_var) {
            $args->query_var = $post_type;
        } else {
            $args->query_var = sanitize_title_with_dashes($args->query_var);
        }
        if ($wp && is_post_type_viewable($args)) {
            $wp->add_query_var($args->query_var);
        }
    }
    if (false !== $args->rewrite && (is_admin() || '' != get_option('permalink_structure'))) {
        if (!is_array($args->rewrite)) {
            $args->rewrite = array();
        }
        if (empty($args->rewrite['slug'])) {
            $args->rewrite['slug'] = $post_type;
        }
        if (!isset($args->rewrite['with_front'])) {
            $args->rewrite['with_front'] = true;
        }
        if (!isset($args->rewrite['pages'])) {
            $args->rewrite['pages'] = true;
        }
        if (!isset($args->rewrite['feeds']) || !$args->has_archive) {
            $args->rewrite['feeds'] = (bool) $args->has_archive;
        }
        if (!isset($args->rewrite['ep_mask'])) {
            if (isset($args->permalink_epmask)) {
                $args->rewrite['ep_mask'] = $args->permalink_epmask;
            } else {
                $args->rewrite['ep_mask'] = EP_PERMALINK;
            }
        }
        if ($args->hierarchical) {
            add_rewrite_tag("%{$post_type}%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type={$post_type}&pagename=");
        } else {
            add_rewrite_tag("%{$post_type}%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type={$post_type}&name=");
        }
        if ($args->has_archive) {
            $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive;
            if ($args->rewrite['with_front']) {
                $archive_slug = substr($wp_rewrite->front, 1) . $archive_slug;
            } else {
                $archive_slug = $wp_rewrite->root . $archive_slug;
            }
            add_rewrite_rule("{$archive_slug}/?\$", "index.php?post_type={$post_type}", 'top');
            if ($args->rewrite['feeds'] && $wp_rewrite->feeds) {
                $feeds = '(' . trim(implode('|', $wp_rewrite->feeds)) . ')';
                add_rewrite_rule("{$archive_slug}/feed/{$feeds}/?\$", "index.php?post_type={$post_type}" . '&feed=$matches[1]', 'top');
                add_rewrite_rule("{$archive_slug}/{$feeds}/?\$", "index.php?post_type={$post_type}" . '&feed=$matches[1]', 'top');
            }
            if ($args->rewrite['pages']) {
                add_rewrite_rule("{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?\$", "index.php?post_type={$post_type}" . '&paged=$matches[1]', 'top');
            }
        }
        $permastruct_args = $args->rewrite;
        $permastruct_args['feed'] = $permastruct_args['feeds'];
        add_permastruct($post_type, "{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args);
    }
    // Register the post type meta box if a custom callback was specified.
    if ($args->register_meta_box_cb) {
        add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1);
    }
    $args->labels = get_post_type_labels($args);
    $args->label = $args->labels->name;
    $wp_post_types[$post_type] = $args;
    add_action('future_' . $post_type, '_future_post_hook', 5, 2);
    foreach ($args->taxonomies as $taxonomy) {
        register_taxonomy_for_object_type($taxonomy, $post_type);
    }
    /**
     * Fires after a post type is registered.
     *
     * @since 3.3.0
     *
     * @param string $post_type Post type.
     * @param object $args      Arguments used to register the post type.
     */
    do_action('registered_post_type', $post_type, $args);
    return $args;
}
コード例 #2
0
 public function _action_init_permalinks($args)
 {
     add_rewrite_tag('%wpsc_min_price%', '([\\d\\.]+)', 'post_type=wpsc-product&wpsc_min_price=');
     add_rewrite_tag('%wpsc_max_price%', '([\\d\\.]+)', 'wpsc_max_price=');
     add_permastruct('wpsc_price_range', $args['has_archive'] . '/%wpsc_min_price%/%wpsc_max_price%', array());
     return $args;
 }
コード例 #3
0
function jeg_post_type_portfolio()
{
    $args = array('labels' => array('name' => 'Portfolio', 'singular_name' => 'Portfolio Item', 'add_new' => 'Add Portfolio', 'add_new_item' => 'Add Portfolio', 'edit_item' => 'Edit Portfolio', 'new_item' => 'New Portfolio', 'view_item' => 'View Item', 'search_items' => 'Search Portfolio Items', 'not_found' => 'No portfolio items found', 'not_found_in_trash' => 'No portfolio items found in Trash', 'parent_item_colon' => ''), 'description' => 'Portfolio Post type', 'public' => true, 'show_ui' => true, 'menu_icon' => get_template_directory_uri() . '/public/img/portfolio.png', 'menu_position' => 6, 'capability_type' => 'post', 'hierarchical' => false, 'supports' => array('title', 'editor', 'comments', 'page-attributes'), 'rewrite' => array('slug' => '%portfolio_page%', 'with_front' => true), 'taxonomies' => array(JEG_PORTFOLIO_CATEGORY));
    register_post_type(JEG_PORTFOLIO_POST_TYPE, $args);
    add_rewrite_tag('%portfolio%', '([^/]+)');
    add_permastruct('portfolio', '%portfolio_page%/%portfolio%/', false);
}
コード例 #4
0
ファイル: collection.php プロジェクト: forthrobot/inuvik
/**
 * Registers a smart collection of products
 *
 * @api
 * @since 1.2
 *
 * @param string $name Class name of the smart collection
 * @return void
 **/
function shopp_register_collection($name = '')
{
    if (empty($name)) {
        shopp_debug(__FUNCTION__ . " failed: Collection name required.");
        return false;
    }
    $Shopp = Shopp::object();
    $namespace = apply_filters('shopp_smart_collections_slug', SmartCollection::$namespace);
    $permastruct = SmartCollection::$taxon;
    $slugs = SmartCollection::slugs($name);
    $slug = $slugs[0];
    $Shopp->Collections[$slug] = $name;
    do_action('shopp_register_collection', $name, $slug);
    $slugs = SmartCollection::slugs($name);
    add_rewrite_tag("%{$permastruct}%", "([^/]+)");
    add_permastruct($permastruct, ShoppPages()->baseslug() . "/{$namespace}/%shopp_collection%", false);
    add_filter($permastruct . '_rewrite_rules', array('ProductCollection', 'pagerewrites'));
    $apicall = create_function('$result, $options, $O', 'ShoppCollection( new ' . $name . '($options) );
		return ShoppStorefrontThemeAPI::category($result, $options, $O);');
    foreach ((array) $slugs as $collection) {
        $collection = str_replace(array('-', '_'), '', $collection);
        // Sanitize slugs
        add_filter('shopp_themeapi_storefront_' . $collection . 'products', $apicall, 10, 3);
        // @deprecated
        add_filter('shopp_themeapi_storefront_' . $collection . 'collection', $apicall, 10, 3);
    }
    // Add special default permalink handling for collection URLs (only add it once)
    global $wp_rewrite;
    if (!$wp_rewrite->using_permalinks() && false === has_filter('term_link', array('SmartCollection', 'defaultlinks'))) {
        add_filter('term_link', array('SmartCollection', 'defaultlinks'), 10, 3);
    }
}
コード例 #5
0
 public function test_remove_permastruct()
 {
     global $wp_rewrite;
     add_permastruct('foo', 'bar/%foo%');
     $this->assertInternalType('array', $wp_rewrite->extra_permastructs['foo']);
     $this->assertSame('/bar/%foo%', $wp_rewrite->extra_permastructs['foo']['struct']);
     remove_permastruct('foo');
     $this->assertFalse(isset($wp_rewrite->extra_permastructs['foo']));
 }
コード例 #6
0
ファイル: Pages.php プロジェクト: jonathandavis/shopp
 public static function permalinks()
 {
     $var = ShoppPages::QUERYVAR;
     $pageslugs = ShoppPages()->slugs();
     $catalog = $pageslugs['catalog'];
     unset($pageslugs['catalog']);
     add_rewrite_tag("%{$var}%", '(' . join('|', $pageslugs) . ')');
     add_permastruct($var, "{$catalog}/%{$var}%", false);
 }
コード例 #7
0
 function set_gallery_permastruct()
 {
     $permalink_structure = get_option('permalink_structure');
     $gallery_structure = get_option('gallery_structure');
     if ($gallery_structure) {
         // false is important in add_permastruct so that it does not append the general blog structure our gallery structure
         add_permastruct('gallery', $gallery_structure, false);
     } else {
         add_permastruct('gallery', "", false);
     }
 }
 /**
  * @global WP $wp 
  */
 public static function init()
 {
     global $wp;
     add_rewrite_rule('wpmsm-manifest\\.json$', 'index.php?wpmsmm=1', 'top');
     add_rewrite_tag('%wpmsmaction%', '(.+)');
     add_permastruct('wpmsmendpoint', '/wpmsm-endpoint/%wpmsmaction%', false);
     $wp->add_query_var('wpmsmm');
     if (!wp_next_scheduled('wpmsm_create_new_keys')) {
         wp_schedule_event(time(), 'monthly', 'wpmsm_create_new_keys');
     }
 }
コード例 #9
0
function mb_forum_rewrite_tags($post_type, $args)
{
    if (mb_get_forum_post_type() !== $post_type) {
        return;
    }
    add_rewrite_tag("%{$post_type}%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type={$post_type}&pagename=");
    //	add_rewrite_tag("%{$post_type}%", '([^/]+)', "post_type=$post_type&pagename=");
    $permastruct_args = $args->rewrite;
    $permastruct_args['feed'] = $permastruct_args['feeds'];
    add_permastruct($post_type, mb_get_forum_slug() . "/%{$post_type}%", $permastruct_args);
}
コード例 #10
0
ファイル: Rewrite.php プロジェクト: sangpena/appflex.mobi
 /**
  *
  * registered_post_type
  *  ** add rewrite tag for Custom Post Type.
  * @version 1.1
  * @since 0.9
  *
  */
 public function registered_post_type($post_type, $args)
 {
     global $wp_post_types, $wp_rewrite;
     if ($args->_builtin or !$args->publicly_queryable or !$args->show_ui) {
         return false;
     }
     $permalink = get_option($post_type . '_structure');
     if (!$permalink) {
         $permalink = CPTP_DEFAULT_PERMALINK;
     }
     $permalink = '%' . $post_type . '_slug%' . $permalink;
     $permalink = str_replace('%postname%', '%' . $post_type . '%', $permalink);
     add_rewrite_tag('%' . $post_type . '_slug%', '(' . $args->rewrite['slug'] . ')', 'post_type=' . $post_type . '&slug=');
     $taxonomies = CPTP_Util::get_taxonomies(true);
     foreach ($taxonomies as $taxonomy => $objects) {
         $wp_rewrite->add_rewrite_tag("%{$taxonomy}%", '(.+?)', "{$taxonomy}=");
     }
     $rewrite_args = $args->rewrite;
     if (!is_array($rewrite_args)) {
         $rewrite_args = array('with_front' => $args->rewrite);
     }
     $rewrite_args["walk_dirs"] = false;
     add_permastruct($post_type, $permalink, $rewrite_args);
     $slug = $args->rewrite['slug'];
     if ($args->has_archive) {
         if (is_string($args->has_archive)) {
             $slug = $args->has_archive;
         }
         if ($args->rewrite['with_front']) {
             $slug = substr($wp_rewrite->front, 1) . $slug;
         }
         add_rewrite_rule($slug . '/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/date/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type=' . $post_type, 'top');
         add_rewrite_rule($slug . '/author/([^/]+)/?$', 'index.php?author_name=$matches[1]&post_type=' . $post_type, 'top');
     }
 }
コード例 #11
0
ファイル: post-types.php プロジェクト: jackmachin/bayer
function post_type_portfolio() {

	global $wpdb;

	register_post_type('portfolio', array( 'label' => 'Portfolio Items','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'show_in_nav_menus' => true,'capability_type' => 'post','hierarchical' => false,'rewrite' => array('slug' => '%portfolio_page%','with_front'=>true),'query_var' => true,'supports' => array('title','editor','trackbacks','revisions','thumbnail'),'labels' => array (
				'name' => 'Portfolio Items',
				'singular_name' => 'Portfolio Item',
				'menu_name' => 'Portfolio Items',
				'add_new' => 'Add Portfolio Item',
				'add_new_item' => 'Add New Portfolio Item',
				'edit' => 'Edit',
				'edit_item' => 'Edit Portfolio Item',
				'new_item' => 'New Portfolio Item',
				'view' => 'View Portfolio Item',
				'view_item' => 'View Portfolio Item',
				'search_items' => 'Search Portfolio Items',
				'not_found' => 'No Portfolio Items Found',
				'not_found_in_trash' => 'No Portfolio Items Found in Trash',
				'parent' => 'Parent Portfolio Item',
			),) );


	add_rewrite_tag( '%portfolio%', '([^/]+)' );
	add_permastruct('portfolio', '%portfolio_page%/%portfolio%/', false );

	$querystr = "
	    SELECT $wpdb->posts.*
	    FROM $wpdb->posts, $wpdb->postmeta
	    WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
	    AND $wpdb->postmeta.meta_key = '_wp_page_template'
	    AND $wpdb->postmeta.meta_value = 'templates/portfolio.php'
	    AND $wpdb->posts.post_status = 'publish'
	    AND $wpdb->posts.post_type = 'page'";

	$pageposts = $wpdb->get_results($querystr, OBJECT);

	foreach ($pageposts as $pagepost){
		add_rewrite_rule($pagepost->post_name.'/([^/]*)/?$','index.php?portfolio=$matches[1]','top');
		add_rewrite_rule($pagepost->post_name.'/([^/]+)/page/?([0-9]{1,})/?$','index.php?portfolio=$matches[1]&paged=$matches[2]','top');
	}

	flush_rewrite_rules();

}
コード例 #12
0
/**
 * Registers the event custom post type
 * Hooked onto init
 *
 * @ignore
 * @access private
 * @since 1.0
 */
function eventorganiser_cpt_register()
{
    $labels = array('name' => __('Events', 'eventorganiser'), 'singular_name' => __('Event', 'eventorganiser'), 'add_new' => _x('Add New', 'post'), 'add_new_item' => __('Add New Event', 'eventorganiser'), 'edit_item' => __('Edit Event', 'eventorganiser'), 'new_item' => __('New Event', 'eventorganiser'), 'all_items' => __('All events', 'eventorganiser'), 'view_item' => __('View Event', 'eventorganiser'), 'search_items' => __('Search events', 'eventorganiser'), 'not_found' => __('No events found', 'eventorganiser'), 'not_found_in_trash' => __('No events found in Trash', 'eventorganiser'), 'parent_item_colon' => '', 'menu_name' => __('Events', 'eventorganiser'));
    $exclude_from_search = eventorganiser_get_option('excludefromsearch') == 0 ? false : true;
    if (!eventorganiser_get_option('prettyurl')) {
        $event_rewrite = false;
        $events_slug = true;
    } else {
        $event_slug = trim(eventorganiser_get_option('url_event', 'events/event'), "/");
        $events_slug = trim(eventorganiser_get_option('url_events', 'events/event'), "/");
        $event_rewrite = array('slug' => $event_slug, 'with_front' => false, 'feeds' => true, 'pages' => true);
        /* Workaround for http://core.trac.wordpress.org/ticket/19871 */
        global $wp_rewrite;
        $wp_rewrite->add_rewrite_tag('%event_ondate%', '([0-9]{4}(?:/[0-9]{2}(?:/[0-9]{2})?)?)', 'post_type=event&ondate=');
        add_permastruct('event_archive', $events_slug . '/on/%event_ondate%', array('with_front' => false));
    }
    $args = array('labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'exclude_from_search' => $exclude_from_search, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'capability_type' => 'event', 'rewrite' => $event_rewrite, 'capabilities' => array('publish_posts' => 'publish_events', 'edit_posts' => 'edit_events', 'edit_others_posts' => 'edit_others_events', 'delete_posts' => 'delete_events', 'delete_others_posts' => 'delete_others_events', 'read_private_posts' => 'read_private_events', 'edit_post' => 'edit_event', 'delete_post' => 'delete_event', 'read_post' => 'read_event'), 'has_archive' => $events_slug, 'hierarchical' => false, 'menu_icon' => defined('MP6') && MP6 ? false : EVENT_ORGANISER_URL . 'css/images/eoicon-16.png', 'menu_position' => apply_filters('eventorganiser_menu_position', 5), 'supports' => eventorganiser_get_option('supports'));
    register_post_type('event', apply_filters('eventorganiser_event_properties', $args));
}
コード例 #13
0
ファイル: Rewrite.php プロジェクト: Trideon/gigolo
 function update_term_rewrite_rules()
 {
     //add rewrite for question taxonomy
     global $wp_rewrite;
     $options = get_option('dwqa_options');
     $page_id = $options['pages']['archive-question'];
     $question_list_page = get_page($page_id);
     $rewrite_category = isset($options['question-category-rewrite']) ? sanitize_title($options['question-category-rewrite']) : 'question-category';
     $rewrite_tag = isset($options['question-tag-rewrite']) ? sanitize_title($options['question-tag-rewrite']) : 'question-tag';
     if ($question_list_page) {
         $dwqa_rewrite_rules = array('^' . $question_list_page->post_name . '/' . $rewrite_category . '/([^/]*)' => 'index.php?page_id=' . $page_id . '&taxonomy=dwqa-question_category&dwqa-question_category=$matches[1]', '^' . $question_list_page->post_name . '/' . $rewrite_tag . '/([^/]*)' => 'index.php?page_id=' . $page_id . '&taxonomy=dwqa-question_tag&dwqa-question_tag=$matches[1]');
         foreach ($dwqa_rewrite_rules as $regex => $redirect) {
             add_rewrite_rule($regex, $redirect, 'top');
         }
         // Add permastruct for pretty link
         add_permastruct('dwqa-question_category', "{$question_list_page->post_name}/{$rewrite_category}/%dwqa-question_category%", array('with_front' => false));
         add_permastruct('dwqa-question_tag', "{$question_list_page->post_name}/{$rewrite_tag}/%dwqa-question_tag%", array('with_front' => false));
     }
 }
コード例 #14
0
ファイル: portfolio.php プロジェクト: hungrig4leben/my-gp
/**
 * Initialize Portolio
 */
function gp_portfolio_init()
{
    add_image_size('gp-portfolio-thumbnail', 90, 90, true);
    $portfolio_base = gp_portfolio_base_slug();
    /**
     * Cache $portfolio_base, if it has changed, then we need to flush rules.
     */
    $flush = false;
    $cached_portfolio_base = get_transient('gp_portfolio_slug');
    if ($cached_portfolio_base) {
        if ($portfolio_base != $cached_portfolio_base) {
            $flush = true;
        }
    } else {
        $flush = true;
    }
    /**
     * First we register taxonomy, then custom post type.
     * The order is important, because of rewrite rules.
     */
    $args = array('label' => 'Project Types', 'singular_label' => 'Project Type', 'query_var' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_tagcloud' => false, 'hierarchical' => true, 'rewrite' => array('slug' => $portfolio_base));
    register_taxonomy('gp-project-type', 'gp_portfolio', $args);
    /**
     * Register portfolio_project custom post type.
     */
    $args = array('label' => __(' Portfolio', 'gp'), 'singular_label' => __('Project', 'gp'), 'public' => true, 'show_ui' => true, 'capability_type' => 'page', 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'taxonomy' => 'gp-project-type', 'has_archive' => true, 'menu_icon' => get_template_directory_uri() . '/images/wp-admin/portfolio.png', 'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'page-attributes'));
    register_post_type('gp_portfolio', $args);
    /**
     * Register portfolio Project Media File
     */
    $args = array('label' => __(' Project Media', 'gp'), 'singular_label' => __('Project Media File', 'gp'), 'public' => false, 'supports' => array('title'));
    register_post_type('gp_portfolio_project_media', $args);
    $portfolio_structure = '/' . $portfolio_base . '/%projecttype%/%gp_portfolio%';
    add_rewrite_tag('%projecttype%', '([^&/]+)', 'gp_project_type=');
    add_rewrite_tag('%gp_portfolio%', '([^&/]+)', 'gp_portfolio=');
    add_permastruct('gp_portfolio', $portfolio_structure, false);
    if ($flush) {
        it_flush_rewrite_rules();
        set_transient('gp_portfolio_slug', $portfolio_base, 60 * 60 * 24);
    }
}
コード例 #15
0
 /**
  * Replace "permastruct", for single.
  *
  * This code simulate the code used in WordPress function "register_post_type"
  * and execute it for each language.
  */
 private function replace_permastruct()
 {
     global $wp_rewrite;
     $post_type = $this->post_type_object->name;
     // remove the original permastructs
     unset($wp_rewrite->extra_permastructs[$post_type]);
     // add the translated permastructs for each languages
     foreach ($this->translated_slugs as $lang => $translated_slug) {
         $args = $translated_slug;
         if ($args->rewrite !== false && (is_admin() || get_option('permalink_structure') != '')) {
             $permastruct_args = $args->rewrite;
             $permastruct_args['feed'] = $permastruct_args['feeds'];
             // set the walk_dirs to false to avoid conflict with has_archive = false and the %language%
             // in the rewrite directive. Without it the archive page redirect to the frontpage if has_archive is false
             $permastruct_args['walk_dirs'] = false;
             // if "Hide URL language information for default language" option is
             // set to true the rules has to be different for the default language
             if ($this->plugin === 'Polylang') {
                 global $polylang;
                 // if "The language is set from content" is enabled
                 if ((bool) $polylang->options['force_lang'] === false) {
                     add_permastruct($post_type . '_' . $lang, "{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args);
                 } else {
                     if ($polylang->options['hide_default'] && $lang == pll_default_language()) {
                         add_permastruct($post_type . '_' . $lang, "{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args);
                     } else {
                         // if "Keep /language/ in pretty permalinks" is enabled
                         if ($polylang->options['rewrite'] == 0 && !($polylang->options['hide_default'] && $lang == pll_default_language())) {
                             add_permastruct($post_type . '_' . $lang, 'language/' . "%language%/{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args);
                         } else {
                             add_permastruct($post_type . '_' . $lang, "%language%/{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args);
                         }
                     }
                 }
             } elseif ($this->plugin === 'WPML') {
                 add_permastruct($post_type . '_' . $lang, "{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args);
             }
             do_action('wpml_translated_post_type_replace_permastruct', $post_type, $lang, $translated_slug);
         }
     }
 }
コード例 #16
0
/**
 * Creates or modifies a taxonomy object.
 *
 * Note: Do not use before the {@see 'init'} hook.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * @since 2.3.0
 * @since 4.2.0 Introduced `show_in_quick_edit` argument.
 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front-end.
 *
 * @global array $wp_taxonomies Registered taxonomies.
 * @global WP    $wp            WP instance.
 *
 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args        {
 *     Optional. Array or query string of arguments for registering a taxonomy.
 *
 *     @type string        $label                 Name of the taxonomy shown in the menu. Usually plural. If not set,
 *                                                `$labels['name']` will be used.
 *     @type array         $labels                An array of labels for this taxonomy. By default, Tag labels are used for
 *                                                non-hierarchical taxonmies, and Category labels are used for hierarchical
 *                                                taxonomies. See accepted values in get_taxonomy_labels().
 *                                                Default empty array.
 *     @type string        $description           A short descriptive summary of what the taxonomy is for. Default empty.
 *     @type bool          $public                Whether the taxonomy is publicly queryable. Default true.
 *     @type bool          $hierarchical          Whether the taxonomy is hierarchical. Default false.
 *     @type bool          $show_ui               Whether to generate and allow a UI for managing terms in this taxonomy in
 *                                                the admin. If not set, the default is inherited from `$public`
 *                                                (default true).
 *     @type bool          $show_in_menu          Whether to show the taxonomy in the admin menu. If true, the taxonomy is
 *                                                shown as a submenu of the object type menu. If false, no menu is shown.
 *                                                `$show_ui` must be true. If not set, default is inherited from `$show_ui`
 *                                                (default true).
 *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
 *                                                set, the default is inherited from `$public` (default true).
 *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
 *                                                the default is inherited from `$show_ui` (default true).
 *     @type bool          $show_admin_column     Whether to display a column for the taxonomy on its post type listing
 *                                                screens. Default false.
 *     @type bool|callable $meta_box_cb           Provide a callback function for the meta box display. If not set,
 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
 *                                                box is shown.
 *     @type array         $capabilities {
 *         Array of capabilities for this taxonomy.
 *
 *         @type string $manage_terms Default 'manage_categories'.
 *         @type string $edit_terms   Default 'manage_categories'.
 *         @type string $delete_terms Default 'manage_categories'.
 *         @type string $assign_terms Default 'edit_posts'.
 *     }
 *     @type bool|array    $rewrite {
 *         Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
 *         rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
 *
 *         @type string $slug         Customize the permastruct slug. Default `$taxonomy` key.
 *         @type bool   $with_front   Should the permastruct be prepended with WP_Rewrite::$front. Default true.
 *         @type bool   $hierarchical Either hierarchical rewrite tag or not. Default false.
 *         @type int    $ep_mask      Assign an endpoint mask. Default `EP_NONE`.
 *     }
 *     @type string        $query_var             Sets the query var key for this taxonomy. Default `$taxonomy` key. If
 *                                                false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
 *                                                string, the query `?{query_var}={term_slug}` will be valid.
 *     @type callable      $update_count_callback Works much like a hook, in that it will be called when the count is
 *                                                updated. Default _update_post_term_count() for taxonomies attached
 *                                                to post types, which confirms that the objects are published before
 *                                                counting them. Default _update_generic_term_count() for taxonomies
 *                                                attached to other object types, such as users.
 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
 *                                                Default false.
 * }
 * @return WP_Error|void WP_Error, if errors.
 */
function register_taxonomy($taxonomy, $object_type, $args = array())
{
    global $wp_taxonomies, $wp;
    if (!is_array($wp_taxonomies)) {
        $wp_taxonomies = array();
    }
    $args = wp_parse_args($args);
    /**
     * Filter the arguments for registering a taxonomy.
     *
     * @since 4.4.0
     *
     * @param array  $args        Array of arguments for registering a taxonomy.
     * @param array  $object_type Array of names of object types for the taxonomy.
     * @param string $taxonomy    Taxonomy key.
     */
    $args = apply_filters('register_taxonomy_args', $args, $taxonomy, (array) $object_type);
    $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false);
    $args = array_merge($defaults, $args);
    if (empty($taxonomy) || strlen($taxonomy) > 32) {
        _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2');
        return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.'));
    }
    if (false !== $args['query_var'] && !empty($wp)) {
        if (true === $args['query_var']) {
            $args['query_var'] = $taxonomy;
        } else {
            $args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        }
        $wp->add_query_var($args['query_var']);
    }
    if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) {
        $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE));
        if (empty($args['rewrite']['slug'])) {
            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
        }
        if ($args['hierarchical'] && $args['rewrite']['hierarchical']) {
            $tag = '(.+?)';
        } else {
            $tag = '([^/]+)';
        }
        add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
        add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']);
    }
    // If not set, default to the setting for public.
    if (null === $args['show_ui']) {
        $args['show_ui'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_menu'] || !$args['show_ui']) {
        $args['show_in_menu'] = $args['show_ui'];
    }
    // If not set, default to the setting for public.
    if (null === $args['show_in_nav_menus']) {
        $args['show_in_nav_menus'] = $args['public'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_tagcloud']) {
        $args['show_tagcloud'] = $args['show_ui'];
    }
    // If not set, default to the setting for show_ui.
    if (null === $args['show_in_quick_edit']) {
        $args['show_in_quick_edit'] = $args['show_ui'];
    }
    $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts');
    $args['cap'] = (object) array_merge($default_caps, $args['capabilities']);
    unset($args['capabilities']);
    $args['name'] = $taxonomy;
    $args['object_type'] = array_unique((array) $object_type);
    $args['labels'] = get_taxonomy_labels((object) $args);
    $args['label'] = $args['labels']->name;
    // If not set, use the default meta box
    if (null === $args['meta_box_cb']) {
        if ($args['hierarchical']) {
            $args['meta_box_cb'] = 'post_categories_meta_box';
        } else {
            $args['meta_box_cb'] = 'post_tags_meta_box';
        }
    }
    $wp_taxonomies[$taxonomy] = (object) $args;
    // register callback handling for metabox
    add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
    /**
     * Fires after a taxonomy is registered.
     *
     * @since 3.3.0
     *
     * @param string       $taxonomy    Taxonomy slug.
     * @param array|string $object_type Object type or array of object types.
     * @param array        $args        Array of taxonomy registration arguments.
     */
    do_action('registered_taxonomy', $taxonomy, $object_type, $args);
}
コード例 #17
0
/**
 * Add dril down permastruct for product categories
 *
 * @since  0.1
 * @access private
 * @param  array $args Product category taxonomy args
 * @return array
 */
function _wpsc_te2_filter_drill_down_category_permalinks($args)
{
    add_permastruct('wpsc_cat_drill_down_category', $args['rewrite']['slug'] . '/%wpsc_product_category%/product-filter/%wpsc_cat_drill_down_tax%');
    return $args;
}
コード例 #18
0
 /**
  * Optionaly removes 'language' in permalinks so that we get http://www.myblog/en/ instead of http://www.myblog/language/en/
  *
  * @since 1.2
  */
 function add_permastruct()
 {
     // Language information always in front of the uri ( 'with_front' => false )
     // The 3rd parameter structure has been modified in WP 3.4
     // Leads to error 404 for pages when there is no language created yet
     if ($this->model->get_languages_list()) {
         add_permastruct('language', $this->options['rewrite'] ? '%language%' : 'language/%language%', array('with_front' => false));
     }
 }
コード例 #19
0
 /**
  * Register the permastructs
  *
  * @package WP Idea Stream
  * @subpackage core/classes
  *
  * @since 2.0.0
  *
  * @uses add_permastruct()
  */
 public function add_permastructs()
 {
     // User Permastruct
     add_permastruct($this->user_rid, $this->user_slug . '/%' . $this->user_rid . '%', array('with_front' => false, 'ep_mask' => EP_NONE, 'paged' => true, 'feed' => false, 'forcomments' => false, 'walk_dirs' => true, 'endpoints' => false));
     // Action Permastruct
     add_permastruct($this->action_rid, $this->action_slug . '/%' . $this->action_rid . '%', array('with_front' => false, 'ep_mask' => EP_NONE, 'paged' => true, 'feed' => false, 'forcomments' => false, 'walk_dirs' => true, 'endpoints' => false));
 }
コード例 #20
0
ファイル: extended-cpts.php プロジェクト: m-e-h/doc-directory
 /**
  * Action fired after a CPT is registered in order to set up the custom permalink structure for the post type.
  * 
  * @param string $post_type Post type name.
  * @param object $args      Arguments used to register the post type.
  */
 public function registered_post_type($post_type, stdClass $args)
 {
     if ($post_type != $this->post_type) {
         return;
     }
     $struct = str_replace("%{$this->post_type}_slug%", $this->post_slug, $args->rewrite['permastruct']);
     add_permastruct($this->post_type, $struct, $args->rewrite);
 }
コード例 #21
0
ファイル: post.php プロジェクト: par-orillonsoft/Wishmagnet
/**
 * Register a post type. Do not use before init.
 *
 * A function for creating or modifying a post type based on the
 * parameters given. The function will accept an array (second optional
 * parameter), along with a string for the post type name.
 *
 * Optional $args contents:
 *
 * - label - Name of the post type shown in the menu. Usually plural. If not set, labels['name'] will be used.
 * - labels - An array of labels for this post type.
 *     * If not set, post labels are inherited for non-hierarchical types and page labels for hierarchical ones.
 *     * You can see accepted values in {@link get_post_type_labels()}.
 * - description - A short descriptive summary of what the post type is. Defaults to blank.
 * - public - Whether a post type is intended for use publicly either via the admin interface or by front-end users.
 *     * Defaults to false.
 *     * While the default settings of exclude_from_search, publicly_queryable, show_ui, and show_in_nav_menus are
 *       inherited from public, each does not rely on this relationship and controls a very specific intention.
 * - exclude_from_search - Whether to exclude posts with this post type from front end search results.
 *     * If not set, the the opposite of public's current value is used.
 * - publicly_queryable - Whether queries can be performed on the front end for the post type as part of parse_request().
 *     * ?post_type={post_type_key}
 *     * ?{post_type_key}={single_post_slug}
 *     * ?{post_type_query_var}={single_post_slug}
 *     * If not set, the default is inherited from public.
 * - show_ui - Whether to generate a default UI for managing this post type in the admin.
 *     * If not set, the default is inherited from public.
 * - show_in_nav_menus - Makes this post type available for selection in navigation menus.
 *     * If not set, the default is inherited from public.
 * - show_in_menu - Where to show the post type in the admin menu.
 *     * If true, the post type is shown in its own top level menu.
 *     * If false, no menu is shown
 *     * If a string of an existing top level menu (eg. 'tools.php' or 'edit.php?post_type=page'), the post type will
 *       be placed as a sub menu of that.
 *     * show_ui must be true.
 *     * If not set, the default is inherited from show_ui
 * - show_in_admin_bar - Makes this post type available via the admin bar.
 *     * If not set, the default is inherited from show_in_menu
 * - menu_position - The position in the menu order the post type should appear.
 *     * show_in_menu must be true
 *     * Defaults to null, which places it at the bottom of its area.
 * - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon.
 * - capability_type - The string to use to build the read, edit, and delete capabilities. Defaults to 'post'.
 *     * May be passed as an array to allow for alternative plurals when using this argument as a base to construct the
 *       capabilities, e.g. array('story', 'stories').
 * - capabilities - Array of capabilities for this post type.
 *     * By default the capability_type is used as a base to construct capabilities.
 *     * You can see accepted values in {@link get_post_type_capabilities()}.
 * - map_meta_cap - Whether to use the internal default meta capability handling. Defaults to false.
 * - hierarchical - Whether the post type is hierarchical (e.g. page). Defaults to false.
 * - supports - An alias for calling add_post_type_support() directly. Defaults to title and editor.
 *     * See {@link add_post_type_support()} for documentation.
 * - register_meta_box_cb - Provide a callback function that will be called when setting up the
 *     meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback.
 * - taxonomies - An array of taxonomy identifiers that will be registered for the post type.
 *     * Default is no taxonomies.
 *     * Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type().
 * - has_archive - True to enable post type archives. Default is false.
 *     * Will generate the proper rewrite rules if rewrite is enabled.
 * - rewrite - Triggers the handling of rewrites for this post type. Defaults to true, using $post_type as slug.
 *     * To prevent rewrite, set to false.
 *     * To specify rewrite rules, an array can be passed with any of these keys
 *         * 'slug' => string Customize the permastruct slug. Defaults to $post_type key
 *         * 'with_front' => bool Should the permastruct be prepended with WP_Rewrite::$front. Defaults to true.
 *         * 'feeds' => bool Should a feed permastruct be built for this post type. Inherits default from has_archive.
 *         * 'pages' => bool Should the permastruct provide for pagination. Defaults to true.
 *         * 'ep_mask' => const Assign an endpoint mask.
 *             * If not specified and permalink_epmask is set, inherits from permalink_epmask.
 *             * If not specified and permalink_epmask is not set, defaults to EP_PERMALINK
 * - query_var - Sets the query_var key for this post type. Defaults to $post_type key
 *     * If false, a post type cannot be loaded at ?{query_var}={post_slug}
 *     * If specified as a string, the query ?{query_var_string}={post_slug} will be valid.
 * - can_export - Allows this post type to be exported. Defaults to true.
 * - delete_with_user - Whether to delete posts of this type when deleting a user.
 *     * If true, posts of this type belonging to the user will be moved to trash when then user is deleted.
 *     * If false, posts of this type belonging to the user will *not* be trashed or deleted.
 *     * If not set (the default), posts are trashed if post_type_supports('author'). Otherwise posts are not trashed or deleted.
 * - _builtin - true if this post type is a native or "built-in" post_type. THIS IS FOR INTERNAL USE ONLY!
 * - _edit_link - URL segement to use for edit link of this post type. THIS IS FOR INTERNAL USE ONLY!
 *
 * @since 2.9.0
 * @uses $wp_post_types Inserts new post type object into the list
 *
 * @param string $post_type Post type key, must not exceed 20 characters
 * @param array|string $args See optional args description above.
 * @return object|WP_Error the registered post type object, or an error object
 */
function register_post_type($post_type, $args = array())
{
    global $wp_post_types, $wp_rewrite, $wp;
    if (!is_array($wp_post_types)) {
        $wp_post_types = array();
    }
    // Args prefixed with an underscore are reserved for internal use.
    $defaults = array('labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, 'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false, 'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 'can_export' => true, 'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null, 'delete_with_user' => null);
    $args = wp_parse_args($args, $defaults);
    $args = (object) $args;
    $post_type = sanitize_key($post_type);
    $args->name = $post_type;
    if (strlen($post_type) > 20) {
        return new WP_Error('post_type_too_long', __('Post types cannot exceed 20 characters in length'));
    }
    // If not set, default to the setting for public.
    if (null === $args->publicly_queryable) {
        $args->publicly_queryable = $args->public;
    }
    // If not set, default to the setting for public.
    if (null === $args->show_ui) {
        $args->show_ui = $args->public;
    }
    // If not set, default to the setting for show_ui.
    if (null === $args->show_in_menu || !$args->show_ui) {
        $args->show_in_menu = $args->show_ui;
    }
    // If not set, default to the whether the full UI is shown.
    if (null === $args->show_in_admin_bar) {
        $args->show_in_admin_bar = true === $args->show_in_menu;
    }
    // Whether to show this type in nav-menus.php. Defaults to the setting for public.
    if (null === $args->show_in_nav_menus) {
        $args->show_in_nav_menus = $args->public;
    }
    // If not set, default to true if not public, false if public.
    if (null === $args->exclude_from_search) {
        $args->exclude_from_search = !$args->public;
    }
    // Back compat with quirky handling in version 3.0. #14122
    if (empty($args->capabilities) && null === $args->map_meta_cap && in_array($args->capability_type, array('post', 'page'))) {
        $args->map_meta_cap = true;
    }
    if (null === $args->map_meta_cap) {
        $args->map_meta_cap = false;
    }
    $args->cap = get_post_type_capabilities($args);
    unset($args->capabilities);
    if (is_array($args->capability_type)) {
        $args->capability_type = $args->capability_type[0];
    }
    if (!empty($args->supports)) {
        add_post_type_support($post_type, $args->supports);
        unset($args->supports);
    } else {
        // Add default features
        add_post_type_support($post_type, array('title', 'editor'));
    }
    if (false !== $args->query_var && !empty($wp)) {
        if (true === $args->query_var) {
            $args->query_var = $post_type;
        }
        $args->query_var = sanitize_title_with_dashes($args->query_var);
        $wp->add_query_var($args->query_var);
    }
    if (false !== $args->rewrite && (is_admin() || '' != get_option('permalink_structure'))) {
        if (!is_array($args->rewrite)) {
            $args->rewrite = array();
        }
        if (empty($args->rewrite['slug'])) {
            $args->rewrite['slug'] = $post_type;
        }
        if (!isset($args->rewrite['with_front'])) {
            $args->rewrite['with_front'] = true;
        }
        if (!isset($args->rewrite['pages'])) {
            $args->rewrite['pages'] = true;
        }
        if (!isset($args->rewrite['feeds']) || !$args->has_archive) {
            $args->rewrite['feeds'] = (bool) $args->has_archive;
        }
        if (!isset($args->rewrite['ep_mask'])) {
            if (isset($args->permalink_epmask)) {
                $args->rewrite['ep_mask'] = $args->permalink_epmask;
            } else {
                $args->rewrite['ep_mask'] = EP_PERMALINK;
            }
        }
        if ($args->hierarchical) {
            add_rewrite_tag("%{$post_type}%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type={$post_type}&name=");
        } else {
            add_rewrite_tag("%{$post_type}%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type={$post_type}&name=");
        }
        if ($args->has_archive) {
            $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive;
            if ($args->rewrite['with_front']) {
                $archive_slug = substr($wp_rewrite->front, 1) . $archive_slug;
            } else {
                $archive_slug = $wp_rewrite->root . $archive_slug;
            }
            add_rewrite_rule("{$archive_slug}/?\$", "index.php?post_type={$post_type}", 'top');
            if ($args->rewrite['feeds'] && $wp_rewrite->feeds) {
                $feeds = '(' . trim(implode('|', $wp_rewrite->feeds)) . ')';
                add_rewrite_rule("{$archive_slug}/feed/{$feeds}/?\$", "index.php?post_type={$post_type}" . '&feed=$matches[1]', 'top');
                add_rewrite_rule("{$archive_slug}/{$feeds}/?\$", "index.php?post_type={$post_type}" . '&feed=$matches[1]', 'top');
            }
            if ($args->rewrite['pages']) {
                add_rewrite_rule("{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?\$", "index.php?post_type={$post_type}" . '&paged=$matches[1]', 'top');
            }
        }
        add_permastruct($post_type, "{$args->rewrite['slug']}/%{$post_type}%", $args->rewrite);
    }
    if ($args->register_meta_box_cb) {
        add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1);
    }
    $args->labels = get_post_type_labels($args);
    $args->label = $args->labels->name;
    $wp_post_types[$post_type] = $args;
    add_action('future_' . $post_type, '_future_post_hook', 5, 2);
    foreach ($args->taxonomies as $taxonomy) {
        register_taxonomy_for_object_type($taxonomy, $post_type);
    }
    do_action('registered_post_type', $post_type, $args);
    return $args;
}
コード例 #22
0
 /**
  * Optionaly removes 'language' in permalinks so that we get http://www.myblog/en/ instead of http://www.myblog/language/en/
  *
  * @since 1.2
  */
 function add_permastruct()
 {
     // Language information always in front of the uri ( 'with_front' => false )
     // The 3rd parameter structure has been modified in WP 3.4
     add_permastruct('language', $this->options['rewrite'] ? '%language%' : 'language/%language%', array('with_front' => false));
 }
コード例 #23
0
ファイル: TAXONOMY.PHP プロジェクト: pauEscarcia/AIMM
/**
 * Create or modify a taxonomy object. Do not use before init.
 *
 * A simple function for creating or modifying a taxonomy object based on the
 * parameters given. The function will accept an array (third optional
 * parameter), along with strings for the taxonomy name and another string for
 * the object type.
 *
 * Nothing is returned, so expect error maybe or use taxonomy_exists() to check
 * whether taxonomy exists.
 *
 * Optional $args contents:
 *
 * label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used.
 *
 * hierarchical - has some defined purpose at other parts of the API and is a
 * boolean value.
 *
 * update_count_callback - works much like a hook, in that it will be called when the count is updated.
 * 	Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms
 * 	that the objects are published before counting them.
 * 	Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links.
 *
 * rewrite - false to prevent rewrite, or array('slug'=>$slug) to customize
 * permastruct; default will use $taxonomy as slug.
 *
 * query_var - false to prevent queries, or string to customize query var
 * (?$query_var=$term); default will use $taxonomy as query var.
 *
 * public - If the taxonomy should be publicly queryable; //@TODO not implemented.
 * defaults to true.
 *
 * show_ui - If the WordPress UI admin tags UI should apply to this taxonomy;
 * defaults to public.
 *
 * show_in_nav_menus - true makes this taxonomy available for selection in navigation menus.
 * Defaults to public.
 *
 * show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget;
 * defaults to show_ui which defaults to public.
 *
 * labels - An array of labels for this taxonomy. You can see accepted values in {@link get_taxonomy_labels()}. By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 * @uses $wp_taxonomies Inserts new taxonomy object into the list
 * @uses $wp Adds query vars
 *
 * @param string $taxonomy Name of taxonomy object
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args See above description for the two keys values.
 * @return null|WP_Error WP_Error if errors, otherwise null.
 */
function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
	global $wp_taxonomies, $wp;

	if ( ! is_array($wp_taxonomies) )
		$wp_taxonomies = array();

	$defaults = array(	'hierarchical' => false,
						'update_count_callback' => '',
						'rewrite' => true,
						'query_var' => $taxonomy,
						'public' => true,
						'show_ui' => null,
						'show_tagcloud' => null,
						'_builtin' => false,
						'labels' => array(),
						'capabilities' => array(),
						'show_in_nav_menus' => null,
					);
	$args = wp_parse_args($args, $defaults);

	if ( strlen( $taxonomy ) > 32 )
		return new WP_Error( 'taxonomy_too_long', __( 'Taxonomies cannot exceed 32 characters in length' ) );

	if ( false !== $args['query_var'] && !empty($wp) ) {
		if ( true === $args['query_var'] )
			$args['query_var'] = $taxonomy;
		else
			$args['query_var'] = sanitize_title_with_dashes($args['query_var']);
		$wp->add_query_var($args['query_var']);
	}

	if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option('permalink_structure') ) ) {
		$args['rewrite'] = wp_parse_args($args['rewrite'], array(
			'slug' => sanitize_title_with_dashes($taxonomy),
			'with_front' => true,
			'hierarchical' => false,
			'ep_mask' => EP_NONE,
		));

		if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] )
			$tag = '(.+?)';
		else
			$tag = '([^/]+)';

		add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" );
		add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] );
	}

	if ( is_null($args['show_ui']) )
		$args['show_ui'] = $args['public'];

	// Whether to show this type in nav-menus.php. Defaults to the setting for public.
	if ( null === $args['show_in_nav_menus'] )
		$args['show_in_nav_menus'] = $args['public'];

	if ( is_null($args['show_tagcloud']) )
		$args['show_tagcloud'] = $args['show_ui'];

	$default_caps = array(
		'manage_terms' => 'manage_categories',
		'edit_terms'   => 'manage_categories',
		'delete_terms' => 'manage_categories',
		'assign_terms' => 'edit_posts',
	);
	$args['cap'] = (object) array_merge( $default_caps, $args['capabilities'] );
	unset( $args['capabilities'] );

	$args['name'] = $taxonomy;
	$args['object_type'] =  array_unique( (array)$object_type );

	$args['labels'] = get_taxonomy_labels( (object) $args );
	$args['label'] = $args['labels']->name;

	$wp_taxonomies[$taxonomy] = (object) $args;

	// register callback handling for metabox
 	add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');

	do_action( 'registered_taxonomy', $taxonomy, $object_type, $args );
}
コード例 #24
0
 /**
  * Adds the necessary rewrite rules for the post type.
  *
  * @since 4.6.0
  * @access public
  *
  * @global WP_Rewrite $wp_rewrite WordPress Rewrite Component.
  * @global WP         $wp         Current WordPress environment instance.
  */
 public function add_rewrite_rules()
 {
     global $wp_rewrite, $wp;
     if (false !== $this->query_var && $wp && is_post_type_viewable($this)) {
         $wp->add_query_var($this->query_var);
     }
     if (false !== $this->rewrite && (is_admin() || '' != get_option('permalink_structure'))) {
         if ($this->hierarchical) {
             add_rewrite_tag("%{$this->name}%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type={$this->name}&pagename=");
         } else {
             add_rewrite_tag("%{$this->name}%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type={$this->name}&name=");
         }
         if ($this->has_archive) {
             $archive_slug = true === $this->has_archive ? $this->rewrite['slug'] : $this->has_archive;
             if ($this->rewrite['with_front']) {
                 $archive_slug = substr($wp_rewrite->front, 1) . $archive_slug;
             } else {
                 $archive_slug = $wp_rewrite->root . $archive_slug;
             }
             add_rewrite_rule("{$archive_slug}/?\$", "index.php?post_type={$this->name}", 'top');
             if ($this->rewrite['feeds'] && $wp_rewrite->feeds) {
                 $feeds = '(' . trim(implode('|', $wp_rewrite->feeds)) . ')';
                 add_rewrite_rule("{$archive_slug}/feed/{$feeds}/?\$", "index.php?post_type={$this->name}" . '&feed=$matches[1]', 'top');
                 add_rewrite_rule("{$archive_slug}/{$feeds}/?\$", "index.php?post_type={$this->name}" . '&feed=$matches[1]', 'top');
             }
             if ($this->rewrite['pages']) {
                 add_rewrite_rule("{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?\$", "index.php?post_type={$this->name}" . '&paged=$matches[1]', 'top');
             }
         }
         $permastruct_args = $this->rewrite;
         $permastruct_args['feed'] = $permastruct_args['feeds'];
         add_permastruct($this->name, "{$this->rewrite['slug']}/%{$this->name}%", $permastruct_args);
     }
 }
コード例 #25
0
 function add_featured_item_permastructure($items_link)
 {
     global $wp_rewrite;
     add_permastruct('featured_item_category', $items_link . '/%featured_item_category%', false);
     add_permastruct('featured_item', $items_link . '/%featured_item_category%/%featured_item%', false);
 }
コード例 #26
0
 /**
  * Add permalink structures for new archive-style destinations.
  *
  * - Users
  * - Topic Views
  * - Search
  *
  * @since bbPress (r4930)
  */
 public static function add_permastructs()
 {
     // Get unique ID's
     $user_id = bbp_get_user_rewrite_id();
     $view_id = bbp_get_view_rewrite_id();
     $search_id = bbp_get_search_rewrite_id();
     // Get root slugs
     $user_slug = bbp_get_user_slug();
     $view_slug = bbp_get_view_slug();
     $search_slug = bbp_get_search_slug();
     // User Permastruct
     add_permastruct($user_id, $user_slug . '/%' . $user_id . '%', array('with_front' => false, 'ep_mask' => EP_NONE, 'paged' => false, 'feed' => false, 'forcomments' => false, 'walk_dirs' => true, 'endpoints' => false));
     // Topic View Permastruct
     add_permastruct($view_id, $view_slug . '/%' . $view_id . '%', array('with_front' => false, 'ep_mask' => EP_NONE, 'paged' => false, 'feed' => false, 'forcomments' => false, 'walk_dirs' => true, 'endpoints' => false));
     // Search Permastruct
     add_permastruct($user_id, $search_slug . '/%' . $search_id . '%', array('with_front' => false, 'ep_mask' => EP_NONE, 'paged' => true, 'feed' => false, 'forcomments' => false, 'walk_dirs' => true, 'endpoints' => false));
 }
コード例 #27
0
ファイル: Wordpress.php プロジェクト: jigoshop/Jigoshop2
 public function addPermastruct($name, $struct, $args = array())
 {
     return add_permastruct($name, $struct, $args);
 }
コード例 #28
0
ファイル: Collection.php プロジェクト: forthrobot/inuvik
 public function register()
 {
     global $wp_rewrite;
     if (!$wp_rewrite->using_permalinks()) {
         return;
     }
     $args['rewrite'] = wp_parse_args($args['rewrite'], array('slug' => sanitize_title_with_dashes($taxonomy), 'with_front' => false));
     add_rewrite_tag("%{$taxonomy}%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term=");
     add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']['with_front']);
 }
コード例 #29
0
ファイル: class-wcbp.php プロジェクト: JDarkGreen/wpmaletek
	/**
	 * Register Permalink Structure for Product.
	 * @since 1.1.0
	 *
	 * @param string $post_type
	 * @param array $args
	 */
	public function add_permastruct( $post_type, $args ) {

		if ( $post_type == 'product' ) {
			$wcbp_base_setting = trim( get_option( 'wcbp_permalinks_base' ), '/' );
			if ( ! $wcbp_base_setting ) {
				$wcbp_base_setting = 'shop';
			}

			add_rewrite_tag( '%product_cat%', '(.+?)', "post_type=product&product_cat=" );

			$permastruct_args         = $args->rewrite;
			$permastruct_args['feed'] = $permastruct_args['feeds'];
			add_permastruct( $post_type, $wcbp_base_setting . '/%product_cat%/%postname%', $permastruct_args );
			// for post id.
			//add_permastruct( $post_type, $wcbp_base_setting.'/%post_id%' ,  $permastruct_args );
		}
	}
コード例 #30
0
ファイル: polylang.php プロジェクト: uoyknaht/kc
 function init()
 {
     global $wpdb;
     $wpdb->termmeta = $wpdb->prefix . 'termmeta';
     // registers the termmeta table in wpdb
     $options = get_option('polylang');
     load_plugin_textdomain('polylang', false, basename(POLYLANG_DIR) . '/languages');
     // plugin i18n
     // registers the language taxonomy
     // codex: use the init action to call this function
     // object types will be set later once all custom post types are registered
     register_taxonomy('language', null, array('labels' => array('name' => __('Languages', 'polylang'), 'singular_name' => __('Language', 'polylang'), 'all_items' => __('All languages', 'polylang')), 'public' => false, 'query_var' => 'lang', 'update_count_callback' => '_update_post_term_count'));
     // optionaly removes 'language' in permalinks so that we get http://www.myblog/en/ instead of http://www.myblog/language/en/
     // language information always in front of the uri ('with_front' => false)
     // the 3rd parameter structure has been modified in WP 3.4
     add_permastruct('language', $options['rewrite'] ? '%language%' : 'language/%language%', version_compare($GLOBALS['wp_version'], '3.4', '<') ? false : array('with_front' => false));
 }