本文整理汇总了PHP中get_post_type_object函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_type_object函数的具体用法?PHP get_post_type_object怎么用?PHP get_post_type_object使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_type_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ctc_after_save_event
/**
* After Save Event
*
* This runs after the event post is saved, for further manipulation of meta data.
*
* @since 1.2
* @param int $post_id Post ID
* @param object $post Data for post being saved
*/
function ctc_after_save_event($post_id, $post)
{
// Event is being saved
if (!isset($post->post_type) || 'ctc_event' != $post->post_type) {
return;
}
// Is a POST occurring?
if (empty($_POST)) {
return;
}
// Not an auto-save (meta values not submitted)
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// Verify the nonce
$nonce_key = 'ctc_event_date_nonce';
$nonce_action = 'ctc_event_date_save';
if (empty($_POST[$nonce_key]) || !wp_verify_nonce($_POST[$nonce_key], $nonce_action)) {
return;
}
// Make sure user has permission to edit
$post_type = get_post_type_object($post->post_type);
if (!current_user_can($post_type->cap->edit_post, $post_id)) {
return;
}
// Action hook
do_action('ctc_after_save_event', $post_id, $post);
}
示例2: flt_adjust_reqd_caps
function flt_adjust_reqd_caps($reqd_caps, $orig_cap, $user_id, $args)
{
global $pagenow, $current_user;
// Work around WP's occasional use of literal 'cap_name' instead of $post_type_object->cap->$cap_name
// note: cap names for "post" type may be customized too
if (in_array($pagenow, array('edit.php', 'post.php', 'post-new.php', 'press-this.php', 'admin-ajax.php', 'upload.php', 'media.php')) && in_array('edit_posts', $reqd_caps) && $user_id == $current_user->ID && !$this->doing_admin_menus()) {
static $did_admin_init = false;
if (!$did_admin_init) {
$did_admin_init = did_action('admin_init');
}
if ($did_admin_init) {
if (!empty($args[0])) {
$item_id = is_object($args[0]) ? $args[0]->ID : $args[0];
} else {
$item_id = 0;
}
if ($type_obj = get_post_type_object(pp_find_post_type($item_id))) {
$key = array_search('edit_posts', $reqd_caps);
if (false !== $key) {
$reqd_caps[$key] = $type_obj->cap->edit_posts;
}
}
}
}
//===============================
return $reqd_caps;
}
示例3: bu_navigation_filter_pages_ancestors
/**
* Appends an "active_section" property to every post being returned during bu_navigation_get_pages
*
* @param array $pages Associative array of pages keyed on page ID
* @return array Filtered associative array of pages with active_section member variable set
*/
function bu_navigation_filter_pages_ancestors($pages)
{
global $wpdb, $post;
// Only useful during single post query
if (!$post) {
return $pages;
}
// Only needed for hierarchical post types
$post_type_object = get_post_type_object($post->post_type);
if (!$post_type_object->hierarchical) {
return $pages;
}
$ancestors = bu_navigation_gather_sections($post->ID, array('post_types' => $post->post_type));
$filtered = array();
if (is_array($pages) && count($pages) > 0) {
if (is_array($ancestors) && count($ancestors) > 0) {
foreach ($pages as $page) {
$page->active_section = false;
if (in_array($page->ID, $ancestors) && $page->ID != $post->ID) {
$page->active_section = true;
}
$filtered[$page->ID] = $page;
}
} else {
$filtered = $pages;
}
}
return $filtered;
}
示例4: savemeta
public static function savemeta($post_id, $post)
{
/* Get the post type object. */
$post_type = get_post_type_object($post->post_type);
/* Check if the current user has permission to edit the post. */
if (!current_user_can($post_type->cap->edit_post, $post_id)) {
return $post_id;
}
/* Get the meta key. */
$meta_key = self::$prefix . $post_id;
/* Get the posted data and sanitize it for use as an HTML class. */
$new_meta_value = isset($_POST[self::$prefix]) ? $_POST[self::$prefix] : '';
/* Get the meta value of the custom field key. */
$meta_value = get_post_meta($post_id, $meta_key, true);
/* If a new meta value was added and there was no previous value, add it. */
if ($new_meta_value && '' == $meta_value) {
add_post_meta($post_id, $meta_key, $new_meta_value, true);
} elseif ($new_meta_value && $new_meta_value != $meta_value) {
update_post_meta($post_id, $meta_key, $new_meta_value);
} elseif ('' == $new_meta_value && $meta_value) {
delete_post_meta($post_id, $meta_key, $meta_value);
if (($ptemplate = self::getPathTheme($post_id)) && file_exists($ptemplate)) {
unlink($ptemplate);
}
}
}
示例5: query_posts
public static function query_posts($request = null)
{
$response = (object) array('status' => false, 'message' => __('Your request has failed', 'fakerpress'), 'results' => array(), 'more' => true);
if (!Admin::$is_ajax && is_null($request) || !is_user_logged_in()) {
return Admin::$is_ajax ? exit(json_encode($response)) : $response;
}
$request = (object) $_POST;
if (isset($request->query['post_type']) && !is_array($request->query['post_type'])) {
$request->query['post_type'] = array_map('trim', (array) explode(',', $request->query['post_type']));
}
$query = new \WP_Query($request->query);
if (!$query->have_posts()) {
return Admin::$is_ajax ? exit(json_encode($response)) : $response;
}
$response->status = true;
$response->message = __('Request successful', 'fakerpress');
foreach ($query->posts as $k => $post) {
$query->posts[$k]->post_type = get_post_type_object($post->post_type);
}
$response->results = $query->posts;
if ($query->max_num_pages >= $request->query['paged']) {
$response->more = false;
}
return Admin::$is_ajax ? exit(json_encode($response)) : $response;
}
示例6: flt_get_editable_authors
function flt_get_editable_authors($unfiltered_results)
{
global $wpdb, $scoper, $post;
if (!($post_type = cr_find_post_type())) {
return $unfiltered_results;
}
if (!($post_type_obj = get_post_type_object($post_type))) {
return $unfiltered_results;
}
$have_cap = cr_user_can($post_type_obj->cap->edit_others_posts, $post->ID, 0, array('require_full_object_role' => true));
if ($have_cap) {
return $scoper->users_who_can($post_type_obj->cap->edit_posts, COLS_ALL_RS);
} else {
if ($post->ID) {
if ($current_author = $scoper->data_sources->get_from_db('owner', 'post', $post->ID)) {
$force_user_id = $current_author;
}
} else {
global $current_user;
$force_user_id = $current_user->ID;
}
if ($force_user_id) {
$display_name = $wpdb->get_var("SELECT display_name FROM {$wpdb->users} WHERE ID = '{$force_user_id}'");
$users = array((object) array('ID' => $force_user_id, 'display_name' => $display_name));
return $users;
}
}
//log_mem_usage_rs( 'flt_get_editable_authors()' );
return $unfiltered_results;
}
示例7: medium_save_video_meta
/**
* Saves the video embed code on post save
*
* @since 4.0
*/
function medium_save_video_meta($post_id)
{
global $post;
// Return early if this is a newly created post that hasn't been saved yet.
if ('auto-draft' == get_post_status($post_id)) {
return $post_id;
}
// Check if the user intended to change this value.
if (!isset($_POST['medium_video_box_nonce']) || !wp_verify_nonce($_POST['medium_video_box_nonce'], plugin_basename(__FILE__))) {
return $post_id;
}
// Get post type object
$post_type = get_post_type_object($post->post_type);
// Check if user has permission
if (!current_user_can($post_type->cap->edit_post, $post_id)) {
return $post_id;
}
// Get posted data and sanitize it
$new_video = isset($_POST['medium_video_field']) ? $_POST['medium_video_field'] : '';
// Get existing video
$video = get_post_meta($post_id, 'video', true);
// If a new video was submitted and there was no previous one, add it
if ($new_video && '' == $video) {
add_post_meta($post_id, 'video', $new_video, true);
} elseif ($new_video && $new_video != $video) {
update_post_meta($post_id, 'video', $new_video);
} elseif ('' == $new_video && $video) {
delete_post_meta($post_id, 'video', $video);
}
}
示例8: popmake_render_popup_columns
/**
* Render Popup Columns
*
* @since 1.0
*
* @param string $column_name Column name
* @param int $post_id Popup (Post) ID
*
* @return void
*/
function popmake_render_popup_columns($column_name, $post_id)
{
if (get_post_type($post_id) == 'popup') {
global $popmake_options;
$post = get_post($post_id);
setup_postdata($post);
$post_type_object = get_post_type_object($post->post_type);
$can_edit_post = current_user_can($post_type_object->cap->edit_post, $post->ID);
switch ($column_name) {
case 'popup_title':
echo '<strong>' . esc_html(popmake_get_the_popup_title($post_id)) . '</strong>';
break;
case 'popup_category':
echo get_the_term_list($post_id, 'popup_category', '', ', ', '');
break;
case 'popup_tag':
echo get_the_term_list($post_id, 'popup_tag', '', ', ', '');
break;
case 'class':
echo '<pre style="display:inline-block;margin:0;"><code>popmake-' . absint($post_id) . '</code></pre>';
if ($post->post_name != $post->ID) {
echo '|';
echo '<pre style="display:inline-block;margin:0;"><code>popmake-' . $post->post_name . '</code></pre>';
}
break;
}
}
}
示例9: my_init
function my_init()
{
$args = objectToArray(get_post_type_object('post'));
$args['has_archive'] = 'news';
$args['rewrite'] = array('slug' => 'news', 'with_front' => false);
register_post_type('post', $args);
}
示例10: bogo_post_row_actions
function bogo_post_row_actions($actions, $post)
{
if (!bogo_is_localizable_post_type($post->post_type)) {
return $actions;
}
$post_type_object = get_post_type_object($post->post_type);
if (!current_user_can($post_type_object->cap->edit_post, $post->ID) || 'trash' == $post->post_status) {
return $actions;
}
$user_locale = bogo_get_user_locale();
$post_locale = bogo_get_post_locale($post->ID);
if ($user_locale == $post_locale) {
return $actions;
}
$translations = bogo_get_post_translations($post);
if (!empty($translations[$user_locale])) {
$translation = $translations[$user_locale];
if (empty($translation->ID) || $translation->ID == $post->ID) {
return $actions;
}
$title = __('Edit %s translation of this item', 'bogo');
$text = __('Edit %s translation', 'bogo');
$edit_link = get_edit_post_link($translation->ID);
} else {
$title = __('Translate this item into %s', 'bogo');
$text = __('Translate into %s', 'bogo');
$edit_link = admin_url('post-new.php?post_type=' . $post->post_type . '&locale=' . $user_locale . '&original_post=' . $post->ID);
}
$language = bogo_get_language($user_locale);
if (empty($language)) {
$language = $user_locale;
}
$actions['translate'] = '<a title="' . esc_attr(sprintf($title, $language)) . '" href="' . $edit_link . '">' . esc_html(sprintf($text, $language)) . '</a>';
return $actions;
}
示例11: clone_landing_page
/**
* Creates cloned landing page and opens it for user
* @param string $status
*/
public static function clone_landing_page($status = 'pending')
{
/* Get the original post */
$id = isset($_GET['post']) ? $_GET['post'] : $_POST['post'];
$post = get_post($id);
/* Copy the post and insert it */
if (!isset($post) || !$post) {
$post_type_obj = get_post_type_object($post->post_type);
wp_die(esc_attr(__('Copy creation failed, could not find original:', 'landing-pages')) . ' ' . $id);
}
if (!is_object($post) && is_numeric($post)) {
$post = get_post($post);
}
$status = $post->post_status;
/* We don't want to clone revisions */
if ($post->post_type == 'revision') {
return;
}
$prefix = "Copy of ";
$suffix = "";
$status = 'pending';
$new_post_author = self::get_current_user();
$new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_mime_type' => $post->post_mime_type, 'post_parent' => $new_post_parent = empty($parent_id) ? $post->post_parent : $parent_id, 'post_password' => $post->post_password, 'post_status' => $status, 'post_title' => $prefix . $post->post_title . $suffix, 'post_type' => $post->post_type);
$new_post['post_date'] = $new_post_date = $post->post_date;
$new_post['post_date_gmt'] = get_gmt_from_date($new_post_date);
$new_post_id = wp_insert_post($new_post);
$meta_data = self::get_meta($post->ID);
foreach ($meta_data as $key => $value) {
update_post_meta($new_post_id, $key, $value);
}
wp_redirect(admin_url('edit.php?post_type=' . $post->post_type));
exit;
}
示例12: normalize
/**
* Normalize parameters for field
*
* @param array $field
*
* @return array
*/
static function normalize($field)
{
/**
* Set default field args
*/
$field = wp_parse_args($field, array('post_type' => 'post', 'field_type' => 'select', 'parent' => false, 'query_args' => array()));
/**
* Set default placeholder
* - If multiple post types: show 'Select a post'
* - If single post type: show 'Select a %post_type_name%'
*/
if (empty($field['placeholder'])) {
$field['placeholder'] = __('Select a post', 'meta-box');
if (is_string($field['post_type']) && post_type_exists($field['post_type'])) {
$post_type_object = get_post_type_object($field['post_type']);
$field['placeholder'] = sprintf(__('Select a %s', 'meta-box'), $post_type_object->labels->singular_name);
}
}
/**
* Set parent option, which will change field name to `parent_id` to save as post parent
*/
if ($field['parent']) {
$field['multiple'] = false;
$field['field_name'] = 'parent_id';
}
/**
* Set default query args
*/
$field['query_args'] = wp_parse_args($field['query_args'], array('post_status' => 'publish', 'posts_per_page' => -1));
$field['query_args']['post_type'] = $field['post_type'];
$field = parent::normalize($field);
return $field;
}
示例13: flt_defeat_publish_filter
function flt_defeat_publish_filter($where)
{
$post_type = cr_find_post_type();
$post_type_obj = get_post_type_object($post_type);
$object_id = scoper_get_object_id('post', $post_type);
// don't alter the query if RS query filtering is disabled, or if this maneuver has been disabled via constant
// note: for non-administrators, QueryInterceptor_RS::flt_objects_where will convert the publish requirement to publish OR private, if the user's blog role or RS-assigned roles grant private access
if (!is_content_administrator_rs() || defined('SCOPER_RETAIN_PUBLISH_FILTER') || defined('DISABLE_QUERYFILTERS_RS')) {
return $where;
}
global $wp_query;
if (is_admin() && !empty($wp_query->query['post_status'])) {
// if a specific status was requested by URI, don't force inclusion of others
return $where;
}
// don't alter the where clause if in wp-admin and not filtering by taxonomy
if (is_admin()) {
global $wp_query;
if (empty($wp_query) && empty($wp_query->is_tax)) {
return $where;
}
}
global $wpdb, $current_user;
// don't alter the where clause for anonymous users
if (empty($current_user->ID)) {
return $where;
}
$where = preg_replace("/{$wpdb->posts}.post_status\\s*=\\s*'publish'/", "({$wpdb->posts}.post_status = 'publish' OR {$wpdb->posts}.post_status = 'private')", $where);
$where = preg_replace("/p2.post_status\\s*=\\s*'publish'/", "(p2.post_status = 'publish' OR p2.post_status = 'private')", $where);
$where = preg_replace("/p.post_status\\s*=\\s*'publish'/", "(p.post_status = 'publish' OR p.post_status = 'private')", $where);
return $where;
}
示例14: copernico_save_seo_post_meta
/**
* SAVE metaboxes for SEO
*/
function copernico_save_seo_post_meta($post_id, $post)
{
/*
* Security checks
*/
if (!isset($_POST['copernico_metabox_nonce']) || !wp_verify_nonce($_POST['copernico_metabox_nonce'], basename(__FILE__))) {
return $post_id;
}
/*
* Check current user permissions
*/
$post_type = get_post_type_object($post->post_type);
if (!current_user_can($post_type->cap->edit_post, $post_id)) {
return $post_id;
}
/*
* Do not save the data if autosave
*/
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
if ($post->post_type == 'post') {
update_post_meta($post_id, 'copernico_seo_title', trim($_POST['copernico_seo_title']));
//update_post_meta($post_id, 'rudr_noindex', $_POST['rudr_noindex']);
}
return $post_id;
}
示例15: __construct
/**
* TODO: Ability to set default values for:
*
* - Campaign type
* - List, list segment
* - Template
*/
public function __construct($post_type = null)
{
$this->post_type = $post_type;
$this->post_type_obj = get_post_type_object($this->post_type);
$this->settings_key = $this->post_type_obj->name . '_mailchimp_settings';
$this->init();
}