• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP WP_Post类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: resolveWordPressPostToModel

 public static function resolveWordPressPostToModel(\WP_Post $post)
 {
     /** @var PostTypeManager $postTypes */
     $postTypes = app('posts.types');
     if ($class = $postTypes->get($post->post_type)) {
         return with(new $class())->newInstance($post->to_array());
     }
     return false;
 }
开发者ID:lara-press,项目名称:framework,代码行数:9,代码来源:Post.php


示例2: normalize

 /**
  * {@inheritdoc}
  */
 public function normalize($blogId, \WP_Post $post)
 {
     $out = $post->to_array();
     unset($out['post_category'], $out['tags_input']);
     $out['terms'] = $this->buildTerms($post);
     if (!empty($post->post_author)) {
         $out['post_author'] = $this->buildAuthor($post);
     }
     return $out;
 }
开发者ID:WPMagnify,项目名称:core,代码行数:13,代码来源:DefaultNormalizer.php


示例3: get

 public function get($post_id)
 {
     if ($post = \WP_Post::get_instance($post_id)) {
         return $this->wordpress_post_factory->createFromWP_Post(\WP_Post::get_instance($post_id));
     }
     return null;
 }
开发者ID:cmoncy,项目名称:WordpressBundle,代码行数:7,代码来源:WordpressPostRepository.php


示例4: getWPPost

 /**
  *
  * @return \WP_Post
  */
 public function getWPPost()
 {
     if (null === $this->wpPost) {
         $this->wpPost = \WP_Post::get_instance($this->ID);
     }
     return $this->wpPost;
 }
开发者ID:chemaclass,项目名称:knob-base,代码行数:11,代码来源:Post.php


示例5: getInstance

 public static function getInstance($pid)
 {
     $post = new self($pid);
     $post->setPost(\WP_Post::get_instance($pid));
     $post->fetch();
     return $post;
 }
开发者ID:loumray,项目名称:wpcore,代码行数:7,代码来源:WPcustomPost.php


示例6: delete

 /**
  * Use this method to prevent excluding something that was not configured by FakerPress
  *
  * @param  array|int|\WP_Post $post The ID for the Post or the Object
  * @return bool
  */
 public static function delete($post)
 {
     if (is_array($post)) {
         $deleted = array();
         foreach ($post as $id) {
             $id = $id instanceof \WP_Post ? $id->ID : $id;
             if (!is_numeric($id)) {
                 continue;
             }
             $deleted[$id] = self::delete($id);
         }
         return $deleted;
     }
     if (is_numeric($post)) {
         $post = \WP_Post::get_instance($post);
     }
     if (!$post instanceof \WP_Post) {
         return false;
     }
     $flag = (bool) get_post_meta($post->ID, self::$flag, true);
     if (true !== $flag) {
         return false;
     }
     return wp_delete_post($post->ID, true);
 }
开发者ID:arobbins,项目名称:sblog,代码行数:31,代码来源:post.php


示例7: output_term

 private static function output_term($term_slug, $fallback_text = '')
 {
     $post = WP_Post::get_instance(wskl_get_option('members_page_' . $term_slug));
     if (!$post) {
         echo $fallback_text;
     } else {
         echo '<h3>' . esc_html($post->post_title) . '</h3>';
         echo wpautop(wptexturize($post->post_content));
     }
 }
开发者ID:EricKim65,项目名称:woosym-korean-localization,代码行数:10,代码来源:class-wskl-dabory-members.php


示例8: get_event

 /**
  * Work with the specifed event object or else use a placeholder if we are in
  * the middle of creating a new event.
  *
  * @param null $event
  */
 protected function get_event($event = null)
 {
     if (is_null($event)) {
         $event = $GLOBALS['post'];
     }
     if (is_numeric($event)) {
         $event = WP_Post::get_instance($event);
     }
     if ($event instanceof stdClass || is_array($event)) {
         $event = new WP_Post((object) $event);
     }
     if (!$event instanceof WP_Post) {
         $event = new WP_Post((object) array('ID' => 0));
     }
     $this->event = $event;
 }
