当前位置: 首页>>代码示例>>PHP>>正文


PHP is_post_type_viewable函数代码示例

本文整理汇总了PHP中is_post_type_viewable函数的典型用法代码示例。如果您正苦于以下问题:PHP is_post_type_viewable函数的具体用法?PHP is_post_type_viewable怎么用?PHP is_post_type_viewable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了is_post_type_viewable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register_post_type


//.........这里部分代码省略.........
    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) {
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:67,代码来源:post.php

示例2: handle_row_actions

 /**
  * Generates and displays row action links.
  *
  * @since 4.3.0
  * @access protected
  *
  * @param object $post        Post being acted upon.
  * @param string $column_name Current column name.
  * @param string $primary     Primary column name.
  * @return string Row actions output for posts.
  */
 protected function handle_row_actions($post, $column_name, $primary)
 {
     if ($primary !== $column_name) {
         return '';
     }
     $post_type_object = get_post_type_object($post->post_type);
     $can_edit_post = current_user_can('edit_post', $post->ID);
     $actions = array();
     if ($can_edit_post && 'trash' != $post->post_status) {
         $actions['edit'] = '<a href="' . get_edit_post_link($post->ID) . '" title="' . esc_attr__('Edit this item') . '">' . __('Edit') . '</a>';
         $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr__('Edit this item inline') . '">' . __('Quick&nbsp;Edit') . '</a>';
     }
     if (current_user_can('delete_post', $post->ID)) {
         if ('trash' == $post->post_status) {
             $actions['untrash'] = "<a title='" . esc_attr__('Restore this item from the Trash') . "' href='" . wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&amp;action=untrash', $post->ID)), 'untrash-post_' . $post->ID) . "'>" . __('Restore') . "</a>";
         } elseif (EMPTY_TRASH_DAYS) {
             $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__('Move this item to the Trash') . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash') . "</a>";
         }
         if ('trash' == $post->post_status || !EMPTY_TRASH_DAYS) {
             $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__('Delete this item permanently') . "' href='" . get_delete_post_link($post->ID, '', true) . "'>" . __('Delete Permanently') . "</a>";
         }
     }
     if (is_post_type_viewable($post_type_object)) {
         $title = _draft_or_post_title();
         if (in_array($post->post_status, array('pending', 'draft', 'future'))) {
             if ($can_edit_post) {
                 $preview_link = set_url_scheme(get_permalink($post->ID));
                 /** This filter is documented in wp-admin/includes/meta-boxes.php */
                 $preview_link = apply_filters('preview_post_link', add_query_arg('preview', 'true', $preview_link), $post);
                 $actions['view'] = '<a href="' . esc_url($preview_link) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
             }
         } elseif ('trash' != $post->post_status) {
             $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
         }
     }
     if (is_post_type_hierarchical($post->post_type)) {
         /**
          * Filter the array of row action links on the Pages list table.
          *
          * The filter is evaluated only for hierarchical post types.
          *
          * @since 2.8.0
          *
          * @param array $actions An array of row action links. Defaults are
          *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
          *                         'Delete Permanently', 'Preview', and 'View'.
          * @param WP_Post $post The post object.
          */
         $actions = apply_filters('page_row_actions', $actions, $post);
     } else {
         /**
          * Filter the array of row action links on the Posts list table.
          *
          * The filter is evaluated only for non-hierarchical post types.
          *
          * @since 2.8.0
          *
          * @param array $actions An array of row action links. Defaults are
          *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
          *                         'Delete Permanently', 'Preview', and 'View'.
          * @param WP_Post $post The post object.
          */
         $actions = apply_filters('post_row_actions', $actions, $post);
     }
     return $this->row_actions($actions);
 }
开发者ID:rlgod,项目名称:WordPress,代码行数:77,代码来源:class-wp-posts-list-table.php

示例3: handle_row_actions

 /**
  * Generates and displays row action links.
  *
  * @since 4.3.0
  * @access protected
  *
  * @param object $post        Post being acted upon.
  * @param string $column_name Current column name.
  * @param string $primary     Primary column name.
  * @return string Row actions output for posts.
  */
 protected function handle_row_actions($post, $column_name, $primary)
 {
     if ($primary !== $column_name) {
         return '';
     }
     $post_type_object = get_post_type_object($post->post_type);
     $can_edit_post = current_user_can('edit_post', $post->ID);
     $actions = array();
     $title = _draft_or_post_title();
     if ($can_edit_post && 'trash' != $post->post_status) {
         $actions['edit'] = sprintf('<a href="%s" aria-label="%s">%s</a>', get_edit_post_link($post->ID), esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)), __('Edit'));
         $actions['inline hide-if-no-js'] = sprintf('<a href="#" class="editinline" aria-label="%s">%s</a>', esc_attr(sprintf(__('Quick edit &#8220;%s&#8221; inline'), $title)), __('Quick&nbsp;Edit'));
     }
     if (current_user_can('delete_post', $post->ID)) {
         if ('trash' === $post->post_status) {
             $actions['untrash'] = sprintf('<a href="%s" aria-label="%s">%s</a>', wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&amp;action=untrash', $post->ID)), 'untrash-post_' . $post->ID), esc_attr(sprintf(__('Restore &#8220;%s&#8221; from the Trash'), $title)), __('Restore'));
         } elseif (EMPTY_TRASH_DAYS) {
             $actions['trash'] = sprintf('<a href="%s" class="submitdelete" aria-label="%s">%s</a>', get_delete_post_link($post->ID), esc_attr(sprintf(__('Move &#8220;%s&#8221; to the Trash'), $title)), _x('Trash', 'verb'));
         }
         if ('trash' === $post->post_status || !EMPTY_TRASH_DAYS) {
             $actions['delete'] = sprintf('<a href="%s" class="submitdelete" aria-label="%s">%s</a>', get_delete_post_link($post->ID, '', true), esc_attr(sprintf(__('Delete &#8220;%s&#8221; permanently'), $title)), __('Delete Permanently'));
         }
     }
     if (is_post_type_viewable($post_type_object)) {
         if (in_array($post->post_status, array('pending', 'draft', 'future'))) {
             if ($can_edit_post) {
                 $unpublished_link = set_url_scheme(get_permalink($post));
                 $preview_link = get_preview_post_link($post, array(), $unpublished_link);
                 $actions['view'] = sprintf('<a href="%s" rel="permalink" aria-label="%s">%s</a>', esc_url($preview_link), esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)), __('Preview'));
             }
         } elseif ('trash' != $post->post_status) {
             $actions['view'] = sprintf('<a href="%s" rel="permalink" aria-label="%s">%s</a>', get_permalink($post->ID), esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)), __('View'));
         }
     }
     if (is_post_type_hierarchical($post->post_type)) {
         /**
          * Filter the array of row action links on the Pages list table.
          *
          * The filter is evaluated only for hierarchical post types.
          *
          * @since 2.8.0
          *
          * @param array $actions An array of row action links. Defaults are
          *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
          *                         'Delete Permanently', 'Preview', and 'View'.
          * @param WP_Post $post The post object.
          */
         $actions = apply_filters('page_row_actions', $actions, $post);
     } else {
         /**
          * Filter the array of row action links on the Posts list table.
          *
          * The filter is evaluated only for non-hierarchical post types.
          *
          * @since 2.8.0
          *
          * @param array $actions An array of row action links. Defaults are
          *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
          *                         'Delete Permanently', 'Preview', and 'View'.
          * @param WP_Post $post The post object.
          */
         $actions = apply_filters('post_row_actions', $actions, $post);
     }
     return $this->row_actions($actions);
 }
