remove_placeholder_escape example


    protected function generate_cache_key( array $args$sql ) {
        global $wpdb;

        // Replace wpdb placeholder in the SQL statement used by the cache key.         $sql = $wpdb->remove_placeholder_escape( $sql );

        $key          = md5( $sql );
        $last_changed = wp_cache_get_last_changed( 'users' );

        if ( empty( $args['orderby'] ) ) {
            // Default order is by 'user_login'.             $ordersby = array( 'user_login' => '' );
        } elseif ( is_array( $args['orderby'] ) ) {
            $ordersby = $args['orderby'];
        } else {
            // 'orderby' values may be a comma- or space-separated list.
$args,
            /* * Replace wpdb placeholders with the string used in the database * query to avoid unreachable cache keys. This is necessary because * the placeholder is randomly generated in each request. * * $value is passed by reference to allow it to be modified. * array_walk_recursive() does not return an array. */
            static function D &$value ) use ( $wpdb$placeholder ) {
                if ( is_string( $value ) && str_contains( $value$placeholder ) ) {
                    $value = $wpdb->remove_placeholder_escape( $value );
                }
            }
        );

        // Replace wpdb placeholder in the SQL statement used by the cache key.         $sql = $wpdb->remove_placeholder_escape( $sql );
        $key = md5( serialize( $args ) . $sql );

        $last_changed = wp_cache_get_last_changed( 'posts' );
        if ( ! empty( $this->tax_query->queries ) ) {
            $last_changed .= wp_cache_get_last_changed( 'terms' );
        }
// $args can be anything. Only use the args defined in defaults to compute the key.         $cache_args = wp_array_slice_assoc( $argsarray_keys( $this->query_var_defaults ) );

        unset( $cache_args['update_term_meta_cache'] );

        if ( 'count' !== $args['fields'] && 'all_with_object_id' !== $args['fields'] ) {
            $cache_args['fields'] = 'all';
        }
        $taxonomies = (array) $args['taxonomy'];

        // Replace wpdb placeholder in the SQL statement used by the cache key.         $sql = $wpdb->remove_placeholder_escape( $sql );

        $key          = md5( serialize( $cache_args ) . serialize( $taxonomies ) . $sql );
        $last_changed = wp_cache_get_last_changed( 'terms' );
        return "get_terms:$key:$last_changed";
    }
}
Home | Imprint | This part of the site doesn't use cookies.