开发者ID:nullify005,项目名称:shcc-website,代码行数:22,代码来源:Chooser_Meta_Box.php


示例9: __construct

 /**
  * Give_Donate_Form constructor.
  *
  * @since 1.0
  *
  * @param bool  $_id
  * @param array $_args
  */
 public function __construct($_id = false, $_args = array())
 {
     if (false === $_id) {
         $defaults = array('post_type' => 'give_forms', 'post_status' => 'draft', 'post_title' => __('New Give Form', 'give'));
         $args = wp_parse_args($_args, $defaults);
         $_id = wp_insert_post($args, true);
     }
     $donate_form = WP_Post::get_instance($_id);
     if (!is_object($donate_form)) {
         return false;
     }
     if (!is_a($donate_form, 'WP_Post')) {
         return false;
     }
     if ('give_forms' !== $donate_form->post_type) {
         return false;
     }
     foreach ($donate_form as $key => $value) {
         $this->{$key} = $value;
     }
 }
开发者ID:lots0logs,项目名称:Give,代码行数:29,代码来源:class-give-donate-form.php


示例10: user_register_observer

 public function user_register_observer($user_id)
 {
     global $wpdb;
     if (get_option('rf_bonus_signup', 'no') == 'no') {
         return;
     }
     $user_data = get_userdata($user_id);
     $lead_data = array();
     $email = $user_data->data->user_email;
     // var_dump($user_data->data);
     $customer_name = '';
     $lastname = get_user_meta($user_id, 'last_name', 'true');
     $firstname = get_user_meta($user_id, 'first_name', 'true');
     $customer_name = $firstname . ' ' . $lastname;
     if (!trim($customer_name)) {
         $customer_name = $user_data->data->display_name;
     }
     //whether the new registered customer is refer by friend
     $query = "SELECT post.ID as id from  {$wpdb->posts} as  post \n\t\t\n\t\t LEFT JOIN {$wpdb->postmeta} AS rf ON (post.ID = rf.post_id \n\t     and rf.meta_key='rf_invite_email' )\n\t     \n\t     LEFT JOIN {$wpdb->postmeta} AS rf_aff ON (post.ID = rf.post_id \n\t     and rf_aff.meta_key='rf_reward_email' )\n\t     \n\t     WHERE post.post_type = 'mg_referfriend'\n\t     AND rf.meta_value = '{$email}'\n\t\t ";
     $row = $wpdb->get_row($query, ARRAY_A);
     if ($row) {
         $post_id = $row['id'];
         if (get_post_meta($post_id, 'is_rewarded_signup', true) != 'yes') {
             $post = WP_Post::get_instance($post_id);
             $affilate_user_id = $post->post_author;
             $user_data = get_userdata($affilate_user_id);
             $affilate_name = '';
             $lastname = get_user_meta($user_id, 'last_name', 'true');
             $firstname = get_user_meta($user_id, 'first_name', 'true');
             $affilate_name = $firstname . ' ' . $lastname;
             if (!$affilate_name) {
                 $affilate_name = $user_data->data->display_name;
             }
             $affiliate_email = get_post_meta($post_id, 'rf_reward_email', true);
             $this->reward_affiliate('sign_up', $affilate_name, $affiliate_email, $email, 0, array(), array());
             update_post_meta($post_id, 'is_rewarded_signup', 'yes');
         }
     }
 }
开发者ID:javolero,项目名称:dabba,代码行数:39,代码来源:referfriend-myaccount.php