开发者ID:dd32,项目名称:wordpress.develop,代码行数:76,代码来源:class-wp-posts-list-table.php

示例4: get_preview_post_link

/**
 * Retrieve URL used for the post preview.
 *
 * Get the preview post URL. Allows additional query args to be appended.
 *
 * @since 4.4.0
 *
 * @param int|WP_Post $post         Optional. Post ID or `WP_Post` object. Defaults to global post.
 * @param array       $query_args   Optional. Array of additional query args to be appended to the link.
 * @param string      $preview_link Optional. Base preview link to be used if it should differ from the post permalink.
 * @return string URL used for the post preview.
 */
function get_preview_post_link($post = null, $query_args = array(), $preview_link = '')
{
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (is_post_type_viewable($post_type_object)) {
        if (!$preview_link) {
            $preview_link = get_permalink($post);
        }
        $query_args['preview'] = 'true';
        $preview_link = add_query_arg($query_args, $preview_link);
    }
    /**
     * Filter the URL used for a post preview.
     *
     * @since 2.0.5
     * @since 4.0.0 Added the `$post` parameter.
     *
     * @param string  $preview_link URL used for the post preview.
     * @param WP_Post $post         Post object.
     */
    return apply_filters('preview_post_link', $preview_link, $post);
}
开发者ID:gigikiri,项目名称:WordPress,代码行数:37,代码来源:link-template.php

