@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | public $action_options; // Option array passed to wp_register_sidebar_widget() |
| 9 | 9 | public $control_options; // Option array passed to wp_register_widget_control() |
| 10 | 10 | |
| 11 | - public $form_id; // The ID of the form to evaluate |
|
| 11 | + public $form_id; // The ID of the form to evaluate |
|
| 12 | 12 | public $number = false; // Unique ID number of the current instance. |
| 13 | 13 | public $id = ''; // Unique ID string of the current instance (id_base-number) |
| 14 | 14 | public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * Echo the settings update form |
|
| 32 | + * Echo the settings update form |
|
| 33 | 33 | * |
| 34 | 34 | * @param array $instance Current settings |
| 35 | 35 | */ |
@@ -42,15 +42,15 @@ discard block |
||
| 42 | 42 | * @return array of the default options |
| 43 | 43 | */ |
| 44 | 44 | public function get_defaults() { |
| 45 | - return array(); |
|
| 45 | + return array(); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public function get_switch_fields() { |
| 49 | - return array(); |
|
| 49 | + return array(); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function migrate_values( $action, $form ) { |
| 53 | - return $action; |
|
| 53 | + return $action; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Functions you'll need to call. |
@@ -69,24 +69,24 @@ discard block |
||
| 69 | 69 | * - height: currently not used but may be needed in the future |
| 70 | 70 | */ |
| 71 | 71 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
| 72 | - if ( ! defined('ABSPATH') ) { |
|
| 73 | - die('You are not allowed to call this page directly.'); |
|
| 74 | - } |
|
| 72 | + if ( ! defined('ABSPATH') ) { |
|
| 73 | + die('You are not allowed to call this page directly.'); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | $this->id_base = strtolower($id_base); |
| 77 | 77 | $this->name = $name; |
| 78 | 78 | $this->option_name = 'frm_' . $this->id_base . '_action'; |
| 79 | 79 | |
| 80 | - $default_options = array( |
|
| 81 | - 'classes' => '', |
|
| 82 | - 'active' => true, |
|
| 80 | + $default_options = array( |
|
| 81 | + 'classes' => '', |
|
| 82 | + 'active' => true, |
|
| 83 | 83 | 'event' => array( 'create' ), |
| 84 | - 'limit' => 1, |
|
| 85 | - 'force_event' => false, |
|
| 86 | - 'priority' => 20, |
|
| 87 | - 'ajax_load' => true, |
|
| 88 | - 'tooltip' => $name, |
|
| 89 | - ); |
|
| 84 | + 'limit' => 1, |
|
| 85 | + 'force_event' => false, |
|
| 86 | + 'priority' => 20, |
|
| 87 | + 'ajax_load' => true, |
|
| 88 | + 'tooltip' => $name, |
|
| 89 | + ); |
|
| 90 | 90 | |
| 91 | 91 | $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options ); |
| 92 | 92 | $this->action_options = wp_parse_args( $action_options, $default_options ); |
@@ -135,132 +135,132 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | public function prepare_new( $form_id = false ) { |
| 138 | - if ( $form_id ) { |
|
| 139 | - $this->form_id = $form_id; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $post_content = array(); |
|
| 143 | - $default_values = $this->get_global_defaults(); |
|
| 144 | - |
|
| 145 | - // fill default values |
|
| 146 | - $post_content = wp_parse_args( $post_content, $default_values); |
|
| 147 | - |
|
| 148 | - if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
| 149 | - $post_content['event'] = array( reset($this->action_options['event']) ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $form_action = array( |
|
| 153 | - 'post_title' => $this->name, |
|
| 154 | - 'post_content' => $post_content, |
|
| 155 | - 'post_excerpt' => $this->id_base, |
|
| 156 | - 'ID' => '', |
|
| 157 | - 'post_status' => 'publish', |
|
| 158 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
| 138 | + if ( $form_id ) { |
|
| 139 | + $this->form_id = $form_id; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $post_content = array(); |
|
| 143 | + $default_values = $this->get_global_defaults(); |
|
| 144 | + |
|
| 145 | + // fill default values |
|
| 146 | + $post_content = wp_parse_args( $post_content, $default_values); |
|
| 147 | + |
|
| 148 | + if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
| 149 | + $post_content['event'] = array( reset($this->action_options['event']) ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $form_action = array( |
|
| 153 | + 'post_title' => $this->name, |
|
| 154 | + 'post_content' => $post_content, |
|
| 155 | + 'post_excerpt' => $this->id_base, |
|
| 156 | + 'ID' => '', |
|
| 157 | + 'post_status' => 'publish', |
|
| 158 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
| 159 | 159 | 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number, |
| 160 | - 'menu_order' => $this->form_id, |
|
| 161 | - ); |
|
| 162 | - unset($post_content); |
|
| 160 | + 'menu_order' => $this->form_id, |
|
| 161 | + ); |
|
| 162 | + unset($post_content); |
|
| 163 | 163 | |
| 164 | - return (object) $form_action; |
|
| 165 | - } |
|
| 164 | + return (object) $form_action; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | public function create( $form_id ) { |
| 168 | - $this->form_id = $form_id; |
|
| 168 | + $this->form_id = $form_id; |
|
| 169 | 169 | |
| 170 | - $action = $this->prepare_new(); |
|
| 170 | + $action = $this->prepare_new(); |
|
| 171 | 171 | |
| 172 | - return $this->save_settings($action); |
|
| 173 | - } |
|
| 172 | + return $this->save_settings($action); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | public function duplicate_form_actions( $form_id, $old_id ) { |
| 176 | - if ( $form_id == $old_id ) { |
|
| 177 | - // don't duplicate the actions if this is a template getting updated |
|
| 178 | - return; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $this->form_id = $old_id; |
|
| 182 | - $actions = $this->get_all( $old_id ); |
|
| 183 | - |
|
| 184 | - $this->form_id = $form_id; |
|
| 185 | - foreach ( $actions as $action ) { |
|
| 186 | - $this->duplicate_one($action, $form_id); |
|
| 187 | - unset($action); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /* Check if imported action should be created or updated |
|
| 176 | + if ( $form_id == $old_id ) { |
|
| 177 | + // don't duplicate the actions if this is a template getting updated |
|
| 178 | + return; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $this->form_id = $old_id; |
|
| 182 | + $actions = $this->get_all( $old_id ); |
|
| 183 | + |
|
| 184 | + $this->form_id = $form_id; |
|
| 185 | + foreach ( $actions as $action ) { |
|
| 186 | + $this->duplicate_one($action, $form_id); |
|
| 187 | + unset($action); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /* Check if imported action should be created or updated |
|
| 192 | 192 | * |
| 193 | 193 | * Since 2.0 |
| 194 | 194 | * |
| 195 | 195 | * @param array $action |
| 196 | 196 | * @return integer $post_id |
| 197 | 197 | */ |
| 198 | - public function maybe_create_action( $action, $forms ) { |
|
| 198 | + public function maybe_create_action( $action, $forms ) { |
|
| 199 | 199 | if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
| 200 | - // Update action only |
|
| 201 | - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
| 202 | - $post_id = $this->save_settings( $action ); |
|
| 203 | - } else { |
|
| 204 | - // Create action |
|
| 205 | - $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
| 206 | - $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
| 207 | - } |
|
| 208 | - return $post_id; |
|
| 209 | - } |
|
| 200 | + // Update action only |
|
| 201 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
| 202 | + $post_id = $this->save_settings( $action ); |
|
| 203 | + } else { |
|
| 204 | + // Create action |
|
| 205 | + $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
| 206 | + $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
| 207 | + } |
|
| 208 | + return $post_id; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | public function duplicate_one( $action, $form_id ) { |
| 212 | - global $frm_duplicate_ids; |
|
| 212 | + global $frm_duplicate_ids; |
|
| 213 | 213 | |
| 214 | - $action->menu_order = $form_id; |
|
| 215 | - $switch = $this->get_global_switch_fields(); |
|
| 216 | - foreach ( (array) $action->post_content as $key => $val ) { |
|
| 214 | + $action->menu_order = $form_id; |
|
| 215 | + $switch = $this->get_global_switch_fields(); |
|
| 216 | + foreach ( (array) $action->post_content as $key => $val ) { |
|
| 217 | 217 | if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
| 218 | 218 | $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
| 219 | - } else if ( ! is_array( $val ) ) { |
|
| 219 | + } else if ( ! is_array( $val ) ) { |
|
| 220 | 220 | $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
| 221 | 221 | } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
| 222 | - // loop through each value if empty |
|
| 222 | + // loop through each value if empty |
|
| 223 | 223 | if ( empty( $switch[ $key ] ) ) { |
| 224 | 224 | $switch[ $key ] = array_keys( $val ); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | foreach ( $switch[ $key ] as $subkey ) { |
| 228 | 228 | $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
| 229 | - } |
|
| 230 | - } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - unset($key, $val); |
|
| 233 | - } |
|
| 234 | - unset($action->ID); |
|
| 232 | + unset($key, $val); |
|
| 233 | + } |
|
| 234 | + unset($action->ID); |
|
| 235 | 235 | |
| 236 | - return $this->save_settings($action); |
|
| 237 | - } |
|
| 236 | + return $this->save_settings($action); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | private function duplicate_array_walk( $action, $subkey, $val ) { |
| 240 | - global $frm_duplicate_ids; |
|
| 240 | + global $frm_duplicate_ids; |
|
| 241 | 241 | |
| 242 | - if ( is_array($subkey) ) { |
|
| 243 | - foreach ( $subkey as $subkey2 ) { |
|
| 244 | - foreach ( (array) $val as $ck => $cv ) { |
|
| 245 | - if ( is_array($cv) ) { |
|
| 242 | + if ( is_array($subkey) ) { |
|
| 243 | + foreach ( $subkey as $subkey2 ) { |
|
| 244 | + foreach ( (array) $val as $ck => $cv ) { |
|
| 245 | + if ( is_array($cv) ) { |
|
| 246 | 246 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
| 247 | 247 | } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
| 248 | 248 | $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
| 249 | - } |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } else { |
|
| 253 | - foreach ( (array) $val as $ck => $cv ) { |
|
| 254 | - if ( is_array($cv) ) { |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } else { |
|
| 253 | + foreach ( (array) $val as $ck => $cv ) { |
|
| 254 | + if ( is_array($cv) ) { |
|
| 255 | 255 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
| 256 | 256 | } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
| 257 | 257 | $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
| 258 | - } |
|
| 259 | - } |
|
| 260 | - } |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return $action; |
|
| 263 | - } |
|
| 262 | + return $action; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | 266 | * Deal with changed settings. |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | */ |
| 271 | 271 | public function update_callback( $form_id ) { |
| 272 | - $this->form_id = $form_id; |
|
| 272 | + $this->form_id = $form_id; |
|
| 273 | 273 | |
| 274 | 274 | $all_instances = $this->get_settings(); |
| 275 | 275 | |
@@ -284,25 +284,25 @@ discard block |
||
| 284 | 284 | return; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - $action_ids = array(); |
|
| 287 | + $action_ids = array(); |
|
| 288 | 288 | |
| 289 | 289 | foreach ( $settings as $number => $new_instance ) { |
| 290 | 290 | $this->_set($number); |
| 291 | 291 | |
| 292 | 292 | if ( ! isset($new_instance['post_title']) ) { |
| 293 | - // settings were never opened, so don't update |
|
| 294 | - $action_ids[] = $new_instance['ID']; |
|
| 295 | - $this->updated = true; |
|
| 296 | - continue; |
|
| 293 | + // settings were never opened, so don't update |
|
| 294 | + $action_ids[] = $new_instance['ID']; |
|
| 295 | + $this->updated = true; |
|
| 296 | + continue; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); |
| 300 | 300 | |
| 301 | 301 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
| 302 | 302 | $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
| 303 | - $new_instance['menu_order'] = $this->form_id; |
|
| 304 | - $new_instance['post_status'] = 'publish'; |
|
| 305 | - $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
|
| 303 | + $new_instance['menu_order'] = $this->form_id; |
|
| 304 | + $new_instance['post_status'] = 'publish'; |
|
| 305 | + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
|
| 306 | 306 | |
| 307 | 307 | $instance = $this->update( $new_instance, $old_instance ); |
| 308 | 308 | |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | $all_instances[ $number ] = $instance; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $action_ids[] = $this->save_settings($instance); |
|
| 331 | + $action_ids[] = $this->save_settings($instance); |
|
| 332 | 332 | |
| 333 | - $this->updated = true; |
|
| 333 | + $this->updated = true; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | return $action_ids; |
@@ -342,59 +342,59 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | public function get_single_action( $id ) { |
| 345 | - $action = get_post($id); |
|
| 345 | + $action = get_post($id); |
|
| 346 | 346 | if ( $action ) { |
| 347 | 347 | $action = $this->prepare_action( $action ); |
| 348 | 348 | $this->_set( $id ); |
| 349 | 349 | } |
| 350 | - return $action; |
|
| 350 | + return $action; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | public function get_one( $form_id ) { |
| 354 | - return $this->get_all($form_id, 1); |
|
| 354 | + return $this->get_all($form_id, 1); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
|
| 358 | - $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
| 359 | - if ( empty($action_controls) ) { |
|
| 360 | - // don't continue if there are no available actions |
|
| 361 | - return array(); |
|
| 362 | - } |
|
| 357 | + public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
|
| 358 | + $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
| 359 | + if ( empty($action_controls) ) { |
|
| 360 | + // don't continue if there are no available actions |
|
| 361 | + return array(); |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | - if ( 'all' != $type ) { |
|
| 365 | - return $action_controls->get_all( $form_id, $limit ); |
|
| 366 | - } |
|
| 364 | + if ( 'all' != $type ) { |
|
| 365 | + return $action_controls->get_all( $form_id, $limit ); |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | 368 | $args = self::action_args( $form_id, $limit ); |
| 369 | 369 | $actions = FrmAppHelper::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' ); |
| 370 | 370 | |
| 371 | - if ( ! $actions ) { |
|
| 372 | - return array(); |
|
| 373 | - } |
|
| 371 | + if ( ! $actions ) { |
|
| 372 | + return array(); |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - $settings = array(); |
|
| 376 | - foreach ( $actions as $action ) { |
|
| 375 | + $settings = array(); |
|
| 376 | + foreach ( $actions as $action ) { |
|
| 377 | 377 | // some plugins/themes are formatting the post_excerpt |
| 378 | 378 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 379 | 379 | |
| 380 | 380 | if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
| 381 | - continue; |
|
| 382 | - } |
|
| 381 | + continue; |
|
| 382 | + } |
|
| 383 | 383 | |
| 384 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
| 384 | + $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
| 385 | 385 | $settings[ $action->ID ] = $action; |
| 386 | 386 | |
| 387 | 387 | if ( count( $settings ) >= $limit ) { |
| 388 | 388 | break; |
| 389 | 389 | } |
| 390 | - } |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | - if ( 1 === $limit ) { |
|
| 393 | - $settings = reset($settings); |
|
| 394 | - } |
|
| 392 | + if ( 1 === $limit ) { |
|
| 393 | + $settings = reset($settings); |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - return $settings; |
|
| 397 | - } |
|
| 396 | + return $settings; |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | 399 | /** |
| 400 | 400 | * @param int $action_id |
@@ -414,45 +414,45 @@ discard block |
||
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | public function get_all( $form_id = false, $limit = 99 ) { |
| 417 | - if ( $form_id ) { |
|
| 418 | - $this->form_id = $form_id; |
|
| 419 | - } |
|
| 417 | + if ( $form_id ) { |
|
| 418 | + $this->form_id = $form_id; |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - $type = $this->id_base; |
|
| 421 | + $type = $this->id_base; |
|
| 422 | 422 | |
| 423 | - global $frm_vars; |
|
| 424 | - $frm_vars['action_type'] = $type; |
|
| 423 | + global $frm_vars; |
|
| 424 | + $frm_vars['action_type'] = $type; |
|
| 425 | 425 | |
| 426 | - add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
| 426 | + add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
| 427 | 427 | $query = self::action_args( $form_id, $limit ); |
| 428 | - $query['post_status'] = 'any'; |
|
| 429 | - $query['suppress_filters'] = false; |
|
| 428 | + $query['post_status'] = 'any'; |
|
| 429 | + $query['suppress_filters'] = false; |
|
| 430 | 430 | |
| 431 | 431 | $actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
| 432 | - unset($query); |
|
| 432 | + unset($query); |
|
| 433 | 433 | |
| 434 | - remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
| 434 | + remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
| 435 | 435 | |
| 436 | - if ( empty($actions) ) { |
|
| 437 | - return array(); |
|
| 438 | - } |
|
| 436 | + if ( empty($actions) ) { |
|
| 437 | + return array(); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - $settings = array(); |
|
| 441 | - foreach ( $actions as $action ) { |
|
| 442 | - if ( count($settings) >= $limit ) { |
|
| 443 | - continue; |
|
| 444 | - } |
|
| 440 | + $settings = array(); |
|
| 441 | + foreach ( $actions as $action ) { |
|
| 442 | + if ( count($settings) >= $limit ) { |
|
| 443 | + continue; |
|
| 444 | + } |
|
| 445 | 445 | |
| 446 | - $action = $this->prepare_action($action); |
|
| 446 | + $action = $this->prepare_action($action); |
|
| 447 | 447 | |
| 448 | 448 | $settings[ $action->ID ] = $action; |
| 449 | - } |
|
| 449 | + } |
|
| 450 | 450 | |
| 451 | - if ( 1 === $limit ) { |
|
| 452 | - $settings = reset($settings); |
|
| 453 | - } |
|
| 451 | + if ( 1 === $limit ) { |
|
| 452 | + $settings = reset($settings); |
|
| 453 | + } |
|
| 454 | 454 | |
| 455 | - return $settings; |
|
| 455 | + return $settings; |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | public static function action_args( $form_id = 0, $limit = 99 ) { |
@@ -475,45 +475,45 @@ discard block |
||
| 475 | 475 | $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
| 476 | 476 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 477 | 477 | |
| 478 | - $default_values = $this->get_global_defaults(); |
|
| 478 | + $default_values = $this->get_global_defaults(); |
|
| 479 | 479 | |
| 480 | - // fill default values |
|
| 481 | - $action->post_content += $default_values; |
|
| 480 | + // fill default values |
|
| 481 | + $action->post_content += $default_values; |
|
| 482 | 482 | |
| 483 | - foreach ( $default_values as $k => $vals ) { |
|
| 484 | - if ( is_array($vals) && ! empty($vals) ) { |
|
| 483 | + foreach ( $default_values as $k => $vals ) { |
|
| 484 | + if ( is_array($vals) && ! empty($vals) ) { |
|
| 485 | 485 | if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
| 486 | - continue; |
|
| 487 | - } |
|
| 486 | + continue; |
|
| 487 | + } |
|
| 488 | 488 | $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
| 489 | - } |
|
| 490 | - } |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | 491 | |
| 492 | - if ( ! is_array($action->post_content['event']) ) { |
|
| 493 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
| 494 | - } |
|
| 492 | + if ( ! is_array($action->post_content['event']) ) { |
|
| 493 | + $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
| 494 | + } |
|
| 495 | 495 | |
| 496 | - return $action; |
|
| 496 | + return $action; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | public function destroy( $form_id = false, $type = 'default' ) { |
| 500 | - global $wpdb; |
|
| 500 | + global $wpdb; |
|
| 501 | 501 | |
| 502 | - $this->form_id = $form_id; |
|
| 502 | + $this->form_id = $form_id; |
|
| 503 | 503 | |
| 504 | - $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
| 505 | - if ( $form_id ) { |
|
| 506 | - $query['menu_order'] = $form_id; |
|
| 507 | - } |
|
| 508 | - if ( 'all' != $type ) { |
|
| 509 | - $query['post_excerpt'] = $this->id_base; |
|
| 510 | - } |
|
| 504 | + $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
| 505 | + if ( $form_id ) { |
|
| 506 | + $query['menu_order'] = $form_id; |
|
| 507 | + } |
|
| 508 | + if ( 'all' != $type ) { |
|
| 509 | + $query['post_excerpt'] = $this->id_base; |
|
| 510 | + } |
|
| 511 | 511 | |
| 512 | - $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
| 512 | + $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
| 513 | 513 | |
| 514 | - foreach ( $post_ids as $id ) { |
|
| 515 | - wp_delete_post($id); |
|
| 516 | - } |
|
| 514 | + foreach ( $post_ids as $id ) { |
|
| 515 | + wp_delete_post($id); |
|
| 516 | + } |
|
| 517 | 517 | self::clear_cache(); |
| 518 | 518 | } |
| 519 | 519 | |
@@ -531,69 +531,69 @@ discard block |
||
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | public function get_global_defaults() { |
| 534 | - $defaults = $this->get_defaults(); |
|
| 534 | + $defaults = $this->get_defaults(); |
|
| 535 | 535 | |
| 536 | - if ( ! isset($defaults['event']) ) { |
|
| 536 | + if ( ! isset($defaults['event']) ) { |
|
| 537 | 537 | $defaults['event'] = array( 'create' ); |
| 538 | - } |
|
| 538 | + } |
|
| 539 | 539 | |
| 540 | - if ( ! isset($defaults['conditions']) ) { |
|
| 541 | - $defaults['conditions'] = array( |
|
| 542 | - 'send_stop' => '', |
|
| 543 | - 'any_all' => '', |
|
| 544 | - ); |
|
| 545 | - } |
|
| 540 | + if ( ! isset($defaults['conditions']) ) { |
|
| 541 | + $defaults['conditions'] = array( |
|
| 542 | + 'send_stop' => '', |
|
| 543 | + 'any_all' => '', |
|
| 544 | + ); |
|
| 545 | + } |
|
| 546 | 546 | |
| 547 | - return $defaults; |
|
| 547 | + return $defaults; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | public function get_global_switch_fields() { |
| 551 | - $switch = $this->get_switch_fields(); |
|
| 551 | + $switch = $this->get_switch_fields(); |
|
| 552 | 552 | $switch['conditions'] = array( 'hide_field' ); |
| 553 | - return $switch; |
|
| 553 | + return $switch; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
| 557 | 557 | * Migrate settings from form->options into new action. |
| 558 | 558 | */ |
| 559 | 559 | public function migrate_to_2( $form, $update = 'update' ) { |
| 560 | - $action = $this->prepare_new($form->id); |
|
| 561 | - $form->options = maybe_unserialize($form->options); |
|
| 560 | + $action = $this->prepare_new($form->id); |
|
| 561 | + $form->options = maybe_unserialize($form->options); |
|
| 562 | 562 | |
| 563 | - // fill with existing options |
|
| 564 | - foreach ( $action->post_content as $name => $val ) { |
|
| 563 | + // fill with existing options |
|
| 564 | + foreach ( $action->post_content as $name => $val ) { |
|
| 565 | 565 | if ( isset( $form->options[ $name ] ) ) { |
| 566 | 566 | $action->post_content[ $name ] = $form->options[ $name ]; |
| 567 | 567 | unset( $form->options[ $name ] ); |
| 568 | - } |
|
| 569 | - } |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | - $action = $this->migrate_values($action, $form); |
|
| 571 | + $action = $this->migrate_values($action, $form); |
|
| 572 | 572 | |
| 573 | - // check if action already exists |
|
| 574 | - $post_id = get_posts( array( |
|
| 575 | - 'name' => $action->post_name, |
|
| 576 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
| 577 | - 'post_status' => $action->post_status, |
|
| 578 | - 'numberposts' => 1, |
|
| 579 | - ) ); |
|
| 573 | + // check if action already exists |
|
| 574 | + $post_id = get_posts( array( |
|
| 575 | + 'name' => $action->post_name, |
|
| 576 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
| 577 | + 'post_status' => $action->post_status, |
|
| 578 | + 'numberposts' => 1, |
|
| 579 | + ) ); |
|
| 580 | 580 | |
| 581 | - if ( empty($post_id) ) { |
|
| 582 | - // create action now |
|
| 583 | - $post_id = $this->save_settings($action); |
|
| 584 | - } |
|
| 581 | + if ( empty($post_id) ) { |
|
| 582 | + // create action now |
|
| 583 | + $post_id = $this->save_settings($action); |
|
| 584 | + } |
|
| 585 | 585 | |
| 586 | - if ( $post_id && 'update' == $update ) { |
|
| 587 | - global $wpdb; |
|
| 588 | - $form->options = maybe_serialize($form->options); |
|
| 586 | + if ( $post_id && 'update' == $update ) { |
|
| 587 | + global $wpdb; |
|
| 588 | + $form->options = maybe_serialize($form->options); |
|
| 589 | 589 | |
| 590 | - // update form options |
|
| 590 | + // update form options |
|
| 591 | 591 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
| 592 | - wp_cache_delete( $form->id, 'frm_form'); |
|
| 593 | - } |
|
| 592 | + wp_cache_delete( $form->id, 'frm_form'); |
|
| 593 | + } |
|
| 594 | 594 | |
| 595 | - return $post_id; |
|
| 596 | - } |
|
| 595 | + return $post_id; |
|
| 596 | + } |
|
| 597 | 597 | |
| 598 | 598 | public static function action_conditions_met( $action, $entry ) { |
| 599 | 599 | $notification = $action->post_content; |
@@ -655,13 +655,13 @@ discard block |
||
| 655 | 655 | |
| 656 | 656 | |
| 657 | 657 | /** |
| 658 | - * Get the value from a specific field and entry |
|
| 659 | - * |
|
| 660 | - * @since 2.01.02 |
|
| 661 | - * @param object $entry |
|
| 662 | - * @param int $field_id |
|
| 663 | - * @return array|bool|mixed|string |
|
| 664 | - */ |
|
| 658 | + * Get the value from a specific field and entry |
|
| 659 | + * |
|
| 660 | + * @since 2.01.02 |
|
| 661 | + * @param object $entry |
|
| 662 | + * @param int $field_id |
|
| 663 | + * @return array|bool|mixed|string |
|
| 664 | + */ |
|
| 665 | 665 | private static function get_value_from_entry( $entry, $field_id ) { |
| 666 | 666 | $observed_value = ''; |
| 667 | 667 | |
@@ -2,16 +2,16 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class FrmFormAction { |
| 4 | 4 | |
| 5 | - public $id_base; // Root id for all actions of this type. |
|
| 6 | - public $name; // Name for this action type. |
|
| 5 | + public $id_base; // Root id for all actions of this type. |
|
| 6 | + public $name; // Name for this action type. |
|
| 7 | 7 | public $option_name; |
| 8 | - public $action_options; // Option array passed to wp_register_sidebar_widget() |
|
| 9 | - public $control_options; // Option array passed to wp_register_widget_control() |
|
| 8 | + public $action_options; // Option array passed to wp_register_sidebar_widget() |
|
| 9 | + public $control_options; // Option array passed to wp_register_widget_control() |
|
| 10 | 10 | |
| 11 | - public $form_id; // The ID of the form to evaluate |
|
| 12 | - public $number = false; // Unique ID number of the current instance. |
|
| 13 | - public $id = ''; // Unique ID string of the current instance (id_base-number) |
|
| 14 | - public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
|
| 11 | + public $form_id; // The ID of the form to evaluate |
|
| 12 | + public $number = false; // Unique ID number of the current instance. |
|
| 13 | + public $id = ''; // Unique ID string of the current instance (id_base-number) |
|
| 14 | + public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
|
| 15 | 15 | |
| 16 | 16 | // Member functions that you must over-ride. |
| 17 | 17 | |
@@ -69,11 +69,11 @@ discard block |
||
| 69 | 69 | * - height: currently not used but may be needed in the future |
| 70 | 70 | */ |
| 71 | 71 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
| 72 | - if ( ! defined('ABSPATH') ) { |
|
| 73 | - die('You are not allowed to call this page directly.'); |
|
| 72 | + if ( ! defined( 'ABSPATH' ) ) { |
|
| 73 | + die( 'You are not allowed to call this page directly.' ); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $this->id_base = strtolower($id_base); |
|
| 76 | + $this->id_base = strtolower( $id_base ); |
|
| 77 | 77 | $this->name = $name; |
| 78 | 78 | $this->option_name = 'frm_' . $this->id_base . '_action'; |
| 79 | 79 | |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | $default_values = $this->get_global_defaults(); |
| 144 | 144 | |
| 145 | 145 | // fill default values |
| 146 | - $post_content = wp_parse_args( $post_content, $default_values); |
|
| 146 | + $post_content = wp_parse_args( $post_content, $default_values ); |
|
| 147 | 147 | |
| 148 | - if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
| 149 | - $post_content['event'] = array( reset($this->action_options['event']) ); |
|
| 148 | + if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) { |
|
| 149 | + $post_content['event'] = array( reset( $this->action_options['event'] ) ); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | $form_action = array( |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number, |
| 160 | 160 | 'menu_order' => $this->form_id, |
| 161 | 161 | ); |
| 162 | - unset($post_content); |
|
| 162 | + unset( $post_content ); |
|
| 163 | 163 | |
| 164 | 164 | return (object) $form_action; |
| 165 | 165 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | $action = $this->prepare_new(); |
| 171 | 171 | |
| 172 | - return $this->save_settings($action); |
|
| 172 | + return $this->save_settings( $action ); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | public function duplicate_form_actions( $form_id, $old_id ) { |
@@ -183,8 +183,8 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | $this->form_id = $form_id; |
| 185 | 185 | foreach ( $actions as $action ) { |
| 186 | - $this->duplicate_one($action, $form_id); |
|
| 187 | - unset($action); |
|
| 186 | + $this->duplicate_one( $action, $form_id ); |
|
| 187 | + unset( $action ); |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
@@ -196,14 +196,14 @@ discard block |
||
| 196 | 196 | * @return integer $post_id |
| 197 | 197 | */ |
| 198 | 198 | public function maybe_create_action( $action, $forms ) { |
| 199 | - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
|
| 199 | + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[$action['menu_order']] == 'updated' ) { |
|
| 200 | 200 | // Update action only |
| 201 | 201 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
| 202 | 202 | $post_id = $this->save_settings( $action ); |
| 203 | 203 | } else { |
| 204 | 204 | // Create action |
| 205 | - $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
| 206 | - $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
| 205 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
| 206 | + $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] ); |
|
| 207 | 207 | } |
| 208 | 208 | return $post_id; |
| 209 | 209 | } |
@@ -214,47 +214,47 @@ discard block |
||
| 214 | 214 | $action->menu_order = $form_id; |
| 215 | 215 | $switch = $this->get_global_switch_fields(); |
| 216 | 216 | foreach ( (array) $action->post_content as $key => $val ) { |
| 217 | - if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
|
| 218 | - $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
|
| 217 | + if ( is_numeric( $val ) && isset( $frm_duplicate_ids[$val] ) ) { |
|
| 218 | + $action->post_content[$key] = $frm_duplicate_ids[$val]; |
|
| 219 | 219 | } else if ( ! is_array( $val ) ) { |
| 220 | - $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
|
| 221 | - } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
|
| 220 | + $action->post_content[$key] = FrmFieldsHelper::switch_field_ids( $val ); |
|
| 221 | + } else if ( isset( $switch[$key] ) && is_array( $switch[$key] ) ) { |
|
| 222 | 222 | // loop through each value if empty |
| 223 | - if ( empty( $switch[ $key ] ) ) { |
|
| 224 | - $switch[ $key ] = array_keys( $val ); |
|
| 223 | + if ( empty( $switch[$key] ) ) { |
|
| 224 | + $switch[$key] = array_keys( $val ); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - foreach ( $switch[ $key ] as $subkey ) { |
|
| 228 | - $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
|
| 227 | + foreach ( $switch[$key] as $subkey ) { |
|
| 228 | + $action->post_content[$key] = $this->duplicate_array_walk( $action->post_content[$key], $subkey, $val ); |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - unset($key, $val); |
|
| 232 | + unset( $key, $val ); |
|
| 233 | 233 | } |
| 234 | - unset($action->ID); |
|
| 234 | + unset( $action->ID ); |
|
| 235 | 235 | |
| 236 | - return $this->save_settings($action); |
|
| 236 | + return $this->save_settings( $action ); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | private function duplicate_array_walk( $action, $subkey, $val ) { |
| 240 | 240 | global $frm_duplicate_ids; |
| 241 | 241 | |
| 242 | - if ( is_array($subkey) ) { |
|
| 242 | + if ( is_array( $subkey ) ) { |
|
| 243 | 243 | foreach ( $subkey as $subkey2 ) { |
| 244 | 244 | foreach ( (array) $val as $ck => $cv ) { |
| 245 | - if ( is_array($cv) ) { |
|
| 246 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
|
| 247 | - } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
|
| 248 | - $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
|
| 245 | + if ( is_array( $cv ) ) { |
|
| 246 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey2, $cv ); |
|
| 247 | + } else if ( isset( $cv[$subkey] ) && is_numeric( $cv[$subkey] ) && isset( $frm_duplicate_ids[$cv[$subkey]] ) ) { |
|
| 248 | + $action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]]; |
|
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | } else { |
| 253 | 253 | foreach ( (array) $val as $ck => $cv ) { |
| 254 | - if ( is_array($cv) ) { |
|
| 255 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
|
| 256 | - } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
|
| 257 | - $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
|
| 254 | + if ( is_array( $cv ) ) { |
|
| 255 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey, $cv ); |
|
| 256 | + } else if ( $ck == $subkey && isset( $frm_duplicate_ids[$cv] ) ) { |
|
| 257 | + $action[$ck] = $frm_duplicate_ids[$cv]; |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | } |
@@ -278,8 +278,8 @@ discard block |
||
| 278 | 278 | return; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) { |
|
| 282 | - $settings = $_POST[ $this->option_name ]; |
|
| 281 | + if ( isset( $_POST[$this->option_name] ) && is_array( $_POST[$this->option_name] ) ) { |
|
| 282 | + $settings = $_POST[$this->option_name]; |
|
| 283 | 283 | } else { |
| 284 | 284 | return; |
| 285 | 285 | } |
@@ -287,19 +287,19 @@ discard block |
||
| 287 | 287 | $action_ids = array(); |
| 288 | 288 | |
| 289 | 289 | foreach ( $settings as $number => $new_instance ) { |
| 290 | - $this->_set($number); |
|
| 290 | + $this->_set( $number ); |
|
| 291 | 291 | |
| 292 | - if ( ! isset($new_instance['post_title']) ) { |
|
| 292 | + if ( ! isset( $new_instance['post_title'] ) ) { |
|
| 293 | 293 | // settings were never opened, so don't update |
| 294 | 294 | $action_ids[] = $new_instance['ID']; |
| 295 | 295 | $this->updated = true; |
| 296 | 296 | continue; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); |
|
| 299 | + $old_instance = isset( $all_instances[$number] ) ? $all_instances[$number] : array(); |
|
| 300 | 300 | |
| 301 | - $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
|
| 302 | - $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
|
| 301 | + $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
|
| 302 | + $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
|
| 303 | 303 | $new_instance['menu_order'] = $this->form_id; |
| 304 | 304 | $new_instance['post_status'] = 'publish'; |
| 305 | 305 | $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
@@ -321,14 +321,14 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this ); |
| 323 | 323 | |
| 324 | - $instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this); |
|
| 324 | + $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
|
| 325 | 325 | $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
| 326 | 326 | |
| 327 | 327 | if ( false !== $instance ) { |
| 328 | - $all_instances[ $number ] = $instance; |
|
| 328 | + $all_instances[$number] = $instance; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $action_ids[] = $this->save_settings($instance); |
|
| 331 | + $action_ids[] = $this->save_settings( $instance ); |
|
| 332 | 332 | |
| 333 | 333 | $this->updated = true; |
| 334 | 334 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | public function get_single_action( $id ) { |
| 345 | - $action = get_post($id); |
|
| 345 | + $action = get_post( $id ); |
|
| 346 | 346 | if ( $action ) { |
| 347 | 347 | $action = $this->prepare_action( $action ); |
| 348 | 348 | $this->_set( $id ); |
@@ -351,12 +351,12 @@ discard block |
||
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | public function get_one( $form_id ) { |
| 354 | - return $this->get_all($form_id, 1); |
|
| 354 | + return $this->get_all( $form_id, 1 ); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
| 358 | 358 | $action_controls = FrmFormActionsController::get_form_actions( $type ); |
| 359 | - if ( empty($action_controls) ) { |
|
| 359 | + if ( empty( $action_controls ) ) { |
|
| 360 | 360 | // don't continue if there are no available actions |
| 361 | 361 | return array(); |
| 362 | 362 | } |
@@ -377,12 +377,12 @@ discard block |
||
| 377 | 377 | // some plugins/themes are formatting the post_excerpt |
| 378 | 378 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 379 | 379 | |
| 380 | - if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
|
| 380 | + if ( ! isset( $action_controls[$action->post_excerpt] ) ) { |
|
| 381 | 381 | continue; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
| 385 | - $settings[ $action->ID ] = $action; |
|
| 384 | + $action = $action_controls[$action->post_excerpt]->prepare_action( $action ); |
|
| 385 | + $settings[$action->ID] = $action; |
|
| 386 | 386 | |
| 387 | 387 | if ( count( $settings ) >= $limit ) { |
| 388 | 388 | break; |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | if ( 1 === $limit ) { |
| 393 | - $settings = reset($settings); |
|
| 393 | + $settings = reset( $settings ); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | return $settings; |
@@ -423,33 +423,33 @@ discard block |
||
| 423 | 423 | global $frm_vars; |
| 424 | 424 | $frm_vars['action_type'] = $type; |
| 425 | 425 | |
| 426 | - add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
| 426 | + add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
|
| 427 | 427 | $query = self::action_args( $form_id, $limit ); |
| 428 | 428 | $query['post_status'] = 'any'; |
| 429 | 429 | $query['suppress_filters'] = false; |
| 430 | 430 | |
| 431 | 431 | $actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
| 432 | - unset($query); |
|
| 432 | + unset( $query ); |
|
| 433 | 433 | |
| 434 | - remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
| 434 | + remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
|
| 435 | 435 | |
| 436 | - if ( empty($actions) ) { |
|
| 436 | + if ( empty( $actions ) ) { |
|
| 437 | 437 | return array(); |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | $settings = array(); |
| 441 | 441 | foreach ( $actions as $action ) { |
| 442 | - if ( count($settings) >= $limit ) { |
|
| 442 | + if ( count( $settings ) >= $limit ) { |
|
| 443 | 443 | continue; |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | - $action = $this->prepare_action($action); |
|
| 446 | + $action = $this->prepare_action( $action ); |
|
| 447 | 447 | |
| 448 | - $settings[ $action->ID ] = $action; |
|
| 448 | + $settings[$action->ID] = $action; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | if ( 1 === $limit ) { |
| 452 | - $settings = reset($settings); |
|
| 452 | + $settings = reset( $settings ); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | return $settings; |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | public function prepare_action( $action ) { |
| 475 | - $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
|
| 475 | + $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
|
| 476 | 476 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 477 | 477 | |
| 478 | 478 | $default_values = $this->get_global_defaults(); |
@@ -481,16 +481,16 @@ discard block |
||
| 481 | 481 | $action->post_content += $default_values; |
| 482 | 482 | |
| 483 | 483 | foreach ( $default_values as $k => $vals ) { |
| 484 | - if ( is_array($vals) && ! empty($vals) ) { |
|
| 485 | - if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
|
| 484 | + if ( is_array( $vals ) && ! empty( $vals ) ) { |
|
| 485 | + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[$k] ) ) { |
|
| 486 | 486 | continue; |
| 487 | 487 | } |
| 488 | - $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
|
| 488 | + $action->post_content[$k] = wp_parse_args( $action->post_content[$k], $vals ); |
|
| 489 | 489 | } |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - if ( ! is_array($action->post_content['event']) ) { |
|
| 493 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
| 492 | + if ( ! is_array( $action->post_content['event'] ) ) { |
|
| 493 | + $action->post_content['event'] = explode( ',', $action->post_content['event'] ); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | return $action; |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
| 513 | 513 | |
| 514 | 514 | foreach ( $post_ids as $id ) { |
| 515 | - wp_delete_post($id); |
|
| 515 | + wp_delete_post( $id ); |
|
| 516 | 516 | } |
| 517 | 517 | self::clear_cache(); |
| 518 | 518 | } |
@@ -533,11 +533,11 @@ discard block |
||
| 533 | 533 | public function get_global_defaults() { |
| 534 | 534 | $defaults = $this->get_defaults(); |
| 535 | 535 | |
| 536 | - if ( ! isset($defaults['event']) ) { |
|
| 536 | + if ( ! isset( $defaults['event'] ) ) { |
|
| 537 | 537 | $defaults['event'] = array( 'create' ); |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - if ( ! isset($defaults['conditions']) ) { |
|
| 540 | + if ( ! isset( $defaults['conditions'] ) ) { |
|
| 541 | 541 | $defaults['conditions'] = array( |
| 542 | 542 | 'send_stop' => '', |
| 543 | 543 | 'any_all' => '', |
@@ -557,18 +557,18 @@ discard block |
||
| 557 | 557 | * Migrate settings from form->options into new action. |
| 558 | 558 | */ |
| 559 | 559 | public function migrate_to_2( $form, $update = 'update' ) { |
| 560 | - $action = $this->prepare_new($form->id); |
|
| 561 | - $form->options = maybe_unserialize($form->options); |
|
| 560 | + $action = $this->prepare_new( $form->id ); |
|
| 561 | + $form->options = maybe_unserialize( $form->options ); |
|
| 562 | 562 | |
| 563 | 563 | // fill with existing options |
| 564 | 564 | foreach ( $action->post_content as $name => $val ) { |
| 565 | - if ( isset( $form->options[ $name ] ) ) { |
|
| 566 | - $action->post_content[ $name ] = $form->options[ $name ]; |
|
| 567 | - unset( $form->options[ $name ] ); |
|
| 565 | + if ( isset( $form->options[$name] ) ) { |
|
| 566 | + $action->post_content[$name] = $form->options[$name]; |
|
| 567 | + unset( $form->options[$name] ); |
|
| 568 | 568 | } |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | - $action = $this->migrate_values($action, $form); |
|
| 571 | + $action = $this->migrate_values( $action, $form ); |
|
| 572 | 572 | |
| 573 | 573 | // check if action already exists |
| 574 | 574 | $post_id = get_posts( array( |
@@ -578,18 +578,18 @@ discard block |
||
| 578 | 578 | 'numberposts' => 1, |
| 579 | 579 | ) ); |
| 580 | 580 | |
| 581 | - if ( empty($post_id) ) { |
|
| 581 | + if ( empty( $post_id ) ) { |
|
| 582 | 582 | // create action now |
| 583 | - $post_id = $this->save_settings($action); |
|
| 583 | + $post_id = $this->save_settings( $action ); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | if ( $post_id && 'update' == $update ) { |
| 587 | 587 | global $wpdb; |
| 588 | - $form->options = maybe_serialize($form->options); |
|
| 588 | + $form->options = maybe_serialize( $form->options ); |
|
| 589 | 589 | |
| 590 | 590 | // update form options |
| 591 | 591 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
| 592 | - wp_cache_delete( $form->id, 'frm_form'); |
|
| 592 | + wp_cache_delete( $form->id, 'frm_form' ); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | return $post_id; |
@@ -617,18 +617,18 @@ discard block |
||
| 617 | 617 | |
| 618 | 618 | $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] ); |
| 619 | 619 | |
| 620 | - $stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']); |
|
| 620 | + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] ); |
|
| 621 | 621 | |
| 622 | 622 | if ( $notification['conditions']['send_stop'] == 'send' ) { |
| 623 | 623 | $stop = $stop ? false : true; |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | - $met[ $stop ] = $stop; |
|
| 626 | + $met[$stop] = $stop; |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { |
| 630 | - $stop = ($notification['conditions']['send_stop'] == 'send'); |
|
| 631 | - } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) { |
|
| 630 | + $stop = ( $notification['conditions']['send_stop'] == 'send' ); |
|
| 631 | + } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) { |
|
| 632 | 632 | $stop = false; |
| 633 | 633 | } |
| 634 | 634 | |
@@ -665,8 +665,8 @@ discard block |
||
| 665 | 665 | private static function get_value_from_entry( $entry, $field_id ) { |
| 666 | 666 | $observed_value = ''; |
| 667 | 667 | |
| 668 | - if ( isset( $entry->metas[ $field_id ] ) ) { |
|
| 669 | - $observed_value = $entry->metas[ $field_id ]; |
|
| 668 | + if ( isset( $entry->metas[$field_id] ) ) { |
|
| 669 | + $observed_value = $entry->metas[$field_id]; |
|
| 670 | 670 | } else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) { |
| 671 | 671 | $field = FrmField::getOne( $field_id ); |
| 672 | 672 | $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value( $entry, $field, array( 'links' => false, 'truncate' => false ) ); |