示例11: is_hidden_on

 /**
  * Verify if users has the option to hide the Attendees list, applys a good filter
  *
  * @param  int|WP_Post  $post
  * @return boolean
  */
 public static function is_hidden_on($post)
 {
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     if (!$post instanceof WP_Post) {
         return false;
     }
     $is_hidden = get_post_meta($post->ID, self::HIDE_META_KEY, true);
     // By default non-existent meta will be an empty string
     if ('' === $is_hidden) {
         $is_hidden = true;
     } else {
         $is_hidden = (bool) $is_hidden;
     }
     /**
      * Use this to filter and hide the Attendees List for a specific post or all of them
      *
      * @param bool $is_hidden
      * @param WP_Post $post
      */
     return apply_filters('tribe_tickets_plus_hide_attendees_list', $is_hidden, $post);
 }
开发者ID:TakenCdosG,项目名称:chefs,代码行数:29,代码来源:Attendees_List.php


示例12: send_email

 public static function send_email(array &$recipients, $post_id, WSKL_Inactive_Accounts_Shortcodes $shortcodes)
 {
     $post = WP_Post::get_instance($post_id);
     if (!$post) {
         error_log("\$post (ID: {$post_id}) returned false. Notification halted.");
         return;
     }
     $success_count = 0;
     $failure_count = 0;
     /** @var WP_User|array|string $recipient if it is an array, 'name', and 'addr' keys are set. */
     foreach ($recipients as $recipient) {
         $shortcodes->set_recipient($recipient);
         $address = self::get_recipient_address($recipient);
         $subject = do_shortcode($post->post_title);
         $message = wptexturize(wpautop(do_shortcode($post->post_content)));
         if (wp_mail($address, $subject, $message)) {
             ++$success_count;
         } else {
             ++$failure_count;
         }
     }
     error_log("Message sent to {$success_count} users. {$failure_count} failed.");
 }
开发者ID:EricKim65,项目名称:woosym-korean-localization,代码行数:23,代码来源:class-wskl-inactive-accounts-email.php


示例13: get_post

 /**
  * Get a post object that represents a field group.
  *
  * @param int|string|WP_Post $field_group Numeric ID of the post, post slug or a post object.
  *
  * @return null|WP_Post Requested post object when the post exists and has correct post type. Null otherwise.
  */
 protected final function get_post($field_group)
 {
     $fg_post = null;
     // http://stackoverflow.com/questions/2559923/shortest-way-to-check-if-a-variable-contains-positive-integer-using-php
     if (is_scalar($field_group) && $field_group == (int) $field_group && (int) $field_group > 0) {
         $fg_post = WP_Post::get_instance($field_group);
     } else {
         if (is_string($field_group)) {
             $query = new WP_Query(array('post_type' => $this->get_post_type(), 'name' => $field_group, 'posts_per_page' => 1));
             if ($query->have_posts()) {
                 $fg_post = $query->get_posts();
                 $fg_post = $fg_post[0];
             }
         } else {
             $fg_post = $field_group;
         }
     }
     if ($fg_post instanceof WP_Post && $this->get_post_type() == $fg_post->post_type) {
         return $fg_post;
     } else {
         return null;
     }
 }
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:30,代码来源:factory.php


