Completed
Push — master ( bc1ad9...b87221 )
by Askupa
01:45
created
functions.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,6 @@
 block discarded – undo
41 41
     /**
42 42
      * Get the value of the given settings
43 43
      *
44
-     * @param [array] $args
45 44
      * @return void
46 45
      */
47 46
     function amarkal_get_settings_value( $slug, $field_name )
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@  discard block
 block discarded – undo
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 top-level settings page
@@ -29,14 +29,14 @@  discard block
 block discarded – undo
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_value'))
39
+if (!function_exists('amarkal_get_settings_value'))
40 40
 {
41 41
     /**
42 42
      * Get the value of the given settings
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @param [array] $args
45 45
      * @return void
46 46
      */
47
-    function amarkal_get_settings_value( $slug, $field_name )
47
+    function amarkal_get_settings_value($slug, $field_name)
48 48
     {
49 49
         $manager = Amarkal\Settings\Manager::get_instance();
50 50
         return $manager->get_field_value($slug, $field_name);
Please login to merge, or discard this patch.
Manager.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,6 @@
 block discarded – undo
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
      */
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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();
Please login to merge, or discard this patch.
RequestHandler.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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(),
Please login to merge, or discard this patch.
SettingsPage.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
      * 
41 41
      * @param array $config
42 42
      */
43
-    public function __construct( array $config = array() ) 
43
+    public function __construct(array $config = array()) 
44 44
     {
45 45
         $this->config   = array_merge($this->default_args(), $config);
46 46
         $this->fields   = new \Amarkal\UI\ComponentList();
47 47
         $this->sections = array();
48 48
         $this->form     = new \Amarkal\UI\Form($this->fields);
49 49
         
50
-        \add_action('admin_menu', array($this,'add_submenu_page'));
51
-        \add_action('admin_enqueue_scripts', array($this,'enqueue_scripts'));
50
+        \add_action('admin_menu', array($this, 'add_submenu_page'));
51
+        \add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
52 52
     }
53 53
 
54 54
     /**
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
      * @param array $args
58 58
      * @return void
59 59
      */
60
-    public function add_section( array $args )
60
+    public function add_section(array $args)
61 61
     {
62 62
         $args = \array_merge($this->default_section_args(), $args);
63 63
         $slug = $args['slug'];
64
-        if(array_key_exists($slug, $this->sections))
64
+        if (array_key_exists($slug, $this->sections))
65 65
         {
66 66
             throw new \RuntimeException("A section with '$slug' has already been created for this page.");  
67 67
         }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      * @param array $args
75 75
      * @return void
76 76
      */
77
-    public function add_field( array $args )
77
+    public function add_field(array $args)
78 78
     {
79 79
         $this->fields->add_component($args);
80 80
     }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     public function enqueue_scripts()
102 102
     {
103 103
         // Only enqueue styles & scripts if this is a settings page
104
-        if($this->config['slug'] === filter_input(INPUT_GET, 'page'))
104
+        if ($this->config['slug'] === filter_input(INPUT_GET, 'page'))
105 105
         {
106 106
             \wp_enqueue_style('amarkal-settings');
107 107
             \wp_enqueue_script('amarkal-settings');
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
      * @param array $new_instance
126 126
      * @return array
127 127
      */
128
-    public function update( $new_instance )
128
+    public function update($new_instance)
129 129
     {
130
-        if($this->can_update())
130
+        if ($this->can_update())
131 131
         {
132 132
             $old_instance = $this->get_old_instance();
133 133
             $final_instance = $this->form->update($new_instance, $old_instance);
134 134
             
135
-            \update_option($this->config['slug'],$final_instance);
135
+            \update_option($this->config['slug'], $final_instance);
136 136
 
137 137
             return $this->results_array(
138 138
                 $this->get_errors(),
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function reset()
154 154
     {
155
-        if($this->can_update())
155
+        if ($this->can_update())
156 156
         {
157 157
             \delete_option($this->config['slug']);
158 158
 
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
      * @param string $slug
174 174
      * @return void
175 175
      */
176
-    public function reset_section( $slug ) 
176
+    public function reset_section($slug) 
177 177
     {
178
-        if($this->can_update())
178
+        if ($this->can_update())
179 179
         {
180 180
             $old_instance = $this->get_old_instance();
181 181
             $final_instance = $this->form->reset_components($this->get_section_fields($slug));
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
     private function get_section_fields($slug)
226 226
     {
227 227
         $fields = array();
228
-        foreach($this->fields->get_all() as $c)
228
+        foreach ($this->fields->get_all() as $c)
229 229
         {
230
-            if($c->section === $slug)
230
+            if ($c->section === $slug)
231 231
             {
232 232
                 $fields[] = $c;
233 233
             }
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     private function get_errors()
244 244
     {
245 245
         $errors = array();
246
-        foreach($this->form->get_errors() as $name => $error)
246
+        foreach ($this->form->get_errors() as $name => $error)
247 247
         {
248 248
             $errors[$name] = $error;
249 249
         }
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
      * @param array $values The list of values
258 258
      * @return array
259 259
      */
260
-    private function results_array( $errors = array(), $values = '' )
260
+    private function results_array($errors = array(), $values = '')
261 261
     {
262 262
         return array(
263 263
             'values' => $values,
Please login to merge, or discard this patch.