Plugin Directory

Changeset 2684972


Ignore:
Timestamp:
02/25/2022 12:14:03 PM (4 years ago)
Author:
rulecom
Message:

Update to version 2.7.3 from GitHub

Location:
woorule
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • woorule/tags/2.7.3/inc/class-woorule-options.php

    r2684556 r2684972  
    2828
    2929    /**
    30      * Plugin options.
    31      *
    32      * @var array
    33      */
    34     protected $options = array();
    35 
    36     /**
    37      * Woorule_Options constructor.
    38      *
    39      * @return void
    40      */
    41     protected function __construct() {
    42         $this->options = get_option( self::OPTIONS_KEY, array() );
    43     }
    44 
    45     /**
    4630     * Prevent unserializing.
    4731     *
     
    6246     * Get class instance.
    6347     *
    64      * @return object Instance.
     48     * @return $this Instance.
    6549     */
    6650    protected static function get_instance() {
     
    8771        $instance = self::get_instance();
    8872
    89         $instance->filter_options();
    90 
    9173        if ( 0 === strpos( $name, 'get_' ) ) {
    9274            return $instance->get( substr( $name, 4 ) );
     
    10688     *
    10789     * @return mixed
    108      *
    109      * @throws BadMethodCallException Exception.
    11090     */
    11191    protected function get( $option_name ) {
    112         //$this->options = get_option( self::OPTIONS_KEY, array() );
     92        $options = self::load_options();
    11393
    11494        if ( 'options' === $option_name ) {
    115             return $this->options;
    116         } elseif ( isset( $this->options[ 'woorule_' . $option_name ] ) ) {
    117             return $this->options[ 'woorule_' . $option_name ];
    118         } else {
    119             throw new BadMethodCallException( $option_name . ' is not defined in ' . __CLASS__ );
     95            return $options;
    12096        }
     97
     98        return isset( $options[ 'woorule_' . $option_name ] ) ? $options[ 'woorule_' . $option_name ] : null;
    12199    }
    122100
     
    128106     *
    129107     * @return void
    130      *
    131      * @throws BadMethodCallException Exception.
    132108     */
    133109    protected function set( $option_name, $value ) {
    134         static $updated = null;
     110        $options = self::load_options();
    135111
    136         if ( 'options' === $option_name && is_array( $value ) ) {
    137             // Merge new options with existent object's options.
    138             $value = wp_parse_args( $value, $this->options );
    139             $this->filter_options( $value );
    140         } elseif ( isset( $this->options[ 'woorule_' . $option_name ] ) ) {
    141             $this->options[ 'woorule_' . $option_name ] = $value;
     112        if ( 'options' === $option_name ) {
     113            if ( is_array( $value ) ) {
     114                // Merge new options with existent object's options.
     115                $value = wp_parse_args( $value, $options );
     116
     117                update_option( self::OPTIONS_KEY, $value, false );
     118            }
    142119        } else {
    143             throw new BadMethodCallException( $option_name . ' is not defined in ' . __CLASS__ );
    144         }
     120            $options[ 'woorule_' . $option_name ] = $value;
    145121
    146         if ( is_null( $updated ) ) {
    147             $updated = true;
    148 
    149             // Save options to DB on shutdown.
    150             add_action(
    151                 'shutdown',
    152                 // Anonymous function is used because we do want to have public DB update function.
    153                 function () {
    154                     $this->filter_options();
    155                     update_option( self::OPTIONS_KEY, $this->options, false );
    156                 }
    157             );
     122            update_option( self::OPTIONS_KEY, $options, false );
    158123        }
    159124    }
     
    164129     * @return array
    165130     */
    166     protected function get_options_defaults() {
     131    private static function get_options_defaults() {
    167132        return (array) apply_filters(
    168133            'woorule_options_defaults',
     
    181146     * @param array $options Options.
    182147     *
    183      * @return void
     148     * @return array
    184149     */
    185     protected function filter_options( $options = null ) {
    186         $this->options = shortcode_atts(
     150    private static function filter_options( $options ) {
     151        return shortcode_atts(
    187152            self::get_options_defaults(),
    188             is_null( $options ) ? $this->options : $options
     153            $options
    189154        );
    190155    }
     156
     157    /**
     158     * Load options.
     159     *
     160     * @return array
     161     */
     162    private static function load_options() {
     163        return self::filter_options( get_option( self::OPTIONS_KEY, array() ) );
     164    }
    191165}
  • woorule/tags/2.7.3/inc/partials/admin-settings.php

    r2684385 r2684972  
    8888            </th>
    8989            <td>
    90                 <input name="woorule_api" id="woorule_api" type="text" class="regular-text code" value="
    91                     <?php echo esc_attr( $args['api_key'] ); ?>"/>
     90                <input name="woorule_api" id="woorule_api" type="text" class="regular-text code" value="<?php echo esc_attr( $args['api_key'] ); ?>"/>
    9291                <span class="description">
    9392                    <?php echo wp_kses_post(
  • woorule/trunk/inc/class-woorule-options.php

    r2684556 r2684972  
    2828
    2929    /**
    30      * Plugin options.
    31      *
    32      * @var array
    33      */
    34     protected $options = array();
    35 
    36     /**
    37      * Woorule_Options constructor.
    38      *
    39      * @return void
    40      */
    41     protected function __construct() {
    42         $this->options = get_option( self::OPTIONS_KEY, array() );
    43     }
    44 
    45     /**
    4630     * Prevent unserializing.
    4731     *
     
    6246     * Get class instance.
    6347     *
    64      * @return object Instance.
     48     * @return $this Instance.
    6549     */
    6650    protected static function get_instance() {
     
    8771        $instance = self::get_instance();
    8872
    89         $instance->filter_options();
    90 
    9173        if ( 0 === strpos( $name, 'get_' ) ) {
    9274            return $instance->get( substr( $name, 4 ) );
     
    10688     *
    10789     * @return mixed
    108      *
    109      * @throws BadMethodCallException Exception.
    11090     */
    11191    protected function get( $option_name ) {
    112         //$this->options = get_option( self::OPTIONS_KEY, array() );
     92        $options = self::load_options();
    11393
    11494        if ( 'options' === $option_name ) {
    115             return $this->options;
    116         } elseif ( isset( $this->options[ 'woorule_' . $option_name ] ) ) {
    117             return $this->options[ 'woorule_' . $option_name ];
    118         } else {
    119             throw new BadMethodCallException( $option_name . ' is not defined in ' . __CLASS__ );
     95            return $options;
    12096        }
     97
     98        return isset( $options[ 'woorule_' . $option_name ] ) ? $options[ 'woorule_' . $option_name ] : null;
    12199    }
    122100
     
    128106     *
    129107     * @return void
    130      *
    131      * @throws BadMethodCallException Exception.
    132108     */
    133109    protected function set( $option_name, $value ) {
    134         static $updated = null;
     110        $options = self::load_options();
    135111
    136         if ( 'options' === $option_name && is_array( $value ) ) {
    137             // Merge new options with existent object's options.
    138             $value = wp_parse_args( $value, $this->options );
    139             $this->filter_options( $value );
    140         } elseif ( isset( $this->options[ 'woorule_' . $option_name ] ) ) {
    141             $this->options[ 'woorule_' . $option_name ] = $value;
     112        if ( 'options' === $option_name ) {
     113            if ( is_array( $value ) ) {
     114                // Merge new options with existent object's options.
     115                $value = wp_parse_args( $value, $options );
     116
     117                update_option( self::OPTIONS_KEY, $value, false );
     118            }
    142119        } else {
    143             throw new BadMethodCallException( $option_name . ' is not defined in ' . __CLASS__ );
    144         }
     120            $options[ 'woorule_' . $option_name ] = $value;
    145121
    146         if ( is_null( $updated ) ) {
    147             $updated = true;
    148 
    149             // Save options to DB on shutdown.
    150             add_action(
    151                 'shutdown',
    152                 // Anonymous function is used because we do want to have public DB update function.
    153                 function () {
    154                     $this->filter_options();
    155                     update_option( self::OPTIONS_KEY, $this->options, false );
    156                 }
    157             );
     122            update_option( self::OPTIONS_KEY, $options, false );
    158123        }
    159124    }
     
    164129     * @return array
    165130     */
    166     protected function get_options_defaults() {
     131    private static function get_options_defaults() {
    167132        return (array) apply_filters(
    168133            'woorule_options_defaults',
     
    181146     * @param array $options Options.
    182147     *
    183      * @return void
     148     * @return array
    184149     */
    185     protected function filter_options( $options = null ) {
    186         $this->options = shortcode_atts(
     150    private static function filter_options( $options ) {
     151        return shortcode_atts(
    187152            self::get_options_defaults(),
    188             is_null( $options ) ? $this->options : $options
     153            $options
    189154        );
    190155    }
     156
     157    /**
     158     * Load options.
     159     *
     160     * @return array
     161     */
     162    private static function load_options() {
     163        return self::filter_options( get_option( self::OPTIONS_KEY, array() ) );
     164    }
    191165}
  • woorule/trunk/inc/partials/admin-settings.php

    r2684385 r2684972  
    8888            </th>
    8989            <td>
    90                 <input name="woorule_api" id="woorule_api" type="text" class="regular-text code" value="
    91                     <?php echo esc_attr( $args['api_key'] ); ?>"/>
     90                <input name="woorule_api" id="woorule_api" type="text" class="regular-text code" value="<?php echo esc_attr( $args['api_key'] ); ?>"/>
    9291                <span class="description">
    9392                    <?php echo wp_kses_post(
Note: See TracChangeset for help on using the changeset viewer.