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


PHP WP_Post::get_instance方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: __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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: make_new_item

 /**
  * Create new Instance of a Post MVI
  *
  * @param WP_Post|int $_post
  * @param array $args {
  *
  *      @type string $instance_class
  *      @type string $list_owner
  *
  *}
  * @return mixed
  *
  * @future Alias this with make_new_post() so it can be called as WPLib::make_new_post( $post_id )
  */
 static function make_new_item($_post, $args = array())
 {
     $args = wp_parse_args($args, array('instance_class' => false, 'list_owner' => 'WPLib_Posts'));
     if (is_numeric($_post)) {
         $_post = WP_Post::get_instance($_post);
     }
     if (!$args['instance_class']) {
         $args['instance_class'] = WPLib::get_constant('INSTANCE_CLASS', $args['list_owner']);
     }
     if (!$args['instance_class']) {
         $args['instance_class'] = self::get_post_type_class($_post->post_type);
     }
     $instance_class = $args['instance_class'];
     return $instance_class ? new $instance_class($_post) : null;
 }
开发者ID:wplib,项目名称:wplib,代码行数:29,代码来源:posts.php

示例14: fetch_post_by_id

 /**
  * Returns Post Array from ID.
  * Also returns latest post from blog or archive if applicable.
  *
  * @since 2.6.0
  * @since 2.6.6 Added $output parameter.
  *
  * @param int $the_id The Post ID.
  * @param int $tt_id The Taxonomy Term ID
  * @param mixed $output The value type to return. Accepts OBJECT, ARRAY_A, or ARRAY_N
  * @return empty|array The Post Array.
  */
 protected function fetch_post_by_id($the_id = '', $tt_id = '', $output = ARRAY_A)
 {
     if ('' === $the_id && '' === $tt_id) {
         $the_id = $this->get_the_real_ID();
         if (false === $the_id) {
             return '';
         }
     }
     /**
      * @since 2.2.8 Use the 2nd parameter.
      * @since 2.3.3 Now casts to array
      */
     if ('' !== $the_id) {
         if ($this->is_blog_page($the_id)) {
             $args = array('posts_per_page' => 1, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish', 'cache_results' => false);
             $post = get_posts($args);
         } else {
             $post = get_post($the_id);
         }
     } elseif ('' !== $tt_id) {
         /**
          * @since 2.3.3 Match the descriptions in admin as on the front end.
          */
         $args = array('posts_per_page' => 1, 'offset' => 0, 'category' => $tt_id, 'category_name' => '', 'post_type' => 'post', 'post_status' => 'publish', 'cache_results' => false);
         $post = get_posts($args);
     } else {
         $post = get_post($the_id);
     }
     /**
      * @since 2.6.5 Transform post array to object (on Archives).
      */
     if (is_array($post) && isset($post[0]) && is_object($post[0])) {
         $post = $post[0];
     }
     //* Something went wrong, nothing to be found. Return empty.
     if (empty($post)) {
         return '';
     }
     //* Stop getting something that doesn't exists. E.g. 404
     if (isset($post->ID) && 0 === $post->ID) {
         return '';
     }
     /**
      * @since 2.6.6
      */
     if (ARRAY_A === $output || ARRAY_N === $output) {
         $_post = WP_Post::get_instance($post);
         $post = $_post->to_array();
         if (ARRAY_N === $output) {
             $post = array_values($post);
         }
     }
     return $post;
 }
开发者ID:sybrew,项目名称:the-seo-framework,代码行数:66,代码来源:post-data.class.php

示例15: related

    public function related($postTypes, $limit)
    {
        global $wpdb;
        array_walk($postTypes, function (&$value, $index) {
            $value = "'{$value}'";
        });
        $postTypes = implode(',', $postTypes);
        $query = <<<QUERY
SELECT WP.ID, COUNT(*) AS tag_count, rand() as random FROM  wp_term_relationships T1 JOIN  wp_term_relationships T2
ON
\tT1.term_taxonomy_id = T2.term_taxonomy_id
AND
\tT1.object_id != T2.object_id
JOIN
\twp_posts WP
ON
\tT2.object_id = WP.ID
WHERE
\tT1.object_id = {$this->id}
    AND WP.post_status='publish'
    and WP.post_type in ({$postTypes})
GROUP BY
\tT2.object_id
ORDER BY COUNT(*) DESC, random desc
limit {$limit}
QUERY;
        $results = $wpdb->get_results($query);
        $related = [];
        if ($results) {
            foreach ($results as $result) {
                $related[] = $this->context->modelForPost(\WP_Post::get_instance($result->ID));
            }
        }
        return $related;
    }
开发者ID:jawngee,项目名称:Stem,代码行数:35,代码来源:Post.php


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