@@ -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. |
@@ -77,17 +77,17 @@ discard block |
||
| 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, |
|
| 84 | + 'limit' => 1, |
|
| 85 | + 'force_event' => false, |
|
| 86 | + 'priority' => 20, |
|
| 87 | + 'ajax_load' => true, |
|
| 88 | 88 | 'plugin' => $this->id_base, |
| 89 | - 'tooltip' => $name, |
|
| 90 | - ); |
|
| 89 | + 'tooltip' => $name, |
|
| 90 | + ); |
|
| 91 | 91 | |
| 92 | 92 | $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options ); |
| 93 | 93 | $this->action_options = wp_parse_args( $action_options, $default_options ); |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | public function prepare_new( $form_id = false ) { |
| 139 | - if ( $form_id ) { |
|
| 140 | - $this->form_id = $form_id; |
|
| 141 | - } |
|
| 139 | + if ( $form_id ) { |
|
| 140 | + $this->form_id = $form_id; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - $post_content = array(); |
|
| 144 | - $default_values = $this->get_global_defaults(); |
|
| 143 | + $post_content = array(); |
|
| 144 | + $default_values = $this->get_global_defaults(); |
|
| 145 | 145 | |
| 146 | 146 | // fill default values |
| 147 | 147 | $post_content = wp_parse_args( $post_content, $default_values ); |
@@ -150,118 +150,118 @@ discard block |
||
| 150 | 150 | $post_content['event'] = array( reset( $this->action_options['event'] ) ); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $form_action = array( |
|
| 154 | - 'post_title' => $this->name, |
|
| 155 | - 'post_content' => $post_content, |
|
| 156 | - 'post_excerpt' => $this->id_base, |
|
| 157 | - 'ID' => '', |
|
| 158 | - 'post_status' => 'publish', |
|
| 159 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
| 153 | + $form_action = array( |
|
| 154 | + 'post_title' => $this->name, |
|
| 155 | + 'post_content' => $post_content, |
|
| 156 | + 'post_excerpt' => $this->id_base, |
|
| 157 | + 'ID' => '', |
|
| 158 | + 'post_status' => 'publish', |
|
| 159 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
| 160 | 160 | 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number, |
| 161 | - 'menu_order' => $this->form_id, |
|
| 162 | - ); |
|
| 161 | + 'menu_order' => $this->form_id, |
|
| 162 | + ); |
|
| 163 | 163 | unset( $post_content ); |
| 164 | 164 | |
| 165 | - return (object) $form_action; |
|
| 166 | - } |
|
| 165 | + return (object) $form_action; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | 168 | public function create( $form_id ) { |
| 169 | - $this->form_id = $form_id; |
|
| 169 | + $this->form_id = $form_id; |
|
| 170 | 170 | |
| 171 | - $action = $this->prepare_new(); |
|
| 171 | + $action = $this->prepare_new(); |
|
| 172 | 172 | |
| 173 | 173 | return $this->save_settings( $action ); |
| 174 | - } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | public function duplicate_form_actions( $form_id, $old_id ) { |
| 177 | - if ( $form_id == $old_id ) { |
|
| 178 | - // don't duplicate the actions if this is a template getting updated |
|
| 179 | - return; |
|
| 180 | - } |
|
| 177 | + if ( $form_id == $old_id ) { |
|
| 178 | + // don't duplicate the actions if this is a template getting updated |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - $this->form_id = $old_id; |
|
| 183 | - $actions = $this->get_all( $old_id ); |
|
| 182 | + $this->form_id = $old_id; |
|
| 183 | + $actions = $this->get_all( $old_id ); |
|
| 184 | 184 | |
| 185 | - $this->form_id = $form_id; |
|
| 186 | - foreach ( $actions as $action ) { |
|
| 185 | + $this->form_id = $form_id; |
|
| 186 | + foreach ( $actions as $action ) { |
|
| 187 | 187 | $this->duplicate_one( $action, $form_id ); |
| 188 | 188 | unset( $action ); |
| 189 | - } |
|
| 190 | - } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /* Check if imported action should be created or updated |
|
| 192 | + /* Check if imported action should be created or updated |
|
| 193 | 193 | * |
| 194 | 194 | * Since 2.0 |
| 195 | 195 | * |
| 196 | 196 | * @param array $action |
| 197 | 197 | * @return integer $post_id |
| 198 | 198 | */ |
| 199 | - public function maybe_create_action( $action, $forms ) { |
|
| 199 | + public function maybe_create_action( $action, $forms ) { |
|
| 200 | 200 | if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
| 201 | - // Update action only |
|
| 202 | - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
| 203 | - $post_id = $this->save_settings( $action ); |
|
| 204 | - } else { |
|
| 201 | + // Update action only |
|
| 202 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
| 203 | + $post_id = $this->save_settings( $action ); |
|
| 204 | + } else { |
|
| 205 | 205 | // Create action |
| 206 | 206 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
| 207 | 207 | $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] ); |
| 208 | - } |
|
| 209 | - return $post_id; |
|
| 210 | - } |
|
| 208 | + } |
|
| 209 | + return $post_id; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | 212 | public function duplicate_one( $action, $form_id ) { |
| 213 | - global $frm_duplicate_ids; |
|
| 213 | + global $frm_duplicate_ids; |
|
| 214 | 214 | |
| 215 | - $action->menu_order = $form_id; |
|
| 216 | - $switch = $this->get_global_switch_fields(); |
|
| 217 | - foreach ( (array) $action->post_content as $key => $val ) { |
|
| 215 | + $action->menu_order = $form_id; |
|
| 216 | + $switch = $this->get_global_switch_fields(); |
|
| 217 | + foreach ( (array) $action->post_content as $key => $val ) { |
|
| 218 | 218 | if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
| 219 | 219 | $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
| 220 | - } else if ( ! is_array( $val ) ) { |
|
| 220 | + } else if ( ! is_array( $val ) ) { |
|
| 221 | 221 | $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
| 222 | 222 | } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
| 223 | - // loop through each value if empty |
|
| 223 | + // loop through each value if empty |
|
| 224 | 224 | if ( empty( $switch[ $key ] ) ) { |
| 225 | 225 | $switch[ $key ] = array_keys( $val ); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | foreach ( $switch[ $key ] as $subkey ) { |
| 229 | 229 | $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
| 230 | - } |
|
| 231 | - } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | unset( $key, $val ); |
| 234 | 234 | } |
| 235 | 235 | unset( $action->ID ); |
| 236 | 236 | |
| 237 | 237 | return $this->save_settings( $action ); |
| 238 | - } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | 240 | private function duplicate_array_walk( $action, $subkey, $val ) { |
| 241 | - global $frm_duplicate_ids; |
|
| 241 | + global $frm_duplicate_ids; |
|
| 242 | 242 | |
| 243 | 243 | if ( is_array( $subkey ) ) { |
| 244 | - foreach ( $subkey as $subkey2 ) { |
|
| 245 | - foreach ( (array) $val as $ck => $cv ) { |
|
| 244 | + foreach ( $subkey as $subkey2 ) { |
|
| 245 | + foreach ( (array) $val as $ck => $cv ) { |
|
| 246 | 246 | if ( is_array( $cv ) ) { |
| 247 | 247 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
| 248 | 248 | } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
| 249 | 249 | $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } else { |
|
| 254 | - foreach ( (array) $val as $ck => $cv ) { |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } else { |
|
| 254 | + foreach ( (array) $val as $ck => $cv ) { |
|
| 255 | 255 | if ( is_array( $cv ) ) { |
| 256 | 256 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
| 257 | 257 | } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
| 258 | 258 | $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
| 259 | - } |
|
| 260 | - } |
|
| 261 | - } |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - return $action; |
|
| 264 | - } |
|
| 263 | + return $action; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | 267 | * Deal with changed settings. |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * Do NOT over-ride this function |
| 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,7 +284,7 @@ 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 ); |
@@ -298,9 +298,9 @@ discard block |
||
| 298 | 298 | // settings were never opened, so don't update |
| 299 | 299 | if ( ! isset( $new_instance['post_title'] ) ) { |
| 300 | 300 | $this->maybe_update_status( $new_instance, $old_instance ); |
| 301 | - $action_ids[] = $new_instance['ID']; |
|
| 302 | - $this->updated = true; |
|
| 303 | - continue; |
|
| 301 | + $action_ids[] = $new_instance['ID']; |
|
| 302 | + $this->updated = true; |
|
| 303 | + continue; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | |
| 335 | 335 | $action_ids[] = $this->save_settings( $instance ); |
| 336 | 336 | |
| 337 | - $this->updated = true; |
|
| 337 | + $this->updated = true; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | return $action_ids; |
@@ -368,19 +368,19 @@ discard block |
||
| 368 | 368 | $action = $this->prepare_action( $action ); |
| 369 | 369 | $this->_set( $id ); |
| 370 | 370 | } |
| 371 | - return $action; |
|
| 371 | + return $action; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | public function get_one( $form_id ) { |
| 375 | 375 | return $this->get_all( $form_id, 1 ); |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) { |
|
| 379 | - $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
| 378 | + public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) { |
|
| 379 | + $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
| 380 | 380 | if ( empty( $action_controls ) ) { |
| 381 | - // don't continue if there are no available actions |
|
| 382 | - return array(); |
|
| 383 | - } |
|
| 381 | + // don't continue if there are no available actions |
|
| 382 | + return array(); |
|
| 383 | + } |
|
| 384 | 384 | |
| 385 | 385 | if ( 'all' != $type ) { |
| 386 | 386 | return $action_controls->get_all( $form_id, $atts ); |
@@ -394,33 +394,33 @@ discard block |
||
| 394 | 394 | $args['post_status'] = $atts['post_status']; |
| 395 | 395 | $actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' ); |
| 396 | 396 | |
| 397 | - if ( ! $actions ) { |
|
| 398 | - return array(); |
|
| 399 | - } |
|
| 397 | + if ( ! $actions ) { |
|
| 398 | + return array(); |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | - $settings = array(); |
|
| 402 | - foreach ( $actions as $action ) { |
|
| 401 | + $settings = array(); |
|
| 402 | + foreach ( $actions as $action ) { |
|
| 403 | 403 | // some plugins/themes are formatting the post_excerpt |
| 404 | 404 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 405 | 405 | |
| 406 | 406 | if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
| 407 | - continue; |
|
| 408 | - } |
|
| 407 | + continue; |
|
| 408 | + } |
|
| 409 | 409 | |
| 410 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
| 410 | + $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
| 411 | 411 | $settings[ $action->ID ] = $action; |
| 412 | 412 | |
| 413 | 413 | if ( count( $settings ) >= $limit ) { |
| 414 | 414 | break; |
| 415 | 415 | } |
| 416 | - } |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | - if ( 1 === $limit ) { |
|
| 418 | + if ( 1 === $limit ) { |
|
| 419 | 419 | $settings = reset( $settings ); |
| 420 | - } |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - return $settings; |
|
| 423 | - } |
|
| 422 | + return $settings; |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | 425 | /** |
| 426 | 426 | * @since 3.04 |
@@ -465,19 +465,19 @@ discard block |
||
| 465 | 465 | self::prepare_get_action( $atts, 'any' ); |
| 466 | 466 | $limit = $atts['limit']; |
| 467 | 467 | |
| 468 | - if ( $form_id ) { |
|
| 469 | - $this->form_id = $form_id; |
|
| 470 | - } |
|
| 468 | + if ( $form_id ) { |
|
| 469 | + $this->form_id = $form_id; |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | - $type = $this->id_base; |
|
| 472 | + $type = $this->id_base; |
|
| 473 | 473 | |
| 474 | - global $frm_vars; |
|
| 475 | - $frm_vars['action_type'] = $type; |
|
| 474 | + global $frm_vars; |
|
| 475 | + $frm_vars['action_type'] = $type; |
|
| 476 | 476 | |
| 477 | 477 | add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
| 478 | 478 | $query = self::action_args( $form_id, $limit ); |
| 479 | 479 | $query['post_status'] = $atts['post_status']; |
| 480 | - $query['suppress_filters'] = false; |
|
| 480 | + $query['suppress_filters'] = false; |
|
| 481 | 481 | |
| 482 | 482 | $actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
| 483 | 483 | unset( $query ); |
@@ -485,25 +485,25 @@ discard block |
||
| 485 | 485 | remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
| 486 | 486 | |
| 487 | 487 | if ( empty( $actions ) ) { |
| 488 | - return array(); |
|
| 489 | - } |
|
| 488 | + return array(); |
|
| 489 | + } |
|
| 490 | 490 | |
| 491 | - $settings = array(); |
|
| 492 | - foreach ( $actions as $action ) { |
|
| 491 | + $settings = array(); |
|
| 492 | + foreach ( $actions as $action ) { |
|
| 493 | 493 | if ( count( $settings ) >= $limit ) { |
| 494 | - continue; |
|
| 495 | - } |
|
| 494 | + continue; |
|
| 495 | + } |
|
| 496 | 496 | |
| 497 | 497 | $action = $this->prepare_action( $action ); |
| 498 | 498 | |
| 499 | 499 | $settings[ $action->ID ] = $action; |
| 500 | - } |
|
| 500 | + } |
|
| 501 | 501 | |
| 502 | - if ( 1 === $limit ) { |
|
| 502 | + if ( 1 === $limit ) { |
|
| 503 | 503 | $settings = reset( $settings ); |
| 504 | - } |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - return $settings; |
|
| 506 | + return $settings; |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | public static function action_args( $form_id = 0, $limit = 99 ) { |
@@ -526,45 +526,45 @@ discard block |
||
| 526 | 526 | $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
| 527 | 527 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 528 | 528 | |
| 529 | - $default_values = $this->get_global_defaults(); |
|
| 529 | + $default_values = $this->get_global_defaults(); |
|
| 530 | 530 | |
| 531 | - // fill default values |
|
| 532 | - $action->post_content += $default_values; |
|
| 531 | + // fill default values |
|
| 532 | + $action->post_content += $default_values; |
|
| 533 | 533 | |
| 534 | - foreach ( $default_values as $k => $vals ) { |
|
| 534 | + foreach ( $default_values as $k => $vals ) { |
|
| 535 | 535 | if ( is_array( $vals ) && ! empty( $vals ) ) { |
| 536 | 536 | if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
| 537 | - continue; |
|
| 538 | - } |
|
| 537 | + continue; |
|
| 538 | + } |
|
| 539 | 539 | $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
| 540 | - } |
|
| 541 | - } |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | 542 | |
| 543 | 543 | if ( ! is_array( $action->post_content['event'] ) ) { |
| 544 | 544 | $action->post_content['event'] = explode( ',', $action->post_content['event'] ); |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - return $action; |
|
| 547 | + return $action; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | public function destroy( $form_id = false, $type = 'default' ) { |
| 551 | - global $wpdb; |
|
| 551 | + global $wpdb; |
|
| 552 | 552 | |
| 553 | - $this->form_id = $form_id; |
|
| 553 | + $this->form_id = $form_id; |
|
| 554 | 554 | |
| 555 | - $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
| 556 | - if ( $form_id ) { |
|
| 557 | - $query['menu_order'] = $form_id; |
|
| 558 | - } |
|
| 559 | - if ( 'all' != $type ) { |
|
| 560 | - $query['post_excerpt'] = $this->id_base; |
|
| 561 | - } |
|
| 555 | + $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
| 556 | + if ( $form_id ) { |
|
| 557 | + $query['menu_order'] = $form_id; |
|
| 558 | + } |
|
| 559 | + if ( 'all' != $type ) { |
|
| 560 | + $query['post_excerpt'] = $this->id_base; |
|
| 561 | + } |
|
| 562 | 562 | |
| 563 | - $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
| 563 | + $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
| 564 | 564 | |
| 565 | - foreach ( $post_ids as $id ) { |
|
| 565 | + foreach ( $post_ids as $id ) { |
|
| 566 | 566 | wp_delete_post( $id ); |
| 567 | - } |
|
| 567 | + } |
|
| 568 | 568 | self::clear_cache(); |
| 569 | 569 | } |
| 570 | 570 | |
@@ -582,26 +582,26 @@ discard block |
||
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | public function get_global_defaults() { |
| 585 | - $defaults = $this->get_defaults(); |
|
| 585 | + $defaults = $this->get_defaults(); |
|
| 586 | 586 | |
| 587 | 587 | if ( ! isset( $defaults['event'] ) ) { |
| 588 | 588 | $defaults['event'] = array( 'create' ); |
| 589 | - } |
|
| 589 | + } |
|
| 590 | 590 | |
| 591 | 591 | if ( ! isset( $defaults['conditions'] ) ) { |
| 592 | - $defaults['conditions'] = array( |
|
| 593 | - 'send_stop' => '', |
|
| 594 | - 'any_all' => '', |
|
| 595 | - ); |
|
| 596 | - } |
|
| 592 | + $defaults['conditions'] = array( |
|
| 593 | + 'send_stop' => '', |
|
| 594 | + 'any_all' => '', |
|
| 595 | + ); |
|
| 596 | + } |
|
| 597 | 597 | |
| 598 | - return $defaults; |
|
| 598 | + return $defaults; |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | public function get_global_switch_fields() { |
| 602 | - $switch = $this->get_switch_fields(); |
|
| 602 | + $switch = $this->get_switch_fields(); |
|
| 603 | 603 | $switch['conditions'] = array( 'hide_field' ); |
| 604 | - return $switch; |
|
| 604 | + return $switch; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -611,17 +611,17 @@ discard block |
||
| 611 | 611 | $action = $this->prepare_new( $form->id ); |
| 612 | 612 | $form->options = maybe_unserialize( $form->options ); |
| 613 | 613 | |
| 614 | - // fill with existing options |
|
| 615 | - foreach ( $action->post_content as $name => $val ) { |
|
| 614 | + // fill with existing options |
|
| 615 | + foreach ( $action->post_content as $name => $val ) { |
|
| 616 | 616 | if ( isset( $form->options[ $name ] ) ) { |
| 617 | 617 | $action->post_content[ $name ] = $form->options[ $name ]; |
| 618 | 618 | unset( $form->options[ $name ] ); |
| 619 | - } |
|
| 620 | - } |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | 621 | |
| 622 | 622 | $action = $this->migrate_values( $action, $form ); |
| 623 | 623 | |
| 624 | - // check if action already exists |
|
| 624 | + // check if action already exists |
|
| 625 | 625 | $post_id = get_posts( |
| 626 | 626 | array( |
| 627 | 627 | 'name' => $action->post_name, |
@@ -636,17 +636,17 @@ discard block |
||
| 636 | 636 | $post_id = $this->save_settings( $action ); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - if ( $post_id && 'update' == $update ) { |
|
| 640 | - global $wpdb; |
|
| 639 | + if ( $post_id && 'update' == $update ) { |
|
| 640 | + global $wpdb; |
|
| 641 | 641 | $form->options = maybe_serialize( $form->options ); |
| 642 | 642 | |
| 643 | - // update form options |
|
| 643 | + // update form options |
|
| 644 | 644 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
| 645 | - FrmForm::clear_form_cache(); |
|
| 646 | - } |
|
| 645 | + FrmForm::clear_form_cache(); |
|
| 646 | + } |
|
| 647 | 647 | |
| 648 | - return $post_id; |
|
| 649 | - } |
|
| 648 | + return $post_id; |
|
| 649 | + } |
|
| 650 | 650 | |
| 651 | 651 | public static function action_conditions_met( $action, $entry ) { |
| 652 | 652 | $notification = $action->post_content; |
@@ -2,15 +2,15 @@ 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() |
|
| 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 |
|
| 12 | - public $number = false; // Unique ID number of the current instance. |
|
| 13 | - public $id = ''; // Unique ID string of the current instance (id_base-number) |
|
| 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 | 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. |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @return integer $post_id |
| 198 | 198 | */ |
| 199 | 199 | public function maybe_create_action( $action, $forms ) { |
| 200 | - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
|
| 200 | + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[$action['menu_order']] ) && $forms[$action['menu_order']] == 'updated' ) { |
|
| 201 | 201 | // Update action only |
| 202 | 202 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
| 203 | 203 | $post_id = $this->save_settings( $action ); |
@@ -215,18 +215,18 @@ discard block |
||
| 215 | 215 | $action->menu_order = $form_id; |
| 216 | 216 | $switch = $this->get_global_switch_fields(); |
| 217 | 217 | foreach ( (array) $action->post_content as $key => $val ) { |
| 218 | - if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
|
| 219 | - $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
|
| 218 | + if ( is_numeric( $val ) && isset( $frm_duplicate_ids[$val] ) ) { |
|
| 219 | + $action->post_content[$key] = $frm_duplicate_ids[$val]; |
|
| 220 | 220 | } else if ( ! is_array( $val ) ) { |
| 221 | - $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
|
| 222 | - } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
|
| 221 | + $action->post_content[$key] = FrmFieldsHelper::switch_field_ids( $val ); |
|
| 222 | + } else if ( isset( $switch[$key] ) && is_array( $switch[$key] ) ) { |
|
| 223 | 223 | // loop through each value if empty |
| 224 | - if ( empty( $switch[ $key ] ) ) { |
|
| 225 | - $switch[ $key ] = array_keys( $val ); |
|
| 224 | + if ( empty( $switch[$key] ) ) { |
|
| 225 | + $switch[$key] = array_keys( $val ); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - foreach ( $switch[ $key ] as $subkey ) { |
|
| 229 | - $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
|
| 228 | + foreach ( $switch[$key] as $subkey ) { |
|
| 229 | + $action->post_content[$key] = $this->duplicate_array_walk( $action->post_content[$key], $subkey, $val ); |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
@@ -244,18 +244,18 @@ discard block |
||
| 244 | 244 | foreach ( $subkey as $subkey2 ) { |
| 245 | 245 | foreach ( (array) $val as $ck => $cv ) { |
| 246 | 246 | if ( is_array( $cv ) ) { |
| 247 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
|
| 248 | - } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
|
| 249 | - $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
|
| 247 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey2, $cv ); |
|
| 248 | + } else if ( isset( $cv[$subkey] ) && is_numeric( $cv[$subkey] ) && isset( $frm_duplicate_ids[$cv[$subkey]] ) ) { |
|
| 249 | + $action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]]; |
|
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | } else { |
| 254 | 254 | foreach ( (array) $val as $ck => $cv ) { |
| 255 | 255 | if ( is_array( $cv ) ) { |
| 256 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
|
| 257 | - } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
|
| 258 | - $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
|
| 256 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey, $cv ); |
|
| 257 | + } else if ( $ck == $subkey && isset( $frm_duplicate_ids[$cv] ) ) { |
|
| 258 | + $action[$ck] = $frm_duplicate_ids[$cv]; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | } |
@@ -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 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | foreach ( $settings as $number => $new_instance ) { |
| 290 | 290 | $this->_set( $number ); |
| 291 | 291 | |
| 292 | - $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); |
|
| 292 | + $old_instance = isset( $all_instances[$number] ) ? $all_instances[$number] : array(); |
|
| 293 | 293 | |
| 294 | 294 | if ( ! isset( $new_instance['post_status'] ) ) { |
| 295 | 295 | $new_instance['post_status'] = 'draft'; |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
| 330 | 330 | |
| 331 | 331 | if ( false !== $instance ) { |
| 332 | - $all_instances[ $number ] = $instance; |
|
| 332 | + $all_instances[$number] = $instance; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | $action_ids[] = $this->save_settings( $instance ); |
@@ -403,12 +403,12 @@ discard block |
||
| 403 | 403 | // some plugins/themes are formatting the post_excerpt |
| 404 | 404 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 405 | 405 | |
| 406 | - if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
|
| 406 | + if ( ! isset( $action_controls[$action->post_excerpt] ) ) { |
|
| 407 | 407 | continue; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
| 411 | - $settings[ $action->ID ] = $action; |
|
| 410 | + $action = $action_controls[$action->post_excerpt]->prepare_action( $action ); |
|
| 411 | + $settings[$action->ID] = $action; |
|
| 412 | 412 | |
| 413 | 413 | if ( count( $settings ) >= $limit ) { |
| 414 | 414 | break; |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | $action = $this->prepare_action( $action ); |
| 498 | 498 | |
| 499 | - $settings[ $action->ID ] = $action; |
|
| 499 | + $settings[$action->ID] = $action; |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | if ( 1 === $limit ) { |
@@ -533,10 +533,10 @@ discard block |
||
| 533 | 533 | |
| 534 | 534 | foreach ( $default_values as $k => $vals ) { |
| 535 | 535 | if ( is_array( $vals ) && ! empty( $vals ) ) { |
| 536 | - if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
|
| 536 | + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[$k] ) ) { |
|
| 537 | 537 | continue; |
| 538 | 538 | } |
| 539 | - $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
|
| 539 | + $action->post_content[$k] = wp_parse_args( $action->post_content[$k], $vals ); |
|
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | |
@@ -613,9 +613,9 @@ discard block |
||
| 613 | 613 | |
| 614 | 614 | // fill with existing options |
| 615 | 615 | foreach ( $action->post_content as $name => $val ) { |
| 616 | - if ( isset( $form->options[ $name ] ) ) { |
|
| 617 | - $action->post_content[ $name ] = $form->options[ $name ]; |
|
| 618 | - unset( $form->options[ $name ] ); |
|
| 616 | + if ( isset( $form->options[$name] ) ) { |
|
| 617 | + $action->post_content[$name] = $form->options[$name]; |
|
| 618 | + unset( $form->options[$name] ); |
|
| 619 | 619 | } |
| 620 | 620 | } |
| 621 | 621 | |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | $stop = $stop ? false : true; |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - $met[ $stop ] = $stop; |
|
| 679 | + $met[$stop] = $stop; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { |
@@ -716,8 +716,8 @@ discard block |
||
| 716 | 716 | private static function get_value_from_entry( $entry, $field_id ) { |
| 717 | 717 | $observed_value = ''; |
| 718 | 718 | |
| 719 | - if ( isset( $entry->metas[ $field_id ] ) ) { |
|
| 720 | - $observed_value = $entry->metas[ $field_id ]; |
|
| 719 | + if ( isset( $entry->metas[$field_id] ) ) { |
|
| 720 | + $observed_value = $entry->metas[$field_id]; |
|
| 721 | 721 | } else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) { |
| 722 | 722 | $field = FrmField::getOne( $field_id ); |
| 723 | 723 | $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value( |