本文整理汇总了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;
}
示例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;
}
示例3: getInstance
public static function getInstance($pid)
{
$post = new self($pid);
$post->setPost(\WP_Post::get_instance($pid));
$post->fetch();
return $post;
}
示例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);
}
示例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));
}
}
示例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;
}
示例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;
}
}
示例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');
}
}
}
示例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);
}
示例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.");
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}