@@ -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'; |
@@ -13,13 +13,13 @@ discard block |
||
13 | 13 | |
14 | 14 | private $form; |
15 | 15 | |
16 | - public function __construct( array $args = array() ) |
|
16 | + public function __construct(array $args = array()) |
|
17 | 17 | { |
18 | 18 | $this->config = array_merge($this->default_args(), $args); |
19 | 19 | $this->form = new \Amarkal\UI\Form($this->config['fields']); |
20 | 20 | |
21 | - \add_action('admin_menu', array($this,'add_submenu_page')); |
|
22 | - \add_action('admin_enqueue_scripts', array($this,'enqueue_scripts')); |
|
21 | + \add_action('admin_menu', array($this, 'add_submenu_page')); |
|
22 | + \add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function add_submenu_page() |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public function enqueue_scripts() |
38 | 38 | { |
39 | 39 | // Only enqueue styles & scripts if this is a settings page |
40 | - if($this->config['slug'] === filter_input(INPUT_GET, 'page')) |
|
40 | + if ($this->config['slug'] === filter_input(INPUT_GET, 'page')) |
|
41 | 41 | { |
42 | 42 | \wp_enqueue_style('amarkal-settings'); |
43 | 43 | \wp_enqueue_script('amarkal-settings'); |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | \add_filter('admin_footer_text', array($this, 'footer_credits')); |
52 | 52 | } |
53 | 53 | |
54 | - public function update( $new_instance ) |
|
54 | + public function update($new_instance) |
|
55 | 55 | { |
56 | - if($this->can_update()) |
|
56 | + if ($this->can_update()) |
|
57 | 57 | { |
58 | 58 | $old_instance = $this->get_old_instance(); |
59 | 59 | $final_instance = $this->form->update($new_instance, $old_instance); |
60 | - foreach($final_instance as $name => $value) |
|
60 | + foreach ($final_instance as $name => $value) |
|
61 | 61 | { |
62 | - \update_option($name,$value); |
|
62 | + \update_option($name, $value); |
|
63 | 63 | } |
64 | 64 | return $this->results_array( |
65 | 65 | $this->get_errors(), |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | |
74 | 74 | public function reset() |
75 | 75 | { |
76 | - if($this->can_update()) |
|
76 | + if ($this->can_update()) |
|
77 | 77 | { |
78 | - foreach($this->config['fields'] as $field) |
|
78 | + foreach ($this->config['fields'] as $field) |
|
79 | 79 | { |
80 | 80 | \delete_option($field['name']); |
81 | 81 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | private function get_errors() |
101 | 101 | { |
102 | 102 | $errors = array(); |
103 | - foreach($this->form->get_errors() as $name => $error) |
|
103 | + foreach ($this->form->get_errors() as $name => $error) |
|
104 | 104 | { |
105 | 105 | $component = $this->form->get_component($name); |
106 | 106 | $errors[] = "<strong>{$component->title}</strong> $error"; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | return $errors; |
109 | 109 | } |
110 | 110 | |
111 | - private function results_array( $errors = array(), $values = '' ) |
|
111 | + private function results_array($errors = array(), $values = '') |
|
112 | 112 | { |
113 | 113 | return array( |
114 | 114 | 'values' => $values, |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | private function get_old_instance() |
125 | 125 | { |
126 | 126 | $old_instance = array(); |
127 | - foreach($this->form->get_components() as $component) |
|
127 | + foreach ($this->form->get_components() as $component) |
|
128 | 128 | { |
129 | 129 | $old_instance[$component->name] = \get_option($component->name, $component->default); |
130 | 130 | } |