| Conditions | 2 |
| Paths | 1 |
| Total Lines | 122 |
| 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 |
||
| 36 | function spurs_theme_customize_register( $wp_customize ) { |
||
| 37 | |||
| 38 | // Theme layout settings. |
||
| 39 | $wp_customize->add_section( |
||
| 40 | 'spurs_theme_layout_options', |
||
| 41 | array( |
||
| 42 | 'title' => __( 'Theme Layout Settings', 'spurs' ), |
||
| 43 | 'capability' => 'edit_theme_options', |
||
| 44 | 'description' => __( 'Container width and sidebar defaults', 'spurs' ), |
||
| 45 | 'priority' => 160, |
||
| 46 | ) |
||
| 47 | ); |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Select sanitization function |
||
| 51 | * |
||
| 52 | * @param string $input Slug to sanitize. |
||
| 53 | * @param WP_Customize_Setting $setting Setting instance. |
||
| 54 | * |
||
| 55 | * @return string Sanitized slug if it is a valid choice; otherwise, the setting default. |
||
| 56 | */ |
||
| 57 | function spurs_theme_slug_sanitize_select( $input, $setting ) { |
||
| 58 | |||
| 59 | // input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only |
||
| 60 | $input = sanitize_key( $input ); |
||
|
|
|||
| 61 | |||
| 62 | // get the list of possible select options |
||
| 63 | $choices = $setting->manager->get_control( $setting->id )->choices; |
||
| 64 | |||
| 65 | // return input if valid or return default option |
||
| 66 | return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); |
||
| 67 | |||
| 68 | } |
||
| 69 | |||
| 70 | $wp_customize->add_setting( |
||
| 71 | 'spurs_container_type', |
||
| 72 | array( |
||
| 73 | 'default' => 'container', |
||
| 74 | 'type' => 'theme_mod', |
||
| 75 | 'sanitize_callback' => 'spurs_theme_slug_sanitize_select', |
||
| 76 | 'capability' => 'edit_theme_options', |
||
| 77 | ) |
||
| 78 | ); |
||
| 79 | |||
| 80 | $wp_customize->add_control( |
||
| 81 | new WP_Customize_Control( |
||
| 82 | $wp_customize, |
||
| 83 | 'spurs_container_type', array( |
||
| 84 | 'label' => __( 'Container Width', 'spurs' ), |
||
| 85 | 'description' => __( 'Use Bootstrap fixed or fluid container?', 'spurs' ), |
||
| 86 | 'section' => 'spurs_theme_layout_options', |
||
| 87 | 'settings' => 'spurs_container_type', |
||
| 88 | 'type' => 'select', |
||
| 89 | 'choices' => array( |
||
| 90 | 'container' => __( 'Fixed-width container', 'spurs' ), |
||
| 91 | 'container-fluid' => __( 'Full-width container', 'spurs' ), |
||
| 92 | ), |
||
| 93 | 'priority' => '10', |
||
| 94 | ) |
||
| 95 | ) ); |
||
| 96 | |||
| 97 | $wp_customize->add_setting( |
||
| 98 | 'spurs_sidebar_position', |
||
| 99 | array( |
||
| 100 | 'default' => 'none', |
||
| 101 | 'type' => 'theme_mod', |
||
| 102 | 'sanitize_callback' => 'sanitize_text_field', |
||
| 103 | 'capability' => 'edit_theme_options', |
||
| 104 | ) |
||
| 105 | ); |
||
| 106 | |||
| 107 | $wp_customize->add_control( |
||
| 108 | new WP_Customize_Control( |
||
| 109 | $wp_customize, |
||
| 110 | 'spurs_sidebar_position', array( |
||
| 111 | 'label' => __( 'Default Sidebar Position', 'spurs' ), |
||
| 112 | 'description' => __( '<b>Applies to all pages and posts.</b> <br /> |
||
| 113 | <b>Select:</b> right, left, both, or none. <br /> |
||
| 114 | <b>Note:</b> you can override on individual pages.', |
||
| 115 | 'spurs' ), |
||
| 116 | 'section' => 'spurs_theme_layout_options', |
||
| 117 | 'settings' => 'spurs_sidebar_position', |
||
| 118 | 'type' => 'select', |
||
| 119 | 'sanitize_callback' => 'spurs_theme_slug_sanitize_select', |
||
| 120 | 'choices' => array( |
||
| 121 | 'none' => __( 'No sidebar', 'spurs' ), |
||
| 122 | 'left' => __( 'Left sidebar', 'spurs' ), |
||
| 123 | 'both' => __( 'Left & Right sidebars', 'spurs' ), |
||
| 124 | 'right' => __( 'Right sidebar', 'spurs' ), |
||
| 125 | ), |
||
| 126 | 'priority' => '20', |
||
| 127 | ) |
||
| 128 | ) ); |
||
| 129 | |||
| 130 | $wp_customize->add_setting( |
||
| 131 | 'spurs_pagination', |
||
| 132 | array( |
||
| 133 | 'default' => 'pagination', |
||
| 134 | 'type' => 'theme_mod', |
||
| 135 | 'sanitize_callback' => 'spurs_theme_slug_sanitize_select', |
||
| 136 | 'capability' => 'edit_theme_options', |
||
| 137 | ) |
||
| 138 | ); |
||
| 139 | |||
| 140 | $wp_customize->add_control( |
||
| 141 | new WP_Customize_Control( |
||
| 142 | $wp_customize, |
||
| 143 | 'spurs_pagination', array( |
||
| 144 | 'label' => __( 'Pagination / Load More', 'spurs' ), |
||
| 145 | 'description' => __( 'Pagination or Load More for post listing.', 'spurs' ), |
||
| 146 | 'section' => 'spurs_theme_layout_options', |
||
| 147 | 'settings' => 'spurs_pagination', |
||
| 148 | 'type' => 'select', |
||
| 149 | 'choices' => array( |
||
| 150 | 'pagination' => __( 'Pagination', 'spurs' ), |
||
| 151 | 'loadmore' => __( 'Load More', 'spurs' ), |
||
| 152 | ), |
||
| 153 | 'priority' => '30', |
||
| 154 | ) |
||
| 155 | ) |
||
| 156 | ); |
||
| 157 | } |
||
| 158 | } // endif function_exists( 'spurs_theme_customize_register' ). |
||
| 179 |