Plugin Directory

Changeset 3044845


Ignore:
Timestamp:
03/04/2024 08:59:40 AM (23 months ago)
Author:
upamahin
Message:

Fixed: Vulnerability issue

Location:
control-block-patterns
Files:
558 added
4 edited

Legend:

Unmodified
Added
Removed
  • control-block-patterns/trunk/classes/Patterns/Tools.php

    r2719787 r3044845  
    5050    public function add_export_link( $actions, $post ) {
    5151        if ( 'ctrl_block_patterns' === $post->post_type ) {
    52             $actions['export'] = '<a href="' . add_query_arg( ['action' => 'cbp-export', 'post[]' => $post->ID] ) . '">' . esc_html__( 'Export', 'control-block-patterns' ) . '</a>';
     52            $actions['export'] = '<a href="' . add_query_arg( ['action' => 'cbp-export', 'post[]' => $post->ID,'_nonce' => wp_create_nonce( 'ctrlbp-export')] ) . '">' . esc_html__( 'Export', 'control-block-patterns' ) . '</a>';
    5353        }
    5454        return $actions;
     
    6262            return;
    6363        }
    64 
     64        if(empty($_REQUEST['_nonce']) || !wp_verify_nonce(esc_attr($_REQUEST['_nonce']), 'ctrlbp-export')){
     65            wp_die(esc_attr('Invalid request', 'control-block-patterns'));
     66        }
    6567        $post_ids = $_REQUEST['post'];
    6668
  • control-block-patterns/trunk/classes/Settings/SettingsPage.php

    r2719787 r3044845  
    11<?php
     2
    23namespace ControlPatterns\Settings;
    34
    4 class SettingsPage {
     5class SettingsPage
     6{
    57    private $args;
    68    public $page_hook;
    79    protected $type;
    810
    9     public function __construct( $args = [] ) {
     11    public function __construct($args = [])
     12    {
    1013        $this->args = $args;
    1114        $this->register_hooks();
    1215    }
    1316
    14     protected function register_hooks() {
    15         add_action( 'admin_menu', array( $this, 'register_admin_menu' ) );
    16         add_action( 'admin_init', array( $this, 'settings_export' ) );
    17         add_action( 'admin_init', array( $this, 'reset_action' ) );
    18         add_action( 'wp_ajax_import_settings_data', [ $this, 'import_settings_data' ] );
    19         add_action( 'wp_ajax_ctrlbp_reset_settings_page', [ $this, 'reset_settings_page' ] );
    20        
    21     }
    22 
    23     public function register_admin_menu() {
     17    protected function register_hooks()
     18    {
     19        add_action('admin_menu', array($this, 'register_admin_menu'));
     20        add_action('admin_init', array($this, 'settings_export'));
     21        add_action('admin_init', array($this, 'reset_action'));
     22        add_action('wp_ajax_import_settings_data', [$this, 'import_settings_data']);
     23        add_action('wp_ajax_ctrlbp_reset_settings_page', [$this, 'reset_settings_page']);
     24    }
     25
     26    public function register_admin_menu()
     27    {
    2428        // Add top level menu.
    25         if ( ! $this->parent ) {
     29        if (!$this->parent) {
    2630            $this->page_hook = add_menu_page(
    2731                $this->page_title,
     
    2933                $this->capability,
    3034                $this->id,
    31                 array( $this, 'show' ),
     35                array($this, 'show'),
    3236                $this->icon_url,
    3337                $this->position
     
    3539
    3640            // If this menu has a default sub-menu.
    37             if ( $this->submenu_title ) {
     41            if ($this->submenu_title) {
    3842                add_submenu_page(
    3943                    $this->id,
     
    4246                    $this->capability,
    4347                    $this->id,
    44                     array( $this, 'show' )
     48                    array($this, 'show')
    4549                );
    4650            }
     
    5357                $this->capability,
    5458                $this->id,
    55                 array( $this, 'show' )
     59                array($this, 'show')
    5660            );
    5761        }
    5862
    5963        // Enqueue scripts and styles.
    60         add_action( "admin_print_styles-{$this->page_hook}", array( $this, 'enqueue' ) );
     64        add_action("admin_print_styles-{$this->page_hook}", array($this, 'enqueue'));
    6165
    6266        // Load action.
    63         add_action( "load-{$this->page_hook}", array( $this, 'load' ) );
    64         add_action( "load-{$this->page_hook}", array( $this, 'add_help_tabs' ) );
    65         add_action( "load-{$this->page_hook}", array( $this, 'add_admin_notice_hook' ) );
    66     }
    67 
    68     public function show() {       
    69         ?>
    70         <div class="<?php echo esc_attr( $this->settings_class() ) ?>">
    71             <h1><?= esc_html( get_admin_page_title() ) ?></h1>
     67        add_action("load-{$this->page_hook}", array($this, 'load'));
     68        add_action("load-{$this->page_hook}", array($this, 'add_help_tabs'));
     69        add_action("load-{$this->page_hook}", array($this, 'add_admin_notice_hook'));
     70    }
     71
     72    public function show()
     73    {
     74?>
     75        <div class="<?php echo esc_attr($this->settings_class()) ?>">
     76            <h1><?= esc_html(get_admin_page_title()) ?></h1>
    7277            <form method="post" action="" enctype="multipart/form-data" id="post" class="ctrlbp-settings-form">
    73             <?php
    74                 if( $this->header ){
    75                     $this->output_header(); 
     78                <?php
     79                if ($this->header) {
     80                    $this->output_header();
    7681                }
    77             ?>
    78             <div class="ctrlbp-settings-wrap">
    79                
    80                 <?php $this->output_tab_nav() ?>
    81 
    82                 <div class="ctrlbp-settings-form-wrap">
    83                    
     82                ?>
     83                <div class="ctrlbp-settings-wrap">
     84
     85                    <?php $this->output_tab_nav() ?>
     86
     87                    <div class="ctrlbp-settings-form-wrap">
     88
    8489                        <div id="poststuff">
    8590                            <?php
    8691                            // Nonce for saving meta boxes status (collapsed/expanded) and order.
    87                             wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
    88                             wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
     92                            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
     93                            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
    8994                            ?>
    90                             <div id="post-body" class="metabox-holder columns-<?= intval( $this->columns ); ?>">
    91                                 <?php if ( $this->columns > 1 ) : ?>
     95                            <div id="post-body" class="metabox-holder columns-<?= intval($this->columns); ?>">
     96                                <?php if ($this->columns > 1) : ?>
    9297                                    <div id="postbox-container-1" class="postbox-container">
    93                                         <?php do_meta_boxes( null, 'side', null ); ?>
     98                                        <?php do_meta_boxes(null, 'side', null); ?>
    9499                                    </div>
    95100                                <?php endif; ?>
    96101                                <div id="postbox-container-2" class="postbox-container">
    97                                     <?php do_meta_boxes( null, 'normal', null ); ?>
    98                                     <?php do_meta_boxes( null, 'advanced', null ); ?>
     102                                    <?php do_meta_boxes(null, 'normal', null); ?>
     103                                    <?php do_meta_boxes(null, 'advanced', null); ?>
    99104                                </div>
    100105                            </div>
    101106                            <br class="clear">
    102                            
     107
    103108                        </div>
    104                    
     109
     110                    </div>
    105111                </div>
    106             </div>         
    107                                
    108             <?php $this->output_buttons(); ?>
    109            
     112
     113                <?php $this->output_buttons(); ?>
     114
    110115            </form>
    111116        </div>
    112         <?php
    113        
    114     }
    115 
    116     private function settings_class(){
     117    <?php
     118
     119    }
     120
     121    private function settings_class()
     122    {
    117123        $class = [
    118124            'wrap',
     
    120126            $this->class,
    121127        ];
    122        
    123         if ( $this->tabs ) {
     128
     129        if ($this->tabs) {
    124130            $class[] = "ctrlbp-settings-tabs-{$this->tab_style}";
    125131        }
    126         if( $this->header ){
     132        if ($this->header) {
    127133            $class[] = "ctrlbp-admin-custom-header";
    128134        }
    129         if( $this->theme ){
     135        if ($this->theme) {
    130136            $class[] = 'ctrlbp-admin-theme';
    131             $class[] =  !is_bool($this->theme)? "ctrlbp-admin-theme-".esc_attr($this->theme) : '';
     137            $class[] =  !is_bool($this->theme) ? "ctrlbp-admin-theme-" . esc_attr($this->theme) : '';
    132138        }
    133139        $class = array_unique(array_filter($class));
     
    135141    }
    136142
    137     private function output_buttons(){ 
    138         $reset_url = add_query_arg( [
     143    private function output_buttons()
     144    {
     145        $reset_url = add_query_arg([
    139146            'reset' => 'all',
    140             '_nonce' => wp_create_nonce( 'ctrlbp-reset' )
    141         ] );
    142        
    143         ?>
     147            '_nonce' => wp_create_nonce('ctrlbp-reset')
     148        ]);
     149
     150    ?>
    144151        <div class="submit-buttons py-3">
    145             <?php submit_button( esc_html( $this->submit_button ), 'primary', 'submit', false ); ?>
     152            <?php submit_button(esc_html($this->submit_button), 'primary', 'submit', false); ?>
    146153            <button type="button" class="button button-danger ctrlbp-reset-settings"><?php echo esc_attr('Reset Settings', 'control-block-patterns') ?></button>
    147             <?php do_action( 'ctrlbp_settings_page_submit_buttons' ); ?>
     154            <?php do_action('ctrlbp_settings_page_submit_buttons'); ?>
    148155        </div>
    149         <?php
    150        
    151     }
    152 
    153     public function reset_action(){     
    154         if( empty($_REQUEST['reset']) || empty($_REQUEST['_nonce']) ) return;
    155        
     156    <?php
     157
     158    }
     159
     160    public function reset_action()
     161    {
     162        if (empty($_REQUEST['reset']) || empty($_REQUEST['_nonce'])) return;
     163
    156164        $nonce = $_REQUEST['_nonce'];
    157         if(($_REQUEST['reset'] == 'all') && wp_verify_nonce( $nonce, 'ctrlbp-reset' )){
     165        if (($_REQUEST['reset'] == 'all') && wp_verify_nonce($nonce, 'ctrlbp-reset')) {
    158166            update_option($this->args['option_name'], $this->get_std($this->args['option_name']));
    159             remove_query_arg( ['reset', '_nonce'] );       
    160             if ( wp_safe_redirect( htmlspecialchars_decode(menu_page_url($this->id, false)) ) ) {
     167            remove_query_arg(['reset', '_nonce']);
     168            if (wp_safe_redirect(htmlspecialchars_decode(menu_page_url($this->id, false)))) {
    161169                exit;
    162             }       
    163         }       
    164     }
    165 
    166     public function settings_export(){
    167         $action  = isset( $_REQUEST['action'] ) && 'ctrlbp-settings-export' === $_REQUEST['action'];
    168         if ( ! $action)  {
     170            }
     171        }
     172    }
     173
     174    public function settings_export()
     175    {
     176        $action  = isset($_REQUEST['action']) && 'ctrlbp-settings-export' === $_REQUEST['action'];
     177        if (!$action || empty($_REQUEST['nonce'])) {
    169178            return;
    170179        }
    171         $file_name = $_REQUEST['id'];
    172 
    173    
    174         $func          = false !== $this->network ? 'get_site_option' : 'get_option';
    175         $options = $func( $_REQUEST['id'] );
    176         $data = json_encode( $options, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT );
    177 
    178         header( 'Content-Type: application/octet-stream' );
    179         header( "Content-Disposition: attachment; filename=$file_name.json" );
    180         header( 'Expires: 0' );
    181         header( 'Cache-Control: must-revalidate' );
    182         header( 'Pragma: public' );
    183         header( 'Content-Length: ' . strlen( $data ) );
    184         echo $data;
     180        $nonce = $_REQUEST['nonce'];
     181        if (wp_verify_nonce($nonce, 'ctrlbp-export')) {
     182            $file_name = $_REQUEST['id'];
     183
     184
     185            $func          = false !== $this->network ? 'get_site_option' : 'get_option';
     186            $options = $func($_REQUEST['id']);
     187            $data = json_encode($options, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
     188
     189            header('Content-Type: application/octet-stream');
     190            header("Content-Disposition: attachment; filename=$file_name.json");
     191            header('Expires: 0');
     192            header('Cache-Control: must-revalidate');
     193            header('Pragma: public');
     194            header('Content-Length: ' . strlen($data));
     195            echo $data;
     196        } else {
     197            wp_die(esc_attr('Invalid request', 'control-block-patterns'));
     198        }
    185199        die;
    186200    }
    187201
    188     private function output_header(){
     202    private function output_header()
     203    {
    189204        $default = array(
    190205            'icon' => '',
    191             'title' => 'Control block Patterns',
    192             'subtitle' => '',
    193             'version' => CTRLBP_VER,
    194             'buttons' => false
     206            'title' => 'Control block Patterns',
     207            'subtitle' => '',
     208            'version' => CTRLBP_VER,
     209            'buttons' => false
    195210        );
    196         extract(wp_parse_args( $this->header, $default ));
    197         ?>
     211        extract(wp_parse_args($this->header, $default));
     212    ?>
    198213        <header class="py-3 px-5 rounded-top bg-dark text-white">
    199214            <div class="ctrlbp-row d-flex">
     
    204219                    </div>
    205220                    <p><?php echo esc_attr($subtitle) ?></p>
    206                 </div>                       
    207             </div>         
     221                </div>
     222            </div>
    208223        </header>
    209         <?php if( $buttons ): ?>
    210             <div class="header-buttons text-end bg-white border px-3 my-1">                 
     224        <?php if ($buttons) : ?>
     225            <div class="header-buttons text-end bg-white border px-3 my-1">
    211226                <?php $this->output_buttons(); ?>
    212             </div>     
    213         <?php endif; ?>
    214         <?php
    215         do_action( 'control-block-patterns/settings/header/'.$this->id );
    216     }
    217 
    218     private function output_tab_nav() {
    219         if ( ! $this->tabs ) {
     227            </div>
     228        <?php endif; ?>
     229<?php
     230        do_action('control-block-patterns/settings/header/' . $this->id);
     231    }
     232
     233    private function output_tab_nav()
     234    {
     235        if (!$this->tabs) {
    220236            return;
    221237        }
    222238        echo '<h2 class="nav-tab-wrapper">';
    223         foreach ( $this->tabs as $id => $tab ) {
    224             if ( is_string( $tab ) ) {
     239        foreach ($this->tabs as $id => $tab) {
     240            if (is_string($tab)) {
    225241                $tab = ['label' => $tab];
    226242            }
    227             $tab = wp_parse_args( $tab, [
     243            $tab = wp_parse_args($tab, [
    228244                'icon'  => '',
    229245                'label' => '',
    230             ] );
    231 
    232             if ( filter_var( $tab['icon'], FILTER_VALIDATE_URL ) ) { // If icon is an URL.
    233                 $icon = '<img src="' . esc_url( $tab['icon'] ) . '">';
     246            ]);
     247
     248            if (filter_var($tab['icon'], FILTER_VALIDATE_URL)) { // If icon is an URL.
     249                $icon = '<img src="' . esc_url($tab['icon']) . '">';
    234250            } else { // If icon is icon font.
    235251                // If icon is dashicons, auto add class 'dashicons' for users.
    236                 if ( false !== strpos( $tab['icon'], 'dashicons' ) ) {
     252                if (false !== strpos($tab['icon'], 'dashicons')) {
    237253                    $tab['icon'] .= ' dashicons';
    238254                }
    239255                // Remove duplicate classes.
    240                 $tab['icon'] = array_filter( array_map( 'trim', explode( ' ', $tab['icon'] ) ) );
    241                 $tab['icon'] = implode( ' ', array_unique( $tab['icon'] ) );
    242 
    243                 $icon = $tab['icon'] ? '<i class="' . esc_attr( $tab['icon'] ) . '"></i>' : '';
    244             }
    245 
    246             printf( '<a href="#tab-%s" class="nav-tab">%s%s</a>', esc_attr( $id ), $icon, esc_html( $tab['label'] ) );
     256                $tab['icon'] = array_filter(array_map('trim', explode(' ', $tab['icon'])));
     257                $tab['icon'] = implode(' ', array_unique($tab['icon']));
     258
     259                $icon = $tab['icon'] ? '<i class="' . esc_attr($tab['icon']) . '"></i>' : '';
     260            }
     261
     262            printf('<a href="#tab-%s" class="nav-tab">%s%s</a>', esc_attr($id), $icon, esc_html($tab['label']));
    247263        }
    248264        echo '</h2>';
    249265    }
    250266
    251     public function enqueue() {
    252 
    253         $version = WP_DEBUG? time() : CTRLBP_VER;
    254         wp_enqueue_style( 'control-block-patterns', CTRLBP_CSS_URI . 'settings.css', '', $version );
    255         if( $this->theme ){
    256             wp_enqueue_style( 'ctrlbp-admin-theme', CTRLBP_CSS_URI . 'admin-theme.css', '', $version );
     267    public function enqueue()
     268    {
     269
     270        $version = WP_DEBUG ? time() : CTRLBP_VER;
     271        wp_enqueue_style('control-block-patterns', CTRLBP_CSS_URI . 'settings.css', '', $version);
     272        if ($this->theme) {
     273            wp_enqueue_style('ctrlbp-admin-theme', CTRLBP_CSS_URI . 'admin-theme.css', '', $version);
    257274        }
    258275
    259276        // For meta boxes.
    260         wp_enqueue_script( 'common' );
    261         wp_enqueue_script( 'wp-lists' );
    262         wp_enqueue_script( 'postbox' );
     277        wp_enqueue_script('common');
     278        wp_enqueue_script('wp-lists');
     279        wp_enqueue_script('postbox');
    263280
    264281        // Enqueue settings page script and style.
    265         wp_enqueue_script( 'control-block-patterns-settings', CTRLBP_JS_URI . 'settings.js', array( 'jquery' ), $version, true );
    266         wp_localize_script( 'control-block-patterns-settings', 'CTRLBPSettingsPage', array(
    267             'tabs'     => array_keys( $this->tabs ),
    268             'nonce'     => wp_create_nonce( 'ctrlbp-settings-page' ),
    269             'ajax_url' => admin_url( 'admin-ajax.php' ),
     282        wp_enqueue_script('control-block-patterns-settings', CTRLBP_JS_URI . 'settings.js', array('jquery'), $version, true);
     283        wp_localize_script('control-block-patterns-settings', 'CTRLBPSettingsPage', array(
     284            'tabs'     => array_keys($this->tabs),
     285            'nonce'     => wp_create_nonce('ctrlbp-settings-page'),
     286            'ajax_url' => admin_url('admin-ajax.php'),
    270287            'option_name' => $this->option_name,
    271288            'option_id' => $this->id,
    272             'confirm_text' => esc_attr__( 'Are you sure want to reset all?', 'control-block-patterns' ),
     289            'confirm_text' => esc_attr__('Are you sure want to reset all?', 'control-block-patterns'),
    273290        ));
    274291    }
    275292
    276     public function load() {
     293    public function load()
     294    {
    277295        $this->args['is_imported'] = $this->import();
    278296
     
    282300         * @param array $page_args The page arguments
    283301         */
    284         do_action( 'ctrlbp_settings_page_load', $this->args );
    285     }
    286 
    287     public function add_admin_notice_hook() {
    288         if ( ! $this->parent || 'options-general.php' !== $this->parent ) {
    289             add_action( 'admin_notices', 'settings_errors' );
    290         }
    291     }
    292 
    293     public function add_help_tabs() {
    294         if ( ! $this->help_tabs || ! is_array( $this->help_tabs ) ) {
     302        do_action('ctrlbp_settings_page_load', $this->args);
     303    }
     304
     305    public function add_admin_notice_hook()
     306    {
     307        if (!$this->parent || 'options-general.php' !== $this->parent) {
     308            add_action('admin_notices', 'settings_errors');
     309        }
     310    }
     311
     312    public function add_help_tabs()
     313    {
     314        if (!$this->help_tabs || !is_array($this->help_tabs)) {
    295315            return;
    296316        }
    297317        $screen = get_current_screen();
    298         foreach ( $this->help_tabs as $k => $help_tab ) {
     318        foreach ($this->help_tabs as $k => $help_tab) {
    299319            // Auto generate help tab ID if missed.
    300             if ( empty( $help_tab['id'] ) ) {
     320            if (empty($help_tab['id'])) {
    301321                $help_tab['id'] = "{$this->id}-help-tab-$k";
    302322            }
    303             $screen->add_help_tab( $help_tab );
    304         }
    305     }
    306 
    307     protected function import() {
     323            $screen->add_help_tab($help_tab);
     324        }
     325    }
     326
     327    protected function import()
     328    {
    308329        $get_func    = 'get_option';
    309330        $update_func = 'update_option';
     
    311332        $option_name = $this->args['option_name'];
    312333
    313         $new = ctrlbp_request()->post( "{$option_name}_backup" );
    314         $new = wp_unslash( $new );
    315         $old = $get_func( $option_name );
    316         $old = json_encode( $old );
    317         if ( ! $new || $old === $new ) {
     334        $new = ctrlbp_request()->post("{$option_name}_backup");
     335        $new = wp_unslash($new);
     336        $old = $get_func($option_name);
     337        $old = json_encode($old);
     338        if (!$new || $old === $new) {
    318339            return false;
    319340        }
    320         $option = json_decode( $new, true );
    321         if ( json_last_error() === JSON_ERROR_NONE ) {
    322             $update_func( $option_name, $option );
     341        $option = json_decode($new, true);
     342        if (json_last_error() === JSON_ERROR_NONE) {
     343            $update_func($option_name, $option);
    323344        }
    324345        return true;
    325346    }
    326347
    327     public function __get( $name ) {
    328         return isset( $this->args[ $name ] ) ? $this->args[ $name ] : null;
    329     }
    330 
    331     private function get_std( $option_name ){
    332         $field_registry = ctrlbp_get_registry( 'field' );
    333         $fields = $field_registry->get_by_object_type( 'setting' );
     348    public function __get($name)
     349    {
     350        return isset($this->args[$name]) ? $this->args[$name] : null;
     351    }
     352
     353    private function get_std($option_name)
     354    {
     355        $field_registry = ctrlbp_get_registry('field');
     356        $fields = $field_registry->get_by_object_type('setting');
    334357        $option_fields = $fields[$option_name];
    335358
     
    337360
    338361        $std = [];
    339         foreach( $setting_ids as $setting_id ){
    340             if(isset($option_fields[$setting_id]['std'])){
     362        foreach ($setting_ids as $setting_id) {
     363            if (isset($option_fields[$setting_id]['std'])) {
    341364                $std[$setting_id] = $option_fields[$setting_id]['std'];
    342             }
    343             else{
     365            } else {
    344366                $std[$setting_id] = null;
    345367            }
    346368        }
    347         return $std;
    348     }
    349 
    350     public function reset_settings_page(){
    351         if( !wp_verify_nonce( $_POST['nonce'], 'ctrlbp-settings-page' ) ){
     369        return $std;
     370    }
     371
     372    public function reset_settings_page()
     373    {
     374        if (!wp_verify_nonce($_POST['nonce'], 'ctrlbp-settings-page')) {
    352375            wp_die(false);
    353376        }
    354377        $option_name = $_POST['option_name'];
    355378        $options = $this->get_std($option_name);
    356         update_option( $option_name, $options, true );
     379        update_option($option_name, $options, true);
    357380
    358381        wp_die(esc_attr__('Settings options reset successfully', 'control-block-patterns'));
    359382    }
    360383
    361     public function import_settings_data(){
    362         if(isset($_POST)){
     384    public function import_settings_data()
     385    {
     386        if (isset($_POST)) {
    363387            $get_func    = 'network' === $this->type ? 'get_site_option' : 'get_option';
    364388            $update_func = 'network' === $this->type ? 'update_site_option' : 'update_option';
    365            
    366 
    367            
     389
     390
     391
    368392            $option_name = $_POST['option_name'];
    369393            $nonce = $_POST['nonce'];
    370             if( !wp_verify_nonce( $nonce, 'ctrlbp-import' ) ){
     394            if (!wp_verify_nonce($nonce, 'ctrlbp-import')) {
    371395                wp_die(esc_attr__('Nothing to update', 'control-block-patterns'));
    372396            }
    373            
     397
    374398            $new = wp_unslash($_POST['import_data']);
    375             $old = $get_func( $option_name );
    376             $old = json_encode( $old, JSON_PRETTY_PRINT );     
    377 
    378 
    379 
    380             if ( ! $new || $old === $new ) {
     399            $old = $get_func($option_name);
     400            $old = json_encode($old, JSON_PRETTY_PRINT);
     401
     402
     403
     404            if (!$new || $old === $new) {
    381405                wp_die(esc_attr__('Nothing to update', 'control-block-patterns'));
    382406            }
    383             $options = array_filter(json_decode( $new, true ));
    384            
     407            $options = array_filter(json_decode($new, true));
     408
    385409            $similar_ids = count(array_intersect_key($this->get_std($option_name), $options));
    386             if( $similar_ids <= 0){
     410            if ($similar_ids <= 0) {
    387411                wp_die(esc_attr__('Nothing to update.', 'control-block-patterns'));
    388             }           
    389            
    390 
    391             if ( json_last_error() === JSON_ERROR_NONE ) {
    392                 $update_func( $option_name, $options );
     412            }
     413
     414
     415            if (json_last_error() === JSON_ERROR_NONE) {
     416                $update_func($option_name, $options);
    393417                wp_die(esc_attr__('Settings options imported successfully', 'control-block-patterns'));
    394418            }
  • control-block-patterns/trunk/control-block-patterns.php

    r2957854 r3044845  
    22/**
    33 * Plugin Name: Control Block Patterns
    4  * Plugin URI:  https://controlpatterns.net
     4 * Plugin URI:  https://themeperch.net
    55 * Description: Save & control your site Block Patterns in an organized way. 1400+ Predefined Blocks are ready to use. You can Register new Pattern Category, Block Patterns, You can also unregister Default Block Patterns & Pattern Categories.
    6  * Version:     1.3.5.4
    7  * Author:      SenseFlame
    8  * Author URI:  https://controlpatterns.net
     6 * Version:     1.3.5.5
     7 * Author:      Themeperch
     8 * Author URI:  https://themeperch.net
    99 * License:     GPL2+
    1010 * Text Domain: control-block-patterns
  • control-block-patterns/trunk/readme.txt

    r2957857 r3044845  
    11=== Build & Control Block Patterns - Boost up Gutenberg Editor ===
    2 Contributors: razib_, senseflame, themeperch
     2Contributors: razib_, themeperch, upamahin, senseflame
    33Tags: block, pattern, block patterns, Gutenberg, patterns builder, reusable blocks, blocks builder, Pattern builder, register Pattern, Register Pattern Category, Pattern Directory
    44Requires at least: 5.5.0
    5 Tested up to: 6.3
     5Tested up to: 6.4
    66Requires PHP: 5.6
    7 Stable tag: 1.3.5.4
     7Stable tag: 1.3.5.5
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6262**Control Block Patterns** is the easiest way to design your layout with beautiful patterns and to insert code or script in your WordPress headers and footers.
    6363
    64 Our goal is to make using WordPress easy, both with our WordPress plugins and resources like **SenseFlame**, the largest WordPress resource site for beginners.
     64Our goal is to make using WordPress easy, both with our WordPress plugins and resources like **Themeperch**, the largest WordPress resource site for beginners.
    6565
    6666We feel that we have done that here. I hope Control Block Patterns are useful to insert patterns and scripts on your site.
     
    159159
    160160== Changelog ==
     161= 1.3.5.5 =
     162* Fixed: Vulnerability issue
     163
    161164= 1.3.5.4 =
    162165* Fixed: PHP 8+ cpmpatibilty
     
    285288## Upgrade Notice ##
    286289
    287 ### 1.3.5.4 ###
    288 * Fixed: PHP 8+ cpmpatibilty
     290### 1.3.5.5 ###
     291* Fixed: Vulnerability issue
Note: See TracChangeset for help on using the changeset viewer.