PluginProbe
Gutenberg / 12.6.0
Gutenberg v12.6.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 7.4.0 All 402 releases
gutenberg / lib / compat / experimental / blocks.php

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

119 lines 4.2 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
20 $comment_args = array(
21 'orderby' => 'comment_date_gmt',
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 $comment_args['order'] = ! empty( $block->context['comments/order'] ) ? $block->context['comments/order'] : null;
56 if ( empty( $comment_args['order'] ) && get_option( 'comment_order' ) ) {
57 $comment_args['order'] = get_option( 'comment_order' );
58 }
59
60 return $comment_args;
61 }
62 }
63
64 if ( ! function_exists( 'get_comments_pagination_arrow' ) ) {
65 /**
66 * Helper function that returns the proper pagination arrow html for
67 * `CommentsPaginationNext` and `CommentsPaginationPrevious` blocks based
68 * on the provided `paginationArrow` from `CommentsPagination` context.
69 *
70 * It's used in CommentsPaginationNext and CommentsPaginationPrevious blocks.
71 *
72 * @param WP_Block $block Block instance.
73 * @param string $pagination_type Type of the arrow we will be rendering. Default 'next'. Accepts 'next' or 'previous'.
74 *
75 * @return string|null Returns the constructed WP_Query arguments.
76 */
77 function get_comments_pagination_arrow( $block, $pagination_type = 'next' ) {
78 $arrow_map = array(
79 'none' => '',
80 'arrow' => array(
81 'next' => '',
82 'previous' => '',
83 ),
84 'chevron' => array(
85 'next' => '»',
86 'previous' => '«',
87 ),
88 );
89 if ( ! empty( $block->context['comments/paginationArrow'] ) && ! empty( $arrow_map[ $block->context['comments/paginationArrow'] ][ $pagination_type ] ) ) {
90 $arrow_attribute = $block->context['comments/paginationArrow'];
91 $arrow = $arrow_map[ $block->context['comments/paginationArrow'] ][ $pagination_type ];
92 $arrow_classes = "wp-block-comments-pagination-$pagination_type-arrow is-arrow-$arrow_attribute";
93 return "<span class='$arrow_classes'>$arrow</span>";
94 }
95 return null;
96 }
97 }
98
99 if ( ! function_exists( 'extend_block_editor_settings_with_discussion_settings' ) ) {
100 /**
101 * Workaround for getting discussion settings as block editor settings
102 * so any user can access to them without needing to be an admin.
103 *
104 * @param array $settings Default editor settings.
105 *
106 * @return array Filtered editor settings.
107 */
108 function extend_block_editor_settings_with_discussion_settings( $settings ) {
109 $settings['__experimentalDiscussionSettings'] = array(
110 'pageComments' => get_option( 'page_comments' ),
111 'commentsPerPage' => get_option( 'comments_per_page' ),
112 'defaultCommentsPage' => get_option( 'default_comments_page' ),
113 'commentOrder' => get_option( 'comment_order' ),
114 );
115 return $settings;
116 }
117 }
118 add_filter( 'block_editor_settings_all', 'extend_block_editor_settings_with_discussion_settings' );
119