/**
  * Mostly the same as `get_metadata()` makes sure any postthumbnail function gets checked at
  * the deepest level possible.
  *
  * @see /wp-includes/meta.php get_metadata()
  *
  * @param null $null
  * @param int $object_id ID of the object metadata is for
  * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
  *   the specified object.
  * @param bool $single Optional, default is false. If true, return only the first value of the
  *   specified meta_key. This parameter has no effect if meta_key is not specified.
  * @return string|array Single metadata value, or array of values
  */
 function set_dfi_meta_key($null = null, $object_id, $meta_key, $single)
 {
     // only affect thumbnails on the frontend, do allow ajax calls
     if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX) || '_thumbnail_id' != $meta_key) {
         return $null;
     }
     $meta_type = 'post';
     $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
     if (!$meta_cache) {
         $meta_cache = update_meta_cache($meta_type, array($object_id));
         $meta_cache = $meta_cache[$object_id];
     }
     if (!$meta_key) {
         return $meta_cache;
     }
     if (isset($meta_cache[$meta_key])) {
         if ($single) {
             return maybe_unserialize($meta_cache[$meta_key][0]);
         } else {
             return array_map('maybe_unserialize', $meta_cache[$meta_key]);
         }
     }
     if ($single) {
         // allow to set an other ID see the readme.txt for details
         return apply_filters('dfi_thumbnail_id', get_option('dfi_image_id'), $object_id);
     } else {
         return array();
     }
 }
Esempio n. 2
0
 /**
  * Pre-populates the p2p meta cache to decrease the number of queries.
  */
 static function cache_p2p_meta($the_posts, $wp_query)
 {
     if (isset($wp_query->_p2p_query) && !empty($the_posts)) {
         update_meta_cache('p2p', wp_list_pluck($the_posts, 'p2p_id'));
     }
     return $the_posts;
 }
 private static function get_meta_cache($object_id, $meta_type)
 {
     $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
     if (!$meta_cache) {
         $meta_cache = update_meta_cache($meta_type, array($object_id));
         $meta_cache = $meta_cache[$object_id];
     }
     return $meta_cache;
 }
 /**
  * Register all active member types
  * 
  */
 public function register_member_type()
 {
     //$this->register_post_type();
     $is_root_blog = bp_is_root_blog();
     //if we are not on the main bp site, switch to it before registering member type
     if (!$is_root_blog) {
         switch_to_blog(bp_get_root_blog_id());
     }
     //get all posts in memeber type post type
     $post_ids = $this->get_active_member_types();
     // get_posts( array( 'post_type'=> bp_member_type_generator()->get_post_type(), 'posts_per_page'=> -1, 'post_status'=> 'publish' ) );
     //update meta cache to avoid multiple db calls
     update_meta_cache('post', $post_ids);
     //build to register the memebr type
     $member_types = array();
     foreach ($post_ids as $post_id) {
         $is_active = get_post_meta($post_id, '_bp_member_type_is_active', true);
         $name = get_post_meta($post_id, '_bp_member_type_name', true);
         if (!$is_active || !$name) {
             continue;
             //if not active or no unique key, do not register
         }
         $enable_directory = get_post_meta($post_id, '_bp_member_type_enable_directory', true);
         $directory_slug = get_post_meta($post_id, '_bp_member_type_directory_slug', true);
         $has_dir = false;
         if ($enable_directory) {
             if ($directory_slug) {
                 $has_dir = $directory_slug;
             } else {
                 $has_dir = true;
             }
         }
         $member_types[$name] = array('labels' => array('name' => get_post_meta($post_id, '_bp_member_type_label_name', true), 'singular_name' => get_post_meta($post_id, '_bp_member_type_label_singular_name', true)), 'has_directory' => $has_dir);
     }
     foreach ($member_types as $member_type => $args) {
         bp_register_member_type($member_type, $args);
     }
     if (!$is_root_blog) {
         restore_current_blog();
     }
 }
function metadata_exists($meta_type, $object_id, $meta_key)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /** This filter is documented in wp-includes/meta.php */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, true);
    if (null !== $check) {
        return (bool) $check;
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (isset($meta_cache[$meta_key])) {
        return true;
    }
    return false;
}
Esempio n. 6
0
/**
 * Perform the query to get the $metavalues array(s) needed by _fill_user and _fill_many_users
 *
 * @since 3.0.0
 * @deprecated 3.3.0
 *
 * @param array $ids User ID numbers list.
 * @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays.
 */