示例14: tribe_events_get_the_excerpt

 /**
  * A Excerpt method used across the board on our Events Plugin Suite.
  *
  * By default it removes all shortcodes, the reason for this is that shortcodes added by other plugins/themes
  * may not have been registered by the time our ajax responses are generated. To avoid leaving unparsed
  * shortcodes in our excerpts then we strip out anything that looks like one.
  *
  * @category Events
  *
  * @param  WP_Post|int|null $post The Post Object|ID, if null defaults to `get_the_ID()`
  * @param  array $allowed_html The wp_kses compatible array
  *
  * @return string|null Will return null on Bad Post Instances
  */
 function tribe_events_get_the_excerpt($post = null, $allowed_html = null)
 {
     // If post is not numeric or instance of WP_Post it defaults to the current Post ID
     if (!is_numeric($post) && !$post instanceof WP_Post) {
         $post = get_the_ID();
     }
     // If not a WP_Post we try to fetch it as one
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     // Prevent Non usable $post instances
     if (!$post instanceof WP_Post) {
         return null;
     }
     // Default Allowed HTML
     if (!is_array($allowed_html)) {
         $base_attrs = array('class' => array(), 'id' => array(), 'style' => array());
         $allowed_html = array('a' => array('class' => array(), 'id' => array(), 'style' => array(), 'href' => array(), 'rel' => array(), 'target' => array()), 'b' => $base_attrs, 'strong' => $base_attrs, 'em' => $base_attrs, 'span' => $base_attrs, 'ul' => $base_attrs, 'li' => $base_attrs, 'ol' => $base_attrs);
     }
     /**
      * Allow developers to filter what are the allowed HTML on the Excerpt
      *
      * @var array Must be compatible to wp_kses structure
      *
      * @link https://codex.wordpress.org/Function_Reference/wp_kses
      */
     $allowed_html = apply_filters('tribe_events_excerpt_allowed_html', $allowed_html, $post);
     /**
      * Allow shortcodes to be Applied on the Excerpt or not
      *
      * @var bool
      */
     $allow_shortcode = apply_filters('tribe_events_excerpt_allow_shortcode', false);
     // Get the Excerpt or content based on what is available
     if (has_excerpt($post->ID)) {
         $excerpt = $post->post_excerpt;
     } else {
         $excerpt = $post->post_content;
     }
     // Remove all shortcode Content before removing HTML
     if (!$allow_shortcode) {
         $excerpt = preg_replace('#\\[.+\\]#U', '', $excerpt);
     }
     // Remove "all" HTML based on what is allowed
     $excerpt = wp_kses($excerpt, $allowed_html);
     // Still treat this as an Excerpt on WP
     $excerpt = wp_trim_excerpt($excerpt);
     return wpautop($excerpt);
 }
开发者ID:reubenbrown13,项目名称:the-events-calendar,代码行数:63,代码来源:general.php


示例15: get_instance

 public static function get_instance($post_id)
 {
     return WP_Post::get_instance($post_id);
 }
开发者ID:robertoperata,项目名称:bbqverona.com,代码行数:4,代码来源:class.wp-testimonial.php


示例16: googleCalendarLink

 /**
  * Returns the GCal export link for a given event id.
  *
  * @param int|WP_Post|null $post The Event Post Object or ID, if left empty will give get the current post.
  *
  * @return string The URL for the GCal export link.
  */
 public function googleCalendarLink($post = null)
 {
     if (is_null($post)) {
         $post = self::postIdHelper($post);
     }
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     if (!$post instanceof WP_Post) {
         return false;
     }
     // After this point we know that we have a safe WP_Post object
     // Fetch if the Event is a Full Day Event
     $is_all_day = Tribe__Date_Utils::is_all_day(get_post_meta($post->ID, '_EventAllDay', true));
     // Fetch the required Date TimeStamps
     $start_date = Tribe__Events__Timezones::event_start_timestamp($post->ID);
     // Google Requires that a Full Day event end day happens on the next Day
     $end_date = Tribe__Events__Timezones::event_end_timestamp($post->ID) + ($is_all_day ? DAY_IN_SECONDS : 0);
     if ($is_all_day) {
         $dates = date('Ymd', $start_date) . '/' . date('Ymd', $end_date);
     } else {
         $dates = date('Ymd', $start_date) . 'T' . date('Hi00', $start_date) . '/' . date('Ymd', $end_date) . 'T' . date('Hi00', $end_date);
     }
     // Fetch the
     $location = trim($this->fullAddressString($post->ID));
     $event_details = apply_filters('the_content', get_the_content($post->ID));
     // Hack: Add space after paragraph
     // Normally Google Cal understands the newline character %0a
     // And that character will automatically replace newlines on urlencode()
     $event_details = str_replace('</p>', '</p> ', $event_details);
     $event_details = strip_tags($event_details);
     //Truncate Event Description and add permalink if greater than 996 characters
     if (strlen($event_details) > 996) {
         $event_url = get_permalink($post->ID);
         $event_details = substr($event_details, 0, 996);
         //Only add the permalink if it's shorter than 900 characters, so we don't exceed the browser's URL limits
         if (strlen($event_url) < 900) {
             $event_details .= sprintf(esc_html__(' (View Full %1$s Description Here: %2$s)', 'the-events-calendar'), $this->singular_event_label, $event_url);
         }
     }
     $params = array('action' => 'TEMPLATE', 'text' => urlencode(strip_tags($post->post_title)), 'dates' => $dates, 'details' => urlencode($event_details), 'location' => urlencode($location), 'trp' => 'false', 'sprop' => 'website:' . home_url());
     $timezone = Tribe__Events__Timezones::get_event_timezone_string($post->ID);
     $timezone = Tribe__Events__Timezones::maybe_get_tz_name($timezone);
     // If we have a good timezone string we setup it; UTC doesn't work on Google
     if (false !== $timezone) {
         $params['ctz'] = urlencode($timezone);
     }
     /**
      * Allow users to Filter our Google Calendar Link params
      * @var array Params used in the add_query_arg
      * @var int   Event ID
      */
     $params = apply_filters('tribe_google_calendar_parameters', $params, $post->ID);
     $base_url = 'http://www.google.com/calendar/event';
     $url = add_query_arg($params, $base_url);
     return $url;
 }
