Plugin Directory

Changeset 958566


Ignore:
Timestamp:
08/01/2014 09:21:56 AM (12 years ago)
Author:
samface
Message:

Fixed critical settings bug and some php notices/warnigns

Location:
angry-creative-logger/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • angry-creative-logger/trunk/classes/routine_handler.php

    r943414 r958566  
    22/*
    33Class name: ACI Routine Handler
    4 Version: 0.3.0
     4Version: 0.3.1
    55Depends: AC Inspector 0.5.x
    66Author: Sammy Nordström, Angry Creative AB
     
    3030        }
    3131
    32         public static function get_inspection_method($routine, $options = array()) {
    33 
    34             if (empty($routine)) {
    35                 return false;
    36             }
    37 
    38             if (!is_array($options) || empty($options)) {
    39 
    40                 $options = self::get_options($routine);
    41 
    42                 if (!is_array($options)) {
     32        public static function get_inspection_method( $routine, $options = array() ) {
     33
     34            if ( empty( $routine ) ) {
     35                return false;
     36            }
     37
     38            if ( !is_array( $options ) || empty( $options ) ) {
     39
     40                $options = self::get_options( $routine );
     41
     42                if ( !is_array( $options ) ) {
    4343                    $options = array();
    4444                }
     
    4646            }
    4747
    48             if (class_exists($routine)) {
    49 
    50                 if ($options['inspection_method'] && method_exists($routine, $options['inspection_method'])) {
    51 
    52                     return array($routine, $options['inspection_method']);
    53 
    54                 } else if (method_exists($routine, 'inspect')) {
    55 
    56                     return array($routine, 'inspect');
     48            if ( class_exists( $routine ) ) {
     49
     50                if ( !empty( $options['inspection_method'] ) && method_exists( $routine, $options['inspection_method'] ) ) {
     51
     52                    return array( $routine, $options['inspection_method'] );
     53
     54                } else if ( method_exists( $routine, 'inspect' ) ) {
     55
     56                    return array( $routine, 'inspect' );
    5757
    5858                }
     
    6060            }
    6161
    62             if (!empty($options['inspection_method']) && function_exists($options['inspection_method'])) {
     62            if ( !empty( $options['inspection_method'] ) && function_exists( $options['inspection_method'] ) ) {
    6363
    6464                return $options['inspection_method'];
    6565
    66             } else if (function_exists($routine)) {
     66            } else if ( function_exists( $routine ) ) {
    6767
    6868                return $routine;
     
    8686        }
    8787
    88         public static function get_options($routine) {
    89 
    90             if (empty($routine)) {
    91                 return false;
    92             }
    93 
    94             $options_key = self::routine_options_key($routine);
    95 
    96             $options = AC_Inspector::get_option($options_key);
    97 
    98             if ( $options['site_specific_settings'] && is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) {
     88        public static function get_options( $routine ) {
     89
     90            if ( empty( $routine ) ) {
     91                return false;
     92            }
     93
     94            $options_key = self::routine_options_key( $routine );
     95
     96            $options = AC_Inspector::get_option( $options_key );
     97
     98            if ( !empty( $options['site_specific_settings'] ) && is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) {
    9999
    100100                global $wpdb;
    101                 $site_blog_ids = $wpdb->get_col("SELECT blog_id FROM ".$wpdb->prefix."blogs");
    102 
    103                 if (is_array($site_blog_ids)) {
    104 
    105                     $global_opt_keys = array_keys($options);
     101                $site_blog_ids = $wpdb->get_col( "SELECT blog_id FROM ".$wpdb->prefix."blogs" );
     102
     103                if ( is_array( $site_blog_ids ) ) {
     104
     105                    $global_opt_keys = array_keys( $options );
    106106
    107107                    foreach( $site_blog_ids AS $site_blog_id ) {
    108108
    109                         if ( !is_array($options[$site_blog_id]) ) {
     109                        if ( !is_array( $options[$site_blog_id] ) ) {
    110110                            $options[$site_blog_id] = array();
    111111                        }
    112112
    113                         foreach($global_opt_keys as $global_opt_key ) {
    114 
    115                             if ( !is_numeric($global_opt_key) && $global_opt_key != 'site_specific_settings' && !isset($options[$site_blog_id][$global_opt_key]) ) {
     113                        foreach( $global_opt_keys as $global_opt_key ) {
     114
     115                            if ( !is_numeric( $global_opt_key ) && $global_opt_key != 'site_specific_settings' && !isset( $options[$site_blog_id][$global_opt_key] ) ) {
    116116                                $options[$site_blog_id][$global_opt_key] = $options[$global_opt_key];
    117117                            }
     
    138138        }
    139139
    140         public static function add($routine, $options = array(), $action = "ac_inspection", $priority = 10, $accepted_args = 1) {
    141 
    142             $inspection_method = self::get_inspection_method($routine, $options);
    143 
    144             if ( !$inspection_method ) {
    145                 return false;
    146             }
    147 
    148             if ( empty($action) ) {
     140        public static function add( $routine, $options = array(), $action = "ac_inspection", $priority = 10, $accepted_args = 1 ) {
     141
     142            $inspection_method = self::get_inspection_method( $routine, $options );
     143
     144            if ( empty( $inspection_method ) ) {
     145                return false;
     146            }
     147
     148            if ( empty( $action ) ) {
    149149                $action = "ac_inspection";
    150150            }
    151151
    152             if ( !is_array( self::$routine_events[$routine] ) ) {
     152            if ( !array_key_exists( $routine, self::$routine_events ) || !is_array( self::$routine_events[$routine] ) ) {
    153153                self::$routine_events[$routine] = array();
    154154            }
    155155
    156             if ( in_array($action, self::$routine_events[$routine]) ) {
     156            if ( in_array( $action, self::$routine_events[$routine] ) ) {
    157157                return false;
    158158            }
     
    170170            }
    171171
    172             if ( is_array($options) && !empty( $options ) ) {
    173                 if ( is_array($saved_options) ) {
     172            if ( !empty( $options ) && is_array( $options ) ) {
     173                if ( is_array( $saved_options ) ) {
    174174                    foreach( $saved_options as $opt_key => $saved_val ) {
    175                         if ( !isset($options[$opt_key]) || $options[$opt_key] != $saved_val ) {
     175                        if ( !isset( $options[$opt_key] ) || $options[$opt_key] != $saved_val ) {
    176176                            $options[$opt_key] = $saved_val;
    177177                        }
    178178                    }
    179179                }
    180                 if ( !is_array($saved_options) || ( count($options) != count($saved_options) ) ) {
     180                if ( !is_array( $saved_options ) || ( count( $options ) != count( $saved_options ) ) ) {
    181181                    self::set_options( $routine, $options );
    182182                }
    183183            }
    184184
    185             if ( $options['site_specific_settings'] && is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) {
     185            if ( !empty( $options['site_specific_settings'] ) && is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) {
    186186                $current_site_id = get_current_blog_id();
    187                 if ($options[$current_site_id]['log_level'] == 'ignore') {
     187                if ( $options[$current_site_id]['log_level'] == 'ignore' ) {
    188188                    return true;
    189189                }
     
    200200        public static function remove($routine, $action = "", $priority = 10) {
    201201
    202             if (empty($routine)) {
     202            if ( empty( $routine ) ) {
    203203                return false;
    204204            }
     
    214214            }
    215215
    216             unset(self::$routine_events[$routine]);
     216            unset( self::$routine_events[$routine] );
    217217           
    218218            return true;
     
    222222        public static function get_event_routines($event) {
    223223
    224             if (empty($event)) {
     224            if ( empty( $event) ) {
    225225                return false;
    226226            }
     
    228228            $event_routines = array();
    229229
    230             foreach(array_keys(self::$routine_events) as $routine) {
     230            foreach( array_keys( self::$routine_events ) as $routine ) {
    231231                if ( in_array( $event, self::$routine_events[$routine] ) ) {
    232232                    $event_routines[] = $routine;
  • angry-creative-logger/trunk/classes/settings.php

    r943414 r958566  
    22/*
    33Class name: ACI Settings
    4 Version: 0.3.0
     4Version: 0.3.1
    55Depends: AC Inspector 0.5.x
    66Author: Sammy Nordström, Angry Creative AB
     
    4949        public function admin_notices() {
    5050
    51             if ( 'ac-inspector' == $_GET['page'] && isset( $_GET['updated'] ) ) {
     51            if ( isset( $_GET['updated'] ) && isset( $_GET['page'] ) && 'ac-inspector' == $_GET['page'] ) {
    5252
    5353                echo '<div class="updated"><p>';
     
    364364        public function validate_options( $input = array() ) {
    365365
    366             if (empty($input) && $_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['aci_options'])) {
     366            if ( empty( $input ) && $_SERVER['REQUEST_METHOD'] == "POST" && isset( $_POST['aci_options'] ) ) {
    367367                $input = $_POST['aci_options'];
    368368            }
     
    370370            $saved_option = parent::get_option( 'ac_inspector_log_path' );
    371371
    372             if ( $saved_option === FALSE ) {
    373 
    374                 parent::add_option( 'ac_inspector_log_path', $input['log_path'] );
    375 
    376             } else {
    377 
    378                 parent::update_option( 'ac_inspector_log_path', $input['log_path'] );
    379 
    380             }
    381 
    382             parent::$log_path = $input['log_path'];
    383 
    384             $routines = ACI_Routine_Handler::get_all();
     372            if ( !empty( $input['log_path'] ) ) {
     373
     374                if ( $saved_option === FALSE ) {
     375
     376                    parent::add_option( 'ac_inspector_log_path', $input['log_path'] );
     377
     378                } else {
     379
     380                    parent::update_option( 'ac_inspector_log_path', $input['log_path'] );
     381
     382                }
     383
     384                parent::$log_path = $input['log_path'];
     385
     386            }
     387
     388            $routines = (array) ACI_Routine_Handler::get_all();
    385389
    386390            foreach( array_keys($routines) as $routine ) {
     
    388392                $routine_settings = ACI_Routine_Handler::get_options($routine);
    389393
    390                 $new_routine_settings = $input[$routine];
     394                if ( !empty( $input[$routine] ) && is_array( $input[$routine] ) ) {
     395                    $new_routine_settings = $input[$routine];
     396                } else {
     397                    $new_routine_settings = array();
     398                }
    391399
    392400                foreach($routine_settings as $opt => $val) {
    393401
    394                     if (isset($new_routine_settings[$opt])) {
     402                    if ( isset( $new_routine_settings[$opt] ) ) {
    395403                        $routine_settings[$opt] = $new_routine_settings[$opt];
    396404                    }
     
    454462            $routine_settings = ACI_Routine_Handler::get_options($routine);
    455463
    456             if ( !empty($routine_settings['description']) ) { ?>
     464            if ( !empty( $routine_settings['description'] ) ) { ?>
    457465
    458466                <tr valign="top">
     
    462470            <?php }
    463471
    464             if ( isset($routine_settings['site_specific_settings']) && is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) { ?>
     472            if ( isset( $routine_settings['site_specific_settings'] ) && is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) { ?>
    465473
    466474                <tr valign="top">
     
    482490                $site_blog_ids = $wpdb->get_col("SELECT blog_id FROM ".$wpdb->prefix."blogs");
    483491
    484                 if (is_array($site_blog_ids)) {
     492                if ( is_array( $site_blog_ids ) ) {
    485493
    486494                    foreach( $site_blog_ids AS $site_blog_id ) {
  • angry-creative-logger/trunk/plugin.php

    r958139 r958566  
    44Plugin URI: http://angrycreative.se
    55Description: Inspects and logs possible issues with your Wordpress installation.
    6 Version: 0.5.1
     6Version: 0.5.2
    77Author: Robin Björklund, Sammy Nordström, Angry Creative AB
    88*/
    99
    10 define( 'ACI_PLUGIN_VERSION', '0.5.1' );
     10define( 'ACI_PLUGIN_VERSION', '0.5.2' );
    1111
    1212define( 'ACI_PLUGIN_DIR', dirname( __FILE__ ) );
  • angry-creative-logger/trunk/readme.txt

    r958139 r958566  
    44Requires at least: 3.0.1
    55Tested up to: 3.9.1
    6 Stable tag: 0.5.1
     6Stable tag: 0.5.2
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.