function get_user_metavalues($ids)
{
    _deprecated_function(__FUNCTION__, '3.3');
    $objects = array();
    $ids = array_map('intval', $ids);
    foreach ($ids as $id) {
        $objects[$id] = array();
    }
    $metas = update_meta_cache('user', $ids);
    foreach ($metas as $id => $meta) {
        foreach ($meta as $key => $metavalues) {
            foreach ($metavalues as $value) {
                $objects[$id][] = (object) array('user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);
            }
        }
    }
    return $objects;
}
/**
 * Updates metadata cache for list of term IDs.
 *
 * Performs SQL query to retrieve all metadata for the terms matching `$term_ids` and stores them in the cache.
 * Subsequent calls to `get_term_meta()` will not need to query the database.
 *
 * @since 4.4.0
 *
 * @param array $term_ids List of term IDs.
 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
 */
function update_termmeta_cache($term_ids)
{
    // Bail if term meta table is not installed.
    if (get_option('db_version') < 34370) {
        return;
    }
    return update_meta_cache('term', $term_ids);
}
 /**
  * get_events_between function
  *
  * Return all events starting after the given start time and before the
  * given end time that the currently logged in user has permission to view.
  * If $spanning is true, then also include events that span this
  * period. All-day events are returned first.
  *
  * @param int $start_time   limit to events starting after this (local) UNIX time
  * @param int $end_time     limit to events starting before this (local) UNIX time
  * @param array $filter     Array of filters for the events returned:
  *                          ['cat_ids']   => non-associatative array of category IDs
  *                          ['tag_ids']   => non-associatative array of tag IDs
  *                          ['post_ids']  => non-associatative array of post IDs
  *                          ['auth_ids']  => non-associatative array of author IDs
  * @param bool $spanning    also include events that span this period
  *
  * @return array            list of matching event objects
  */
 function get_events_between($start_time, $end_time, $filter, $spanning = false)
 {
     global $wpdb, $ai1ec_events_helper, $ai1ec_localization_helper;
     // Convert timestamps to MySQL format in GMT time
     $start_time = $ai1ec_events_helper->local_to_gmt($start_time);
     $end_time = $ai1ec_events_helper->local_to_gmt($end_time);
     // Query arguments
     $args = array($start_time, $end_time);
     // Get post status Where snippet and associated SQL arguments
     $this->_get_post_status_sql($post_status_where, $args);
     // Get the Join (filter_join) and Where (filter_where) statements based on
     // $filter elements specified
     $this->_get_filter_sql($filter);
     $wpml_join_particle = $ai1ec_localization_helper->get_wpml_table_join('p.ID');
     $wpml_where_particle = $ai1ec_localization_helper->get_wpml_table_where();
     $query = $wpdb->prepare("SELECT p.*, e.post_id, i.id AS instance_id, " . "i.start AS start, " . "i.end AS end, " . 'e.allday AS event_allday, ' . "e.recurrence_rules, e.exception_rules, e.recurrence_dates, e.exception_dates, " . "e.venue, e.country, e.address, e.city, e.province, e.postal_code, e.instant_event, " . "e.show_map, e.contact_name, e.contact_phone, e.contact_email, e.cost, e.ticket_url, " . "e.ical_feed_url, e.ical_source_url, e.ical_organizer, e.ical_contact, e.ical_uid " . "FROM {$wpdb->prefix}ai1ec_events e " . "INNER JOIN {$wpdb->posts} p ON p.ID = e.post_id " . $wpml_join_particle . "INNER JOIN {$wpdb->prefix}ai1ec_event_instances i ON e.post_id = i.post_id " . $filter['filter_join'] . "WHERE post_type = '" . AI1EC_POST_TYPE . "' " . $wpml_where_particle . "AND " . ($spanning ? "i.end > %d AND i.start < %d " : "i.start BETWEEN %d AND %d ") . $filter['filter_where'] . $post_status_where . 'GROUP BY i.id ' . 'ORDER BY allday DESC, i.start ASC, post_title ASC', $args);
     $events = $wpdb->get_results($query, ARRAY_A);
     $id_list = array();
     foreach ($events as $event) {
         $id_list[] = $event['post_id'];
     }
     if (!empty($id_list)) {
         update_meta_cache('post', $id_list);
     }
     foreach ($events as &$event) {
         $event['start'] = $event['start'];
         $event['end'] = $event['end'];
         $event['allday'] = $this->_is_all_day($event);
         $event = new Ai1ec_Event($event);
     }
     return $events;
 }
Esempio n. 9
0
 function update_termmeta_cache($term_ids)
 {
     return update_meta_cache('term', $term_ids);
 }
Esempio n. 10
0
/**
 * Filters 'img' elements in post content to add 'srcset' and 'sizes' attributes.
 *
 * @since 4.4.0
 *
 * @see wp_image_add_srcset_and_sizes()
 *
 * @param string $content The raw post content to be filtered.
 * @return string Converted content with 'srcset' and 'sizes' attributes added to images.
 */
function wp_make_content_images_responsive($content)
{
    if (!preg_match_all('/<img [^>]+>/', $content, $matches)) {
        return $content;
    }
    $selected_images = $attachment_ids = array();
    foreach ($matches[0] as $image) {
        if (false === strpos($image, ' srcset=') && preg_match('/wp-image-([0-9]+)/i', $image, $class_id) && ($attachment_id = absint($class_id[1]))) {
            /*
             * If exactly the same image tag is used more than once, overwrite it.
             * All identical tags will be replaced later with 'str_replace()'.
             */
            $selected_images[$image] = $attachment_id;
            // Overwrite the ID when the same image is included more than once.
            $attachment_ids[$attachment_id] = true;
        }
    }
    if (count($attachment_ids) > 1) {
        /*
         * Warm object cache for use with 'get_post_meta()'.
         *
         * To avoid making a database call for each image, a single query
         * warms the object cache with the meta information for all images.
         */
        update_meta_cache('post', array_keys($attachment_ids));
    }
    foreach ($selected_images as $image => $attachment_id) {
        $image_meta = get_post_meta($attachment_id, '_wp_attachment_metadata', true);
        $content = str_replace($image, wp_image_add_srcset_and_sizes($image, $image_meta, $attachment_id), $content);
    }
    return $content;
}
Esempio n. 11
0
function dsq_clear_pending_post_ids($post_ids)
{
    if (count($post_ids) < 1) {
        return;
    }
    global $wpdb;
    $posts_query = implode(', ', array_fill(0, count($post_ids), '%s'));
    // add as many placeholders as needed
    $sql = "\r\n        DELETE FROM {$wpdb->postmeta} \r\n        WHERE meta_key = 'dsq_needs_sync' AND post_id IN (" . $posts_query . ")\r\n    ";
    // Call $wpdb->prepare passing the values of the array as separate arguments
    $query = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql), $post_ids));
    $wpdb->query($query);
    update_meta_cache('dsq_needs_sync', $post_ids);
}
Esempio n. 12
0
/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $object_id ID of the object metadata is for
 * @param string $meta_key Optional.  Metadata key.  If not specified, retrieve all metadata for
 * 		the specified object.
 * @param bool $single Optional, default is false.  If true, return only the first value of the
 * 		specified meta_key.  This parameter has no effect if meta_key is not specified.
 * @return string|array Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type) {
        return false;
    }
    if (!($object_id = absint($object_id))) {
        return false;
    }
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}
Esempio n. 13
0
 /**
  * @param $object_type
  * @param null $_null
  * @param int $object_id
  * @param string $meta_key
  * @param bool $single
  *
  * @return array|bool|int|mixed|null|string|void
  */
 public function get_meta($object_type, $_null = null, $object_id = 0, $meta_key = '', $single = false)
 {
     $meta_type = $object_type;
     if ('post_type' == $meta_type) {
         $meta_type = 'post';
     }
     if (empty($meta_key)) {
         $single = false;
     }
     $object = $this->get_object($object_type, $object_id);
     if (empty($object_id) || empty($object)) {
         return $_null;
     }
     $no_conflict = pods_no_conflict_check($meta_type);
     if (!$no_conflict) {
         pods_no_conflict_on($meta_type);
     }
     $meta_cache = array();
     if (!$single && isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
         $meta_cache = wp_cache_get($object_id, 'pods_' . $meta_type . '_meta');
         if (empty($meta_cache)) {
             $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
             if (empty($meta_cache)) {
                 $meta_cache = update_meta_cache($meta_type, array($object_id));
                 $meta_cache = $meta_cache[$object_id];
             }
         }
     }
     if (empty($meta_cache) || !is_array($meta_cache)) {
         $meta_cache = array();
     }
     $pod = pods($object['name']);
     $meta_keys = array($meta_key);
     if (empty($meta_key)) {
         $meta_keys = array_keys($meta_cache);
     }
     $key_found = false;
     foreach ($meta_keys as $meta_k) {
         if (!empty($pod)) {
             if (isset($pod->fields[$meta_k])) {
                 if (empty($pod->id)) {
                     $pod->fetch($object_id);
                     $pod->id = $object_id;
                 }
                 $key_found = true;
                 $meta_cache[$meta_k] = $pod->field(array('name' => $meta_k, 'single' => $single, 'get_meta' => true));
                 if (!is_array($meta_cache[$meta_k]) || !isset($meta_cache[$meta_k][0])) {
                     if (empty($meta_cache[$meta_k]) && !is_array($meta_cache[$meta_k]) && $single) {
                         $meta_cache[$meta_k] = array();
                     } else {
                         $meta_cache[$meta_k] = array($meta_cache[$meta_k]);
                     }
                 }
                 if (in_array($pod->fields[$meta_k]['type'], PodsForm::tableless_field_types()) && isset($meta_cache['_pods_' . $meta_k])) {
                     unset($meta_cache['_pods_' . $meta_k]);
                 }
             } elseif (false !== strpos($meta_k, '.')) {
                 if (empty($pod->id)) {
                     $pod->fetch($object_id);
                     $pod->id = $object_id;
                 }
                 $key_found = true;
                 $first = current(explode('.', $meta_k));
                 if (isset($pod->fields[$first])) {
                     $meta_cache[$meta_k] = $pod->field(array('name' => $meta_k, 'single' => $single, 'get_meta' => true));
                     if ((!is_array($meta_cache[$meta_k]) || !isset($meta_cache[$meta_k][0])) && $single) {
                         if (empty($meta_cache[$meta_k]) && !is_array($meta_cache[$meta_k]) && $single) {
                             $meta_cache[$meta_k] = array();
                         } else {
                             $meta_cache[$meta_k] = array($meta_cache[$meta_k]);
                         }
                     }
                     if (in_array($pod->fields[$first]['type'], PodsForm::tableless_field_types()) && isset($meta_cache['_pods_' . $first])) {
                         unset($meta_cache['_pods_' . $first]);
                     }
                 }
             }
         }
     }
     if (!$no_conflict) {
         pods_no_conflict_off($meta_type);
     }
     unset($pod);
     // memory clear
     if (!$key_found) {
         return $_null;
     }
     if (!$single && isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
         wp_cache_set($object_id, $meta_cache, 'pods_' . $meta_type . '_meta');
     }
     if (empty($meta_key)) {
         return $meta_cache;
     } elseif (isset($meta_cache[$meta_key])) {
         $value = $meta_cache[$meta_key];
     } else {
         $value = '';
     }
     if (!is_numeric($value) && empty($value)) {
         if ($single) {
             $value = '';
         } else {
             $value = array();
         }
     } elseif (!is_array($value)) {
         $value = array($value);
     }
     return $value;
 }
