| @@ -31,9 +31,15 @@ | ||
| 31 | 31 | return $widgets; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function callback_ajax_loadmore_posts() { |
| 35 | + // Verify the front-end nonce (sent by UltimatePostKitConfig.nonce) before | |
| 36 | + // processing this public load-more request. | |
| 37 | + if ( ! check_ajax_referer( 'upk-site', 'nonce', false ) ) { | |
| 38 | + wp_send_json_error( array( 'message' => esc_html__( 'Security check failed.', 'ultimate-post-kit' ) ), 403 ); | |
| 39 | + } | |
| 35 | 40 | |
| 41 | + | |
| 36 | 42 | $settings = []; |
| 37 | 43 | |
| 38 | 44 | if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) { |
| 39 | 45 | $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' ); |
| @@ -54,8 +60,11 @@ | ||
| 54 | 60 | ], |
| 55 | 61 | $settings |
| 56 | 62 | ); |
| 57 | 63 | |
| 64 | + // Fill display flags the request may have omitted (see trait) before the render loop reads them. | |
| 65 | + $settings = array_merge( $this->loadmore_display_defaults(), $settings ); | |
| 66 | + | |
| 58 | 67 | $ajaxposts = $this->query_args( $settings ); |
| 59 | 68 | |
| 60 | 69 | ob_start(); |
| 61 | 70 | $found_posts = false; |
| @@ -75,13 +84,8 @@ | ||
| 75 | 84 | $image_src = $image_src ? $image_src[0] : $placeholder; |
| 76 | 85 | |
| 77 | 86 | $title_tag = Utils::get_valid_html_tag($settings['title_tags']); |
| 78 | 87 | |
| 79 | - $onclick = ''; | |
| 80 | - if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { | |
| 81 | - $onclick = 'onclick="window.open(\'' . esc_url( $post_link ) . '\', \'_self\')"'; | |
| 82 | - } | |
| 83 | - | |
| 84 | 88 | $list_box_class = 'upk-content'; |
| 85 | 89 | if ( $settings['show_readmore'] === 'yes' ) { |
| 86 | 90 | $list_box_class = 'upk-content upk-readmore--yes'; |
| 87 | 91 | } |
| @@ -86,9 +90,9 @@ | ||
| 86 | 90 | $list_box_class = 'upk-content upk-readmore--yes'; |
| 87 | 91 | } |
| 88 | 92 | |
| 89 | 93 | ?> |
| 90 | - <div <?php echo $onclick; ?> class="upk-item"> | |
| 94 | + <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item"> | |
| 91 | 95 | <div class="upk-item-box"> |
| 92 | 96 | <div class="upk-image-wrap"> |
| 93 | 97 | <a href="<?php echo esc_url( $post_link ); ?>"> |
| 94 | 98 | <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $title ); ?>"> |
| @@ -134,9 +138,9 @@ | ||
| 134 | 138 | <?php |
| 135 | 139 | if ( has_excerpt() ) { |
| 136 | 140 | the_excerpt(); |
| 137 | 141 | } else { |
| 138 | - echo wp_trim_words( get_the_content(), $settings['excerpt_length'] ?? 15 ); | |
| 142 | + echo esc_html( wp_trim_words( get_the_content(), ultimate_post_kit_clamp_excerpt_length( $settings['excerpt_length'] ?? 15, 15 ) ) ); | |
| 139 | 143 | } |
| 140 | 144 | ?> |
| 141 | 145 | </div> |
| 142 | 146 | <?php endif; ?> |
| @@ -154,10 +158,9 @@ | ||
| 154 | 158 | |
| 155 | 159 | <?php if ( $settings['show_comments'] === 'yes' ) : ?> |
| 156 | 160 | <div data-separator="<?php echo esc_attr( $settings['meta_separator'] ?? '//' ); ?>"> |
| 157 | 161 | <div class="upk-fanel-comments"> |
| 158 | - <?php echo get_comments_number( $post_id ); ?> | |
| 159 | - <?php echo esc_html_x( 'Comments', 'Frontend', 'ultimate-post-kit' ); ?> | |
| 162 | + <?php echo esc_html( $this->upk_get_formatted_comments_count( $post_id ) ); ?> | |
| 160 | 163 | </div> |
| 161 | 164 | </div> |
| 162 | 165 | <?php endif; ?> |
| 163 | 166 | |
| @@ -162,9 +165,9 @@ | ||
| 162 | 165 | <?php endif; ?> |
| 163 | 166 | |
| 164 | 167 | <?php if ( _is_upk_pro_activated() && $settings['show_reading_time'] === 'yes' ) : ?> |
| 165 | 168 | <div class="upk-reading-time" data-separator="<?php echo esc_attr( $settings['meta_separator'] ?? '//' ); ?>"> |
| 166 | - <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $settings['avg_reading_speed'] ?? 200 ) ); ?> | |
| 169 | + <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $settings['avg_reading_speed'], $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?> | |
| 167 | 170 | </div> |
| 168 | 171 | <?php endif; ?> |
| 169 | 172 | </div> |
| 170 | 173 | <?php endif; ?> |