@@ -17,7 +17,7 @@ |
||
| 17 | 17 | <p> |
| 18 | 18 | <label> |
| 19 | 19 | <?php echo esc_html( apply_filters( 'frm_upload_instructions2', __( 'Choose a Formidable XML file', 'formidable' ) ) ) ?> |
| 20 | - (<?php echo esc_html( sprintf( __( 'Maximum size: %s', 'formidable' ), ini_get( 'upload_max_filesize') ) ) ?>) |
|
| 20 | + (<?php echo esc_html( sprintf( __( 'Maximum size: %s', 'formidable' ), ini_get( 'upload_max_filesize' ) ) ) ?>) |
|
| 21 | 21 | </label> |
| 22 | 22 | <input type="file" name="frm_import_file" size="25" /> |
| 23 | 23 | </p> |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | ?> |
| 34 | 34 | <tr id="menu-locations-row"> |
| 35 | 35 | <td class="menu-location-title"> |
| 36 | - <strong><?php echo esc_html( empty( $form->name ) ? __( '(no title)') : $form->name ) ?></strong> |
|
| 36 | + <strong><?php echo esc_html( empty( $form->name ) ? __( '(no title)' ) : $form->name ) ?></strong> |
|
| 37 | 37 | </td> |
| 38 | 38 | <td class="menu-location-menus"> |
| 39 | 39 | <input type="hidden" name="prev_style[<?php echo esc_attr( $form->id ) ?>]" value="<?php echo esc_attr( $this_style ) ?>" /> |
@@ -336,7 +336,7 @@ |
||
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | return self::escape_csv( $line ); |
| 339 | - } |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | 341 | /** |
| 342 | 342 | * Escape a " in a csv with another " |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | foreach ( self::$fields as $col ) { |
| 105 | 105 | $field_headings = array(); |
| 106 | 106 | if ( isset( $col->field_options['separate_value'] ) && $col->field_options['separate_value'] && ! in_array( $col->type, array( 'user_id', 'file', 'data', 'date' ), true ) ) { |
| 107 | - $field_headings[ $col->id . '_label' ] = strip_tags( $col->name . ' ' . __( '(label)', 'formidable' ) ); |
|
| 107 | + $field_headings[$col->id . '_label'] = strip_tags( $col->name . ' ' . __( '(label)', 'formidable' ) ); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $field_headings[ $col->id ] = strip_tags( $col->name ); |
|
| 110 | + $field_headings[$col->id] = strip_tags( $col->name ); |
|
| 111 | 111 | $field_headings = apply_filters( 'frm_csv_field_columns', $field_headings, array( |
| 112 | 112 | 'field' => $col, |
| 113 | 113 | ) ); |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | if ( self::$comment_count ) { |
| 118 | - for ( $i = 0; $i < self::$comment_count; $i++ ) { |
|
| 119 | - $headings[ 'comment' . $i ] = __( 'Comment', 'formidable' ); |
|
| 120 | - $headings[ 'comment_user_id' . $i ] = __( 'Comment User', 'formidable' ); |
|
| 121 | - $headings[ 'comment_created_at' . $i ] = __( 'Comment Date', 'formidable' ); |
|
| 118 | + for ( $i = 0; $i < self::$comment_count; $i ++ ) { |
|
| 119 | + $headings['comment' . $i] = __( 'Comment', 'formidable' ); |
|
| 120 | + $headings['comment_user_id' . $i] = __( 'Comment User', 'formidable' ); |
|
| 121 | + $headings['comment_created_at' . $i] = __( 'Comment Date', 'formidable' ); |
|
| 122 | 122 | } |
| 123 | 123 | unset( $i ); |
| 124 | 124 | } |
@@ -176,30 +176,30 @@ discard block |
||
| 176 | 176 | continue; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - if ( ! isset( $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ] ) ) { |
|
| 180 | - $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ] = array(); |
|
| 181 | - } elseif ( ! is_array( $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ] ) ) { |
|
| 179 | + if ( ! isset( $entries[self::$entry->parent_item_id]->metas[$meta_id] ) ) { |
|
| 180 | + $entries[self::$entry->parent_item_id]->metas[$meta_id] = array(); |
|
| 181 | + } elseif ( ! is_array( $entries[self::$entry->parent_item_id]->metas[$meta_id] ) ) { |
|
| 182 | 182 | // if the data is here, it should be an array but if this field has collected data |
| 183 | 183 | // both while inside and outside of the repeating section, it's possible this is a string |
| 184 | - $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ] = (array) $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ]; |
|
| 184 | + $entries[self::$entry->parent_item_id]->metas[$meta_id] = (array) $entries[self::$entry->parent_item_id]->metas[$meta_id]; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | //add the repeated values |
| 188 | - $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ][] = $meta_value; |
|
| 188 | + $entries[self::$entry->parent_item_id]->metas[$meta_id][] = $meta_value; |
|
| 189 | 189 | } |
| 190 | - $entries[ self::$entry->parent_item_id ]->metas += self::$entry->metas; |
|
| 190 | + $entries[self::$entry->parent_item_id]->metas += self::$entry->metas; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // add the embedded form id |
| 194 | - if ( ! isset( $entries[ self::$entry->parent_item_id ]->embedded_fields ) ) { |
|
| 195 | - $entries[ self::$entry->parent_item_id ]->embedded_fields = array(); |
|
| 194 | + if ( ! isset( $entries[self::$entry->parent_item_id]->embedded_fields ) ) { |
|
| 195 | + $entries[self::$entry->parent_item_id]->embedded_fields = array(); |
|
| 196 | 196 | } |
| 197 | - $entries[ self::$entry->parent_item_id ]->embedded_fields[ self::$entry->id ] = self::$entry->form_id; |
|
| 197 | + $entries[self::$entry->parent_item_id]->embedded_fields[self::$entry->id] = self::$entry->form_id; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | private static function add_field_values_to_csv( &$row ) { |
| 201 | 201 | foreach ( self::$fields as $col ) { |
| 202 | - $field_value = isset( self::$entry->metas[ $col->id ] ) ? self::$entry->metas[ $col->id ] : false; |
|
| 202 | + $field_value = isset( self::$entry->metas[$col->id] ) ? self::$entry->metas[$col->id] : false; |
|
| 203 | 203 | |
| 204 | 204 | $field_value = maybe_unserialize( $field_value ); |
| 205 | 205 | self::add_array_values_to_columns( $row, compact( 'col', 'field_value' ) ); |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | 'show_icon' => false, |
| 218 | 218 | 'entry_id' => self::$entry->id, |
| 219 | 219 | 'sep' => self::$separator, |
| 220 | - 'embedded_field_id' => ( isset( self::$entry->embedded_fields ) && isset( self::$entry->embedded_fields[ self::$entry->id ] ) ) ? 'form' . self::$entry->embedded_fields[ self::$entry->id ] : 0, |
|
| 220 | + 'embedded_field_id' => ( isset( self::$entry->embedded_fields ) && isset( self::$entry->embedded_fields[self::$entry->id] ) ) ? 'form' . self::$entry->embedded_fields[self::$entry->id] : 0, |
|
| 221 | 221 | ) ); |
| 222 | - $row[ $col->id . '_label' ] = $sep_value; |
|
| 222 | + $row[$col->id . '_label'] = $sep_value; |
|
| 223 | 223 | unset( $sep_value ); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - $row[ $col->id ] = $field_value; |
|
| 226 | + $row[$col->id] = $field_value; |
|
| 227 | 227 | |
| 228 | 228 | unset( $col, $field_value ); |
| 229 | 229 | } |
@@ -236,8 +236,8 @@ discard block |
||
| 236 | 236 | if ( is_array( $atts['field_value'] ) ) { |
| 237 | 237 | foreach ( $atts['field_value'] as $key => $sub_value ) { |
| 238 | 238 | $column_key = $atts['col']->id . '_' . $key; |
| 239 | - if ( ! is_numeric( $key ) && isset( self::$headings[ $column_key ] ) ) { |
|
| 240 | - $row[ $column_key ] = $sub_value; |
|
| 239 | + if ( ! is_numeric( $key ) && isset( self::$headings[$column_key] ) ) { |
|
| 240 | + $row[$column_key] = $sub_value; |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | $sep = ''; |
| 259 | 259 | |
| 260 | 260 | foreach ( self::$headings as $k => $heading ) { |
| 261 | - $row = isset( $rows[ $k ] ) ? $rows[ $k ] : ''; |
|
| 261 | + $row = isset( $rows[$k] ) ? $rows[$k] : ''; |
|
| 262 | 262 | if ( is_array( $row ) ) { |
| 263 | 263 | // implode the repeated field values |
| 264 | 264 | $row = implode( self::$separator, FrmAppHelper::array_flatten( $row, 'reset' ) ); |
@@ -1,106 +1,106 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmFormActionsController { |
| 4 | - public static $action_post_type = 'frm_form_actions'; |
|
| 5 | - public static $registered_actions; |
|
| 6 | - |
|
| 7 | - public static function register_post_types() { |
|
| 8 | - register_post_type( self::$action_post_type, array( |
|
| 9 | - 'label' => __( 'Form Actions', 'formidable' ), |
|
| 10 | - 'description' => '', |
|
| 11 | - 'public' => false, |
|
| 12 | - 'show_ui' => false, |
|
| 13 | - 'exclude_from_search' => true, |
|
| 14 | - 'show_in_nav_menus' => false, |
|
| 15 | - 'show_in_menu' => true, |
|
| 16 | - 'capability_type' => 'page', |
|
| 17 | - 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'page-attributes' ), |
|
| 18 | - 'has_archive' => false, |
|
| 19 | - ) ); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * post_content: json settings |
|
| 23 | - * menu_order: form id |
|
| 24 | - * post_excerpt: action type |
|
| 25 | - */ |
|
| 26 | - |
|
| 27 | - self::actions_init(); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public static function actions_init() { |
|
| 31 | - self::$registered_actions = new Frm_Form_Action_Factory(); |
|
| 32 | - self::register_actions(); |
|
| 33 | - do_action( 'frm_form_actions_init' ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public static function register_actions() { |
|
| 37 | - $action_classes = apply_filters( 'frm_registered_form_actions', array( |
|
| 38 | - 'email' => 'FrmEmailAction', |
|
| 39 | - 'wppost' => 'FrmDefPostAction', |
|
| 40 | - 'register' => 'FrmDefRegAction', |
|
| 41 | - 'paypal' => 'FrmDefPayPalAction', |
|
| 42 | - //'aweber' => 'FrmDefAweberAction', |
|
| 43 | - 'mailchimp' => 'FrmDefMlcmpAction', |
|
| 44 | - 'twilio' => 'FrmDefTwilioAction', |
|
| 45 | - 'highrise' => 'FrmDefHrsAction', |
|
| 46 | - ) ); |
|
| 47 | - |
|
| 48 | - include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'); |
|
| 49 | - include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php'); |
|
| 50 | - |
|
| 51 | - foreach ( $action_classes as $action_class ) { |
|
| 52 | - self::$registered_actions->register($action_class); |
|
| 53 | - } |
|
| 54 | - } |
|
| 4 | + public static $action_post_type = 'frm_form_actions'; |
|
| 5 | + public static $registered_actions; |
|
| 6 | + |
|
| 7 | + public static function register_post_types() { |
|
| 8 | + register_post_type( self::$action_post_type, array( |
|
| 9 | + 'label' => __( 'Form Actions', 'formidable' ), |
|
| 10 | + 'description' => '', |
|
| 11 | + 'public' => false, |
|
| 12 | + 'show_ui' => false, |
|
| 13 | + 'exclude_from_search' => true, |
|
| 14 | + 'show_in_nav_menus' => false, |
|
| 15 | + 'show_in_menu' => true, |
|
| 16 | + 'capability_type' => 'page', |
|
| 17 | + 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'page-attributes' ), |
|
| 18 | + 'has_archive' => false, |
|
| 19 | + ) ); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * post_content: json settings |
|
| 23 | + * menu_order: form id |
|
| 24 | + * post_excerpt: action type |
|
| 25 | + */ |
|
| 26 | + |
|
| 27 | + self::actions_init(); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public static function actions_init() { |
|
| 31 | + self::$registered_actions = new Frm_Form_Action_Factory(); |
|
| 32 | + self::register_actions(); |
|
| 33 | + do_action( 'frm_form_actions_init' ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public static function register_actions() { |
|
| 37 | + $action_classes = apply_filters( 'frm_registered_form_actions', array( |
|
| 38 | + 'email' => 'FrmEmailAction', |
|
| 39 | + 'wppost' => 'FrmDefPostAction', |
|
| 40 | + 'register' => 'FrmDefRegAction', |
|
| 41 | + 'paypal' => 'FrmDefPayPalAction', |
|
| 42 | + //'aweber' => 'FrmDefAweberAction', |
|
| 43 | + 'mailchimp' => 'FrmDefMlcmpAction', |
|
| 44 | + 'twilio' => 'FrmDefTwilioAction', |
|
| 45 | + 'highrise' => 'FrmDefHrsAction', |
|
| 46 | + ) ); |
|
| 47 | + |
|
| 48 | + include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'); |
|
| 49 | + include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php'); |
|
| 50 | + |
|
| 51 | + foreach ( $action_classes as $action_class ) { |
|
| 52 | + self::$registered_actions->register($action_class); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | public static function get_form_actions( $action = 'all' ) { |
| 57 | - $temp_actions = self::$registered_actions; |
|
| 58 | - if ( empty($temp_actions) ) { |
|
| 59 | - self::actions_init(); |
|
| 60 | - $temp_actions = self::$registered_actions->actions; |
|
| 61 | - } else { |
|
| 62 | - $temp_actions = $temp_actions->actions; |
|
| 63 | - } |
|
| 57 | + $temp_actions = self::$registered_actions; |
|
| 58 | + if ( empty($temp_actions) ) { |
|
| 59 | + self::actions_init(); |
|
| 60 | + $temp_actions = self::$registered_actions->actions; |
|
| 61 | + } else { |
|
| 62 | + $temp_actions = $temp_actions->actions; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $actions = array(); |
|
| 65 | + $actions = array(); |
|
| 66 | 66 | |
| 67 | - foreach ( $temp_actions as $a ) { |
|
| 68 | - if ( 'all' != $action && $a->id_base == $action ) { |
|
| 69 | - return $a; |
|
| 70 | - } |
|
| 67 | + foreach ( $temp_actions as $a ) { |
|
| 68 | + if ( 'all' != $action && $a->id_base == $action ) { |
|
| 69 | + return $a; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | $actions[ $a->id_base ] = $a; |
| 73 | - } |
|
| 74 | - unset( $temp_actions, $a ); |
|
| 75 | - |
|
| 76 | - $action_limit = 10; |
|
| 77 | - if ( count( $actions ) <= $action_limit ) { |
|
| 78 | - return $actions; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // remove the last few inactive icons if there are too many |
|
| 82 | - $temp_actions = $actions; |
|
| 83 | - arsort( $temp_actions ); |
|
| 84 | - foreach ( $temp_actions as $type => $a ) { |
|
| 85 | - if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) { |
|
| 73 | + } |
|
| 74 | + unset( $temp_actions, $a ); |
|
| 75 | + |
|
| 76 | + $action_limit = 10; |
|
| 77 | + if ( count( $actions ) <= $action_limit ) { |
|
| 78 | + return $actions; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // remove the last few inactive icons if there are too many |
|
| 82 | + $temp_actions = $actions; |
|
| 83 | + arsort( $temp_actions ); |
|
| 84 | + foreach ( $temp_actions as $type => $a ) { |
|
| 85 | + if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) { |
|
| 86 | 86 | unset( $actions[ $type ] ); |
| 87 | - if ( count( $actions ) <= $action_limit ) { |
|
| 88 | - break; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - unset( $type, $a ); |
|
| 92 | - } |
|
| 87 | + if ( count( $actions ) <= $action_limit ) { |
|
| 88 | + break; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + unset( $type, $a ); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $actions; |
|
| 95 | - } |
|
| 94 | + return $actions; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * @since 2.0 |
| 99 | 99 | */ |
| 100 | - public static function list_actions( $form, $values ) { |
|
| 101 | - if ( empty( $form ) ) { |
|
| 102 | - return; |
|
| 103 | - } |
|
| 100 | + public static function list_actions( $form, $values ) { |
|
| 101 | + if ( empty( $form ) ) { |
|
| 102 | + return; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * use this hook to migrate old settings into a new action |
@@ -110,122 +110,122 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $form_actions = FrmFormAction::get_action_for_form( $form->id ); |
| 112 | 112 | |
| 113 | - $action_controls = self::get_form_actions(); |
|
| 113 | + $action_controls = self::get_form_actions(); |
|
| 114 | 114 | |
| 115 | - $action_map = array(); |
|
| 115 | + $action_map = array(); |
|
| 116 | 116 | |
| 117 | 117 | foreach ( $action_controls as $key => $control ) { |
| 118 | - $action_map[ $control->id_base ] = $key; |
|
| 119 | - } |
|
| 118 | + $action_map[ $control->id_base ] = $key; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - foreach ( $form_actions as $action ) { |
|
| 122 | - if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
|
| 123 | - // don't try and show settings if action no longer exists |
|
| 124 | - continue; |
|
| 125 | - } |
|
| 121 | + foreach ( $form_actions as $action ) { |
|
| 122 | + if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
|
| 123 | + // don't try and show settings if action no longer exists |
|
| 124 | + continue; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
|
| 128 | - } |
|
| 129 | - } |
|
| 127 | + self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
| 132 | - $action_control->_set($action_key); |
|
| 132 | + $action_control->_set($action_key); |
|
| 133 | 133 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' ); |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - public static function add_form_action() { |
|
| 136 | + public static function add_form_action() { |
|
| 137 | 137 | FrmAppHelper::permission_check('frm_edit_forms'); |
| 138 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 138 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 139 | 139 | |
| 140 | - global $frm_vars; |
|
| 140 | + global $frm_vars; |
|
| 141 | 141 | |
| 142 | 142 | $action_key = absint( $_POST['list_id'] ); |
| 143 | - $action_type = sanitize_text_field( $_POST['type'] ); |
|
| 143 | + $action_type = sanitize_text_field( $_POST['type'] ); |
|
| 144 | 144 | |
| 145 | - $action_control = self::get_form_actions( $action_type ); |
|
| 146 | - $action_control->_set($action_key); |
|
| 145 | + $action_control = self::get_form_actions( $action_type ); |
|
| 146 | + $action_control->_set($action_key); |
|
| 147 | 147 | |
| 148 | - $form_id = absint( $_POST['form_id'] ); |
|
| 148 | + $form_id = absint( $_POST['form_id'] ); |
|
| 149 | 149 | |
| 150 | - $form_action = $action_control->prepare_new($form_id); |
|
| 150 | + $form_action = $action_control->prepare_new($form_id); |
|
| 151 | 151 | |
| 152 | - $values = array(); |
|
| 153 | - $form = self::fields_to_values($form_id, $values); |
|
| 152 | + $values = array(); |
|
| 153 | + $form = self::fields_to_values($form_id, $values); |
|
| 154 | 154 | |
| 155 | 155 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' ); |
| 156 | - wp_die(); |
|
| 157 | - } |
|
| 156 | + wp_die(); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - public static function fill_action() { |
|
| 159 | + public static function fill_action() { |
|
| 160 | 160 | FrmAppHelper::permission_check('frm_edit_forms'); |
| 161 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 161 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 162 | 162 | |
| 163 | - $action_key = absint( $_POST['action_id'] ); |
|
| 164 | - $action_type = sanitize_text_field( $_POST['action_type'] ); |
|
| 163 | + $action_key = absint( $_POST['action_id'] ); |
|
| 164 | + $action_type = sanitize_text_field( $_POST['action_type'] ); |
|
| 165 | 165 | |
| 166 | - $action_control = self::get_form_actions( $action_type ); |
|
| 167 | - if ( empty($action_control) ) { |
|
| 168 | - wp_die(); |
|
| 169 | - } |
|
| 166 | + $action_control = self::get_form_actions( $action_type ); |
|
| 167 | + if ( empty($action_control) ) { |
|
| 168 | + wp_die(); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - $form_action = $action_control->get_single_action( $action_key ); |
|
| 171 | + $form_action = $action_control->get_single_action( $action_key ); |
|
| 172 | 172 | |
| 173 | - $values = array(); |
|
| 174 | - $form = self::fields_to_values($form_action->menu_order, $values); |
|
| 173 | + $values = array(); |
|
| 174 | + $form = self::fields_to_values($form_action->menu_order, $values); |
|
| 175 | 175 | |
| 176 | 176 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' ); |
| 177 | - wp_die(); |
|
| 178 | - } |
|
| 177 | + wp_die(); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | private static function fields_to_values( $form_id, array &$values ) { |
| 181 | - $form = FrmForm::getOne($form_id); |
|
| 181 | + $form = FrmForm::getOne($form_id); |
|
| 182 | 182 | |
| 183 | 183 | $values = array( |
| 184 | 184 | 'fields' => array(), |
| 185 | 185 | 'id' => $form->id, |
| 186 | 186 | ); |
| 187 | 187 | |
| 188 | - $fields = FrmField::get_all_for_form($form->id); |
|
| 189 | - foreach ( $fields as $k => $f ) { |
|
| 190 | - $f = (array) $f; |
|
| 191 | - $opts = (array) $f['field_options']; |
|
| 192 | - $f = array_merge($opts, $f); |
|
| 193 | - if ( ! isset( $f['post_field'] ) ) { |
|
| 194 | - $f['post_field'] = ''; |
|
| 195 | - } |
|
| 196 | - $values['fields'][] = $f; |
|
| 197 | - unset($k, $f); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $form; |
|
| 201 | - } |
|
| 188 | + $fields = FrmField::get_all_for_form($form->id); |
|
| 189 | + foreach ( $fields as $k => $f ) { |
|
| 190 | + $f = (array) $f; |
|
| 191 | + $opts = (array) $f['field_options']; |
|
| 192 | + $f = array_merge($opts, $f); |
|
| 193 | + if ( ! isset( $f['post_field'] ) ) { |
|
| 194 | + $f['post_field'] = ''; |
|
| 195 | + } |
|
| 196 | + $values['fields'][] = $f; |
|
| 197 | + unset($k, $f); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $form; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | 203 | public static function update_settings( $form_id ) { |
| 204 | - global $wpdb; |
|
| 204 | + global $wpdb; |
|
| 205 | 205 | |
| 206 | - $registered_actions = self::$registered_actions->actions; |
|
| 206 | + $registered_actions = self::$registered_actions->actions; |
|
| 207 | 207 | |
| 208 | 208 | $old_actions = FrmDb::get_col( $wpdb->posts, array( |
| 209 | 209 | 'post_type' => self::$action_post_type, |
| 210 | 210 | 'menu_order' => $form_id, |
| 211 | 211 | ), 'ID' ); |
| 212 | - $new_actions = array(); |
|
| 212 | + $new_actions = array(); |
|
| 213 | 213 | |
| 214 | - foreach ( $registered_actions as $registered_action ) { |
|
| 215 | - $action_ids = $registered_action->update_callback($form_id); |
|
| 216 | - if ( ! empty( $action_ids ) ) { |
|
| 217 | - $new_actions[] = $action_ids; |
|
| 218 | - } |
|
| 219 | - } |
|
| 214 | + foreach ( $registered_actions as $registered_action ) { |
|
| 215 | + $action_ids = $registered_action->update_callback($form_id); |
|
| 216 | + if ( ! empty( $action_ids ) ) { |
|
| 217 | + $new_actions[] = $action_ids; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - //Only use array_merge if there are new actions |
|
| 222 | - if ( ! empty( $new_actions ) ) { |
|
| 223 | - $new_actions = call_user_func_array( 'array_merge', $new_actions ); |
|
| 224 | - } |
|
| 225 | - $old_actions = array_diff( $old_actions, $new_actions ); |
|
| 221 | + //Only use array_merge if there are new actions |
|
| 222 | + if ( ! empty( $new_actions ) ) { |
|
| 223 | + $new_actions = call_user_func_array( 'array_merge', $new_actions ); |
|
| 224 | + } |
|
| 225 | + $old_actions = array_diff( $old_actions, $new_actions ); |
|
| 226 | 226 | |
| 227 | 227 | self::delete_missing_actions( $old_actions ); |
| 228 | - } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | 230 | public static function delete_missing_actions( $old_actions ) { |
| 231 | 231 | if ( ! empty( $old_actions ) ) { |
@@ -245,22 +245,22 @@ discard block |
||
| 245 | 245 | self::trigger_actions( $event, $form_id, $entry_id, 'all', $args ); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * @param string $event |
|
| 250 | - */ |
|
| 248 | + /** |
|
| 249 | + * @param string $event |
|
| 250 | + */ |
|
| 251 | 251 | public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) { |
| 252 | 252 | $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type ); |
| 253 | 253 | |
| 254 | 254 | if ( empty( $form_actions ) ) { |
| 255 | - return; |
|
| 256 | - } |
|
| 255 | + return; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | 258 | FrmForm::maybe_get_form( $form ); |
| 259 | 259 | |
| 260 | - $link_settings = self::get_form_actions( $type ); |
|
| 261 | - if ( 'all' != $type ) { |
|
| 262 | - $link_settings = array( $type => $link_settings ); |
|
| 263 | - } |
|
| 260 | + $link_settings = self::get_form_actions( $type ); |
|
| 261 | + if ( 'all' != $type ) { |
|
| 262 | + $link_settings = array( $type => $link_settings ); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | 265 | $stored_actions = array(); |
| 266 | 266 | $action_priority = array(); |
@@ -271,17 +271,17 @@ discard block |
||
| 271 | 271 | $this_event = $event; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - foreach ( $form_actions as $action ) { |
|
| 274 | + foreach ( $form_actions as $action ) { |
|
| 275 | 275 | |
| 276 | 276 | $skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) ); |
| 277 | 277 | $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) ); |
| 278 | 278 | if ( $skip_this_action ) { |
| 279 | - continue; |
|
| 280 | - } |
|
| 279 | + continue; |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - if ( ! is_object( $entry ) ) { |
|
| 283 | - $entry = FrmEntry::getOne( $entry, true ); |
|
| 284 | - } |
|
| 282 | + if ( ! is_object( $entry ) ) { |
|
| 283 | + $entry = FrmEntry::getOne( $entry, true ); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | 286 | if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) { |
| 287 | 287 | continue; |
@@ -295,64 +295,64 @@ discard block |
||
| 295 | 295 | if ( ! $trigger_children ) { |
| 296 | 296 | continue; |
| 297 | 297 | } |
| 298 | - } |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - // check conditional logic |
|
| 300 | + // check conditional logic |
|
| 301 | 301 | $stop = FrmFormAction::action_conditions_met( $action, $entry ); |
| 302 | - if ( $stop ) { |
|
| 303 | - continue; |
|
| 304 | - } |
|
| 302 | + if ( $stop ) { |
|
| 303 | + continue; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - // store actions so they can be triggered with the correct priority |
|
| 307 | - $stored_actions[ $action->ID ] = $action; |
|
| 308 | - $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
|
| 306 | + // store actions so they can be triggered with the correct priority |
|
| 307 | + $stored_actions[ $action->ID ] = $action; |
|
| 308 | + $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
|
| 309 | 309 | |
| 310 | - unset($action); |
|
| 311 | - } |
|
| 310 | + unset($action); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - if ( ! empty( $stored_actions ) ) { |
|
| 314 | - asort($action_priority); |
|
| 313 | + if ( ! empty( $stored_actions ) ) { |
|
| 314 | + asort($action_priority); |
|
| 315 | 315 | |
| 316 | - // make sure hooks are loaded |
|
| 317 | - new FrmNotification(); |
|
| 316 | + // make sure hooks are loaded |
|
| 317 | + new FrmNotification(); |
|
| 318 | 318 | |
| 319 | - foreach ( $action_priority as $action_id => $priority ) { |
|
| 320 | - $action = $stored_actions[ $action_id ]; |
|
| 319 | + foreach ( $action_priority as $action_id => $priority ) { |
|
| 320 | + $action = $stored_actions[ $action_id ]; |
|
| 321 | 321 | do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event ); |
| 322 | 322 | do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form ); |
| 323 | 323 | |
| 324 | - // If post is created, get updated $entry object |
|
| 325 | - if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { |
|
| 326 | - $entry = FrmEntry::getOne($entry->id, true); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - } |
|
| 324 | + // If post is created, get updated $entry object |
|
| 325 | + if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { |
|
| 326 | + $entry = FrmEntry::getOne($entry->id, true); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | 332 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 333 | - if ( ! isset($args['old_id']) || empty($args['old_id']) ) { |
|
| 334 | - // continue if we know which actions to copy |
|
| 335 | - return; |
|
| 336 | - } |
|
| 333 | + if ( ! isset($args['old_id']) || empty($args['old_id']) ) { |
|
| 334 | + // continue if we know which actions to copy |
|
| 335 | + return; |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | 338 | $action_controls = self::get_form_actions(); |
| 339 | 339 | |
| 340 | - foreach ( $action_controls as $action_control ) { |
|
| 341 | - $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
|
| 342 | - unset( $action_control ); |
|
| 343 | - } |
|
| 344 | - } |
|
| 340 | + foreach ( $action_controls as $action_control ) { |
|
| 341 | + $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
|
| 342 | + unset( $action_control ); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - public static function limit_by_type( $where ) { |
|
| 347 | - global $frm_vars, $wpdb; |
|
| 346 | + public static function limit_by_type( $where ) { |
|
| 347 | + global $frm_vars, $wpdb; |
|
| 348 | 348 | |
| 349 | - if ( ! isset( $frm_vars['action_type'] ) ) { |
|
| 350 | - return $where; |
|
| 351 | - } |
|
| 349 | + if ( ! isset( $frm_vars['action_type'] ) ) { |
|
| 350 | + return $where; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
|
| 354 | - return $where; |
|
| 355 | - } |
|
| 353 | + $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
|
| 354 | + return $where; |
|
| 355 | + } |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | foreach ( $keys as $key ) { |
| 380 | 380 | // don't register new action if old action with the same id is already registered |
| 381 | 381 | if ( ! isset( $this->actions[ $key ] ) ) { |
| 382 | - $this->actions[ $key ]->_register(); |
|
| 382 | + $this->actions[ $key ]->_register(); |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | } |
@@ -45,17 +45,17 @@ discard block |
||
| 45 | 45 | 'highrise' => 'FrmDefHrsAction', |
| 46 | 46 | ) ); |
| 47 | 47 | |
| 48 | - include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'); |
|
| 49 | - include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php'); |
|
| 48 | + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php' ); |
|
| 49 | + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php' ); |
|
| 50 | 50 | |
| 51 | 51 | foreach ( $action_classes as $action_class ) { |
| 52 | - self::$registered_actions->register($action_class); |
|
| 52 | + self::$registered_actions->register( $action_class ); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public static function get_form_actions( $action = 'all' ) { |
| 57 | 57 | $temp_actions = self::$registered_actions; |
| 58 | - if ( empty($temp_actions) ) { |
|
| 58 | + if ( empty( $temp_actions ) ) { |
|
| 59 | 59 | self::actions_init(); |
| 60 | 60 | $temp_actions = self::$registered_actions->actions; |
| 61 | 61 | } else { |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | return $a; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $actions[ $a->id_base ] = $a; |
|
| 72 | + $actions[$a->id_base] = $a; |
|
| 73 | 73 | } |
| 74 | 74 | unset( $temp_actions, $a ); |
| 75 | 75 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | arsort( $temp_actions ); |
| 84 | 84 | foreach ( $temp_actions as $type => $a ) { |
| 85 | 85 | if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) { |
| 86 | - unset( $actions[ $type ] ); |
|
| 86 | + unset( $actions[$type] ); |
|
| 87 | 87 | if ( count( $actions ) <= $action_limit ) { |
| 88 | 88 | break; |
| 89 | 89 | } |
@@ -115,26 +115,26 @@ discard block |
||
| 115 | 115 | $action_map = array(); |
| 116 | 116 | |
| 117 | 117 | foreach ( $action_controls as $key => $control ) { |
| 118 | - $action_map[ $control->id_base ] = $key; |
|
| 118 | + $action_map[$control->id_base] = $key; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | foreach ( $form_actions as $action ) { |
| 122 | - if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
|
| 122 | + if ( ! isset( $action_map[$action->post_excerpt] ) ) { |
|
| 123 | 123 | // don't try and show settings if action no longer exists |
| 124 | 124 | continue; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
|
| 127 | + self::action_control( $action, $form, $action->ID, $action_controls[$action_map[$action->post_excerpt]], $values ); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
| 132 | - $action_control->_set($action_key); |
|
| 132 | + $action_control->_set( $action_key ); |
|
| 133 | 133 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' ); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | public static function add_form_action() { |
| 137 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
| 137 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
| 138 | 138 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 139 | 139 | |
| 140 | 140 | global $frm_vars; |
@@ -143,58 +143,58 @@ discard block |
||
| 143 | 143 | $action_type = sanitize_text_field( $_POST['type'] ); |
| 144 | 144 | |
| 145 | 145 | $action_control = self::get_form_actions( $action_type ); |
| 146 | - $action_control->_set($action_key); |
|
| 146 | + $action_control->_set( $action_key ); |
|
| 147 | 147 | |
| 148 | 148 | $form_id = absint( $_POST['form_id'] ); |
| 149 | 149 | |
| 150 | - $form_action = $action_control->prepare_new($form_id); |
|
| 150 | + $form_action = $action_control->prepare_new( $form_id ); |
|
| 151 | 151 | |
| 152 | 152 | $values = array(); |
| 153 | - $form = self::fields_to_values($form_id, $values); |
|
| 153 | + $form = self::fields_to_values( $form_id, $values ); |
|
| 154 | 154 | |
| 155 | 155 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' ); |
| 156 | 156 | wp_die(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | public static function fill_action() { |
| 160 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
| 160 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
| 161 | 161 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 162 | 162 | |
| 163 | 163 | $action_key = absint( $_POST['action_id'] ); |
| 164 | 164 | $action_type = sanitize_text_field( $_POST['action_type'] ); |
| 165 | 165 | |
| 166 | 166 | $action_control = self::get_form_actions( $action_type ); |
| 167 | - if ( empty($action_control) ) { |
|
| 167 | + if ( empty( $action_control ) ) { |
|
| 168 | 168 | wp_die(); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | $form_action = $action_control->get_single_action( $action_key ); |
| 172 | 172 | |
| 173 | 173 | $values = array(); |
| 174 | - $form = self::fields_to_values($form_action->menu_order, $values); |
|
| 174 | + $form = self::fields_to_values( $form_action->menu_order, $values ); |
|
| 175 | 175 | |
| 176 | 176 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' ); |
| 177 | 177 | wp_die(); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | private static function fields_to_values( $form_id, array &$values ) { |
| 181 | - $form = FrmForm::getOne($form_id); |
|
| 181 | + $form = FrmForm::getOne( $form_id ); |
|
| 182 | 182 | |
| 183 | 183 | $values = array( |
| 184 | 184 | 'fields' => array(), |
| 185 | 185 | 'id' => $form->id, |
| 186 | 186 | ); |
| 187 | 187 | |
| 188 | - $fields = FrmField::get_all_for_form($form->id); |
|
| 188 | + $fields = FrmField::get_all_for_form( $form->id ); |
|
| 189 | 189 | foreach ( $fields as $k => $f ) { |
| 190 | 190 | $f = (array) $f; |
| 191 | 191 | $opts = (array) $f['field_options']; |
| 192 | - $f = array_merge($opts, $f); |
|
| 192 | + $f = array_merge( $opts, $f ); |
|
| 193 | 193 | if ( ! isset( $f['post_field'] ) ) { |
| 194 | 194 | $f['post_field'] = ''; |
| 195 | 195 | } |
| 196 | 196 | $values['fields'][] = $f; |
| 197 | - unset($k, $f); |
|
| 197 | + unset( $k, $f ); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | return $form; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $new_actions = array(); |
| 213 | 213 | |
| 214 | 214 | foreach ( $registered_actions as $registered_action ) { |
| 215 | - $action_ids = $registered_action->update_callback($form_id); |
|
| 215 | + $action_ids = $registered_action->update_callback( $form_id ); |
|
| 216 | 216 | if ( ! empty( $action_ids ) ) { |
| 217 | 217 | $new_actions[] = $action_ids; |
| 218 | 218 | } |
@@ -304,33 +304,33 @@ discard block |
||
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | // store actions so they can be triggered with the correct priority |
| 307 | - $stored_actions[ $action->ID ] = $action; |
|
| 308 | - $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
|
| 307 | + $stored_actions[$action->ID] = $action; |
|
| 308 | + $action_priority[$action->ID] = $link_settings[$action->post_excerpt]->action_options['priority']; |
|
| 309 | 309 | |
| 310 | - unset($action); |
|
| 310 | + unset( $action ); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | if ( ! empty( $stored_actions ) ) { |
| 314 | - asort($action_priority); |
|
| 314 | + asort( $action_priority ); |
|
| 315 | 315 | |
| 316 | 316 | // make sure hooks are loaded |
| 317 | 317 | new FrmNotification(); |
| 318 | 318 | |
| 319 | 319 | foreach ( $action_priority as $action_id => $priority ) { |
| 320 | - $action = $stored_actions[ $action_id ]; |
|
| 320 | + $action = $stored_actions[$action_id]; |
|
| 321 | 321 | do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event ); |
| 322 | 322 | do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form ); |
| 323 | 323 | |
| 324 | 324 | // If post is created, get updated $entry object |
| 325 | 325 | if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { |
| 326 | - $entry = FrmEntry::getOne($entry->id, true); |
|
| 326 | + $entry = FrmEntry::getOne( $entry->id, true ); |
|
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 333 | - if ( ! isset($args['old_id']) || empty($args['old_id']) ) { |
|
| 333 | + if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) { |
|
| 334 | 334 | // continue if we know which actions to copy |
| 335 | 335 | return; |
| 336 | 336 | } |
@@ -364,22 +364,22 @@ discard block |
||
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | public function register( $action_class ) { |
| 367 | - $this->actions[ $action_class ] = new $action_class(); |
|
| 367 | + $this->actions[$action_class] = new $action_class(); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | public function unregister( $action_class ) { |
| 371 | - if ( isset( $this->actions[ $action_class ] ) ) { |
|
| 372 | - unset($this->actions[ $action_class ]); |
|
| 371 | + if ( isset( $this->actions[$action_class] ) ) { |
|
| 372 | + unset( $this->actions[$action_class] ); |
|
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | public function _register_actions() { |
| 377 | - $keys = array_keys($this->actions); |
|
| 377 | + $keys = array_keys( $this->actions ); |
|
| 378 | 378 | |
| 379 | 379 | foreach ( $keys as $key ) { |
| 380 | 380 | // don't register new action if old action with the same id is already registered |
| 381 | - if ( ! isset( $this->actions[ $key ] ) ) { |
|
| 382 | - $this->actions[ $key ]->_register(); |
|
| 381 | + if ( ! isset( $this->actions[$key] ) ) { |
|
| 382 | + $this->actions[$key]->_register(); |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | } |
@@ -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,61 +342,61 @@ 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 | 364 | $limit = apply_filters( 'frm_form_action_limit', $limit, compact( 'type', 'form_id' ) ); |
| 365 | 365 | |
| 366 | - if ( 'all' != $type ) { |
|
| 367 | - return $action_controls->get_all( $form_id, $limit ); |
|
| 368 | - } |
|
| 366 | + if ( 'all' != $type ) { |
|
| 367 | + return $action_controls->get_all( $form_id, $limit ); |
|
| 368 | + } |
|
| 369 | 369 | |
| 370 | 370 | $args = self::action_args( $form_id, $limit ); |
| 371 | 371 | $actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' ); |
| 372 | 372 | |
| 373 | - if ( ! $actions ) { |
|
| 374 | - return array(); |
|
| 375 | - } |
|
| 373 | + if ( ! $actions ) { |
|
| 374 | + return array(); |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | - $settings = array(); |
|
| 378 | - foreach ( $actions as $action ) { |
|
| 377 | + $settings = array(); |
|
| 378 | + foreach ( $actions as $action ) { |
|
| 379 | 379 | // some plugins/themes are formatting the post_excerpt |
| 380 | 380 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 381 | 381 | |
| 382 | 382 | if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
| 383 | - continue; |
|
| 384 | - } |
|
| 383 | + continue; |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
| 386 | + $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
| 387 | 387 | $settings[ $action->ID ] = $action; |
| 388 | 388 | |
| 389 | 389 | if ( count( $settings ) >= $limit ) { |
| 390 | 390 | break; |
| 391 | 391 | } |
| 392 | - } |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - if ( 1 === $limit ) { |
|
| 395 | - $settings = reset($settings); |
|
| 396 | - } |
|
| 394 | + if ( 1 === $limit ) { |
|
| 395 | + $settings = reset($settings); |
|
| 396 | + } |
|
| 397 | 397 | |
| 398 | - return $settings; |
|
| 399 | - } |
|
| 398 | + return $settings; |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | 401 | /** |
| 402 | 402 | * @param int $action_id |
@@ -419,45 +419,45 @@ discard block |
||
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | public function get_all( $form_id = false, $limit = 99 ) { |
| 422 | - if ( $form_id ) { |
|
| 423 | - $this->form_id = $form_id; |
|
| 424 | - } |
|
| 422 | + if ( $form_id ) { |
|
| 423 | + $this->form_id = $form_id; |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | - $type = $this->id_base; |
|
| 426 | + $type = $this->id_base; |
|
| 427 | 427 | |
| 428 | - global $frm_vars; |
|
| 429 | - $frm_vars['action_type'] = $type; |
|
| 428 | + global $frm_vars; |
|
| 429 | + $frm_vars['action_type'] = $type; |
|
| 430 | 430 | |
| 431 | 431 | add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
| 432 | 432 | $query = self::action_args( $form_id, $limit ); |
| 433 | - $query['post_status'] = 'any'; |
|
| 434 | - $query['suppress_filters'] = false; |
|
| 433 | + $query['post_status'] = 'any'; |
|
| 434 | + $query['suppress_filters'] = false; |
|
| 435 | 435 | |
| 436 | 436 | $actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
| 437 | - unset($query); |
|
| 437 | + unset($query); |
|
| 438 | 438 | |
| 439 | 439 | remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
| 440 | 440 | |
| 441 | - if ( empty($actions) ) { |
|
| 442 | - return array(); |
|
| 443 | - } |
|
| 441 | + if ( empty($actions) ) { |
|
| 442 | + return array(); |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | - $settings = array(); |
|
| 446 | - foreach ( $actions as $action ) { |
|
| 447 | - if ( count($settings) >= $limit ) { |
|
| 448 | - continue; |
|
| 449 | - } |
|
| 445 | + $settings = array(); |
|
| 446 | + foreach ( $actions as $action ) { |
|
| 447 | + if ( count($settings) >= $limit ) { |
|
| 448 | + continue; |
|
| 449 | + } |
|
| 450 | 450 | |
| 451 | - $action = $this->prepare_action($action); |
|
| 451 | + $action = $this->prepare_action($action); |
|
| 452 | 452 | |
| 453 | 453 | $settings[ $action->ID ] = $action; |
| 454 | - } |
|
| 454 | + } |
|
| 455 | 455 | |
| 456 | - if ( 1 === $limit ) { |
|
| 457 | - $settings = reset($settings); |
|
| 458 | - } |
|
| 456 | + if ( 1 === $limit ) { |
|
| 457 | + $settings = reset($settings); |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - return $settings; |
|
| 460 | + return $settings; |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | public static function action_args( $form_id = 0, $limit = 99 ) { |
@@ -480,45 +480,45 @@ discard block |
||
| 480 | 480 | $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
| 481 | 481 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 482 | 482 | |
| 483 | - $default_values = $this->get_global_defaults(); |
|
| 483 | + $default_values = $this->get_global_defaults(); |
|
| 484 | 484 | |
| 485 | - // fill default values |
|
| 486 | - $action->post_content += $default_values; |
|
| 485 | + // fill default values |
|
| 486 | + $action->post_content += $default_values; |
|
| 487 | 487 | |
| 488 | - foreach ( $default_values as $k => $vals ) { |
|
| 489 | - if ( is_array($vals) && ! empty($vals) ) { |
|
| 488 | + foreach ( $default_values as $k => $vals ) { |
|
| 489 | + if ( is_array($vals) && ! empty($vals) ) { |
|
| 490 | 490 | if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
| 491 | - continue; |
|
| 492 | - } |
|
| 491 | + continue; |
|
| 492 | + } |
|
| 493 | 493 | $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
| 494 | - } |
|
| 495 | - } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | 496 | |
| 497 | - if ( ! is_array($action->post_content['event']) ) { |
|
| 498 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
| 499 | - } |
|
| 497 | + if ( ! is_array($action->post_content['event']) ) { |
|
| 498 | + $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | - return $action; |
|
| 501 | + return $action; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | public function destroy( $form_id = false, $type = 'default' ) { |
| 505 | - global $wpdb; |
|
| 505 | + global $wpdb; |
|
| 506 | 506 | |
| 507 | - $this->form_id = $form_id; |
|
| 507 | + $this->form_id = $form_id; |
|
| 508 | 508 | |
| 509 | - $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
| 510 | - if ( $form_id ) { |
|
| 511 | - $query['menu_order'] = $form_id; |
|
| 512 | - } |
|
| 513 | - if ( 'all' != $type ) { |
|
| 514 | - $query['post_excerpt'] = $this->id_base; |
|
| 515 | - } |
|
| 509 | + $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
| 510 | + if ( $form_id ) { |
|
| 511 | + $query['menu_order'] = $form_id; |
|
| 512 | + } |
|
| 513 | + if ( 'all' != $type ) { |
|
| 514 | + $query['post_excerpt'] = $this->id_base; |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | - $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
| 517 | + $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
| 518 | 518 | |
| 519 | - foreach ( $post_ids as $id ) { |
|
| 520 | - wp_delete_post($id); |
|
| 521 | - } |
|
| 519 | + foreach ( $post_ids as $id ) { |
|
| 520 | + wp_delete_post($id); |
|
| 521 | + } |
|
| 522 | 522 | self::clear_cache(); |
| 523 | 523 | } |
| 524 | 524 | |
@@ -536,69 +536,69 @@ discard block |
||
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | public function get_global_defaults() { |
| 539 | - $defaults = $this->get_defaults(); |
|
| 539 | + $defaults = $this->get_defaults(); |
|
| 540 | 540 | |
| 541 | - if ( ! isset($defaults['event']) ) { |
|
| 541 | + if ( ! isset($defaults['event']) ) { |
|
| 542 | 542 | $defaults['event'] = array( 'create' ); |
| 543 | - } |
|
| 543 | + } |
|
| 544 | 544 | |
| 545 | - if ( ! isset($defaults['conditions']) ) { |
|
| 546 | - $defaults['conditions'] = array( |
|
| 547 | - 'send_stop' => '', |
|
| 548 | - 'any_all' => '', |
|
| 549 | - ); |
|
| 550 | - } |
|
| 545 | + if ( ! isset($defaults['conditions']) ) { |
|
| 546 | + $defaults['conditions'] = array( |
|
| 547 | + 'send_stop' => '', |
|
| 548 | + 'any_all' => '', |
|
| 549 | + ); |
|
| 550 | + } |
|
| 551 | 551 | |
| 552 | - return $defaults; |
|
| 552 | + return $defaults; |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | public function get_global_switch_fields() { |
| 556 | - $switch = $this->get_switch_fields(); |
|
| 556 | + $switch = $this->get_switch_fields(); |
|
| 557 | 557 | $switch['conditions'] = array( 'hide_field' ); |
| 558 | - return $switch; |
|
| 558 | + return $switch; |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
| 562 | 562 | * Migrate settings from form->options into new action. |
| 563 | 563 | */ |
| 564 | 564 | public function migrate_to_2( $form, $update = 'update' ) { |
| 565 | - $action = $this->prepare_new($form->id); |
|
| 566 | - $form->options = maybe_unserialize($form->options); |
|
| 565 | + $action = $this->prepare_new($form->id); |
|
| 566 | + $form->options = maybe_unserialize($form->options); |
|
| 567 | 567 | |
| 568 | - // fill with existing options |
|
| 569 | - foreach ( $action->post_content as $name => $val ) { |
|
| 568 | + // fill with existing options |
|
| 569 | + foreach ( $action->post_content as $name => $val ) { |
|
| 570 | 570 | if ( isset( $form->options[ $name ] ) ) { |
| 571 | 571 | $action->post_content[ $name ] = $form->options[ $name ]; |
| 572 | 572 | unset( $form->options[ $name ] ); |
| 573 | - } |
|
| 574 | - } |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | - $action = $this->migrate_values($action, $form); |
|
| 576 | + $action = $this->migrate_values($action, $form); |
|
| 577 | 577 | |
| 578 | - // check if action already exists |
|
| 579 | - $post_id = get_posts( array( |
|
| 580 | - 'name' => $action->post_name, |
|
| 581 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
| 582 | - 'post_status' => $action->post_status, |
|
| 583 | - 'numberposts' => 1, |
|
| 584 | - ) ); |
|
| 578 | + // check if action already exists |
|
| 579 | + $post_id = get_posts( array( |
|
| 580 | + 'name' => $action->post_name, |
|
| 581 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
| 582 | + 'post_status' => $action->post_status, |
|
| 583 | + 'numberposts' => 1, |
|
| 584 | + ) ); |
|
| 585 | 585 | |
| 586 | - if ( empty($post_id) ) { |
|
| 587 | - // create action now |
|
| 588 | - $post_id = $this->save_settings($action); |
|
| 589 | - } |
|
| 586 | + if ( empty($post_id) ) { |
|
| 587 | + // create action now |
|
| 588 | + $post_id = $this->save_settings($action); |
|
| 589 | + } |
|
| 590 | 590 | |
| 591 | - if ( $post_id && 'update' == $update ) { |
|
| 592 | - global $wpdb; |
|
| 593 | - $form->options = maybe_serialize($form->options); |
|
| 591 | + if ( $post_id && 'update' == $update ) { |
|
| 592 | + global $wpdb; |
|
| 593 | + $form->options = maybe_serialize($form->options); |
|
| 594 | 594 | |
| 595 | - // update form options |
|
| 595 | + // update form options |
|
| 596 | 596 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
| 597 | - FrmForm::clear_form_cache(); |
|
| 598 | - } |
|
| 597 | + FrmForm::clear_form_cache(); |
|
| 598 | + } |
|
| 599 | 599 | |
| 600 | - return $post_id; |
|
| 601 | - } |
|
| 600 | + return $post_id; |
|
| 601 | + } |
|
| 602 | 602 | |
| 603 | 603 | public static function action_conditions_met( $action, $entry ) { |
| 604 | 604 | $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. |
@@ -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 | } |
@@ -379,12 +379,12 @@ discard block |
||
| 379 | 379 | // some plugins/themes are formatting the post_excerpt |
| 380 | 380 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 381 | 381 | |
| 382 | - if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
|
| 382 | + if ( ! isset( $action_controls[$action->post_excerpt] ) ) { |
|
| 383 | 383 | continue; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
| 387 | - $settings[ $action->ID ] = $action; |
|
| 386 | + $action = $action_controls[$action->post_excerpt]->prepare_action( $action ); |
|
| 387 | + $settings[$action->ID] = $action; |
|
| 388 | 388 | |
| 389 | 389 | if ( count( $settings ) >= $limit ) { |
| 390 | 390 | break; |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | if ( 1 === $limit ) { |
| 395 | - $settings = reset($settings); |
|
| 395 | + $settings = reset( $settings ); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | return $settings; |
@@ -434,27 +434,27 @@ discard block |
||
| 434 | 434 | $query['suppress_filters'] = false; |
| 435 | 435 | |
| 436 | 436 | $actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
| 437 | - unset($query); |
|
| 437 | + unset( $query ); |
|
| 438 | 438 | |
| 439 | 439 | remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
| 440 | 440 | |
| 441 | - if ( empty($actions) ) { |
|
| 441 | + if ( empty( $actions ) ) { |
|
| 442 | 442 | return array(); |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | $settings = array(); |
| 446 | 446 | foreach ( $actions as $action ) { |
| 447 | - if ( count($settings) >= $limit ) { |
|
| 447 | + if ( count( $settings ) >= $limit ) { |
|
| 448 | 448 | continue; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $action = $this->prepare_action($action); |
|
| 451 | + $action = $this->prepare_action( $action ); |
|
| 452 | 452 | |
| 453 | - $settings[ $action->ID ] = $action; |
|
| 453 | + $settings[$action->ID] = $action; |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | if ( 1 === $limit ) { |
| 457 | - $settings = reset($settings); |
|
| 457 | + $settings = reset( $settings ); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | return $settings; |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | public function prepare_action( $action ) { |
| 480 | - $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
|
| 480 | + $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
|
| 481 | 481 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 482 | 482 | |
| 483 | 483 | $default_values = $this->get_global_defaults(); |
@@ -486,16 +486,16 @@ discard block |
||
| 486 | 486 | $action->post_content += $default_values; |
| 487 | 487 | |
| 488 | 488 | foreach ( $default_values as $k => $vals ) { |
| 489 | - if ( is_array($vals) && ! empty($vals) ) { |
|
| 490 | - if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
|
| 489 | + if ( is_array( $vals ) && ! empty( $vals ) ) { |
|
| 490 | + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[$k] ) ) { |
|
| 491 | 491 | continue; |
| 492 | 492 | } |
| 493 | - $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
|
| 493 | + $action->post_content[$k] = wp_parse_args( $action->post_content[$k], $vals ); |
|
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | - if ( ! is_array($action->post_content['event']) ) { |
|
| 498 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
| 497 | + if ( ! is_array( $action->post_content['event'] ) ) { |
|
| 498 | + $action->post_content['event'] = explode( ',', $action->post_content['event'] ); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | return $action; |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
| 518 | 518 | |
| 519 | 519 | foreach ( $post_ids as $id ) { |
| 520 | - wp_delete_post($id); |
|
| 520 | + wp_delete_post( $id ); |
|
| 521 | 521 | } |
| 522 | 522 | self::clear_cache(); |
| 523 | 523 | } |
@@ -538,11 +538,11 @@ discard block |
||
| 538 | 538 | public function get_global_defaults() { |
| 539 | 539 | $defaults = $this->get_defaults(); |
| 540 | 540 | |
| 541 | - if ( ! isset($defaults['event']) ) { |
|
| 541 | + if ( ! isset( $defaults['event'] ) ) { |
|
| 542 | 542 | $defaults['event'] = array( 'create' ); |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - if ( ! isset($defaults['conditions']) ) { |
|
| 545 | + if ( ! isset( $defaults['conditions'] ) ) { |
|
| 546 | 546 | $defaults['conditions'] = array( |
| 547 | 547 | 'send_stop' => '', |
| 548 | 548 | 'any_all' => '', |
@@ -562,18 +562,18 @@ discard block |
||
| 562 | 562 | * Migrate settings from form->options into new action. |
| 563 | 563 | */ |
| 564 | 564 | public function migrate_to_2( $form, $update = 'update' ) { |
| 565 | - $action = $this->prepare_new($form->id); |
|
| 566 | - $form->options = maybe_unserialize($form->options); |
|
| 565 | + $action = $this->prepare_new( $form->id ); |
|
| 566 | + $form->options = maybe_unserialize( $form->options ); |
|
| 567 | 567 | |
| 568 | 568 | // fill with existing options |
| 569 | 569 | foreach ( $action->post_content as $name => $val ) { |
| 570 | - if ( isset( $form->options[ $name ] ) ) { |
|
| 571 | - $action->post_content[ $name ] = $form->options[ $name ]; |
|
| 572 | - unset( $form->options[ $name ] ); |
|
| 570 | + if ( isset( $form->options[$name] ) ) { |
|
| 571 | + $action->post_content[$name] = $form->options[$name]; |
|
| 572 | + unset( $form->options[$name] ); |
|
| 573 | 573 | } |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | - $action = $this->migrate_values($action, $form); |
|
| 576 | + $action = $this->migrate_values( $action, $form ); |
|
| 577 | 577 | |
| 578 | 578 | // check if action already exists |
| 579 | 579 | $post_id = get_posts( array( |
@@ -583,14 +583,14 @@ discard block |
||
| 583 | 583 | 'numberposts' => 1, |
| 584 | 584 | ) ); |
| 585 | 585 | |
| 586 | - if ( empty($post_id) ) { |
|
| 586 | + if ( empty( $post_id ) ) { |
|
| 587 | 587 | // create action now |
| 588 | - $post_id = $this->save_settings($action); |
|
| 588 | + $post_id = $this->save_settings( $action ); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | if ( $post_id && 'update' == $update ) { |
| 592 | 592 | global $wpdb; |
| 593 | - $form->options = maybe_serialize($form->options); |
|
| 593 | + $form->options = maybe_serialize( $form->options ); |
|
| 594 | 594 | |
| 595 | 595 | // update form options |
| 596 | 596 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
@@ -622,18 +622,18 @@ discard block |
||
| 622 | 622 | |
| 623 | 623 | $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] ); |
| 624 | 624 | |
| 625 | - $stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']); |
|
| 625 | + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] ); |
|
| 626 | 626 | |
| 627 | 627 | if ( $notification['conditions']['send_stop'] == 'send' ) { |
| 628 | 628 | $stop = $stop ? false : true; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - $met[ $stop ] = $stop; |
|
| 631 | + $met[$stop] = $stop; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { |
| 635 | 635 | $stop = ( $notification['conditions']['send_stop'] == 'send' ); |
| 636 | - } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) { |
|
| 636 | + } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) { |
|
| 637 | 637 | $stop = false; |
| 638 | 638 | } |
| 639 | 639 | |
@@ -668,8 +668,8 @@ discard block |
||
| 668 | 668 | private static function get_value_from_entry( $entry, $field_id ) { |
| 669 | 669 | $observed_value = ''; |
| 670 | 670 | |
| 671 | - if ( isset( $entry->metas[ $field_id ] ) ) { |
|
| 672 | - $observed_value = $entry->metas[ $field_id ]; |
|
| 671 | + if ( isset( $entry->metas[$field_id] ) ) { |
|
| 672 | + $observed_value = $entry->metas[$field_id]; |
|
| 673 | 673 | } else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) { |
| 674 | 674 | $field = FrmField::getOne( $field_id ); |
| 675 | 675 | $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value( $entry, $field, array( |
@@ -83,12 +83,12 @@ |
||
| 83 | 83 | ) ); |
| 84 | 84 | |
| 85 | 85 | foreach ( $this->style_settings as $key => $setting ) { |
| 86 | - if ( isset( $atts[ $key ] ) && $atts[ $key ] !== '' ) { |
|
| 87 | - $this->style_settings[ $key ] = $atts[ $key ]; |
|
| 86 | + if ( isset( $atts[$key] ) && $atts[$key] !== '' ) { |
|
| 87 | + $this->style_settings[$key] = $atts[$key]; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | if ( $this->is_color_setting( $key ) ) { |
| 91 | - $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] ); |
|
| 91 | + $this->style_settings[$key] = $this->get_color_markup( $this->style_settings[$key] ); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | public function widget( $args, $instance ) { |
| 11 | - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
|
| 11 | + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
|
| 12 | 12 | |
| 13 | 13 | echo $args['before_widget']; |
| 14 | 14 | |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 | |
| 5 | 5 | public function __construct() { |
| 6 | 6 | $widget_ops = array( 'description' => __( 'Display a Formidable Form', 'formidable' ) ); |
| 7 | - parent::__construct('frm_show_form', __( 'Formidable Form', 'formidable' ), $widget_ops); |
|
| 7 | + parent::__construct( 'frm_show_form', __( 'Formidable Form', 'formidable' ), $widget_ops ); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | public function widget( $args, $instance ) { |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | <div class="clear"></div> |
| 63 | 63 | <p class="frm_no_bottom_margin"> |
| 64 | 64 | <label> |
| 65 | - <input type="checkbox" name="<?php echo esc_attr( $frm_style->get_field_name( 'remove_box_shadow' ) ) ?>" id="frm_remove_box_shadow" value="1" <?php checked($style->post_content['remove_box_shadow'], 1) ?> /> |
|
| 65 | + <input type="checkbox" name="<?php echo esc_attr( $frm_style->get_field_name( 'remove_box_shadow' ) ) ?>" id="frm_remove_box_shadow" value="1" <?php checked( $style->post_content['remove_box_shadow'], 1 ) ?> /> |
|
| 66 | 66 | <?php esc_html_e( 'Remove box shadow', 'formidable' ) ?> |
| 67 | 67 | </label> |
| 68 | 68 | </p> |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | <div class="clear"></div> |
| 83 | 83 | <p class="frm_no_bottom_margin"> |
| 84 | 84 | <label> |
| 85 | - <input type="checkbox" name="<?php echo esc_attr( $frm_style->get_field_name( 'remove_box_shadow_active' ) ); ?>" id="frm_remove_box_shadow_active" value="1" <?php checked($style->post_content['remove_box_shadow_active'], 1) ?> /> |
|
| 85 | + <input type="checkbox" name="<?php echo esc_attr( $frm_style->get_field_name( 'remove_box_shadow_active' ) ); ?>" id="frm_remove_box_shadow_active" value="1" <?php checked( $style->post_content['remove_box_shadow_active'], 1 ) ?> /> |
|
| 86 | 86 | <?php esc_html_e( 'Remove box shadow', 'formidable' ) ?> |
| 87 | 87 | </label> |
| 88 | 88 | </p> |
@@ -1,42 +1,42 @@ |
||
| 1 | 1 | <div class="field-group clearfix frm-first-row"> |
| 2 | 2 | <label><?php esc_html_e( 'Size', 'formidable' ) ?></label> |
| 3 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('field_font_size') ) ?>" id="frm_field_font_size" value="<?php echo esc_attr( $style->post_content['field_font_size'] ) ?>" /> |
|
| 3 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'field_font_size' ) ) ?>" id="frm_field_font_size" value="<?php echo esc_attr( $style->post_content['field_font_size'] ) ?>" /> |
|
| 4 | 4 | </div> |
| 5 | 5 | |
| 6 | 6 | <div class="field-group clearfix frm-first-row"> |
| 7 | 7 | <label><?php esc_html_e( 'Height', 'formidable' ) ?></label> |
| 8 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('field_height') ) ?>" id="frm_field_height" value="<?php echo esc_attr( $style->post_content['field_height'] ) ?>" /> |
|
| 8 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'field_height' ) ) ?>" id="frm_field_height" value="<?php echo esc_attr( $style->post_content['field_height'] ) ?>" /> |
|
| 9 | 9 | </div> |
| 10 | 10 | |
| 11 | 11 | <div class="field-group clearfix frm-first-row"> |
| 12 | 12 | <label><?php esc_html_e( 'Width', 'formidable' ) ?></label> |
| 13 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('field_width') ) ?>" id="frm_field_width" value="<?php echo esc_attr( $style->post_content['field_width'] ) ?>" /> |
|
| 13 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'field_width' ) ) ?>" id="frm_field_width" value="<?php echo esc_attr( $style->post_content['field_width'] ) ?>" /> |
|
| 14 | 14 | </div> |
| 15 | 15 | |
| 16 | 16 | <div class="clear"></div> |
| 17 | 17 | <p class="frm_no_bottom_margin"> |
| 18 | - <label><input type="checkbox" name="<?php echo esc_attr( $frm_style->get_field_name('auto_width') ) ?>" id="frm_auto_width" value="1" <?php checked( $style->post_content['auto_width'], 1 ) ?> /> |
|
| 18 | + <label><input type="checkbox" name="<?php echo esc_attr( $frm_style->get_field_name( 'auto_width' ) ) ?>" id="frm_auto_width" value="1" <?php checked( $style->post_content['auto_width'], 1 ) ?> /> |
|
| 19 | 19 | <?php esc_html_e( 'Automatic Width for drop-down fields', 'formidable' ) ?></label> |
| 20 | 20 | </p> |
| 21 | 21 | |
| 22 | 22 | <div class="field-group clearfix"> |
| 23 | 23 | <label><?php esc_html_e( 'Padding', 'formidable' ) ?></label> |
| 24 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('field_pad') ) ?>" id="frm_field_pad" value="<?php echo esc_attr( $style->post_content['field_pad'] ) ?>" /> |
|
| 24 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'field_pad' ) ) ?>" id="frm_field_pad" value="<?php echo esc_attr( $style->post_content['field_pad'] ) ?>" /> |
|
| 25 | 25 | </div> |
| 26 | 26 | |
| 27 | 27 | <div class="field-group clearfix"> |
| 28 | 28 | <label><?php esc_html_e( 'Margin', 'formidable' ) ?></label> |
| 29 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('field_margin') ) ?>" id="frm_field_margin" value="<?php echo esc_attr( $style->post_content['field_margin'] ) ?>" /> |
|
| 29 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'field_margin' ) ) ?>" id="frm_field_margin" value="<?php echo esc_attr( $style->post_content['field_margin'] ) ?>" /> |
|
| 30 | 30 | </div> |
| 31 | 31 | |
| 32 | 32 | <div class="field-group clearfix"> |
| 33 | 33 | <label><?php esc_html_e( 'Corners', 'formidable' ) ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Formidable uses CSS3 border-radius for corner rounding, which is not currently supported by Internet Explorer.', 'formidable' ) ?>" ></span></label> |
| 34 | - <input type="text" value="<?php echo esc_attr( $style->post_content['border_radius'] ) ?>" name="<?php echo esc_attr( $frm_style->get_field_name('border_radius') ) ?>" id="frm_border_radius" /> |
|
| 34 | + <input type="text" value="<?php echo esc_attr( $style->post_content['border_radius'] ) ?>" name="<?php echo esc_attr( $frm_style->get_field_name( 'border_radius' ) ) ?>" id="frm_border_radius" /> |
|
| 35 | 35 | </div> |
| 36 | 36 | |
| 37 | 37 | <div class="field-group clearfix frm-first-row"> |
| 38 | 38 | <label><?php esc_html_e( 'Weight', 'formidable' ) ?></label> |
| 39 | - <select name="<?php echo esc_attr( $frm_style->get_field_name('field_weight') ) ?>" id="frm_field_weight"> |
|
| 39 | + <select name="<?php echo esc_attr( $frm_style->get_field_name( 'field_weight' ) ) ?>" id="frm_field_weight"> |
|
| 40 | 40 | <?php foreach ( FrmStyle::get_bold_options() as $value => $name ) { ?> |
| 41 | 41 | <option value="<?php echo esc_attr( $value ) ?>" <?php selected( $style->post_content['field_weight'], $value ) ?>><?php echo esc_attr( $name ) ?></option> |
| 42 | 42 | <?php } ?> |