开发者ID:TakenCdosG,项目名称:chefs,代码行数:64,代码来源:Main.php


示例17: tribe_events_get_the_excerpt

 /**
  * A Excerpt method used across the board on our Events Plugin Suite.
  *
  * By default it removes all shortcodes, the reason for this is that shortcodes added by other plugins/themes
  * may not have been registered by the time our ajax responses are generated. To avoid leaving unparsed
  * shortcodes in our excerpts then we strip out anything that looks like one.
  *
  * @category Events
  *
  * @param  WP_Post|int|null $post The Post Object|ID, if null defaults to `get_the_ID()`
  * @param  array $allowed_html The wp_kses compatible array
  *
  * @return string|null Will return null on Bad Post Instances
  */
 function tribe_events_get_the_excerpt($post = null, $allowed_html = null)
 {
     // If post is not numeric or instance of WP_Post it defaults to the current Post ID
     if (!is_numeric($post) && !$post instanceof WP_Post) {
         $post = get_the_ID();
     }
     // If not a WP_Post we try to fetch it as one
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     // Prevent Non usable $post instances
     if (!$post instanceof WP_Post) {
         return null;
     }
     // Default Allowed HTML
     if (!is_array($allowed_html)) {
         $base_attrs = array('class' => array(), 'id' => array(), 'style' => array());
         $allowed_html = array('a' => array('class' => array(), 'id' => array(), 'style' => array(), 'href' => array(), 'rel' => array(), 'target' => array()), 'b' => $base_attrs, 'strong' => $base_attrs, 'em' => $base_attrs, 'span' => $base_attrs, 'ul' => $base_attrs, 'li' => $base_attrs, 'ol' => $base_attrs);
     }
     /**
      * Allow developers to filter what are the allowed HTML on the Excerpt
      *
      * @var array Must be compatible to wp_kses structure
      *
      * @link https://codex.wordpress.org/Function_Reference/wp_kses
      */
     $allowed_html = apply_filters('tribe_events_excerpt_allowed_html', $allowed_html, $post);
     /**
      * Allow shortcodes to be Applied on the Excerpt or not
      *
      * @var bool
      */
     $allow_shortcode = apply_filters('tribe_events_excerpt_allow_shortcode', false);
     // Get the Excerpt or content based on what is available
     if (has_excerpt($post->ID)) {
         $excerpt = $post->post_excerpt;
     } else {
         $excerpt = $post->post_content;
     }
     // Remove all shortcode Content before removing HTML
     if (!$allow_shortcode) {
         $excerpt = preg_replace('#\\[.+\\]#U', '', $excerpt);
     }
     // Remove "all" HTML based on what is allowed
     $excerpt = wp_kses($excerpt, $allowed_html);
     /**
      * Filter the number of words in an excerpt.
      *
      * @param int $number The number of words. Default 55.
      */
     $excerpt_length = apply_filters('excerpt_length', 55);
     /**
      * Filter the string in the "more" link displayed after a trimmed excerpt.
      *
      * @param string $more_string The string shown within the more link.
      */
     $excerpt_more = apply_filters('excerpt_more', ' [&hellip;]');
     // Now we actually trim it
     $excerpt = wp_trim_words($excerpt, $excerpt_length, $excerpt_more);
     return wpautop($excerpt);
 }
