PluginProbe
Gutenberg / 12.3.2
Gutenberg v12.3.2
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / lib / compat / experimental / blocks.php

blocks.php in Gutenberg 12.3.2, at lib/compat/experimental/blocks.php

93 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Temporary compatibility shims for features present in Gutenberg.
4 *
5 * @package gutenberg
6 */
7
8 if ( ! function_exists( 'build_comment_query_vars_from_block' ) ) {
9 /**
10 * Helper function that constructs a comment query vars array from the passed block properties.
11 *
12 * It's used with the Comment Query Loop inner blocks.
13 *
14 * @param WP_Block $block Block instance.
15 *
16 * @return array Returns the comment query parameters to use with the WP_Comment_Query constructor.
17 */
18 function build_comment_query_vars_from_block( $block ) {
19 $comment_args = array(
20 'orderby' => 'comment_date_gmt',
21 'order' => 'ASC',
22 'status' => 'approve',
23 'no_found_rows' => false,
24 'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
25 );
26
27 if ( ! empty( $block->context['postId'] ) ) {
28 $comment_args['post_id'] = (int) $block->context['postId'];
29 }
30
31 if ( get_option( 'thread_comments' ) ) {
32 $comment_args['hierarchical'] = 'threaded';
33 } else {
34 $comment_args['hierarchical'] = false;
35 }
36
37 $per_page = ! empty( $block->context['comments/perPage'] ) ? (int) $block->context['comments/perPage'] : 0;
38 if ( 0 === $per_page && get_option( 'page_comments' ) ) {
39 $per_page = (int) get_query_var( 'comments_per_page' );
40 if ( 0 === $per_page ) {
41 $per_page = (int) get_option( 'comments_per_page' );
42 }
43 }
44 if ( $per_page > 0 ) {
45 $comment_args['number'] = $per_page;
46 $page = (int) get_query_var( 'cpage' );
47
48 if ( $page ) {
49 $comment_args['offset'] = ( $page - 1 ) * $per_page;
50 } elseif ( 'oldest' === get_option( 'default_comments_page' ) ) {
51 $comment_args['offset'] = 0;
52 }
53 }
54
55 return $comment_args;
56 }
57 }
58
59 if ( ! function_exists( 'get_comments_pagination_arrow' ) ) {
60 /**
61 * Helper function that returns the proper pagination arrow html for
62 * `CommentsPaginationNext` and `CommentsPaginationPrevious` blocks based
63 * on the provided `paginationArrow` from `CommentsPagination` context.
64 *
65 * It's used in CommentsPaginationNext and CommentsPaginationPrevious blocks.
66 *
67 * @param WP_Block $block Block instance.
68 * @param string $pagination_type Type of the arrow we will be rendering. Default 'next'. Accepts 'next' or 'previous'.
69 *
70 * @return string|null Returns the constructed WP_Query arguments.
71 */
72 function get_comments_pagination_arrow( $block, $pagination_type = 'next' ) {
73 $arrow_map = array(
74 'none' => '',
75 'arrow' => array(
76 'next' => '',
77 'previous' => '',
78 ),
79 'chevron' => array(
80 'next' => '»',
81 'previous' => '«',
82 ),
83 );
84 if ( ! empty( $block->context['comments/paginationArrow'] ) && ! empty( $arrow_map[ $block->context['comments/paginationArrow'] ][ $pagination_type ] ) ) {
85 $arrow_attribute = $block->context['comments/paginationArrow'];
86 $arrow = $arrow_map[ $block->context['comments/paginationArrow'] ][ $pagination_type ];
87 $arrow_classes = "wp-block-comments-pagination-$pagination_type-arrow is-arrow-$arrow_attribute";
88 return "<span class='$arrow_classes'>$arrow</span>";
89 }
90 return null;
91 }
92 }
93