@@ -12,475 +12,475 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class Admin { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Holds class instance |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - * |
|
| 20 | - * @var object \lsx\search\classes\Admin() |
|
| 21 | - */ |
|
| 22 | - protected static $instance = null; |
|
| 23 | - /** |
|
| 24 | - * Holds the options for the search. |
|
| 25 | - * |
|
| 26 | - * @var array() |
|
| 27 | - */ |
|
| 28 | - public $options = false; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Holds the facetwp data for use in the fields. |
|
| 32 | - * |
|
| 33 | - * @var array() |
|
| 34 | - */ |
|
| 35 | - public $facet_data = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Holds the Alpha betical facetwp data for use in the fields. |
|
| 39 | - * |
|
| 40 | - * @var array() |
|
| 41 | - */ |
|
| 42 | - public $az_facets = array(); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Holds the settings page theme functions |
|
| 46 | - * |
|
| 47 | - * @var object \lsx\search\classes\admin\Settings_Theme(); |
|
| 48 | - */ |
|
| 49 | - public $settings_theme; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Construct method. |
|
| 53 | - */ |
|
| 54 | - public function __construct() { |
|
| 55 | - $this->load_classes(); |
|
| 56 | - add_action( 'cmb2_admin_init', array( $this, 'register_settings_page' ) ); |
|
| 57 | - add_action( 'lsx_search_settings_page', array( $this, 'configure_settings_search_engine_fields' ), 15, 1 ); |
|
| 58 | - add_action( 'lsx_search_settings_page', array( $this, 'configure_settings_search_archive_fields' ), 15, 1 ); |
|
| 59 | - add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
| 60 | - |
|
| 61 | - if ( is_admin() ) { |
|
| 62 | - add_filter( 'lsx_customizer_colour_selectors_body', array( $this, 'customizer_body_colours_handler' ), 15, 2 ); |
|
| 63 | - add_filter( 'lsx_customizer_colour_selectors_button', array( $this, 'customizer_button_colours' ), 10, 2 ); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Return an instance of this class. |
|
| 69 | - * |
|
| 70 | - * @since 1.0.0 |
|
| 71 | - * |
|
| 72 | - * @return object \lsx\member_directory\search\Admin() A single instance of this class. |
|
| 73 | - */ |
|
| 74 | - public static function get_instance() { |
|
| 75 | - // If the single instance hasn't been set, set it now. |
|
| 76 | - if ( null === self::$instance ) { |
|
| 77 | - self::$instance = new self(); |
|
| 78 | - } |
|
| 79 | - return self::$instance; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Loads the variable classes and the static classes. |
|
| 84 | - */ |
|
| 85 | - private function load_classes() { |
|
| 86 | - require_once LSX_SEARCH_PATH . 'classes/admin/class-settings-theme.php'; |
|
| 87 | - $this->settings_theme = admin\Settings_Theme::get_instance(); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Configure Business Directory custom fields for the Settings page. |
|
| 92 | - * |
|
| 93 | - * @return void |
|
| 94 | - */ |
|
| 95 | - public function register_settings_page() { |
|
| 96 | - $args = array( |
|
| 97 | - 'id' => 'lsx_search_settings', |
|
| 98 | - 'title' => '<h1>' . esc_html__( 'LSX Search Settings', 'lsx-search' ) . ' <span class="version">' . LSX_SEARCH_VER . '</span></h1>', |
|
| 99 | - 'menu_title' => esc_html__( 'LSX Search', 'search' ), // Falls back to 'title' (above). |
|
| 100 | - 'object_types' => array( 'options-page' ), |
|
| 101 | - 'option_key' => 'lsx-search-settings', // The option key and admin menu page slug. |
|
| 102 | - 'parent_slug' => 'options-general.php', |
|
| 103 | - 'capability' => 'manage_options', // Cap required to view options-page. |
|
| 104 | - ); |
|
| 105 | - $cmb = new_cmb2_box( $args ); |
|
| 106 | - do_action( 'lsx_search_settings_page', $cmb ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Sets post types with active search options. |
|
| 111 | - */ |
|
| 112 | - public function register_post_type_tabs( $post_types_plural ) { |
|
| 113 | - $post_types_plural = array( |
|
| 114 | - 'project' => 'projects', |
|
| 115 | - 'service' => 'services', |
|
| 116 | - 'team' => 'team', |
|
| 117 | - 'testimonial' => 'testimonials', |
|
| 118 | - 'video' => 'videos', |
|
| 119 | - 'product' => 'products', // WooCommerce |
|
| 120 | - 'post' => 'posts', |
|
| 121 | - ); |
|
| 122 | - return $post_types_plural; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Gets the Tour Operator Post Types. |
|
| 127 | - * |
|
| 128 | - * @return array |
|
| 129 | - */ |
|
| 130 | - public function get_to_post_types() { |
|
| 131 | - $to_types = array( |
|
| 132 | - 'accommodation', |
|
| 133 | - 'tour', |
|
| 134 | - 'destination', |
|
| 135 | - 'review', |
|
| 136 | - 'activity', |
|
| 137 | - 'special', |
|
| 138 | - 'vehicle', |
|
| 139 | - ); |
|
| 140 | - return $to_types; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Sets the FacetWP variables. |
|
| 145 | - * |
|
| 146 | - * @return void |
|
| 147 | - */ |
|
| 148 | - public function set_facetwp_vars() { |
|
| 149 | - if ( function_exists( '\FWP' ) ) { |
|
| 150 | - $facet_data = \FWP()->helper->get_facets(); |
|
| 151 | - } |
|
| 152 | - $this->facet_data = array(); |
|
| 153 | - $this->az_facets = array( |
|
| 154 | - '' => __( 'Do not show', 'lsx-search' ), |
|
| 155 | - ); |
|
| 156 | - if ( ! empty( $facet_data ) && is_array( $facet_data ) ) { |
|
| 157 | - foreach ( $facet_data as $facet ) { |
|
| 158 | - if ( 'alpha' === $facet['type'] ) { |
|
| 159 | - $this->az_facets[ $facet['name'] ] = $facet['label'] . '(' . $facet['name'] . ')'; |
|
| 160 | - } else { |
|
| 161 | - $this->facet_data[ $facet['name'] ] = $facet['label'] . '(' . $facet['name'] . ')'; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Enqueue JS and CSS. |
|
| 169 | - */ |
|
| 170 | - public function assets( $hook ) { |
|
| 171 | - wp_enqueue_script( 'lsx-search-admin', LSX_SEARCH_URL . 'assets/js/src/lsx-search-admin.js', array( 'jquery' ), LSX_SEARCH_VER, true ); |
|
| 172 | - wp_enqueue_style( 'lsx-search-admin', LSX_SEARCH_URL . 'assets/css/lsx-search-admin.css', array(), LSX_SEARCH_VER ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Enable Business Directory Search settings only if LSX Search plugin is enabled. |
|
| 177 | - * |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public function configure_settings_search_engine_fields( $cmb ) { |
|
| 181 | - $global_args = array( |
|
| 182 | - 'title' => __( 'Global', 'lsx-search' ), |
|
| 183 | - 'desc' => esc_html__( 'Control the filters which show on your WordPress search results page.', 'lsx-search' ), |
|
| 184 | - ); |
|
| 185 | - $this->search_fields( $cmb, 'engine', $global_args ); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Enable Business Directory Search settings only if LSX Search plugin is enabled. |
|
| 190 | - * |
|
| 191 | - * @param object $cmb The CMB2() class. |
|
| 192 | - * @param string $position either top of bottom. |
|
| 193 | - * @return void |
|
| 194 | - */ |
|
| 195 | - public function configure_settings_search_archive_fields( $cmb ) { |
|
| 196 | - $archives = array(); |
|
| 197 | - $post_type_args = array( |
|
| 198 | - 'public' => true, |
|
| 199 | - ); |
|
| 200 | - $post_types = get_post_types( $post_type_args ); |
|
| 201 | - if ( ! empty( $post_types ) ) { |
|
| 202 | - foreach ( $post_types as $post_type_key => $post_type_value ) { |
|
| 203 | - switch ( $post_type_key ) { |
|
| 204 | - case 'post': |
|
| 205 | - $page_url = home_url(); |
|
| 206 | - $page_title = __( 'Home', 'lsx-search' ); |
|
| 207 | - $show_on_front = get_option( 'show_on_front' ); |
|
| 208 | - if ( 'page' === $show_on_front ) { |
|
| 209 | - $page_for_posts = get_option( 'page_for_posts' ); |
|
| 210 | - if ( '' !== $page_for_posts ) { |
|
| 211 | - $page_title = get_the_title( $page_for_posts ); |
|
| 212 | - $page_url = get_permalink( $page_for_posts ); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - $description = sprintf( |
|
| 216 | - /* translators: %s: The subscription info */ |
|
| 217 | - __( 'Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> page.', 'lsx-search' ), |
|
| 218 | - $page_url, |
|
| 219 | - $page_title |
|
| 220 | - ); |
|
| 221 | - $archives[ $post_type_key ] = array( |
|
| 222 | - 'title' => __( 'Blog', 'lsx-search' ), |
|
| 223 | - 'desc' => $description, |
|
| 224 | - ); |
|
| 225 | - break; |
|
| 226 | - |
|
| 227 | - case 'product': |
|
| 228 | - $page_url = home_url(); |
|
| 229 | - $page_title = __( 'Shop', 'lsx-search' ); |
|
| 230 | - if ( function_exists( 'wc_get_page_id' ) ) { |
|
| 231 | - $shop_page = wc_get_page_id( 'shop' ); |
|
| 232 | - $page_url = get_permalink( $shop_page ); |
|
| 233 | - $page_title = get_the_title( $shop_page ); |
|
| 234 | - } |
|
| 235 | - $description = sprintf( |
|
| 236 | - /* translators: %s: The subscription info */ |
|
| 237 | - __( 'Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> page.', 'lsx-search' ), |
|
| 238 | - $page_url, |
|
| 239 | - $page_title |
|
| 240 | - ); |
|
| 241 | - $archives[ $post_type_key ] = array( |
|
| 242 | - 'title' => __( 'Shop', 'lsx-search' ), |
|
| 243 | - 'desc' => $description, |
|
| 244 | - ); |
|
| 245 | - break; |
|
| 246 | - |
|
| 247 | - default: |
|
| 248 | - if ( ! in_array( $post_type_key, \lsx\search\includes\get_restricted_post_types() ) ) { |
|
| 249 | - $temp_post_type = get_post_type_object( $post_type_key ); |
|
| 250 | - if ( ! is_wp_error( $temp_post_type ) ) { |
|
| 251 | - $page_url = get_post_type_archive_link( $temp_post_type->name ); |
|
| 252 | - $description = sprintf( |
|
| 253 | - /* translators: %s: The subscription info */ |
|
| 254 | - __( 'Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> archive.', 'lsx-search' ), |
|
| 255 | - $page_url, |
|
| 256 | - $temp_post_type->label |
|
| 257 | - ); |
|
| 258 | - |
|
| 259 | - $archives[ $post_type_key ] = array( |
|
| 260 | - 'title' => $temp_post_type->label, |
|
| 261 | - 'desc' => $description, |
|
| 262 | - ); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - break; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - if ( ! empty( $archives ) ) { |
|
| 270 | - foreach ( $archives as $archive_key => $archive_args ) { |
|
| 271 | - $this->search_fields( $cmb, $archive_key, $archive_args ); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Enable Business Directory Search settings only if LSX Search plugin is enabled. |
|
| 278 | - * |
|
| 279 | - * @param object $cmb The CMB2() class. |
|
| 280 | - * @param string $section either engine,archive or single. |
|
| 281 | - * @return void |
|
| 282 | - */ |
|
| 283 | - public function search_fields( $cmb, $section, $args ) { |
|
| 284 | - $this->set_facetwp_vars(); |
|
| 285 | - $cmb->add_field( |
|
| 286 | - array( |
|
| 287 | - 'id' => 'settings_' . $section . '_search', |
|
| 288 | - 'type' => 'title', |
|
| 289 | - 'name' => $args['title'], |
|
| 290 | - 'default' => $args['title'], |
|
| 291 | - 'description' => $args['desc'], |
|
| 292 | - ) |
|
| 293 | - ); |
|
| 294 | - do_action( 'lsx_search_settings_section', $cmb, 'top' ); |
|
| 295 | - $cmb->add_field( |
|
| 296 | - array( |
|
| 297 | - 'name' => esc_html__( 'Enable Search Filters', 'lsx-search' ), |
|
| 298 | - 'id' => $section . '_search_enable', |
|
| 299 | - 'description' => esc_html__( 'Display FacetWP filters on your search results page.', 'lsx-search' ), |
|
| 300 | - 'type' => 'checkbox', |
|
| 301 | - ) |
|
| 302 | - ); |
|
| 303 | - |
|
| 304 | - $cmb->add_field( |
|
| 305 | - array( |
|
| 306 | - 'name' => esc_html__( 'Page Layout', 'lsx-search' ), |
|
| 307 | - 'id' => $section . '_search_layout', |
|
| 308 | - 'type' => 'select', |
|
| 309 | - 'options' => array( |
|
| 310 | - '' => esc_html__( 'Follow the theme layout', 'lsx-search' ), |
|
| 311 | - '2cr' => esc_html__( 'Sidebar on left', 'lsx-search' ), |
|
| 312 | - '2cl' => esc_html__( 'Sidebar on right', 'lsx-search' ), |
|
| 313 | - ), |
|
| 314 | - 'default' => '', |
|
| 315 | - ) |
|
| 316 | - ); |
|
| 317 | - |
|
| 318 | - if ( 'product' === $section ) { |
|
| 319 | - $cmb->add_field( |
|
| 320 | - array( |
|
| 321 | - 'name' => esc_html__( 'Results Layout', 'lsx-search' ), |
|
| 322 | - 'id' => $section . '_search_grid_list', |
|
| 323 | - 'type' => 'select', |
|
| 324 | - 'show_option_none' => false, |
|
| 325 | - 'description' => __( 'Set a default layout for the search results.', 'lsx-search' ), |
|
| 326 | - 'options' => array( |
|
| 327 | - 'grid' => esc_html__( 'Grid', 'lsx-search' ), |
|
| 328 | - 'list' => esc_html__( 'List', 'lsx-search' ), |
|
| 329 | - ), |
|
| 330 | - 'default' => 'grid', |
|
| 331 | - ) |
|
| 332 | - ); |
|
| 333 | - $cmb->add_field( |
|
| 334 | - array( |
|
| 335 | - 'name' => esc_html__( 'Layout Switcher', 'lsx-search' ), |
|
| 336 | - 'id' => $section . '_search_layout_switcher_enable', |
|
| 337 | - 'type' => 'checkbox', |
|
| 338 | - 'description' => __( 'Display the layout switcher to allow the user to toggle between the list and grid layouts.', 'lsx-search' ), |
|
| 339 | - ) |
|
| 340 | - ); |
|
| 341 | - } |
|
| 342 | - if ( 'engine' === $section && function_exists('is_plugin_active') && is_plugin_active( 'tour-operator/tour-operator.php' ) ) { |
|
| 343 | - $cmb->add_field( |
|
| 344 | - array( |
|
| 345 | - 'name' => esc_html__( 'List layout images', 'lsx-search' ), |
|
| 346 | - 'id' => $section . '_search_list_layout_image_style', |
|
| 347 | - 'type' => 'select', |
|
| 348 | - 'options' => array( |
|
| 349 | - '' => esc_html__( 'Full Height', 'lsx-search' ), |
|
| 350 | - 'max-height' => esc_html__( 'Max Height', 'lsx-search' ), |
|
| 351 | - ), |
|
| 352 | - 'default' => '', |
|
| 353 | - ) |
|
| 354 | - ); |
|
| 355 | - } |
|
| 356 | - if ( 'engine' === $section ) { |
|
| 357 | - $cmb->add_field( |
|
| 358 | - array( |
|
| 359 | - 'name' => esc_html__( 'Display Excerpt', 'lsx-search' ), |
|
| 360 | - 'id' => $section . '_excerpt_enable', |
|
| 361 | - 'type' => 'checkbox', |
|
| 362 | - 'description' => __( 'Display the excerpt of a listing.', 'lsx-search' ), |
|
| 363 | - ) |
|
| 364 | - ); |
|
| 365 | - $cmb->add_field( |
|
| 366 | - array( |
|
| 367 | - 'name' => esc_html__( 'Enable Post Type Label', 'lsx-search' ), |
|
| 368 | - 'id' => $section . '_search_enable_pt_label', |
|
| 369 | - 'type' => 'checkbox', |
|
| 370 | - 'description' => __( 'This enables the post type label from entries on search results page.', 'lsx-search' ), |
|
| 371 | - ) |
|
| 372 | - ); |
|
| 373 | - if ( function_exists('is_plugin_active') && is_plugin_active( 'tour-operator/tour-operator.php' ) ) { |
|
| 374 | - $cmb->add_field( |
|
| 375 | - array( |
|
| 376 | - 'name' => esc_html__( 'Enable Continent Filter', 'lsx-search' ), |
|
| 377 | - 'id' => $section . '_search_enable_continent_filter', |
|
| 378 | - 'type' => 'checkbox', |
|
| 379 | - 'description' => __( 'This enables the continent filter in FacetWP destinations filter.', 'lsx-search' ), |
|
| 380 | - ) |
|
| 381 | - ); |
|
| 382 | - $cmb->add_field( |
|
| 383 | - array( |
|
| 384 | - 'name' => esc_html__( 'Enable Continental Regions', 'lsx-search' ), |
|
| 385 | - 'id' => $section . '_search_enable_continental_regions', |
|
| 386 | - 'type' => 'checkbox', |
|
| 387 | - 'description' => __( 'This disable continents and enabled the sub regions.', 'lsx-search' ), |
|
| 388 | - ) |
|
| 389 | - ); |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if ( function_exists('is_plugin_active') && is_plugin_active( 'tour-operator/tour-operator.php' ) && 'accommodation' === $section ) { |
|
| 394 | - $cmb->add_field( |
|
| 395 | - array( |
|
| 396 | - 'name' => esc_html__( 'Results Layout - list vs map', 'lsx-search' ), |
|
| 397 | - 'id' => $section . '_search_results_layout', |
|
| 398 | - 'type' => 'select', |
|
| 399 | - 'options' => array( |
|
| 400 | - 'list_map' => esc_html__( 'List and Map', 'lsx-search' ), |
|
| 401 | - 'list' => esc_html__( 'List only', 'lsx-search' ), |
|
| 402 | - ), |
|
| 403 | - 'default' => '', |
|
| 404 | - ) |
|
| 405 | - ); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - $cmb->add_field( |
|
| 409 | - array( |
|
| 410 | - 'name' => esc_html__( 'Enable Collapse', 'lsx-search' ), |
|
| 411 | - 'id' => $section . '_search_collapse', |
|
| 412 | - 'type' => 'checkbox', |
|
| 413 | - 'description' => __( 'Enable collapsible filters on search results.', 'lsx-search' ), |
|
| 414 | - ) |
|
| 415 | - ); |
|
| 416 | - |
|
| 417 | - $cmb->add_field( |
|
| 418 | - array( |
|
| 419 | - 'name' => esc_html__( 'Disable Sorting', 'lsx-search' ), |
|
| 420 | - 'id' => $section . '_search_disable_sorting', |
|
| 421 | - 'type' => 'checkbox', |
|
| 422 | - 'description' => __( 'Toggle the sorting drop down menu on your search results.', 'lsx-search' ), |
|
| 423 | - ) |
|
| 424 | - ); |
|
| 425 | - |
|
| 426 | - $cmb->add_field( |
|
| 427 | - array( |
|
| 428 | - 'name' => esc_html__( 'Disable the Date Sorting Option', 'lsx-search' ), |
|
| 429 | - 'id' => $section . '_search_disable_date', |
|
| 430 | - 'type' => 'checkbox', |
|
| 431 | - ) |
|
| 432 | - ); |
|
| 433 | - |
|
| 434 | - $cmb->add_field( |
|
| 435 | - array( |
|
| 436 | - 'name' => esc_html__( 'Display Clear Button', 'lsx-search' ), |
|
| 437 | - 'id' => $section . '_search_display_clear_button', |
|
| 438 | - 'type' => 'checkbox', |
|
| 439 | - 'description' => __( 'Check this to turn on a button that will clear your search results.', 'lsx-search' ), |
|
| 440 | - ) |
|
| 441 | - ); |
|
| 442 | - |
|
| 443 | - $cmb->add_field( |
|
| 444 | - array( |
|
| 445 | - 'name' => esc_html__( 'Display Result Count', 'lsx-search' ), |
|
| 446 | - 'id' => $section . '_search_display_result_count', |
|
| 447 | - 'type' => 'checkbox', |
|
| 448 | - ) |
|
| 449 | - ); |
|
| 450 | - if ( function_exists('is_plugin_active') && is_plugin_active( 'facetwp-alpha/index.php' ) ) { |
|
| 451 | - $cmb->add_field( |
|
| 452 | - array( |
|
| 453 | - 'name' => esc_html__( 'Alphabet Facet', 'lsx-search' ), |
|
| 454 | - 'description' => esc_html__( 'Select the alphabetical sorter facet.', 'lsx-search' ), |
|
| 455 | - 'id' => $section . '_search_az_pagination', |
|
| 456 | - 'type' => 'select', |
|
| 457 | - 'options' => $this->az_facets, |
|
| 458 | - ) |
|
| 459 | - ); |
|
| 460 | - } |
|
| 461 | - $cmb->add_field( |
|
| 462 | - array( |
|
| 463 | - 'name' => esc_html__( 'Facets', 'lsx-search' ), |
|
| 464 | - 'description' => esc_html__( 'Choose the filters to display in the sidebar. Edit FacetWP filters to change individual filters.', 'lsx-search' ), |
|
| 465 | - 'id' => $section . '_search_facets', |
|
| 466 | - 'type' => 'multicheck', |
|
| 467 | - 'options' => $this->facet_data, |
|
| 468 | - ) |
|
| 469 | - ); |
|
| 470 | - do_action( 'lsx_search_settings_section', $cmb, 'bottom' ); |
|
| 471 | - $cmb->add_field( |
|
| 472 | - array( |
|
| 473 | - 'id' => 'settings_' . $section . '_search_closing', |
|
| 474 | - 'type' => 'tab_closing', |
|
| 475 | - ) |
|
| 476 | - ); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Handle body colours that might be change by LSX Customiser. |
|
| 481 | - */ |
|
| 482 | - public function customizer_body_colours_handler( $css, $colors ) { |
|
| 483 | - $css .= ' |
|
| 15 | + /** |
|
| 16 | + * Holds class instance |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + * |
|
| 20 | + * @var object \lsx\search\classes\Admin() |
|
| 21 | + */ |
|
| 22 | + protected static $instance = null; |
|
| 23 | + /** |
|
| 24 | + * Holds the options for the search. |
|
| 25 | + * |
|
| 26 | + * @var array() |
|
| 27 | + */ |
|
| 28 | + public $options = false; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Holds the facetwp data for use in the fields. |
|
| 32 | + * |
|
| 33 | + * @var array() |
|
| 34 | + */ |
|
| 35 | + public $facet_data = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Holds the Alpha betical facetwp data for use in the fields. |
|
| 39 | + * |
|
| 40 | + * @var array() |
|
| 41 | + */ |
|
| 42 | + public $az_facets = array(); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Holds the settings page theme functions |
|
| 46 | + * |
|
| 47 | + * @var object \lsx\search\classes\admin\Settings_Theme(); |
|
| 48 | + */ |
|
| 49 | + public $settings_theme; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Construct method. |
|
| 53 | + */ |
|
| 54 | + public function __construct() { |
|
| 55 | + $this->load_classes(); |
|
| 56 | + add_action( 'cmb2_admin_init', array( $this, 'register_settings_page' ) ); |
|
| 57 | + add_action( 'lsx_search_settings_page', array( $this, 'configure_settings_search_engine_fields' ), 15, 1 ); |
|
| 58 | + add_action( 'lsx_search_settings_page', array( $this, 'configure_settings_search_archive_fields' ), 15, 1 ); |
|
| 59 | + add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
| 60 | + |
|
| 61 | + if ( is_admin() ) { |
|
| 62 | + add_filter( 'lsx_customizer_colour_selectors_body', array( $this, 'customizer_body_colours_handler' ), 15, 2 ); |
|
| 63 | + add_filter( 'lsx_customizer_colour_selectors_button', array( $this, 'customizer_button_colours' ), 10, 2 ); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Return an instance of this class. |
|
| 69 | + * |
|
| 70 | + * @since 1.0.0 |
|
| 71 | + * |
|
| 72 | + * @return object \lsx\member_directory\search\Admin() A single instance of this class. |
|
| 73 | + */ |
|
| 74 | + public static function get_instance() { |
|
| 75 | + // If the single instance hasn't been set, set it now. |
|
| 76 | + if ( null === self::$instance ) { |
|
| 77 | + self::$instance = new self(); |
|
| 78 | + } |
|
| 79 | + return self::$instance; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Loads the variable classes and the static classes. |
|
| 84 | + */ |
|
| 85 | + private function load_classes() { |
|
| 86 | + require_once LSX_SEARCH_PATH . 'classes/admin/class-settings-theme.php'; |
|
| 87 | + $this->settings_theme = admin\Settings_Theme::get_instance(); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Configure Business Directory custom fields for the Settings page. |
|
| 92 | + * |
|
| 93 | + * @return void |
|
| 94 | + */ |
|
| 95 | + public function register_settings_page() { |
|
| 96 | + $args = array( |
|
| 97 | + 'id' => 'lsx_search_settings', |
|
| 98 | + 'title' => '<h1>' . esc_html__( 'LSX Search Settings', 'lsx-search' ) . ' <span class="version">' . LSX_SEARCH_VER . '</span></h1>', |
|
| 99 | + 'menu_title' => esc_html__( 'LSX Search', 'search' ), // Falls back to 'title' (above). |
|
| 100 | + 'object_types' => array( 'options-page' ), |
|
| 101 | + 'option_key' => 'lsx-search-settings', // The option key and admin menu page slug. |
|
| 102 | + 'parent_slug' => 'options-general.php', |
|
| 103 | + 'capability' => 'manage_options', // Cap required to view options-page. |
|
| 104 | + ); |
|
| 105 | + $cmb = new_cmb2_box( $args ); |
|
| 106 | + do_action( 'lsx_search_settings_page', $cmb ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Sets post types with active search options. |
|
| 111 | + */ |
|
| 112 | + public function register_post_type_tabs( $post_types_plural ) { |
|
| 113 | + $post_types_plural = array( |
|
| 114 | + 'project' => 'projects', |
|
| 115 | + 'service' => 'services', |
|
| 116 | + 'team' => 'team', |
|
| 117 | + 'testimonial' => 'testimonials', |
|
| 118 | + 'video' => 'videos', |
|
| 119 | + 'product' => 'products', // WooCommerce |
|
| 120 | + 'post' => 'posts', |
|
| 121 | + ); |
|
| 122 | + return $post_types_plural; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Gets the Tour Operator Post Types. |
|
| 127 | + * |
|
| 128 | + * @return array |
|
| 129 | + */ |
|
| 130 | + public function get_to_post_types() { |
|
| 131 | + $to_types = array( |
|
| 132 | + 'accommodation', |
|
| 133 | + 'tour', |
|
| 134 | + 'destination', |
|
| 135 | + 'review', |
|
| 136 | + 'activity', |
|
| 137 | + 'special', |
|
| 138 | + 'vehicle', |
|
| 139 | + ); |
|
| 140 | + return $to_types; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Sets the FacetWP variables. |
|
| 145 | + * |
|
| 146 | + * @return void |
|
| 147 | + */ |
|
| 148 | + public function set_facetwp_vars() { |
|
| 149 | + if ( function_exists( '\FWP' ) ) { |
|
| 150 | + $facet_data = \FWP()->helper->get_facets(); |
|
| 151 | + } |
|
| 152 | + $this->facet_data = array(); |
|
| 153 | + $this->az_facets = array( |
|
| 154 | + '' => __( 'Do not show', 'lsx-search' ), |
|
| 155 | + ); |
|
| 156 | + if ( ! empty( $facet_data ) && is_array( $facet_data ) ) { |
|
| 157 | + foreach ( $facet_data as $facet ) { |
|
| 158 | + if ( 'alpha' === $facet['type'] ) { |
|
| 159 | + $this->az_facets[ $facet['name'] ] = $facet['label'] . '(' . $facet['name'] . ')'; |
|
| 160 | + } else { |
|
| 161 | + $this->facet_data[ $facet['name'] ] = $facet['label'] . '(' . $facet['name'] . ')'; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Enqueue JS and CSS. |
|
| 169 | + */ |
|
| 170 | + public function assets( $hook ) { |
|
| 171 | + wp_enqueue_script( 'lsx-search-admin', LSX_SEARCH_URL . 'assets/js/src/lsx-search-admin.js', array( 'jquery' ), LSX_SEARCH_VER, true ); |
|
| 172 | + wp_enqueue_style( 'lsx-search-admin', LSX_SEARCH_URL . 'assets/css/lsx-search-admin.css', array(), LSX_SEARCH_VER ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Enable Business Directory Search settings only if LSX Search plugin is enabled. |
|
| 177 | + * |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public function configure_settings_search_engine_fields( $cmb ) { |
|
| 181 | + $global_args = array( |
|
| 182 | + 'title' => __( 'Global', 'lsx-search' ), |
|
| 183 | + 'desc' => esc_html__( 'Control the filters which show on your WordPress search results page.', 'lsx-search' ), |
|
| 184 | + ); |
|
| 185 | + $this->search_fields( $cmb, 'engine', $global_args ); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Enable Business Directory Search settings only if LSX Search plugin is enabled. |
|
| 190 | + * |
|
| 191 | + * @param object $cmb The CMB2() class. |
|
| 192 | + * @param string $position either top of bottom. |
|
| 193 | + * @return void |
|
| 194 | + */ |
|
| 195 | + public function configure_settings_search_archive_fields( $cmb ) { |
|
| 196 | + $archives = array(); |
|
| 197 | + $post_type_args = array( |
|
| 198 | + 'public' => true, |
|
| 199 | + ); |
|
| 200 | + $post_types = get_post_types( $post_type_args ); |
|
| 201 | + if ( ! empty( $post_types ) ) { |
|
| 202 | + foreach ( $post_types as $post_type_key => $post_type_value ) { |
|
| 203 | + switch ( $post_type_key ) { |
|
| 204 | + case 'post': |
|
| 205 | + $page_url = home_url(); |
|
| 206 | + $page_title = __( 'Home', 'lsx-search' ); |
|
| 207 | + $show_on_front = get_option( 'show_on_front' ); |
|
| 208 | + if ( 'page' === $show_on_front ) { |
|
| 209 | + $page_for_posts = get_option( 'page_for_posts' ); |
|
| 210 | + if ( '' !== $page_for_posts ) { |
|
| 211 | + $page_title = get_the_title( $page_for_posts ); |
|
| 212 | + $page_url = get_permalink( $page_for_posts ); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + $description = sprintf( |
|
| 216 | + /* translators: %s: The subscription info */ |
|
| 217 | + __( 'Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> page.', 'lsx-search' ), |
|
| 218 | + $page_url, |
|
| 219 | + $page_title |
|
| 220 | + ); |
|
| 221 | + $archives[ $post_type_key ] = array( |
|
| 222 | + 'title' => __( 'Blog', 'lsx-search' ), |
|
| 223 | + 'desc' => $description, |
|
| 224 | + ); |
|
| 225 | + break; |
|
| 226 | + |
|
| 227 | + case 'product': |
|
| 228 | + $page_url = home_url(); |
|
| 229 | + $page_title = __( 'Shop', 'lsx-search' ); |
|
| 230 | + if ( function_exists( 'wc_get_page_id' ) ) { |
|
| 231 | + $shop_page = wc_get_page_id( 'shop' ); |
|
| 232 | + $page_url = get_permalink( $shop_page ); |
|
| 233 | + $page_title = get_the_title( $shop_page ); |
|
| 234 | + } |
|
| 235 | + $description = sprintf( |
|
| 236 | + /* translators: %s: The subscription info */ |
|
| 237 | + __( 'Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> page.', 'lsx-search' ), |
|
| 238 | + $page_url, |
|
| 239 | + $page_title |
|
| 240 | + ); |
|
| 241 | + $archives[ $post_type_key ] = array( |
|
| 242 | + 'title' => __( 'Shop', 'lsx-search' ), |
|
| 243 | + 'desc' => $description, |
|
| 244 | + ); |
|
| 245 | + break; |
|
| 246 | + |
|
| 247 | + default: |
|
| 248 | + if ( ! in_array( $post_type_key, \lsx\search\includes\get_restricted_post_types() ) ) { |
|
| 249 | + $temp_post_type = get_post_type_object( $post_type_key ); |
|
| 250 | + if ( ! is_wp_error( $temp_post_type ) ) { |
|
| 251 | + $page_url = get_post_type_archive_link( $temp_post_type->name ); |
|
| 252 | + $description = sprintf( |
|
| 253 | + /* translators: %s: The subscription info */ |
|
| 254 | + __( 'Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> archive.', 'lsx-search' ), |
|
| 255 | + $page_url, |
|
| 256 | + $temp_post_type->label |
|
| 257 | + ); |
|
| 258 | + |
|
| 259 | + $archives[ $post_type_key ] = array( |
|
| 260 | + 'title' => $temp_post_type->label, |
|
| 261 | + 'desc' => $description, |
|
| 262 | + ); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + break; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + if ( ! empty( $archives ) ) { |
|
| 270 | + foreach ( $archives as $archive_key => $archive_args ) { |
|
| 271 | + $this->search_fields( $cmb, $archive_key, $archive_args ); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Enable Business Directory Search settings only if LSX Search plugin is enabled. |
|
| 278 | + * |
|
| 279 | + * @param object $cmb The CMB2() class. |
|
| 280 | + * @param string $section either engine,archive or single. |
|
| 281 | + * @return void |
|
| 282 | + */ |
|
| 283 | + public function search_fields( $cmb, $section, $args ) { |
|
| 284 | + $this->set_facetwp_vars(); |
|
| 285 | + $cmb->add_field( |
|
| 286 | + array( |
|
| 287 | + 'id' => 'settings_' . $section . '_search', |
|
| 288 | + 'type' => 'title', |
|
| 289 | + 'name' => $args['title'], |
|
| 290 | + 'default' => $args['title'], |
|
| 291 | + 'description' => $args['desc'], |
|
| 292 | + ) |
|
| 293 | + ); |
|
| 294 | + do_action( 'lsx_search_settings_section', $cmb, 'top' ); |
|
| 295 | + $cmb->add_field( |
|
| 296 | + array( |
|
| 297 | + 'name' => esc_html__( 'Enable Search Filters', 'lsx-search' ), |
|
| 298 | + 'id' => $section . '_search_enable', |
|
| 299 | + 'description' => esc_html__( 'Display FacetWP filters on your search results page.', 'lsx-search' ), |
|
| 300 | + 'type' => 'checkbox', |
|
| 301 | + ) |
|
| 302 | + ); |
|
| 303 | + |
|
| 304 | + $cmb->add_field( |
|
| 305 | + array( |
|
| 306 | + 'name' => esc_html__( 'Page Layout', 'lsx-search' ), |
|
| 307 | + 'id' => $section . '_search_layout', |
|
| 308 | + 'type' => 'select', |
|
| 309 | + 'options' => array( |
|
| 310 | + '' => esc_html__( 'Follow the theme layout', 'lsx-search' ), |
|
| 311 | + '2cr' => esc_html__( 'Sidebar on left', 'lsx-search' ), |
|
| 312 | + '2cl' => esc_html__( 'Sidebar on right', 'lsx-search' ), |
|
| 313 | + ), |
|
| 314 | + 'default' => '', |
|
| 315 | + ) |
|
| 316 | + ); |
|
| 317 | + |
|
| 318 | + if ( 'product' === $section ) { |
|
| 319 | + $cmb->add_field( |
|
| 320 | + array( |
|
| 321 | + 'name' => esc_html__( 'Results Layout', 'lsx-search' ), |
|
| 322 | + 'id' => $section . '_search_grid_list', |
|
| 323 | + 'type' => 'select', |
|
| 324 | + 'show_option_none' => false, |
|
| 325 | + 'description' => __( 'Set a default layout for the search results.', 'lsx-search' ), |
|
| 326 | + 'options' => array( |
|
| 327 | + 'grid' => esc_html__( 'Grid', 'lsx-search' ), |
|
| 328 | + 'list' => esc_html__( 'List', 'lsx-search' ), |
|
| 329 | + ), |
|
| 330 | + 'default' => 'grid', |
|
| 331 | + ) |
|
| 332 | + ); |
|
| 333 | + $cmb->add_field( |
|
| 334 | + array( |
|
| 335 | + 'name' => esc_html__( 'Layout Switcher', 'lsx-search' ), |
|
| 336 | + 'id' => $section . '_search_layout_switcher_enable', |
|
| 337 | + 'type' => 'checkbox', |
|
| 338 | + 'description' => __( 'Display the layout switcher to allow the user to toggle between the list and grid layouts.', 'lsx-search' ), |
|
| 339 | + ) |
|
| 340 | + ); |
|
| 341 | + } |
|
| 342 | + if ( 'engine' === $section && function_exists('is_plugin_active') && is_plugin_active( 'tour-operator/tour-operator.php' ) ) { |
|
| 343 | + $cmb->add_field( |
|
| 344 | + array( |
|
| 345 | + 'name' => esc_html__( 'List layout images', 'lsx-search' ), |
|
| 346 | + 'id' => $section . '_search_list_layout_image_style', |
|
| 347 | + 'type' => 'select', |
|
| 348 | + 'options' => array( |
|
| 349 | + '' => esc_html__( 'Full Height', 'lsx-search' ), |
|
| 350 | + 'max-height' => esc_html__( 'Max Height', 'lsx-search' ), |
|
| 351 | + ), |
|
| 352 | + 'default' => '', |
|
| 353 | + ) |
|
| 354 | + ); |
|
| 355 | + } |
|
| 356 | + if ( 'engine' === $section ) { |
|
| 357 | + $cmb->add_field( |
|
| 358 | + array( |
|
| 359 | + 'name' => esc_html__( 'Display Excerpt', 'lsx-search' ), |
|
| 360 | + 'id' => $section . '_excerpt_enable', |
|
| 361 | + 'type' => 'checkbox', |
|
| 362 | + 'description' => __( 'Display the excerpt of a listing.', 'lsx-search' ), |
|
| 363 | + ) |
|
| 364 | + ); |
|
| 365 | + $cmb->add_field( |
|
| 366 | + array( |
|
| 367 | + 'name' => esc_html__( 'Enable Post Type Label', 'lsx-search' ), |
|
| 368 | + 'id' => $section . '_search_enable_pt_label', |
|
| 369 | + 'type' => 'checkbox', |
|
| 370 | + 'description' => __( 'This enables the post type label from entries on search results page.', 'lsx-search' ), |
|
| 371 | + ) |
|
| 372 | + ); |
|
| 373 | + if ( function_exists('is_plugin_active') && is_plugin_active( 'tour-operator/tour-operator.php' ) ) { |
|
| 374 | + $cmb->add_field( |
|
| 375 | + array( |
|
| 376 | + 'name' => esc_html__( 'Enable Continent Filter', 'lsx-search' ), |
|
| 377 | + 'id' => $section . '_search_enable_continent_filter', |
|
| 378 | + 'type' => 'checkbox', |
|
| 379 | + 'description' => __( 'This enables the continent filter in FacetWP destinations filter.', 'lsx-search' ), |
|
| 380 | + ) |
|
| 381 | + ); |
|
| 382 | + $cmb->add_field( |
|
| 383 | + array( |
|
| 384 | + 'name' => esc_html__( 'Enable Continental Regions', 'lsx-search' ), |
|
| 385 | + 'id' => $section . '_search_enable_continental_regions', |
|
| 386 | + 'type' => 'checkbox', |
|
| 387 | + 'description' => __( 'This disable continents and enabled the sub regions.', 'lsx-search' ), |
|
| 388 | + ) |
|
| 389 | + ); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if ( function_exists('is_plugin_active') && is_plugin_active( 'tour-operator/tour-operator.php' ) && 'accommodation' === $section ) { |
|
| 394 | + $cmb->add_field( |
|
| 395 | + array( |
|
| 396 | + 'name' => esc_html__( 'Results Layout - list vs map', 'lsx-search' ), |
|
| 397 | + 'id' => $section . '_search_results_layout', |
|
| 398 | + 'type' => 'select', |
|
| 399 | + 'options' => array( |
|
| 400 | + 'list_map' => esc_html__( 'List and Map', 'lsx-search' ), |
|
| 401 | + 'list' => esc_html__( 'List only', 'lsx-search' ), |
|
| 402 | + ), |
|
| 403 | + 'default' => '', |
|
| 404 | + ) |
|
| 405 | + ); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + $cmb->add_field( |
|
| 409 | + array( |
|
| 410 | + 'name' => esc_html__( 'Enable Collapse', 'lsx-search' ), |
|
| 411 | + 'id' => $section . '_search_collapse', |
|
| 412 | + 'type' => 'checkbox', |
|
| 413 | + 'description' => __( 'Enable collapsible filters on search results.', 'lsx-search' ), |
|
| 414 | + ) |
|
| 415 | + ); |
|
| 416 | + |
|
| 417 | + $cmb->add_field( |
|
| 418 | + array( |
|
| 419 | + 'name' => esc_html__( 'Disable Sorting', 'lsx-search' ), |
|
| 420 | + 'id' => $section . '_search_disable_sorting', |
|
| 421 | + 'type' => 'checkbox', |
|
| 422 | + 'description' => __( 'Toggle the sorting drop down menu on your search results.', 'lsx-search' ), |
|
| 423 | + ) |
|
| 424 | + ); |
|
| 425 | + |
|
| 426 | + $cmb->add_field( |
|
| 427 | + array( |
|
| 428 | + 'name' => esc_html__( 'Disable the Date Sorting Option', 'lsx-search' ), |
|
| 429 | + 'id' => $section . '_search_disable_date', |
|
| 430 | + 'type' => 'checkbox', |
|
| 431 | + ) |
|
| 432 | + ); |
|
| 433 | + |
|
| 434 | + $cmb->add_field( |
|
| 435 | + array( |
|
| 436 | + 'name' => esc_html__( 'Display Clear Button', 'lsx-search' ), |
|
| 437 | + 'id' => $section . '_search_display_clear_button', |
|
| 438 | + 'type' => 'checkbox', |
|
| 439 | + 'description' => __( 'Check this to turn on a button that will clear your search results.', 'lsx-search' ), |
|
| 440 | + ) |
|
| 441 | + ); |
|
| 442 | + |
|
| 443 | + $cmb->add_field( |
|
| 444 | + array( |
|
| 445 | + 'name' => esc_html__( 'Display Result Count', 'lsx-search' ), |
|
| 446 | + 'id' => $section . '_search_display_result_count', |
|
| 447 | + 'type' => 'checkbox', |
|
| 448 | + ) |
|
| 449 | + ); |
|
| 450 | + if ( function_exists('is_plugin_active') && is_plugin_active( 'facetwp-alpha/index.php' ) ) { |
|
| 451 | + $cmb->add_field( |
|
| 452 | + array( |
|
| 453 | + 'name' => esc_html__( 'Alphabet Facet', 'lsx-search' ), |
|
| 454 | + 'description' => esc_html__( 'Select the alphabetical sorter facet.', 'lsx-search' ), |
|
| 455 | + 'id' => $section . '_search_az_pagination', |
|
| 456 | + 'type' => 'select', |
|
| 457 | + 'options' => $this->az_facets, |
|
| 458 | + ) |
|
| 459 | + ); |
|
| 460 | + } |
|
| 461 | + $cmb->add_field( |
|
| 462 | + array( |
|
| 463 | + 'name' => esc_html__( 'Facets', 'lsx-search' ), |
|
| 464 | + 'description' => esc_html__( 'Choose the filters to display in the sidebar. Edit FacetWP filters to change individual filters.', 'lsx-search' ), |
|
| 465 | + 'id' => $section . '_search_facets', |
|
| 466 | + 'type' => 'multicheck', |
|
| 467 | + 'options' => $this->facet_data, |
|
| 468 | + ) |
|
| 469 | + ); |
|
| 470 | + do_action( 'lsx_search_settings_section', $cmb, 'bottom' ); |
|
| 471 | + $cmb->add_field( |
|
| 472 | + array( |
|
| 473 | + 'id' => 'settings_' . $section . '_search_closing', |
|
| 474 | + 'type' => 'tab_closing', |
|
| 475 | + ) |
|
| 476 | + ); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Handle body colours that might be change by LSX Customiser. |
|
| 481 | + */ |
|
| 482 | + public function customizer_body_colours_handler( $css, $colors ) { |
|
| 483 | + $css .= ' |
|
| 484 | 484 | @import "' . LSX_SEARCH_PATH . '/assets/css/scss/customizer-search-body-colours"; |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -496,18 +496,18 @@ discard block |
||
| 496 | 496 | ); |
| 497 | 497 | '; |
| 498 | 498 | |
| 499 | - return $css; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Adds the lsx search buttons to the customizer plugin. |
|
| 504 | - * |
|
| 505 | - * @param string $css |
|
| 506 | - * @param array $colours |
|
| 507 | - * @return string |
|
| 508 | - */ |
|
| 509 | - public function customizer_button_colours( $css, $colours ) { |
|
| 510 | - $css .= ' |
|
| 499 | + return $css; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Adds the lsx search buttons to the customizer plugin. |
|
| 504 | + * |
|
| 505 | + * @param string $css |
|
| 506 | + * @param array $colours |
|
| 507 | + * @return string |
|
| 508 | + */ |
|
| 509 | + public function customizer_button_colours( $css, $colours ) { |
|
| 510 | + $css .= ' |
|
| 511 | 511 | #secondary.facetwp-sidebar { |
| 512 | 512 | .facetwp-item.facetwp-form { |
| 513 | 513 | .search-form { |
@@ -520,6 +520,6 @@ discard block |
||
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | '; |
| 523 | - return $css; |
|
| 524 | - } |
|
| 523 | + return $css; |
|
| 524 | + } |
|
| 525 | 525 | } |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function __construct() { |
| 55 | 55 | $this->load_classes(); |
| 56 | - add_action( 'cmb2_admin_init', array( $this, 'register_settings_page' ) ); |
|
| 57 | - add_action( 'lsx_search_settings_page', array( $this, 'configure_settings_search_engine_fields' ), 15, 1 ); |
|
| 58 | - add_action( 'lsx_search_settings_page', array( $this, 'configure_settings_search_archive_fields' ), 15, 1 ); |
|
| 59 | - add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
| 60 | - |
|
| 61 | - if ( is_admin() ) { |
|
| 62 | - add_filter( 'lsx_customizer_colour_selectors_body', array( $this, 'customizer_body_colours_handler' ), 15, 2 ); |
|
| 63 | - add_filter( 'lsx_customizer_colour_selectors_button', array( $this, 'customizer_button_colours' ), 10, 2 ); |
|
| 56 | + add_action('cmb2_admin_init', array($this, 'register_settings_page')); |
|
| 57 | + add_action('lsx_search_settings_page', array($this, 'configure_settings_search_engine_fields'), 15, 1); |
|
| 58 | + add_action('lsx_search_settings_page', array($this, 'configure_settings_search_archive_fields'), 15, 1); |
|
| 59 | + add_action('admin_enqueue_scripts', array($this, 'assets')); |
|
| 60 | + |
|
| 61 | + if (is_admin()) { |
|
| 62 | + add_filter('lsx_customizer_colour_selectors_body', array($this, 'customizer_body_colours_handler'), 15, 2); |
|
| 63 | + add_filter('lsx_customizer_colour_selectors_button', array($this, 'customizer_button_colours'), 10, 2); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public static function get_instance() { |
| 75 | 75 | // If the single instance hasn't been set, set it now. |
| 76 | - if ( null === self::$instance ) { |
|
| 76 | + if (null === self::$instance) { |
|
| 77 | 77 | self::$instance = new self(); |
| 78 | 78 | } |
| 79 | 79 | return self::$instance; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * Loads the variable classes and the static classes. |
| 84 | 84 | */ |
| 85 | 85 | private function load_classes() { |
| 86 | - require_once LSX_SEARCH_PATH . 'classes/admin/class-settings-theme.php'; |
|
| 86 | + require_once LSX_SEARCH_PATH.'classes/admin/class-settings-theme.php'; |
|
| 87 | 87 | $this->settings_theme = admin\Settings_Theme::get_instance(); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -95,21 +95,21 @@ discard block |
||
| 95 | 95 | public function register_settings_page() { |
| 96 | 96 | $args = array( |
| 97 | 97 | 'id' => 'lsx_search_settings', |
| 98 | - 'title' => '<h1>' . esc_html__( 'LSX Search Settings', 'lsx-search' ) . ' <span class="version">' . LSX_SEARCH_VER . '</span></h1>', |
|
| 99 | - 'menu_title' => esc_html__( 'LSX Search', 'search' ), // Falls back to 'title' (above). |
|
| 100 | - 'object_types' => array( 'options-page' ), |
|
| 98 | + 'title' => '<h1>'.esc_html__('LSX Search Settings', 'lsx-search').' <span class="version">'.LSX_SEARCH_VER.'</span></h1>', |
|
| 99 | + 'menu_title' => esc_html__('LSX Search', 'search'), // Falls back to 'title' (above). |
|
| 100 | + 'object_types' => array('options-page'), |
|
| 101 | 101 | 'option_key' => 'lsx-search-settings', // The option key and admin menu page slug. |
| 102 | 102 | 'parent_slug' => 'options-general.php', |
| 103 | 103 | 'capability' => 'manage_options', // Cap required to view options-page. |
| 104 | 104 | ); |
| 105 | - $cmb = new_cmb2_box( $args ); |
|
| 106 | - do_action( 'lsx_search_settings_page', $cmb ); |
|
| 105 | + $cmb = new_cmb2_box($args); |
|
| 106 | + do_action('lsx_search_settings_page', $cmb); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * Sets post types with active search options. |
| 111 | 111 | */ |
| 112 | - public function register_post_type_tabs( $post_types_plural ) { |
|
| 112 | + public function register_post_type_tabs($post_types_plural) { |
|
| 113 | 113 | $post_types_plural = array( |
| 114 | 114 | 'project' => 'projects', |
| 115 | 115 | 'service' => 'services', |
@@ -146,19 +146,19 @@ discard block |
||
| 146 | 146 | * @return void |
| 147 | 147 | */ |
| 148 | 148 | public function set_facetwp_vars() { |
| 149 | - if ( function_exists( '\FWP' ) ) { |
|
| 149 | + if (function_exists('\FWP')) { |
|
| 150 | 150 | $facet_data = \FWP()->helper->get_facets(); |
| 151 | 151 | } |
| 152 | 152 | $this->facet_data = array(); |
| 153 | 153 | $this->az_facets = array( |
| 154 | - '' => __( 'Do not show', 'lsx-search' ), |
|
| 154 | + '' => __('Do not show', 'lsx-search'), |
|
| 155 | 155 | ); |
| 156 | - if ( ! empty( $facet_data ) && is_array( $facet_data ) ) { |
|
| 157 | - foreach ( $facet_data as $facet ) { |
|
| 158 | - if ( 'alpha' === $facet['type'] ) { |
|
| 159 | - $this->az_facets[ $facet['name'] ] = $facet['label'] . '(' . $facet['name'] . ')'; |
|
| 156 | + if (!empty($facet_data) && is_array($facet_data)) { |
|
| 157 | + foreach ($facet_data as $facet) { |
|
| 158 | + if ('alpha' === $facet['type']) { |
|
| 159 | + $this->az_facets[$facet['name']] = $facet['label'].'('.$facet['name'].')'; |
|
| 160 | 160 | } else { |
| 161 | - $this->facet_data[ $facet['name'] ] = $facet['label'] . '(' . $facet['name'] . ')'; |
|
| 161 | + $this->facet_data[$facet['name']] = $facet['label'].'('.$facet['name'].')'; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | } |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | /** |
| 168 | 168 | * Enqueue JS and CSS. |
| 169 | 169 | */ |
| 170 | - public function assets( $hook ) { |
|
| 171 | - wp_enqueue_script( 'lsx-search-admin', LSX_SEARCH_URL . 'assets/js/src/lsx-search-admin.js', array( 'jquery' ), LSX_SEARCH_VER, true ); |
|
| 172 | - wp_enqueue_style( 'lsx-search-admin', LSX_SEARCH_URL . 'assets/css/lsx-search-admin.css', array(), LSX_SEARCH_VER ); |
|
| 170 | + public function assets($hook) { |
|
| 171 | + wp_enqueue_script('lsx-search-admin', LSX_SEARCH_URL.'assets/js/src/lsx-search-admin.js', array('jquery'), LSX_SEARCH_VER, true); |
|
| 172 | + wp_enqueue_style('lsx-search-admin', LSX_SEARCH_URL.'assets/css/lsx-search-admin.css', array(), LSX_SEARCH_VER); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -177,12 +177,12 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return void |
| 179 | 179 | */ |
| 180 | - public function configure_settings_search_engine_fields( $cmb ) { |
|
| 180 | + public function configure_settings_search_engine_fields($cmb) { |
|
| 181 | 181 | $global_args = array( |
| 182 | - 'title' => __( 'Global', 'lsx-search' ), |
|
| 183 | - 'desc' => esc_html__( 'Control the filters which show on your WordPress search results page.', 'lsx-search' ), |
|
| 182 | + 'title' => __('Global', 'lsx-search'), |
|
| 183 | + 'desc' => esc_html__('Control the filters which show on your WordPress search results page.', 'lsx-search'), |
|
| 184 | 184 | ); |
| 185 | - $this->search_fields( $cmb, 'engine', $global_args ); |
|
| 185 | + $this->search_fields($cmb, 'engine', $global_args); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -192,71 +192,71 @@ discard block |
||
| 192 | 192 | * @param string $position either top of bottom. |
| 193 | 193 | * @return void |
| 194 | 194 | */ |
| 195 | - public function configure_settings_search_archive_fields( $cmb ) { |
|
| 195 | + public function configure_settings_search_archive_fields($cmb) { |
|
| 196 | 196 | $archives = array(); |
| 197 | 197 | $post_type_args = array( |
| 198 | 198 | 'public' => true, |
| 199 | 199 | ); |
| 200 | - $post_types = get_post_types( $post_type_args ); |
|
| 201 | - if ( ! empty( $post_types ) ) { |
|
| 202 | - foreach ( $post_types as $post_type_key => $post_type_value ) { |
|
| 203 | - switch ( $post_type_key ) { |
|
| 200 | + $post_types = get_post_types($post_type_args); |
|
| 201 | + if (!empty($post_types)) { |
|
| 202 | + foreach ($post_types as $post_type_key => $post_type_value) { |
|
| 203 | + switch ($post_type_key) { |
|
| 204 | 204 | case 'post': |
| 205 | 205 | $page_url = home_url(); |
| 206 | - $page_title = __( 'Home', 'lsx-search' ); |
|
| 207 | - $show_on_front = get_option( 'show_on_front' ); |
|
| 208 | - if ( 'page' === $show_on_front ) { |
|
| 209 | - $page_for_posts = get_option( 'page_for_posts' ); |
|
| 210 | - if ( '' !== $page_for_posts ) { |
|
| 211 | - $page_title = get_the_title( $page_for_posts ); |
|
| 212 | - $page_url = get_permalink( $page_for_posts ); |
|
| 206 | + $page_title = __('Home', 'lsx-search'); |
|
| 207 | + $show_on_front = get_option('show_on_front'); |
|
| 208 | + if ('page' === $show_on_front) { |
|
| 209 | + $page_for_posts = get_option('page_for_posts'); |
|
| 210 | + if ('' !== $page_for_posts) { |
|
| 211 | + $page_title = get_the_title($page_for_posts); |
|
| 212 | + $page_url = get_permalink($page_for_posts); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | $description = sprintf( |
| 216 | 216 | /* translators: %s: The subscription info */ |
| 217 | - __( 'Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> page.', 'lsx-search' ), |
|
| 217 | + __('Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> page.', 'lsx-search'), |
|
| 218 | 218 | $page_url, |
| 219 | 219 | $page_title |
| 220 | 220 | ); |
| 221 | - $archives[ $post_type_key ] = array( |
|
| 222 | - 'title' => __( 'Blog', 'lsx-search' ), |
|
| 221 | + $archives[$post_type_key] = array( |
|
| 222 | + 'title' => __('Blog', 'lsx-search'), |
|
| 223 | 223 | 'desc' => $description, |
| 224 | 224 | ); |
| 225 | 225 | break; |
| 226 | 226 | |
| 227 | 227 | case 'product': |
| 228 | 228 | $page_url = home_url(); |
| 229 | - $page_title = __( 'Shop', 'lsx-search' ); |
|
| 230 | - if ( function_exists( 'wc_get_page_id' ) ) { |
|
| 231 | - $shop_page = wc_get_page_id( 'shop' ); |
|
| 232 | - $page_url = get_permalink( $shop_page ); |
|
| 233 | - $page_title = get_the_title( $shop_page ); |
|
| 229 | + $page_title = __('Shop', 'lsx-search'); |
|
| 230 | + if (function_exists('wc_get_page_id')) { |
|
| 231 | + $shop_page = wc_get_page_id('shop'); |
|
| 232 | + $page_url = get_permalink($shop_page); |
|
| 233 | + $page_title = get_the_title($shop_page); |
|
| 234 | 234 | } |
| 235 | 235 | $description = sprintf( |
| 236 | 236 | /* translators: %s: The subscription info */ |
| 237 | - __( 'Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> page.', 'lsx-search' ), |
|
| 237 | + __('Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> page.', 'lsx-search'), |
|
| 238 | 238 | $page_url, |
| 239 | 239 | $page_title |
| 240 | 240 | ); |
| 241 | - $archives[ $post_type_key ] = array( |
|
| 242 | - 'title' => __( 'Shop', 'lsx-search' ), |
|
| 241 | + $archives[$post_type_key] = array( |
|
| 242 | + 'title' => __('Shop', 'lsx-search'), |
|
| 243 | 243 | 'desc' => $description, |
| 244 | 244 | ); |
| 245 | 245 | break; |
| 246 | 246 | |
| 247 | 247 | default: |
| 248 | - if ( ! in_array( $post_type_key, \lsx\search\includes\get_restricted_post_types() ) ) { |
|
| 249 | - $temp_post_type = get_post_type_object( $post_type_key ); |
|
| 250 | - if ( ! is_wp_error( $temp_post_type ) ) { |
|
| 251 | - $page_url = get_post_type_archive_link( $temp_post_type->name ); |
|
| 248 | + if (!in_array($post_type_key, \lsx\search\includes\get_restricted_post_types())) { |
|
| 249 | + $temp_post_type = get_post_type_object($post_type_key); |
|
| 250 | + if (!is_wp_error($temp_post_type)) { |
|
| 251 | + $page_url = get_post_type_archive_link($temp_post_type->name); |
|
| 252 | 252 | $description = sprintf( |
| 253 | 253 | /* translators: %s: The subscription info */ |
| 254 | - __( 'Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> archive.', 'lsx-search' ), |
|
| 254 | + __('Control the filters which show on your <a target="_blank" href="%1$s">%2$s</a> archive.', 'lsx-search'), |
|
| 255 | 255 | $page_url, |
| 256 | 256 | $temp_post_type->label |
| 257 | 257 | ); |
| 258 | 258 | |
| 259 | - $archives[ $post_type_key ] = array( |
|
| 259 | + $archives[$post_type_key] = array( |
|
| 260 | 260 | 'title' => $temp_post_type->label, |
| 261 | 261 | 'desc' => $description, |
| 262 | 262 | ); |
@@ -266,9 +266,9 @@ discard block |
||
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | - if ( ! empty( $archives ) ) { |
|
| 270 | - foreach ( $archives as $archive_key => $archive_args ) { |
|
| 271 | - $this->search_fields( $cmb, $archive_key, $archive_args ); |
|
| 269 | + if (!empty($archives)) { |
|
| 270 | + foreach ($archives as $archive_key => $archive_args) { |
|
| 271 | + $this->search_fields($cmb, $archive_key, $archive_args); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | } |
@@ -280,125 +280,125 @@ discard block |
||
| 280 | 280 | * @param string $section either engine,archive or single. |
| 281 | 281 | * @return void |
| 282 | 282 | */ |
| 283 | - public function search_fields( $cmb, $section, $args ) { |
|
| 283 | + public function search_fields($cmb, $section, $args) { |
|
| 284 | 284 | $this->set_facetwp_vars(); |
| 285 | 285 | $cmb->add_field( |
| 286 | 286 | array( |
| 287 | - 'id' => 'settings_' . $section . '_search', |
|
| 287 | + 'id' => 'settings_'.$section.'_search', |
|
| 288 | 288 | 'type' => 'title', |
| 289 | 289 | 'name' => $args['title'], |
| 290 | 290 | 'default' => $args['title'], |
| 291 | 291 | 'description' => $args['desc'], |
| 292 | 292 | ) |
| 293 | 293 | ); |
| 294 | - do_action( 'lsx_search_settings_section', $cmb, 'top' ); |
|
| 294 | + do_action('lsx_search_settings_section', $cmb, 'top'); |
|
| 295 | 295 | $cmb->add_field( |
| 296 | 296 | array( |
| 297 | - 'name' => esc_html__( 'Enable Search Filters', 'lsx-search' ), |
|
| 298 | - 'id' => $section . '_search_enable', |
|
| 299 | - 'description' => esc_html__( 'Display FacetWP filters on your search results page.', 'lsx-search' ), |
|
| 297 | + 'name' => esc_html__('Enable Search Filters', 'lsx-search'), |
|
| 298 | + 'id' => $section.'_search_enable', |
|
| 299 | + 'description' => esc_html__('Display FacetWP filters on your search results page.', 'lsx-search'), |
|
| 300 | 300 | 'type' => 'checkbox', |
| 301 | 301 | ) |
| 302 | 302 | ); |
| 303 | 303 | |
| 304 | 304 | $cmb->add_field( |
| 305 | 305 | array( |
| 306 | - 'name' => esc_html__( 'Page Layout', 'lsx-search' ), |
|
| 307 | - 'id' => $section . '_search_layout', |
|
| 306 | + 'name' => esc_html__('Page Layout', 'lsx-search'), |
|
| 307 | + 'id' => $section.'_search_layout', |
|
| 308 | 308 | 'type' => 'select', |
| 309 | 309 | 'options' => array( |
| 310 | - '' => esc_html__( 'Follow the theme layout', 'lsx-search' ), |
|
| 311 | - '2cr' => esc_html__( 'Sidebar on left', 'lsx-search' ), |
|
| 312 | - '2cl' => esc_html__( 'Sidebar on right', 'lsx-search' ), |
|
| 310 | + '' => esc_html__('Follow the theme layout', 'lsx-search'), |
|
| 311 | + '2cr' => esc_html__('Sidebar on left', 'lsx-search'), |
|
| 312 | + '2cl' => esc_html__('Sidebar on right', 'lsx-search'), |
|
| 313 | 313 | ), |
| 314 | 314 | 'default' => '', |
| 315 | 315 | ) |
| 316 | 316 | ); |
| 317 | 317 | |
| 318 | - if ( 'product' === $section ) { |
|
| 318 | + if ('product' === $section) { |
|
| 319 | 319 | $cmb->add_field( |
| 320 | 320 | array( |
| 321 | - 'name' => esc_html__( 'Results Layout', 'lsx-search' ), |
|
| 322 | - 'id' => $section . '_search_grid_list', |
|
| 321 | + 'name' => esc_html__('Results Layout', 'lsx-search'), |
|
| 322 | + 'id' => $section.'_search_grid_list', |
|
| 323 | 323 | 'type' => 'select', |
| 324 | 324 | 'show_option_none' => false, |
| 325 | - 'description' => __( 'Set a default layout for the search results.', 'lsx-search' ), |
|
| 325 | + 'description' => __('Set a default layout for the search results.', 'lsx-search'), |
|
| 326 | 326 | 'options' => array( |
| 327 | - 'grid' => esc_html__( 'Grid', 'lsx-search' ), |
|
| 328 | - 'list' => esc_html__( 'List', 'lsx-search' ), |
|
| 327 | + 'grid' => esc_html__('Grid', 'lsx-search'), |
|
| 328 | + 'list' => esc_html__('List', 'lsx-search'), |
|
| 329 | 329 | ), |
| 330 | 330 | 'default' => 'grid', |
| 331 | 331 | ) |
| 332 | 332 | ); |
| 333 | 333 | $cmb->add_field( |
| 334 | 334 | array( |
| 335 | - 'name' => esc_html__( 'Layout Switcher', 'lsx-search' ), |
|
| 336 | - 'id' => $section . '_search_layout_switcher_enable', |
|
| 335 | + 'name' => esc_html__('Layout Switcher', 'lsx-search'), |
|
| 336 | + 'id' => $section.'_search_layout_switcher_enable', |
|
| 337 | 337 | 'type' => 'checkbox', |
| 338 | - 'description' => __( 'Display the layout switcher to allow the user to toggle between the list and grid layouts.', 'lsx-search' ), |
|
| 338 | + 'description' => __('Display the layout switcher to allow the user to toggle between the list and grid layouts.', 'lsx-search'), |
|
| 339 | 339 | ) |
| 340 | 340 | ); |
| 341 | 341 | } |
| 342 | - if ( 'engine' === $section && function_exists('is_plugin_active') && is_plugin_active( 'tour-operator/tour-operator.php' ) ) { |
|
| 342 | + if ('engine' === $section && function_exists('is_plugin_active') && is_plugin_active('tour-operator/tour-operator.php')) { |
|
| 343 | 343 | $cmb->add_field( |
| 344 | 344 | array( |
| 345 | - 'name' => esc_html__( 'List layout images', 'lsx-search' ), |
|
| 346 | - 'id' => $section . '_search_list_layout_image_style', |
|
| 345 | + 'name' => esc_html__('List layout images', 'lsx-search'), |
|
| 346 | + 'id' => $section.'_search_list_layout_image_style', |
|
| 347 | 347 | 'type' => 'select', |
| 348 | 348 | 'options' => array( |
| 349 | - '' => esc_html__( 'Full Height', 'lsx-search' ), |
|
| 350 | - 'max-height' => esc_html__( 'Max Height', 'lsx-search' ), |
|
| 349 | + '' => esc_html__('Full Height', 'lsx-search'), |
|
| 350 | + 'max-height' => esc_html__('Max Height', 'lsx-search'), |
|
| 351 | 351 | ), |
| 352 | 352 | 'default' => '', |
| 353 | 353 | ) |
| 354 | 354 | ); |
| 355 | 355 | } |
| 356 | - if ( 'engine' === $section ) { |
|
| 356 | + if ('engine' === $section) { |
|
| 357 | 357 | $cmb->add_field( |
| 358 | 358 | array( |
| 359 | - 'name' => esc_html__( 'Display Excerpt', 'lsx-search' ), |
|
| 360 | - 'id' => $section . '_excerpt_enable', |
|
| 359 | + 'name' => esc_html__('Display Excerpt', 'lsx-search'), |
|
| 360 | + 'id' => $section.'_excerpt_enable', |
|
| 361 | 361 | 'type' => 'checkbox', |
| 362 | - 'description' => __( 'Display the excerpt of a listing.', 'lsx-search' ), |
|
| 362 | + 'description' => __('Display the excerpt of a listing.', 'lsx-search'), |
|
| 363 | 363 | ) |
| 364 | 364 | ); |
| 365 | 365 | $cmb->add_field( |
| 366 | 366 | array( |
| 367 | - 'name' => esc_html__( 'Enable Post Type Label', 'lsx-search' ), |
|
| 368 | - 'id' => $section . '_search_enable_pt_label', |
|
| 367 | + 'name' => esc_html__('Enable Post Type Label', 'lsx-search'), |
|
| 368 | + 'id' => $section.'_search_enable_pt_label', |
|
| 369 | 369 | 'type' => 'checkbox', |
| 370 | - 'description' => __( 'This enables the post type label from entries on search results page.', 'lsx-search' ), |
|
| 370 | + 'description' => __('This enables the post type label from entries on search results page.', 'lsx-search'), |
|
| 371 | 371 | ) |
| 372 | 372 | ); |
| 373 | - if ( function_exists('is_plugin_active') && is_plugin_active( 'tour-operator/tour-operator.php' ) ) { |
|
| 373 | + if (function_exists('is_plugin_active') && is_plugin_active('tour-operator/tour-operator.php')) { |
|
| 374 | 374 | $cmb->add_field( |
| 375 | 375 | array( |
| 376 | - 'name' => esc_html__( 'Enable Continent Filter', 'lsx-search' ), |
|
| 377 | - 'id' => $section . '_search_enable_continent_filter', |
|
| 376 | + 'name' => esc_html__('Enable Continent Filter', 'lsx-search'), |
|
| 377 | + 'id' => $section.'_search_enable_continent_filter', |
|
| 378 | 378 | 'type' => 'checkbox', |
| 379 | - 'description' => __( 'This enables the continent filter in FacetWP destinations filter.', 'lsx-search' ), |
|
| 379 | + 'description' => __('This enables the continent filter in FacetWP destinations filter.', 'lsx-search'), |
|
| 380 | 380 | ) |
| 381 | 381 | ); |
| 382 | 382 | $cmb->add_field( |
| 383 | 383 | array( |
| 384 | - 'name' => esc_html__( 'Enable Continental Regions', 'lsx-search' ), |
|
| 385 | - 'id' => $section . '_search_enable_continental_regions', |
|
| 384 | + 'name' => esc_html__('Enable Continental Regions', 'lsx-search'), |
|
| 385 | + 'id' => $section.'_search_enable_continental_regions', |
|
| 386 | 386 | 'type' => 'checkbox', |
| 387 | - 'description' => __( 'This disable continents and enabled the sub regions.', 'lsx-search' ), |
|
| 387 | + 'description' => __('This disable continents and enabled the sub regions.', 'lsx-search'), |
|
| 388 | 388 | ) |
| 389 | 389 | ); |
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - if ( function_exists('is_plugin_active') && is_plugin_active( 'tour-operator/tour-operator.php' ) && 'accommodation' === $section ) { |
|
| 393 | + if (function_exists('is_plugin_active') && is_plugin_active('tour-operator/tour-operator.php') && 'accommodation' === $section) { |
|
| 394 | 394 | $cmb->add_field( |
| 395 | 395 | array( |
| 396 | - 'name' => esc_html__( 'Results Layout - list vs map', 'lsx-search' ), |
|
| 397 | - 'id' => $section . '_search_results_layout', |
|
| 396 | + 'name' => esc_html__('Results Layout - list vs map', 'lsx-search'), |
|
| 397 | + 'id' => $section.'_search_results_layout', |
|
| 398 | 398 | 'type' => 'select', |
| 399 | 399 | 'options' => array( |
| 400 | - 'list_map' => esc_html__( 'List and Map', 'lsx-search' ), |
|
| 401 | - 'list' => esc_html__( 'List only', 'lsx-search' ), |
|
| 400 | + 'list_map' => esc_html__('List and Map', 'lsx-search'), |
|
| 401 | + 'list' => esc_html__('List only', 'lsx-search'), |
|
| 402 | 402 | ), |
| 403 | 403 | 'default' => '', |
| 404 | 404 | ) |
@@ -407,52 +407,52 @@ discard block |
||
| 407 | 407 | |
| 408 | 408 | $cmb->add_field( |
| 409 | 409 | array( |
| 410 | - 'name' => esc_html__( 'Enable Collapse', 'lsx-search' ), |
|
| 411 | - 'id' => $section . '_search_collapse', |
|
| 410 | + 'name' => esc_html__('Enable Collapse', 'lsx-search'), |
|
| 411 | + 'id' => $section.'_search_collapse', |
|
| 412 | 412 | 'type' => 'checkbox', |
| 413 | - 'description' => __( 'Enable collapsible filters on search results.', 'lsx-search' ), |
|
| 413 | + 'description' => __('Enable collapsible filters on search results.', 'lsx-search'), |
|
| 414 | 414 | ) |
| 415 | 415 | ); |
| 416 | 416 | |
| 417 | 417 | $cmb->add_field( |
| 418 | 418 | array( |
| 419 | - 'name' => esc_html__( 'Disable Sorting', 'lsx-search' ), |
|
| 420 | - 'id' => $section . '_search_disable_sorting', |
|
| 419 | + 'name' => esc_html__('Disable Sorting', 'lsx-search'), |
|
| 420 | + 'id' => $section.'_search_disable_sorting', |
|
| 421 | 421 | 'type' => 'checkbox', |
| 422 | - 'description' => __( 'Toggle the sorting drop down menu on your search results.', 'lsx-search' ), |
|
| 422 | + 'description' => __('Toggle the sorting drop down menu on your search results.', 'lsx-search'), |
|
| 423 | 423 | ) |
| 424 | 424 | ); |
| 425 | 425 | |
| 426 | 426 | $cmb->add_field( |
| 427 | 427 | array( |
| 428 | - 'name' => esc_html__( 'Disable the Date Sorting Option', 'lsx-search' ), |
|
| 429 | - 'id' => $section . '_search_disable_date', |
|
| 428 | + 'name' => esc_html__('Disable the Date Sorting Option', 'lsx-search'), |
|
| 429 | + 'id' => $section.'_search_disable_date', |
|
| 430 | 430 | 'type' => 'checkbox', |
| 431 | 431 | ) |
| 432 | 432 | ); |
| 433 | 433 | |
| 434 | 434 | $cmb->add_field( |
| 435 | 435 | array( |
| 436 | - 'name' => esc_html__( 'Display Clear Button', 'lsx-search' ), |
|
| 437 | - 'id' => $section . '_search_display_clear_button', |
|
| 436 | + 'name' => esc_html__('Display Clear Button', 'lsx-search'), |
|
| 437 | + 'id' => $section.'_search_display_clear_button', |
|
| 438 | 438 | 'type' => 'checkbox', |
| 439 | - 'description' => __( 'Check this to turn on a button that will clear your search results.', 'lsx-search' ), |
|
| 439 | + 'description' => __('Check this to turn on a button that will clear your search results.', 'lsx-search'), |
|
| 440 | 440 | ) |
| 441 | 441 | ); |
| 442 | 442 | |
| 443 | 443 | $cmb->add_field( |
| 444 | 444 | array( |
| 445 | - 'name' => esc_html__( 'Display Result Count', 'lsx-search' ), |
|
| 446 | - 'id' => $section . '_search_display_result_count', |
|
| 445 | + 'name' => esc_html__('Display Result Count', 'lsx-search'), |
|
| 446 | + 'id' => $section.'_search_display_result_count', |
|
| 447 | 447 | 'type' => 'checkbox', |
| 448 | 448 | ) |
| 449 | 449 | ); |
| 450 | - if ( function_exists('is_plugin_active') && is_plugin_active( 'facetwp-alpha/index.php' ) ) { |
|
| 450 | + if (function_exists('is_plugin_active') && is_plugin_active('facetwp-alpha/index.php')) { |
|
| 451 | 451 | $cmb->add_field( |
| 452 | 452 | array( |
| 453 | - 'name' => esc_html__( 'Alphabet Facet', 'lsx-search' ), |
|
| 454 | - 'description' => esc_html__( 'Select the alphabetical sorter facet.', 'lsx-search' ), |
|
| 455 | - 'id' => $section . '_search_az_pagination', |
|
| 453 | + 'name' => esc_html__('Alphabet Facet', 'lsx-search'), |
|
| 454 | + 'description' => esc_html__('Select the alphabetical sorter facet.', 'lsx-search'), |
|
| 455 | + 'id' => $section.'_search_az_pagination', |
|
| 456 | 456 | 'type' => 'select', |
| 457 | 457 | 'options' => $this->az_facets, |
| 458 | 458 | ) |
@@ -460,17 +460,17 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | $cmb->add_field( |
| 462 | 462 | array( |
| 463 | - 'name' => esc_html__( 'Facets', 'lsx-search' ), |
|
| 464 | - 'description' => esc_html__( 'Choose the filters to display in the sidebar. Edit FacetWP filters to change individual filters.', 'lsx-search' ), |
|
| 465 | - 'id' => $section . '_search_facets', |
|
| 463 | + 'name' => esc_html__('Facets', 'lsx-search'), |
|
| 464 | + 'description' => esc_html__('Choose the filters to display in the sidebar. Edit FacetWP filters to change individual filters.', 'lsx-search'), |
|
| 465 | + 'id' => $section.'_search_facets', |
|
| 466 | 466 | 'type' => 'multicheck', |
| 467 | 467 | 'options' => $this->facet_data, |
| 468 | 468 | ) |
| 469 | 469 | ); |
| 470 | - do_action( 'lsx_search_settings_section', $cmb, 'bottom' ); |
|
| 470 | + do_action('lsx_search_settings_section', $cmb, 'bottom'); |
|
| 471 | 471 | $cmb->add_field( |
| 472 | 472 | array( |
| 473 | - 'id' => 'settings_' . $section . '_search_closing', |
|
| 473 | + 'id' => 'settings_'.$section.'_search_closing', |
|
| 474 | 474 | 'type' => 'tab_closing', |
| 475 | 475 | ) |
| 476 | 476 | ); |
@@ -479,20 +479,20 @@ discard block |
||
| 479 | 479 | /** |
| 480 | 480 | * Handle body colours that might be change by LSX Customiser. |
| 481 | 481 | */ |
| 482 | - public function customizer_body_colours_handler( $css, $colors ) { |
|
| 482 | + public function customizer_body_colours_handler($css, $colors) { |
|
| 483 | 483 | $css .= ' |
| 484 | - @import "' . LSX_SEARCH_PATH . '/assets/css/scss/customizer-search-body-colours"; |
|
| 484 | + @import "' . LSX_SEARCH_PATH.'/assets/css/scss/customizer-search-body-colours"; |
|
| 485 | 485 | |
| 486 | 486 | /** |
| 487 | 487 | * LSX Customizer - Body (LSX Search) |
| 488 | 488 | */ |
| 489 | 489 | @include customizer-search-body-colours ( |
| 490 | - $bg: ' . $colors['background_color'] . ', |
|
| 491 | - $breaker: ' . $colors['body_line_color'] . ', |
|
| 492 | - $color: ' . $colors['body_text_color'] . ', |
|
| 493 | - $link: ' . $colors['body_link_color'] . ', |
|
| 494 | - $hover: ' . $colors['body_link_hover_color'] . ', |
|
| 495 | - $small: ' . $colors['body_text_small_color'] . ' |
|
| 490 | + $bg: ' . $colors['background_color'].', |
|
| 491 | + $breaker: ' . $colors['body_line_color'].', |
|
| 492 | + $color: ' . $colors['body_text_color'].', |
|
| 493 | + $link: ' . $colors['body_link_color'].', |
|
| 494 | + $hover: ' . $colors['body_link_hover_color'].', |
|
| 495 | + $small: ' . $colors['body_text_small_color'].' |
|
| 496 | 496 | ); |
| 497 | 497 | '; |
| 498 | 498 | |
@@ -506,14 +506,14 @@ discard block |
||
| 506 | 506 | * @param array $colours |
| 507 | 507 | * @return string |
| 508 | 508 | */ |
| 509 | - public function customizer_button_colours( $css, $colours ) { |
|
| 509 | + public function customizer_button_colours($css, $colours) { |
|
| 510 | 510 | $css .= ' |
| 511 | 511 | #secondary.facetwp-sidebar { |
| 512 | 512 | .facetwp-item.facetwp-form { |
| 513 | 513 | .search-form { |
| 514 | 514 | .btn { |
| 515 | 515 | &.search-submit { |
| 516 | - @include lsx-button-colour(' . $colours['button_text_color'] . ', ' . $colours['button_text_color_hover'] . ', ' . $colours['button_background_color'] . ', ' . $colours['button_background_hover_color'] . ', ' . $colours['button_shadow'] . '); |
|
| 516 | + @include lsx-button-colour(' . $colours['button_text_color'].', '.$colours['button_text_color_hover'].', '.$colours['button_background_color'].', '.$colours['button_background_hover_color'].', '.$colours['button_shadow'].'); |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | } |
@@ -10,154 +10,154 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Layout { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Holds class instance |
|
| 15 | - * |
|
| 16 | - * @since 1.0.0 |
|
| 17 | - * |
|
| 18 | - * @var object \lsx\search\classes\frontend\Layout() |
|
| 19 | - */ |
|
| 20 | - protected static $instance = null; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Contructor |
|
| 24 | - */ |
|
| 25 | - public function __construct() { |
|
| 26 | - add_action( 'wp', array( $this, 'load_functions' ), 24 ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Return an instance of this class. |
|
| 31 | - * |
|
| 32 | - * @since 1.0.0 |
|
| 33 | - * |
|
| 34 | - * @return object \lsx\search\classes\frontend\Layout() A single instance of this class. |
|
| 35 | - */ |
|
| 36 | - public static function get_instance() { |
|
| 37 | - // If the single instance hasn't been set, set it now. |
|
| 38 | - if ( null == self::$instance ) { |
|
| 39 | - self::$instance = new self(); |
|
| 40 | - } |
|
| 41 | - return self::$instance; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Check all settings. |
|
| 46 | - */ |
|
| 47 | - public function load_functions() { |
|
| 48 | - $lsx_search = LSX_Search::get_instance(); |
|
| 49 | - if ( $lsx_search->frontend->search_enabled ) { |
|
| 50 | - if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_layout_switcher_enable' ] ) ) { |
|
| 51 | - add_filter( 'lsx_blog_customizer_show_switcher', array( $this, 'show_layout_switcher' ), 10, 1 ); |
|
| 52 | - add_filter( 'lsx_layout_switcher_options', array( $this, 'lsx_layout_switcher_options' ), 10, 1 ); |
|
| 53 | - add_filter( 'lsx_layout_switcher_page_key', array( $this, 'lsx_layout_switcher_page_key' ), 10, 1 ); |
|
| 54 | - add_filter( 'lsx_layout_switcher_options_default', array( $this, 'lsx_layout_switcher_options_default' ), 10, 1 ); |
|
| 55 | - |
|
| 56 | - // Layout Classes |
|
| 57 | - add_filter( 'woocommerce_product_loop_start', array( $this, 'woocommerce_layout_class' ), 10, 1 ); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Display the woocommerce archive swticher. |
|
| 64 | - */ |
|
| 65 | - public function show_layout_switcher( $show = false ) { |
|
| 66 | - if ( is_search() ) { |
|
| 67 | - $archive_layout_switcher = get_theme_mod( 'lsx_blog_customizer_archive_layout_switcher', false ); |
|
| 68 | - if ( true === $archive_layout_switcher ) { |
|
| 69 | - $show = true; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - return $show; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Remove the default and half-grid options from the results layouts. |
|
| 77 | - * |
|
| 78 | - * @param array $layout_options |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function lsx_layout_switcher_options( $layout_options ) { |
|
| 82 | - unset( $layout_options['default'] ); |
|
| 83 | - unset( $layout_options['half-grid'] ); |
|
| 84 | - return $layout_options; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Replace the key for the layout switcher. |
|
| 89 | - * |
|
| 90 | - * @param string $page_key |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 93 | - public function lsx_layout_switcher_page_key( $page_key ) { |
|
| 94 | - $lsx_search = LSX_Search::get_instance(); |
|
| 95 | - $page_key = str_replace( '_search', '', $lsx_search->frontend->search_prefix ); |
|
| 96 | - return $page_key; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * CHange the default layout to a grid layout. |
|
| 101 | - * |
|
| 102 | - * @param string $default |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public function lsx_layout_switcher_options_default( $default = 'grid' ) { |
|
| 106 | - $lsx_search = LSX_Search::get_instance(); |
|
| 107 | - $default = 'grid'; |
|
| 108 | - if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) && ! empty( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) ) { |
|
| 109 | - $default = $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ]; |
|
| 110 | - } |
|
| 111 | - return $default; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Controls the layout for the woocommerce shop page. |
|
| 116 | - */ |
|
| 117 | - public function woocommerce_layout_class( $output = '' ) { |
|
| 118 | - $default_class = $this->lsx_layout_switcher_options_default(); |
|
| 119 | - $selected = $this->get_layout_value_from_cookie( 'product' ); |
|
| 120 | - if ( '' !== $selected ) { |
|
| 121 | - $default_class = $selected; |
|
| 122 | - } |
|
| 123 | - $output = str_replace( 'products', 'products ' . $default_class, $output ); |
|
| 124 | - return $output; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Get layout value from cookie |
|
| 129 | - * |
|
| 130 | - * @since 1.0.0 |
|
| 131 | - */ |
|
| 132 | - public function get_layout_value_from_cookie( $page_key = 'blog' ) { |
|
| 133 | - $archive_layout = 'grid'; |
|
| 134 | - |
|
| 135 | - if ( isset( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ) ) { |
|
| 136 | - $archive_layout_from_cookie = sanitize_key( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ); |
|
| 137 | - $archive_layout_from_cookie = $this->sanitize_select_layout_switcher( $archive_layout_from_cookie ); |
|
| 138 | - |
|
| 139 | - if ( ! empty( $archive_layout_from_cookie ) ) { |
|
| 140 | - $archive_layout = $archive_layout_from_cookie; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - return $archive_layout; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Sanitize select (layout switcher). |
|
| 148 | - * |
|
| 149 | - * @since 1.0.0 |
|
| 150 | - */ |
|
| 151 | - public function sanitize_select_layout_switcher( $input ) { |
|
| 152 | - $valid = array( |
|
| 153 | - 'list' => esc_html__( 'List', 'lsx-search' ), |
|
| 154 | - 'grid' => esc_html__( 'Grid', 'lsx-search' ), |
|
| 155 | - ); |
|
| 156 | - |
|
| 157 | - if ( array_key_exists( $input, $valid ) ) { |
|
| 158 | - return $input; |
|
| 159 | - } else { |
|
| 160 | - return ''; |
|
| 161 | - } |
|
| 162 | - } |
|
| 13 | + /** |
|
| 14 | + * Holds class instance |
|
| 15 | + * |
|
| 16 | + * @since 1.0.0 |
|
| 17 | + * |
|
| 18 | + * @var object \lsx\search\classes\frontend\Layout() |
|
| 19 | + */ |
|
| 20 | + protected static $instance = null; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Contructor |
|
| 24 | + */ |
|
| 25 | + public function __construct() { |
|
| 26 | + add_action( 'wp', array( $this, 'load_functions' ), 24 ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Return an instance of this class. |
|
| 31 | + * |
|
| 32 | + * @since 1.0.0 |
|
| 33 | + * |
|
| 34 | + * @return object \lsx\search\classes\frontend\Layout() A single instance of this class. |
|
| 35 | + */ |
|
| 36 | + public static function get_instance() { |
|
| 37 | + // If the single instance hasn't been set, set it now. |
|
| 38 | + if ( null == self::$instance ) { |
|
| 39 | + self::$instance = new self(); |
|
| 40 | + } |
|
| 41 | + return self::$instance; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Check all settings. |
|
| 46 | + */ |
|
| 47 | + public function load_functions() { |
|
| 48 | + $lsx_search = LSX_Search::get_instance(); |
|
| 49 | + if ( $lsx_search->frontend->search_enabled ) { |
|
| 50 | + if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_layout_switcher_enable' ] ) ) { |
|
| 51 | + add_filter( 'lsx_blog_customizer_show_switcher', array( $this, 'show_layout_switcher' ), 10, 1 ); |
|
| 52 | + add_filter( 'lsx_layout_switcher_options', array( $this, 'lsx_layout_switcher_options' ), 10, 1 ); |
|
| 53 | + add_filter( 'lsx_layout_switcher_page_key', array( $this, 'lsx_layout_switcher_page_key' ), 10, 1 ); |
|
| 54 | + add_filter( 'lsx_layout_switcher_options_default', array( $this, 'lsx_layout_switcher_options_default' ), 10, 1 ); |
|
| 55 | + |
|
| 56 | + // Layout Classes |
|
| 57 | + add_filter( 'woocommerce_product_loop_start', array( $this, 'woocommerce_layout_class' ), 10, 1 ); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Display the woocommerce archive swticher. |
|
| 64 | + */ |
|
| 65 | + public function show_layout_switcher( $show = false ) { |
|
| 66 | + if ( is_search() ) { |
|
| 67 | + $archive_layout_switcher = get_theme_mod( 'lsx_blog_customizer_archive_layout_switcher', false ); |
|
| 68 | + if ( true === $archive_layout_switcher ) { |
|
| 69 | + $show = true; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + return $show; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Remove the default and half-grid options from the results layouts. |
|
| 77 | + * |
|
| 78 | + * @param array $layout_options |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function lsx_layout_switcher_options( $layout_options ) { |
|
| 82 | + unset( $layout_options['default'] ); |
|
| 83 | + unset( $layout_options['half-grid'] ); |
|
| 84 | + return $layout_options; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Replace the key for the layout switcher. |
|
| 89 | + * |
|
| 90 | + * @param string $page_key |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | + public function lsx_layout_switcher_page_key( $page_key ) { |
|
| 94 | + $lsx_search = LSX_Search::get_instance(); |
|
| 95 | + $page_key = str_replace( '_search', '', $lsx_search->frontend->search_prefix ); |
|
| 96 | + return $page_key; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * CHange the default layout to a grid layout. |
|
| 101 | + * |
|
| 102 | + * @param string $default |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public function lsx_layout_switcher_options_default( $default = 'grid' ) { |
|
| 106 | + $lsx_search = LSX_Search::get_instance(); |
|
| 107 | + $default = 'grid'; |
|
| 108 | + if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) && ! empty( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) ) { |
|
| 109 | + $default = $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ]; |
|
| 110 | + } |
|
| 111 | + return $default; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Controls the layout for the woocommerce shop page. |
|
| 116 | + */ |
|
| 117 | + public function woocommerce_layout_class( $output = '' ) { |
|
| 118 | + $default_class = $this->lsx_layout_switcher_options_default(); |
|
| 119 | + $selected = $this->get_layout_value_from_cookie( 'product' ); |
|
| 120 | + if ( '' !== $selected ) { |
|
| 121 | + $default_class = $selected; |
|
| 122 | + } |
|
| 123 | + $output = str_replace( 'products', 'products ' . $default_class, $output ); |
|
| 124 | + return $output; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Get layout value from cookie |
|
| 129 | + * |
|
| 130 | + * @since 1.0.0 |
|
| 131 | + */ |
|
| 132 | + public function get_layout_value_from_cookie( $page_key = 'blog' ) { |
|
| 133 | + $archive_layout = 'grid'; |
|
| 134 | + |
|
| 135 | + if ( isset( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ) ) { |
|
| 136 | + $archive_layout_from_cookie = sanitize_key( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ); |
|
| 137 | + $archive_layout_from_cookie = $this->sanitize_select_layout_switcher( $archive_layout_from_cookie ); |
|
| 138 | + |
|
| 139 | + if ( ! empty( $archive_layout_from_cookie ) ) { |
|
| 140 | + $archive_layout = $archive_layout_from_cookie; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + return $archive_layout; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Sanitize select (layout switcher). |
|
| 148 | + * |
|
| 149 | + * @since 1.0.0 |
|
| 150 | + */ |
|
| 151 | + public function sanitize_select_layout_switcher( $input ) { |
|
| 152 | + $valid = array( |
|
| 153 | + 'list' => esc_html__( 'List', 'lsx-search' ), |
|
| 154 | + 'grid' => esc_html__( 'Grid', 'lsx-search' ), |
|
| 155 | + ); |
|
| 156 | + |
|
| 157 | + if ( array_key_exists( $input, $valid ) ) { |
|
| 158 | + return $input; |
|
| 159 | + } else { |
|
| 160 | + return ''; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * Contructor |
| 24 | 24 | */ |
| 25 | 25 | public function __construct() { |
| 26 | - add_action( 'wp', array( $this, 'load_functions' ), 24 ); |
|
| 26 | + add_action('wp', array($this, 'load_functions'), 24); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public static function get_instance() { |
| 37 | 37 | // If the single instance hasn't been set, set it now. |
| 38 | - if ( null == self::$instance ) { |
|
| 38 | + if (null == self::$instance) { |
|
| 39 | 39 | self::$instance = new self(); |
| 40 | 40 | } |
| 41 | 41 | return self::$instance; |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function load_functions() { |
| 48 | 48 | $lsx_search = LSX_Search::get_instance(); |
| 49 | - if ( $lsx_search->frontend->search_enabled ) { |
|
| 50 | - if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_layout_switcher_enable' ] ) ) { |
|
| 51 | - add_filter( 'lsx_blog_customizer_show_switcher', array( $this, 'show_layout_switcher' ), 10, 1 ); |
|
| 52 | - add_filter( 'lsx_layout_switcher_options', array( $this, 'lsx_layout_switcher_options' ), 10, 1 ); |
|
| 53 | - add_filter( 'lsx_layout_switcher_page_key', array( $this, 'lsx_layout_switcher_page_key' ), 10, 1 ); |
|
| 54 | - add_filter( 'lsx_layout_switcher_options_default', array( $this, 'lsx_layout_switcher_options_default' ), 10, 1 ); |
|
| 49 | + if ($lsx_search->frontend->search_enabled) { |
|
| 50 | + if (isset($lsx_search->frontend->options['display'][$lsx_search->frontend->search_prefix.'_layout_switcher_enable'])) { |
|
| 51 | + add_filter('lsx_blog_customizer_show_switcher', array($this, 'show_layout_switcher'), 10, 1); |
|
| 52 | + add_filter('lsx_layout_switcher_options', array($this, 'lsx_layout_switcher_options'), 10, 1); |
|
| 53 | + add_filter('lsx_layout_switcher_page_key', array($this, 'lsx_layout_switcher_page_key'), 10, 1); |
|
| 54 | + add_filter('lsx_layout_switcher_options_default', array($this, 'lsx_layout_switcher_options_default'), 10, 1); |
|
| 55 | 55 | |
| 56 | 56 | // Layout Classes |
| 57 | - add_filter( 'woocommerce_product_loop_start', array( $this, 'woocommerce_layout_class' ), 10, 1 ); |
|
| 57 | + add_filter('woocommerce_product_loop_start', array($this, 'woocommerce_layout_class'), 10, 1); |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | /** |
| 63 | 63 | * Display the woocommerce archive swticher. |
| 64 | 64 | */ |
| 65 | - public function show_layout_switcher( $show = false ) { |
|
| 66 | - if ( is_search() ) { |
|
| 67 | - $archive_layout_switcher = get_theme_mod( 'lsx_blog_customizer_archive_layout_switcher', false ); |
|
| 68 | - if ( true === $archive_layout_switcher ) { |
|
| 65 | + public function show_layout_switcher($show = false) { |
|
| 66 | + if (is_search()) { |
|
| 67 | + $archive_layout_switcher = get_theme_mod('lsx_blog_customizer_archive_layout_switcher', false); |
|
| 68 | + if (true === $archive_layout_switcher) { |
|
| 69 | 69 | $show = true; |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * @param array $layout_options |
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | - public function lsx_layout_switcher_options( $layout_options ) { |
|
| 82 | - unset( $layout_options['default'] ); |
|
| 83 | - unset( $layout_options['half-grid'] ); |
|
| 81 | + public function lsx_layout_switcher_options($layout_options) { |
|
| 82 | + unset($layout_options['default']); |
|
| 83 | + unset($layout_options['half-grid']); |
|
| 84 | 84 | return $layout_options; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | * @param string $page_key |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - public function lsx_layout_switcher_page_key( $page_key ) { |
|
| 93 | + public function lsx_layout_switcher_page_key($page_key) { |
|
| 94 | 94 | $lsx_search = LSX_Search::get_instance(); |
| 95 | - $page_key = str_replace( '_search', '', $lsx_search->frontend->search_prefix ); |
|
| 95 | + $page_key = str_replace('_search', '', $lsx_search->frontend->search_prefix); |
|
| 96 | 96 | return $page_key; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * @param string $default |
| 103 | 103 | * @return string |
| 104 | 104 | */ |
| 105 | - public function lsx_layout_switcher_options_default( $default = 'grid' ) { |
|
| 105 | + public function lsx_layout_switcher_options_default($default = 'grid') { |
|
| 106 | 106 | $lsx_search = LSX_Search::get_instance(); |
| 107 | 107 | $default = 'grid'; |
| 108 | - if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) && ! empty( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) ) { |
|
| 109 | - $default = $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ]; |
|
| 108 | + if (isset($lsx_search->frontend->options['display'][$lsx_search->frontend->search_prefix.'_grid_list']) && !empty($lsx_search->frontend->options['display'][$lsx_search->frontend->search_prefix.'_grid_list'])) { |
|
| 109 | + $default = $lsx_search->frontend->options['display'][$lsx_search->frontend->search_prefix.'_grid_list']; |
|
| 110 | 110 | } |
| 111 | 111 | return $default; |
| 112 | 112 | } |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | /** |
| 115 | 115 | * Controls the layout for the woocommerce shop page. |
| 116 | 116 | */ |
| 117 | - public function woocommerce_layout_class( $output = '' ) { |
|
| 117 | + public function woocommerce_layout_class($output = '') { |
|
| 118 | 118 | $default_class = $this->lsx_layout_switcher_options_default(); |
| 119 | - $selected = $this->get_layout_value_from_cookie( 'product' ); |
|
| 120 | - if ( '' !== $selected ) { |
|
| 119 | + $selected = $this->get_layout_value_from_cookie('product'); |
|
| 120 | + if ('' !== $selected) { |
|
| 121 | 121 | $default_class = $selected; |
| 122 | 122 | } |
| 123 | - $output = str_replace( 'products', 'products ' . $default_class, $output ); |
|
| 123 | + $output = str_replace('products', 'products '.$default_class, $output); |
|
| 124 | 124 | return $output; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @since 1.0.0 |
| 131 | 131 | */ |
| 132 | - public function get_layout_value_from_cookie( $page_key = 'blog' ) { |
|
| 132 | + public function get_layout_value_from_cookie($page_key = 'blog') { |
|
| 133 | 133 | $archive_layout = 'grid'; |
| 134 | 134 | |
| 135 | - if ( isset( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ) ) { |
|
| 136 | - $archive_layout_from_cookie = sanitize_key( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ); |
|
| 137 | - $archive_layout_from_cookie = $this->sanitize_select_layout_switcher( $archive_layout_from_cookie ); |
|
| 135 | + if (isset($_COOKIE['lsx-'.$page_key.'-layout'])) { |
|
| 136 | + $archive_layout_from_cookie = sanitize_key($_COOKIE['lsx-'.$page_key.'-layout']); |
|
| 137 | + $archive_layout_from_cookie = $this->sanitize_select_layout_switcher($archive_layout_from_cookie); |
|
| 138 | 138 | |
| 139 | - if ( ! empty( $archive_layout_from_cookie ) ) { |
|
| 139 | + if (!empty($archive_layout_from_cookie)) { |
|
| 140 | 140 | $archive_layout = $archive_layout_from_cookie; |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @since 1.0.0 |
| 150 | 150 | */ |
| 151 | - public function sanitize_select_layout_switcher( $input ) { |
|
| 151 | + public function sanitize_select_layout_switcher($input) { |
|
| 152 | 152 | $valid = array( |
| 153 | - 'list' => esc_html__( 'List', 'lsx-search' ), |
|
| 154 | - 'grid' => esc_html__( 'Grid', 'lsx-search' ), |
|
| 153 | + 'list' => esc_html__('List', 'lsx-search'), |
|
| 154 | + 'grid' => esc_html__('Grid', 'lsx-search'), |
|
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | - if ( array_key_exists( $input, $valid ) ) { |
|
| 157 | + if (array_key_exists($input, $valid)) { |
|
| 158 | 158 | return $input; |
| 159 | 159 | } else { |
| 160 | 160 | return ''; |