示例5: wp_enqueue_media

    wp_enqueue_media(array('post' => $post_ID));
}
// Add the local autosave notice HTML
add_action('admin_footer', '_local_storage_notice');
/*
 * @todo Document the $messages array(s).
 */
$permalink = get_permalink($post_ID);
if (!$permalink) {
    $permalink = '';
}
$messages = array();
$preview_post_link_html = $scheduled_post_link_html = $view_post_link_html = '';
$preview_page_link_html = $scheduled_page_link_html = $view_page_link_html = '';
$preview_url = get_preview_post_link($post);
$viewable = is_post_type_viewable($post_type_object);
if ($viewable) {
    // Preview post link.
    $preview_post_link_html = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($preview_url), __('Preview post'));
    // Scheduled post preview link.
    $scheduled_post_link_html = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($permalink), __('Preview post'));
    // View post link.
    $view_post_link_html = sprintf(' <a href="%1$s">%2$s</a>', esc_url($permalink), __('View post'));
    // Preview page link.
    $preview_page_link_html = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($preview_url), __('Preview page'));
    // Scheduled page preview link.
    $scheduled_page_link_html = sprintf(' <a target="_blank" href="%1$s">%2$s</a>', esc_url($permalink), __('Preview page'));
    // View page link.
    $view_page_link_html = sprintf(' <a href="%1$s">%2$s</a>', esc_url($permalink), __('View page'));
}
/* translators: Publish box date format, see https://secure.php.net/date */
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:31,代码来源:edit-form-advanced.php

示例6: post_submit_meta_box

/**
 * Displays post submit form fields.
 *
 * @since 2.7.0
 *
 * @global string $action
 *
 * @param WP_Post  $post Current post object.
 * @param array    $args {
 *     Array of arguments for building the post submit meta box.
 *
 *     @type string   $id       Meta box ID.
 *     @type string   $title    Meta box title.
 *     @type callable $callback Meta box display callback.
 *     @type array    $args     Extra meta box arguments.
 * }
 */
