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); } } }
public function test__unregister_post_status() { register_post_status('foo'); _unregister_post_status('foo'); $stati = get_post_stati(); $this->assertFalse(isset($stati['foo'])); }
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; }
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; }
public function post_status($haystack = array('draft', 'publish', 'private')) { if (empty($haystack)) { $haystack = array_values(get_post_stati()); } return $this->generator->randomElement((array) $haystack); }
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'); }
/** * 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; }
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')); }
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; }
/** * @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); } }
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); } }
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']); }
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); }
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; }
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); }
public function get_statuses() { if (empty($this->statuses)) { $stati = get_post_stati(array('internal' => 0), 'objects'); foreach ($stati as $k => $status) { $this->statuses[$k] = $status->label; } } return $this->statuses; }
public static function flt_comments_clauses($clauses, &$qry_obj) { global $wpdb; $stati = get_post_stati(array('public' => true, 'private' => true), 'names', 'or'); if (!defined('PP_NO_ATTACHMENT_COMMENTS')) { $stati[] = 'inherit'; } $status_csv = "'" . implode("','", $stati) . "'"; $clauses['where'] = preg_replace("/\\s*AND\\s*{$wpdb->posts}.post_status\\s*=\\s*[']?publish[']?/", "AND {$wpdb->posts}.post_status IN ({$status_csv})", $clauses['where']); return $clauses; }
/** * * @global object $wpdb * */ function get_core_info() { global $wpdb; $jquery_ver = __('n/a', 'wpv-views'); if (wp_script_is('jquery', 'registered')) { $reg_scripts = $GLOBALS['wp_scripts']->registered; $jquery_ver = $reg_scripts['jquery']->ver; } $core = array('Wordpress' => array('Multisite' => is_multisite() ? 'Yes' : 'No', 'SiteURL' => site_url(), 'HomeURL' => home_url(), 'Version' => get_bloginfo('version'), 'PermalinkStructure' => get_option('permalink_structure'), 'PostTypes' => implode(', ', get_post_types('', 'names')), 'PostSatus' => implode(', ', get_post_stati())), 'Server' => array('jQueryVersion' => $jquery_ver, 'PHPVersion' => phpversion(), 'MySQLVersion' => $wpdb->db_version(), 'ServerSoftware' => $_SERVER['SERVER_SOFTWARE']), 'PHP' => array('MemoryLimit' => ini_get('memory_limit'), 'UploadMax' => ini_get('upload_max_filesize'), 'PostMax' => ini_get('post_max_size'), 'TimeLimit' => ini_get('max_execution_time'), 'MaxInputVars' => ini_get('max_input_vars'))); return $core; }
/** * Post status change * * @param string $new_status The new status of the post * @param string $old_status The old statud of the post * @param WP_Post $post The WP_Post object * @return null */ function post_status_change($new_status, $old_status, $post) { $post_statuses = get_post_stati(); $hook_settings = gnt_get_hook_settings(); foreach ($post_statuses as $post_status) { if (isset($hook_settings['post_status_' . $post_status . '-enable']) && $hook_settings['post_status_' . $post_status . '-enable']) { if ($old_status !== $post_status && $new_status === $post_status) { do_action('gnt_hook_post_status_' . $post_status, array('hook' => 'post_' . $post_status, 'text' => $post->post_title . __(' changed status to ', 'get-notified') . $post_status, 'post' => $post, 'post_status' => $post_status)); } } } }
protected function sanitize_request() { $request_data = parent::sanitize_request(); $this->post_type = $request_data['req_ptype'] ? $request_data['req_ptype'] : 'post'; $post_statuses = array_keys(get_post_stati()); $post_status = get_query_var('post_status'); if (is_string($post_status)) { $post_status = $post_status ? array($post_status) : array(); } $illegal_status = array_diff($post_status, $post_statuses); $this->post_status = array_diff($post_status, $illegal_status); }
function Relevanssi_Search_Filter_RS() { $this->valid_stati = array_merge(get_post_stati(array('public' => true)), get_post_stati(array('private' => true))); if (!empty($GLOBALS['relevanssi_variables']) || !empty($GLOBALS['relevanssi_free_plugin_version']) || !empty($GLOBALS['relevanssi_plugin_version'])) { remove_filter('relevanssi_post_ok', 'relevanssi_default_post_ok', 10, 2); add_filter('relevanssi_post_ok', array(&$this, 'relevanssi_post_ok'), 10, 2); } else { remove_filter('relevanssi_post_ok', 'relevanssi_default_post_ok'); add_filter('relevanssi_post_ok', array(&$this, 'relevanssi_post_ok_legacy')); } add_filter('relevanssi_results', array(&$this, 'relevanssi_log_results')); }
function flt_comments_clauses($clauses, &$qry_obj) { global $wpdb; if (is_content_administrator_rs()) { $stati = array_merge(get_post_stati(array('public' => true)), get_post_stati(array('private' => true))); if (!defined('SCOPER_NO_ATTACHMENT_COMMENTS')) { $stati[] = 'inherit'; } $status_csv = "'" . implode("','", $stati) . "'"; $clauses['where'] = preg_replace("/\\s*AND\\s*{$wpdb->posts}.post_status\\s*=\\s*[']?publish[']?/", "AND {$wpdb->posts}.post_status IN ({$status_csv})", $clauses['where']); } return $clauses; }
public function test_get_items_logged_in() { $user_id = $this->factory->user->create(); wp_set_current_user($user_id); $request = new WP_REST_Request('GET', '/wp/v2/statuses'); $response = $this->server->dispatch($request); $data = $response->get_data(); $statuses = get_post_stati(array('internal' => false), 'objects'); $this->assertEquals(5, count($data)); // Check each key in $data against those in $statuses foreach ($data as $obj) { $this->check_post_status_obj($statuses[$obj['slug']], $obj); } }
function get_views() { global $post_type_object, $locked_post_status, $avail_post_stati; $post_type = $post_type_object->name; if (!empty($locked_post_status)) { return array(); } $status_links = array(); $num_posts = wp_count_posts($post_type, 'readable'); $class = ''; $allposts = ''; $current_user_id = get_current_user_id(); if ($this->user_posts_count) { if (isset($_GET['author']) && $_GET['author'] == $current_user_id) { $class = ' class="current"'; } $status_links['mine'] = "<a href='edit.php?post_type={$post_type}&author={$current_user_id}'{$class}>" . sprintf(_nx('Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts'), number_format_i18n($this->user_posts_count)) . '</a>'; $allposts = '&all_posts=1'; } $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($class) && empty($_REQUEST['post_status']) && empty($_REQUEST['show_sticky']) ? ' class="current"' : ''; $status_links['all'] = "<a href='edit.php?post_type={$post_type}{$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 (!in_array($status_name, $avail_post_stati)) { continue; } if (empty($num_posts->{$status_name})) { continue; } if (isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status']) { $class = ' class="current"'; } $status_links[$status_name] = "<a href='edit.php?post_status={$status_name}&post_type={$post_type}'{$class}>" . sprintf(translate_nooped_plural($status->label_count, $num_posts->{$status_name}), number_format_i18n($num_posts->{$status_name})) . '</a>'; } if (!empty($this->sticky_posts_count)) { $class = !empty($_REQUEST['show_sticky']) ? ' class="current"' : ''; $sticky_link = array('sticky' => "<a href='edit.php?post_type={$post_type}&show_sticky=1'{$class}>" . sprintf(_nx('Sticky <span class="count">(%s)</span>', 'Sticky <span class="count">(%s)</span>', $this->sticky_posts_count, 'posts'), number_format_i18n($this->sticky_posts_count)) . '</a>'); // Sticky comes after Publish, or if not listed, after All. $split = 1 + array_search(isset($status_links['publish']) ? 'publish' : 'all', array_keys($status_links)); $status_links = array_merge(array_slice($status_links, 0, $split), $sticky_link, array_slice($status_links, $split)); } return $status_links; }
/** * Retrieves all post statuses, depending on user context. * * @since 4.7.0 * @access public * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */ public function get_items($request) { $data = array(); $statuses = get_post_stati(array('internal' => false), 'object'); $statuses['trash'] = get_post_status_object('trash'); foreach ($statuses as $slug => $obj) { $ret = $this->check_read_permission($obj); if (!$ret) { continue; } $status = $this->prepare_item_for_response($obj, $request); $data[$obj->name] = $this->prepare_response_for_collection($status); } return rest_ensure_response($data); }
function scoper_admin_init() { global $pagenow; if (in_array($pagenow, array('update.php', 'plugin-install.php', 'update-core.php', 'plugins.php'))) { require_once dirname(__FILE__) . '/plugin-update-watch_rs.php'; RS_UpdateWatch::update_watch(); } if (!empty($_POST['rs_submit']) || !empty($_POST['rs_defaults']) || !empty($_POST['rs_flush_cache'])) { // For 'options' and 'realm' admin panels, handle updated options right after current_user load (and before scoper init). // By then, check_admin_referer is available, but Scoper config and WP admin menu has not been loaded yet. require_once SCOPER_ABSPATH . '/submittee_rs.php'; $handler = new Scoper_Submittee(); if (isset($_POST['rs_submit'])) { $sitewide = isset($_POST['rs_options_doing_sitewide']); $customize_defaults = isset($_POST['rs_options_customize_defaults']); $handler->handle_submission('update', $sitewide, $customize_defaults); } elseif (isset($_POST['rs_defaults'])) { $sitewide = isset($_POST['rs_options_doing_sitewide']); $customize_defaults = isset($_POST['rs_options_customize_defaults']); $handler->handle_submission('default', $sitewide, $customize_defaults); } elseif (isset($_POST['rs_flush_cache'])) { $handler->handle_submission('flush'); } } // work around conflict with Simple Fields plugin uploader if (defined('EASY_FIELDS_URL')) { if (strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/media-upload.php') || strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/async-upload.php')) { define('DISABLE_QUERYFILTERS_RS', true); } } if (defined('SSEO_VERSION')) { require_once dirname(__FILE__) . '/eyes-only-admin_rs.php'; } global $pagenow; // prevent default_private option from forcing a draft/pending post into private publishing if (in_array($pagenow, array('post.php', 'post-new.php'))) { if (empty($_POST['publish']) && isset($_POST['post_status']) && isset($_POST['post_type']) && scoper_get_otype_option('default_private', 'post', $_POST['post_type'])) { $stati = get_post_stati(array('public' => true, 'private' => true), 'names', 'or'); if ('private' == $_POST['visibility'] && !in_array($_POST['hidden_post_status'], $stati)) { $_POST['post_status'] = $_POST['hidden_post_status']; $_REQUEST['post_status'] = $_REQUEST['hidden_post_status']; $_POST['visibility'] = 'public'; $_REQUEST['visibility'] = 'public'; } } } }
/** * All built-in post statuses. * * @since 150821 Improving bbPress support. * * @return array All built-in post statuses. */ public function builtInPostStatuses() { if (!is_null($statuses =& $this->cacheKey('builtInPostStatuses'))) { return $statuses; // Already did this. } $statuses = []; // Initialize. foreach (get_post_stati([], 'objects') as $_key => $_status) { if (!empty($_status->_builtin)) { $statuses[] = $_status->name; } } unset($_key, $_status); // Housekeeping. return $statuses; }
/** * Get all post statuses, depending on user context * * @param WP_REST_Request $request * @return array|WP_Error */ public function get_items($request) { $data = array(); if (is_user_logged_in()) { $statuses = get_post_stati(array('internal' => false), 'object'); } else { $statuses = get_post_stati(array('public' => true), 'object'); } foreach ($statuses as $obj) { $status = $this->prepare_item_for_response($obj, $request); if (is_wp_error($status)) { continue; } $data[$obj->name] = $this->prepare_response_for_collection($status); } return rest_ensure_response($data); }
function wpse149143_wp_count_posts($counts, $type, $perm) { global $wpdb; if (!is_admin() || 'readable' !== $perm) { return $counts; } $post_type_object = get_post_type_object($type); if (current_user_can($post_type_object->cap->edit_others_posts)) { return $counts; } $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s AND (post_author = %d) GROUP BY post_status"; $results = (array) $wpdb->get_results($wpdb->prepare($query, $type, get_current_user_id()), ARRAY_A); $counts = array_fill_keys(get_post_stati(), 0); foreach ($results as $row) { $counts[$row['post_status']] = $row['num_posts']; } return (object) $counts; }
/** * Checks if the current user can read the post * * @since 1.5 * * @param int $post_id * @return bool */ public function current_user_can_read($post_id) { $post = get_post($post_id); if ('inherit' === $post->post_status) { $post = get_post($post->post_parent); } if (in_array($post->post_status, get_post_stati(array('public' => true)))) { return true; } // Follow WP practices, which shows links to private posts ( when readable ), but not for draft posts ( ex: get_adjacent_post_link() ) if (in_array($post->post_status, get_post_stati(array('private' => 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); // Comparison must not be strict! } return false; }