@@ -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'; |
@@ -6,11 +6,11 @@ |
||
6 | 6 | { |
7 | 7 | private $config; |
8 | 8 | |
9 | - public function __construct( array $args = array() ) |
|
9 | + public function __construct(array $args = array()) |
|
10 | 10 | { |
11 | 11 | $this->config = array_merge($this->default_args(), $args); |
12 | 12 | |
13 | - \add_action('admin_menu', array($this,'add_menu_page')); |
|
13 | + \add_action('admin_menu', array($this, 'add_menu_page')); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | public function add_menu_page() |
@@ -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')) |
@@ -13,26 +13,26 @@ |
||
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 | - function amarkal_add_settings_page( $args ) |
|
26 | + function amarkal_add_settings_page($args) |
|
27 | 27 | { |
28 | 28 | $manager = Amarkal\Settings\Manager::get_instance(); |
29 | 29 | $manager->add_page($args); |
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | -if(!function_exists('amarkal_add_settings_child_page')) |
|
33 | +if (!function_exists('amarkal_add_settings_child_page')) |
|
34 | 34 | { |
35 | - function amarkal_add_settings_child_page( $args ) |
|
35 | + function amarkal_add_settings_child_page($args) |
|
36 | 36 | { |
37 | 37 | $manager = Amarkal\Settings\Manager::get_instance(); |
38 | 38 | $manager->add_child_page($args); |
@@ -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,14 +29,14 @@ discard block |
||
29 | 29 | |
30 | 30 | public function init() |
31 | 31 | { |
32 | - \add_action('wp_ajax_amarkal_settings_save', array( $this, 'save_settings')); |
|
33 | - \add_action('wp_ajax_amarkal_settings_reset', array( $this, 'reset_settings')); |
|
32 | + \add_action('wp_ajax_amarkal_settings_save', array($this, 'save_settings')); |
|
33 | + \add_action('wp_ajax_amarkal_settings_reset', array($this, 'reset_settings')); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | public function save_settings() |
37 | 37 | { |
38 | 38 | $this->set_request_data(); |
39 | - $child_page = $this->get_request_child_page(); |
|
39 | + $child_page = $this->get_request_child_page(); |
|
40 | 40 | |
41 | 41 | \wp_send_json($child_page->update($this->request_data)); |
42 | 42 | } |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | |
61 | 61 | private function set_request_data() |
62 | 62 | { |
63 | - \parse_str(filter_input(INPUT_POST,'data'),$this->request_data); |
|
63 | + \parse_str(filter_input(INPUT_POST, 'data'), $this->request_data); |
|
64 | 64 | $nonce = $this->request_data['_amarkal_settings_nonce']; |
65 | 65 | |
66 | - if( !isset( $nonce ) || |
|
67 | - !\wp_verify_nonce($nonce, self::NONCE_ACTION) ) |
|
66 | + if (!isset($nonce) || |
|
67 | + !\wp_verify_nonce($nonce, self::NONCE_ACTION)) |
|
68 | 68 | { |
69 | 69 | \wp_send_json(array( |
70 | 70 | 'values' => array(), |
@@ -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 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public function add_page($args) |
37 | 37 | { |
38 | 38 | $slug = $args['slug']; |
39 | - if(array_key_exists($slug,$this->pages)) |
|
39 | + if (array_key_exists($slug, $this->pages)) |
|
40 | 40 | { |
41 | 41 | throw new \RuntimeException("A page with slug '$slug' has already been registered"); |
42 | 42 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function get_page($slug) |
54 | 54 | { |
55 | - if(!array_key_exists($slug,$this->pages)) |
|
55 | + if (!array_key_exists($slug, $this->pages)) |
|
56 | 56 | { |
57 | 57 | throw new \RuntimeException("The page '$slug' does not exist"); |
58 | 58 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function add_child_page($args) |
68 | 68 | { |
69 | 69 | $parent_slug = $args['parent_slug']; |
70 | - if(!array_key_exists($parent_slug, $this->child_pages)) |
|
70 | + if (!array_key_exists($parent_slug, $this->child_pages)) |
|
71 | 71 | { |
72 | 72 | $this->child_pages[$parent_slug] = array(); |
73 | 73 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function get_child_page($slug, $parent_slug) |
86 | 86 | { |
87 | - if(!array_key_exists($parent_slug, $this->child_pages) || |
|
87 | + if (!array_key_exists($parent_slug, $this->child_pages) || |
|
88 | 88 | !array_key_exists($slug, $this->child_pages[$parent_slug])) |
89 | 89 | { |
90 | 90 | throw new \RuntimeException("The child page '$slug' does not exist for the parent '$parent_slug'"); |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function register_scripts() |
99 | 99 | { |
100 | - \wp_register_style('amarkal-settings',$this->get_url(__DIR__.'/assets/css/dist/amarkal-settings.min.css')); |
|
101 | - \wp_register_script('amarkal-settings',$this->get_url(__DIR__.'/assets/js/dist/amarkal-settings.min.js'),array('amarkal-ui')); |
|
100 | + \wp_register_style('amarkal-settings', $this->get_url(__DIR__.'/assets/css/dist/amarkal-settings.min.css')); |
|
101 | + \wp_register_script('amarkal-settings', $this->get_url(__DIR__.'/assets/js/dist/amarkal-settings.min.js'), array('amarkal-ui')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | private function init() |
116 | 116 | { |
117 | - \add_action('admin_init',array($this,'register_scripts')); |
|
117 | + \add_action('admin_init', array($this, 'register_scripts')); |
|
118 | 118 | |
119 | 119 | $rh = RequestHandler::get_instance(); |
120 | 120 | $rh->init(); |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | * @param string $path |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - private function get_url( $path ) |
|
129 | + private function get_url($path) |
|
130 | 130 | { |
131 | - $url = str_replace( ABSPATH, '', $path ); |
|
132 | - return esc_url_raw( site_url( $url ) ); |
|
131 | + $url = str_replace(ABSPATH, '', $path); |
|
132 | + return esc_url_raw(site_url($url)); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | \ No newline at end of file |
@@ -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'; |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param array $config |
26 | 26 | */ |
27 | - public function __construct( array $config = array() ) |
|
27 | + public function __construct(array $config = array()) |
|
28 | 28 | { |
29 | 29 | $this->config = array_merge($this->default_args(), $config); |
30 | 30 | $this->form = new \Amarkal\UI\Form($this->config['fields']); |
31 | 31 | |
32 | - \add_action('admin_menu', array($this,'add_submenu_page')); |
|
33 | - \add_action('admin_enqueue_scripts', array($this,'enqueue_scripts')); |
|
32 | + \add_action('admin_menu', array($this, 'add_submenu_page')); |
|
33 | + \add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function enqueue_scripts() |
56 | 56 | { |
57 | 57 | // Only enqueue styles & scripts if this is a settings page |
58 | - if($this->config['slug'] === filter_input(INPUT_GET, 'page')) |
|
58 | + if ($this->config['slug'] === filter_input(INPUT_GET, 'page')) |
|
59 | 59 | { |
60 | 60 | \wp_enqueue_style('amarkal-settings'); |
61 | 61 | \wp_enqueue_script('amarkal-settings'); |
@@ -79,15 +79,15 @@ discard block |
||
79 | 79 | * @param array $new_instance |
80 | 80 | * @return array |
81 | 81 | */ |
82 | - public function update( $new_instance ) |
|
82 | + public function update($new_instance) |
|
83 | 83 | { |
84 | - if($this->can_update()) |
|
84 | + if ($this->can_update()) |
|
85 | 85 | { |
86 | 86 | $old_instance = $this->get_old_instance(); |
87 | 87 | $final_instance = $this->form->update($new_instance, $old_instance); |
88 | - foreach($final_instance as $name => $value) |
|
88 | + foreach ($final_instance as $name => $value) |
|
89 | 89 | { |
90 | - \update_option($name,$value); |
|
90 | + \update_option($name, $value); |
|
91 | 91 | } |
92 | 92 | return $this->results_array( |
93 | 93 | $this->get_errors(), |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function reset() |
109 | 109 | { |
110 | - if($this->can_update()) |
|
110 | + if ($this->can_update()) |
|
111 | 111 | { |
112 | - foreach($this->config['fields'] as $field) |
|
112 | + foreach ($this->config['fields'] as $field) |
|
113 | 113 | { |
114 | 114 | \delete_option($field['name']); |
115 | 115 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | private function get_errors() |
140 | 140 | { |
141 | 141 | $errors = array(); |
142 | - foreach($this->form->get_errors() as $name => $error) |
|
142 | + foreach ($this->form->get_errors() as $name => $error) |
|
143 | 143 | { |
144 | 144 | $component = $this->form->get_component($name); |
145 | 145 | $errors[] = array( |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param array $values The list of values |
158 | 158 | * @return array |
159 | 159 | */ |
160 | - private function results_array( $errors = array(), $values = '' ) |
|
160 | + private function results_array($errors = array(), $values = '') |
|
161 | 161 | { |
162 | 162 | return array( |
163 | 163 | 'values' => $values, |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | private function get_old_instance() |
185 | 185 | { |
186 | 186 | $old_instance = array(); |
187 | - foreach($this->form->get_components() as $component) |
|
187 | + foreach ($this->form->get_components() as $component) |
|
188 | 188 | { |
189 | 189 | $old_instance[$component->name] = \get_option($component->name, $component->default); |
190 | 190 | } |