Plugin Directory

Changeset 2789717


Ignore:
Timestamp:
09/24/2022 06:02:28 PM (4 years ago)
Author:
greencp
Message:

v2.5

Location:
wp-performance-pack/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • wp-performance-pack/trunk/modules/disable_widgets/class.wppp_disable_widgets.php

    r2369424 r2789717  
    2525    function init() {
    2626        // 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                }
    3335            }
    3436        }
  • wp-performance-pack/trunk/modules/dynamic_images/class.wppp_serve_image.php

    r2369424 r2789717  
    208208            }
    209209            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            */
    210218
    211219            // create intermediate file name before resizing in order to serve intermediate images from file if they are mirrored into wppp folder
     
    262270                    $data['data'] = ob_get_contents(); // read from buffer
    263271                    ob_end_clean();
    264                     if ( strlen( $data[ 'data' ] ) <= 64 * 1024 )
     272                    if ( strlen( $data[ 'data' ] ) <= 256 * 1024 )
    265273                        wp_cache_set( $this->localfilename . $this->width . 'x' . $this->height, $data, 'wppp', 24 * HOUR_IN_SECONDS );
    266274                    header( 'Content-Length: ' . strlen( $data[ 'data' ] ) );
  • wp-performance-pack/trunk/modules/l10n_improvements/class.wppp_mo_dynamic.php

    r2325169 r2789717  
    8686        // The magic is 0x950412de
    8787        // 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;
    9090        // 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)
    9292        if ($magic_little == $magic || $magic_little_64 == $magic) {
    9393            return 'V';
     
    370370                    foreach ( unpack( 'C*', $key ) as $char ) {
    371371                        $hash_val = ( $hash_val << 4 ) + $char;
    372                         if( 0 !== ( $g = $hash_val & 0xF0000000 ) ){
     372                        if( 0 !== ( $g = $hash_val & (int)0xF0000000 ) ){
    373373                            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.
    375375                                /*
    376376                                workaround based on this function (adapted to actual used parameters):
     
    568568            if ( isset( $this->_nplurals ) ) {
    569569                $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
    571571                if ( isset( $ts[ $i ] ) ) {
    572572                    return $ts[ $i ];
  • wp-performance-pack/trunk/modules/wpfeatures/class.wppp_wpfeatures.php

    r2369424 r2789717  
    2020    }
    2121
    22     public function early_init () {
     22    public function early_init() {
    2323        if ( !$this->wppp->options[ 'jquery_migrate' ] ) {
    2424            //Remove JQuery migrate
    2525            add_action( 'wp_default_scripts', array( $this, 'remove_jquery_migrate' ) );
    2626        }
    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() {
    3037        if ( !$this->wppp->options[ 'emojis' ] )
    3138            $this->remove_emoji();
     
    5057        if ( !$this->wppp->options[ 'feed_links' ] )
    5158            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' ] )
    5360            remove_action( 'wp_head', 'feed_links_extra', 3 );  //removes comments feed.
    5461        if ( !$this->wppp->options[ 'adjacent_posts_links' ] )
     
    5764            // https://make.wordpress.org/core/2019/10/09/introducing-handling-of-big-images-in-wordpress-5-3/
    5865            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
    60147
    61148    function remove_jquery_migrate( &$scripts ) {
     
    114201        return $settings;
    115202    }
     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    }
    116311}
  • wp-performance-pack/trunk/modules/wpfeatures/class.wppp_wpfeatures_advanced.php

    r2228316 r2789717  
    2828                </td>
    2929            </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>
    3035            <tr>
    3136                <th scope="row"><?php _e( 'Edit lock', 'wp-performance-pack' ); ?></th>
     
    102107        <table class="form-table" style="clear:none">
    103108            <tr>
    104                 <th scope="row"><?php _e( 'JQuery migrate' ); ?></th>
     109                <th scope="row"><?php _e( 'JQuery Migrate (frontend)' ); ?></th>
    105110                <td><?php $this->e_switchButton( 'jquery_migrate' ); ?></td>
    106111            </tr>
  • wp-performance-pack/trunk/readme.txt

    r2369424 r2789717  
    33Tags: performance, image resizing, gettext, disable, cdn
    44Requires at least: 4.7
    5 Tested up to: 5.5
     5Tested up to: 6.2
    66Requires PHP: 5.3
    7 Stable tag: 2.4
     7Stable tag: 2.5
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    124124== Changelog ==
    125125
     126= 2.5 =
     127* [wpfeatures] NEW! Added option do disable comments and pingbacks
     128* PHP 8 deprecated fixes
     129* various small fixes
     130
    126131= 2.4 =
    127132* [dynimg] Some fixes and improvements when using object cache for intermediate image sizes.
  • wp-performance-pack/trunk/wp-performance-pack.php

    r2369424 r2789717  
    44    Plugin URI: http://wordpress.org/plugins/wp-performance-pack
    55    Description: Performance optimizations for WordPress. Improve localization performance and image handling, serve images through CDN. 
    6     Version: 2.4
     6    Version: 2.5
    77    Text Domain: wp-performance-pack
    88    Author: Bj&ouml;rn Ahrens
     
    130130     * @const string
    131131     */
    132     const wppp_version = '2.4';
     132    const wppp_version = '2.5';
    133133
    134134    /**
     
    178178        ),
    179179        'wpfeatures' => array(
     180            'comments'              => array( 'default' => true, 'type' => 'bool' ),
    180181            'emojis'                => array( 'default' => true, 'type' => 'bool' ),
    181182            'editlock'              => array( 'default' => true, 'type' => 'bool' ),
     
    249250        // initialize fields
    250251        global $wp_version;
    251         if ( !function_exists( 'is_plugin_active_for_network' ) ) {
    252             require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
    253         }
    254252
    255253        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            }
    257260            $this->check_update();
    258261            $this->load_options();
     
    261264            add_action( 'init', array ( $this, 'init' ) );
    262265            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' ) );
    263272
    264273            // activate and initialize modules
     
    270279                }
    271280            }
    272 
    273             // check that WPPP is loaded as first plugin
    274             self::plugin_load_first();
    275281
    276282            if ( $this->options['debug'] )
     
    319325     * Make sure WPPP is loaded as first plugin. Important for e.g. usage of dynamic MOs with all text domains.
    320326     */
    321     public static function plugin_load_first() {
     327    public function plugin_load_first() {
    322328        $path = plugin_basename( __FILE__ );
    323329
     
    348354            add_option( 'wppp_version', self::wppp_version );
    349355        }
    350         self::plugin_load_first();
     356        $this->plugin_load_first();
    351357    }
    352358
     
    394400            return;
    395401        }
    396    
     402
    397403        $installed = $this->get_option( 'wppp_version' );
    398404        if ( version_compare( $installed, self::wppp_version, '!=' ) ) {
Note: See TracChangeset for help on using the changeset viewer.