当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Post类代码示例

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


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


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