| Conditions | 17 |
| Paths | 54 |
| Total Lines | 179 |
| Code Lines | 122 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 176 | public function customize_register( $wp_customize ) { |
||
| 177 | global $customizer_colour_names; |
||
| 178 | global $customizer_colour_choices; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Colors |
||
| 182 | */ |
||
| 183 | $wp_customize->add_panel( 'colors', array( |
||
| 184 | 'title' => esc_html__( 'Site Design', 'lsx-customizer' ), |
||
| 185 | 'priority' => 60, |
||
| 186 | ) ); |
||
| 187 | |||
| 188 | $wp_customize->add_section( 'colors-palette', array( |
||
| 189 | 'title' => esc_html__( 'Block Editor', 'lsx-customizer' ), |
||
| 190 | 'description' => esc_html__( 'Define the block editor colour pallette.', 'lsx-customizer' ), |
||
| 191 | 'priority' => 2, |
||
| 192 | 'panel' => 'colors', |
||
| 193 | ) ); |
||
| 194 | |||
| 195 | $wp_customize->add_section( 'colors-button', array( |
||
| 196 | 'title' => esc_html__( 'Button', 'lsx-customizer' ), |
||
| 197 | 'priority' => 3, |
||
| 198 | 'panel' => 'colors', |
||
| 199 | ) ); |
||
| 200 | |||
| 201 | $wp_customize->add_section( 'colors-button-cta', array( |
||
| 202 | 'title' => esc_html__( 'Button CTA', 'lsx-customizer' ), |
||
| 203 | 'priority' => 4, |
||
| 204 | 'panel' => 'colors', |
||
| 205 | ) ); |
||
| 206 | |||
| 207 | $wp_customize->add_section( 'colors-button-secondary', array( |
||
| 208 | 'title' => esc_html__( 'Button Secondary', 'lsx-customizer' ), |
||
| 209 | 'priority' => 5, |
||
| 210 | 'panel' => 'colors', |
||
| 211 | ) ); |
||
| 212 | |||
| 213 | $wp_customize->add_section( 'colors-button-tertiary', array( |
||
| 214 | 'title' => esc_html__( 'Button Tertiary', 'lsx-customizer' ), |
||
| 215 | 'priority' => 6, |
||
| 216 | 'panel' => 'colors', |
||
| 217 | ) ); |
||
| 218 | |||
| 219 | $wp_customize->add_section( 'colors-top-menu', array( |
||
| 220 | 'title' => esc_html__( 'Top Menu', 'lsx-customizer' ), |
||
| 221 | 'priority' => 7, |
||
| 222 | 'panel' => 'colors', |
||
| 223 | ) ); |
||
| 224 | |||
| 225 | $wp_customize->add_section( 'colors-header', array( |
||
| 226 | 'title' => esc_html__( 'Header', 'lsx-customizer' ), |
||
| 227 | 'priority' => 8, |
||
| 228 | 'panel' => 'colors', |
||
| 229 | ) ); |
||
| 230 | |||
| 231 | $wp_customize->add_section( 'colors-main-menu', array( |
||
| 232 | 'title' => esc_html__( 'Main Menu', 'lsx-customizer' ), |
||
| 233 | 'priority' => 9, |
||
| 234 | 'panel' => 'colors', |
||
| 235 | ) ); |
||
| 236 | |||
| 237 | $wp_customize->add_section( 'colors-banner', array( |
||
| 238 | 'title' => esc_html__( 'Banner', 'lsx-customizer' ), |
||
| 239 | 'priority' => 10, |
||
| 240 | 'panel' => 'colors', |
||
| 241 | ) ); |
||
| 242 | |||
| 243 | $wp_customize->add_section( 'colors-body', array( |
||
| 244 | 'title' => esc_html__( 'Body', 'lsx-customizer' ), |
||
| 245 | 'priority' => 11, |
||
| 246 | 'panel' => 'colors', |
||
| 247 | ) ); |
||
| 248 | |||
| 249 | $wp_customize->add_section( 'colors-footer-cta', array( |
||
| 250 | 'title' => esc_html__( 'Footer CTA', 'lsx-customizer' ), |
||
| 251 | 'priority' => 12, |
||
| 252 | 'panel' => 'colors', |
||
| 253 | ) ); |
||
| 254 | |||
| 255 | $wp_customize->add_section( 'colors-footer-widgets', array( |
||
| 256 | 'title' => esc_html__( 'Footer Widgets', 'lsx-customizer' ), |
||
| 257 | 'priority' => 13, |
||
| 258 | 'panel' => 'colors', |
||
| 259 | ) ); |
||
| 260 | |||
| 261 | $wp_customize->add_section( 'colors-footer', array( |
||
| 262 | 'title' => esc_html__( 'Footer', 'lsx-customizer' ), |
||
| 263 | 'priority' => 14, |
||
| 264 | 'panel' => 'colors', |
||
| 265 | ) ); |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Colour Palette |
||
| 269 | */ |
||
| 270 | $colors = $this->get_color_scheme(); |
||
| 271 | |||
| 272 | $customizer_colour_defaults = array( |
||
| 273 | __( 'Primary Colour', 'lsx-customizer' ) => get_theme_mod( 'button_background_color', $colors['button_background_color'] ), |
||
| 274 | __( 'Strong Primary Colour', 'lsx-button_shadow' ) => get_theme_mod( 'button_background_hover_color', $colors['button_background_hover_color'] ), |
||
| 275 | __( 'Call To Action Colour', 'lsx-customizer' ) => get_theme_mod( 'button_cta_background_color', $colors['button_cta_background_color'] ), |
||
| 276 | __( 'Strong CTA Colour', 'lsx-button_shadow' ) => get_theme_mod( 'button_cta_shadow', $colors['button_cta_shadow'] ), |
||
| 277 | __( 'Secondary Colour', 'lsx-customizer' ) => get_theme_mod( 'button_secondary_background_color', $colors['button_secondary_background_color'] ), |
||
| 278 | __( 'Strong Secondary Colour', 'lsx-button_shadow' ) => get_theme_mod( 'button_secondary_shadow', $colors['button_secondary_shadow'] ), |
||
| 279 | __( 'Tertiary Colour', 'lsx-customizer' ) => get_theme_mod( 'button_tertiary_background_color', $colors['button_tertiary_background_color'] ), |
||
| 280 | __( 'Strong Tertiary Colour', 'lsx-button_shadow' ) => get_theme_mod( 'button_tertiary_shadow', $colors['button_tertiary_shadow'] ), |
||
| 281 | ); |
||
| 282 | foreach ( $customizer_colour_defaults as $key => $value ) { |
||
| 283 | |||
| 284 | $color_name = strtolower( str_replace( ' ', '_', $key ) ); |
||
| 285 | $color_name = $color_name; |
||
| 286 | |||
| 287 | $wp_customize->add_setting( $color_name, array( |
||
| 288 | 'default' => $value, |
||
| 289 | 'type' => 'theme_mod', |
||
| 290 | 'transport' => 'postMessage', |
||
| 291 | 'sanitize_callback' => 'sanitize_hex_color', |
||
| 292 | ) ); |
||
| 293 | $wp_customize->add_control( |
||
| 294 | new WP_Customize_Color_Control( |
||
| 295 | $wp_customize, |
||
| 296 | $color_name, |
||
| 297 | array( |
||
| 298 | 'label' => $key, |
||
| 299 | 'section' => 'colors-palette', |
||
| 300 | 'settings' => $color_name, |
||
| 301 | ) |
||
| 302 | ) |
||
| 303 | ); |
||
| 304 | } |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Colors |
||
| 308 | */ |
||
| 309 | foreach ( $customizer_colour_names as $key => $value ) { |
||
| 310 | $sanitize_callback = 'sanitize_hex_color'; |
||
| 311 | |||
| 312 | if ( 'background_color' === $key ) { |
||
| 313 | $sanitize_callback = 'sanitize_hex_color_no_hash'; |
||
| 314 | } |
||
| 315 | |||
| 316 | $section = 'colors-core'; |
||
| 317 | |||
| 318 | if ( preg_match( '/^button_cta_.*/', $key ) ) { |
||
| 319 | $section = 'colors-button-cta'; |
||
| 320 | } elseif ( preg_match( '/^button_secondary_.*/', $key ) ) { |
||
| 321 | $section = 'colors-button-secondary'; |
||
| 322 | } elseif ( preg_match( '/^button_tertiary_.*/', $key ) ) { |
||
| 323 | $section = 'colors-button-tertiary'; |
||
| 324 | } elseif ( preg_match( '/^button_.*/', $key ) ) { |
||
| 325 | $section = 'colors-button'; |
||
| 326 | } elseif ( preg_match( '/^top_menu_.*/', $key ) ) { |
||
| 327 | $section = 'colors-top-menu'; |
||
| 328 | } elseif ( preg_match( '/^header_.*/', $key ) ) { |
||
| 329 | $section = 'colors-header'; |
||
| 330 | } elseif ( preg_match( '/^main_menu_.*/', $key ) ) { |
||
| 331 | $section = 'colors-main-menu'; |
||
| 332 | } elseif ( preg_match( '/^banner_.*/', $key ) ) { |
||
| 333 | $section = 'colors-banner'; |
||
| 334 | } elseif ( preg_match( '/^body_.*/', $key ) || 'background_color' === $key ) { |
||
| 335 | $section = 'colors-body'; |
||
| 336 | } elseif ( preg_match( '/^footer_cta_.*/', $key ) ) { |
||
| 337 | $section = 'colors-footer-cta'; |
||
| 338 | } elseif ( preg_match( '/^footer_widgets_.*/', $key ) ) { |
||
| 339 | $section = 'colors-footer-widgets'; |
||
| 340 | } elseif ( preg_match( '/^footer_.*/', $key ) ) { |
||
| 341 | $section = 'colors-footer'; |
||
| 342 | } |
||
| 343 | |||
| 344 | $wp_customize->add_setting( $key, array( |
||
| 345 | 'default' => $customizer_colour_choices['default']['colors'][ $key ], |
||
| 346 | 'type' => 'theme_mod', |
||
| 347 | 'transport' => 'postMessage', |
||
| 348 | 'sanitize_callback' => $sanitize_callback, |
||
| 349 | ) ); |
||
| 350 | |||
| 351 | $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $key, array( |
||
| 352 | 'label' => $value, |
||
| 353 | 'section' => $section, |
||
| 354 | 'settings' => $key, |
||
| 355 | ) ) ); |
||
| 477 |