@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @WordPress\filter wordpoints_points_widget_text 30 After esc_html(). |
16 | 16 | */ |
17 | -function wordpoints_ranks_points_widget_text_filter( $text, $instance ) { |
|
17 | +function wordpoints_ranks_points_widget_text_filter($text, $instance) { |
|
18 | 18 | |
19 | - if ( is_user_logged_in() ) { |
|
19 | + if (is_user_logged_in()) { |
|
20 | 20 | |
21 | 21 | $rank = wordpoints_get_formatted_user_rank( |
22 | 22 | get_current_user_id() |
23 | 23 | , "points_type-{$instance['points_type']}" |
24 | 24 | , 'my-points-widget' |
25 | - , array( 'widget_settings' => $instance ) |
|
25 | + , array('widget_settings' => $instance) |
|
26 | 26 | ); |
27 | 27 | |
28 | - $text = str_replace( '%rank%', $rank, $text ); |
|
28 | + $text = str_replace('%rank%', $rank, $text); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | return $text; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | ?> |
44 | 44 | <br /> |
45 | - <small><i><?php echo esc_html( sprintf( __( '%s will be replaced with the rank of the logged in user', 'wordpoints' ), '%rank%' ) ); ?></i></small> |
|
45 | + <small><i><?php echo esc_html(sprintf(__('%s will be replaced with the rank of the logged in user', 'wordpoints'), '%rank%')); ?></i></small> |
|
46 | 46 | <?php |
47 | 47 | } |
48 | 48 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @WordPress\filter wordpoints_points_top_users_username |
55 | 55 | */ |
56 | -function wordpoints_ranks_points_top_users_username_filter( $name, $user_id, $points_type, $context ) { |
|
56 | +function wordpoints_ranks_points_top_users_username_filter($name, $user_id, $points_type, $context) { |
|
57 | 57 | |
58 | 58 | $rank = wordpoints_get_formatted_user_rank( |
59 | 59 | $user_id |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @WordPress\filter shortcode_atts_wordpoints_user_rank |
75 | 75 | */ |
76 | -function wordpoints_user_rank_shortcode_points_type_attr( $out, $pairs, $atts ) { |
|
76 | +function wordpoints_user_rank_shortcode_points_type_attr($out, $pairs, $atts) { |
|
77 | 77 | |
78 | - if ( empty( $out['rank_group'] ) ) { |
|
78 | + if (empty($out['rank_group'])) { |
|
79 | 79 | |
80 | - if ( isset( $atts['points_type'] ) ) { |
|
80 | + if (isset($atts['points_type'])) { |
|
81 | 81 | |
82 | 82 | $out['rank_group'] = "points_type-{$atts['points_type']}"; |
83 | 83 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | $points_type = wordpoints_get_default_points_type(); |
87 | 87 | |
88 | - if ( $points_type ) { |
|
88 | + if ($points_type) { |
|
89 | 89 | $out['rank_group'] = "points_type-{$points_type}"; |
90 | 90 | } |
91 | 91 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | function wordpoints_register_points_ranks() { |
105 | 105 | |
106 | - foreach ( wordpoints_get_points_types() as $slug => $points_type ) { |
|
106 | + foreach (wordpoints_get_points_types() as $slug => $points_type) { |
|
107 | 107 | |
108 | 108 | WordPoints_Rank_Groups::register_group( |
109 | 109 | "points_type-{$slug}" |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | WordPoints_Rank_Types::register_type( |
123 | 123 | "points-{$slug}" |
124 | 124 | , 'WordPoints_Points_Rank_Type' |
125 | - , array( 'points_type' => $slug ) |
|
125 | + , array('points_type' => $slug) |
|
126 | 126 | ); |
127 | 127 | |
128 | 128 | WordPoints_Rank_Groups::register_type_for_group( |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | |
147 | 147 | $tab = wordpoints_admin_get_current_tab(); |
148 | 148 | |
149 | - if ( 'add-new' === $tab ) { |
|
149 | + if ('add-new' === $tab) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | 153 | add_meta_box( |
154 | 154 | 'ranks' |
155 | - , _x( 'Ranks', 'Points Types screen meta box title', 'wordpoints' ) |
|
155 | + , _x('Ranks', 'Points Types screen meta box title', 'wordpoints') |
|
156 | 156 | , 'wordpoints_ranks_display_points_types_meta_box_ranks' |
157 | 157 | , 'wordpoints_page_wordpoints_points_types' |
158 | 158 | , 'side' |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @param array $points_type The data for the points type being edited. |
169 | 169 | */ |
170 | -function wordpoints_ranks_display_points_types_meta_box_ranks( $points_type ) { |
|
170 | +function wordpoints_ranks_display_points_types_meta_box_ranks($points_type) { |
|
171 | 171 | |
172 | 172 | ?> |
173 | 173 | |
174 | - <a href="<?php echo esc_url( self_admin_url( 'admin.php?page=wordpoints_ranks&tab=points_type-' . $points_type['slug'] ) ); ?>"> |
|
175 | - <?php esc_html_e( 'Go to the ranks for this points type.', 'wordpoints' ); ?> |
|
174 | + <a href="<?php echo esc_url(self_admin_url('admin.php?page=wordpoints_ranks&tab=points_type-' . $points_type['slug'])); ?>"> |
|
175 | + <?php esc_html_e('Go to the ranks for this points type.', 'wordpoints'); ?> |
|
176 | 176 | </a> |
177 | 177 | |
178 | 178 | <?php |
@@ -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 |
@@ -9,25 +9,25 @@ discard block |
||
9 | 9 | |
10 | 10 | $rank_groups = WordPoints_Rank_Groups::get(); |
11 | 11 | |
12 | -if ( empty( $rank_groups ) ) { |
|
12 | +if (empty($rank_groups)) { |
|
13 | 13 | |
14 | 14 | ?> |
15 | 15 | <div class="wrap"> |
16 | - <?php wordpoints_show_admin_error( esc_html__( 'No rank groups are currently available.', 'wordpoints' ) ); ?> |
|
16 | + <?php wordpoints_show_admin_error(esc_html__('No rank groups are currently available.', 'wordpoints')); ?> |
|
17 | 17 | </div> |
18 | 18 | <?php |
19 | 19 | |
20 | 20 | return; |
21 | 21 | } |
22 | 22 | |
23 | -$rank_group = $rank_groups[ wordpoints_admin_get_current_tab( $rank_groups ) ]; |
|
23 | +$rank_group = $rank_groups[wordpoints_admin_get_current_tab($rank_groups)]; |
|
24 | 24 | |
25 | 25 | ?> |
26 | 26 | |
27 | 27 | <div class="wrap"> |
28 | - <h1><?php esc_html_e( 'Ranks', 'wordpoints' ); ?></h1> |
|
28 | + <h1><?php esc_html_e('Ranks', 'wordpoints'); ?></h1> |
|
29 | 29 | |
30 | - <?php wordpoints_admin_show_tabs( wp_list_pluck( $rank_groups, 'name' ), false ) ?> |
|
30 | + <?php wordpoints_admin_show_tabs(wp_list_pluck($rank_groups, 'name'), false) ?> |
|
31 | 31 | |
32 | 32 | <div id="ranks-error-message" class="notice notice-error hidden"> |
33 | 33 | <p></p> |
@@ -42,34 +42,34 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @param WordPoints_Rank_Group $rank_group The rank group being displayed. |
44 | 44 | */ |
45 | - do_action( 'wordpoints_ranks_admin_screen_top', $rank_group ); |
|
45 | + do_action('wordpoints_ranks_admin_screen_top', $rank_group); |
|
46 | 46 | |
47 | 47 | ?> |
48 | 48 | |
49 | 49 | <div class="wordpoints-rank-group-container"> |
50 | - <p class="description group-description"><?php echo esc_html( $rank_group->description ); ?></p> |
|
50 | + <p class="description group-description"><?php echo esc_html($rank_group->description); ?></p> |
|
51 | 51 | <ul |
52 | - id="wordpoints-rank-group_<?php echo esc_attr( $rank_group->slug ); ?>" |
|
52 | + id="wordpoints-rank-group_<?php echo esc_attr($rank_group->slug); ?>" |
|
53 | 53 | class="wordpoints-rank-group" |
54 | - data-slug="<?php echo esc_attr( $rank_group->slug ); ?>" |
|
55 | - data-nonce="<?php echo esc_attr( wp_create_nonce( "wordpoints_get_ranks-{$rank_group->slug}" ) ); ?>" |
|
54 | + data-slug="<?php echo esc_attr($rank_group->slug); ?>" |
|
55 | + data-nonce="<?php echo esc_attr(wp_create_nonce("wordpoints_get_ranks-{$rank_group->slug}")); ?>" |
|
56 | 56 | > |
57 | 57 | </ul> |
58 | 58 | <div class="spinner-overlay" style="display: block;"> |
59 | 59 | <span class="spinner is-active"></span> |
60 | 60 | </div> |
61 | 61 | <div class="controls"> |
62 | - <button class="add-rank button-primary"><?php esc_html_e( 'Add Rank', 'wordpoints' ); ?></button> |
|
62 | + <button class="add-rank button-primary"><?php esc_html_e('Add Rank', 'wordpoints'); ?></button> |
|
63 | 63 | <label class="wordpoints-rank-types"> |
64 | - <?php esc_html_e( 'Rank Type:', 'wordpoints' ); ?> |
|
64 | + <?php esc_html_e('Rank Type:', 'wordpoints'); ?> |
|
65 | 65 | <select> |
66 | - <?php foreach ( $rank_group->get_types() as $rank_type ) : ?> |
|
67 | - <?php if ( 'base' !== $rank_type ) : ?> |
|
66 | + <?php foreach ($rank_group->get_types() as $rank_type) : ?> |
|
67 | + <?php if ('base' !== $rank_type) : ?> |
|
68 | 68 | <option |
69 | - value="<?php echo esc_attr( $rank_type ); ?>" |
|
70 | - data-nonce="<?php echo esc_attr( wp_create_nonce( "wordpoints_create_rank|{$rank_group->slug}|{$rank_type}" ) ); ?>" |
|
69 | + value="<?php echo esc_attr($rank_type); ?>" |
|
70 | + data-nonce="<?php echo esc_attr(wp_create_nonce("wordpoints_create_rank|{$rank_group->slug}|{$rank_type}")); ?>" |
|
71 | 71 | > |
72 | - <?php echo esc_html( WordPoints_Rank_Types::get_type( $rank_type )->get_name() ); ?> |
|
72 | + <?php echo esc_html(WordPoints_Rank_Types::get_type($rank_type)->get_name()); ?> |
|
73 | 73 | </option> |
74 | 74 | <?php endif; ?> |
75 | 75 | <?php endforeach; ?> |
@@ -86,35 +86,35 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param WordPoints_Rank_Group $rank_group The rank group being displayed. |
88 | 88 | */ |
89 | - do_action( 'wordpoints_ranks_admin_screen_bottom', $rank_group ); |
|
89 | + do_action('wordpoints_ranks_admin_screen_bottom', $rank_group); |
|
90 | 90 | |
91 | 91 | ?> |
92 | 92 | </div> |
93 | 93 | |
94 | -<?php foreach ( $rank_group->get_types() as $rank_type ) : ?> |
|
95 | - <script type="text/template" class="rank-template_<?php echo sanitize_html_class( $rank_type ); ?>"> |
|
94 | +<?php foreach ($rank_group->get_types() as $rank_type) : ?> |
|
95 | + <script type="text/template" class="rank-template_<?php echo sanitize_html_class($rank_type); ?>"> |
|
96 | 96 | <div class="view"> |
97 | 97 | <div> |
98 | 98 | <%- name %> |
99 | - <?php if ( ($field = key( wp_list_filter( WordPoints_Rank_Types::get_type( $rank_type )->get_meta_fields(), array( 'in_title' => true ) ) )) ) : ?> |
|
100 | - <span><% if ( typeof <?php echo preg_replace( '/[^a-z0-9_]/i', '', $field ); // WPCS: XSS OK ?> !== "undefined" ) { print( <?php echo preg_replace( '/[^a-z0-9_]/i', '', $field ); // WPCS: XSS OK ?> ); } %></span> |
|
99 | + <?php if (($field = key(wp_list_filter(WordPoints_Rank_Types::get_type($rank_type)->get_meta_fields(), array('in_title' => true))))) : ?> |
|
100 | + <span><% if ( typeof <?php echo preg_replace('/[^a-z0-9_]/i', '', $field); // WPCS: XSS OK ?> !== "undefined" ) { print( <?php echo preg_replace('/[^a-z0-9_]/i', '', $field); // WPCS: XSS OK ?> ); } %></span> |
|
101 | 101 | <?php endif; ?> |
102 | 102 | </div> |
103 | - <a class="edit"><?php echo esc_html_x( 'Edit', 'rank', 'wordpoints' ); ?></a> |
|
104 | - <a class="close"><?php esc_html_e( 'Close', 'wordpoints' ); ?></a> |
|
103 | + <a class="edit"><?php echo esc_html_x('Edit', 'rank', 'wordpoints'); ?></a> |
|
104 | + <a class="close"><?php esc_html_e('Close', 'wordpoints'); ?></a> |
|
105 | 105 | </div> |
106 | 106 | <form> |
107 | 107 | <div class="fields"> |
108 | 108 | <p class="description description-thin"> |
109 | 109 | <label> |
110 | - <?php echo esc_html_x( 'Title', 'rank', 'wordpoints' ); ?> |
|
110 | + <?php echo esc_html_x('Title', 'rank', 'wordpoints'); ?> |
|
111 | 111 | <input class="widefat" type="text" value="<%- name %>" name="name" /> |
112 | 112 | </label> |
113 | 113 | </p> |
114 | - <input type="hidden" name="type" value="<?php echo esc_attr( $rank_type ); ?>" /> |
|
114 | + <input type="hidden" name="type" value="<?php echo esc_attr($rank_type); ?>" /> |
|
115 | 115 | <input type="hidden" name="order" value="<%- order %>" /> |
116 | 116 | <input type="hidden" name="nonce" value="<%- nonce %>" /> |
117 | - <?php WordPoints_Rank_Types::get_type( $rank_type )->display_rank_meta_form_fields( array(), array( 'placeholders' => true ) ); ?> |
|
117 | + <?php WordPoints_Rank_Types::get_type($rank_type)->display_rank_meta_form_fields(array(), array('placeholders' => true)); ?> |
|
118 | 118 | </div> |
119 | 119 | <div class="messages"> |
120 | 120 | <div class="success"></div> |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | <span class="spinner is-active"></span> |
126 | 126 | </div> |
127 | 127 | <div class="action-buttons"> |
128 | - <button class="save button-primary" disabled><?php esc_html_e( 'Save', 'wordpoints' ); ?></button> |
|
129 | - <button class="cancel button-secondary"><?php esc_html_e( 'Cancel', 'wordpoints' ); ?></button> |
|
130 | - <button class="close button-secondary"><?php esc_html_e( 'Close', 'wordpoints' ); ?></button> |
|
131 | - <?php if ( 'base' !== $rank_type ) : ?> |
|
132 | - <button class="delete button-secondary"><?php esc_html_e( 'Delete', 'wordpoints' ); ?></button> |
|
128 | + <button class="save button-primary" disabled><?php esc_html_e('Save', 'wordpoints'); ?></button> |
|
129 | + <button class="cancel button-secondary"><?php esc_html_e('Cancel', 'wordpoints'); ?></button> |
|
130 | + <button class="close button-secondary"><?php esc_html_e('Close', 'wordpoints'); ?></button> |
|
131 | + <?php if ('base' !== $rank_type) : ?> |
|
132 | + <button class="delete button-secondary"><?php esc_html_e('Delete', 'wordpoints'); ?></button> |
|
133 | 133 | <?php endif; ?> |
134 | 134 | </div> |
135 | 135 | </div> |
@@ -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 |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | $rank_groups = WordPoints_Rank_Groups::get(); |
67 | 67 | $ranks = array(); |
68 | 68 | |
69 | - foreach ( $rank_groups as $group ) { |
|
70 | - $ranks[ $group->slug ] = self::prepare_group_ranks( $group ); |
|
69 | + foreach ($rank_groups as $group) { |
|
70 | + $ranks[$group->slug] = self::prepare_group_ranks($group); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | return $ranks; |
@@ -82,20 +82,20 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return array The ranks of this group, prepared for sending to the JS. |
84 | 84 | */ |
85 | - public static function prepare_group_ranks( $group ) { |
|
85 | + public static function prepare_group_ranks($group) { |
|
86 | 86 | |
87 | 87 | $rank_ids = $group->get_ranks(); |
88 | 88 | $ranks = array(); |
89 | 89 | |
90 | - foreach ( $rank_ids as $order => $rank_id ) { |
|
90 | + foreach ($rank_ids as $order => $rank_id) { |
|
91 | 91 | |
92 | - $rank = wordpoints_get_rank( $rank_id ); |
|
92 | + $rank = wordpoints_get_rank($rank_id); |
|
93 | 93 | |
94 | - if ( ! $rank ) { |
|
94 | + if ( ! $rank) { |
|
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - $ranks[] = self::_prepare_rank( $rank ); |
|
98 | + $ranks[] = self::_prepare_rank($rank); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return $ranks; |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function __construct() { |
114 | 114 | |
115 | - if ( isset( self::$instance ) ) { |
|
116 | - _doing_it_wrong( __METHOD__, 'Class should only be constructed once.', '1.7.0' ); |
|
115 | + if (isset(self::$instance)) { |
|
116 | + _doing_it_wrong(__METHOD__, 'Class should only be constructed once.', '1.7.0'); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | self::$instance = $this; |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function hooks() { |
130 | 130 | |
131 | - add_action( 'wp_ajax_wordpoints_admin_get_ranks', array( $this, 'get_ranks' ) ); |
|
132 | - add_action( 'wp_ajax_wordpoints_admin_create_rank', array( $this, 'create_rank' ) ); |
|
133 | - add_action( 'wp_ajax_wordpoints_admin_update_rank', array( $this, 'update_rank' ) ); |
|
134 | - add_action( 'wp_ajax_wordpoints_admin_delete_rank', array( $this, 'delete_rank' ) ); |
|
131 | + add_action('wp_ajax_wordpoints_admin_get_ranks', array($this, 'get_ranks')); |
|
132 | + add_action('wp_ajax_wordpoints_admin_create_rank', array($this, 'create_rank')); |
|
133 | + add_action('wp_ajax_wordpoints_admin_update_rank', array($this, 'update_rank')); |
|
134 | + add_action('wp_ajax_wordpoints_admin_delete_rank', array($this, 'delete_rank')); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | |
146 | 146 | $group = $this->_get_group(); |
147 | 147 | |
148 | - $this->_verify_request( "wordpoints_get_ranks-{$group->slug}" ); |
|
148 | + $this->_verify_request("wordpoints_get_ranks-{$group->slug}"); |
|
149 | 149 | |
150 | - wp_send_json_success( self::prepare_group_ranks( $group ) ); |
|
150 | + wp_send_json_success(self::prepare_group_ranks($group)); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | $group = $this->_get_group(); |
163 | 163 | $type = $this->_get_rank_type()->get_slug(); |
164 | 164 | |
165 | - $this->_verify_request( "wordpoints_create_rank|{$group->slug}|{$type}" ); |
|
165 | + $this->_verify_request("wordpoints_create_rank|{$group->slug}|{$type}"); |
|
166 | 166 | |
167 | 167 | // Attempt to save the rank. |
168 | 168 | $result = wordpoints_add_rank( |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | , $this->_get_rank_meta() |
174 | 174 | ); |
175 | 175 | |
176 | - $this->_send_json_result( $result, 'create' ); |
|
176 | + $this->_send_json_result($result, 'create'); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | |
195 | 195 | $type = $this->_get_rank_type()->get_slug(); |
196 | 196 | |
197 | - if ( $type !== $rank->type ) { |
|
198 | - wp_send_json_error( array( 'message' => __( 'This rank does not match any rank in the database, perhaps it was deleted. Refresh the page to update the list of ranks.', 'wordpoints' ) ) ); |
|
197 | + if ($type !== $rank->type) { |
|
198 | + wp_send_json_error(array('message' => __('This rank does not match any rank in the database, perhaps it was deleted. Refresh the page to update the list of ranks.', 'wordpoints'))); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | $result = wordpoints_update_rank( |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | , $this->_get_rank_meta() |
208 | 208 | ); |
209 | 209 | |
210 | - $this->_send_json_result( $result, 'update' ); |
|
210 | + $this->_send_json_result($result, 'update'); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | "wordpoints_delete_rank|{$group->slug}|{$rank->ID}" |
227 | 227 | ); |
228 | 228 | |
229 | - $result = wordpoints_delete_rank( $rank->ID ); |
|
229 | + $result = wordpoints_delete_rank($rank->ID); |
|
230 | 230 | |
231 | - if ( ! $result ) { |
|
232 | - wp_send_json_error( array( 'message' => __( 'There was an error deleting the rank. Please try again.', 'wordpoints' ) ) ); |
|
231 | + if ( ! $result) { |
|
232 | + wp_send_json_error(array('message' => __('There was an error deleting the rank. Please try again.', 'wordpoints'))); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | wp_send_json_success(); |
@@ -250,11 +250,11 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @param string $debug_context Context sent with the message (for debugging). |
252 | 252 | */ |
253 | - private function _unexpected_error( $debug_context ) { |
|
253 | + private function _unexpected_error($debug_context) { |
|
254 | 254 | |
255 | 255 | wp_send_json_error( |
256 | 256 | array( |
257 | - 'message' => __( 'There was an unexpected error. Try reloading the page.', 'wordpoints' ), |
|
257 | + 'message' => __('There was an unexpected error. Try reloading the page.', 'wordpoints'), |
|
258 | 258 | 'debug' => $debug_context, |
259 | 259 | ) |
260 | 260 | ); |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | */ |
271 | 271 | private function _verify_user_can() { |
272 | 272 | |
273 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
274 | - wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to perform this action. Maybe you have been logged out?', 'wordpoints' ) ) ); |
|
273 | + if ( ! current_user_can('manage_options')) { |
|
274 | + wp_send_json_error(array('message' => __('Sorry, you are not allowed to perform this action. Maybe you have been logged out?', 'wordpoints'))); |
|
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
@@ -284,14 +284,14 @@ discard block |
||
284 | 284 | * |
285 | 285 | * @param string $action The action the nonce should be for. |
286 | 286 | */ |
287 | - private function _verify_request( $action ) { |
|
287 | + private function _verify_request($action) { |
|
288 | 288 | |
289 | 289 | if ( |
290 | - empty( $_POST['nonce'] ) |
|
291 | - || ! wordpoints_verify_nonce( 'nonce', $action, null, 'post' ) |
|
290 | + empty($_POST['nonce']) |
|
291 | + || ! wordpoints_verify_nonce('nonce', $action, null, 'post') |
|
292 | 292 | ) { |
293 | 293 | wp_send_json_error( |
294 | - array( 'message' => __( 'Your security token for this action has expired. Refresh the page and try again.', 'wordpoints' ) ) |
|
294 | + array('message' => __('Your security token for this action has expired. Refresh the page and try again.', 'wordpoints')) |
|
295 | 295 | ); |
296 | 296 | } |
297 | 297 | } |
@@ -305,14 +305,14 @@ discard block |
||
305 | 305 | */ |
306 | 306 | private function _get_group() { |
307 | 307 | |
308 | - if ( ! isset( $_POST['group'] ) ) { // WPCS: CSRF OK. |
|
309 | - $this->_unexpected_error( 'group' ); |
|
308 | + if ( ! isset($_POST['group'])) { // WPCS: CSRF OK. |
|
309 | + $this->_unexpected_error('group'); |
|
310 | 310 | } |
311 | 311 | |
312 | - $group = WordPoints_Rank_Groups::get_group( sanitize_key( $_POST['group'] ) ); // WPCS: CSRF OK. |
|
312 | + $group = WordPoints_Rank_Groups::get_group(sanitize_key($_POST['group'])); // WPCS: CSRF OK. |
|
313 | 313 | |
314 | - if ( ! $group ) { |
|
315 | - wp_send_json_error( array( 'message' => __( 'The rank group passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints' ) ) ); |
|
314 | + if ( ! $group) { |
|
315 | + wp_send_json_error(array('message' => __('The rank group passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints'))); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | return $group; |
@@ -327,14 +327,14 @@ discard block |
||
327 | 327 | */ |
328 | 328 | private function _get_rank() { |
329 | 329 | |
330 | - if ( ! isset( $_POST['id'] ) ) { // WPCS: CSRF OK. |
|
331 | - $this->_unexpected_error( 'id' ); |
|
330 | + if ( ! isset($_POST['id'])) { // WPCS: CSRF OK. |
|
331 | + $this->_unexpected_error('id'); |
|
332 | 332 | } |
333 | 333 | |
334 | - $rank = wordpoints_get_rank( wordpoints_int( $_POST['id'] ) ); // WPCS: CSRF OK. |
|
334 | + $rank = wordpoints_get_rank(wordpoints_int($_POST['id'])); // WPCS: CSRF OK. |
|
335 | 335 | |
336 | - if ( ! $rank ) { |
|
337 | - wp_send_json_error( array( 'message' => __( 'The rank ID passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints' ) ) ); |
|
336 | + if ( ! $rank) { |
|
337 | + wp_send_json_error(array('message' => __('The rank ID passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints'))); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | return $rank; |
@@ -351,18 +351,18 @@ discard block |
||
351 | 351 | |
352 | 352 | $empty_name = true; |
353 | 353 | |
354 | - if ( ! empty( $_POST['name'] ) ) { // WPCS: CSRF OK. |
|
355 | - $name = sanitize_text_field( wp_unslash( $_POST['name'] ) ); // WPCS: CSRF OK. |
|
354 | + if ( ! empty($_POST['name'])) { // WPCS: CSRF OK. |
|
355 | + $name = sanitize_text_field(wp_unslash($_POST['name'])); // WPCS: CSRF OK. |
|
356 | 356 | |
357 | - if ( ! empty( $name ) ) { |
|
357 | + if ( ! empty($name)) { |
|
358 | 358 | $empty_name = false; |
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
362 | - if ( $empty_name ) { |
|
362 | + if ($empty_name) { |
|
363 | 363 | wp_send_json_error( |
364 | 364 | array( |
365 | - 'message' => __( 'Please enter a name for this rank.', 'wordpoints' ), |
|
365 | + 'message' => __('Please enter a name for this rank.', 'wordpoints'), |
|
366 | 366 | 'field' => 'name', |
367 | 367 | ) |
368 | 368 | ); |
@@ -380,17 +380,17 @@ discard block |
||
380 | 380 | */ |
381 | 381 | private function _get_rank_type() { |
382 | 382 | |
383 | - if ( empty( $_POST['type'] ) ) { // WPCS: CSRF OK. |
|
384 | - $this->_unexpected_error( 'type' ); |
|
383 | + if (empty($_POST['type'])) { // WPCS: CSRF OK. |
|
384 | + $this->_unexpected_error('type'); |
|
385 | 385 | } |
386 | 386 | |
387 | - $type = sanitize_text_field( wp_unslash( $_POST['type'] ) ); // WPCS: CSRF OK. |
|
387 | + $type = sanitize_text_field(wp_unslash($_POST['type'])); // WPCS: CSRF OK. |
|
388 | 388 | |
389 | - if ( ! WordPoints_Rank_Types::is_type_registered( $type ) ) { |
|
390 | - wp_send_json_error( array( 'message' => __( 'That rank type was not recognized. It may no longer be available. Try reloading the page.', 'wordpoints' ) ) ); |
|
389 | + if ( ! WordPoints_Rank_Types::is_type_registered($type)) { |
|
390 | + wp_send_json_error(array('message' => __('That rank type was not recognized. It may no longer be available. Try reloading the page.', 'wordpoints'))); |
|
391 | 391 | } |
392 | 392 | |
393 | - $this->rank_type = WordPoints_Rank_Types::get_type( $type ); |
|
393 | + $this->rank_type = WordPoints_Rank_Types::get_type($type); |
|
394 | 394 | |
395 | 395 | return $this->rank_type; |
396 | 396 | } |
@@ -405,10 +405,10 @@ discard block |
||
405 | 405 | private function _get_rank_position() { |
406 | 406 | |
407 | 407 | if ( |
408 | - ! isset( $_POST['order'] ) // WPCS: CSRF OK. |
|
409 | - || false === wordpoints_int( $_POST['order'] ) // WPCS: CSRF OK. |
|
408 | + ! isset($_POST['order']) // WPCS: CSRF OK. |
|
409 | + || false === wordpoints_int($_POST['order']) // WPCS: CSRF OK. |
|
410 | 410 | ) { |
411 | - $this->_unexpected_error( 'order' ); |
|
411 | + $this->_unexpected_error('order'); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | return (int) $_POST['order']; |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | private function _get_rank_meta() { |
425 | 425 | |
426 | 426 | return array_intersect_key( |
427 | - wp_unslash( $_POST ) // WPCS: CSRF OK. |
|
427 | + wp_unslash($_POST) // WPCS: CSRF OK. |
|
428 | 428 | , $this->rank_type->get_meta_fields() |
429 | 429 | ); |
430 | 430 | } |
@@ -437,19 +437,19 @@ discard block |
||
437 | 437 | * @param mixed $result The result of the action. |
438 | 438 | * @param string $action The action being performed: 'create' or 'update'. |
439 | 439 | */ |
440 | - private function _send_json_result( $result, $action ) { |
|
440 | + private function _send_json_result($result, $action) { |
|
441 | 441 | |
442 | - if ( ! $result ) { |
|
442 | + if ( ! $result) { |
|
443 | 443 | |
444 | - if ( 'create' === $action ) { |
|
445 | - $message = __( 'There was an error adding the rank. Please try again.', 'wordpoints' ); |
|
444 | + if ('create' === $action) { |
|
445 | + $message = __('There was an error adding the rank. Please try again.', 'wordpoints'); |
|
446 | 446 | } else { |
447 | - $message = __( 'There was an error updating the rank. Please try again.', 'wordpoints' ); |
|
447 | + $message = __('There was an error updating the rank. Please try again.', 'wordpoints'); |
|
448 | 448 | } |
449 | 449 | |
450 | - wp_send_json_error( array( 'message' => $message ) ); |
|
450 | + wp_send_json_error(array('message' => $message)); |
|
451 | 451 | |
452 | - } elseif ( is_wp_error( $result ) ) { |
|
452 | + } elseif (is_wp_error($result)) { |
|
453 | 453 | |
454 | 454 | wp_send_json_error( |
455 | 455 | array( |
@@ -461,11 +461,11 @@ discard block |
||
461 | 461 | |
462 | 462 | $data = null; |
463 | 463 | |
464 | - if ( 'create' === $action ) { |
|
465 | - $data = self::_prepare_rank( wordpoints_get_rank( $result ) ); |
|
464 | + if ('create' === $action) { |
|
465 | + $data = self::_prepare_rank(wordpoints_get_rank($result)); |
|
466 | 466 | } |
467 | 467 | |
468 | - wp_send_json_success( $data ); |
|
468 | + wp_send_json_success($data); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | // |
@@ -481,15 +481,15 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @return array The rank data extracted into an array. |
483 | 483 | */ |
484 | - private static function _prepare_rank( $rank ) { |
|
484 | + private static function _prepare_rank($rank) { |
|
485 | 485 | |
486 | 486 | $name = $rank->name; |
487 | - if ( empty( $name ) ) { |
|
488 | - $name = __( '(no title)', 'wordpoints' ); |
|
487 | + if (empty($name)) { |
|
488 | + $name = __('(no title)', 'wordpoints'); |
|
489 | 489 | } |
490 | 490 | |
491 | - $order = WordPoints_Rank_Groups::get_group( $rank->rank_group ) |
|
492 | - ->get_rank_position( $rank->ID ); |
|
491 | + $order = WordPoints_Rank_Groups::get_group($rank->rank_group) |
|
492 | + ->get_rank_position($rank->ID); |
|
493 | 493 | |
494 | 494 | $prepared_rank = array( |
495 | 495 | 'id' => $rank->ID, |
@@ -504,10 +504,10 @@ discard block |
||
504 | 504 | ), |
505 | 505 | ); |
506 | 506 | |
507 | - $rank_type = WordPoints_Rank_Types::get_type( $rank->type ); |
|
507 | + $rank_type = WordPoints_Rank_Types::get_type($rank->type); |
|
508 | 508 | |
509 | - foreach ( $rank_type->get_meta_fields() as $field => $data ) { |
|
510 | - $prepared_rank[ $field ] = $rank->{$field}; |
|
509 | + foreach ($rank_type->get_meta_fields() as $field => $data) { |
|
510 | + $prepared_rank[$field] = $rank->{$field}; |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | return $prepared_rank; |