Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Jetpack Compatibility File |
||
| 4 | * See: https://jetpack.com/ |
||
| 5 | * |
||
| 6 | * @package Jetpack |
||
| 7 | */ |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Add Jetpack extra functionality to Twenty Twenty. |
||
| 11 | * |
||
| 12 | * See: https://jetpack.com/support/infinite-scroll/ |
||
| 13 | * See: https://jetpack.com/support/responsive-videos/ |
||
| 14 | * See: https://jetpack.com/support/content-options/ |
||
| 15 | */ |
||
| 16 | View Code Duplication | function twentytwenty_jetpack_setup() { |
|
| 17 | /** |
||
| 18 | * Add theme support for Infinite Scroll. |
||
| 19 | */ |
||
| 20 | add_theme_support( |
||
| 21 | 'infinite-scroll', |
||
| 22 | array( |
||
| 23 | 'type' => 'click', |
||
| 24 | 'container' => 'site-content', |
||
| 25 | 'render' => 'twentytwenty_infinite_scroll_render', |
||
| 26 | 'footer' => 'site-content', |
||
| 27 | 'footer_widgets' => array( |
||
| 28 | 'sidebar-1', |
||
| 29 | 'sidebar-2', |
||
| 30 | ), |
||
| 31 | ) |
||
| 32 | ); |
||
| 33 | |||
| 34 | // Add theme support for Content Options. |
||
| 35 | add_theme_support( |
||
| 36 | 'jetpack-content-options', |
||
| 37 | array( |
||
| 38 | 'post-details' => array( |
||
| 39 | 'stylesheet' => 'twentytwenty-style', |
||
| 40 | 'date' => '.post-date', |
||
| 41 | 'categories' => '.entry-categories', |
||
| 42 | 'tags' => '.post-tags', |
||
| 43 | 'author' => '.post-author', |
||
| 44 | ), |
||
| 45 | 'featured-images' => array( |
||
| 46 | 'archive' => true, |
||
| 47 | 'post' => true, |
||
| 48 | 'page' => true, |
||
| 49 | 'fallback' => false, |
||
| 50 | ), |
||
| 51 | ) |
||
| 52 | ); |
||
| 53 | |||
| 54 | // Social Menu. |
||
| 55 | add_theme_support( 'jetpack-social-menu', 'svg' ); |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Add theme support for geo-location. |
||
| 59 | */ |
||
| 60 | add_theme_support( 'jetpack-geo-location' ); |
||
| 61 | } |
||
| 62 | add_action( 'after_setup_theme', 'twentytwenty_jetpack_setup' ); |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Custom render function for Infinite Scroll. |
||
| 66 | */ |
||
| 67 | function twentytwenty_infinite_scroll_render() { |
||
| 68 | while ( have_posts() ) { |
||
| 69 | echo '<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true" />'; |
||
| 70 | the_post(); |
||
| 71 | get_template_part( 'template-parts/content', get_post_type() ); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Remove Sharing buttons and Likes from excerpts that are used as intro on single post views. |
||
| 77 | */ |
||
| 78 | function twentytwenty_no_sharing_on_excerpts() { |
||
| 79 | if ( is_single() ) { |
||
| 80 | // Remove sharing buttons. |
||
| 81 | remove_filter( 'the_excerpt', 'sharing_display', 19 ); |
||
| 82 | |||
| 83 | // Remove Likes. |
||
| 84 | if ( class_exists( 'Jetpack_Likes' ) ) { |
||
| 85 | remove_filter( 'the_excerpt', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 ); |
||
|
0 ignored issues
–
show
|
|||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | add_action( 'loop_start', 'twentytwenty_no_sharing_on_excerpts' ); |
||
| 90 | |||
| 91 | /** |
||
| 92 | * We do not need to display the Likes Heading here. |
||
| 93 | * |
||
| 94 | * @param string $heading Headline structure. |
||
| 95 | * @param string $title Title. |
||
| 96 | * @param string $module Module name. |
||
| 97 | */ |
||
| 98 | function twentytwenty_no_likes_heading( $heading, $title, $module ) { |
||
| 99 | if ( 'likes' === $module ) { |
||
| 100 | return ''; |
||
| 101 | } |
||
| 102 | |||
| 103 | return $heading; |
||
| 104 | } |
||
| 105 | add_filter( 'jetpack_sharing_headline_html', 'twentytwenty_no_likes_heading', 10, 3 ); |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Disable Ads in post excerpts, that are used as intro on single post views. |
||
| 109 | */ |
||
| 110 | add_filter( 'wordads_excerpt_disable', '__return_true' ); |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Add our compat CSS file for Infinite Scroll and custom widget stylings and such. |
||
| 114 | * Set the version equal to filemtime for development builds, and the JETPACK__VERSION for production |
||
| 115 | * or skip it entirely for wpcom. |
||
| 116 | */ |
||
| 117 | View Code Duplication | function twentytwenty_enqueue_jetpack_style() { |
|
| 118 | $version = Jetpack::is_development_version() |
||
| 119 | ? filemtime( JETPACK__PLUGIN_DIR . 'modules/theme-tools/compat/twentytwenty.css' ) |
||
| 120 | : JETPACK__VERSION; |
||
| 121 | |||
| 122 | wp_enqueue_style( 'twentytwenty-jetpack', plugins_url( 'twentytwenty.css', __FILE__ ), array(), $version ); |
||
| 123 | wp_style_add_data( 'twentytwenty-jetpack', 'rtl', 'replace' ); |
||
| 124 | } |
||
| 125 | add_action( 'wp_enqueue_scripts', 'twentytwenty_enqueue_jetpack_style' ); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Add inline custom CSS with custom accent color if there is any set. |
||
| 129 | */ |
||
| 130 | function twentytwenty_infinity_accent_color_css() { |
||
| 131 | // Bail early if no custom color was set. |
||
| 132 | if ( |
||
| 133 | 'custom' !== get_theme_mod( 'accent_hue_active' ) |
||
| 134 | || empty( get_theme_mod( 'accent_accessible_colors' ) ) |
||
| 135 | ) { |
||
| 136 | return; |
||
| 137 | } |
||
| 138 | |||
| 139 | $color_info = get_theme_mod( 'accent_accessible_colors' ); |
||
| 140 | $custom_css = sprintf( |
||
| 141 | ' |
||
| 142 | .infinite-scroll #site-content #infinite-handle span button, |
||
| 143 | .infinite-scroll #site-content #infinite-handle span button:hover, |
||
| 144 | .infinite-scroll #site-content #infinite-handle span button:focus { |
||
| 145 | background: %1$s; |
||
| 146 | color: %2$s; |
||
| 147 | } |
||
| 148 | #site-content .entry-content div.sharedaddy h3.sd-title, |
||
| 149 | #site-content .entry-content h3.sd-title, |
||
| 150 | #site-content .entry-content #jp-relatedposts h3.jp-relatedposts-headline { |
||
| 151 | color: %3$s; |
||
| 152 | } |
||
| 153 | ', |
||
| 154 | $color_info['content']['accent'], |
||
| 155 | $color_info['content']['background'], |
||
| 156 | $color_info['content']['secondary'] |
||
| 157 | ); |
||
| 158 | |||
| 159 | // Add our custom style to the existing Twenty Twenty CSS compat file. |
||
| 160 | wp_add_inline_style( 'twentytwenty-jetpack', $custom_css ); |
||
| 161 | } |
||
| 162 | add_action( 'wp_enqueue_scripts', 'twentytwenty_infinity_accent_color_css' ); |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Load AMP theme specific hooks for infinite scroll. |
||
| 166 | * |
||
| 167 | * @return void |
||
| 168 | */ |
||
| 169 | function amp_twentytwenty_infinite_scroll_render_hooks() { |
||
| 170 | add_filter( 'jetpack_amp_infinite_footers', 'twentytwenty_amp_infinite_footers', 10, 2 ); |
||
| 171 | add_filter( 'jetpack_amp_infinite_output', 'twentytwenty_amp_infinite_output' ); |
||
| 172 | add_filter( 'jetpack_amp_infinite_separator', 'twentytwenty_amp_infinite_separator' ); |
||
| 173 | add_filter( 'jetpack_amp_infinite_older_posts', 'twentytwenty_amp_infinite_older_posts' ); |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Get the theme specific footers. |
||
| 178 | * |
||
| 179 | * @param array $footers The footers of the themes. |
||
| 180 | * @param string $buffer Contents of the output buffer. |
||
| 181 | * |
||
| 182 | * @return mixed |
||
| 183 | */ |
||
| 184 | function twentytwenty_amp_infinite_footers( $footers, $buffer ) { |
||
| 185 | // Collect the footer wrapper. |
||
| 186 | preg_match( |
||
| 187 | '/<div class="footer-nav-widgets-wrapper.*<!-- .footer-nav-widgets-wrapper -->/s', |
||
| 188 | $buffer, |
||
| 189 | $footer |
||
| 190 | ); |
||
| 191 | $footers[] = reset( $footer ); |
||
| 192 | |||
| 193 | // Collect the footer wrapper. |
||
| 194 | preg_match( |
||
| 195 | '/<footer id="site-footer".*<!-- #site-footer -->/s', |
||
| 196 | $buffer, |
||
| 197 | $footer |
||
| 198 | ); |
||
| 199 | $footers[] = reset( $footer ); |
||
| 200 | |||
| 201 | return $footers; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Hide and remove various elements from next page load. |
||
| 206 | * |
||
| 207 | * @param string $buffer Contents of the output buffer. |
||
| 208 | * |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | function twentytwenty_amp_infinite_output( $buffer ) { |
||
| 212 | // Hide site header on next page load. |
||
| 213 | $buffer = preg_replace( |
||
| 214 | '/id="site-header"/', |
||
| 215 | '$0 next-page-hide', |
||
| 216 | $buffer |
||
| 217 | ); |
||
| 218 | |||
| 219 | // Hide pagination on next page load. |
||
| 220 | $buffer = preg_replace( |
||
| 221 | '/class=".*pagination-wrapper.*"/', |
||
| 222 | '$0 next-page-hide hidden', |
||
| 223 | $buffer |
||
| 224 | ); |
||
| 225 | |||
| 226 | // Remove the footer as it will be added back to amp next page footer. |
||
| 227 | $buffer = preg_replace( |
||
| 228 | '/<div class="footer-nav-widgets-wrapper.*<!-- .footer-nav-widgets-wrapper -->/s', |
||
| 229 | '', |
||
| 230 | $buffer |
||
| 231 | ); |
||
| 232 | |||
| 233 | // Remove the footer as it will be added back to amp next page footer. |
||
| 234 | $buffer = preg_replace( |
||
| 235 | '/<footer id="site-footer".*<!-- #site-footer -->/s', |
||
| 236 | '', |
||
| 237 | $buffer |
||
| 238 | ); |
||
| 239 | |||
| 240 | return $buffer; |
||
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Filter the AMP infinite scroll separator |
||
| 245 | * |
||
| 246 | * @return string |
||
| 247 | */ |
||
| 248 | function twentytwenty_amp_infinite_separator() { |
||
| 249 | ob_start(); |
||
| 250 | ?> |
||
| 251 | <hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true"> |
||
| 252 | <?php |
||
| 253 | return ob_get_clean(); |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Filter the AMP infinite scroll older posts button |
||
| 258 | * |
||
| 259 | * @return string |
||
| 260 | */ |
||
| 261 | function twentytwenty_amp_infinite_older_posts() { |
||
| 262 | ob_start(); |
||
| 263 | ?> |
||
| 264 | <div id="infinite-handle" class="read-more-button-wrap"> |
||
| 265 | <span> |
||
| 266 | <a href="{{url}}" class="more-link" rel="amphtml"> |
||
| 267 | <span class="faux-button"> |
||
| 268 | <?php esc_html_e( 'Older posts', 'jetpack' ); ?> |
||
| 269 | </span> |
||
| 270 | </a> |
||
| 271 | </span> |
||
| 272 | </div> |
||
| 273 | <?php |
||
| 274 | return ob_get_clean(); |
||
| 275 | } |
||
| 276 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.