Changeset 2789717
- Timestamp:
- 09/24/2022 06:02:28 PM (4 years ago)
- Location:
- wp-performance-pack/trunk
- Files:
-
- 7 edited
-
modules/disable_widgets/class.wppp_disable_widgets.php (modified) (1 diff)
-
modules/dynamic_images/class.wppp_serve_image.php (modified) (2 diffs)
-
modules/l10n_improvements/class.wppp_mo_dynamic.php (modified) (3 diffs)
-
modules/wpfeatures/class.wppp_wpfeatures.php (modified) (4 diffs)
-
modules/wpfeatures/class.wppp_wpfeatures_advanced.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
wp-performance-pack.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-performance-pack/trunk/modules/disable_widgets/class.wppp_disable_widgets.php
r2369424 r2789717 25 25 function init() { 26 26 // Load and register only the via WPPP enabled core widgets 27 foreach( $this->known_default_widgets as $widget => $files ) { 28 if ( !in_array( $widget, $this->wppp->options[ 'disabled_widgets' ] ) ) { 29 foreach ( $files as $file ) 30 include_once( ABSPATH . WPINC . '/widgets/' . $file ); 31 register_widget( $widget ); 32 $this->default_widget_loaded = true; 27 if ( is_array( $this->known_default_widgets ) ) { 28 foreach( $this->known_default_widgets as $widget => $files ) { 29 if ( !in_array( $widget, $this->wppp->options[ 'disabled_widgets' ] ) ) { 30 foreach ( $files as $file ) 31 include_once( ABSPATH . WPINC . '/widgets/' . $file ); 32 register_widget( $widget ); 33 $this->default_widget_loaded = true; 34 } 33 35 } 34 36 } -
wp-performance-pack/trunk/modules/dynamic_images/class.wppp_serve_image.php
r2369424 r2789717 208 208 } 209 209 unset( $sizes ); 210 211 /* 212 if ( $crop ) 213 header('Location: http://192.168.3.5:8085/insecure/rs:fill:' . $this->width . ':' . $this->height . ':1/g:sm/plain/local://' . $this->filename ); 214 else 215 header('Location: http://192.168.3.5:8085/insecure/rs:fit:' . $this->width . ':' . $this->height . ':1/g:sm/plain/local://' . $this->filename ); 216 exit; 217 */ 210 218 211 219 // create intermediate file name before resizing in order to serve intermediate images from file if they are mirrored into wppp folder … … 262 270 $data['data'] = ob_get_contents(); // read from buffer 263 271 ob_end_clean(); 264 if ( strlen( $data[ 'data' ] ) <= 64* 1024 )272 if ( strlen( $data[ 'data' ] ) <= 256 * 1024 ) 265 273 wp_cache_set( $this->localfilename . $this->width . 'x' . $this->height, $data, 'wppp', 24 * HOUR_IN_SECONDS ); 266 274 header( 'Content-Length: ' . strlen( $data[ 'data' ] ) ); -
wp-performance-pack/trunk/modules/l10n_improvements/class.wppp_mo_dynamic.php
r2325169 r2789717 86 86 // The magic is 0x950412de 87 87 // bug in PHP 5.0.2, see https://savannah.nongnu.org/bugs/?func=detailitem&item_id=10565 88 $magic_little = (int) -1794895138;89 $magic_little_64 = (int) 2500072158;88 $magic_little = (int)-1794895138; 89 $magic_little_64 = (int)2500072158; 90 90 // 0xde120495 91 $magic_big = ( (int) - 569244523) & 0xFFFFFFFF;91 $magic_big = ( (int)-569244523 ) & (int)0xFFFFFFFF; // explicit cast 0xFFFFFFFF to int so it doesn't become a float (= 4.294.967.295) 92 92 if ($magic_little == $magic || $magic_little_64 == $magic) { 93 93 return 'V'; … … 370 370 foreach ( unpack( 'C*', $key ) as $char ) { 371 371 $hash_val = ( $hash_val << 4 ) + $char; 372 if( 0 !== ( $g = $hash_val & 0xF0000000 ) ){372 if( 0 !== ( $g = $hash_val & (int)0xF0000000 ) ){ 373 373 if ( $g < 0 ) 374 $hash_val ^= ( ( ( $g & 0x7FFFFFFF ) >> 24 ) |0x80 ); // wordaround: php operator >> is arithmetic, not logic, so shifting negative values gives unexpected results. Cut sign bit, shift right, set sign bit again.374 $hash_val ^= ( ( ( $g & (int)0x7FFFFFFF ) >> 24 ) | (int)0x80 ); // wordaround: php operator >> is arithmetic, not logic, so shifting negative values gives unexpected results. Cut sign bit, shift right, set sign bit again. 375 375 /* 376 376 workaround based on this function (adapted to actual used parameters): … … 568 568 if ( isset( $this->_nplurals ) ) { 569 569 $ts = explode( self::PLURAL_SEP, $t, $this->_nplurals ); 570 $i = $this->gettext_select_plural_form( $count );570 $i = $this->gettext_select_plural_form( (int)$count ); // Sometimes $count passed to translate_plural isn't an int value, so explicitly cast it to int to avoid warnings 571 571 if ( isset( $ts[ $i ] ) ) { 572 572 return $ts[ $i ]; -
wp-performance-pack/trunk/modules/wpfeatures/class.wppp_wpfeatures.php
r2369424 r2789717 20 20 } 21 21 22 public function early_init () {22 public function early_init() { 23 23 if ( !$this->wppp->options[ 'jquery_migrate' ] ) { 24 24 //Remove JQuery migrate 25 25 add_action( 'wp_default_scripts', array( $this, 'remove_jquery_migrate' ) ); 26 26 } 27 } 28 29 function init () { 27 28 if ( !$this->wppp->options[ 'comments' ] ) { 29 // Completely disable comments 30 add_action( 'widgets_init', array( $this, 'disable_recent_comments_widget' ) ); // Check if WPPP disable widgets is acitvated and if so, use that feature instead 31 remove_action( 'init', 'register_block_core_post_comments' ); 32 remove_action( 'init', 'register_block_core_post_comments_form' ); 33 } 34 } 35 36 function init() { 30 37 if ( !$this->wppp->options[ 'emojis' ] ) 31 38 $this->remove_emoji(); … … 50 57 if ( !$this->wppp->options[ 'feed_links' ] ) 51 58 remove_action( 'wp_head', 'feed_links', 2 ); //removes feed links. 52 if ( !$this->wppp->options[ 'feed_links_extra' ] )59 if ( !$this->wppp->options[ 'feed_links_extra' ] || !$this->wppp->options[ 'comments' ] ) 53 60 remove_action( 'wp_head', 'feed_links_extra', 3 ); //removes comments feed. 54 61 if ( !$this->wppp->options[ 'adjacent_posts_links' ] ) … … 57 64 // https://make.wordpress.org/core/2019/10/09/introducing-handling-of-big-images-in-wordpress-5-3/ 58 65 add_filter( 'big_image_size_threshold', '__return_false' ); 59 } 66 67 if ( !$this->wppp->options[ 'comments' ] ) { 68 // Completely disable comments 69 70 // Hide existing comments 71 add_filter( 'comments_array', '__return_empty_array', 10, 2 ); 72 add_filter( 'wp_count_comments', array( $this, 'filter_wp_count_comments' ), 20, 2 ); // prevent comment queries 73 74 // Disable Recent Comments Widget 75 // TODO: Check if WPPP disable widgets is acitvated and if so, use that feature instead 76 add_action( 'widgets_init', function() { 77 unregister_widget('WP_Widget_Recent_Comments'); 78 add_filter( 'show_recent_comments_widget_style', '__return_false' ); // Remove the widgets style action - source "disable comments" plugin 79 } ); 80 81 // Close comments on the front-end 82 add_filter( 'comments_open', '__return_false', 20, 2 ); 83 add_filter( 'pings_open', '__return_false', 20, 2 ); 84 85 // Disable Pingbacks (source https://www.pmg.com/blog/pingback-killer) 86 add_filter( 'wp_headers', array( $this, 'remove_pingback_header' ), 10, 1 ); 87 add_filter( 'bloginfo_url', array( $this, 'kill_pingback_url' ), 10, 2 ); 88 add_filter( 'pre_update_default_ping_status', '__return_false' ); 89 add_filter( 'pre_option_default_ping_status', '__return_zero' ); 90 add_filter( 'pre_update_default_pingback_flag', '__return_false' ); 91 add_filter( 'pre_option_default_pingback_flag', '__return_zero' ); 92 93 // Disable Comments REST API Endpoint 94 add_filter( 'rest_endpoints', array( $this, 'uncomment_restapi' ) ); 95 add_filter( 'rest_pre_insert_comment', function() { return; }, 10, 2); 96 add_filter( 'xmlrpc_methods', array( $this, 'uncomment_xmlrpc' ) ); 97 } 98 } 99 100 function admin_init() { 101 if ( !$this->wppp->options[ 'comments' ] ) { 102 // Completely disable comments 103 104 // Redirect any user trying to access a comments related page 105 global $pagenow; 106 if ( $pagenow == 'comment.php' || $pagenow == 'edit-comments.php' || $pagenow == 'options-discussion.php' ) { 107 wp_safe_redirect( admin_url() ); 108 exit; 109 } 110 111 // Disable support for comments and trackbacks in post types 112 foreach ( get_post_types() as $post_type ) { 113 if ( post_type_supports( $post_type, 'comments' ) ) { 114 remove_post_type_support( $post_type, 'comments' ); 115 remove_post_type_support( $post_type, 'trackbacks' ); 116 } 117 } 118 119 // Prevent self pings (source: https://wordpress.org/plugins/no-self-ping) 120 add_action( 'pre_ping', array( $this, 'no_self_ping' ) ); 121 122 // Remove admin bar link 123 if ( is_admin_bar_showing() ) { 124 remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); // Remove comments links from admin bar. 125 } 126 127 if ( is_admin() ) { 128 // Backend 129 130 // Remove comment related dashboard widgets 131 add_action( 'wp_dashboard_setup', array( $this, 'disable_dashboard_widgets' ) ); 132 // Remove comments page in menu 133 add_action( 'admin_menu', function() { 134 remove_menu_page('edit-comments.php'); 135 remove_submenu_page( 'options-general.php', 'options-discussion.php' ); 136 } ); 137 138 } else { 139 // Frontend 140 141 } 142 } 143 } 144 145 146 60 147 61 148 function remove_jquery_migrate( &$scripts ) { … … 114 201 return $settings; 115 202 } 203 204 /* 205 * Disable comments functions 206 */ 207 208 public function filter_wp_count_comments( $comments, $post_id ) { 209 return (object) array( 210 'approved' => 0, 211 'awaiting_moderation' => 0, 212 'moderated' => 0, 213 'spam' => 0, 214 'trash' => 0, 215 'post-trashed' => 0, 216 'total_comments' => 0, 217 'all' => 0 218 ); 219 } 220 221 public function disable_dashboard_widgets() { 222 // Replace original activity widget with a copy that doesn't check for comments 223 wp_add_dashboard_widget( 'dashboard_activity_nc', __( 'Activity' ), array( $this, 'dashboard_site_activity_nocomments' ) ); 224 remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' ); 225 remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); 226 } 227 228 function dashboard_site_activity_nocomments() { 229 // This is a copy of wp_dashboard_site_activity from dashboard.php but with anything regarding comment disabled 230 // it replaces the original activiy dashboard widget 231 echo '<div id="activity-widget">'; 232 233 $future_posts = wp_dashboard_recent_posts( 234 array( 235 'max' => 5, 236 'status' => 'future', 237 'order' => 'ASC', 238 'title' => __( 'Publishing Soon' ), 239 'id' => 'future-posts', 240 ) 241 ); 242 $recent_posts = wp_dashboard_recent_posts( 243 array( 244 'max' => 5, 245 'status' => 'publish', 246 'order' => 'DESC', 247 'title' => __( 'Recently Published' ), 248 'id' => 'published-posts', 249 ) 250 ); 251 252 //$recent_comments = wp_dashboard_recent_comments(); 253 254 if ( ! $future_posts && ! $recent_posts ) { //&& ! $recent_comments ) { 255 echo '<div class="no-activity">'; 256 echo '<p>' . __( 'No activity yet!' ) . '</p>'; 257 echo '</div>'; 258 } 259 260 echo '<p>Comments disabled by WPPP</p>'; 261 262 echo '</div>'; 263 } 264 265 public function disable_recent_comments_widget() 266 { 267 unregister_widget( 'WP_Widget_Recent_Comments' ); 268 add_filter( 'show_recent_comments_widget_style', '__return_false' ); // Remove the widgets style action - source "disable comments" plugin 269 } 270 271 public function uncomment_xmlrpc( $methods ) { 272 if ( isset( $methods[ 'wp.newComment' ] ) ) { 273 unset( $methods[ 'wp.newComment' ] ); 274 } 275 if ( isset( $methods[ 'pingback.ping' ] ) ) { 276 unset( $methods[ 'pingback.ping' ] ); 277 } 278 return $methods; 279 } 280 281 public function uncomment_restapi( $endpoints ) { 282 if ( isset( $endpoints[ 'comments' ] ) ) { 283 unset( $endpoints[ 'comments' ] ); 284 } 285 return $endpoints; 286 } 287 288 function remove_pingback_header( $headers ) { 289 if( isset( $headers[ 'X-Pingback' ] ) ) { 290 unset( $headers[ 'X-Pingback' ] ); 291 } 292 return $headers; 293 } 294 295 function kill_pingback_url( $output, $show ) { 296 if( $show == 'pingback_url' ) { 297 $output = ''; 298 } 299 return $output; 300 } 301 302 function no_self_ping( &$links ) { 303 $home = esc_url( home_url() ); 304 // Process each link in the content and remove is it matches the current site URL 305 foreach ( $links as $l => $link ) { 306 if ( 0 === strpos( $link, $home ) ) { 307 unset( $links[ $l ] ); 308 } 309 } 310 } 116 311 } -
wp-performance-pack/trunk/modules/wpfeatures/class.wppp_wpfeatures_advanced.php
r2228316 r2789717 28 28 </td> 29 29 </tr> 30 <tr> 31 <th scope="row"><?php _e( 'Comments and Pingbacks', 'wp-performance-pack' ); ?></th> 32 <td> 33 <?php $this->e_switchButton( 'comments' ); ?> 34 </td> 30 35 <tr> 31 36 <th scope="row"><?php _e( 'Edit lock', 'wp-performance-pack' ); ?></th> … … 102 107 <table class="form-table" style="clear:none"> 103 108 <tr> 104 <th scope="row"><?php _e( 'JQuery migrate' ); ?></th>109 <th scope="row"><?php _e( 'JQuery Migrate (frontend)' ); ?></th> 105 110 <td><?php $this->e_switchButton( 'jquery_migrate' ); ?></td> 106 111 </tr> -
wp-performance-pack/trunk/readme.txt
r2369424 r2789717 3 3 Tags: performance, image resizing, gettext, disable, cdn 4 4 Requires at least: 4.7 5 Tested up to: 5.55 Tested up to: 6.2 6 6 Requires PHP: 5.3 7 Stable tag: 2. 47 Stable tag: 2.5 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 124 124 == Changelog == 125 125 126 = 2.5 = 127 * [wpfeatures] NEW! Added option do disable comments and pingbacks 128 * PHP 8 deprecated fixes 129 * various small fixes 130 126 131 = 2.4 = 127 132 * [dynimg] Some fixes and improvements when using object cache for intermediate image sizes. -
wp-performance-pack/trunk/wp-performance-pack.php
r2369424 r2789717 4 4 Plugin URI: http://wordpress.org/plugins/wp-performance-pack 5 5 Description: Performance optimizations for WordPress. Improve localization performance and image handling, serve images through CDN. 6 Version: 2. 46 Version: 2.5 7 7 Text Domain: wp-performance-pack 8 8 Author: Björn Ahrens … … 130 130 * @const string 131 131 */ 132 const wppp_version = '2. 4';132 const wppp_version = '2.5'; 133 133 134 134 /** … … 178 178 ), 179 179 'wpfeatures' => array( 180 'comments' => array( 'default' => true, 'type' => 'bool' ), 180 181 'emojis' => array( 'default' => true, 'type' => 'bool' ), 181 182 'editlock' => array( 'default' => true, 'type' => 'bool' ), … … 249 250 // initialize fields 250 251 global $wp_version; 251 if ( !function_exists( 'is_plugin_active_for_network' ) ) {252 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );253 }254 252 255 253 if ( $fullinit ) { 256 $this->is_network = is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ); 254 if ( is_multisite() ) { 255 if ( !function_exists( 'is_plugin_active_for_network' ) ) { 256 require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); 257 } 258 $this->is_network = is_plugin_active_for_network( plugin_basename( __FILE__ ) ); 259 } 257 260 $this->check_update(); 258 261 $this->load_options(); … … 261 264 add_action( 'init', array ( $this, 'init' ) ); 262 265 add_action( 'admin_init', array ( $this, 'admin_init' ) ); 266 // check that WPPP is loaded as first plugin 267 // do this on wp_loaded after wordpress is fully initialized and all other plugins are loaded 268 // so it will load first on next load. otherwise this could conflict with another plugin resorting the 269 // plugin order 270 // TODO: Maybe add this to settings instead of doing it every time 271 add_action( 'wp_loaded', array( $this, 'plugin_load_first' ) ); 263 272 264 273 // activate and initialize modules … … 270 279 } 271 280 } 272 273 // check that WPPP is loaded as first plugin274 self::plugin_load_first();275 281 276 282 if ( $this->options['debug'] ) … … 319 325 * Make sure WPPP is loaded as first plugin. Important for e.g. usage of dynamic MOs with all text domains. 320 326 */ 321 public staticfunction plugin_load_first() {327 public function plugin_load_first() { 322 328 $path = plugin_basename( __FILE__ ); 323 329 … … 348 354 add_option( 'wppp_version', self::wppp_version ); 349 355 } 350 self::plugin_load_first();356 $this->plugin_load_first(); 351 357 } 352 358 … … 394 400 return; 395 401 } 396 402 397 403 $installed = $this->get_option( 'wppp_version' ); 398 404 if ( version_compare( $installed, self::wppp_version, '!=' ) ) {
Note: See TracChangeset
for help on using the changeset viewer.