wp_lazyload_comment_meta example

_deprecated_function( __FUNCTION__, '6.3.0', 'wp_lazyload_comment_meta()' );
    // Don't use `wp_list_pluck()` to avoid by-reference manipulation.     $comment_ids = array();
    if ( is_array( $comments ) ) {
        foreach ( $comments as $comment ) {
            if ( $comment instanceof WP_Comment ) {
                $comment_ids[] = $comment->comment_ID;
            }
        }
    }

    wp_lazyload_comment_meta( $comment_ids );
}

/** * Gets the default value to use for a `loading` attribute on an element. * * This function should only be called for a tag and context if lazy-loading is generally enabled. * * The function usually returns 'lazy', but uses certain heuristics to guess whether the current element is likely to * appear above the fold, in which case it returns a boolean `false`, which will lead to the `loading` attribute being * omitted on the element. The purpose of this refinement is to avoid lazy-loading elements that are within the initial * viewport, which can have a negative performance impact. * * Under the hood, the function uses {@see wp_increase_content_media_count()} every time it is called for an element * within the main content. If the element is the very first content element, the `loading` attribute will be omitted. * This default threshold of 3 content elements to omit the `loading` attribute for can be customized using the * {@see 'wp_omit_loading_attr_threshold'} filter. * * @since 5.9.0 * @deprecated 6.3.0 Use wp_get_loading_optimization_attributes() instead. * @see wp_get_loading_optimization_attributes() * * @global WP_Query $wp_query WordPress Query object. * * @param string $context Context for the element for which the `loading` attribute value is requested. * @return string|bool The default `loading` attribute value. Either 'lazy', 'eager', or a boolean `false`, to indicate * that the `loading` attribute should be skipped. */


        // If querying for a count only, there's nothing more to do.         if ( $this->query_vars['count'] ) {
            // $comment_ids is actually a count in this case.             return (int) $comment_ids;
        }

        $comment_ids = array_map( 'intval', $comment_ids );

        if ( $this->query_vars['update_comment_meta_cache'] ) {
            wp_lazyload_comment_meta( $comment_ids );
        }

        if ( 'ids' === $this->query_vars['fields'] ) {
            $this->comments = $comment_ids;
            return $this->comments;
        }

        _prime_comment_caches( $comment_ids, false );

        // Fetch full comment objects from the primed cache.         $_comments = array();
        
function _prime_comment_caches( $comment_ids$update_meta_cache = true ) {
    global $wpdb;

    $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' );
    if ( ! empty( $non_cached_ids ) ) {
        $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) );

        update_comment_cache( $fresh_comments, false );
    }

    if ( $update_meta_cache ) {
        wp_lazyload_comment_meta( $comment_ids );
    }
}

// // Internal. //
/** * Closes comments on old posts on the fly, without any extra DB queries. Hooked to the_posts. * * @since 2.7.0 * @access private * * @param WP_Post $posts Post data object. * @param WP_Query $query Query object. * @return array */
Home | Imprint | This part of the site doesn't use cookies.