Plugin Directory

Changeset 3330747


Ignore:
Timestamp:
07/19/2025 11:00:29 PM (8 months ago)
Author:
demispatti
Message:

Updated the code

Location:
cb-parallax/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • cb-parallax/trunk/admin/includes/class-localisation.php

    r3330746 r3330747  
    3434     */
    3535    private string $domain;
    36    
    3736    /**
    3837     * Holds a list of supported post types.
     
    4140     */
    4241    private array $screen_ids;
    43    
    4442    /**
    4543     * The reference to the options class.
     
    5048     */
    5149    private MenuIncludes\cb_parallax_options $options;
    52    
    5350    /**
    5451     * Holds the current plugin options for the requested page or post
     
    5754     */
    5855    private array $plugin_options;
    59    
    6056    /**
    6157     * Holds the current image options for the requested page or post
     
    6460     */
    6561    private array $image_options;
    66    
    6762    /**
    6863     * cb_parallax_admin constructor.
     
    7873        $this->options = $options;
    7974    }
    80    
    8175    /**
    8276     * Registers the methods that need to be hooked with WordPress.
     
    10296        }
    10397    }
    104    
    10598    /**
    10699     * Retrieves the stored image options that are related to the requested page or post and assigns the values to it's member.
    107      *
    108      * @param bool false | \WP_Post $post
    109100     */
    110101    public function retrieve_image_options() : void
     
    158149        // The following values have no defaults, so we check them "by hand":
    159150        // We retrieve these values "by hand" since there is no default value that could be used as a pattern to match against.
    160         $colors['backgroundColor'] = isset($image_options['cb_parallax_boxed_layout_content_container_background_color']) ? $image_options['cb_parallax_boxed_layout_content_container_background_color'] : '';
    161         $colors['overlayColor'] = isset($image_options['cb_parallax_overlay_color']) ? $image_options['cb_parallax_overlay_color'] : '';
     151        $colors['backgroundColor'] = $image_options['cb_parallax_boxed_layout_content_container_background_color'] ?? '';
     152        $colors['overlayColor'] = $image_options['cb_parallax_overlay_color'] ?? '';
    162153       
    163154        // Check the color values
     
    170161        }
    171162        // Add the attachment id.
    172         $attachment_id = $options['attachmentId'] = isset($image_options['cb_parallax_attachment_id']) ? $image_options['cb_parallax_attachment_id'] : '';
     163        $attachment_id = $options['attachmentId'] = $image_options['cb_parallax_attachment_id'] ?? '';
    173164        // If an attachment ID was found, get the image source.
    174165        $image = null;
     
    177168        }
    178169        // Set the url.
    179         $options['backgroundImageUrl'] = isset($image[0]) ? $image[0] : '';
     170        $options['backgroundImageUrl'] = $image[0] ?? '';
    180171        // Set the image dimensions.
    181         $options['attachmentWidth'] = isset($image[1]) ? $image[1] : '';
    182         $options['attachmentHeight'] = isset($image[2]) ? $image[2] : '';
     172        $options['attachmentWidth'] = $image[1] ?? '';
     173        $options['attachmentHeight'] = $image[2] ?? '';
    183174       
    184175        $this->image_options = $options;
    185176    }
    186    
    187177    /**
    188178     * Assembles the data we're sending to the javascript file,
     
    233223        wp_localize_script('cb-parallax-settings-display-js', 'Cb_Parallax_Admin', $data);
    234224    }
    235    
    236225    /**
    237226     * Sets the stored plugin options.
    238      *
    239      * @param bool false | WP_Post $post
    240      */
    241     private function set_plugin_options($post = false) : void
    242     {
    243         $this->plugin_options = $this->options->get_plugin_options($post);
    244     }
    245    
     227     */
     228    private function set_plugin_options() : void
     229    {
     230        $this->plugin_options = $this->options->get_plugin_options();
     231    }
    246232    /**
    247233     * Sets the stored image options.
    248      *
    249      * @param bool false | \WP_Post $post
    250234     */
    251235    private function set_image_options() : void
     
    253237        $this->image_options = $this->options->get_image_options();
    254238    }
    255    
    256239    /**
    257240     * Retrieves the image data for the requested image,
     
    277260        return $image_data;
    278261    }
    279    
    280262    /**
    281263     * Returns an array containing arrays of strings that may be translated into the user-defined locale.
     
    317299            ));
    318300    }
    319    
    320301    /**
    321302     * Checks the image for the minimum width and height required to make use of the parallax effect.
     
    332313        return $image_data['image_width'] >= $min_width && $image_data['image_height'] >= $min_height ? '1' : '0';
    333314    }
    334    
    335315    /**
    336316     * Assembles the data we're sending to the javascript file,
  • cb-parallax/trunk/admin/includes/class-meta-box.php

    r3330683 r3330747  
    215215            $options = $this->options->get_default_image_options();
    216216        }
    217         $attachment_id = isset($options['cb_parallax_attachment_id']) ? $options['cb_parallax_attachment_id'] : false;
    218         $canParallax = isset($options['cb_parallax_can_parallax']) ? $options['cb_parallax_can_parallax'] : false;
    219         $parallax_enabled = isset($options['cb_parallax_can_parallax']) ? $options['cb_parallax_can_parallax'] : false;
     217        $attachment_id = $options['cb_parallax_attachment_id'] ?? false;
     218        $canParallax = $options['cb_parallax_can_parallax'] ?? false;
     219        $parallax_enabled = $options['cb_parallax_can_parallax'] ?? false;
    220220       
    221221        // Get image meta
     
    225225        }
    226226        // Get the image URL.
    227         $url = isset($image[0]) ? $image[0] : '';
     227        $url = $image[0] ?? '';
    228228       
    229229        $nonce = wp_create_nonce('cb_parallax_manage_options_nonce');
     
    275275     * Retrieves the plugin-related input, preprocesses it and uses the reference of the options class to process and finally store the plugin-related data.
    276276     *
    277      * @param int $post_id
     277     * @param string $post_id
    278278     * @param \WP_Post $post
    279279     *
    280280     * @return void
    281281     */
    282     public function save_post($post_id, $post) : void
     282    public function save_post($post_id, WP_Post $post) : void
    283283    {
    284284        // Verify the nonce.
     
    308308        $data = array();
    309309        foreach ($image_options_whitelist as $key => $args) {
    310             $data[$key] = isset($posted_data[$key]) ? $posted_data[$key] : null;
     310            $data[$key] = $posted_data[$key] ?? null;
    311311        }
    312312       
  • cb-parallax/trunk/admin/menu/class-settings-page.php

    r3330678 r3330747  
    141141    public function enqueue_styles(string $hook_suffix) : void
    142142    {
    143         if (isset($hook_suffix) && $hook_suffix === $this->screen_id) {
     143        if ('' !== $hook_suffix && $hook_suffix === $this->screen_id) {
    144144            // Color picker.
    145145            wp_enqueue_style('wp-color-picker');
     
    163163    public function enqueue_scripts(string $hook_suffix) : void
    164164    {
    165         if (isset($hook_suffix) && $hook_suffix === $this->screen_id) {
     165        if ('' !== $hook_suffix && $hook_suffix === $this->screen_id) {
    166166            wp_enqueue_script('jquery');
    167167            // Dashicons
     
    215215    public function include_menu_localisation(string $hook_suffix) : void
    216216    {
    217         if (isset($hook_suffix) && $hook_suffix === $this->screen_id) {
     217        if ('' !== $hook_suffix && $hook_suffix === $this->screen_id) {
    218218            $script_localisation = new AdminIncludes\cb_parallax_localisation($this->domain, $this->screen_ids, $this->options);
    219219            $script_localisation->add_hooks();
     
    249249       
    250250        $stored_options = get_option('cb_parallax_options');
    251         $attachment_id = isset($stored_options['cb_parallax_attachment_id']) ? $stored_options['cb_parallax_attachment_id'] : null;
    252         $canParallax = isset($stored_options['cb_parallax_can_parallax']) ? $stored_options['cb_parallax_can_parallax'] : false;
    253         $parallax_enabled = isset($stored_options['cb_parallax_can_parallax']) ? $stored_options['cb_parallax_can_parallax'] : false;
     251        $attachment_id = $stored_options['cb_parallax_attachment_id'] ?? null;
     252        $canParallax = $stored_options['cb_parallax_can_parallax'] ?? false;
     253        $parallax_enabled = $stored_options['cb_parallax_can_parallax'] ?? false;
    254254       
    255255        // Get image meta data
     
    259259        }
    260260        // Get the image url
    261         $url = isset($image[0]) ? $image[0] : '';
     261        $url = $image[0] ?? '';
    262262       
    263263        /**
     
    276276        $settings = $this->options->get_options_arguments();
    277277        foreach ($settings as $option_key => $args) {
    278             $value = isset($stored_options[$option_key]) ? $stored_options[$option_key] : '';
     278            $value = $stored_options[$option_key] ?? '';
    279279           
    280280            switch ($args['input_type']) {
  • cb-parallax/trunk/admin/menu/includes/class-ajax.php

    r3330746 r3330747  
    4747     * @access   protected
    4848     */
    49     protected ?string $nonce_error_text;
     49    protected string $nonce_error_text;
    5050   
    5151    /**
     
    6262        $this->domain = $domain;
    6363        $this->options = $options;
    64         $this->nonce_error_text = __('That won\'t do.', $this->domain);
     64        $this->nonce_error_text = strval(__('That won\'t do.', $this->domain));
    6565    }
    6666   
     
    106106       
    107107        // retrieve the options
    108         $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : '';
     108        $post_id = $_POST['post_id'] ?? '';
    109109        $data = array();
    110110        $options_arguments = '' === $_POST['post_id'] ? $this->options->get_default_options() : $this->options->get_default_options('image');
     
    165165    public function cb_parallax_reset_options() : void
    166166    {
    167         $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : false;
     167        $nonce = $_POST['nonce'] ?? false;
    168168       
    169169        if (false === wp_verify_nonce($nonce, 'cb_parallax_manage_options_nonce')) {
     
    179179         * We use this value to determine if we're resetting plugin options or options on a per-post basis.
    180180         */
    181         $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : '';
     181        $post_id = $_POST['post_id'] ?? '';
    182182       
    183183        $result = $this->options->reset_options($post_id);
  • cb-parallax/trunk/admin/menu/includes/class-options.php

    r3330746 r3330747  
    33namespace CbParallax\Admin\Menu\Includes;
    44
     5use WP_Post;
    56use WP_Error;
    67use CbParallax\Admin\Menu\Includes as MenuIncludes;
     
    120121        return $plugin_options;
    121122    }
     123    /**
     124     * @return array
     125     */
    122126    private function image_options_whitelist() : array
    123127    {
     
    296300        }
    297301       
    298         $args = array();
    299        
    300         foreach ($options as $option_key => $arguments) {
    301             $args[$option_key] = array(
     302        $args = array_map(function($arguments)
     303        {
     304            return array(
    302305                'option_key'     => $arguments['option_key'],
    303306                'name'           => $arguments['name'],
     
    308311                'select_values'  => $arguments['select_values'],
    309312            );
    310         }
     313        }, $options);
    311314       
    312315        return $args;
     
    713716            $post_meta = get_post_meta($post->ID, 'cb_parallax', true);
    714717            // Maybe overwrite the value with the one from the post meta data
    715             $stored_options['cb_parallax_parallax_enabled'] = isset($post_meta['cb_parallax_parallax_enabled']) ? $post_meta['cb_parallax_parallax_enabled'] : $stored_options['cb_parallax_parallax_enabled'];
     718            $stored_options['cb_parallax_parallax_enabled'] = $post_meta['cb_parallax_parallax_enabled'] ?? $stored_options['cb_parallax_parallax_enabled'];
    716719        }
    717720       
    718721        foreach ($plugin_options_keys as $key) {
    719             $plugin_options[$key] = isset($stored_options[$key]) ? $stored_options[$key] : '0';
     722            $plugin_options[$key] = $stored_options[$key] ?? '0';
    720723        }
    721724       
     
    781784     * @return string $result
    782785     */
    783     public function determine_options_source($post) : string
     786    public function determine_options_source(WP_Post $post) : string
    784787    {
    785788        $stored_options = get_option('cb_parallax_options');
     
    864867        delete_option('cb_parallax_options');
    865868       
    866         $result = null;
    867869        // Checks if the options are post-related or plugin-related.
    868870        if ('' === $post_id) {
     
    928930     * Since the ids for attachments will most likely be assigned in a different order after website migrations,
    929931     * we check the file by it's file name, too. We rather serve no file instead of a wrong one.
    930      *
    931      * @param \WP_Post $post
    932932     *
    933933     * @return bool
     
    950950            return false;
    951951        } else {
    952             $stored_file = isset($attachment_meta['file']) ? $attachment_meta['file'] : 'false';
     952            $stored_file = $attachment_meta['file'] ?? 'false';
    953953            $found_file = str_replace(site_url().'/wp-content/uploads/', '', $image_attributes[0]);
    954954        }
     
    969969        return true;
    970970    }
    971    
    972971    /**
    973972     * Returns the image options based on the plugin settings or the post meta data respectively.
    974      *
    975      * @param mixed | \WP_Post $post | bool false
    976973     *
    977974     * @return array $image_options
  • cb-parallax/trunk/admin/partials/class-settings-display.php

    r3330746 r3330747  
    124124        $this->default_image_options = $this->options->get_default_image_options();
    125125    }
    126    
    127126    /**
    128127     * Creates and returns a string containing the hidden fields:
     
    133132     * @param string $attachment_id
    134133     * @param string $url
     134     * @param        $canParallax
     135     * @param        $parallax_enabled
    135136     *
    136137     * @return string $html
     
    251252                           name="<?php echo 'cb_parallax_options' ?>[<?php echo $option_key ?>]"
    252253                           value="<?php echo $value ?>"
    253                         <?php checked(1, isset($value) ? $value : 0, true); ?> data-key="<?php echo $option_key; ?>"
     254                        <?php checked(1, $value ?? 0, true); ?> data-key="<?php echo $option_key; ?>"
    254255                           data-input="cb-parallax"/>
    255256                    <span class="cb-parallax-switch-label <?php echo $option_key ?>" data-on="On" data-off="Off"></span>
     
    285286                <input type="text" id="<?php echo $option_key ?>" title="<?php echo $description ?>"
    286287                       name="<?php echo 'cb_parallax_options' ?>[<?php echo $option_key ?>]"
    287                        Placeholder="<?php echo isset($this->default_image_options[$option_key]) ? $this->default_image_options[$option_key] : $this->default_plugin_options[$option_key] ?>"
     288                       Placeholder="<?php echo $this->default_image_options[$option_key] ?? $this->default_plugin_options[$option_key] ?>"
    288289                       value="<?php echo $value ?>"
    289290                       class="<?php echo $option_key ?> cb-parallax-color-picker
  • cb-parallax/trunk/includes/class-cb-parallax-upgrade.php

    r3330746 r3330747  
    130130        }
    131131    }
     132    /**
     133     * @return bool
     134     */
    132135    private function upgrade_plugin_options() : bool
    133136    {
     
    171174        return false;
    172175    }
    173    
     176    /**
     177     * @return bool|void
     178     */
     179    /**
     180     * @return bool|void
     181     */
    174182    private function upgrade_post_meta_options()
    175183    {
     
    255263        }
    256264    }
     265    /**
     266     * @return void
     267     */
    257268    private function add_upgrade_flag() : void
    258269    {
  • cb-parallax/trunk/includes/class-cb-parallax.php

    r3330678 r3330747  
    128128        $this->run_public();
    129129    }
     130    /**
     131     * @return void
     132     */
    130133    private function ensure_options() : void
    131134    {
     
    135138        }
    136139    }
     140    /**
     141     * @return void
     142     */
    137143    public function set_initial_plugin_options() : void
    138144    {
  • cb-parallax/trunk/public/class-public.php

    r3330746 r3330747  
    7878    /**
    7979     * Retrieves the user-defined plugin settings.
    80      *
    81      * @param bool false | WP_Post $post
    82      */
    83     private function set_plugin_options($post = false) : void
    84     {
    85         $this->plugin_options = $this->options->get_plugin_options($post);
     80     */
     81    private function set_plugin_options() : void
     82    {
     83        $this->plugin_options = $this->options->get_plugin_options();
    8684    }
    8785   
     
    177175        }
    178176    }
     177    /**
     178     * @return void
     179     */
    179180    public function enqueue_layout_scripts() : void
    180181    {
     
    204205        }
    205206    }
     207    /**
     208     * @return void
     209     */
    206210    public function enqueue_parallax_scripts() : void
    207211    {
  • cb-parallax/trunk/public/includes/class-public-localisation.php

    r3330746 r3330747  
    9292    /**
    9393     * Sets the stored image options.
    94      *
    95      * @param bool false | \WP_Post $post
    9694     */
    9795    private function set_image_options() : void
     
    102100    /**
    103101     * Sets the stored plugin options.
    104      *
    105      * @param bool false | WP_Post $post
    106      */
    107     private function set_plugin_options($post = false) : void
    108     {
    109         $this->plugin_options = $this->options->get_plugin_options($post);
     102     */
     103    private function set_plugin_options() : void
     104    {
     105        $this->plugin_options = $this->options->get_plugin_options();
    110106    }
    111107   
     
    161157        }
    162158    }
     159    /**
     160     * @return array
     161     */
    163162    private function getPrepareData() : array
    164163    {
     
    241240        $overlay_image_select_values = $this->options->get_image_options_whitelist();
    242241        $overlay_image_select_values = $overlay_image_select_values['cb_parallax_overlay_image'];
    243         $overlay_image = isset($stored_image_options['cb_parallax_overlay_image']) ? $stored_image_options['cb_parallax_overlay_image'] : 'none';
     242        $overlay_image = $stored_image_options['cb_parallax_overlay_image'] ?? 'none';
    244243       
    245244        // Replace the human readable overlay image name with the effective file name
Note: See TracChangeset for help on using the changeset viewer.