Esempio n. 14
0
 /**
  * Convert old parameter names to new ones in DataTables "Custom Commands".
  * DataTables 1.9 used Hungarian notation, while DataTables 1.10+ (used since TablePress 1.5) uses camelCase notation.
  *
  * @since 1.5.0
  */
 public function convert_datatables_parameter_names_tp15()
 {
     $table_post = $this->tables->get('table_post');
     if (empty($table_post)) {
         return;
     }
     // Prime the meta cache with the table options of all tables.
     update_meta_cache('post', array_values($table_post));
     foreach ($table_post as $table_id => $post_id) {
         $table_options = $this->_get_table_options($post_id);
         // Nothing to do if there are no "Custom Commands".
         if (empty($table_options['datatables_custom_commands'])) {
             continue;
         }
         // Run search/replace.
         $old_custom_commands = $table_options['datatables_custom_commands'];
         $table_options['datatables_custom_commands'] = strtr($table_options['datatables_custom_commands'], $this->datatables_parameter_mappings);
         // No need to save (which runs a DB query) if nothing was replaced in the "Custom Commands".
         if ($old_custom_commands === $table_options['datatables_custom_commands']) {
             continue;
         }
         $this->_update_table_options($post_id, $table_options);
     }
 }
function dsq_clear_pending_post_ids($post_ids)
{
    global $wpdb;
    $post_ids_query = "'" . implode("', '", $post_ids) . "'";
    $wpdb->query($wpdb->prepare("\r\n        DELETE FROM {$wpdb->postmeta} \r\n        WHERE meta_key = 'dsq_needs_sync' AND post_id IN (%s)\r\n    ", $post_ids_query));
    update_meta_cache('dsq_needs_sync', $post_ids);
}
Esempio n. 16
0
/**
 * Get a post meta or, if it's never been saved, return false. This function is based on the "get_metadata" function in WP core.
 *
 * @param int $object_id ID of the object metadata is for
 * @param string $meta_key Metadata key. 
 * @return string If never been saved return: 'never_been_saved_73698363746983746' otherwise return the value saved for this meta. 
 */