开发者ID:rmacdon465,项目名称:the-events-calendar,代码行数:75,代码来源:general.php


示例18: create

 /**
  * Creates a download
  *
  * @since  2.3.6
  * @param  array  $data Array of attributes for a download
  * @return mixed  false if data isn't passed and class not instantiated for creation, or New Download ID
  */
 public function create($data = array())
 {
     if ($this->id != 0) {
         return false;
     }
     $defaults = array('post_type' => 'download', 'post_status' => 'draft', 'post_title' => __('New Download Product', 'easy-digital-downloads'));
     $args = wp_parse_args($data, $defaults);
     do_action('edd_download_pre_create', $args);
     $id = wp_insert_post($args, true);
     $download = WP_Post::get_instance($id);
     do_action('edd_download_post_create', $id, $args);
     return $this->setup_download($download);
 }
开发者ID:Balamir,项目名称:Easy-Digital-Downloads,代码行数:20,代码来源:class-edd-download.php


示例19: updateAll

 /**
  * Update all taxonomies.
  * This should only ever be called from a cron job scheduled by EasyRecipeScheduler because it can potentially take quite a while
  */
 function updateAll()
 {
     /** @var wpdb $wpdb */
     global $wpdb;
     /**
      * If we are already running, don't do it again
      */
     if ($this->scheduler->isRunning()) {
         return;
     }
     /**
      * Set as running
      * Set a "timeout" of 10 minutes. This will prevent it being re-run for 10 minutes if the current run terminates abnormally for any reason
      */
     $this->scheduler->setRunning(10 * 60);
     $q = "SELECT ID FROM {$wpdb->posts} WHERE post_type NOT IN ('attachment','index','nav_menu_item')";
     $postIDs = $wpdb->get_col($q);
     $this->countTerms['cuisine'] = array();
     $this->countTerms['course'] = array();
     foreach ($postIDs as $postID) {
         $post = WP_Post::get_instance($postID);
         $this->update($post, false);
     }
     /**
      * Update any term counts that we may have adjusted
      */
     if (count($this->countTerms['cuisine']) > 0) {
         wp_update_term_count_now(array_unique(array_keys($this->countTerms['cuisine'])), 'cuisine');
     }
     if (count($this->countTerms['course']) > 0) {
         wp_update_term_count_now(array_unique(array_keys($this->countTerms['course'])), 'course');
     }
     /**
      * Mark the taxonomies as having been created
      */
     $settings = EasyRecipeSettings::getInstance();
     $settings->taxonomiesCreated = true;
     $settings->update();
     /**
      * Mark this job as complete
      */
     $this->scheduler->terminate();
 }
开发者ID:Bakerpedia,项目名称:Developement_WPengine,代码行数:47,代码来源:EasyRecipeTaxonomies.php


示例20: __construct

 /**
  * Get things going
  *
  * @since	1.0
  */
 public function __construct($_id = false, $_args = array())
 {
     $form = WP_Post::get_instance($_id);
     return $this->setup_form($form, $_args);
 }
开发者ID:KB-Support,项目名称:kb-support,代码行数:10,代码来源:class-kbs-form.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP WP_Query类代码示例发布时间:2022-05-23
下一篇:
PHP WP_Mock类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap