@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @type string $slug The slug of this rank type. |
76 | 76 | * } |
77 | 77 | */ |
78 | - public function __construct( array $args ) { |
|
78 | + public function __construct(array $args) { |
|
79 | 79 | |
80 | 80 | $this->slug = $args['slug']; |
81 | 81 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return array|WP_Error|false The validated metadata, or false or a WP_Error |
110 | 110 | * if it should't be saved. |
111 | 111 | */ |
112 | - abstract public function validate_rank_meta( array $meta ); |
|
112 | + abstract public function validate_rank_meta(array $meta); |
|
113 | 113 | |
114 | 114 | /** |
115 | 115 | * Determine if a user meets the requirements for a rank of this type. |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return bool Whether the user meets the requirements for this rank. |
128 | 128 | */ |
129 | - abstract protected function can_transition_user_rank( $user_id, $rank, array $args ); |
|
129 | + abstract protected function can_transition_user_rank($user_id, $rank, array $args); |
|
130 | 130 | |
131 | 131 | // |
132 | 132 | // Final Public Methods. |
@@ -185,47 +185,47 @@ discard block |
||
185 | 185 | array $args = array() |
186 | 186 | ) { |
187 | 187 | |
188 | - $args = array_merge( array( 'placeholders' => false ), $args ); |
|
188 | + $args = array_merge(array('placeholders' => false), $args); |
|
189 | 189 | |
190 | - foreach ( $this->meta_fields as $name => $field ) { |
|
190 | + foreach ($this->meta_fields as $name => $field) { |
|
191 | 191 | |
192 | 192 | // If we aren't using placeholders, calculate the value. Hidden fields |
193 | 193 | // never use placeholders. |
194 | - if ( ! $args['placeholders'] || 'hidden' === $field['type'] ) { |
|
194 | + if ( ! $args['placeholders'] || 'hidden' === $field['type']) { |
|
195 | 195 | |
196 | 196 | // Default to the default value. |
197 | 197 | $value = $field['default']; |
198 | 198 | |
199 | 199 | // If the value is set use that instead. |
200 | - if ( isset( $meta[ $name ] ) ) { |
|
201 | - $value = $meta[ $name ]; |
|
200 | + if (isset($meta[$name])) { |
|
201 | + $value = $meta[$name]; |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - switch ( $field['type'] ) { |
|
205 | + switch ($field['type']) { |
|
206 | 206 | |
207 | 207 | case 'hidden': |
208 | 208 | case 'number': |
209 | 209 | case 'text': |
210 | - if ( isset( $field['label'] ) ) { |
|
210 | + if (isset($field['label'])) { |
|
211 | 211 | ?><p class="description description-thin"><label><?php |
212 | - echo esc_html( $field['label'] ); |
|
212 | + echo esc_html($field['label']); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | ?> |
216 | 216 | <input |
217 | - type="<?php echo esc_attr( $field['type'] ); ?>" |
|
218 | - name="<?php echo esc_attr( $name ); ?>" |
|
219 | - <?php if ( $args['placeholders'] && 'hidden' !== $field['type'] ) : ?> |
|
220 | - value="<% if ( typeof <?php echo preg_replace( '/[^a-z0-9_]/i', '', $name ); // WPCS: XSS OK ?> !== "undefined" ) { print( <?php echo preg_replace( '/[^a-z0-9_]/i', '', $name ); // WPCS: XSS OK ?> ); } %>" |
|
217 | + type="<?php echo esc_attr($field['type']); ?>" |
|
218 | + name="<?php echo esc_attr($name); ?>" |
|
219 | + <?php if ($args['placeholders'] && 'hidden' !== $field['type']) : ?> |
|
220 | + value="<% if ( typeof <?php echo preg_replace('/[^a-z0-9_]/i', '', $name); // WPCS: XSS OK ?> !== "undefined" ) { print( <?php echo preg_replace('/[^a-z0-9_]/i', '', $name); // WPCS: XSS OK ?> ); } %>" |
|
221 | 221 | <?php else : ?> |
222 | - value="<?php echo esc_attr( $value ); ?>" |
|
222 | + value="<?php echo esc_attr($value); ?>" |
|
223 | 223 | <?php endif; ?> |
224 | 224 | class="widefat" |
225 | 225 | /> |
226 | 226 | <?php |
227 | 227 | |
228 | - if ( isset( $field['label'] ) ) { |
|
228 | + if (isset($field['label'])) { |
|
229 | 229 | ?></label></p><?php |
230 | 230 | } |
231 | 231 | break; |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | __METHOD__ |
236 | 236 | , sprintf( |
237 | 237 | 'WordPoints Error: Unknown field type "%s".' |
238 | - , esc_html( $field['type'] ) |
|
238 | + , esc_html($field['type']) |
|
239 | 239 | ) |
240 | 240 | , '1.7.0' |
241 | 241 | ); |
@@ -256,21 +256,21 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return WordPoints_Rank The highest rank that the user can be increased to. |
258 | 258 | */ |
259 | - final public function maybe_increase_user_rank( $user_id, $rank, array $args = array() ) { |
|
259 | + final public function maybe_increase_user_rank($user_id, $rank, array $args = array()) { |
|
260 | 260 | |
261 | - $next_rank = $rank->get_adjacent( 1 ); |
|
261 | + $next_rank = $rank->get_adjacent(1); |
|
262 | 262 | |
263 | - if ( ! $next_rank ) { |
|
263 | + if ( ! $next_rank) { |
|
264 | 264 | return $rank; |
265 | 265 | } |
266 | 266 | |
267 | - $rank_type = WordPoints_Rank_Types::get_type( $next_rank->type ); |
|
267 | + $rank_type = WordPoints_Rank_Types::get_type($next_rank->type); |
|
268 | 268 | |
269 | - if ( ! $rank_type->can_transition_user_rank( $user_id, $next_rank, $args ) ) { |
|
269 | + if ( ! $rank_type->can_transition_user_rank($user_id, $next_rank, $args)) { |
|
270 | 270 | return $rank; |
271 | 271 | } |
272 | 272 | |
273 | - return $this->maybe_increase_user_rank( $user_id, $next_rank, $args ); |
|
273 | + return $this->maybe_increase_user_rank($user_id, $next_rank, $args); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | * |
285 | 285 | * @return WordPoints_Rank The highest rank that the user can have. |
286 | 286 | */ |
287 | - final public function maybe_decrease_user_rank( $user_id, $rank, array $args = array() ) { |
|
287 | + final public function maybe_decrease_user_rank($user_id, $rank, array $args = array()) { |
|
288 | 288 | |
289 | - $rank_type = WordPoints_Rank_Types::get_type( $rank->type ); |
|
289 | + $rank_type = WordPoints_Rank_Types::get_type($rank->type); |
|
290 | 290 | |
291 | - if ( $rank_type->can_transition_user_rank( $user_id, $rank, $args ) ) { |
|
291 | + if ($rank_type->can_transition_user_rank($user_id, $rank, $args)) { |
|
292 | 292 | return $rank; |
293 | 293 | } |
294 | 294 | |
295 | 295 | $previous_rank = $rank->get_adjacent( -1 ); |
296 | 296 | |
297 | - if ( ! $previous_rank ) { |
|
297 | + if ( ! $previous_rank) { |
|
298 | 298 | return $rank; |
299 | 299 | } |
300 | 300 | |
301 | - return $this->maybe_decrease_user_rank( $user_id, $previous_rank, $args ); |
|
301 | + return $this->maybe_decrease_user_rank($user_id, $previous_rank, $args); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | // |
@@ -322,28 +322,28 @@ discard block |
||
322 | 322 | |
323 | 323 | $groups = WordPoints_Rank_Groups::get(); |
324 | 324 | |
325 | - foreach ( $groups as $group_slug => $group ) { |
|
325 | + foreach ($groups as $group_slug => $group) { |
|
326 | 326 | |
327 | - if ( ! WordPoints_Rank_Groups::is_type_registered_for_group( $this->slug, $group_slug ) ) { |
|
327 | + if ( ! WordPoints_Rank_Groups::is_type_registered_for_group($this->slug, $group_slug)) { |
|
328 | 328 | continue; |
329 | 329 | } |
330 | 330 | |
331 | - $rank_id = wordpoints_get_user_rank( $user_id, $group_slug ); |
|
331 | + $rank_id = wordpoints_get_user_rank($user_id, $group_slug); |
|
332 | 332 | |
333 | - $rank = wordpoints_get_rank( $rank_id ); |
|
333 | + $rank = wordpoints_get_rank($rank_id); |
|
334 | 334 | |
335 | - if ( ! $rank ) { |
|
335 | + if ( ! $rank) { |
|
336 | 336 | continue; |
337 | 337 | } |
338 | 338 | |
339 | - if ( $increase ) { |
|
340 | - $new_rank = $this->maybe_increase_user_rank( $user_id, $rank, $args ); |
|
339 | + if ($increase) { |
|
340 | + $new_rank = $this->maybe_increase_user_rank($user_id, $rank, $args); |
|
341 | 341 | } else { |
342 | - $new_rank = $this->maybe_decrease_user_rank( $user_id, $rank, $args ); |
|
342 | + $new_rank = $this->maybe_decrease_user_rank($user_id, $rank, $args); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $new_rank !== $rank ) { |
|
346 | - wordpoints_update_user_rank( $user_id, $new_rank->ID ); |
|
345 | + if ($new_rank !== $rank) { |
|
346 | + wordpoints_update_user_rank($user_id, $new_rank->ID); |
|
347 | 347 | } |
348 | 348 | } |
349 | 349 | } |
@@ -218,8 +218,11 @@ |
||
218 | 218 | name="<?php echo esc_attr( $name ); ?>" |
219 | 219 | <?php if ( $args['placeholders'] && 'hidden' !== $field['type'] ) : ?> |
220 | 220 | value="<% if ( typeof <?php echo preg_replace( '/[^a-z0-9_]/i', '', $name ); // WPCS: XSS OK ?> !== "undefined" ) { print( <?php echo preg_replace( '/[^a-z0-9_]/i', '', $name ); // WPCS: XSS OK ?> ); } %>" |
221 | - <?php else : ?> |
|
222 | - value="<?php echo esc_attr( $value ); ?>" |
|
221 | + <?php else { |
|
222 | + : ?> |
|
223 | + value="<?php echo esc_attr( $value ); |
|
224 | +} |
|
225 | +?>" |
|
223 | 226 | <?php endif; ?> |
224 | 227 | class="widefat" |
225 | 228 | /> |
@@ -12,13 +12,13 @@ |
||
12 | 12 | * |
13 | 13 | * @since 2.1.0 |
14 | 14 | */ |
15 | -include_once( WORDPOINTS_DIR . '/components/ranks/includes/integration/points/functions.php' ); |
|
15 | +include_once(WORDPOINTS_DIR . '/components/ranks/includes/integration/points/functions.php'); |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Actions and filters to integrate with the points component. |
19 | 19 | * |
20 | 20 | * @since 2.1.0 |
21 | 21 | */ |
22 | -include_once( WORDPOINTS_DIR . '/components/ranks/includes/integration/points/filters.php' ); |
|
22 | +include_once(WORDPOINTS_DIR . '/components/ranks/includes/integration/points/filters.php'); |
|
23 | 23 | |
24 | 24 | // EOF |
@@ -7,15 +7,15 @@ |
||
7 | 7 | * @since 2.1.0 |
8 | 8 | */ |
9 | 9 | |
10 | -add_filter( 'wordpoints_points_widget_text', 'wordpoints_ranks_points_widget_text_filter', 30, 2 ); |
|
11 | -add_action( 'wordpoints_my_points_widget_below_text_field', 'wordpoints_ranks_my_points_widget_below_text_field' ); |
|
10 | +add_filter('wordpoints_points_widget_text', 'wordpoints_ranks_points_widget_text_filter', 30, 2); |
|
11 | +add_action('wordpoints_my_points_widget_below_text_field', 'wordpoints_ranks_my_points_widget_below_text_field'); |
|
12 | 12 | |
13 | -add_filter( 'wordpoints_points_top_users_username', 'wordpoints_ranks_points_top_users_username_filter', 10, 4 ); |
|
13 | +add_filter('wordpoints_points_top_users_username', 'wordpoints_ranks_points_top_users_username_filter', 10, 4); |
|
14 | 14 | |
15 | -add_filter( 'shortcode_atts_wordpoints_user_rank', 'wordpoints_user_rank_shortcode_points_type_attr', 10, 3 ); |
|
15 | +add_filter('shortcode_atts_wordpoints_user_rank', 'wordpoints_user_rank_shortcode_points_type_attr', 10, 3); |
|
16 | 16 | |
17 | -add_action( 'wordpoints_ranks_register', 'wordpoints_register_points_ranks' ); |
|
17 | +add_action('wordpoints_ranks_register', 'wordpoints_register_points_ranks'); |
|
18 | 18 | |
19 | -add_action( 'add_meta_boxes', 'wordpoints_ranks_add_points_types_meta_box_ranks', 20 ); |
|
19 | +add_action('add_meta_boxes', 'wordpoints_ranks_add_points_types_meta_box_ranks', 20); |
|
20 | 20 | |
21 | 21 | // EOF |
@@ -8,13 +8,13 @@ |
||
8 | 8 | * @deprecated 2.2.0 |
9 | 9 | */ |
10 | 10 | |
11 | -_deprecated_file( __FILE__, '2.2.0' ); |
|
11 | +_deprecated_file(__FILE__, '2.2.0'); |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * The base rank type class. |
15 | 15 | * |
16 | 16 | * @since 1.7.0 |
17 | 17 | */ |
18 | -include_once( WORDPOINTS_DIR . '/components/ranks/includes/rank-types/base.php' ); |
|
18 | +include_once(WORDPOINTS_DIR . '/components/ranks/includes/rank-types/base.php'); |
|
19 | 19 | |
20 | 20 | // EOF |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return bool Whether the group is registered. |
34 | 34 | */ |
35 | - public static function is_group_registered( $slug ) { |
|
35 | + public static function is_group_registered($slug) { |
|
36 | 36 | |
37 | - return isset( self::$groups[ $slug ] ); |
|
37 | + return isset(self::$groups[$slug]); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -47,17 +47,17 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return bool True if registered, false if already registered. |
49 | 49 | */ |
50 | - public static function register_group( $slug, $data ) { |
|
50 | + public static function register_group($slug, $data) { |
|
51 | 51 | |
52 | - if ( self::is_group_registered( $slug ) ) { |
|
52 | + if (self::is_group_registered($slug)) { |
|
53 | 53 | return false; |
54 | 54 | } |
55 | 55 | |
56 | - self::$groups[ $slug ] = new WordPoints_Rank_Group( $slug, $data ); |
|
56 | + self::$groups[$slug] = new WordPoints_Rank_Group($slug, $data); |
|
57 | 57 | |
58 | 58 | // If this is a brand new group, create the base rank. |
59 | - if ( ! self::$groups[ $slug ]->get_base_rank() ) { |
|
60 | - wordpoints_add_rank( '', 'base', $slug, 0 ); |
|
59 | + if ( ! self::$groups[$slug]->get_base_rank()) { |
|
60 | + wordpoints_add_rank('', 'base', $slug, 0); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | return true; |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return bool True if deregistered, false if not registered. |
74 | 74 | */ |
75 | - public static function deregister_group( $slug ) { |
|
75 | + public static function deregister_group($slug) { |
|
76 | 76 | |
77 | - if ( ! self::is_group_registered( $slug ) ) { |
|
77 | + if ( ! self::is_group_registered($slug)) { |
|
78 | 78 | return false; |
79 | 79 | } |
80 | 80 | |
81 | - unset( self::$groups[ $slug ] ); |
|
81 | + unset(self::$groups[$slug]); |
|
82 | 82 | |
83 | 83 | return true; |
84 | 84 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public static function get() { |
94 | 94 | |
95 | - if ( ! did_action( 'wordpoints_ranks_register' ) ) { |
|
95 | + if ( ! did_action('wordpoints_ranks_register')) { |
|
96 | 96 | _doing_it_wrong( |
97 | 97 | __METHOD__ |
98 | 98 | , 'Rank groups should not be retreived until after they are all registered.' |
@@ -112,13 +112,13 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return WordPoints_Rank_Group|false The handler object, or false. |
114 | 114 | */ |
115 | - public static function get_group( $group ) { |
|
115 | + public static function get_group($group) { |
|
116 | 116 | |
117 | - if ( ! self::is_group_registered( $group ) ) { |
|
117 | + if ( ! self::is_group_registered($group)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - return self::$groups[ $group ]; |
|
121 | + return self::$groups[$group]; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return bool Whether the rank type is registered for the group. |
137 | 137 | */ |
138 | - public static function is_type_registered_for_group( $type, $group ) { |
|
138 | + public static function is_type_registered_for_group($type, $group) { |
|
139 | 139 | |
140 | - if ( ! self::is_group_registered( $group ) ) { |
|
140 | + if ( ! self::is_group_registered($group)) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | |
144 | - return self::$groups[ $group ]->has_type( $type ); |
|
144 | + return self::$groups[$group]->has_type($type); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -156,13 +156,13 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return bool True on success. False if the group is invalid. |
158 | 158 | */ |
159 | - public static function register_type_for_group( $type, $group ) { |
|
159 | + public static function register_type_for_group($type, $group) { |
|
160 | 160 | |
161 | - if ( ! self::is_group_registered( $group ) ) { |
|
161 | + if ( ! self::is_group_registered($group)) { |
|
162 | 162 | return false; |
163 | 163 | } |
164 | 164 | |
165 | - return self::$groups[ $group ]->add_type( $type ); |
|
165 | + return self::$groups[$group]->add_type($type); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -176,17 +176,17 @@ discard block |
||
176 | 176 | * @return bool True on success. False if the group is invalid, or the rank type |
177 | 177 | * isn't registered for it. |
178 | 178 | */ |
179 | - public static function deregister_type_for_group( $type, $group ) { |
|
179 | + public static function deregister_type_for_group($type, $group) { |
|
180 | 180 | |
181 | - if ( ! self::is_group_registered( $group ) ) { |
|
181 | + if ( ! self::is_group_registered($group)) { |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
185 | - if ( ! self::is_type_registered_for_group( $type, $group ) ) { |
|
185 | + if ( ! self::is_type_registered_for_group($type, $group)) { |
|
186 | 186 | return false; |
187 | 187 | } |
188 | 188 | |
189 | - return self::$groups[ $group ]->remove_type( $type ); |
|
189 | + return self::$groups[$group]->remove_type($type); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return bool Whether this rank type is registered. |
37 | 37 | */ |
38 | - public static function is_type_registered( $type ) { |
|
38 | + public static function is_type_registered($type) { |
|
39 | 39 | |
40 | - return isset( self::$types[ $type ] ); |
|
40 | + return isset(self::$types[$type]); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -54,15 +54,15 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return bool Whether the rank type was registered. |
56 | 56 | */ |
57 | - public static function register_type( $type, $class, array $args = array() ) { |
|
57 | + public static function register_type($type, $class, array $args = array()) { |
|
58 | 58 | |
59 | - if ( self::is_type_registered( $type ) ) { |
|
59 | + if (self::is_type_registered($type)) { |
|
60 | 60 | return false; |
61 | 61 | } |
62 | 62 | |
63 | 63 | $args['slug'] = $type; |
64 | 64 | |
65 | - self::$types[ $type ] = new $class( $args ); |
|
65 | + self::$types[$type] = new $class($args); |
|
66 | 66 | |
67 | 67 | return true; |
68 | 68 | } |
@@ -78,23 +78,23 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return bool Whether the rank type was deregistered. |
80 | 80 | */ |
81 | - public static function deregister_type( $type ) { |
|
81 | + public static function deregister_type($type) { |
|
82 | 82 | |
83 | - if ( 'base' === $type ) { |
|
83 | + if ('base' === $type) { |
|
84 | 84 | return false; |
85 | 85 | } |
86 | 86 | |
87 | - if ( ! self::is_type_registered( $type ) ) { |
|
87 | + if ( ! self::is_type_registered($type)) { |
|
88 | 88 | return false; |
89 | 89 | } |
90 | 90 | |
91 | - self::$types[ $type ]->destruct(); |
|
91 | + self::$types[$type]->destruct(); |
|
92 | 92 | |
93 | - foreach ( WordPoints_Rank_Groups::get() as $group ) { |
|
94 | - $group->remove_type( $type ); |
|
93 | + foreach (WordPoints_Rank_Groups::get() as $group) { |
|
94 | + $group->remove_type($type); |
|
95 | 95 | } |
96 | 96 | |
97 | - unset( self::$types[ $type ] ); |
|
97 | + unset(self::$types[$type]); |
|
98 | 98 | |
99 | 99 | return true; |
100 | 100 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public static function get() { |
110 | 110 | |
111 | - if ( ! did_action( 'wordpoints_ranks_register' ) ) { |
|
111 | + if ( ! did_action('wordpoints_ranks_register')) { |
|
112 | 112 | _doing_it_wrong( |
113 | 113 | __METHOD__ |
114 | 114 | , 'Ranks should not be retreived until after they are all registered.' |
@@ -128,13 +128,13 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return WordPoints_Rank_Type|false The hander object, or false. |
130 | 130 | */ |
131 | - public static function get_type( $type ) { |
|
131 | + public static function get_type($type) { |
|
132 | 132 | |
133 | - if ( ! self::is_type_registered( $type ) ) { |
|
133 | + if ( ! self::is_type_registered($type)) { |
|
134 | 134 | return false; |
135 | 135 | } |
136 | 136 | |
137 | - return self::$types[ $type ]; |
|
137 | + return self::$types[$type]; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -146,21 +146,21 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public static function init() { |
148 | 148 | |
149 | - self::register_type( 'base', 'WordPoints_Base_Rank_Type' ); |
|
149 | + self::register_type('base', 'WordPoints_Base_Rank_Type'); |
|
150 | 150 | |
151 | 151 | /** |
152 | 152 | * Ranks should not register later than this action. |
153 | 153 | * |
154 | 154 | * @since 1.7.0 |
155 | 155 | */ |
156 | - do_action( 'wordpoints_ranks_register' ); |
|
156 | + do_action('wordpoints_ranks_register'); |
|
157 | 157 | |
158 | 158 | /** |
159 | 159 | * All ranks are registered. |
160 | 160 | * |
161 | 161 | * @since 1.7.0 |
162 | 162 | */ |
163 | - do_action( 'wordpoints_ranks_registered' ); |
|
163 | + do_action('wordpoints_ranks_registered'); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 |
@@ -26,27 +26,27 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return int|false|WP_Error The ID of the inserted rank, or false or WP_Error on failure. |
28 | 28 | */ |
29 | -function wordpoints_add_rank( $name, $type, $group, $position, array $meta = array() ) { |
|
29 | +function wordpoints_add_rank($name, $type, $group, $position, array $meta = array()) { |
|
30 | 30 | |
31 | 31 | global $wpdb; |
32 | 32 | |
33 | - if ( ! WordPoints_Rank_Groups::is_type_registered_for_group( $type, $group ) ) { |
|
33 | + if ( ! WordPoints_Rank_Groups::is_type_registered_for_group($type, $group)) { |
|
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | |
37 | - $rank_type = WordPoints_Rank_Types::get_type( $type ); |
|
37 | + $rank_type = WordPoints_Rank_Types::get_type($type); |
|
38 | 38 | |
39 | - if ( ! $rank_type ) { |
|
39 | + if ( ! $rank_type) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | - $meta = $rank_type->validate_rank_meta( $meta ); |
|
44 | - if ( false === $meta || is_wp_error( $meta ) ) { |
|
43 | + $meta = $rank_type->validate_rank_meta($meta); |
|
44 | + if (false === $meta || is_wp_error($meta)) { |
|
45 | 45 | return $meta; |
46 | 46 | } |
47 | 47 | |
48 | - if ( 'utf8' === $wpdb->get_col_charset( $wpdb->wordpoints_ranks, 'name' ) ) { |
|
49 | - $name = wp_encode_emoji( $name ); |
|
48 | + if ('utf8' === $wpdb->get_col_charset($wpdb->wordpoints_ranks, 'name')) { |
|
49 | + $name = wp_encode_emoji($name); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | $inserted = $wpdb->insert( |
@@ -60,17 +60,17 @@ discard block |
||
60 | 60 | ) |
61 | 61 | ); |
62 | 62 | |
63 | - if ( ! $inserted ) { |
|
63 | + if ( ! $inserted) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | 67 | $rank_id = (int) $wpdb->insert_id; |
68 | 68 | |
69 | - foreach ( $meta as $meta_key => $meta_value ) { |
|
70 | - wordpoints_add_rank_meta( $rank_id, $meta_key, $meta_value ); |
|
69 | + foreach ($meta as $meta_key => $meta_value) { |
|
70 | + wordpoints_add_rank_meta($rank_id, $meta_key, $meta_value); |
|
71 | 71 | } |
72 | 72 | |
73 | - WordPoints_Rank_Groups::get_group( $group )->add_rank( $rank_id, $position ); |
|
73 | + WordPoints_Rank_Groups::get_group($group)->add_rank($rank_id, $position); |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * Perform actions when a rank is added. |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @param int $rank_id The ID of the rank that was added. |
81 | 81 | */ |
82 | - do_action( 'wordpoints_add_rank', $rank_id ); |
|
82 | + do_action('wordpoints_add_rank', $rank_id); |
|
83 | 83 | |
84 | 84 | return $rank_id; |
85 | 85 | } |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return bool True if the rank was deleted, false otherwise. |
95 | 95 | */ |
96 | -function wordpoints_delete_rank( $id ) { |
|
96 | +function wordpoints_delete_rank($id) { |
|
97 | 97 | |
98 | 98 | global $wpdb; |
99 | 99 | |
100 | - $rank = wordpoints_get_rank( $id ); |
|
100 | + $rank = wordpoints_get_rank($id); |
|
101 | 101 | |
102 | - if ( ! $rank ) { |
|
102 | + if ( ! $rank) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | |
@@ -110,15 +110,15 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @param WordPoints_Rank $rank The rank that is being deleted. |
112 | 112 | */ |
113 | - do_action( 'wordpoints_pre_delete_rank', $rank ); |
|
113 | + do_action('wordpoints_pre_delete_rank', $rank); |
|
114 | 114 | |
115 | 115 | $deleted = $wpdb->delete( |
116 | 116 | $wpdb->wordpoints_ranks |
117 | - , array( 'id' => $id ) |
|
118 | - , array( '%d' ) |
|
117 | + , array('id' => $id) |
|
118 | + , array('%d') |
|
119 | 119 | ); |
120 | 120 | |
121 | - if ( ! $deleted ) { |
|
121 | + if ( ! $deleted) { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | ) |
134 | 134 | ); // WPCS: cache pass. |
135 | 135 | |
136 | - WordPoints_Rank_Groups::get_group( $rank->rank_group )->remove_rank( $id ); |
|
136 | + WordPoints_Rank_Groups::get_group($rank->rank_group)->remove_rank($id); |
|
137 | 137 | |
138 | - wp_cache_delete( $id, 'wordpoints_ranks' ); |
|
138 | + wp_cache_delete($id, 'wordpoints_ranks'); |
|
139 | 139 | |
140 | - foreach ( $rank_meta_ids as $mid ) { |
|
141 | - delete_metadata_by_mid( 'wordpoints_rank', $mid ); |
|
140 | + foreach ($rank_meta_ids as $mid) { |
|
141 | + delete_metadata_by_mid('wordpoints_rank', $mid); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @param int $rank_id The ID of the rank that was deleted. |
150 | 150 | */ |
151 | - do_action( 'wordpoints_delete_rank', $id ); |
|
151 | + do_action('wordpoints_delete_rank', $id); |
|
152 | 152 | |
153 | 153 | return true; |
154 | 154 | } |
@@ -170,28 +170,28 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return bool|WP_Error True the rank was updated successfully, or false/WP_Error on failure. |
172 | 172 | */ |
173 | -function wordpoints_update_rank( $id, $name, $type, $group, $position, array $meta = array() ) { |
|
173 | +function wordpoints_update_rank($id, $name, $type, $group, $position, array $meta = array()) { |
|
174 | 174 | |
175 | 175 | global $wpdb; |
176 | 176 | |
177 | - $rank = wordpoints_get_rank( $id ); |
|
177 | + $rank = wordpoints_get_rank($id); |
|
178 | 178 | |
179 | - if ( ! $rank ) { |
|
179 | + if ( ! $rank) { |
|
180 | 180 | return false; |
181 | 181 | } |
182 | 182 | |
183 | - if ( ! WordPoints_Rank_Groups::is_type_registered_for_group( $type, $group ) ) { |
|
183 | + if ( ! WordPoints_Rank_Groups::is_type_registered_for_group($type, $group)) { |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | |
187 | - $rank_type = WordPoints_Rank_Types::get_type( $type ); |
|
187 | + $rank_type = WordPoints_Rank_Types::get_type($type); |
|
188 | 188 | |
189 | - if ( ! $rank_type ) { |
|
189 | + if ( ! $rank_type) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
193 | - $meta = $rank_type->validate_rank_meta( $meta ); |
|
194 | - if ( false === $meta || is_wp_error( $meta ) ) { |
|
193 | + $meta = $rank_type->validate_rank_meta($meta); |
|
194 | + if (false === $meta || is_wp_error($meta)) { |
|
195 | 195 | return $meta; |
196 | 196 | } |
197 | 197 | |
@@ -207,50 +207,50 @@ discard block |
||
207 | 207 | * @param int $position The new position this rank should have in the group. |
208 | 208 | * @param array $meta The new metadata for the rank. |
209 | 209 | */ |
210 | - do_action( 'wordpoints_pre_update_rank', $rank, $name, $type, $group, $position, $meta ); |
|
210 | + do_action('wordpoints_pre_update_rank', $rank, $name, $type, $group, $position, $meta); |
|
211 | 211 | |
212 | - if ( 'utf8' === $wpdb->get_col_charset( $wpdb->wordpoints_ranks, 'name' ) ) { |
|
213 | - $name = wp_encode_emoji( $name ); |
|
212 | + if ('utf8' === $wpdb->get_col_charset($wpdb->wordpoints_ranks, 'name')) { |
|
213 | + $name = wp_encode_emoji($name); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | $updated = $wpdb->update( |
217 | 217 | $wpdb->wordpoints_ranks |
218 | - , array( 'name' => $name, 'type' => $type, 'rank_group' => $group ) |
|
219 | - , array( 'id' => $id ) |
|
218 | + , array('name' => $name, 'type' => $type, 'rank_group' => $group) |
|
219 | + , array('id' => $id) |
|
220 | 220 | , '%s' |
221 | 221 | , '%d' |
222 | 222 | ); |
223 | 223 | |
224 | - if ( false === $updated ) { |
|
224 | + if (false === $updated) { |
|
225 | 225 | return false; |
226 | 226 | } |
227 | 227 | |
228 | - wp_cache_delete( $id, 'wordpoints_ranks' ); |
|
228 | + wp_cache_delete($id, 'wordpoints_ranks'); |
|
229 | 229 | |
230 | - foreach ( $meta as $meta_key => $meta_value ) { |
|
231 | - wordpoints_update_rank_meta( $id, $meta_key, $meta_value ); |
|
230 | + foreach ($meta as $meta_key => $meta_value) { |
|
231 | + wordpoints_update_rank_meta($id, $meta_key, $meta_value); |
|
232 | 232 | } |
233 | 233 | |
234 | - $rank_group = WordPoints_Rank_Groups::get_group( $group ); |
|
234 | + $rank_group = WordPoints_Rank_Groups::get_group($group); |
|
235 | 235 | |
236 | - if ( $rank->rank_group !== $group ) { |
|
236 | + if ($rank->rank_group !== $group) { |
|
237 | 237 | |
238 | - $previous_group = WordPoints_Rank_Groups::get_group( $rank->rank_group ); |
|
239 | - if ( $previous_group ) { |
|
240 | - $previous_group->remove_rank( $rank->ID ); |
|
238 | + $previous_group = WordPoints_Rank_Groups::get_group($rank->rank_group); |
|
239 | + if ($previous_group) { |
|
240 | + $previous_group->remove_rank($rank->ID); |
|
241 | 241 | } |
242 | 242 | |
243 | - $rank_group->add_rank( $rank->ID, $position ); |
|
243 | + $rank_group->add_rank($rank->ID, $position); |
|
244 | 244 | |
245 | 245 | } else { |
246 | 246 | |
247 | - if ( $position !== $rank_group->get_rank_position( $rank->ID ) ) { |
|
248 | - $rank_group->move_rank( $rank->ID, $position ); |
|
247 | + if ($position !== $rank_group->get_rank_position($rank->ID)) { |
|
248 | + $rank_group->move_rank($rank->ID, $position); |
|
249 | 249 | } else { |
250 | 250 | // If the position doesn't change, we still need refresh the ranks of |
251 | 251 | // users who have this rank, if the metadata or type has changed. |
252 | - if ( $meta || $type !== $rank->type ) { |
|
253 | - wordpoints_refresh_rank_users( $rank->ID ); |
|
252 | + if ($meta || $type !== $rank->type) { |
|
253 | + wordpoints_refresh_rank_users($rank->ID); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @param int $rank_id The ID of the rank that was updated. |
264 | 264 | */ |
265 | - do_action( 'wordpoints_update_rank', $id ); |
|
265 | + do_action('wordpoints_update_rank', $id); |
|
266 | 266 | |
267 | 267 | return true; |
268 | 268 | } |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return WordPoints_Rank|false The rank object, or false if it doesn't exist. |
278 | 278 | */ |
279 | -function wordpoints_get_rank( $id ) { |
|
279 | +function wordpoints_get_rank($id) { |
|
280 | 280 | |
281 | - $rank = new WordPoints_Rank( $id ); |
|
281 | + $rank = new WordPoints_Rank($id); |
|
282 | 282 | |
283 | - if ( ! $rank->exists() ) { |
|
283 | + if ( ! $rank->exists()) { |
|
284 | 284 | return false; |
285 | 285 | } |
286 | 286 | |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @return string The integer value of $points formatted for display. |
304 | 304 | */ |
305 | -function wordpoints_format_rank( $rank_id, $context, array $args = array() ) { |
|
305 | +function wordpoints_format_rank($rank_id, $context, array $args = array()) { |
|
306 | 306 | |
307 | - $rank = wordpoints_get_rank( $rank_id ); |
|
307 | + $rank = wordpoints_get_rank($rank_id); |
|
308 | 308 | |
309 | - if ( ! $rank ) { |
|
309 | + if ( ! $rank) { |
|
310 | 310 | return false; |
311 | 311 | } |
312 | 312 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @type int $user_id The ID of the user the rank is being displayed with. |
327 | 327 | * } |
328 | 328 | */ |
329 | - return apply_filters( 'wordpoints_format_rank', $formatted, $rank, $context, $args ); |
|
329 | + return apply_filters('wordpoints_format_rank', $formatted, $rank, $context, $args); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | // |
@@ -348,13 +348,13 @@ discard block |
||
348 | 348 | * |
349 | 349 | * @return int|bool The meta ID on success, false on failure. |
350 | 350 | */ |
351 | -function wordpoints_add_rank_meta( $rank_id, $meta_key, $meta_value, $unique = false ) { |
|
351 | +function wordpoints_add_rank_meta($rank_id, $meta_key, $meta_value, $unique = false) { |
|
352 | 352 | |
353 | 353 | return add_metadata( |
354 | 354 | 'wordpoints_rank' |
355 | 355 | , $rank_id |
356 | - , wp_slash( $meta_key ) |
|
357 | - , wp_slash( $meta_value ) |
|
356 | + , wp_slash($meta_key) |
|
357 | + , wp_slash($meta_value) |
|
358 | 358 | , $unique |
359 | 359 | ); |
360 | 360 | } |
@@ -375,13 +375,13 @@ discard block |
||
375 | 375 | * @return int|bool Meta ID if the key didn't exist, true on successful update, |
376 | 376 | * false on failure. |
377 | 377 | */ |
378 | -function wordpoints_update_rank_meta( $rank_id, $meta_key, $meta_value, $prev_value = '' ) { |
|
378 | +function wordpoints_update_rank_meta($rank_id, $meta_key, $meta_value, $prev_value = '') { |
|
379 | 379 | |
380 | 380 | return update_metadata( |
381 | 381 | 'wordpoints_rank' |
382 | 382 | , $rank_id |
383 | - , wp_slash( $meta_key ) |
|
384 | - , wp_slash( $meta_value ) |
|
383 | + , wp_slash($meta_key) |
|
384 | + , wp_slash($meta_value) |
|
385 | 385 | , $prev_value |
386 | 386 | ); |
387 | 387 | } |
@@ -401,13 +401,13 @@ discard block |
||
401 | 401 | * |
402 | 402 | * @return bool True on successful delete, false on failure. |
403 | 403 | */ |
404 | -function wordpoints_delete_rank_meta( $rank_id, $meta_key, $meta_value = '', $delete_all = false ) { |
|
404 | +function wordpoints_delete_rank_meta($rank_id, $meta_key, $meta_value = '', $delete_all = false) { |
|
405 | 405 | |
406 | 406 | return delete_metadata( |
407 | 407 | 'wordpoints_rank' |
408 | 408 | , $rank_id |
409 | - , wp_slash( $meta_key ) |
|
410 | - , wp_slash( $meta_value ) |
|
409 | + , wp_slash($meta_key) |
|
410 | + , wp_slash($meta_value) |
|
411 | 411 | , $delete_all |
412 | 412 | ); |
413 | 413 | } |
@@ -425,9 +425,9 @@ discard block |
||
425 | 425 | * |
426 | 426 | * @return string|array Single metadata value or array of metadata values. |
427 | 427 | */ |
428 | -function wordpoints_get_rank_meta( $rank_id, $meta_key = '', $single = false ) { |
|
428 | +function wordpoints_get_rank_meta($rank_id, $meta_key = '', $single = false) { |
|
429 | 429 | |
430 | - return get_metadata( 'wordpoints_rank', $rank_id, $meta_key, $single ); |
|
430 | + return get_metadata('wordpoints_rank', $rank_id, $meta_key, $single); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | // |
@@ -444,30 +444,30 @@ discard block |
||
444 | 444 | * |
445 | 445 | * @return int|false The ID of the rank this user has, or false for invalid args. |
446 | 446 | */ |
447 | -function wordpoints_get_user_rank( $user_id, $group ) { |
|
447 | +function wordpoints_get_user_rank($user_id, $group) { |
|
448 | 448 | |
449 | 449 | global $wpdb; |
450 | 450 | |
451 | - if ( ! wordpoints_posint( $user_id ) ) { |
|
451 | + if ( ! wordpoints_posint($user_id)) { |
|
452 | 452 | return false; |
453 | 453 | } |
454 | 454 | |
455 | - $rank_group = WordPoints_Rank_Groups::get_group( $group ); |
|
455 | + $rank_group = WordPoints_Rank_Groups::get_group($group); |
|
456 | 456 | |
457 | - if ( ! $rank_group ) { |
|
457 | + if ( ! $rank_group) { |
|
458 | 458 | return false; |
459 | 459 | } |
460 | 460 | |
461 | - $group_ranks = wp_cache_get( $group, 'wordpoints_user_ranks' ); |
|
461 | + $group_ranks = wp_cache_get($group, 'wordpoints_user_ranks'); |
|
462 | 462 | |
463 | - foreach ( (array) $group_ranks as $_rank_id => $user_ids ) { |
|
464 | - if ( isset( $user_ids[ $user_id ] ) ) { |
|
463 | + foreach ((array) $group_ranks as $_rank_id => $user_ids) { |
|
464 | + if (isset($user_ids[$user_id])) { |
|
465 | 465 | $rank_id = $_rank_id; |
466 | 466 | break; |
467 | 467 | } |
468 | 468 | } |
469 | 469 | |
470 | - if ( ! isset( $rank_id ) ) { |
|
470 | + if ( ! isset($rank_id)) { |
|
471 | 471 | |
472 | 472 | $rank_id = $wpdb->get_var( |
473 | 473 | $wpdb->prepare( |
@@ -488,13 +488,13 @@ discard block |
||
488 | 488 | ) |
489 | 489 | ); |
490 | 490 | |
491 | - if ( ! $rank_id ) { |
|
491 | + if ( ! $rank_id) { |
|
492 | 492 | $rank_id = $rank_group->get_base_rank(); |
493 | 493 | } |
494 | 494 | |
495 | - $group_ranks[ $rank_id ][ $user_id ] = $user_id; |
|
495 | + $group_ranks[$rank_id][$user_id] = $user_id; |
|
496 | 496 | |
497 | - wp_cache_set( $group, $group_ranks, 'wordpoints_user_ranks' ); |
|
497 | + wp_cache_set($group, $group_ranks, 'wordpoints_user_ranks'); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | return (int) $rank_id; |
@@ -512,17 +512,17 @@ discard block |
||
512 | 512 | * |
513 | 513 | * @return string|false The rank of this user formatted for dispay, or false. |
514 | 514 | */ |
515 | -function wordpoints_get_formatted_user_rank( $user_id, $group, $context, array $args = array() ) { |
|
515 | +function wordpoints_get_formatted_user_rank($user_id, $group, $context, array $args = array()) { |
|
516 | 516 | |
517 | - $rank_id = wordpoints_get_user_rank( $user_id, $group ); |
|
517 | + $rank_id = wordpoints_get_user_rank($user_id, $group); |
|
518 | 518 | |
519 | - if ( ! $rank_id ) { |
|
519 | + if ( ! $rank_id) { |
|
520 | 520 | return false; |
521 | 521 | } |
522 | 522 | |
523 | - $args = array_merge( $args, array( 'user_id' => $user_id ) ); |
|
523 | + $args = array_merge($args, array('user_id' => $user_id)); |
|
524 | 524 | |
525 | - return wordpoints_format_rank( $rank_id, $context, $args ); |
|
525 | + return wordpoints_format_rank($rank_id, $context, $args); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -535,29 +535,29 @@ discard block |
||
535 | 535 | * |
536 | 536 | * @return bool True if the update was successful. False otherwise. |
537 | 537 | */ |
538 | -function wordpoints_update_user_rank( $user_id, $rank_id ) { |
|
538 | +function wordpoints_update_user_rank($user_id, $rank_id) { |
|
539 | 539 | |
540 | 540 | global $wpdb; |
541 | 541 | |
542 | - if ( ! wordpoints_posint( $rank_id ) || ! wordpoints_posint( $user_id ) ) { |
|
542 | + if ( ! wordpoints_posint($rank_id) || ! wordpoints_posint($user_id)) { |
|
543 | 543 | return false; |
544 | 544 | } |
545 | 545 | |
546 | - $rank = wordpoints_get_rank( $rank_id ); |
|
546 | + $rank = wordpoints_get_rank($rank_id); |
|
547 | 547 | |
548 | - if ( ! $rank ) { |
|
548 | + if ( ! $rank) { |
|
549 | 549 | return false; |
550 | 550 | } |
551 | 551 | |
552 | - $old_rank_id = wordpoints_get_user_rank( $user_id, $rank->rank_group ); |
|
552 | + $old_rank_id = wordpoints_get_user_rank($user_id, $rank->rank_group); |
|
553 | 553 | |
554 | - if ( $rank_id === $old_rank_id ) { |
|
554 | + if ($rank_id === $old_rank_id) { |
|
555 | 555 | return true; |
556 | 556 | } |
557 | 557 | |
558 | - $old_rank = wordpoints_get_rank( $old_rank_id ); |
|
558 | + $old_rank = wordpoints_get_rank($old_rank_id); |
|
559 | 559 | |
560 | - switch ( $old_rank->type ) { |
|
560 | + switch ($old_rank->type) { |
|
561 | 561 | |
562 | 562 | case 'base': |
563 | 563 | // If this is a base rank, it's possible that the user will not have |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | |
578 | 578 | // If the user rank isn't in the database, we can't run an update query, |
579 | 579 | // and need to do this insert instead. |
580 | - if ( ! $has_rank ) { |
|
580 | + if ( ! $has_rank) { |
|
581 | 581 | |
582 | 582 | // This user doesn't yet have a rank in this group. |
583 | 583 | $result = $wpdb->insert( |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | default: |
599 | 599 | $result = $wpdb->update( |
600 | 600 | $wpdb->wordpoints_user_ranks |
601 | - , array( 'rank_id' => $rank_id ) |
|
601 | + , array('rank_id' => $rank_id) |
|
602 | 602 | , array( |
603 | 603 | 'user_id' => $user_id, |
604 | 604 | 'rank_id' => $old_rank_id, |
@@ -609,22 +609,22 @@ discard block |
||
609 | 609 | |
610 | 610 | } // End switch ( $old_rank->type ). |
611 | 611 | |
612 | - if ( false === $result ) { |
|
612 | + if (false === $result) { |
|
613 | 613 | return false; |
614 | 614 | } |
615 | 615 | |
616 | - $group_ranks = wp_cache_get( $rank->rank_group, 'wordpoints_user_ranks' ); |
|
616 | + $group_ranks = wp_cache_get($rank->rank_group, 'wordpoints_user_ranks'); |
|
617 | 617 | |
618 | - foreach ( $group_ranks as $_rank_id => $user_ids ) { |
|
619 | - unset( $group_ranks[ $_rank_id ][ $user_id ] ); |
|
618 | + foreach ($group_ranks as $_rank_id => $user_ids) { |
|
619 | + unset($group_ranks[$_rank_id][$user_id]); |
|
620 | 620 | } |
621 | 621 | |
622 | - wp_cache_set( $rank->rank_group, $group_ranks, 'wordpoints_user_ranks' ); |
|
622 | + wp_cache_set($rank->rank_group, $group_ranks, 'wordpoints_user_ranks'); |
|
623 | 623 | |
624 | - unset( $group_ranks ); |
|
624 | + unset($group_ranks); |
|
625 | 625 | |
626 | - wp_cache_delete( $rank_id, 'wordpoints_users_with_rank' ); |
|
627 | - wp_cache_delete( $old_rank_id, 'wordpoints_users_with_rank' ); |
|
626 | + wp_cache_delete($rank_id, 'wordpoints_users_with_rank'); |
|
627 | + wp_cache_delete($old_rank_id, 'wordpoints_users_with_rank'); |
|
628 | 628 | |
629 | 629 | /** |
630 | 630 | * Perform actions when a user rank is updated. |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | * @param int $new_rank_id The ID of the new rank the user has. |
636 | 636 | * @param int $old_rank_id The ID of the old rank the user used to have. |
637 | 637 | */ |
638 | - do_action( 'wordpoints_update_user_rank', $user_id, $rank_id, $old_rank_id ); |
|
638 | + do_action('wordpoints_update_user_rank', $user_id, $rank_id, $old_rank_id); |
|
639 | 639 | |
640 | 640 | return true; |
641 | 641 | } |
@@ -649,19 +649,19 @@ discard block |
||
649 | 649 | * |
650 | 650 | * @return int[]|false Array of user IDs or false if the $rank_id is invalid. |
651 | 651 | */ |
652 | -function wordpoints_get_users_with_rank( $rank_id ) { |
|
652 | +function wordpoints_get_users_with_rank($rank_id) { |
|
653 | 653 | |
654 | 654 | global $wpdb; |
655 | 655 | |
656 | - $rank = wordpoints_get_rank( $rank_id ); |
|
656 | + $rank = wordpoints_get_rank($rank_id); |
|
657 | 657 | |
658 | - if ( ! $rank ) { |
|
658 | + if ( ! $rank) { |
|
659 | 659 | return false; |
660 | 660 | } |
661 | 661 | |
662 | - $user_ids = wp_cache_get( $rank_id, 'wordpoints_users_with_rank' ); |
|
662 | + $user_ids = wp_cache_get($rank_id, 'wordpoints_users_with_rank'); |
|
663 | 663 | |
664 | - if ( false === $user_ids ) { |
|
664 | + if (false === $user_ids) { |
|
665 | 665 | |
666 | 666 | $user_ids = $wpdb->get_col( |
667 | 667 | $wpdb->prepare( |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | ) |
675 | 675 | ); |
676 | 676 | |
677 | - if ( 'base' === $rank->type ) { |
|
677 | + if ('base' === $rank->type) { |
|
678 | 678 | |
679 | 679 | $other_user_ids = $wpdb->get_col( |
680 | 680 | $wpdb->prepare( |
@@ -693,10 +693,10 @@ discard block |
||
693 | 693 | ) |
694 | 694 | ); |
695 | 695 | |
696 | - $user_ids = array_merge( $user_ids, $other_user_ids ); |
|
696 | + $user_ids = array_merge($user_ids, $other_user_ids); |
|
697 | 697 | } |
698 | 698 | |
699 | - wp_cache_set( $rank_id, $user_ids, 'wordpoints_users_with_rank' ); |
|
699 | + wp_cache_set($rank_id, $user_ids, 'wordpoints_users_with_rank'); |
|
700 | 700 | |
701 | 701 | } // End if ( not cached ). |
702 | 702 | |
@@ -712,59 +712,59 @@ discard block |
||
712 | 712 | * |
713 | 713 | * @param int $rank_id The ID of the rank to refresh. |
714 | 714 | */ |
715 | -function wordpoints_refresh_rank_users( $rank_id ) { |
|
715 | +function wordpoints_refresh_rank_users($rank_id) { |
|
716 | 716 | |
717 | - $rank = wordpoints_get_rank( $rank_id ); |
|
717 | + $rank = wordpoints_get_rank($rank_id); |
|
718 | 718 | |
719 | - if ( ! $rank || 'base' === $rank->type ) { |
|
719 | + if ( ! $rank || 'base' === $rank->type) { |
|
720 | 720 | return; |
721 | 721 | } |
722 | 722 | |
723 | 723 | $prev_rank = $rank->get_adjacent( -1 ); |
724 | 724 | |
725 | - if ( ! $prev_rank ) { |
|
725 | + if ( ! $prev_rank) { |
|
726 | 726 | return; |
727 | 727 | } |
728 | 728 | |
729 | 729 | // Get a list of users who have this rank. |
730 | - $users = wordpoints_get_users_with_rank( $rank->ID ); |
|
730 | + $users = wordpoints_get_users_with_rank($rank->ID); |
|
731 | 731 | |
732 | 732 | // Also get users who have the previous rank. |
733 | - $prev_rank_users = wordpoints_get_users_with_rank( $prev_rank->ID ); |
|
733 | + $prev_rank_users = wordpoints_get_users_with_rank($prev_rank->ID); |
|
734 | 734 | |
735 | 735 | // If there are some users who have this rank, check if any of them need to |
736 | 736 | // decrease to that rank. |
737 | - if ( ! empty( $users ) ) { |
|
737 | + if ( ! empty($users)) { |
|
738 | 738 | |
739 | - $rank_type = WordPoints_Rank_Types::get_type( $rank->type ); |
|
739 | + $rank_type = WordPoints_Rank_Types::get_type($rank->type); |
|
740 | 740 | |
741 | - foreach ( $users as $user_id ) { |
|
741 | + foreach ($users as $user_id) { |
|
742 | 742 | |
743 | - $new_rank = $rank_type->maybe_decrease_user_rank( $user_id, $rank ); |
|
743 | + $new_rank = $rank_type->maybe_decrease_user_rank($user_id, $rank); |
|
744 | 744 | |
745 | - if ( $new_rank->ID === $rank->ID ) { |
|
745 | + if ($new_rank->ID === $rank->ID) { |
|
746 | 746 | continue; |
747 | 747 | } |
748 | 748 | |
749 | - wordpoints_update_user_rank( $user_id, $new_rank->ID ); |
|
749 | + wordpoints_update_user_rank($user_id, $new_rank->ID); |
|
750 | 750 | } |
751 | 751 | } |
752 | 752 | |
753 | 753 | // If there were some users with the previous rank, check if any of them can now |
754 | 754 | // increase to this rank. |
755 | - if ( ! empty( $prev_rank_users ) ) { |
|
755 | + if ( ! empty($prev_rank_users)) { |
|
756 | 756 | |
757 | - $rank_type = WordPoints_Rank_Types::get_type( $rank->type ); |
|
757 | + $rank_type = WordPoints_Rank_Types::get_type($rank->type); |
|
758 | 758 | |
759 | - foreach ( $prev_rank_users as $user_id ) { |
|
759 | + foreach ($prev_rank_users as $user_id) { |
|
760 | 760 | |
761 | - $new_rank = $rank_type->maybe_increase_user_rank( $user_id, $prev_rank ); |
|
761 | + $new_rank = $rank_type->maybe_increase_user_rank($user_id, $prev_rank); |
|
762 | 762 | |
763 | - if ( $new_rank->ID === $prev_rank->ID ) { |
|
763 | + if ($new_rank->ID === $prev_rank->ID) { |
|
764 | 764 | continue; |
765 | 765 | } |
766 | 766 | |
767 | - wordpoints_update_user_rank( $user_id, $new_rank->ID ); |
|
767 | + wordpoints_update_user_rank($user_id, $new_rank->ID); |
|
768 | 768 | } |
769 | 769 | } |
770 | 770 | } |
@@ -12,20 +12,20 @@ |
||
12 | 12 | * |
13 | 13 | * @since 1.7.0 |
14 | 14 | */ |
15 | -include_once( WORDPOINTS_DIR . 'components/ranks/admin/includes/ajax.php' ); |
|
15 | +include_once(WORDPOINTS_DIR . 'components/ranks/admin/includes/ajax.php'); |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Admin-side functions of the ranks component. |
19 | 19 | * |
20 | 20 | * @since 2.1.0 |
21 | 21 | */ |
22 | -include_once( WORDPOINTS_DIR . 'components/ranks/admin/includes/functions.php' ); |
|
22 | +include_once(WORDPOINTS_DIR . 'components/ranks/admin/includes/functions.php'); |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Admin-side actin and filter hooks of the ranks component. |
26 | 26 | * |
27 | 27 | * @since 2.1.0 |
28 | 28 | */ |
29 | -include_once( WORDPOINTS_DIR . 'components/ranks/admin/includes/filters.php' ); |
|
29 | +include_once(WORDPOINTS_DIR . 'components/ranks/admin/includes/filters.php'); |
|
30 | 30 | |
31 | 31 | // EOF |
@@ -7,11 +7,11 @@ |
||
7 | 7 | * @since 2.1.0 |
8 | 8 | */ |
9 | 9 | |
10 | -add_action( 'init', 'wordpoints_ranks_admin_register_scripts' ); |
|
10 | +add_action('init', 'wordpoints_ranks_admin_register_scripts'); |
|
11 | 11 | |
12 | -add_action( 'admin_menu', 'wordpoints_ranks_admin_menu' ); |
|
12 | +add_action('admin_menu', 'wordpoints_ranks_admin_menu'); |
|
13 | 13 | |
14 | -add_action( 'load-wordpoints_page_wordpoints_ranks', 'wordpoints_ranks_admin_screen_load' ); |
|
14 | +add_action('load-wordpoints_page_wordpoints_ranks', 'wordpoints_ranks_admin_screen_load'); |
|
15 | 15 | |
16 | 16 | |
17 | 17 | // EOF |