@@ -15,103 +15,103 @@ |
||
15 | 15 | * @subpackage Http |
16 | 16 | */ |
17 | 17 | class Guard implements GuardContract { |
18 | - /** |
|
19 | - * Default options. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $defaults = array( |
|
24 | - 'rule' => 'public', |
|
25 | - 'callback' => null, |
|
26 | - ); |
|
18 | + /** |
|
19 | + * Default options. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $defaults = array( |
|
24 | + 'rule' => 'public', |
|
25 | + 'callback' => null, |
|
26 | + ); |
|
27 | 27 | |
28 | - /** |
|
29 | - * Guard options. |
|
30 | - * |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $options; |
|
28 | + /** |
|
29 | + * Guard options. |
|
30 | + * |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $options; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Instantiate a new Guard with provided options. |
|
37 | - * |
|
38 | - * @param array $options |
|
39 | - */ |
|
40 | - public function __construct( array $options = array() ) { |
|
41 | - $this->options = $this->set_defaults( $options ); |
|
42 | - } |
|
35 | + /** |
|
36 | + * Instantiate a new Guard with provided options. |
|
37 | + * |
|
38 | + * @param array $options |
|
39 | + */ |
|
40 | + public function __construct( array $options = array() ) { |
|
41 | + $this->options = $this->set_defaults( $options ); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Validates whether the current user is authorized. |
|
46 | - * |
|
47 | - * @return true|WP_Error |
|
48 | - */ |
|
49 | - public function authorized() { |
|
50 | - // if the rule is public, always authorized |
|
51 | - if ( 'public' === $this->options['rule'] ) { |
|
52 | - return true; |
|
53 | - } |
|
44 | + /** |
|
45 | + * Validates whether the current user is authorized. |
|
46 | + * |
|
47 | + * @return true|WP_Error |
|
48 | + */ |
|
49 | + public function authorized() { |
|
50 | + // if the rule is public, always authorized |
|
51 | + if ( 'public' === $this->options['rule'] ) { |
|
52 | + return true; |
|
53 | + } |
|
54 | 54 | |
55 | - // enable passing in callback |
|
56 | - if ( 'callback' === $this->options['rule'] && is_callable( $this->options['callback'] ) ) { |
|
57 | - return call_user_func( $this->options['callback'] ); |
|
58 | - } |
|
55 | + // enable passing in callback |
|
56 | + if ( 'callback' === $this->options['rule'] && is_callable( $this->options['callback'] ) ) { |
|
57 | + return call_user_func( $this->options['callback'] ); |
|
58 | + } |
|
59 | 59 | |
60 | - // map rule to method |
|
61 | - if ( method_exists( $this, $method = $this->options['rule'] ) ) { |
|
62 | - return $this->{$method}(); |
|
63 | - } |
|
60 | + // map rule to method |
|
61 | + if ( method_exists( $this, $method = $this->options['rule'] ) ) { |
|
62 | + return $this->{$method}(); |
|
63 | + } |
|
64 | 64 | |
65 | - // disable in rule is misconfigused |
|
66 | - // @todo set up internal translations |
|
67 | - return new WP_Error( 'misconfigured_guard', __( 'Misconfigured guard rule', 'jaxion' ), [ 'status' => 500 ] ); |
|
68 | - } |
|
65 | + // disable in rule is misconfigused |
|
66 | + // @todo set up internal translations |
|
67 | + return new WP_Error( 'misconfigured_guard', __( 'Misconfigured guard rule', 'jaxion' ), [ 'status' => 500 ] ); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Checks whether the current user can edit other's posts. |
|
72 | - * |
|
73 | - * @return bool|WP_Error |
|
74 | - */ |
|
75 | - protected function can_edit_others_posts() { |
|
76 | - return current_user_can( 'edit_others_posts' ) ?: $this->make_error(); |
|
77 | - } |
|
70 | + /** |
|
71 | + * Checks whether the current user can edit other's posts. |
|
72 | + * |
|
73 | + * @return bool|WP_Error |
|
74 | + */ |
|
75 | + protected function can_edit_others_posts() { |
|
76 | + return current_user_can( 'edit_others_posts' ) ?: $this->make_error(); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Checks whether the user is currently logged in. |
|
81 | - * |
|
82 | - * @return bool|WP_Error |
|
83 | - */ |
|
84 | - protected function user_logged_in() { |
|
85 | - return is_user_logged_in() ?: $this->make_error(); |
|
86 | - } |
|
79 | + /** |
|
80 | + * Checks whether the user is currently logged in. |
|
81 | + * |
|
82 | + * @return bool|WP_Error |
|
83 | + */ |
|
84 | + protected function user_logged_in() { |
|
85 | + return is_user_logged_in() ?: $this->make_error(); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Checks whether the user can manage the site options. |
|
90 | - * |
|
91 | - * @return bool|WP_Error |
|
92 | - */ |
|
93 | - protected function can_manage_options() { |
|
94 | - return current_user_can( 'manage_options' ) ?: $this->make_error(); |
|
95 | - } |
|
88 | + /** |
|
89 | + * Checks whether the user can manage the site options. |
|
90 | + * |
|
91 | + * @return bool|WP_Error |
|
92 | + */ |
|
93 | + protected function can_manage_options() { |
|
94 | + return current_user_can( 'manage_options' ) ?: $this->make_error(); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Sets the default params for the Guard options. |
|
99 | - * |
|
100 | - * @param array $options |
|
101 | - * |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - protected function set_defaults( $options ) { |
|
105 | - // these are the valid options |
|
106 | - return wp_parse_args( $options, $this->defaults ); |
|
107 | - } |
|
97 | + /** |
|
98 | + * Sets the default params for the Guard options. |
|
99 | + * |
|
100 | + * @param array $options |
|
101 | + * |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + protected function set_defaults( $options ) { |
|
105 | + // these are the valid options |
|
106 | + return wp_parse_args( $options, $this->defaults ); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Create an unauthorized error object. |
|
111 | - * |
|
112 | - * @return WP_Error |
|
113 | - */ |
|
114 | - protected function make_error() { |
|
115 | - return new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) ); |
|
116 | - } |
|
109 | + /** |
|
110 | + * Create an unauthorized error object. |
|
111 | + * |
|
112 | + * @return WP_Error |
|
113 | + */ |
|
114 | + protected function make_error() { |
|
115 | + return new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) ); |
|
116 | + } |
|
117 | 117 | } |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param array $options |
39 | 39 | */ |
40 | - public function __construct( array $options = array() ) { |
|
41 | - $this->options = $this->set_defaults( $options ); |
|
40 | + public function __construct(array $options = array()) { |
|
41 | + $this->options = $this->set_defaults($options); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,23 +48,23 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function authorized() { |
50 | 50 | // if the rule is public, always authorized |
51 | - if ( 'public' === $this->options['rule'] ) { |
|
51 | + if ('public' === $this->options['rule']) { |
|
52 | 52 | return true; |
53 | 53 | } |
54 | 54 | |
55 | 55 | // enable passing in callback |
56 | - if ( 'callback' === $this->options['rule'] && is_callable( $this->options['callback'] ) ) { |
|
57 | - return call_user_func( $this->options['callback'] ); |
|
56 | + if ('callback' === $this->options['rule'] && is_callable($this->options['callback'])) { |
|
57 | + return call_user_func($this->options['callback']); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // map rule to method |
61 | - if ( method_exists( $this, $method = $this->options['rule'] ) ) { |
|
61 | + if (method_exists($this, $method = $this->options['rule'])) { |
|
62 | 62 | return $this->{$method}(); |
63 | 63 | } |
64 | 64 | |
65 | 65 | // disable in rule is misconfigused |
66 | 66 | // @todo set up internal translations |
67 | - return new WP_Error( 'misconfigured_guard', __( 'Misconfigured guard rule', 'jaxion' ), [ 'status' => 500 ] ); |
|
67 | + return new WP_Error('misconfigured_guard', __('Misconfigured guard rule', 'jaxion'), ['status' => 500]); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return bool|WP_Error |
74 | 74 | */ |
75 | 75 | protected function can_edit_others_posts() { |
76 | - return current_user_can( 'edit_others_posts' ) ?: $this->make_error(); |
|
76 | + return current_user_can('edit_others_posts') ?: $this->make_error(); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return bool|WP_Error |
92 | 92 | */ |
93 | 93 | protected function can_manage_options() { |
94 | - return current_user_can( 'manage_options' ) ?: $this->make_error(); |
|
94 | + return current_user_can('manage_options') ?: $this->make_error(); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return array |
103 | 103 | */ |
104 | - protected function set_defaults( $options ) { |
|
104 | + protected function set_defaults($options) { |
|
105 | 105 | // these are the valid options |
106 | - return wp_parse_args( $options, $this->defaults ); |
|
106 | + return wp_parse_args($options, $this->defaults); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -112,6 +112,6 @@ discard block |
||
112 | 112 | * @return WP_Error |
113 | 113 | */ |
114 | 114 | protected function make_error() { |
115 | - return new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) ); |
|
115 | + return new WP_Error('unauthorized', __('Unauthorized user', 'jaxion'), array('status' => 401)); |
|
116 | 116 | } |
117 | 117 | } |