| Conditions | 2 |
| Paths | 1 |
| Total Lines | 75 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 33 | function bitsy_theme_customize_register( $wp_customize ) { |
||
| 34 | |||
| 35 | // Theme layout settings. |
||
| 36 | $wp_customize->add_section( 'bitsy_theme_layout_options', array( |
||
| 37 | 'title' => __( 'Theme Layout Settings', 'spurs' ), |
||
|
1 ignored issue
–
show
|
|||
| 38 | 'capability' => 'edit_theme_options', |
||
| 39 | 'description' => __( 'Container width and sidebar defaults', 'spurs' ), |
||
| 40 | 'priority' => 160, |
||
| 41 | ) ); |
||
| 42 | |||
| 43 | //select sanitization function |
||
| 44 | function bitsy_theme_slug_sanitize_select( $input, $setting ) { |
||
| 45 | |||
| 46 | //input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only |
||
| 47 | $input = sanitize_key( $input ); |
||
|
1 ignored issue
–
show
|
|||
| 48 | |||
| 49 | //get the list of possible select options |
||
| 50 | $choices = $setting->manager->get_control( $setting->id )->choices; |
||
| 51 | |||
| 52 | //return input if valid or return default option |
||
| 53 | return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); |
||
| 54 | |||
| 55 | } |
||
| 56 | |||
| 57 | $wp_customize->add_setting( 'bitsy_container_type', array( |
||
| 58 | 'default' => 'container', |
||
| 59 | 'type' => 'theme_mod', |
||
| 60 | 'sanitize_callback' => 'bitsy_theme_slug_sanitize_select', |
||
| 61 | 'capability' => 'edit_theme_options', |
||
| 62 | ) ); |
||
| 63 | |||
| 64 | $wp_customize->add_control( |
||
| 65 | new WP_Customize_Control( |
||
|
1 ignored issue
–
show
|
|||
| 66 | $wp_customize, |
||
| 67 | 'bitsy_container_type', array( |
||
| 68 | 'label' => __( 'Container Width', 'spurs' ), |
||
| 69 | 'description' => __( "Use Bootstrap fixed or fluid container?", 'spurs' ), |
||
| 70 | 'section' => 'bitsy_theme_layout_options', |
||
| 71 | 'settings' => 'bitsy_container_type', |
||
| 72 | 'type' => 'select', |
||
| 73 | 'choices' => array( |
||
| 74 | 'container' => __( 'Fixed-width container', 'spurs' ), |
||
| 75 | 'container-fluid' => __( 'Full-width container', 'spurs' ), |
||
| 76 | ), |
||
| 77 | 'priority' => '10', |
||
| 78 | ) |
||
| 79 | ) ); |
||
| 80 | |||
| 81 | $wp_customize->add_setting( 'bitsy_sidebar_position', array( |
||
| 82 | 'default' => 'right', |
||
| 83 | 'type' => 'theme_mod', |
||
| 84 | 'sanitize_callback' => 'sanitize_text_field', |
||
| 85 | 'capability' => 'edit_theme_options', |
||
| 86 | ) ); |
||
| 87 | |||
| 88 | $wp_customize->add_control( |
||
| 89 | new WP_Customize_Control( |
||
| 90 | $wp_customize, |
||
| 91 | 'bitsy_sidebar_position', array( |
||
| 92 | 'label' => __( 'Default Sidebar Position', 'spurs' ), |
||
| 93 | 'description' => __( "<b>Applies to all pages and posts.</b> <br /> |
||
| 94 | <b>Select:</b> right, left, both, or none. <br /> |
||
| 95 | <b>Note:</b> you can override on individual pages.", |
||
| 96 | 'spurs' ), |
||
| 97 | 'section' => 'bitsy_theme_layout_options', |
||
| 98 | 'settings' => 'bitsy_sidebar_position', |
||
| 99 | 'type' => 'select', |
||
| 100 | 'sanitize_callback' => 'bitsy_theme_slug_sanitize_select', |
||
| 101 | 'choices' => array( |
||
| 102 | 'right' => __( 'Right sidebar', 'spurs' ), |
||
| 103 | 'left' => __( 'Left sidebar', 'spurs' ), |
||
| 104 | 'both' => __( 'Left & Right sidebars', 'spurs' ), |
||
| 105 | 'none' => __( 'No sidebar', 'spurs' ), |
||
| 106 | ), |
||
| 107 | 'priority' => '20', |
||
| 108 | ) |
||
| 126 | add_action( 'customize_preview_init', 'bitsy_customize_preview_js' ); |