本文整理汇总了PHP中get_post_stati函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_stati函数的具体用法?PHP get_post_stati怎么用?PHP get_post_stati使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_stati函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tally_term_counts
public static function tally_term_counts(&$terms, $taxonomy, $args = array())
{
global $wpdb, $pp_current_user;
if (!$terms) {
return;
}
$defaults = array('pad_counts' => true, 'post_type' => '', 'required_operation' => '');
$args = array_merge($defaults, (array) $args);
extract($args);
$term_items = array();
if ($terms) {
if (!is_object(reset($terms))) {
return $terms;
}
foreach ((array) $terms as $key => $term) {
$terms_by_id[$term->term_id] =& $terms[$key];
$term_ids[$term->term_taxonomy_id] = $term->term_id;
}
}
// Get the object and term ids and stick them in a lookup table
$tax_obj = get_taxonomy($taxonomy);
$object_types = $post_type ? (array) $post_type : (array) esc_sql($tax_obj->object_type);
if (pp_unfiltered()) {
$stati = get_post_stati(array('public' => true, 'private' => true), 'names', 'or');
$type_status_clause = "AND post_type IN ('" . implode("', '", $object_types) . "') AND post_status IN ('" . implode("', '", $stati) . "')";
} else {
global $query_interceptor;
$type_status_clause = $query_interceptor->get_posts_where(array('post_types' => $object_types, 'required_operation' => $required_operation));
// need to apply term restrictions in case post is restricted by another taxonomy
}
if (!$required_operation) {
$required_operation = pp_is_front() && !is_preview() ? 'read' : 'edit';
}
$results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM {$wpdb->term_relationships} INNER JOIN {$wpdb->posts} ON object_id = ID WHERE term_taxonomy_id IN ('" . implode("','", array_keys($term_ids)) . "') {$type_status_clause}");
foreach ($results as $row) {
$id = $term_ids[$row->term_taxonomy_id];
$term_items[$id][$row->object_id] = isset($term_items[$id][$row->object_id]) ? ++$term_items[$id][$row->object_id] : 1;
}
// Touch every ancestor's lookup row for each post in each term
foreach ($term_ids as $term_id) {
$child = $term_id;
while (!empty($terms_by_id[$child]) && ($parent = $terms_by_id[$child]->parent)) {
if (!empty($term_items[$term_id])) {
foreach ($term_items[$term_id] as $item_id => $touches) {
$term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id] : 1;
}
}
$child = $parent;
}
}
foreach (array_keys($terms_by_id) as $key) {
$terms_by_id[$key]->count = 0;
}
// Transfer the touched cells
foreach ((array) $term_items as $id => $items) {
if (isset($terms_by_id[$id])) {
$terms_by_id[$id]->count = count($items);
}
}
}
示例2: test__unregister_post_status
public function test__unregister_post_status()
{
register_post_status('foo');
_unregister_post_status('foo');
$stati = get_post_stati();
$this->assertFalse(isset($stati['foo']));
}
示例3: get_views
function get_views()
{
$status_links = array();
$num_posts = wp_count_posts(self::$post_type, 'readable');
$allposts = '';
$total_posts = array_sum((array) $num_posts);
// Subtract post types that are not included in the admin all list.
foreach (get_post_stati(array('show_in_admin_all_list' => false)) as $state) {
$total_posts -= $num_posts->{$state};
}
$class = empty($_REQUEST['post_status']) ? ' class="current"' : '';
$status_links['all'] = "<a href='edit.php?post_type=sa_invoice&page=sprout-apps/invoice_payments{$allposts}'{$class}>" . sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts'), number_format_i18n($total_posts)) . '</a>';
foreach (get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status) {
$class = '';
$status_name = $status->name;
if (empty($num_posts->{$status_name})) {
continue;
}
if (isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status']) {
$class = ' class="current"';
}
// replace "Published" with "Complete".
$label = str_replace('Published', 'Complete', translate_nooped_plural($status->label_count, $num_posts->{$status_name}));
$status_links[$status_name] = "<a href='edit.php?post_type=sa_invoice&page=sprout-apps/invoice_payments&post_status={$status_name}'{$class}>" . sprintf($label, number_format_i18n($num_posts->{$status_name})) . '</a>';
}
return $status_links;
}
示例4: us_ajax_blog
function us_ajax_blog()
{
// Filtering $template_vars, as is will be extracted to the template as local variables
$template_vars = shortcode_atts(array('query_args' => array(), 'layout_type' => 'large', 'metas' => array(), 'content_type' => 'none', 'show_read_more' => FALSE, 'pagination' => 'regular', 'el_class' => ''), us_maybe_get_post_json('template_vars'));
// Filtering query_args
if (isset($template_vars['query_args']) and is_array($template_vars['query_args'])) {
// Query Args keys, that won't be filtered
$allowed_query_keys = array('category_name', 'year', 'monthnum', 'day', 'tag', 's', 'paged', 'orderby', 'posts_per_page', 'post_type');
foreach ($template_vars['query_args'] as $query_key => $query_val) {
if (!in_array($query_key, $allowed_query_keys)) {
unset($template_vars['query_args'][$query_key]);
}
}
if (!isset($template_vars['query_args']['s']) and !isset($template_vars['post_type'])) {
$template_vars['query_args']['post_type'] = 'post';
}
// Providing proper post statuses
$template_vars['query_args']['post_status'] = array('publish' => 'publish');
$template_vars['query_args']['post_status'] += (array) get_post_stati(array('public' => TRUE));
// Add private states if user is capable to view them
if (is_user_logged_in() and current_user_can('read_private_posts')) {
$template_vars['query_args']['post_status'] += (array) get_post_stati(array('private' => TRUE));
}
$template_vars['query_args']['post_status'] = array_values($template_vars['query_args']['post_status']);
}
// Passing values that were filtered due to post protocol
us_load_template('templates/blog/listing', $template_vars);
// We don't use JSON to reduce data size
die;
}
示例5: post_status
public function post_status($haystack = array('draft', 'publish', 'private'))
{
if (empty($haystack)) {
$haystack = array_values(get_post_stati());
}
return $this->generator->randomElement((array) $haystack);
}
示例6: stats_load
function stats_load()
{
global $wp_roles;
Jetpack::enable_module_configurable(__FILE__);
Jetpack::module_configuration_load(__FILE__, 'stats_configuration_load');
Jetpack::module_configuration_head(__FILE__, 'stats_configuration_head');
Jetpack::module_configuration_screen(__FILE__, 'stats_configuration_screen');
// Tell HQ about changed posts
$post_stati = get_post_stati(array('public' => true));
// All public post stati
$post_stati[] = 'private';
// Content from private stati will be redacted
Jetpack_Sync::sync_posts(__FILE__, array('post_types' => get_post_types(array('public' => true)), 'post_stati' => $post_stati));
// Generate the tracking code after wp() has queried for posts.
add_action('template_redirect', 'stats_template_redirect', 1);
add_action('wp_head', 'stats_admin_bar_head', 100);
add_action('wp_head', 'stats_hide_smile_css');
add_action('jetpack_admin_menu', 'stats_admin_menu');
// Map stats caps
add_filter('map_meta_cap', 'stats_map_meta_caps', 10, 4);
if (isset($_GET['oldwidget'])) {
// Old one.
add_action('wp_dashboard_setup', 'stats_register_dashboard_widget');
} else {
add_action('admin_init', 'stats_merged_widget_admin_init');
}
add_filter('jetpack_xmlrpc_methods', 'stats_xmlrpc_methods');
add_filter('pre_option_db_version', 'stats_ignore_db_version');
}
示例7: countPosts
/**
* Counts the posts of the specified post type.
*
* This is another version of wp_count_posts() without a filter.
*
* @since 2.0.0
*/
public static function countPosts($strPostType, $perm = '')
{
global $wpdb;
if (!post_type_exists($strPostType)) {
return new stdClass();
}
$oUser = wp_get_current_user();
$cache_key = 'posts-' . $strPostType;
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
if ('readable' == $perm && is_user_logged_in()) {
$post_type_object = get_post_type_object($strPostType);
if (!current_user_can($post_type_object->cap->read_private_posts)) {
$cache_key .= '_' . $perm . '_' . $oUser->ID;
$query .= " AND (post_status != 'private' OR ( post_author = '{$oUser->ID}' AND post_status = 'private' ))";
}
}
$query .= ' GROUP BY post_status';
$oCount = wp_cache_get($cache_key, 'counts');
if (false === $oCount) {
$results = (array) $wpdb->get_results($wpdb->prepare($query, $strPostType), ARRAY_A);
$oCount = array_fill_keys(get_post_stati(), 0);
foreach ($results as $row) {
$oCount[$row['post_status']] = $row['num_posts'];
}
$oCount = (object) $oCount;
wp_cache_set($cache_key, $oCount, 'counts');
}
return $oCount;
}
示例8: Relevanssi_Search_Filter_RS
function Relevanssi_Search_Filter_RS()
{
$this->valid_stati = array_merge(get_post_stati(array('public' => true)), get_post_stati(array('private' => true)));
remove_filter('relevanssi_post_ok', 'relevanssi_default_post_ok');
add_filter('relevanssi_post_ok', array(&$this, 'relevanssi_post_ok'));
add_filter('relevanssi_results', array(&$this, 'relevanssi_log_results'));
}
示例9: get_reqd_caps
function get_reqd_caps()
{
$reqd_caps = array();
$generic_uri = in_array($GLOBALS['pagenow'], array('index.php', 'comments.php'));
if (!$generic_uri && ($_post_type = cr_find_post_type('', false))) {
// arg: don't return 'post' as default if detection fails
$post_types = array($_post_type => get_post_type_object($_post_type));
} else {
$post_types = array_diff_key(get_post_types(array('public' => true), 'object'), array('attachment' => true));
}
$use_post_types = scoper_get_option('use_post_types');
$post_statuses = get_post_stati(array('internal' => null), 'object');
foreach ($post_types as $_post_type => $type_obj) {
if (empty($use_post_types[$_post_type])) {
continue;
}
foreach ($post_statuses as $status => $status_obj) {
$reqd_caps[$_post_type][$status] = array($type_obj->cap->edit_others_posts);
if (scoper_get_option('require_moderate_comments_cap')) {
$reqd_caps[$_post_type][$status][] = 'moderate_comments';
}
if ($status_obj->private) {
$reqd_caps[$_post_type][$status][] = $type_obj->cap->edit_private_posts;
}
if ($status_obj->public || 'future' == $status) {
$reqd_caps[$_post_type][$status][] = $type_obj->cap->edit_published_posts;
}
}
}
return $reqd_caps;
}
示例10: break_remaining_events_from_series
/**
* @param int $first_event_of_new_series The post ID of the first event of the new series
*
* @return void
*/
public function break_remaining_events_from_series($first_event_of_new_series)
{
$post = get_post($first_event_of_new_series);
$parent_id = $post->post_parent;
if (empty($parent_id)) {
return;
}
$children = get_posts(array('post_type' => Tribe__Events__Main::POSTTYPE, 'post_parent' => $parent_id, 'post_status' => get_post_stati(), 'meta_key' => '_EventStartDate', 'orderby' => 'meta_key', 'order' => 'ASC', 'fields' => 'ids', 'posts_per_page' => -1));
$children_to_move_to_new_series = array();
$break_date = get_post_meta($first_event_of_new_series, '_EventStartDate', true);
foreach ($children as $child_id) {
$child_date = get_post_meta($child_id, '_EventStartDate', true);
if ($child_date > $break_date) {
$children_to_move_to_new_series[$child_id] = $child_date;
}
}
$this->copy_post_meta($parent_id, $first_event_of_new_series);
$parent_recurrence = get_post_meta($parent_id, '_EventRecurrence', true);
$new_recurrence = get_post_meta($first_event_of_new_series, '_EventRecurrence', true);
$recurrences = Tribe__Events__Pro__Recurrence__Meta::get_recurrence_for_event($parent_id);
$earliest_date = strtotime(Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_earliest_date());
$latest_date = strtotime(Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_latest_date());
$child_movements_by_rule = array();
foreach ($parent_recurrence['rules'] as $rule_key => $rule) {
if (empty($recurrences['rules'][$rule_key])) {
continue;
}
$child_movements_by_rule[$rule_key] = 0;
$recurrences['rules'][$rule_key]->setMinDate($earliest_date);
$recurrences['rules'][$rule_key]->setMaxDate($latest_date);
$dates = $recurrences['rules'][$rule_key]->getDates();
// count the number of child events that are in this rule that are being moved
foreach ($children_to_move_to_new_series as $child_id => $child_date) {
$child_movements_by_rule[$rule_key] += (int) in_array($child_date, $dates);
}
if ('After' === $rule['end-type']) {
$parent_recurrence['rules'][$rule_key]['end-count'] -= $child_movements_by_rule[$rule_key] + 1;
$new_recurrence['rules'][$rule_key]['end-count'] = $child_movements_by_rule[$rule_key] + 1;
} else {
$parent_recurrence['rules'][$rule_key]['end'] = date('Y-m-d', strtotime($break_date));
}
}
update_post_meta($parent_id, '_EventRecurrence', $parent_recurrence);
update_post_meta($first_event_of_new_series, '_EventRecurrence', $new_recurrence);
add_post_meta($first_event_of_new_series, '_EventOriginalParent', $parent_id);
if (count($children) - count($children_to_move_to_new_series) == 1) {
delete_post_meta($parent_id, '_EventRecurrence');
}
$new_parent = get_post($first_event_of_new_series);
$new_parent->post_parent = 0;
$new_parent->comment_count = 0;
wp_update_post($new_parent);
foreach ($children_to_move_to_new_series as $child_id => $child_date) {
$child = get_post($child_id);
$child->post_parent = $first_event_of_new_series;
$child->comment_count = 0;
wp_update_post($child);
}
}
示例11: test_all_public_post_stati_should_be_included_when_no_post_status_is_provided
public function test_all_public_post_stati_should_be_included_when_no_post_status_is_provided()
{
register_post_status('foo', array('public' => true));
$q = new WP_Query(array('posts_per_page' => 1));
foreach (get_post_stati(array('public' => true)) as $status) {
$this->assertContains("post_status = '{$status}'", $q->request);
}
}
示例12: test_get_items
public function test_get_items()
{
$request = new WP_REST_Request('GET', '/wp/v2/statuses');
$response = $this->server->dispatch($request);
$data = $response->get_data();
$statuses = get_post_stati(array('public' => true), 'objects');
$this->assertEquals(1, count($data));
$this->assertEquals('publish', $data['publish']['slug']);
}
示例13: setup_post_status
public function setup_post_status()
{
if (isset($this->post_status) or empty($this->post_type)) {
return;
}
$args = array('private' => false, 'internal' => false, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true);
current_user_can(get_post_type_object($this->post_type)->cap->read_private_posts) and $args['private'] = true;
$this->post_status = get_post_stati($args);
}
示例14: get_views
function get_views()
{
$status_links = array();
$num_posts = wp_count_posts(self::$storage_post_type, 'readable');
$entries_stati = get_post_stati(array('show_in_admin_status_list' => true), 'objects');
$view_link = add_query_arg(array('page' => 'cf7_storage'), admin_url('admin.php'));
$status_links['all'] = sprintf('<a href="%s">%s <span class="count">(%d)</span></a>', $view_link, esc_html__('All', 'cf7-storage'), $num_posts->publish);
$status_links['trash'] = sprintf('<a href="%s" %s>%s</a>', add_query_arg('post_status', 'trash', $view_link), $this->is_trash ? 'class="current"' : null, sprintf(translate_nooped_plural($entries_stati['trash']->label_count, $num_posts->trash), number_format_i18n($num_posts->trash)));
return $status_links;
}
示例15: current_user_can_read
public function current_user_can_read($post_id)
{
$post = get_post($post_id);
if (in_array($post->post_status, get_post_stati(array('public' => true)))) {
return true;
}
$post_type_object = get_post_type_object($post->post_type);
$user = wp_get_current_user();
return is_user_logged_in() && (current_user_can($post_type_object->cap->read_private_posts) || $user->ID == $post->post_author);
}