Plugin Directory

Changeset 1117133


Ignore:
Timestamp:
03/20/2015 07:48:27 PM (11 years ago)
Author:
barragan
Message:

Check if WP_POST_REVISIONS is already defined in wp-config.php file.

Location:
wp-revisions-limit/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-revisions-limit/trunk/README.txt

    r1116968 r1117133  
    44Requires at least: 3.6
    55Tested up to: 4.1
    6 Stable tag: 1.0.0
     6Stable tag: 1.0.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3333== Changelog ==
    3434
     35= 1.0.1 =
     36* Check if WP_POST_REVISIONS is already defined in wp-config.php file.
     37
    3538= 1.0.0 =
    3639* Initial public release
  • wp-revisions-limit/trunk/admin/class-wp-revisions-limit-admin.php

    r1116908 r1117133  
    4646
    4747    /**
     48     * Holds the name of WP_POST_REVISIONS constant
     49     */
     50    const WP_POST_REVISIONS = 'WP_POST_REVISIONS';
     51
     52    /**
    4853     * Holds the default value of revisions number
    4954     */
    50     private $default_revisions_limit;
     55    const DEFAULT_REVISIONS_LIMIT = 5;
    5156
    5257    /**
     
    6166        $this->plugin_name = $plugin_name;
    6267        $this->version = $version;
    63         $this->default_revisions_limit = 5;
    6468
    6569    }
     
    186190        }
    187191
    188         require_once 'partials/wp-revisions-limit-admin-display.php';
     192        $wp_config_file = $_SERVER["DOCUMENT_ROOT"] . '/wp-config.php';
     193        $contents = file_get_contents( $wp_config_file );
     194        $pattern = "define\(( )?'WP_POST_REVISIONS'";
     195        $pattern = "/^$pattern.*/m";
     196
     197        if ( !preg_match_all( $pattern, $contents, $matches ) ) {
     198            require_once 'partials/wp-revisions-limit-admin-display.php';
     199        } else {
     200            wp_die( __( 'Constant WP_POST_REVISIONS is already defined in wp-config.php file, remove it to be able to set up a limit for your post revisions.' ) );
     201        }
    189202
    190203    }
     
    211224    public function define_post_revisions() {
    212225
    213         $this->load_options();
    214        
    215         if ( isset( $this->options['revisions_limit'] ) && $this->options['revisions_limit'] != '' ) {
    216             if ( is_numeric( $this->options['revisions_limit'] ) ) {
    217                 define( 'WP_POST_REVISIONS', (int)$this->options['revisions_limit'] + 1 );
     226        if ( !defined( self::WP_POST_REVISIONS ) ) {
     227            $this->load_options();
     228           
     229            if ( isset( $this->options['revisions_limit'] ) && $this->options['revisions_limit'] != '' ) {
     230                if ( is_numeric( $this->options['revisions_limit'] ) ) {
     231                    define( self::WP_POST_REVISIONS, (int)$this->options['revisions_limit'] + 1 );
     232                } else {
     233                    define( self::WP_POST_REVISIONS, self::DEFAULT_REVISIONS_LIMIT );
     234                }
    218235            } else {
    219                 define( 'WP_POST_REVISIONS', $this->default_revisions_limit );
     236                define( self::WP_POST_REVISIONS, self::DEFAULT_REVISIONS_LIMIT );
    220237            }
    221         } else {
    222             define( 'WP_POST_REVISIONS', $this->default_revisions_limit );
    223         }
    224 
     238        }
    225239    }
    226240
     
    232246    public function load_options() {
    233247
    234         if ( !$this->options )
     248        if ( !isset( $this->options ) ) {
    235249            $this->options = get_option( 'revisions_limit_option' );
     250        }
    236251
    237252        return $this->options;
  • wp-revisions-limit/trunk/wp-revisions-limit.php

    r1116908 r1117133  
    1111 * Plugin URI:        http://www.twomandarins.com
    1212 * Description:       Limit number of revisions stored.
    13  * Version:           1.0.0
     13 * Version:           1.0.1
    1414 * Author:            Roger Rodrigo (TwoMandarins)
    1515 * Author URI:        http://www.twomandarins.com
Note: See TracChangeset for help on using the changeset viewer.