Changeset 3330747
- Timestamp:
- 07/19/2025 11:00:29 PM (8 months ago)
- Location:
- cb-parallax/trunk
- Files:
-
- 10 edited
-
admin/includes/class-localisation.php (modified) (15 diffs)
-
admin/includes/class-meta-box.php (modified) (4 diffs)
-
admin/menu/class-settings-page.php (modified) (6 diffs)
-
admin/menu/includes/class-ajax.php (modified) (5 diffs)
-
admin/menu/includes/class-options.php (modified) (10 diffs)
-
admin/partials/class-settings-display.php (modified) (4 diffs)
-
includes/class-cb-parallax-upgrade.php (modified) (3 diffs)
-
includes/class-cb-parallax.php (modified) (2 diffs)
-
public/class-public.php (modified) (3 diffs)
-
public/includes/class-public-localisation.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cb-parallax/trunk/admin/includes/class-localisation.php
r3330746 r3330747 34 34 */ 35 35 private string $domain; 36 37 36 /** 38 37 * Holds a list of supported post types. … … 41 40 */ 42 41 private array $screen_ids; 43 44 42 /** 45 43 * The reference to the options class. … … 50 48 */ 51 49 private MenuIncludes\cb_parallax_options $options; 52 53 50 /** 54 51 * Holds the current plugin options for the requested page or post … … 57 54 */ 58 55 private array $plugin_options; 59 60 56 /** 61 57 * Holds the current image options for the requested page or post … … 64 60 */ 65 61 private array $image_options; 66 67 62 /** 68 63 * cb_parallax_admin constructor. … … 78 73 $this->options = $options; 79 74 } 80 81 75 /** 82 76 * Registers the methods that need to be hooked with WordPress. … … 102 96 } 103 97 } 104 105 98 /** 106 99 * 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 $post109 100 */ 110 101 public function retrieve_image_options() : void … … 158 149 // The following values have no defaults, so we check them "by hand": 159 150 // 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'] ?? ''; 162 153 163 154 // Check the color values … … 170 161 } 171 162 // 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'] ?? ''; 173 164 // If an attachment ID was found, get the image source. 174 165 $image = null; … … 177 168 } 178 169 // Set the url. 179 $options['backgroundImageUrl'] = isset($image[0]) ? $image[0] :'';170 $options['backgroundImageUrl'] = $image[0] ?? ''; 180 171 // 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] ?? ''; 183 174 184 175 $this->image_options = $options; 185 176 } 186 187 177 /** 188 178 * Assembles the data we're sending to the javascript file, … … 233 223 wp_localize_script('cb-parallax-settings-display-js', 'Cb_Parallax_Admin', $data); 234 224 } 235 236 225 /** 237 226 * 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 } 246 232 /** 247 233 * Sets the stored image options. 248 *249 * @param bool false | \WP_Post $post250 234 */ 251 235 private function set_image_options() : void … … 253 237 $this->image_options = $this->options->get_image_options(); 254 238 } 255 256 239 /** 257 240 * Retrieves the image data for the requested image, … … 277 260 return $image_data; 278 261 } 279 280 262 /** 281 263 * Returns an array containing arrays of strings that may be translated into the user-defined locale. … … 317 299 )); 318 300 } 319 320 301 /** 321 302 * Checks the image for the minimum width and height required to make use of the parallax effect. … … 332 313 return $image_data['image_width'] >= $min_width && $image_data['image_height'] >= $min_height ? '1' : '0'; 333 314 } 334 335 315 /** 336 316 * Assembles the data we're sending to the javascript file, -
cb-parallax/trunk/admin/includes/class-meta-box.php
r3330683 r3330747 215 215 $options = $this->options->get_default_image_options(); 216 216 } 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; 220 220 221 221 // Get image meta … … 225 225 } 226 226 // Get the image URL. 227 $url = isset($image[0]) ? $image[0] :'';227 $url = $image[0] ?? ''; 228 228 229 229 $nonce = wp_create_nonce('cb_parallax_manage_options_nonce'); … … 275 275 * Retrieves the plugin-related input, preprocesses it and uses the reference of the options class to process and finally store the plugin-related data. 276 276 * 277 * @param int$post_id277 * @param string $post_id 278 278 * @param \WP_Post $post 279 279 * 280 280 * @return void 281 281 */ 282 public function save_post($post_id, $post) : void282 public function save_post($post_id, WP_Post $post) : void 283 283 { 284 284 // Verify the nonce. … … 308 308 $data = array(); 309 309 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; 311 311 } 312 312 -
cb-parallax/trunk/admin/menu/class-settings-page.php
r3330678 r3330747 141 141 public function enqueue_styles(string $hook_suffix) : void 142 142 { 143 if ( isset($hook_suffix)&& $hook_suffix === $this->screen_id) {143 if ('' !== $hook_suffix && $hook_suffix === $this->screen_id) { 144 144 // Color picker. 145 145 wp_enqueue_style('wp-color-picker'); … … 163 163 public function enqueue_scripts(string $hook_suffix) : void 164 164 { 165 if ( isset($hook_suffix)&& $hook_suffix === $this->screen_id) {165 if ('' !== $hook_suffix && $hook_suffix === $this->screen_id) { 166 166 wp_enqueue_script('jquery'); 167 167 // Dashicons … … 215 215 public function include_menu_localisation(string $hook_suffix) : void 216 216 { 217 if ( isset($hook_suffix)&& $hook_suffix === $this->screen_id) {217 if ('' !== $hook_suffix && $hook_suffix === $this->screen_id) { 218 218 $script_localisation = new AdminIncludes\cb_parallax_localisation($this->domain, $this->screen_ids, $this->options); 219 219 $script_localisation->add_hooks(); … … 249 249 250 250 $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; 254 254 255 255 // Get image meta data … … 259 259 } 260 260 // Get the image url 261 $url = isset($image[0]) ? $image[0] :'';261 $url = $image[0] ?? ''; 262 262 263 263 /** … … 276 276 $settings = $this->options->get_options_arguments(); 277 277 foreach ($settings as $option_key => $args) { 278 $value = isset($stored_options[$option_key]) ? $stored_options[$option_key] :'';278 $value = $stored_options[$option_key] ?? ''; 279 279 280 280 switch ($args['input_type']) { -
cb-parallax/trunk/admin/menu/includes/class-ajax.php
r3330746 r3330747 47 47 * @access protected 48 48 */ 49 protected ?string $nonce_error_text;49 protected string $nonce_error_text; 50 50 51 51 /** … … 62 62 $this->domain = $domain; 63 63 $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)); 65 65 } 66 66 … … 106 106 107 107 // retrieve the options 108 $post_id = isset($_POST['post_id']) ? $_POST['post_id'] :'';108 $post_id = $_POST['post_id'] ?? ''; 109 109 $data = array(); 110 110 $options_arguments = '' === $_POST['post_id'] ? $this->options->get_default_options() : $this->options->get_default_options('image'); … … 165 165 public function cb_parallax_reset_options() : void 166 166 { 167 $nonce = isset($_POST['nonce']) ? $_POST['nonce'] :false;167 $nonce = $_POST['nonce'] ?? false; 168 168 169 169 if (false === wp_verify_nonce($nonce, 'cb_parallax_manage_options_nonce')) { … … 179 179 * We use this value to determine if we're resetting plugin options or options on a per-post basis. 180 180 */ 181 $post_id = isset($_POST['post_id']) ? $_POST['post_id'] :'';181 $post_id = $_POST['post_id'] ?? ''; 182 182 183 183 $result = $this->options->reset_options($post_id); -
cb-parallax/trunk/admin/menu/includes/class-options.php
r3330746 r3330747 3 3 namespace CbParallax\Admin\Menu\Includes; 4 4 5 use WP_Post; 5 6 use WP_Error; 6 7 use CbParallax\Admin\Menu\Includes as MenuIncludes; … … 120 121 return $plugin_options; 121 122 } 123 /** 124 * @return array 125 */ 122 126 private function image_options_whitelist() : array 123 127 { … … 296 300 } 297 301 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( 302 305 'option_key' => $arguments['option_key'], 303 306 'name' => $arguments['name'], … … 308 311 'select_values' => $arguments['select_values'], 309 312 ); 310 } 313 }, $options); 311 314 312 315 return $args; … … 713 716 $post_meta = get_post_meta($post->ID, 'cb_parallax', true); 714 717 // 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']; 716 719 } 717 720 718 721 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'; 720 723 } 721 724 … … 781 784 * @return string $result 782 785 */ 783 public function determine_options_source( $post) : string786 public function determine_options_source(WP_Post $post) : string 784 787 { 785 788 $stored_options = get_option('cb_parallax_options'); … … 864 867 delete_option('cb_parallax_options'); 865 868 866 $result = null;867 869 // Checks if the options are post-related or plugin-related. 868 870 if ('' === $post_id) { … … 928 930 * Since the ids for attachments will most likely be assigned in a different order after website migrations, 929 931 * 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 $post932 932 * 933 933 * @return bool … … 950 950 return false; 951 951 } else { 952 $stored_file = isset($attachment_meta['file']) ? $attachment_meta['file'] :'false';952 $stored_file = $attachment_meta['file'] ?? 'false'; 953 953 $found_file = str_replace(site_url().'/wp-content/uploads/', '', $image_attributes[0]); 954 954 } … … 969 969 return true; 970 970 } 971 972 971 /** 973 972 * Returns the image options based on the plugin settings or the post meta data respectively. 974 *975 * @param mixed | \WP_Post $post | bool false976 973 * 977 974 * @return array $image_options -
cb-parallax/trunk/admin/partials/class-settings-display.php
r3330746 r3330747 124 124 $this->default_image_options = $this->options->get_default_image_options(); 125 125 } 126 127 126 /** 128 127 * Creates and returns a string containing the hidden fields: … … 133 132 * @param string $attachment_id 134 133 * @param string $url 134 * @param $canParallax 135 * @param $parallax_enabled 135 136 * 136 137 * @return string $html … … 251 252 name="<?php echo 'cb_parallax_options' ?>[<?php echo $option_key ?>]" 252 253 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; ?>" 254 255 data-input="cb-parallax"/> 255 256 <span class="cb-parallax-switch-label <?php echo $option_key ?>" data-on="On" data-off="Off"></span> … … 285 286 <input type="text" id="<?php echo $option_key ?>" title="<?php echo $description ?>" 286 287 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] ?>" 288 289 value="<?php echo $value ?>" 289 290 class="<?php echo $option_key ?> cb-parallax-color-picker -
cb-parallax/trunk/includes/class-cb-parallax-upgrade.php
r3330746 r3330747 130 130 } 131 131 } 132 /** 133 * @return bool 134 */ 132 135 private function upgrade_plugin_options() : bool 133 136 { … … 171 174 return false; 172 175 } 173 176 /** 177 * @return bool|void 178 */ 179 /** 180 * @return bool|void 181 */ 174 182 private function upgrade_post_meta_options() 175 183 { … … 255 263 } 256 264 } 265 /** 266 * @return void 267 */ 257 268 private function add_upgrade_flag() : void 258 269 { -
cb-parallax/trunk/includes/class-cb-parallax.php
r3330678 r3330747 128 128 $this->run_public(); 129 129 } 130 /** 131 * @return void 132 */ 130 133 private function ensure_options() : void 131 134 { … … 135 138 } 136 139 } 140 /** 141 * @return void 142 */ 137 143 public function set_initial_plugin_options() : void 138 144 { -
cb-parallax/trunk/public/class-public.php
r3330746 r3330747 78 78 /** 79 79 * 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(); 86 84 } 87 85 … … 177 175 } 178 176 } 177 /** 178 * @return void 179 */ 179 180 public function enqueue_layout_scripts() : void 180 181 { … … 204 205 } 205 206 } 207 /** 208 * @return void 209 */ 206 210 public function enqueue_parallax_scripts() : void 207 211 { -
cb-parallax/trunk/public/includes/class-public-localisation.php
r3330746 r3330747 92 92 /** 93 93 * Sets the stored image options. 94 *95 * @param bool false | \WP_Post $post96 94 */ 97 95 private function set_image_options() : void … … 102 100 /** 103 101 * 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(); 110 106 } 111 107 … … 161 157 } 162 158 } 159 /** 160 * @return array 161 */ 163 162 private function getPrepareData() : array 164 163 { … … 241 240 $overlay_image_select_values = $this->options->get_image_options_whitelist(); 242 241 $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'; 244 243 245 244 // Replace the human readable overlay image name with the effective file name
Note: See TracChangeset
for help on using the changeset viewer.