PluginProbe
WP Ultimate Post Grid / 2.8.2
WP Ultimate Post Grid v2.8.2
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / helpers / content.php

content.php in WP Ultimate Post Grid 2.8.2, at helpers/content.php

50 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class WPUPG_Content {
4
5 public function __construct()
6 {
7 add_filter( 'the_content', array( $this, 'prefilter_grid' ), 1 );
8 add_filter( 'the_content', array( $this, 'content_filter' ), 10 );
9 }
10
11 public function prefilter_grid( $content )
12 {
13 $pattern = get_shortcode_regex( array( 'wpupg-grid' ) );
14
15 if ( preg_match_all( '/' . $pattern . '/s', $content, $matches ) && array_key_exists( 2, $matches ) ) {
16 foreach ( $matches[2] as $key => $value ) {
17 if ( 'wpupg-grid' === $value ) {
18 $grid_shortcode = $matches[0][ $key ];
19 $grid_shortcode = str_ireplace( '[wpupg-grid ', '[wpupg-grid wpupg_no_output="1" ', $grid_shortcode );
20
21 // This forces a prefilter of the grid without actual output.
22 do_shortcode( $grid_shortcode );
23 }
24 }
25 }
26
27 return $content;
28 }
29
30 public function content_filter( $content )
31 {
32 $ignore_query = !is_main_query();
33 if ( apply_filters( 'wpupg_content_loop_check', $ignore_query ) ) {
34 return $content;
35 }
36
37 if ( get_post_type() == WPUPG_POST_TYPE ) {
38 remove_filter( 'the_content', array( $this, 'content_filter' ), 10 );
39
40 $grid = WPUPG_Grid_Manager::get( get_post() );
41
42 $content .= '[wpupg-filter id="' . $grid->slug() . '"]';
43 $content .= '[wpupg-grid id="' . $grid->slug() . '"]';
44
45 add_filter( 'the_content', array( $this, 'content_filter' ), 10 );
46 }
47
48 return $content;
49 }
50 }