本文整理汇总了PHP中get_post_status_object函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_status_object函数的具体用法?PHP get_post_status_object怎么用?PHP get_post_status_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_status_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_register_carf_post_status
public function test_register_carf_post_status()
{
$post_status_object = get_post_status_object('carf');
$this->assertNull($post_status_object);
register_extended_post_status('carf', ['label' => 'Car']);
$post_status_object = get_post_status_object('carf');
$this->assertSame('Car', $post_status_object->label);
}
示例2: get_item
/**
* Get a specific post status
*
* @param WP_REST_Request $request
* @return array|WP_Error
*/
public function get_item($request)
{
$obj = get_post_status_object($request['status']);
if (empty($obj)) {
return new WP_Error('rest_status_invalid', __('Invalid status.'), array('status' => 404));
}
return $this->prepare_item_for_response($obj, $request);
}
示例3: kb_tickets_post_column_id
/**
* Output the ID row.
*
* @since 1.0
* @param int $ticket_id The ticket ID
* @param obj $kbs_ticket The ticket WP_Post object
* @return str
*/
function kb_tickets_post_column_id($ticket_id, $kbs_ticket)
{
do_action('kb_pre_tickets_column_id', $kbs_ticket);
$output = '<a href="' . get_edit_post_link($ticket_id) . '">#' . $ticket_id . '</a>';
$output .= '<br />';
$output .= get_post_status_object($kbs_ticket->post_status)->label;
do_action('kb_post_tickets_column_id', $kbs_ticket);
return apply_filters('kb_tickets_post_column_id', $output, $ticket_id);
}
示例4: can_react_to_post
/**
* Returns true if a post can be "reacted" upon, false if not
*/
public static function can_react_to_post($post_ID)
{
$post = get_post($post_ID);
if (!$post || is_wp_error($post)) {
return false;
}
if ('inherit' === $post->post_status) {
$parent_post = get_post($post->post_parent);
$post_password = $parent_post->post_password;
$post_status_obj = get_post_status_object($parent_post->post_status);
$post_status = $parent_post->post_status;
} else {
$post_status_obj = get_post_status_object($post->post_status);
$post_status = $post->post_status;
$post_password = $post->post_password;
}
if (!$post_status_obj->public) {
if (is_user_logged_in()) {
if ($post_status_obj->protected) {
if (!current_user_can('edit_post', $post->ID)) {
return false;
}
} elseif ($post_status_obj->private) {
if (!current_user_can('read_post', $post->ID)) {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
if (in_array($post_status, array('draft', 'pending', 'future', 'trash'))) {
return false;
}
if (strlen($post_password) && !current_user_can('read_post', $post->ID)) {
return false;
}
if ('off' === get_option('emoji_reactions_allow_guest_reactions', 'off') && !is_user_logged_in()) {
return false;
}
if (is_user_logged_in()) {
$check_count_against = array('user_id' => get_current_user_id());
} else {
$check_count_against = array('search' => preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']));
}
$allowed_reactions_per_user = get_option('emoji_reactions_num_per_user_per_post', 10);
if ($allowed_reactions_per_user > 0) {
$check_count_against = array('type' => 'emoji-reaction', 'count' => true) + $check_count_against;
$current_user_reaction_count = get_comments($check_count_against);
if ($current_user_reaction_count >= $allowed_reactions_per_user) {
return false;
}
}
return true;
}
示例5: create_comment
public static function create_comment($entry_id, $form_id)
{
$comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
$post = get_post($comment_post_ID);
if (empty($post->comment_status)) {
return;
}
// get_post_status() will get the parent status for attachments.
$status = get_post_status($post);
$status_obj = get_post_status_object($status);
if (!comments_open($comment_post_ID)) {
do_action('comment_closed', $comment_post_ID);
//wp_die( __( 'Sorry, comments are closed for this item.') );
return;
} else {
if ('trash' == $status) {
do_action('comment_on_trash', $comment_post_ID);
return;
} else {
if (!$status_obj->public && !$status_obj->private) {
do_action('comment_on_draft', $comment_post_ID);
return;
} else {
if (post_password_required($comment_post_ID)) {
do_action('comment_on_password_protected', $comment_post_ID);
return;
} else {
do_action('pre_comment_on_post', $comment_post_ID);
}
}
}
}
$comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : '';
// If the user is logged in
$user_ID = get_current_user_id();
if ($user_ID) {
global $current_user;
$display_name = !empty($current_user->display_name) ? $current_user->display_name : $current_user->user_login;
$comment_author = $display_name;
$comment_author_email = '';
//get email from field
$comment_author_url = $current_user->user_url;
} else {
$comment_author = isset($_POST['author']) ? trim(strip_tags($_POST['author'])) : '';
$comment_author_email = isset($_POST['email']) ? trim($_POST['email']) : '';
$comment_author_url = isset($_POST['url']) ? trim($_POST['url']) : '';
}
$comment_type = '';
if (!$user_ID && get_option('require_name_email') && (6 > strlen($comment_author_email) || $comment_author == '')) {
return;
}
if ($comment_content == '') {
return;
}
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
wp_new_comment($commentdata);
}
示例6: register_post_stati
public static function register_post_stati()
{
if (get_post_status_object('btb_canceled')) {
return;
}
$args = array('label' => _x('Booked', 'Status General Name', 'bt-booking'), 'label_count' => _n_noop('Booked <span class="count">(%s)</a>', 'Booked <span class="count">(%s)</a>', 'bt-booking'), 'protected' => true, 'show_in_admin_status_list' => true, 'exclude_from_search' => false);
register_post_status('btb_booked', $args);
$args = array('label' => _x('Prebooked', 'Status General Name', 'bt-booking'), 'label_count' => _n_noop('Prebooked <span class="count">(%s)</a>', 'Prebooked <span class="count">(%s)</a>', 'bt-booking'), 'protected' => true, 'show_in_admin_status_list' => true, 'exclude_from_search' => false);
register_post_status('btb_prebook', $args);
$args = array('label' => _x('Canceled', 'Status General Name', 'bt-booking'), 'label_count' => _n_noop('Canceled <span class="count">(%s)</a>', 'Canceled <span class="count">(%s)</a>', 'bt-booking'), 'protected' => true, 'show_in_admin_status_list' => true, 'exclude_from_search' => false);
register_post_status('btb_canceled', $args);
}
示例7: get_data
function get_data($item)
{
$data = array('title-attr' => $item->get_permalink());
$post = $item->get_object();
if ('publish' != $post->post_status) {
$status_obj = get_post_status_object($post->post_status);
if ($status_obj) {
$data['status']['text'] = $status_obj->label;
}
}
return $data;
}
示例8: render_list_table_page
/**
* Setup the list table and render the list table page, or call the given
* action.
*
* @param string $page_title
* @param WordPress\Orm\Admin\ListTable $list_table
*/
public static function render_list_table_page($page_title, $list_table)
{
// We pass the class to filters & actions
$list_table_class = get_class($list_table);
// Get stuff
$pagenum = $list_table->get_pagenum();
$action = $list_table->current_action();
if ($action) {
check_admin_referer('bulk-posts');
$sendback = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'locked', 'ids'), wp_get_referer());
// Comment this
if (!$sendback) {
$sendback = admin_url('admin.php?page=test-venues');
}
// Add the current page to the sendback URL
$sendback = add_query_arg('paged', $pagenum, $sendback);
// ?
if (strpos($sendback, 'post.php') !== false) {
$sendback = admin_url($post_new_file);
}
// Get the post ids to operate on
if ('delete_all' == $doaction) {
$post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
if (get_post_status_object($post_status)) {
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type=%s AND post_status = %s", $post_type, $post_status));
}
$doaction = 'delete';
} elseif (isset($_REQUEST['media'])) {
$post_ids = $_REQUEST['media'];
} elseif (isset($_REQUEST['ids'])) {
$post_ids = explode(',', $_REQUEST['ids']);
} elseif (!empty($_REQUEST['post'])) {
$post_ids = array_map('intval', $_REQUEST['post']);
}
if (!isset($post_ids)) {
wp_redirect($sendback);
exit;
}
// Plugins need to do their thing here
do_action('wporm:list_table:action', $action, $post_ids, $list_table, $list_table_class);
// Redirect the user
$sendback = remove_query_arg(['action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'], $sendback);
wp_redirect($sendback);
exit;
} elseif (!empty($_REQUEST['_wp_http_referer'])) {
wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI'])));
exit;
}
$list_table->prepare_items();
require ABSPATH . 'wp-admin/admin-header.php';
require __DIR__ . '/../views/list-table.php';
}
示例9: sv_render_status_column
function sv_render_status_column($column_name, $post_id)
{
global $post;
if ($column_name === 'status') {
$currentPostStatus = $post->post_status;
$statusObject = get_post_status_object($currentPostStatus);
if ($statusObject != null) {
printf('<mark class="%1$s tips" data-tip="%2$s">%3$s</mark>', $statusObject->name, $statusObject->label, $statusObject->label);
} else {
printf('<mark class="$1%s tips" data-tip="$1%s">$1%s</mark>', $currentPostStatus);
}
}
}
示例10: get_comments_number
/**
* Hooks the WP get_comments_number filter to get the number of comments
* across all posts in the translation group.
*
* @param int $count The number of comments on the single translation
* @param int $post_id The post ID of the single translation
* @return int The count of all comments on published posts in this translation group
**/
public function get_comments_number($count, $post_id)
{
$translations = bbl_get_post_translations($post_id);
$count = 0;
foreach ($translations as &$translation) {
$post_status = get_post_status_object($translation->post_status);
// FIXME: I'm not entirely sure about using publicly_queryable here… what I want to avoid is draft, private, etc statii.
if ($post_status->publicly_queryable) {
$count += $translation->comment_count;
}
}
return $count;
}
示例11: fix_table_edit_reqd_caps
function fix_table_edit_reqd_caps($rs_reqd_caps, $orig_meta_cap, $_post, $object_type_obj)
{
foreach (array('edit', 'delete') as $op) {
if (in_array($orig_meta_cap, array("{$op}_post", "{$op}_page"))) {
$status_obj = get_post_status_object($_post->post_status);
foreach (array('public' => 'published', 'private' => 'private') as $status_prop => $cap_suffix) {
if (!empty($status_obj->{$status_prop})) {
$cap_prop = "{$op}_{$cap_suffix}_posts";
$rs_reqd_caps[] = $object_type_obj->cap->{$cap_prop};
$GLOBALS['revisionary']->skip_revision_allowance = true;
}
}
}
}
return $rs_reqd_caps;
}
示例12: mb_user_can
/**
* Helper function for checking if a user can read forums, topics, or replies. We need this to handle
* users who are not logged in but should have permission to read (e.g, non-private forums). This
* function is meant to be used in conjunction with a filter on `map_meta_cap`.
*
* @since 1.0.0
* @access public
* @param int $user_id
* @param string $cap
* @param int $post_id
* @return bool
*/
function mb_user_can($user_id, $cap, $post_id)
{
// @todo Check hierarchy.
if (in_array($cap, array('read_forum', 'read_topic', 'read_reply'))) {
if ('read_forum' === $cap) {
$status_obj = get_post_status_object(mb_get_forum_status($post_id));
} elseif ('read_topic' === $cap) {
$status_obj = get_post_status_object(mb_get_topic_status($post_id));
} elseif ('read_forum' === $cap) {
$status_obj = get_post_status_object(mb_get_reply_status($post_id));
}
if (false === $status_obj->private && false === $status_obj->protected) {
return true;
}
}
return user_can($user_id, $cap, $post_id);
}
示例13: _pp_flt_map_media_meta_cap
function _pp_flt_map_media_meta_cap($caps, $cap, $user_id, $args)
{
if (!empty($args[0])) {
$post = is_object($args[0]) ? $args[0] : get_post($args[0]);
if ($post && 'attachment' == $post->post_type) {
if (!empty($post->post_parent)) {
$post_status = get_post_status($post->ID);
} elseif ('inherit' == $post->post_status) {
$post_status = pp_get_option('unattached_files_private') ? 'private' : 'publish';
} else {
$post_status = $post->post_status;
}
$post_type = get_post_type_object($post->post_type);
$post_author_id = $post->post_author;
$caps = array_diff($caps, (array) $cap);
switch ($cap) {
case 'read_post':
case 'read_page':
$status_obj = get_post_status_object($post_status);
if ($status_obj->public || $status_obj->private && $user_id == $post_author_id) {
$caps[] = $post_type->cap->read;
break;
}
// If no author set yet, default to current user for cap checks.
if (!$post_author_id) {
$post_author_id = $user_id;
}
if ($status_obj->private) {
$caps[] = $post_type->cap->read_private_posts;
} else {
$caps = map_meta_cap('edit_post', $user_id, $post->ID);
}
$caps = apply_filters('pp_map_attachment_read_caps', $caps, $post, $user_id);
break;
default:
require_once dirname(__FILE__) . '/media-edit-metacap-workaround_pp.php';
$args = array_merge($args, compact('post', 'post_status', 'post_type', 'post_author_id'));
$caps = _ppff_flt_map_media_edit_meta_cap($caps, $cap, $user_id, $args);
}
}
}
return $caps;
}
示例14: action_manage_posts_custom_column
/**
* Produce the column values for the custom columns we created
*/
function action_manage_posts_custom_column($column_name, $ticket_id)
{
switch ($column_name) {
case 'updated':
$modified_gmt = get_post_modified_time('U', true, $ticket_id);
echo sprintf(__('%s ago', 'supportflow'), human_time_diff($modified_gmt));
break;
case 'sf_excerpt':
$replies = SupportFlow()->get_ticket_replies($ticket_id, array('posts_per_page' => 1, 'order' => 'ASC'));
if (!isset($replies[0])) {
echo '—';
break;
}
$first_reply = $replies[0]->post_content;
if (strlen($first_reply) > 50) {
$first_reply = substr($first_reply, 0, 50);
}
echo $first_reply;
break;
case 'customers':
$customers = SupportFlow()->get_ticket_customers($ticket_id, array('fields' => 'emails'));
if (empty($customers)) {
echo '—';
break;
}
foreach ($customers as $key => $customer_email) {
$args = array(SupportFlow()->customers_tax => SupportFlow()->get_email_hash($customer_email), 'post_type' => SupportFlow()->post_type);
$customer_photo = get_avatar($customer_email, 16);
$customer_link = '<a class="customer_link" href="' . esc_url(add_query_arg($args, admin_url('edit.php'))) . '">' . $customer_email . '</a>';
$customers[$key] = $customer_photo . ' ' . $customer_link;
}
echo implode('<br />', $customers);
break;
case 'status':
$post_status = get_post_status($ticket_id);
$args = array('post_type' => SupportFlow()->post_type, 'post_status' => $post_status);
$status_name = get_post_status_object($post_status)->label;
$filter_link = add_query_arg($args, admin_url('edit.php'));
echo '<a href="' . esc_url($filter_link) . '">' . esc_html($status_name) . '</a>';
break;
case 'email':
$email_account_id = get_post_meta($ticket_id, 'email_account', true);
$email_accounts = SupportFlow()->extend->email_accounts->get_email_accounts();
$args = array('post_type' => SupportFlow()->post_type, 'email_account' => $email_account_id);
if (!isset($email_accounts[$email_account_id])) {
echo '—';
break;
}
$email_account_username = $email_accounts[$email_account_id]['username'];
$filter_link = add_query_arg($args, admin_url('edit.php'));
echo '<a href="' . esc_url($filter_link) . '">' . esc_html($email_account_username) . '</a>';
break;
case 'sf_replies':
$replies = SupportFlow()->get_ticket_replies_count($ticket_id);
echo '<div class="post-com-count-wrapper">';
echo "<span class='replies-count'>{$replies}</span>";
echo '</div>';
break;
case 'created':
$created_time = get_the_time(get_option('time_format') . ' T', $ticket_id);
$created_date = get_the_time(get_option('date_format'), $ticket_id);
echo sprintf(__('%s<br />%s', 'supportflow'), $created_time, $created_date);
break;
}
}
示例15: parse_column
/**
* Parsing the column based on the $column_name.
*
* @param string $column_name
* @param stdobject $rec
*
* @return string
*/
protected function parse_column($column_name, $rec)
{
static $date_format;
if ($date_format == null) {
$date_format = get_option('date_format');
}
switch ($column_name) {
case 'col_page_title':
$column_value = $this->parse_page_title_column($rec);
break;
case 'col_page_slug':
$permalink = get_permalink($rec->ID);
$display_slug = str_replace(get_bloginfo('url'), '', $permalink);
$column_value = sprintf('<a href="%2$s" target="_blank">%1$s</a>', stripslashes($display_slug), esc_url($permalink));
break;
case 'col_post_type':
$post_type = get_post_type_object($rec->post_type);
$column_value = $post_type->labels->singular_name;
break;
case 'col_post_status':
$post_status = get_post_status_object($rec->post_status);
$column_value = $post_status->label;
break;
case 'col_post_date':
$column_value = date_i18n($date_format, strtotime($rec->post_date));
break;
case 'col_row_action':
$column_value = sprintf('<a href="#" class="wpseo-save" data-id="%1$s">Save</a> | <a href="#" class="wpseo-save-all">Save All</a>', $rec->ID);
break;
}
if (!empty($column_value)) {
return $column_value;
}
}