function mp_core_get_post_meta_or_never_been_saved($object_id, $meta_key)
{
    if (!is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filter whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, $meta_type, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should
     *                                     return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param string|array      $single    Meta value, or an array of values.
     */
    $check = apply_filters("get_post_metadata", null, $object_id, $meta_key, true);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, 'post' . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache('post', array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        return maybe_unserialize($meta_cache[$meta_key][0]);
    }
    //Return string if this field has never been saved before (with the number added just to make it extremely unlikely that a field would save this exact value for another purpose. Don't hate the playa, hate the game).
    return 'never_been_saved_73698363746983746';
}
/**
 * @since 3.2.3 translation of meta data
 * @since 3.4.6.4 improved caching algorithm
 */
function qtranxf_translate_metadata($meta_type, $original_value, $object_id, $meta_key = '', $single = false)
{
    global $q_config;
    static $meta_cache_unserialized = array();
    if (!isset($q_config['url_info'])) {
        //qtranxf_dbg_log('qtranxf_filter_postmeta: too early: $object_id='.$object_id.'; $meta_key',$meta_key,true);
        return $original_value;
    }
    //qtranxf_dbg_log('qtranxf_filter_postmeta: $object_id='.$object_id.'; $meta_key=',$meta_key);
    //$meta_type = 'post';
    $lang = $q_config['language'];
    $cache_key = $meta_type . '_meta';
    $cache_key_lang = $cache_key . $lang;
    $meta_cache_wp = wp_cache_get($object_id, $cache_key);
    if ($meta_cache_wp) {
        //if there is wp cache, then we check if there is qtx cache
        $meta_cache = wp_cache_get($object_id, $cache_key_lang);
    } else {
        //reset qtx cache, since it would not be valid in the absence of wp cache
        qtranxf_cache_delete_metadata($meta_type, $object_id);
        $meta_cache = null;
    }
    if (!isset($meta_cache_unserialized[$meta_type])) {
        $meta_cache_unserialized[$meta_type] = array();
    }
    if (!isset($meta_cache_unserialized[$meta_type][$object_id])) {
        $meta_cache_unserialized[$meta_type][$object_id] = array();
    }
    $meta_unserialized =& $meta_cache_unserialized[$meta_type][$object_id];
    if (!$meta_cache) {
        if ($meta_cache_wp) {
            $meta_cache = $meta_cache_wp;
        } else {
            $meta_cache = update_meta_cache($meta_type, array($object_id));
            $meta_cache = $meta_cache[$object_id];
        }
        $meta_unserialized = array();
        //clear this cache if we are re-doing meta_cache
        //qtranxf_dbg_log('qtranxf_filter_postmeta: $object_id='.$object_id.'; $meta_cache before:',$meta_cache);
        foreach ($meta_cache as $mkey => $mval) {
            $meta_unserialized[$mkey] = array();
            if (strpos($mkey, '_url') !== false) {
                switch ($mkey) {
                    case '_menu_item_url':
                        break;
                        // function qtranxf_wp_get_nav_menu_items takes care of this later
                    // function qtranxf_wp_get_nav_menu_items takes care of this later
                    default:
                        foreach ($mval as $k => $v) {
                            $s = is_serialized($v);
                            if ($s) {
                                $v = unserialize($v);
                            }
                            $v = qtranxf_convertURLs($v, $lang);
                            $meta_unserialized[$mkey][$k] = $v;
                            if ($s) {
                                $v = serialize($v);
                            }
                            $meta_cache[$mkey][$k] = $v;
                        }
                        break;
                }
            } else {
                foreach ($mval as $k => $v) {
                    if (!qtranxf_isMultilingual($v)) {
                        continue;
                    }
                    $s = is_serialized($v);
                    if ($s) {
                        $v = unserialize($v);
                    }
                    $v = qtranxf_use($lang, $v, false, false);
                    $meta_unserialized[$mkey][$k] = $v;
                    if ($s) {
                        $v = serialize($v);
                    }
                    $meta_cache[$mkey][$k] = $v;
                }
            }
        }
        //qtranxf_dbg_log('qtranxf_filter_postmeta: $object_id='.$object_id.'; $meta_cache  after:',$meta_cache);
        wp_cache_set($object_id, $meta_cache, $cache_key_lang);
    }
    if (!$meta_key) {
        if ($single) {
            /**
             @since 3.2.9.9.7
             The code executed after a call to this filter in /wp-includes/meta.php,
             in function get_metadata, is apparently designed having non-empty $meta_key in mind:
            
             	if ( $single && is_array( $check ) ){
             		return $check[0];
             	}else
             		return $check;
            
             Following the logic of the code "if ( !$meta_key ) return $meta_cache;",
            		a few lines below in the same function, the code above rather have to be:
            
             	if ( $meta_key && $single && is_array( $check ) ){
             		return $check[0];
             	}else
             		return $check;
            
             WP assumes that, if $meta_key is empty, then $single must be 'false', but developers sometimes put 'true' anyway, as it is ignored in the original function. The line below offsets this imperfection.
             If WP ever fixes that place, this block of code can be removed.
            */
            return array($meta_cache);
        }
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        //cache unserialized values, just for the sake of performance.
        $meta_key_unserialized =& $meta_unserialized[$meta_key];
        if ($single) {
            if (!isset($meta_key_unserialized[0])) {
                $meta_key_unserialized[0] = maybe_unserialize($meta_cache[$meta_key][0]);
            }
        } else {
            foreach ($meta_cache[$meta_key] as $k => $v) {
                if (!isset($meta_key_unserialized[$k])) {
                    $meta_key_unserialized[$k] = maybe_unserialize($meta_cache[$meta_key][$k]);
                }
            }
        }
        return $meta_key_unserialized;
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}
 /**
  * Filters Post metadata being retrieved before it's returned to caller.
  *
  * @param mixed metadata The original metadata.
  * @param int object_id The post ID.
  * @param meta_key The metadata to be retrieved.
  * @return mixed The metadata value.
  */
 public function get_post_metadata($metadata, $object_id, $meta_key)
 {
     if (version_compare($this->wc()->version, '2.1', '>=')) {
         return $metadata;
     }
     // WooCommerce 2.0.x only
     // This method is only called during generation of "Sales overview" report
     // page. Order totals in base currency should be used for reporting.
     // NOTE: this method of returning the order totals in base currency is a hack,
     // but there is no other way to do it, because the "Sales overview" reports
     // don't call a hook that allows to alter the values, or the fields retrieved,
     // but they just call get_post_meta() for every order.
     // See file woocommerce-admin-reports.php, method woocommerce_sales_overview(),
     // line ~472.
     if ($meta_key == '_order_total') {
         $meta_cache = update_meta_cache('post', array($object_id));
         $obj_cache = $meta_cache[$object_id];
         $order = new Aelia_Order($object_id);
         return $order->get_total_in_base_currency();
     }
     return $metadata;
 }
Esempio n. 19
0
/**
 * Updates venue meta cache when event venues are retrieved.
 *
 * For backwards compatibility it adds the venue details to the taxonomy terms.
 * Hooked onto get_terms and get_event-venue
 *
 * @ignore
 * @access private
 * @since 1.5
 *
 * @param array $terms Array of terms,
 * @param string $tax Should be (an array containing) 'event-venue'.
 * @param array  Array of event-venue terms,
 */
function eventorganiser_update_venue_meta_cache($terms, $tax)
{
    if (is_array($tax) && !in_array('event-venue', $tax)) {
        return $terms;
    }
    if (!is_array($tax) && $tax != 'event-venue') {
        return $terms;
    }
    $single = false;
    if (!is_array($terms)) {
        $single = true;
        $terms = array($terms);
    }
    if (empty($terms)) {
        return $terms;
    }
    //Check if its array of terms or term IDs
    $first_element = reset($terms);
    if (is_object($first_element)) {
        $term_ids = wp_list_pluck($terms, 'term_id');
    } else {
        $term_ids = $terms;
    }
    update_meta_cache('eo_venue', $term_ids);
    //Backwards compatible. Depreciated - use the functions, not properties.
    foreach ($terms as $term) {
        if (!is_object($term)) {
            continue;
        }
        $term_id = (int) $term->term_id;
        if (!isset($term->venue_address)) {
            $address = eo_get_venue_address($term_id);
            foreach ($address as $key => $value) {
                $term->{'venue_' . $key} = $value;
            }
        }
        if (!isset($term->venue_lat) || !isset($term->venue_lng)) {
            $term->venue_lat = number_format(floatval(eo_get_venue_lat($term_id)), 6);
            $term->venue_lng = number_format(floatval(eo_get_venue_lng($term_id)), 6);
        }
    }
    if ($single) {
        return $terms[0];
    }
    return $terms;
}
Esempio n. 20
0
/**
 * @since 3.2.3 translation of postmeta
 */
function qtranxf_filter_postmeta($original_value, $object_id, $meta_key = '', $single = false)
{
    global $q_config;
    if (!isset($q_config['url_info'])) {
        //qtranxf_dbg_log('qtranxf_filter_postmeta: too early: $object_id='.$object_id.'; $meta_key',$meta_key,true);
        return $original_value;
    }
    //qtranxf_dbg_log('qtranxf_filter_postmeta: $object_id='.$object_id.'; $meta_key=',$meta_key);
    $meta_type = 'post';
    $lang = $q_config['language'];
    $cache_key = $meta_type . '_meta';
    $cache_key_lang = $cache_key . $lang;
    $meta_cache_wp = wp_cache_get($object_id, $cache_key);
    if ($meta_cache_wp) {
        //if there is wp cache, then we check if there is qtx cache
        $meta_cache = wp_cache_get($object_id, $cache_key_lang);
    } else {
        //reset qtx cache, since it would not be valid in the absence of wp cache
        qtranxf_cache_delete_postmeta($object_id);
        $meta_cache = null;
    }
    if (!$meta_cache) {
        if ($meta_cache_wp) {
            $meta_cache = $meta_cache_wp;
        } else {
            $meta_cache = update_meta_cache($meta_type, array($object_id));
            $meta_cache = $meta_cache[$object_id];
        }
        //qtranxf_dbg_log('qtranxf_filter_postmeta: $object_id='.$object_id.'; $meta_cache before:',$meta_cache);
        foreach ($meta_cache as $mkey => $mval) {
            if (strpos($mkey, '_url') !== false) {
                $val = array_map('maybe_unserialize', $mval);
                switch ($mkey) {
                    case '_menu_item_url':
                        break;
                        // function qtranxf_wp_get_nav_menu_items takes care of this later
                    // function qtranxf_wp_get_nav_menu_items takes care of this later
                    default:
                        //qtranxf_dbg_log('qtranxf_filter_postmeta: $object_id='.$object_id.'; $meta_cache['.$mkey.'] url before:',$val);
                        $val = qtranxf_convertURLs($val, $lang);
                        //qtranxf_dbg_log('qtranxf_filter_postmeta: $object_id='.$object_id.'; $meta_cache['.$mkey.'] url  after:',$val);
                        break;
                }
            } else {
                $val = array();
                foreach ($mval as $k => $v) {
                    $ml = qtranxf_isMultilingual($v);
                    $v = maybe_unserialize($v);
                    if ($ml) {
                        $v = qtranxf_use($lang, $v, false, false);
                    }
                    $val[$k] = $v;
                }
            }
            $meta_cache[$mkey] = $val;
        }
        //qtranxf_dbg_log('qtranxf_filter_postmeta: $object_id='.$object_id.'; $meta_cache  after:',$meta_cache);
        wp_cache_set($object_id, $meta_cache, $cache_key_lang);
    }
    if (!$meta_key) {
        if ($single) {
            /**
             @since 3.2.9.9.7
             The code executed after a call to this filter in /wp-includes/meta.php,
             in function get_metadata, is apparently designed having non-empty $meta_key in mind:
            
             	if ( $single && is_array( $check ) ){
             		return $check[0];
             	}else
             		return $check;
            
             Following the logic of the code "if ( !$meta_key ) return $meta_cache;",
            		a few lines below in the same function, the code above rather have to be:
            
             	if ( $meta_key && $single && is_array( $check ) ){
             		return $check[0];
             	}else
             		return $check;
            
             The line below offsets this imperfection.
             If WP ever fixes that place, this block of code will have to be removed.
            */
            return array($meta_cache);
        }
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        return $meta_cache[$meta_key];
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}
 /**
  * Lazy-load comment meta when inside of a `WP_Query` loop.
  * This method is public so that it can be used as a filter callback. As a rule, there is no need to invoke it
  * directly, from either inside or outside the `WP_Query` object.
  * @param mixed $check     The `$check` param passed from the 'get_comment_metadata' hook.
  * @param int  $comment_id ID of the comment whose metadata is being cached.
  * @return mixed The original value of `$check`, to not affect 'get_comment_metadata'.
  */
 public function lazyload_comment_meta($check, $comment_id)
 {
     /*
      * We only do this once per `WP_Query` instance.
      * Can't use `remove_filter()` because of non-unique object hashes.
      */
     if ($this->updated_comment_meta_cache) {
         return $check;
     }
     // Don't use `wp_list_pluck()` to avoid by-reference manipulation.
     $comment_ids = array();
     if (is_array($this->comments)) {
         foreach ($this->comments as $comment) {
             $comment_ids[] = $comment->comment_ID;
         }
     }
     /*
      * Only update the metadata cache for comments belonging to these posts if the comment_id passed
      * to `get_comment_meta()` matches one of those comments. This prevents a single call to
      * `get_comment_meta()` from priming metadata for all `WP_Query` objects.
      */
     if (in_array($comment_id, $comment_ids)) {
         update_meta_cache('comment', $comment_ids);
         $this->updated_comment_meta_cache = true;
     } elseif (empty($comment_ids)) {
         $this->updated_comment_meta_cache = true;
     }
     return $check;
 }
Esempio n. 22
0
    /**
     * Return events falling within some time range.
     *
     * Return all events starting after the given start time and before the
     * given end time that the currently logged in user has permission to view.
     * If $spanning is true, then also include events that span this
     * period. All-day events are returned first.
     *
     * @param Ai1ec_Date_Time $start Limit to events starting after this.
     * @param Ai1ec_Date_Time $end   Limit to events starting before this.
     * @param array $filter          Array of filters for the events returned:
     *                                   ['cat_ids']  => list of category IDs;
     *                                   ['tag_ids']  => list of tag IDs;
     *                                   ['post_ids'] => list of post IDs;
     *                                   ['auth_ids'] => list of author IDs.
     * @param bool $spanning         Also include events that span this period.
     *
     * @return array List of matching event objects.
     */
    public function get_events_between(Ai1ec_Date_Time $start, Ai1ec_Date_Time $end, array $filter = array(), $spanning = false)
    {
        // Query arguments
        $args = array($start->format_to_gmt(), $end->format_to_gmt());
        // Get post status Where snippet and associated SQL arguments
        $where_parameters = $this->_get_post_status_sql();
        $post_status_where = $where_parameters['post_status_where'];
        $args = array_merge($args, $where_parameters['args']);
        // Get the Join (filter_join) and Where (filter_where) statements based
        // on $filter elements specified
        $filter = $this->_get_filter_sql($filter);
        $ai1ec_localization_helper = $this->_registry->get('p28n.wpml');
        $wpml_join_particle = $ai1ec_localization_helper->get_wpml_table_join('p.ID');
        $wpml_where_particle = $ai1ec_localization_helper->get_wpml_table_where();
        if ($spanning) {
            $spanning_string = 'i.end > %d AND i.start < %d ';
        } else {
            $spanning_string = 'i.start BETWEEN %d AND %d ';
        }
        $sql = '
			SELECT
				`p`.*,
				`e`.`post_id`,
				`i`.`id` AS `instance_id`,
				`i`.`start` AS `start`,
				`i`.`end` AS `end`,
				`e`.`timezone_name` AS `timezone_name`,
				`e`.`allday` AS `event_allday`,
				`e`.`recurrence_rules`,
				`e`.`exception_rules`,
				`e`.`recurrence_dates`,
				`e`.`exception_dates`,
				`e`.`venue`,
				`e`.`country`,
				`e`.`address`,
				`e`.`city`,
				`e`.`province`,
				`e`.`postal_code`,
				`e`.`instant_event`,
				`e`.`show_map`,
				`e`.`contact_name`,
				`e`.`contact_phone`,
				`e`.`contact_email`,
				`e`.`contact_url`,
				`e`.`cost`,
				`e`.`ticket_url`,
				`e`.`ical_feed_url`,
				`e`.`ical_source_url`,
				`e`.`ical_organizer`,
				`e`.`ical_contact`,
				`e`.`ical_uid`
			FROM
				' . $this->_dbi->get_table_name('ai1ec_events') . ' e
				INNER JOIN
					' . $this->_dbi->get_table_name('posts') . ' p
						ON ( `p`.`ID` = `e`.`post_id` )
				' . $wpml_join_particle . '
				INNER JOIN
					' . $this->_dbi->get_table_name('ai1ec_event_instances') . ' i
					ON ( `e`.`post_id` = `i`.`post_id` )
				' . $filter['filter_join'] . '
			WHERE
				post_type = \'' . AI1EC_POST_TYPE . '\'
				' . $wpml_where_particle . '
			AND
				' . $spanning_string . '
				' . $filter['filter_where'] . '
				' . $post_status_where . '
			GROUP BY
				`i`.`id`
			ORDER BY
				`e` . `allday`     DESC,
				`i` . `start`      ASC,
				`p` . `post_title` ASC';
        $query = $this->_dbi->prepare($sql, $args);
        $events = $this->_dbi->get_results($query, ARRAY_A);
        $id_list = array();
        foreach ($events as $event) {
            $id_list[] = $event['post_id'];
        }
        if (!empty($id_list)) {
            update_meta_cache('post', $id_list);
        }
        foreach ($events as &$event) {
            $event['allday'] = $this->_is_all_day($event);
            $event = $this->_registry->get('model.event', $event);
        }
        return $events;
    }
Esempio n. 23
0
/**
 * Updates the comment cache of given comments.
 *
 * Will add the comments in $comments to the cache. If comment ID already exists
 * in the comment cache then it will not be updated. The comment is added to the
 * cache using the comment group with the key using the ID of the comments.
 *
 * @since 2.3.0
 * @since 4.4.0 Introduced the `$update_meta_cache` parameter.
 *
 * @param array $comments          Array of comment row objects
 * @param bool  $update_meta_cache Whether to update commentmeta cache. Default true.
 */
function update_comment_cache($comments, $update_meta_cache = true)
{
    foreach ((array) $comments as $comment) {
        wp_cache_add($comment->comment_ID, $comment, 'comment');
    }
    if ($update_meta_cache) {
        // Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
        $comment_ids = array();
        foreach ($comments as $comment) {
            $comment_ids[] = $comment->comment_ID;
        }
        update_meta_cache('comment', $comment_ids);
    }
}
Esempio n. 24
0
 /**
  * Load all posts with one query, to prime the cache
  *
  * @see get_post()
  * @since 1.0.0
  *
  * @param array $all_post_ids List of Post IDs
  * @param bool $update_meta_cache Whether to update the Post Meta Cache (for table options and visibility)
  */
 public function load_posts(array $all_post_ids, $update_meta_cache = true)
 {
     global $wpdb;
     // Split post loading, to save memory
     $offset = 0;
     $length = 100;
     // 100 posts at a time
     $number_of_posts = count($all_post_ids);
     while ($offset < $number_of_posts) {
         $post_ids = array_slice($all_post_ids, $offset, $length);
         $post_ids = _get_non_cached_ids($post_ids, 'posts');
         // Don't load posts that are in the cache already
         if (!empty($post_ids)) {
             $post_ids_list = implode(',', $post_ids);
             $posts = $wpdb->get_results("SELECT {$wpdb->posts}.* FROM {$wpdb->posts} WHERE ID IN ({$post_ids_list})");
             update_post_cache($posts);
             if ($update_meta_cache) {
                 update_meta_cache('post', $post_ids);
                 // get all post meta data for all table posts, @see get_post_meta()
             }
         }
         $offset += $length;
         // next array_slice() $offset
     }
 }
Esempio n. 25
0
 /**
  * Retrieve info for user lists to prevent multiple queries by get_userdata()
  *
  * @since 3.0.0
  *
  * @param array $user_ids User ID numbers list
  */
 function cache_users($user_ids)
 {
     global $wpdb;
     $clean = _get_non_cached_ids($user_ids, 'users');
     if (empty($clean)) {
         return;
     }
     $list = implode(',', $clean);
     $users = $wpdb->get_results("SELECT * FROM {$wpdb->users} WHERE ID IN ({$list})");
     $ids = array();
     foreach ($users as $user) {
         update_user_caches($user);
         $ids[] = $user->ID;
     }
     update_meta_cache('user', $ids);
 }
 /**
  * Adds posts and pages to the sitemap.
  *
  * @since 1.3
  */
 protected function posts()
 {
     global $wpdb;
     $post_type = $this->get_info('content_type');
     $post_type_is_page = $post_type == 'page';
     $post_type_is_post = $post_type == 'post';
     if (!($post_type_is_post || $post_type_is_page)) {
         return false;
     }
     $post_ids = $post_attachments = array();
     $post_not_in = '';
     $limit = $this->getLimit();
     $exclude = $this->db->getOption($this->sitemap_type, array(), 'exclude');
     if ($exclude && ($ids = wp_parse_id_list($exclude))) {
         $post_not_in = 'ID NOT IN (' . implode(',', $ids) . ') AND';
     }
     if ($post_type_is_page) {
         $this->pageForPosts = (int) get_option('page_for_posts');
     }
     // We retrieve a few more fields than needed to make get_permalink() work properly
     $posts = $wpdb->get_results("SELECT ID, post_date, post_status, post_name, post_modified, post_parent, post_type\n\t\t\t FROM {$wpdb->posts}\n\t\t\t WHERE {$post_not_in} post_type = '{$post_type}' AND post_status = 'publish' AND post_password = ''\n\t\t\t ORDER BY post_modified DESC\n\t\t\t LIMIT {$limit}");
     if (!$posts) {
         return false;
     }
     foreach ($posts as $index => $post) {
         $post = sanitize_post($post, 'raw');
         $post_ids[] = $post->ID;
     }
     if ($post_type_is_post && $this->blog) {
         $this->blog->post_modified = $posts[0]->post_modified;
     }
     if ($this->db->getOption('images', true)) {
         $ids = implode(',', $post_ids);
         $attachments = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, post_parent, post_type\n\t\t\t\t FROM {$wpdb->posts}\n\t\t\t\t WHERE post_parent IN ({$ids}) AND post_type = 'attachment' AND post_mime_type LIKE 'image/%'\n\t\t\t\t ORDER BY post_modified DESC");
         if ($attachments) {
             $this->isImageSitemap = true;
             foreach ($attachments as $attachment) {
                 $attachment = sanitize_post($attachment, 'raw');
                 $post_ids[] = $attachment->ID;
                 $post_attachments[$attachment->post_parent][] = $attachment;
             }
             update_post_cache($attachments);
         }
     }
     // Retrieves and stores into the cache the metadata we need later
     update_meta_cache('post', $post_ids);
     // This hack lets us save a lot of queries that would be performed when we call get_permalink()
     update_post_cache($posts);
     $changefreq = $this->get_info('changefreq');
     $priority = $this->get_info('priority');
     foreach ($posts as $post) {
         $images = null;
         if (isset($post_attachments[$post->ID])) {
             $images =& $post_attachments[$post->ID];
         }
         if ($post->ID == $this->pageOnFront) {
             $this->home = $post;
             $this->home->images = $images;
             continue;
         } elseif ($post->ID == $this->pageForPosts) {
             $this->blog = $post;
             $this->blog->changefreq = $changefreq;
             $this->blog->priority = $priority;
             $this->blog->images = $images;
             continue;
         }
         $this->addUrlItem(get_permalink($post), $post->post_modified, $this->db->getPostMeta($post->ID, 'changefreq', $changefreq), $this->db->getPostMeta($post->ID, 'priority', $priority), $images);
     }
 }
Esempio n. 27
0
 /**
  * Get the cart data from the PHP session and store it in class variables.
  */
 public function get_cart_from_session()
 {
     // Load cart session data from session
     foreach ($this->cart_session_data as $key => $default) {
         $this->{$key} = WC()->session->get($key, $default);
     }
     $update_cart_session = false;
     $this->removed_cart_contents = array_filter(WC()->session->get('removed_cart_contents', array()));
     $this->applied_coupons = array_filter(WC()->session->get('applied_coupons', array()));
     /**
      * Load the cart object. This defaults to the persistent cart if null.
      */
     $cart = WC()->session->get('cart', null);
     if (is_null($cart) && ($saved_cart = get_user_meta(get_current_user_id(), '_woocommerce_persistent_cart', true))) {
         $cart = $saved_cart['cart'];
         $update_cart_session = true;
     } elseif (is_null($cart)) {
         $cart = array();
     }
     if (is_array($cart)) {
         // Prime meta cache to reduce future queries
         update_meta_cache('post', wp_list_pluck($cart, 'product_id'));
         foreach ($cart as $key => $values) {
             $_product = wc_get_product($values['variation_id'] ? $values['variation_id'] : $values['product_id']);
             if (!empty($_product) && $_product->exists() && $values['quantity'] > 0) {
                 if (!$_product->is_purchasable()) {
                     // Flag to indicate the stored cart should be update
                     $update_cart_session = true;
                     wc_add_notice(sprintf(__('%s has been removed from your cart because it can no longer be purchased. Please contact us if you need assistance.', 'woocommerce'), $_product->get_title()), 'error');
                     do_action('woocommerce_remove_cart_item_from_session', $key, $values);
                 } else {
                     // Put session data into array. Run through filter so other plugins can load their own session data
                     $session_data = array_merge($values, array('data' => $_product));
                     $this->cart_contents[$key] = apply_filters('woocommerce_get_cart_item_from_session', $session_data, $values, $key);
                 }
             }
         }
     }
     // Trigger action
     do_action('woocommerce_cart_loaded_from_session', $this);
     if ($update_cart_session) {
         WC()->session->cart = $this->get_cart_for_session();
     }
     // Queue re-calc if subtotal is not set
     if (!$this->subtotal && !$this->is_empty() || $update_cart_session) {
         $this->calculate_totals();
     }
 }
Esempio n. 28
0
 /**
  * Update metadata for retrieved events.
  *
  * This speeds up further meta data requests.
  *
  * @param array $events List of events retrieved.
  *
  * @return void
  */
 protected function _update_meta(array $events)
 {
     $post_ids = array();
     foreach ($events as $event) {
         $post_ids[] = (int) $event->get('post_id');
     }
     update_meta_cache('post', $post_ids);
     $this->_registry->get('model.taxonomy')->update_meta($post_ids);
 }
Esempio n. 29
0
/**
 * Updates metadata cache for list of post IDs.
 *
 * Performs SQL query to retrieve the metadata for the post IDs and updates the
 * metadata cache for the posts. Therefore, the functions, which call this
 * function, do not need to perform SQL queries on their own.
 *
 * @package WordPress
 * @subpackage Cache
 * @since 2.1.0
 *
 * @uses $wpdb
 *
 * @param array $post_ids List of post IDs.
 * @return bool|array Returns false if there is nothing to update or an array of metadata.
 */
function update_postmeta_cache($post_ids)
{
    return update_meta_cache('post', $post_ids);
}
Esempio n. 30
0
/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of WP_Comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filter the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if (!$wp_query->comment_meta_cached) {
            $comment_ids = wp_list_pluck($_comments, 'comment_ID');
            update_meta_cache('comment', $comment_ids);
            $wp_query->comment_meta_cached = true;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = 'newest' == get_option('default_comments_page') ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $wp_query->max_num_comment_pages = $walker->max_pages;
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}