@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function __construct() { |
| 49 | 49 | |
| 50 | - $this->conditions_extension = wordpoints_hooks()->get_sub_app( 'extensions' )->get( |
|
| 50 | + $this->conditions_extension = wordpoints_hooks()->get_sub_app('extensions')->get( |
|
| 51 | 51 | 'conditions' |
| 52 | 52 | ); |
| 53 | 53 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @since 2.1.0 |
| 57 | 57 | */ |
| 58 | 58 | public function get_title() { |
| 59 | - return __( 'Contains', 'wordpoints' ); |
|
| 59 | + return __('Contains', 'wordpoints'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | return array( |
| 67 | 67 | 'min' => array( |
| 68 | 68 | 'slug' => 'min', |
| 69 | - 'label' => __( 'Minimum number of items', 'wordpoints' ), |
|
| 69 | + 'label' => __('Minimum number of items', 'wordpoints'), |
|
| 70 | 70 | 'type' => 'number', |
| 71 | 71 | 'default' => 1, |
| 72 | 72 | ), |
| 73 | 73 | 'max' => array( |
| 74 | 74 | 'slug' => 'max', |
| 75 | - 'label' => __( 'Maximum number of items', 'wordpoints' ), |
|
| 75 | + 'label' => __('Maximum number of items', 'wordpoints'), |
|
| 76 | 76 | 'type' => 'number', |
| 77 | 77 | ), |
| 78 | 78 | ); |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | $this->validate_count(); |
| 94 | 94 | |
| 95 | - if ( isset( $settings['conditions'] ) ) { |
|
| 96 | - $this->validate_conditions( $arg ); |
|
| 95 | + if (isset($settings['conditions'])) { |
|
| 96 | + $this->validate_conditions($arg); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | return $this->settings; |
@@ -107,31 +107,31 @@ discard block |
||
| 107 | 107 | protected function validate_count() { |
| 108 | 108 | |
| 109 | 109 | if ( |
| 110 | - ! empty( $this->settings['max'] ) |
|
| 111 | - && ! wordpoints_posint( $this->settings['max'] ) |
|
| 110 | + ! empty($this->settings['max']) |
|
| 111 | + && ! wordpoints_posint($this->settings['max']) |
|
| 112 | 112 | ) { |
| 113 | 113 | $this->validator->add_error( |
| 114 | - __( 'The maximum must be a positive integer.', 'wordpoints' ) |
|
| 114 | + __('The maximum must be a positive integer.', 'wordpoints') |
|
| 115 | 115 | , 'max' |
| 116 | 116 | ); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if ( ! empty( $this->settings['min'] ) ) { |
|
| 119 | + if ( ! empty($this->settings['min'])) { |
|
| 120 | 120 | |
| 121 | - if ( ! wordpoints_posint( $this->settings['min'] ) ) { |
|
| 121 | + if ( ! wordpoints_posint($this->settings['min'])) { |
|
| 122 | 122 | |
| 123 | 123 | $this->validator->add_error( |
| 124 | - __( 'The minimum must be a positive integer.', 'wordpoints' ) |
|
| 124 | + __('The minimum must be a positive integer.', 'wordpoints') |
|
| 125 | 125 | , 'min' |
| 126 | 126 | ); |
| 127 | 127 | |
| 128 | 128 | } elseif ( |
| 129 | - ! empty( $this->settings['max'] ) |
|
| 129 | + ! empty($this->settings['max']) |
|
| 130 | 130 | && $this->settings['max'] < $this->settings['min'] |
| 131 | 131 | ) { |
| 132 | 132 | |
| 133 | 133 | $this->validator->add_error( |
| 134 | - __( 'The minimum must be less than the maximum.', 'wordpoints' ) |
|
| 134 | + __('The minimum must be less than the maximum.', 'wordpoints') |
|
| 135 | 135 | , 'min' |
| 136 | 136 | ); |
| 137 | 137 | } |
@@ -145,24 +145,24 @@ discard block |
||
| 145 | 145 | * |
| 146 | 146 | * @param WordPoints_EntityishI $current_arg The current arg. |
| 147 | 147 | */ |
| 148 | - protected function validate_conditions( $current_arg ) { |
|
| 148 | + protected function validate_conditions($current_arg) { |
|
| 149 | 149 | |
| 150 | - $args = new WordPoints_Hook_Event_Args( array() ); |
|
| 150 | + $args = new WordPoints_Hook_Event_Args(array()); |
|
| 151 | 151 | |
| 152 | - if ( $current_arg instanceof WordPoints_Entity_Array ) { |
|
| 152 | + if ($current_arg instanceof WordPoints_Entity_Array) { |
|
| 153 | 153 | |
| 154 | 154 | $entity = wordpoints_entities()->get( |
| 155 | 155 | $current_arg->get_entity_slug() |
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | - if ( $entity instanceof WordPoints_Entity ) { |
|
| 159 | - $args->add_entity( $entity ); |
|
| 158 | + if ($entity instanceof WordPoints_Entity) { |
|
| 159 | + $args->add_entity($entity); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - $args->set_validator( $this->validator ); |
|
| 163 | + $args->set_validator($this->validator); |
|
| 164 | 164 | |
| 165 | - $this->validator->push_field( 'conditions' ); |
|
| 165 | + $this->validator->push_field('conditions'); |
|
| 166 | 166 | |
| 167 | 167 | $this->settings['conditions'] = $this->conditions_extension->validate_conditions( |
| 168 | 168 | $this->settings['conditions'] |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | /** |
| 176 | 176 | * @since 2.1.0 |
| 177 | 177 | */ |
| 178 | - public function is_met( array $settings, WordPoints_Hook_Event_Args $args ) { |
|
| 178 | + public function is_met(array $settings, WordPoints_Hook_Event_Args $args) { |
|
| 179 | 179 | |
| 180 | 180 | $this->settings = $settings; |
| 181 | 181 | |
@@ -183,16 +183,16 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | $entities = array(); |
| 185 | 185 | |
| 186 | - if ( $arg instanceof WordPoints_Entity_Array ) { |
|
| 186 | + if ($arg instanceof WordPoints_Entity_Array) { |
|
| 187 | 187 | |
| 188 | 188 | $entities = $arg->get_the_entities(); |
| 189 | 189 | |
| 190 | - if ( isset( $this->settings['conditions'] ) ) { |
|
| 191 | - $entities = $this->filter_entities( $entities ); |
|
| 190 | + if (isset($this->settings['conditions'])) { |
|
| 191 | + $entities = $this->filter_entities($entities); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - return $this->check_count( count( $entities ) ); |
|
| 195 | + return $this->check_count(count($entities)); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -204,20 +204,20 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @return WordPoints_Entity[] The entities that matched the sub-conditions. |
| 206 | 206 | */ |
| 207 | - protected function filter_entities( $entities ) { |
|
| 207 | + protected function filter_entities($entities) { |
|
| 208 | 208 | |
| 209 | - foreach ( $entities as $index => $entity ) { |
|
| 209 | + foreach ($entities as $index => $entity) { |
|
| 210 | 210 | |
| 211 | - $event_args = new WordPoints_Hook_Event_Args( array() ); |
|
| 212 | - $event_args->add_entity( $entity ); |
|
| 211 | + $event_args = new WordPoints_Hook_Event_Args(array()); |
|
| 212 | + $event_args->add_entity($entity); |
|
| 213 | 213 | |
| 214 | 214 | $matches = $this->conditions_extension->conditions_are_met( |
| 215 | 215 | $this->settings['conditions'] |
| 216 | 216 | , $event_args |
| 217 | 217 | ); |
| 218 | 218 | |
| 219 | - if ( ! $matches ) { |
|
| 220 | - unset( $entities[ $index ] ); |
|
| 219 | + if ( ! $matches) { |
|
| 220 | + unset($entities[$index]); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | * |
| 234 | 234 | * @return bool Whether the count met the requirements. |
| 235 | 235 | */ |
| 236 | - protected function check_count( $count ) { |
|
| 236 | + protected function check_count($count) { |
|
| 237 | 237 | |
| 238 | - if ( isset( $this->settings['max'] ) && $count > $this->settings['max'] ) { |
|
| 238 | + if (isset($this->settings['max']) && $count > $this->settings['max']) { |
|
| 239 | 239 | return false; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if ( isset( $this->settings['min'] ) && $count < $this->settings['min'] ) { |
|
| 242 | + if (isset($this->settings['min']) && $count < $this->settings['min']) { |
|
| 243 | 243 | return false; |
| 244 | 244 | } |
| 245 | 245 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @since 2.1.0 |
| 19 | 19 | */ |
| 20 | 20 | public function get_title() { |
| 21 | - return __( 'Equals', 'wordpoints' ); |
|
| 21 | + return __('Equals', 'wordpoints'); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | return array( |
| 30 | 30 | 'value' => array( |
| 31 | 31 | 'type' => 'text', |
| 32 | - 'label' => _x( 'Value', 'equals hook condition label', 'wordpoints' ), |
|
| 32 | + 'label' => _x('Value', 'equals hook condition label', 'wordpoints'), |
|
| 33 | 33 | ), |
| 34 | 34 | ); |
| 35 | 35 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @since 2.1.0 |
| 39 | 39 | */ |
| 40 | - public function is_met( array $settings, WordPoints_Hook_Event_Args $args ) { |
|
| 40 | + public function is_met(array $settings, WordPoints_Hook_Event_Args $args) { |
|
| 41 | 41 | |
| 42 | 42 | return $settings['value'] === $args->get_current()->get_the_value(); |
| 43 | 43 | } |
@@ -111,21 +111,21 @@ discard block |
||
| 111 | 111 | ) { |
| 112 | 112 | |
| 113 | 113 | if ( |
| 114 | - empty( $settings['target'] ) |
|
| 115 | - || ! is_array( $settings['target'] ) |
|
| 114 | + empty($settings['target']) |
|
| 115 | + || ! is_array($settings['target']) |
|
| 116 | 116 | ) { |
| 117 | 117 | |
| 118 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
| 118 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
| 119 | 119 | |
| 120 | 120 | } else { |
| 121 | 121 | |
| 122 | - $target = $event_args->get_from_hierarchy( $settings['target'] ); |
|
| 122 | + $target = $event_args->get_from_hierarchy($settings['target']); |
|
| 123 | 123 | |
| 124 | 124 | if ( |
| 125 | 125 | ! $target instanceof WordPoints_Entity |
| 126 | - || ! in_array( $target->get_slug(), (array) $this->arg_types ) |
|
| 126 | + || ! in_array($target->get_slug(), (array) $this->arg_types) |
|
| 127 | 127 | ) { |
| 128 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
| 128 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | /** |
| 136 | 136 | * @since 2.1.0 |
| 137 | 137 | */ |
| 138 | - public function update_settings( WordPoints_Hook_ReactionI $reaction, array $settings ) { |
|
| 139 | - $reaction->update_meta( 'target', $settings['target'] ); |
|
| 138 | + public function update_settings(WordPoints_Hook_ReactionI $reaction, array $settings) { |
|
| 139 | + $reaction->update_meta('target', $settings['target']); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function hit() { |
| 90 | 90 | |
| 91 | - if ( ! $this->hit_id ) { |
|
| 91 | + if ( ! $this->hit_id) { |
|
| 92 | 92 | |
| 93 | 93 | $this->hit_id = $this->log_hit(); |
| 94 | 94 | |
| 95 | - if ( ! $this->hit_id ) { |
|
| 95 | + if ( ! $this->hit_id) { |
|
| 96 | 96 | return false; |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -128,11 +128,11 @@ discard block |
||
| 128 | 128 | $this->reaction->get_context_id() |
| 129 | 129 | ), |
| 130 | 130 | 'reaction_id' => $this->reaction->get_id(), |
| 131 | - 'date' => current_time( 'mysql', true ), |
|
| 131 | + 'date' => current_time('mysql', true), |
|
| 132 | 132 | ) |
| 133 | 133 | ); |
| 134 | 134 | |
| 135 | - if ( ! $inserted ) { |
|
| 135 | + if ( ! $inserted) { |
|
| 136 | 136 | return false; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -23,33 +23,33 @@ discard block |
||
| 23 | 23 | WordPoints_Hook_Reaction_Validator $validator |
| 24 | 24 | ) { |
| 25 | 25 | |
| 26 | - if ( ! isset( $settings['value'] ) || '' === $settings['value'] ) { |
|
| 26 | + if ( ! isset($settings['value']) || '' === $settings['value']) { |
|
| 27 | 27 | |
| 28 | 28 | $settings_fields = $this->get_settings_fields(); |
| 29 | 29 | |
| 30 | 30 | $validator->add_error( |
| 31 | 31 | sprintf( |
| 32 | - __( '%s is required.', 'wordpoints' ) |
|
| 32 | + __('%s is required.', 'wordpoints') |
|
| 33 | 33 | , $settings_fields['value']['label'] |
| 34 | 34 | ) |
| 35 | 35 | , 'value' |
| 36 | 36 | ); |
| 37 | 37 | |
| 38 | - } elseif ( $arg instanceof WordPoints_Entity_Attr ) { |
|
| 38 | + } elseif ($arg instanceof WordPoints_Entity_Attr) { |
|
| 39 | 39 | |
| 40 | - $data_types = wordpoints_apps()->get_sub_app( 'data_types' ); |
|
| 40 | + $data_types = wordpoints_apps()->get_sub_app('data_types'); |
|
| 41 | 41 | |
| 42 | - $data_type = $data_types->get( $arg->get_data_type() ); |
|
| 42 | + $data_type = $data_types->get($arg->get_data_type()); |
|
| 43 | 43 | |
| 44 | 44 | // If this data type isn't recognized, that's probably OK. Validation is |
| 45 | 45 | // just to help the user know that they've made a mistake anyway. |
| 46 | - if ( ! ( $data_type instanceof WordPoints_Data_TypeI ) ) { |
|
| 46 | + if ( ! ($data_type instanceof WordPoints_Data_TypeI)) { |
|
| 47 | 47 | return $settings; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $validated_value = $data_type->validate_value( $settings['value'] ); |
|
| 50 | + $validated_value = $data_type->validate_value($settings['value']); |
|
| 51 | 51 | |
| 52 | - if ( is_wp_error( $validated_value ) ) { |
|
| 52 | + if (is_wp_error($validated_value)) { |
|
| 53 | 53 | |
| 54 | 54 | $settings_fields = $this->get_settings_fields(); |
| 55 | 55 | |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | $settings['value'] = $validated_value; |
| 68 | 68 | |
| 69 | - } elseif ( $arg instanceof WordPoints_Entity ) { |
|
| 69 | + } elseif ($arg instanceof WordPoints_Entity) { |
|
| 70 | 70 | |
| 71 | - if ( ! $arg->exists( $settings['value'] ) ) { |
|
| 71 | + if ( ! $arg->exists($settings['value'])) { |
|
| 72 | 72 | $validator->add_error( |
| 73 | 73 | sprintf( |
| 74 | 74 | // translators: 1. item type, 2. item ID/slug. |
| 75 | - __( '%1$s “%2$s” not found.', 'wordpoints' ) |
|
| 75 | + __('%1$s “%2$s” not found.', 'wordpoints') |
|
| 76 | 76 | , $arg->get_title() |
| 77 | 77 | , $settings['value'] |
| 78 | 78 | ) |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @return bool Whether the reaction exists. |
| 61 | 61 | */ |
| 62 | - public function reaction_exists( $id ); |
|
| 62 | + public function reaction_exists($id); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * Get an reaction object. |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return WordPoints_Hook_ReactionI|false The reaction, or false if nonexistent. |
| 72 | 72 | */ |
| 73 | - public function get_reaction( $id ); |
|
| 73 | + public function get_reaction($id); |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * Create an reaction. |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * The reaction object if created successfully. False or a validator |
| 84 | 84 | * instance if not. |
| 85 | 85 | */ |
| 86 | - public function create_reaction( array $settings ); |
|
| 86 | + public function create_reaction(array $settings); |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * Update an reaction. |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * The reaction object if updated successfully. False or a validator |
| 98 | 98 | * instance if not. |
| 99 | 99 | */ |
| 100 | - public function update_reaction( $id, array $settings ); |
|
| 100 | + public function update_reaction($id, array $settings); |
|
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * Delete an reaction. |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return bool Whether the reaction was deleted successfully. |
| 110 | 110 | */ |
| 111 | - public function delete_reaction( $id ); |
|
| 111 | + public function delete_reaction($id); |
|
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Get all hook reactions for the reactor. |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @return WordPoints_Hook_ReactionI[] |
| 133 | 133 | */ |
| 134 | - public function get_reactions_to_event( $event_slug ); |
|
| 134 | + public function get_reactions_to_event($event_slug); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // EOF |
@@ -27,29 +27,29 @@ |
||
| 27 | 27 | /** |
| 28 | 28 | * @since 2.1.0 |
| 29 | 29 | */ |
| 30 | - public function get_option( $name ) { |
|
| 31 | - return get_site_option( $name ); |
|
| 30 | + public function get_option($name) { |
|
| 31 | + return get_site_option($name); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * @since 2.1.0 |
| 36 | 36 | */ |
| 37 | - protected function add_option( $name, $value ) { |
|
| 38 | - return add_site_option( $name, $value ); |
|
| 37 | + protected function add_option($name, $value) { |
|
| 38 | + return add_site_option($name, $value); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @since 2.1.0 |
| 43 | 43 | */ |
| 44 | - public function update_option( $name, $value ) { |
|
| 45 | - return update_site_option( $name, $value ); |
|
| 44 | + public function update_option($name, $value) { |
|
| 45 | + return update_site_option($name, $value); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * @since 2.1.0 |
| 50 | 50 | */ |
| 51 | - protected function delete_option( $name ) { |
|
| 52 | - return delete_site_option( $name ); |
|
| 51 | + protected function delete_option($name) { |
|
| 52 | + return delete_site_option($name); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
@@ -22,25 +22,25 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @since 2.1.0 |
| 24 | 24 | */ |
| 25 | - public function reaction_exists( $id ) { |
|
| 26 | - return (bool) $this->get_option( $this->get_settings_option_name( $id ) ); |
|
| 25 | + public function reaction_exists($id) { |
|
| 26 | + return (bool) $this->get_option($this->get_settings_option_name($id)); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @since 2.1.0 |
| 31 | 31 | */ |
| 32 | 32 | public function get_reactions() { |
| 33 | - return $this->create_reaction_objects( $this->get_reaction_index() ); |
|
| 33 | + return $this->create_reaction_objects($this->get_reaction_index()); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * @since 2.1.0 |
| 38 | 38 | */ |
| 39 | - public function get_reactions_to_event( $event_slug ) { |
|
| 39 | + public function get_reactions_to_event($event_slug) { |
|
| 40 | 40 | |
| 41 | 41 | $index = $this->get_reaction_index(); |
| 42 | - $index = wp_list_filter( $index, array( 'event' => $event_slug ) ); |
|
| 43 | - return $this->create_reaction_objects( $index ); |
|
| 42 | + $index = wp_list_filter($index, array('event' => $event_slug)); |
|
| 43 | + return $this->create_reaction_objects($index); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | protected function get_reaction_index() { |
| 61 | 61 | |
| 62 | - $index = $this->get_option( $this->get_reaction_index_option_name() ); |
|
| 62 | + $index = $this->get_option($this->get_reaction_index_option_name()); |
|
| 63 | 63 | |
| 64 | - if ( ! is_array( $index ) ) { |
|
| 64 | + if ( ! is_array($index)) { |
|
| 65 | 65 | $index = array(); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @return bool Whether the index was updated successfully. |
| 79 | 79 | */ |
| 80 | - protected function update_reaction_index( $index ) { |
|
| 80 | + protected function update_reaction_index($index) { |
|
| 81 | 81 | |
| 82 | 82 | return $this->update_option( |
| 83 | 83 | $this->get_reaction_index_option_name() |
@@ -96,15 +96,15 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @return string|false The event slug, or false if not found. |
| 98 | 98 | */ |
| 99 | - public function get_reaction_event_from_index( $id ) { |
|
| 99 | + public function get_reaction_event_from_index($id) { |
|
| 100 | 100 | |
| 101 | 101 | $index = $this->get_reaction_index(); |
| 102 | 102 | |
| 103 | - if ( ! isset( $index[ $id ]['event'] ) ) { |
|
| 103 | + if ( ! isset($index[$id]['event'])) { |
|
| 104 | 104 | return false; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - return $index[ $id ]['event']; |
|
| 107 | + return $index[$id]['event']; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -119,17 +119,17 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | * @return bool Whether the event was updated successfully. |
| 121 | 121 | */ |
| 122 | - public function update_reaction_event_in_index( $id, $event ) { |
|
| 122 | + public function update_reaction_event_in_index($id, $event) { |
|
| 123 | 123 | |
| 124 | 124 | $index = $this->get_reaction_index(); |
| 125 | 125 | |
| 126 | - if ( ! isset( $index[ $id ] ) ) { |
|
| 126 | + if ( ! isset($index[$id])) { |
|
| 127 | 127 | return false; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - $index[ $id ]['event'] = $event; |
|
| 130 | + $index[$id]['event'] = $event; |
|
| 131 | 131 | |
| 132 | - return $this->update_reaction_index( $index ); |
|
| 132 | + return $this->update_reaction_index($index); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -141,15 +141,15 @@ discard block |
||
| 141 | 141 | * |
| 142 | 142 | * @return WordPoints_Hook_Reaction_Options[] The objects for the reactions. |
| 143 | 143 | */ |
| 144 | - protected function create_reaction_objects( $index ) { |
|
| 144 | + protected function create_reaction_objects($index) { |
|
| 145 | 145 | |
| 146 | 146 | $reactions = array(); |
| 147 | 147 | |
| 148 | - foreach ( $index as $reaction ) { |
|
| 148 | + foreach ($index as $reaction) { |
|
| 149 | 149 | |
| 150 | - $object = $this->get_reaction( $reaction['id'] ); |
|
| 150 | + $object = $this->get_reaction($reaction['id']); |
|
| 151 | 151 | |
| 152 | - if ( ! $object ) { |
|
| 152 | + if ( ! $object) { |
|
| 153 | 153 | continue; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -162,52 +162,52 @@ discard block |
||
| 162 | 162 | /** |
| 163 | 163 | * @since 2.1.0 |
| 164 | 164 | */ |
| 165 | - public function delete_reaction( $id ) { |
|
| 165 | + public function delete_reaction($id) { |
|
| 166 | 166 | |
| 167 | - if ( ! $this->reaction_exists( $id ) ) { |
|
| 167 | + if ( ! $this->reaction_exists($id)) { |
|
| 168 | 168 | return false; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - $result = $this->delete_option( $this->get_settings_option_name( $id ) ); |
|
| 171 | + $result = $this->delete_option($this->get_settings_option_name($id)); |
|
| 172 | 172 | |
| 173 | - if ( ! $result ) { |
|
| 173 | + if ( ! $result) { |
|
| 174 | 174 | return false; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | $index = $this->get_reaction_index(); |
| 178 | 178 | |
| 179 | - unset( $index[ $id ] ); |
|
| 179 | + unset($index[$id]); |
|
| 180 | 180 | |
| 181 | - return $this->update_reaction_index( $index ); |
|
| 181 | + return $this->update_reaction_index($index); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * @since 2.1.0 |
| 186 | 186 | */ |
| 187 | - protected function _create_reaction( $event_slug ) { |
|
| 187 | + protected function _create_reaction($event_slug) { |
|
| 188 | 188 | |
| 189 | 189 | $index = $this->get_reaction_index(); |
| 190 | 190 | |
| 191 | - $id = $this->get_next_id( $index ); |
|
| 191 | + $id = $this->get_next_id($index); |
|
| 192 | 192 | |
| 193 | - $settings = array( 'event' => $event_slug ); |
|
| 193 | + $settings = array('event' => $event_slug); |
|
| 194 | 194 | |
| 195 | 195 | $result = $this->add_option( |
| 196 | - $this->get_settings_option_name( $id ) |
|
| 196 | + $this->get_settings_option_name($id) |
|
| 197 | 197 | , $settings |
| 198 | 198 | ); |
| 199 | 199 | |
| 200 | - if ( ! $result ) { |
|
| 200 | + if ( ! $result) { |
|
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - $index[ $id ] = array( 'event' => $event_slug, 'id' => $id ); |
|
| 204 | + $index[$id] = array('event' => $event_slug, 'id' => $id); |
|
| 205 | 205 | |
| 206 | - if ( ! $this->update_reaction_index( $index ) ) { |
|
| 206 | + if ( ! $this->update_reaction_index($index)) { |
|
| 207 | 207 | return false; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - $this->update_option( $this->get_last_reaction_id_option_name(), $id ); |
|
| 210 | + $this->update_option($this->get_last_reaction_id_option_name(), $id); |
|
| 211 | 211 | |
| 212 | 212 | return $id; |
| 213 | 213 | } |
@@ -221,23 +221,23 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return int The ID to use for the next reaction. |
| 223 | 223 | */ |
| 224 | - protected function get_next_id( $index ) { |
|
| 224 | + protected function get_next_id($index) { |
|
| 225 | 225 | |
| 226 | 226 | $id = 1; |
| 227 | 227 | |
| 228 | - $last_id = $this->get_option( $this->get_last_reaction_id_option_name() ); |
|
| 228 | + $last_id = $this->get_option($this->get_last_reaction_id_option_name()); |
|
| 229 | 229 | |
| 230 | - if ( wordpoints_posint( $last_id ) ) { |
|
| 230 | + if (wordpoints_posint($last_id)) { |
|
| 231 | 231 | $id = $last_id + 1; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | // Double-check this against the index. This should avoid some issues from |
| 235 | 235 | // race conditions. |
| 236 | - if ( ! empty( $index ) ) { |
|
| 236 | + if ( ! empty($index)) { |
|
| 237 | 237 | |
| 238 | - $max = max( array_keys( $index ) ); |
|
| 238 | + $max = max(array_keys($index)); |
|
| 239 | 239 | |
| 240 | - if ( $max >= $id ) { |
|
| 240 | + if ($max >= $id) { |
|
| 241 | 241 | $id = $max + 1; |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -256,8 +256,8 @@ discard block |
||
| 256 | 256 | * |
| 257 | 257 | * @return mixed The option value, or false. |
| 258 | 258 | */ |
| 259 | - public function get_option( $name ) { |
|
| 260 | - return get_option( $name ); |
|
| 259 | + public function get_option($name) { |
|
| 260 | + return get_option($name); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return bool Whether the option was added successfully. |
| 272 | 272 | */ |
| 273 | - protected function add_option( $name, $value ) { |
|
| 274 | - return add_option( $name, $value ); |
|
| 273 | + protected function add_option($name, $value) { |
|
| 274 | + return add_option($name, $value); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | * |
| 287 | 287 | * @return bool Whether the option was updated successfully. |
| 288 | 288 | */ |
| 289 | - public function update_option( $name, $value ) { |
|
| 290 | - return update_option( $name, $value ); |
|
| 289 | + public function update_option($name, $value) { |
|
| 290 | + return update_option($name, $value); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -299,8 +299,8 @@ discard block |
||
| 299 | 299 | * |
| 300 | 300 | * @return bool Whether the option was deleted successfully. |
| 301 | 301 | */ |
| 302 | - protected function delete_option( $name ) { |
|
| 303 | - return delete_option( $name ); |
|
| 302 | + protected function delete_option($name) { |
|
| 303 | + return delete_option($name); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * |
| 315 | 315 | * @return string The name of the option where the settings are stored. |
| 316 | 316 | */ |
| 317 | - public function get_settings_option_name( $id ) { |
|
| 317 | + public function get_settings_option_name($id) { |
|
| 318 | 318 | return "wordpoints_hook_reaction-{$this->slug}-{$this->mode_slug}-{$id}"; |
| 319 | 319 | } |
| 320 | 320 | |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | * @since 2.1.0 |
| 26 | 26 | */ |
| 27 | 27 | public function get_event_slug() { |
| 28 | - return $this->store->get_reaction_event_from_index( $this->ID ); |
|
| 28 | + return $this->store->get_reaction_event_from_index($this->ID); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * @since 2.1.0 |
| 33 | 33 | */ |
| 34 | - public function update_event_slug( $event_slug ) { |
|
| 34 | + public function update_event_slug($event_slug) { |
|
| 35 | 35 | return $this->store->update_reaction_event_in_index( |
| 36 | 36 | $this->ID |
| 37 | 37 | , $event_slug |
@@ -41,63 +41,63 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * @since 2.1.0 |
| 43 | 43 | */ |
| 44 | - public function get_meta( $key ) { |
|
| 44 | + public function get_meta($key) { |
|
| 45 | 45 | |
| 46 | 46 | $settings = $this->get_settings(); |
| 47 | 47 | |
| 48 | - if ( ! is_array( $settings ) || ! isset( $settings[ $key ] ) ) { |
|
| 48 | + if ( ! is_array($settings) || ! isset($settings[$key])) { |
|
| 49 | 49 | return false; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - return $settings[ $key ]; |
|
| 52 | + return $settings[$key]; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * @since 2.1.0 |
| 57 | 57 | */ |
| 58 | - public function add_meta( $key, $value ) { |
|
| 58 | + public function add_meta($key, $value) { |
|
| 59 | 59 | |
| 60 | 60 | $settings = $this->get_settings(); |
| 61 | 61 | |
| 62 | - if ( ! is_array( $settings ) || isset( $settings[ $key ] ) ) { |
|
| 62 | + if ( ! is_array($settings) || isset($settings[$key])) { |
|
| 63 | 63 | return false; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - $settings[ $key ] = $value; |
|
| 66 | + $settings[$key] = $value; |
|
| 67 | 67 | |
| 68 | - return $this->update_settings( $settings ); |
|
| 68 | + return $this->update_settings($settings); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @since 2.1.0 |
| 73 | 73 | */ |
| 74 | - public function update_meta( $key, $value ) { |
|
| 74 | + public function update_meta($key, $value) { |
|
| 75 | 75 | |
| 76 | 76 | $settings = $this->get_settings(); |
| 77 | 77 | |
| 78 | - if ( ! is_array( $settings ) ) { |
|
| 78 | + if ( ! is_array($settings)) { |
|
| 79 | 79 | return false; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - $settings[ $key ] = $value; |
|
| 82 | + $settings[$key] = $value; |
|
| 83 | 83 | |
| 84 | - return $this->update_settings( $settings ); |
|
| 84 | + return $this->update_settings($settings); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * @since 2.1.0 |
| 89 | 89 | */ |
| 90 | - public function delete_meta( $key ) { |
|
| 90 | + public function delete_meta($key) { |
|
| 91 | 91 | |
| 92 | 92 | $settings = $this->get_settings(); |
| 93 | 93 | |
| 94 | - if ( ! is_array( $settings ) || ! isset( $settings[ $key ] ) ) { |
|
| 94 | + if ( ! is_array($settings) || ! isset($settings[$key])) { |
|
| 95 | 95 | return false; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - unset( $settings[ $key ] ); |
|
| 98 | + unset($settings[$key]); |
|
| 99 | 99 | |
| 100 | - return $this->update_settings( $settings ); |
|
| 100 | + return $this->update_settings($settings); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | protected function get_settings() { |
| 118 | 118 | |
| 119 | 119 | return $this->store->get_option( |
| 120 | - $this->store->get_settings_option_name( $this->ID ) |
|
| 120 | + $this->store->get_settings_option_name($this->ID) |
|
| 121 | 121 | ); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | * @return bool Whether the settings were updated successfully. |
| 132 | 132 | */ |
| 133 | - protected function update_settings( $settings ) { |
|
| 133 | + protected function update_settings($settings) { |
|
| 134 | 134 | |
| 135 | 135 | return $this->store->update_option( |
| 136 | - $this->store->get_settings_option_name( $this->ID ) |
|
| 136 | + $this->store->get_settings_option_name($this->ID) |
|
| 137 | 137 | , $settings |
| 138 | 138 | ); |
| 139 | 139 | } |