| Conditions | 1 |
| Paths | 1 |
| Total Lines | 225 |
| 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 |
||
| 40 | public function customize_register( $wp_customize ) { |
||
| 41 | require_once dirname( JETPACK__PLUGIN_FILE ) . '/modules/search/customize-controls/class-label-control.php'; |
||
| 42 | require_once dirname( JETPACK__PLUGIN_FILE ) . '/modules/search/customize-controls/class-excluded-post-types-control.php'; |
||
| 43 | $section_id = 'jetpack_search'; |
||
| 44 | $setting_prefix = Jetpack_Search_Options::OPTION_PREFIX; |
||
| 45 | |||
| 46 | $wp_customize->add_section( |
||
| 47 | $section_id, |
||
| 48 | array( |
||
| 49 | 'title' => esc_html__( 'Jetpack Search', 'jetpack' ), |
||
| 50 | 'capability' => 'edit_theme_options', |
||
| 51 | 'priority' => 200, |
||
| 52 | ) |
||
| 53 | ); |
||
| 54 | |||
| 55 | $id = $setting_prefix . 'color_theme'; |
||
| 56 | $wp_customize->add_setting( |
||
| 57 | $id, |
||
| 58 | array( |
||
| 59 | 'default' => 'light', |
||
| 60 | 'transport' => 'postMessage', |
||
| 61 | 'type' => 'option', |
||
| 62 | ) |
||
| 63 | ); |
||
| 64 | $wp_customize->add_control( |
||
| 65 | $id, |
||
| 66 | array( |
||
| 67 | 'label' => __( 'Theme', 'jetpack' ), |
||
| 68 | 'description' => __( 'Select a theme for your search overlay.', 'jetpack' ), |
||
| 69 | 'section' => $section_id, |
||
| 70 | 'type' => 'radio', |
||
| 71 | 'choices' => array( |
||
| 72 | 'light' => __( 'Light', 'jetpack' ), |
||
| 73 | 'dark' => __( 'Dark', 'jetpack' ), |
||
| 74 | ), |
||
| 75 | ) |
||
| 76 | ); |
||
| 77 | |||
| 78 | $id = $setting_prefix . 'default_sort'; |
||
| 79 | $wp_customize->add_setting( |
||
| 80 | $id, |
||
| 81 | array( |
||
| 82 | 'default' => 'relevance', |
||
| 83 | 'type' => 'option', |
||
| 84 | ) |
||
| 85 | ); |
||
| 86 | $wp_customize->add_control( |
||
| 87 | $id, |
||
| 88 | array( |
||
| 89 | 'choices' => array( |
||
| 90 | 'relevance' => __( 'Relevance (recommended)', 'jetpack' ), |
||
| 91 | 'newest' => __( 'Newest first', 'jetpack' ), |
||
| 92 | 'oldest' => __( 'Oldest first', 'jetpack' ), |
||
| 93 | ), |
||
| 94 | 'description' => __( 'Pick the initial sort for your search results.', 'jetpack' ), |
||
| 95 | 'label' => __( 'Default Sort', 'jetpack' ), |
||
| 96 | 'section' => $section_id, |
||
| 97 | 'type' => 'select', |
||
| 98 | ) |
||
| 99 | ); |
||
| 100 | |||
| 101 | $id = $setting_prefix . 'overlay_trigger'; |
||
| 102 | $wp_customize->add_setting( |
||
| 103 | $id, |
||
| 104 | array( |
||
| 105 | 'default' => 'results', |
||
| 106 | 'transport' => 'postMessage', |
||
| 107 | 'type' => 'option', |
||
| 108 | ) |
||
| 109 | ); |
||
| 110 | $wp_customize->add_control( |
||
| 111 | $id, |
||
| 112 | array( |
||
| 113 | 'label' => __( 'Search Input Overlay Trigger', 'jetpack' ), |
||
| 114 | 'description' => __( 'Select when your overlay should appear.', 'jetpack' ), |
||
| 115 | 'section' => $section_id, |
||
| 116 | 'type' => 'select', |
||
| 117 | 'choices' => array( |
||
| 118 | 'immediate' => __( 'Open when the user starts typing', 'jetpack' ), |
||
| 119 | 'results' => __( 'Open when results are available', 'jetpack' ), |
||
| 120 | ), |
||
| 121 | ) |
||
| 122 | ); |
||
| 123 | |||
| 124 | $id = $setting_prefix . 'excluded_post_types'; |
||
| 125 | $wp_customize->add_setting( |
||
| 126 | $id, |
||
| 127 | array( |
||
| 128 | 'default' => '', |
||
| 129 | 'type' => 'option', |
||
| 130 | ) |
||
| 131 | ); |
||
| 132 | $wp_customize->add_control( |
||
| 133 | new Excluded_Post_Types_Control( |
||
| 134 | $wp_customize, |
||
| 135 | $id, |
||
| 136 | array( |
||
| 137 | 'description' => __( 'Choose post types to exclude from search results.', 'jetpack' ), |
||
| 138 | 'label' => __( 'Excluded Post Types', 'jetpack' ), |
||
| 139 | 'section' => $section_id, |
||
| 140 | ) |
||
| 141 | ) |
||
| 142 | ); |
||
| 143 | |||
| 144 | $id = $setting_prefix . 'result_format'; |
||
| 145 | $wp_customize->add_setting( |
||
| 146 | $id, |
||
| 147 | array( |
||
| 148 | 'default' => 'minimal', |
||
| 149 | 'transport' => 'postMessage', |
||
| 150 | 'type' => 'option', |
||
| 151 | ) |
||
| 152 | ); |
||
| 153 | $wp_customize->add_control( |
||
| 154 | $id, |
||
| 155 | array( |
||
| 156 | 'label' => __( 'Result Format', 'jetpack' ), |
||
| 157 | 'description' => __( 'Choose how the search results look.', 'jetpack' ), |
||
| 158 | 'section' => $section_id, |
||
| 159 | 'type' => 'select', |
||
| 160 | 'choices' => array( |
||
| 161 | 'minimal' => __( 'Minimal', 'jetpack' ), |
||
| 162 | 'expanded' => __( 'Expanded (shows images)', 'jetpack' ), |
||
| 163 | 'product' => __( 'Product (for WooCommerce stores)', 'jetpack' ), |
||
| 164 | ), |
||
| 165 | ) |
||
| 166 | ); |
||
| 167 | |||
| 168 | $id = $setting_prefix . 'highlight_color'; |
||
| 169 | $wp_customize->add_setting( |
||
| 170 | $id, |
||
| 171 | array( |
||
| 172 | 'default' => '#FFC', |
||
| 173 | 'transport' => 'postMessage', |
||
| 174 | 'type' => 'option', |
||
| 175 | ) |
||
| 176 | ); |
||
| 177 | $wp_customize->add_control( |
||
| 178 | new WP_Customize_Color_Control( |
||
| 179 | $wp_customize, |
||
| 180 | $id, |
||
| 181 | array( |
||
| 182 | 'label' => __( 'Highlight Search Terms', 'jetpack' ), |
||
| 183 | 'description' => __( 'Choose a color to highlight matching search terms.', 'jetpack' ), |
||
| 184 | 'section' => $section_id, |
||
| 185 | ) |
||
| 186 | ) |
||
| 187 | ); |
||
| 188 | |||
| 189 | $id = $setting_prefix . 'additional_settings_placeholder'; |
||
| 190 | $wp_customize->add_setting( |
||
| 191 | $id, |
||
| 192 | array( 'type' => 'option' ) |
||
| 193 | ); |
||
| 194 | $wp_customize->add_control( |
||
| 195 | new Label_Control( |
||
| 196 | $wp_customize, |
||
| 197 | $id, |
||
| 198 | array( |
||
| 199 | 'label' => __( 'Additional Jetpack Search Settings', 'jetpack' ), |
||
| 200 | 'section' => $section_id, |
||
| 201 | ) |
||
| 202 | ) |
||
| 203 | ); |
||
| 204 | |||
| 205 | $id = $setting_prefix . 'enable_sort'; |
||
| 206 | $wp_customize->add_setting( |
||
| 207 | $id, |
||
| 208 | array( |
||
| 209 | 'default' => '1', |
||
| 210 | 'sanitize_callback' => array( 'Jetpack_Search_Helpers', 'sanitize_checkbox_value' ), |
||
| 211 | 'sanitize_js_callback' => array( 'Jetpack_Search_Helpers', 'sanitize_checkbox_value_for_js' ), |
||
| 212 | 'transport' => 'postMessage', |
||
| 213 | 'type' => 'option', |
||
| 214 | ) |
||
| 215 | ); |
||
| 216 | $wp_customize->add_control( |
||
| 217 | $id, |
||
| 218 | array( |
||
| 219 | 'label' => __( 'Show sort selector', 'jetpack' ), |
||
| 220 | 'section' => $section_id, |
||
| 221 | 'type' => 'checkbox', |
||
| 222 | ) |
||
| 223 | ); |
||
| 224 | |||
| 225 | $id = $setting_prefix . 'inf_scroll'; |
||
| 226 | $wp_customize->add_setting( |
||
| 227 | $id, |
||
| 228 | array( |
||
| 229 | 'default' => '1', |
||
| 230 | 'sanitize_callback' => array( 'Jetpack_Search_Helpers', 'sanitize_checkbox_value' ), |
||
| 231 | 'sanitize_js_callback' => array( 'Jetpack_Search_Helpers', 'sanitize_checkbox_value_for_js' ), |
||
| 232 | 'transport' => 'postMessage', |
||
| 233 | 'type' => 'option', |
||
| 234 | ) |
||
| 235 | ); |
||
| 236 | $wp_customize->add_control( |
||
| 237 | $id, |
||
| 238 | array( |
||
| 239 | 'type' => 'checkbox', |
||
| 240 | 'section' => $section_id, |
||
| 241 | 'label' => __( 'Enable infinite scrolling', 'jetpack' ), |
||
| 242 | ) |
||
| 243 | ); |
||
| 244 | |||
| 245 | $id = $setting_prefix . 'show_powered_by'; |
||
| 246 | $wp_customize->add_setting( |
||
| 247 | $id, |
||
| 248 | array( |
||
| 249 | 'default' => '1', |
||
| 250 | 'sanitize_callback' => array( 'Jetpack_Search_Helpers', 'sanitize_checkbox_value' ), |
||
| 251 | 'sanitize_js_callback' => array( 'Jetpack_Search_Helpers', 'sanitize_checkbox_value_for_js' ), |
||
| 252 | 'transport' => 'postMessage', |
||
| 253 | 'type' => 'option', |
||
| 254 | ) |
||
| 255 | ); |
||
| 256 | $wp_customize->add_control( |
||
| 257 | $id, |
||
| 258 | array( |
||
| 259 | 'type' => 'checkbox', |
||
| 260 | 'section' => $section_id, |
||
| 261 | 'label' => __( 'Display "Powered by Jetpack"', 'jetpack' ), |
||
| 262 | ) |
||
| 263 | ); |
||
| 264 | } |
||
| 265 | |||
| 284 |