function post_submit_meta_box($post, $args = array())
{
    global $action;
    $post_type = $post->post_type;
    $post_type_object = get_post_type_object($post_type);
    $can_publish = current_user_can($post_type_object->cap->publish_posts);
    ?>
<div class="submitbox" id="submitpost">

<div id="minor-publishing">

<?php 
    // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key
    ?>
<div style="display:none;">
<?php 
    submit_button(__('Save'), 'button', 'save');
    ?>
</div>

<div id="minor-publishing-actions">
<div id="save-action">
<?php 
    if ('publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status) {
        ?>
<input <?php 
        if ('private' == $post->post_status) {
            ?>
style="display:none"<?php 
        }
        ?>
 type="submit" name="save" id="save-post" value="<?php 
        esc_attr_e('Save Draft');
        ?>
" class="button" />
<span class="spinner"></span>
<?php 
    } elseif ('pending' == $post->post_status && $can_publish) {
        ?>
<input type="submit" name="save" id="save-post" value="<?php 
        esc_attr_e('Save as Pending');
        ?>
" class="button" />
<span class="spinner"></span>
<?php 
    }
    ?>
</div>
<?php 
    if (is_post_type_viewable($post_type_object)) {
        ?>
<div id="preview-action">
<?php 
        $preview_link = esc_url(get_preview_post_link($post));
        if ('publish' == $post->post_status) {
            $preview_button = __('Preview Changes');
        } else {
            $preview_button = __('Preview');
        }
        ?>
<a class="preview button" href="<?php 
        echo $preview_link;
        ?>
" target="wp-preview-<?php 
        echo (int) $post->ID;
        ?>
" id="post-preview"><?php 
        echo $preview_button;
        ?>
</a>
<input type="hidden" name="wp-preview" id="wp-preview" value="" />
</div>
<?php 
    }
    // public post type
    /**
     * Fires before the post time/date setting in the Publish meta box.
     *
     * @since 4.4.0
     *
     * @param WP_Post $post WP_Post object for the current post.
     */
    do_action('post_submitbox_minor_actions', $post);
//.........这里部分代码省略.........
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:101,代码来源:meta-boxes.php

示例7: _cleanup_query_vars

function _cleanup_query_vars()
{
    // clean out globals to stop them polluting wp and wp_query
    foreach ($GLOBALS['wp']->public_query_vars as $v) {
        unset($GLOBALS[$v]);
    }
    foreach ($GLOBALS['wp']->private_query_vars as $v) {
        unset($GLOBALS[$v]);
    }
    foreach (get_taxonomies(array(), 'objects') as $t) {
        if ($t->publicly_queryable && !empty($t->query_var)) {
            $GLOBALS['wp']->add_query_var($t->query_var);
        }
    }
    foreach (get_post_types(array(), 'objects') as $t) {
        if (is_post_type_viewable($t) && !empty($t->query_var)) {
            $GLOBALS['wp']->add_query_var($t->query_var);
        }
    }
}
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:20,代码来源:utils.php

示例8: wp_get_archives

/**
 * Display archive links based on type and format.
 *
 * @since 1.2.0
 * @since 4.4.0 $post_type arg was added.
 *
 * @see get_archives_link()
 *
 * @global wpdb      $wpdb
 * @global WP_Locale $wp_locale
 *
 * @param string|array $args {
 *     Default archive links arguments. Optional.
 *
 *     @type string     $type            Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
 *                                       'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
 *                                       display the same archive link list as well as post titles instead
 *                                       of displaying dates. The difference between the two is that 'alpha'
 *                                       will order by post title and 'postbypost' will order by post date.
 *                                       Default 'monthly'.
 *     @type string|int $limit           Number of links to limit the query to. Default empty (no limit).
 *     @type string     $format          Format each link should take using the $before and $after args.
 *                                       Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
 *                                       (`<li>` tag), or a custom format, which generates a link anchor
 *                                       with $before preceding and $after succeeding. Default 'html'.
 *     @type string     $before          Markup to prepend to the beginning of each link. Default empty.
 *     @type string     $after           Markup to append to the end of each link. Default empty.
 *     @type bool       $show_post_count Whether to display the post count alongside the link. Default false.
 *     @type bool|int   $echo            Whether to echo or return the links list. Default 1|true to echo.
 *     @type string     $order           Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
 *                                       Default 'DESC'.
 *     @type string     $post_type       Post type. Default 'post'.
 * }
 * @return string|void String when retrieving.
 */
function wp_get_archives($args = '')
{
    global $wpdb, $wp_locale;
    $defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC', 'post_type' => 'post');
    $r = wp_parse_args($args, $defaults);
    $post_type_object = get_post_type_object($r['post_type']);
    if (!is_post_type_viewable($post_type_object)) {
        return;
    }
    $r['post_type'] = $post_type_object->name;
    if ('' == $r['type']) {
        $r['type'] = 'monthly';
    }
    if (!empty($r['limit'])) {
        $r['limit'] = absint($r['limit']);
        $r['limit'] = ' LIMIT ' . $r['limit'];
    }
    $order = strtoupper($r['order']);
    if ($order !== 'ASC') {
        $order = 'DESC';
    }
    // this is what will separate dates on weekly archive links
    $archive_week_separator = '&#8211;';
    // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
    $archive_date_format_over_ride = 0;
    // options for daily archive (only if you over-ride the general date format)
    $archive_day_date_format = 'Y/m/d';
    // options for weekly archive (only if you over-ride the general date format)
    $archive_week_start_date_format = 'Y/m/d';
    $archive_week_end_date_format = 'Y/m/d';
    if (!$archive_date_format_over_ride) {
        $archive_day_date_format = get_option('date_format');
        $archive_week_start_date_format = get_option('date_format');
        $archive_week_end_date_format = get_option('date_format');
    }
    $sql_where = $wpdb->prepare("WHERE post_type = %s AND post_status = 'publish'", $r['post_type']);
    /**
     * Filter the SQL WHERE clause for retrieving archives.
     *
     * @since 2.2.0
     *
     * @param string $sql_where Portion of SQL query containing the WHERE clause.
     * @param array  $r         An array of default arguments.
     */
    $where = apply_filters('getarchives_where', $sql_where, $r);
    /**
     * Filter the SQL JOIN clause for retrieving archives.
     *
     * @since 2.2.0
     *
     * @param string $sql_join Portion of SQL query containing JOIN clause.
     * @param array  $r        An array of default arguments.
     */
    $join = apply_filters('getarchives_join', '', $r);
    $output = '';
    $last_changed = wp_cache_get('last_changed', 'posts');
    if (!$last_changed) {
        $last_changed = microtime();
        wp_cache_set('last_changed', $last_changed, 'posts');
    }
    $limit = $r['limit'];
    if ('monthly' == $r['type']) {
        $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date {$order} {$limit}";
        $key = md5($query);
        $key = "wp_get_archives:{$key}:{$last_changed}";
//.........这里部分代码省略.........
开发者ID:blogfor,项目名称:king,代码行数:101,代码来源:general-template.php

示例9: parse_request


//.........这里部分代码省略.........
             $query = preg_replace("!^.+\\?!", '', $query);
             // Substitute the substring matches into the query.
             $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
             $this->matched_query = $query;
             // Parse the query.
             parse_str($query, $perma_query_vars);
             // If we're processing a 404 request, clear the error var since we found something.
             if ('404' == $error) {
                 unset($error, $_GET['error']);
             }
         }
         // If req_uri is empty or if it is a request for ourself, unset error.
         if (empty($requested_path) || $requested_file == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
             unset($error, $_GET['error']);
             if (isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
                 unset($perma_query_vars);
             }
             $this->did_permalink = false;
         }
     }
     /**
      * Filter the query variables whitelist before processing.
      *
      * Allows (publicly allowed) query vars to be added, removed, or changed prior
      * to executing the query. Needed to allow custom rewrite rules using your own arguments
      * to work, or any other custom query variables you want to be publicly available.
      *
      * @since 1.5.0
      *
      * @param array $public_query_vars The array of whitelisted query variables.
      */
     $this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
     foreach (get_post_types(array(), 'objects') as $post_type => $t) {
         if (is_post_type_viewable($t) && $t->query_var) {
             $post_type_query_vars[$t->query_var] = $post_type;
         }
     }
     foreach ($this->public_query_vars as $wpvar) {
         if (isset($this->extra_query_vars[$wpvar])) {
             $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
         } elseif (isset($_POST[$wpvar])) {
             $this->query_vars[$wpvar] = $_POST[$wpvar];
         } elseif (isset($_GET[$wpvar])) {
             $this->query_vars[$wpvar] = $_GET[$wpvar];
         } elseif (isset($perma_query_vars[$wpvar])) {
             $this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
         }
         if (!empty($this->query_vars[$wpvar])) {
             if (!is_array($this->query_vars[$wpvar])) {
                 $this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];
             } else {
                 foreach ($this->query_vars[$wpvar] as $vkey => $v) {
                     if (!is_object($v)) {
                         $this->query_vars[$wpvar][$vkey] = (string) $v;
                     }
                 }
             }
             if (isset($post_type_query_vars[$wpvar])) {
                 $this->query_vars['post_type'] = $post_type_query_vars[$wpvar];
                 $this->query_vars['name'] = $this->query_vars[$wpvar];
             }
         }
     }
     // Convert urldecoded spaces back into +
     foreach (get_taxonomies(array(), 'objects') as $taxonomy => $t) {
         if ($t->query_var && isset($this->query_vars[$t->query_var])) {
开发者ID:qaryas,项目名称:qaryas_site,代码行数:67,代码来源:class-wp.php

示例10: test_should_return_false_for_bad_post_type_name

 /**
  * @ticket 35609
  */
 public function test_should_return_false_for_bad_post_type_name()
 {
     $this->assertFalse(is_post_type_viewable('foo'));
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:7,代码来源:isPostTypeViewable.php

示例11: get_item

 /**
  * Retrieves a single post.
  *
  * @since 4.7.0
  * @access public
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
  */
 public function get_item($request)
 {
     $id = (int) $request['id'];
     $post = get_post($id);
     if (empty($id) || empty($post->ID) || $this->post_type !== $post->post_type) {
         return new WP_Error('rest_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
     }
     $data = $this->prepare_item_for_response($post, $request);
     $response = rest_ensure_response($data);
     if (is_post_type_viewable(get_post_type_object($post->post_type))) {
         $response->link_header('alternate', get_permalink($id), array('type' => 'text/html'));
     }
     return $response;
 }
开发者ID:aaronjorbin,项目名称:wordpress.codecov,代码行数:23,代码来源:class-wp-rest-posts-controller.php

示例12: add_rewrite_rules

 /**
  * 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);
     }
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:43,代码来源:class-wp-post-type.php

示例13: get_how_long_ago

 /**
  * Get the formatted date & time for the activity
  *
  * @since 0.1.0
  *
  * @param   int  $post_id
  *
  * @return  string
  */
 protected function get_how_long_ago($post_id = 0)
 {
     // Get the post
     $post = get_post($post_id);
     $date = get_the_date(get_option('date_format'), $post->ID);
     $time = get_the_time(get_option('time_format'), $post->ID);
     $both = "{$date} {$time}";
     // Get the human readable difference
     $pt = strtotime($post->post_date_gmt);
     $human = wp_user_activity_human_diff_time($pt, current_time('timestamp', true));
     // Start with the timestamp
     $classes = get_post_class('wp-user-activity', $post->ID);
     $url = false;
     $retval = '<time class="diff-time" pubdate datetime="' . esc_attr($both) . '" title="' . esc_attr($both) . '">' . sprintf('%s ago', $human) . '</time>';
     // Edit link
     if (is_admin() && current_user_can('edit_activity', $post->ID)) {
         $classes[] = 'edit-link';
         $url = get_edit_post_link($post->ID);
         // View link
     } elseif (is_post_type_viewable(get_post_type_object($post->post_type))) {
         $classes[] = 'view-link';
         $url = get_post_permalink($post->ID);
     }
     // Wrap time in anchor tag
     if (!empty($url)) {
         $retval = '<a href="' . esc_url($url) . '" class="' . join(' ', $classes) . '">' . $retval . '</a>';
     }
     return $retval;
 }
开发者ID:stuttter,项目名称:wp-user-activity,代码行数:38,代码来源:classes.php

示例14: get_permalink

     $post->post_type = $post_type;
     $post->post_parent = $post_parent;
 }
 $post->post_status = 'publish';
 $post->post_name = $slug;
 if ($post->post_type === 'page') {
 }
 $desired_permalink = get_permalink($post);
 $parsed = parse_url($desired_permalink);
 $desired_path = trim($parsed['path'], '/');
 /*
  * Copied from $wp->parse_request(). This function seems to do a lot of housekeeping
  * which should probably be accessible if other things should be able to mock out and fake requests.
  */
 foreach (get_post_types(array(), 'objects') as $post_type => $t) {
     if (is_post_type_viewable($t) && $t->query_var) {
         $post_type_query_vars[$t->query_var] = $post_type;
     }
 }
 // Find a rewrite. Depends on #18877.
 $rewrite = $wp_rewrite->wp_rewrite_rules();
 $found_rewrite_match = $wp_rewrite->find_match($desired_path, $desired_path, $rewrite);
 if ($found_rewrite_match) {
     $query_string = $found_rewrite_match[1];
     parse_str($query_string, $query_args);
     foreach ($wp->public_query_vars as $wpvar) {
         if (!empty($query_args[$wpvar])) {
             if (isset($post_type_query_vars[$wpvar])) {
                 $query_args['post_type'] = $post_type_query_vars[$wpvar];
                 $query_args['name'] = $query_args[$wpvar];
                 // Unset the `{post_type_name}` query variable, as the `name` qv will suffice.
开发者ID:ericandrewlewis,项目名称:wp-cool-slugs,代码行数:31,代码来源:index.php

示例15: queue_post_purge

 public function queue_post_purge($post_id)
 {
     if ($this->site_cache_purged) {
         return false;
     }
     if (defined('WP_IMPORTING')) {
         $this->purge_site_cache();
         return false;
     }
     $post = get_post($post_id);
     if (empty($post) || 'revision' === $post->post_type || !in_array(get_post_status($post_id), array('publish', 'inherit', 'trash'), true)) {
         return false;
     }
     if (!is_post_type_viewable($post->post_type)) {
         return;
     }
     $post_purge_urls = array();
     $post_purge_urls[] = get_permalink($post_id);
     $post_purge_urls[] = home_url('/');
     // Don't just purge the attachment page, but also include the file itself
     if ('attachment' === $post->post_type) {
         $this->purge_urls[] = wp_get_attachment_url($post_id);
     }
     $taxonomies = get_object_taxonomies($post, 'object');
     foreach ($taxonomies as $taxonomy) {
         if (true !== $taxonomy->public) {
             continue;
         }
         $taxonomy_name = $taxonomy->name;
         $terms = get_the_terms($post_id, $taxonomy_name);
         if (false === $terms) {
             continue;
         }
         foreach ($terms as $term) {
             $post_purge_urls = array_merge($post_purge_urls, $this->get_purge_urls_for_term($term));
         }
     }
     // Purge the standard site feeds
     // @TODO Do we need to PURGE the comment feeds if the post_status is publish?
     $site_feeds = array(get_bloginfo('rdf_url'), get_bloginfo('rss_url'), get_bloginfo('rss2_url'), get_bloginfo('atom_url'), get_bloginfo('comments_atom_url'), get_bloginfo('comments_rss2_url'), get_post_comments_feed_link($post_id));
     $post_purge_urls = array_merge($post_purge_urls, $site_feeds);
     /**
      * Allows adding URLs to be PURGEd from cache when a given post ID is PURGEd
      *
      * Developers can hook this filter and check the post being purged in order
      * to also purge related URLs, e.g. feeds.
      *
      * Related category archives, tag archives, generic feeds, etc, are already
      * included to be purged (see code above).
      *
      * PLEASE NOTE: Your site benefits from the performance that our HTTP
      * Reverse Proxy Caching provides, and purging URLs from that cache
      * should be done cautiously. VIP may push back on use of this filter
      * during initial code review and pre-deployment review where we
      * see issues.
      *
      * @deprecated 1.1 Use `wpcom_vip_cache_purge_{post_type}_urls` instead
      * @param array $this->purge_urls {
      *     An array of URLs for you to add to
      * }
      * @param type  $post_id The ID of the post which is the primary reason for the purge
      */
     $post_purge_urls = apply_filters('wpcom_vip_cache_purge_urls', $post_purge_urls, $post_id);
     $this->purge_urls = array_merge($this->purge_urls, $post_purge_urls);
     /**
      * Allows adding URLs to be PURGEd from cache when a given post ID is PURGEd
      *
      * Developers can hook this filter and check the post being purged in order
      * to also purge related URLs, e.g. feeds.
      *
      * Related category archives, tag archives, generic feeds, etc, are already
      * included to be purged (see code above).
      *
      * PLEASE NOTE: Your site benefits from the performance that our HTTP
      * Reverse Proxy Caching provides, and purging URLs from that cache
      * should be done cautiously. VIP may push back on use of this filter
      * during initial code review and pre-deployment review where we
      * see issues.
      *
      * @param array $this->purge_urls {
      *     An array of URLs for you to add to
      * }
      * @param type  $post_id The ID of the post which is the primary reason for the purge
      */
     $this->purge_urls = apply_filters("wpcom_vip_cache_purge_{$post->post_type}_post_urls", $this->purge_urls, $post_id);
     $this->purge_urls = array_unique($this->purge_urls);
     return true;
 }
开发者ID:Automattic,项目名称:vip-mu-plugins-public,代码行数:88,代码来源:vip-cache-manager.php


注:本文中的is_post_type_viewable函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。