@@ -6,7 +6,7 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | // Prevent direct file access |
9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
10 | 10 | |
11 | 11 | // Load module functions |
12 | 12 | require_once 'functions.php'; |
@@ -18,7 +18,9 @@ |
||
18 | 18 | /** |
19 | 19 | * Prevent loading the library more than once |
20 | 20 | */ |
21 | -if( defined( 'AMARKAL_SETTINGS' ) ) return false; |
|
21 | +if( defined( 'AMARKAL_SETTINGS' ) ) { |
|
22 | + return false; |
|
23 | +} |
|
22 | 24 | define( 'AMARKAL_SETTINGS', true ); |
23 | 25 | |
24 | 26 | if(!function_exists('amarkal_add_settings_page')) |
@@ -56,7 +56,6 @@ |
||
56 | 56 | /** |
57 | 57 | * Get the value of the given settings field |
58 | 58 | * |
59 | - * @param [array] $args |
|
60 | 59 | * @return void |
61 | 60 | */ |
62 | 61 | function amarkal_get_settings_value( $slug, $field_name ) |
@@ -13,15 +13,15 @@ discard block |
||
13 | 13 | */ |
14 | 14 | |
15 | 15 | // Prevent direct file access |
16 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
16 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Prevent loading the library more than once |
20 | 20 | */ |
21 | -if( defined( 'AMARKAL_SETTINGS' ) ) return false; |
|
22 | -define( 'AMARKAL_SETTINGS', true ); |
|
21 | +if (defined('AMARKAL_SETTINGS')) return false; |
|
22 | +define('AMARKAL_SETTINGS', true); |
|
23 | 23 | |
24 | -if(!function_exists('amarkal_add_settings_page')) |
|
24 | +if (!function_exists('amarkal_add_settings_page')) |
|
25 | 25 | { |
26 | 26 | /** |
27 | 27 | * Add a new settings page |
@@ -29,14 +29,14 @@ discard block |
||
29 | 29 | * @param [array] $args |
30 | 30 | * @return void |
31 | 31 | */ |
32 | - function amarkal_add_settings_page( $args ) |
|
32 | + function amarkal_add_settings_page($args) |
|
33 | 33 | { |
34 | 34 | $manager = Amarkal\Settings\Manager::get_instance(); |
35 | 35 | return $manager->add_settings_page($args); |
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
39 | -if(!function_exists('amarkal_get_settings_page')) |
|
39 | +if (!function_exists('amarkal_get_settings_page')) |
|
40 | 40 | { |
41 | 41 | /** |
42 | 42 | * Get a settings page instance |
@@ -44,14 +44,14 @@ discard block |
||
44 | 44 | * @param string $slug |
45 | 45 | * @return Amarkal\Settings\SettingsPage |
46 | 46 | */ |
47 | - function amarkal_get_settings_page( $slug ) |
|
47 | + function amarkal_get_settings_page($slug) |
|
48 | 48 | { |
49 | 49 | $manager = Amarkal\Settings\Manager::get_instance(); |
50 | 50 | return $manager->get_settings_page($slug); |
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | -if(!function_exists('amarkal_get_settings_value')) |
|
54 | +if (!function_exists('amarkal_get_settings_value')) |
|
55 | 55 | { |
56 | 56 | /** |
57 | 57 | * Get the value of the given settings field |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param [array] $args |
60 | 60 | * @return void |
61 | 61 | */ |
62 | - function amarkal_get_settings_value( $slug, $field_name ) |
|
62 | + function amarkal_get_settings_value($slug, $field_name) |
|
63 | 63 | { |
64 | 64 | $manager = Amarkal\Settings\Manager::get_instance(); |
65 | 65 | $page = $manager->get_settings_page($slug); |
@@ -6,13 +6,13 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | // Prevent direct file access |
9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Load module functions. If this amarkal module has not been loaded, |
13 | 13 | * functions.php will not return false. |
14 | 14 | */ |
15 | -if(false !== (require_once 'functions.php')) |
|
15 | +if (false !== (require_once 'functions.php')) |
|
16 | 16 | { |
17 | 17 | // Load required classes if not using composer |
18 | 18 | require_once 'RequestHandler.php'; |
@@ -50,7 +50,6 @@ |
||
50 | 50 | * Get a settings page from the list of registered settings pages. |
51 | 51 | * |
52 | 52 | * @param string $slug |
53 | - * @param string $parent_slug |
|
54 | 53 | * @return SettingsPage |
55 | 54 | * @throws \RuntimeException If no settings page was found for the given slug/parent_slug |
56 | 55 | */ |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public static function get_instance() |
23 | 23 | { |
24 | - if( null === static::$instance ) |
|
24 | + if (null === static::$instance) |
|
25 | 25 | { |
26 | 26 | static::$instance = new static(); |
27 | 27 | } |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | * @param array $args |
35 | 35 | * @throws \RuntimeException |
36 | 36 | */ |
37 | - public function add_settings_page( $args ) |
|
37 | + public function add_settings_page($args) |
|
38 | 38 | { |
39 | 39 | $slug = $args['slug']; |
40 | - if(array_key_exists($slug,$this->settings_pages)) |
|
40 | + if (array_key_exists($slug, $this->settings_pages)) |
|
41 | 41 | { |
42 | 42 | throw new \RuntimeException("A settings page with slug '$slug' has already been registered"); |
43 | 43 | } |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | * @return SettingsPage |
55 | 55 | * @throws \RuntimeException If no settings page was found for the given slug/parent_slug |
56 | 56 | */ |
57 | - public function get_settings_page( $slug ) |
|
57 | + public function get_settings_page($slug) |
|
58 | 58 | { |
59 | - if(!array_key_exists($slug, $this->settings_pages)) |
|
59 | + if (!array_key_exists($slug, $this->settings_pages)) |
|
60 | 60 | { |
61 | 61 | throw new \RuntimeException("The settings page '$slug' does not exist"); |
62 | 62 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | public function register_scripts() |
87 | 87 | { |
88 | 88 | \wp_register_style('amarkal-settings', \Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-settings.min.css')); |
89 | - \wp_register_script('amarkal-settings',\Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/js/dist/amarkal-settings.min.js'),array('amarkal-ui')); |
|
89 | + \wp_register_script('amarkal-settings', \Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/js/dist/amarkal-settings.min.js'), array('amarkal-ui')); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | private function init() |
104 | 104 | { |
105 | - \add_action('admin_init',array($this,'register_scripts')); |
|
105 | + \add_action('admin_init', array($this, 'register_scripts')); |
|
106 | 106 | |
107 | 107 | $rh = RequestHandler::get_instance(); |
108 | 108 | $rh->init(); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public static function get_instance() |
22 | 22 | { |
23 | - if( null === static::$instance ) |
|
23 | + if (null === static::$instance) |
|
24 | 24 | { |
25 | 25 | static::$instance = new static(); |
26 | 26 | } |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | |
30 | 30 | public function init() |
31 | 31 | { |
32 | - \add_action('wp_ajax_amarkal_settings_save', array( $this, 'action_save')); |
|
33 | - \add_action('wp_ajax_amarkal_settings_reset_all', array( $this, 'action_reset_all')); |
|
34 | - \add_action('wp_ajax_amarkal_settings_reset_section', array( $this, 'action_reset_section')); |
|
32 | + \add_action('wp_ajax_amarkal_settings_save', array($this, 'action_save')); |
|
33 | + \add_action('wp_ajax_amarkal_settings_reset_all', array($this, 'action_reset_all')); |
|
34 | + \add_action('wp_ajax_amarkal_settings_reset_section', array($this, 'action_reset_section')); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function action_save() |
38 | 38 | { |
39 | 39 | $this->set_request_data(); |
40 | - $settings_page = $this->get_request_settings_page(); |
|
40 | + $settings_page = $this->get_request_settings_page(); |
|
41 | 41 | |
42 | 42 | \wp_send_json($settings_page->update($this->request_data)); |
43 | 43 | } |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | |
70 | 70 | private function set_request_data() |
71 | 71 | { |
72 | - $this->request_data = filter_input(INPUT_POST,'data',FILTER_DEFAULT,FILTER_REQUIRE_ARRAY); |
|
72 | + $this->request_data = filter_input(INPUT_POST, 'data', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
73 | 73 | $nonce = $this->request_data['_amarkal_settings_nonce']; |
74 | 74 | |
75 | - if( !isset( $nonce ) || |
|
76 | - !\wp_verify_nonce($nonce, self::NONCE_ACTION) ) |
|
75 | + if (!isset($nonce) || |
|
76 | + !\wp_verify_nonce($nonce, self::NONCE_ACTION)) |
|
77 | 77 | { |
78 | 78 | \wp_send_json(array( |
79 | 79 | 'values' => array(), |
@@ -47,15 +47,15 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param array $config |
49 | 49 | */ |
50 | - public function __construct( array $config = array() ) |
|
50 | + public function __construct(array $config = array()) |
|
51 | 51 | { |
52 | 52 | $this->config = array_merge($this->default_args(), $config); |
53 | 53 | $this->fields = new \Amarkal\UI\ComponentList(); |
54 | 54 | $this->sections = array(); |
55 | 55 | $this->form = new \Amarkal\UI\Form($this->fields); |
56 | 56 | |
57 | - \add_action('admin_menu', array($this,'add_submenu_page')); |
|
58 | - \add_action('admin_enqueue_scripts', array($this,'enqueue_scripts')); |
|
57 | + \add_action('admin_menu', array($this, 'add_submenu_page')); |
|
58 | + \add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * @param array $args |
65 | 65 | * @return void |
66 | 66 | */ |
67 | - public function add_section( array $args ) |
|
67 | + public function add_section(array $args) |
|
68 | 68 | { |
69 | 69 | $args = \array_merge($this->default_section_args(), $args); |
70 | 70 | $slug = $args['slug']; |
71 | - if(array_key_exists($slug, $this->sections)) |
|
71 | + if (array_key_exists($slug, $this->sections)) |
|
72 | 72 | { |
73 | 73 | throw new \RuntimeException("A section with '$slug' has already been created for this page."); |
74 | 74 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @param array $args |
82 | 82 | * @return void |
83 | 83 | */ |
84 | - public function add_field( array $args ) |
|
84 | + public function add_field(array $args) |
|
85 | 85 | { |
86 | 86 | $this->fields->add_component($args); |
87 | 87 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function get_field_values() |
95 | 95 | { |
96 | - if(!isset($this->values)) |
|
96 | + if (!isset($this->values)) |
|
97 | 97 | { |
98 | 98 | $this->values = array_merge($this->form->reset(), $this->get_old_instance()); |
99 | 99 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @param string $name |
107 | 107 | * @return any |
108 | 108 | */ |
109 | - public function get_field_value( $name ) |
|
109 | + public function get_field_value($name) |
|
110 | 110 | { |
111 | 111 | $values = $this->get_field_values(); |
112 | 112 | return $values[$name]; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | public function enqueue_scripts() |
135 | 135 | { |
136 | 136 | // Only enqueue styles & scripts if this is a settings page |
137 | - if($this->config['slug'] === filter_input(INPUT_GET, 'page')) |
|
137 | + if ($this->config['slug'] === filter_input(INPUT_GET, 'page')) |
|
138 | 138 | { |
139 | 139 | \wp_enqueue_style('amarkal-settings'); |
140 | 140 | \wp_enqueue_script('amarkal-settings'); |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * @param array $new_instance |
159 | 159 | * @return array |
160 | 160 | */ |
161 | - public function update( $new_instance ) |
|
161 | + public function update($new_instance) |
|
162 | 162 | { |
163 | - if($this->can_update()) |
|
163 | + if ($this->can_update()) |
|
164 | 164 | { |
165 | 165 | $old_instance = $this->get_old_instance(); |
166 | 166 | $this->values = $this->form->update($new_instance, $old_instance); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function reset() |
187 | 187 | { |
188 | - if($this->can_update()) |
|
188 | + if ($this->can_update()) |
|
189 | 189 | { |
190 | 190 | \delete_option($this->config['slug']); |
191 | 191 | $this->values = $this->form->reset(); |
@@ -207,9 +207,9 @@ discard block |
||
207 | 207 | * @param string $slug |
208 | 208 | * @return void |
209 | 209 | */ |
210 | - public function reset_section( $slug ) |
|
210 | + public function reset_section($slug) |
|
211 | 211 | { |
212 | - if($this->can_update()) |
|
212 | + if ($this->can_update()) |
|
213 | 213 | { |
214 | 214 | $old_instance = $this->get_old_instance(); |
215 | 215 | $final_instance = $this->form->reset_components($this->get_section_fields($slug)); |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | private function get_section_fields($slug) |
259 | 259 | { |
260 | 260 | $fields = array(); |
261 | - foreach($this->fields->get_all() as $c) |
|
261 | + foreach ($this->fields->get_all() as $c) |
|
262 | 262 | { |
263 | - if($c->section === $slug) |
|
263 | + if ($c->section === $slug) |
|
264 | 264 | { |
265 | 265 | $fields[] = $c; |
266 | 266 | } |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | private function get_errors() |
277 | 277 | { |
278 | 278 | $errors = array(); |
279 | - foreach($this->form->get_errors() as $name => $error) |
|
279 | + foreach ($this->form->get_errors() as $name => $error) |
|
280 | 280 | { |
281 | 281 | $errors[$name] = $error; |
282 | 282 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @param array $values The list of values |
291 | 291 | * @return array |
292 | 292 | */ |
293 | - private function results_array( $errors = array(), $values = '' ) |
|
293 | + private function results_array($errors = array(), $values = '') |
|
294 | 294 | { |
295 | 295 | return array( |
296 | 296 | 'values' => $values, |