ajax-handlers.php
6 months ago
class-configurate.php
1 year ago
class-helpers.php
1 year ago
class-search-options.php
1 year ago
index.php
4 years ago
class-search-options.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WBCR\Factory_Templates_134; |
| 4 | |
| 5 | /** |
| 6 | * Class Search options |
| 7 | * |
| 8 | * Allows you to collect all the options from the plugin pages, is a registry of options. |
| 9 | * |
| 10 | * @author Alex Kovlaev <alex.kovalevv@gmail.com>, https://github.com/alexkovalevv |
| 11 | * |
| 12 | * @since 2.2.0 |
| 13 | */ |
| 14 | class Search_Options { |
| 15 | |
| 16 | private static $_all_options; |
| 17 | |
| 18 | /** |
| 19 | * Registers page options in the options registry |
| 20 | * |
| 21 | * This will allow the user to search all the plugin options. |
| 22 | * |
| 23 | * @param array $options |
| 24 | * @param string $page_url |
| 25 | * @param string $page_id |
| 26 | * @since 2.2.0 |
| 27 | * |
| 28 | */ |
| 29 | public static function register_options($options, $page_url, $page_id) |
| 30 | { |
| 31 | if( empty($options) || !is_array($options) ) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | $extracted_options = static::recursive_extraxt_options($options); |
| 36 | |
| 37 | if( !empty($extracted_options) ) { |
| 38 | foreach((array)$extracted_options as $option) { |
| 39 | if( 'div' === $option['type'] || 'html' === $option['type'] || !isset($option['title']) ) { |
| 40 | continue; |
| 41 | } |
| 42 | |
| 43 | $formated_option['title'] = $option['title']; |
| 44 | |
| 45 | /*if( isset($option['hint']) ) { |
| 46 | $formated_option['hint'] = $option['hint']; |
| 47 | }*/ |
| 48 | |
| 49 | $formated_option['page_url'] = $page_url . '#factory-control-' . $option['name']; |
| 50 | $formated_option['page_id'] = $page_id; |
| 51 | |
| 52 | static::$_all_options[] = $formated_option; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Extracted options from a nested array |
| 59 | * @param array $options |
| 60 | * @return array |
| 61 | * @since 2.2.0 |
| 62 | */ |
| 63 | protected static function recursive_extraxt_options($options) |
| 64 | { |
| 65 | $extracted_options = []; |
| 66 | |
| 67 | foreach($options as $option) { |
| 68 | if( isset($option['items']) ) { |
| 69 | $extracted_options = array_merge($extracted_options, static::recursive_extraxt_options($option['items'])); |
| 70 | } else { |
| 71 | $extracted_options[] = $option; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return $extracted_options; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get all plugin options |
| 80 | * @return mixed |
| 81 | * @since 2.2.0 |
| 82 | */ |
| 83 | public static function get_all_options() |
| 84 | { |
| 85 | return static::$_all_options; |
| 86 | } |
| 87 | } |