PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 All 502 releases
jetpack / modules / theme-tools / compat / twentynineteen.php

twentynineteen.php in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at modules/theme-tools/compat/twentynineteen.php

171 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Jetpack Compatibility File
4 * See: https://jetpack.com/
5 *
6 * @package automattic/jetpack
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit( 0 );
11 }
12
13 /**
14 * Add Jetpack theme supports for Twenty Nineteen.
15 */
16 function twentynineteen_jetpack_setup() {
17
18 /**
19 * Add theme support for Infinite Scroll.
20 */
21 add_theme_support(
22 'infinite-scroll',
23 array(
24 'type' => 'click',
25 'container' => 'main',
26 'render' => 'twentynineteen_infinite_scroll_render',
27 'footer' => 'page',
28 )
29 );
30 }
31 add_action( 'after_setup_theme', 'twentynineteen_jetpack_setup' );
32
33 /**
34 * Custom render function for Infinite Scroll.
35 */
36 function twentynineteen_infinite_scroll_render() {
37 while ( have_posts() ) {
38 the_post();
39 get_template_part( 'template-parts/content/content' );
40 }
41 }
42
43 /**
44 * Enqueue Jetpack compat styles for Twenty Nineteen.
45 */
46 function twentynineteen_init_jetpack() {
47 /**
48 * Add our compat CSS file for Infinite Scroll and custom widget stylings and such.
49 * Set the version equal to filemtime for development builds, and the JETPACK__VERSION for production
50 * or skip it entirely for wpcom.
51 */
52 if ( ! is_admin() ) {
53 $version = false;
54 if ( method_exists( 'Jetpack', 'is_development_version' ) ) {
55 $version = Jetpack::is_development_version() ? filemtime( plugin_dir_path( __FILE__ ) . 'twentynineteen.css' ) : JETPACK__VERSION;
56 }
57 wp_enqueue_style( 'twentynineteen-jetpack', plugins_url( 'twentynineteen.css', __FILE__ ), array(), $version );
58 wp_style_add_data( 'twentynineteen-jetpack', 'rtl', 'replace' );
59 }
60 }
61 add_action( 'init', 'twentynineteen_init_jetpack' );
62
63 /**
64 * Alter gallery widget default width.
65 */
66 function twentynineteen_gallery_widget_content_width() {
67 return 390;
68 }
69 add_filter( 'gallery_widget_content_width', 'twentynineteen_gallery_widget_content_width' );
70
71 /**
72 * Adds custom classes to the array of body classes.
73 *
74 * @param array $classes Classes for the body element.
75 * @return array
76 */
77 function twentynineteen_jetpack_body_classes( $classes ) {
78 // Adds a class if we're in the Customizer.
79 if ( is_customize_preview() ) :
80 $classes[] = 'twentynineteen-customizer';
81 endif;
82
83 return $classes;
84 }
85 add_filter( 'body_class', 'twentynineteen_jetpack_body_classes' );
86
87 /**
88 * Load AMP theme specific hooks for infinite scroll.
89 *
90 * @return void
91 */
92 function amp_twentynineteen_infinite_scroll_render_hooks() {
93 add_filter( 'jetpack_amp_infinite_footers', 'twentynineteen_amp_infinite_footers', 10, 2 );
94 add_filter( 'jetpack_amp_infinite_output', 'twentynineteen_amp_infinite_output' );
95 add_filter( 'jetpack_amp_infinite_older_posts', 'twentynineteen_amp_infinite_older_posts' );
96 }
97
98 /**
99 * Get the theme specific footers.
100 *
101 * @param array $footers The footers of the themes.
102 * @param string $buffer Contents of the output buffer.
103 *
104 * @return mixed
105 */
106 function twentynineteen_amp_infinite_footers( $footers, $buffer ) {
107 // Collect the footer wrapper.
108 preg_match(
109 '/<footer id="colophon".*<!-- #colophon -->/s',
110 $buffer,
111 $footer
112 );
113 $footers[] = reset( $footer );
114
115 return $footers;
116 }
117
118 /**
119 * Hide and remove various elements from next page load.
120 *
121 * @param string $buffer Contents of the output buffer.
122 *
123 * @return string
124 */
125 function twentynineteen_amp_infinite_output( $buffer ) {
126 // Hide site header on next page load.
127 $buffer = preg_replace(
128 '/id="masthead"/',
129 '$0 next-page-hide',
130 $buffer
131 );
132
133 // Hide pagination on next page load.
134 $buffer = preg_replace(
135 '/class=".*navigation pagination.*"/',
136 '$0 next-page-hide hidden',
137 $buffer
138 );
139
140 // Remove the footer as it will be added back to amp next page footer.
141 $buffer = preg_replace(
142 '/<footer id="colophon".*<!-- #colophon -->/s',
143 '',
144 $buffer
145 );
146
147 return $buffer;
148 }
149
150 /**
151 * Filter the AMP infinite scroll older posts button
152 *
153 * @return string
154 */
155 function twentynineteen_amp_infinite_older_posts() {
156 ob_start();
157 ?>
158 <div id="infinite-handle" style="text-align: center;">
159 <span>
160 <a href="{{url}}">
161 <button>
162 <?php esc_html_e( 'Older posts', 'jetpack' ); ?>
163 </button>
164 </a>
165 </span>
166 </div>
167 <?php
168 return ob_get_clean();
169 }
170
171