@@ -147,6 +147,7 @@ discard block |
||
| 147 | 147 | * Include the permissions settings for each capability. |
| 148 | 148 | * |
| 149 | 149 | * @since 3.06.04 |
| 150 | + * @param FrmSettings $settings_list |
|
| 150 | 151 | * @return array |
| 151 | 152 | */ |
| 152 | 153 | private function messages( $settings_list ) { |
@@ -173,6 +174,7 @@ discard block |
||
| 173 | 174 | * Include the permissions settings for each capability. |
| 174 | 175 | * |
| 175 | 176 | * @since 3.06.04 |
| 177 | + * @param FrmSettings $settings_list |
|
| 176 | 178 | * @return array |
| 177 | 179 | */ |
| 178 | 180 | private function permissions( $settings_list ) { |
@@ -177,9 +177,9 @@ |
||
| 177 | 177 | */ |
| 178 | 178 | private function permissions( $settings_list ) { |
| 179 | 179 | $permissions = array(); |
| 180 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 180 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 181 | 181 | |
| 182 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 182 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 183 | 183 | if ( isset( $settings_list->$frm_role ) ) { |
| 184 | 184 | $permissions[ $frm_role ] = $settings_list->$frm_role; |
| 185 | 185 | } |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | * @return array |
| 114 | 114 | */ |
| 115 | 115 | private function settings() { |
| 116 | - $settings_list = FrmAppHelper::get_settings(); |
|
| 117 | - $settings = array( |
|
| 116 | + $settings_list = FrmAppHelper::get_settings(); |
|
| 117 | + $settings = array( |
|
| 118 | 118 | 'messages' => $this->messages( $settings_list ), |
| 119 | 119 | 'permissions' => $this->permissions( $settings_list ), |
| 120 | 120 | ); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | foreach ( $pass_settings as $setting ) { |
| 138 | 138 | if ( isset( $settings_list->$setting ) ) { |
| 139 | - $settings[ $setting ] = $settings_list->$setting; |
|
| 139 | + $settings[$setting] = $settings_list->$setting; |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | $message_settings = array(); |
| 165 | 165 | foreach ( $messages as $message ) { |
| 166 | - $message_settings[ $message ] = $settings_list->$message; |
|
| 166 | + $message_settings[$message] = $settings_list->$message; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | return $message_settings; |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | private function permissions( $settings_list ) { |
| 179 | 179 | $permissions = array(); |
| 180 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 180 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 181 | 181 | |
| 182 | 182 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 183 | 183 | if ( isset( $settings_list->$frm_role ) ) { |
| 184 | - $permissions[ $frm_role ] = $settings_list->$frm_role; |
|
| 184 | + $permissions[$frm_role] = $settings_list->$frm_role; |
|
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | ); |
| 237 | 237 | |
| 238 | 238 | foreach ( $saved_forms as $form ) { |
| 239 | - $forms[ $form->id ] = array( |
|
| 239 | + $forms[$form->id] = array( |
|
| 240 | 240 | 'id' => $form->id, |
| 241 | 241 | 'description' => $form->description, |
| 242 | 242 | 'logged_in' => $form->logged_in, |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | ); |
| 249 | 249 | |
| 250 | 250 | foreach ( $settings as $setting ) { |
| 251 | - if ( isset( $form->options[ $setting ] ) ) { |
|
| 252 | - $forms[ $form->id ][ $setting ] = $form->options[ $setting ]; |
|
| 251 | + if ( isset( $form->options[$setting] ) ) { |
|
| 252 | + $forms[$form->id][$setting] = $form->options[$setting]; |
|
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @return array |
| 298 | 298 | */ |
| 299 | 299 | private function fields() { |
| 300 | - $args = array( |
|
| 300 | + $args = array( |
|
| 301 | 301 | 'limit' => 100, |
| 302 | 302 | 'order_by' => 'id DESC', |
| 303 | 303 | ); |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | |
| 320 | 320 | $saved_actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' ); |
| 321 | 321 | foreach ( $saved_actions as $action ) { |
| 322 | - $actions[ $action->ID ] = array( |
|
| 322 | + $actions[$action->ID] = array( |
|
| 323 | 323 | 'form_id' => $action->menu_order, |
| 324 | 324 | 'type' => $action->post_excerpt, |
| 325 | 325 | 'status' => $action->post_status, |
@@ -1,15 +1,15 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - die( 'You are not allowed to call this page directly.' ); |
|
| 3 | + die( 'You are not allowed to call this page directly.' ); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmForm { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @return int|boolean id on success or false on failure |
|
| 10 | - */ |
|
| 11 | - public static function create( $values ) { |
|
| 12 | - global $wpdb; |
|
| 8 | + /** |
|
| 9 | + * @return int|boolean id on success or false on failure |
|
| 10 | + */ |
|
| 11 | + public static function create( $values ) { |
|
| 12 | + global $wpdb; |
|
| 13 | 13 | |
| 14 | 14 | $new_values = array( |
| 15 | 15 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
@@ -33,52 +33,52 @@ discard block |
||
| 33 | 33 | $options = apply_filters( 'frm_form_options_before_update', $options, $values ); |
| 34 | 34 | $new_values['options'] = serialize( $options ); |
| 35 | 35 | |
| 36 | - //if(isset($values['id']) && is_numeric($values['id'])) |
|
| 37 | - // $new_values['id'] = $values['id']; |
|
| 36 | + //if(isset($values['id']) && is_numeric($values['id'])) |
|
| 37 | + // $new_values['id'] = $values['id']; |
|
| 38 | 38 | |
| 39 | 39 | $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
| 40 | 40 | |
| 41 | - $id = $wpdb->insert_id; |
|
| 41 | + $id = $wpdb->insert_id; |
|
| 42 | 42 | |
| 43 | 43 | // Clear form caching |
| 44 | 44 | self::clear_form_cache(); |
| 45 | 45 | |
| 46 | - return $id; |
|
| 47 | - } |
|
| 46 | + return $id; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return int|boolean ID on success or false on failure |
|
| 51 | - */ |
|
| 52 | - public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
|
| 53 | - global $wpdb; |
|
| 49 | + /** |
|
| 50 | + * @return int|boolean ID on success or false on failure |
|
| 51 | + */ |
|
| 52 | + public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
|
| 53 | + global $wpdb; |
|
| 54 | 54 | |
| 55 | - $values = self::getOne( $id, $blog_id ); |
|
| 56 | - if ( ! $values ) { |
|
| 57 | - return false; |
|
| 58 | - } |
|
| 55 | + $values = self::getOne( $id, $blog_id ); |
|
| 56 | + if ( ! $values ) { |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $new_key = $copy_keys ? $values->form_key : ''; |
|
| 60 | + $new_key = $copy_keys ? $values->form_key : ''; |
|
| 61 | 61 | |
| 62 | - $new_values = array( |
|
| 62 | + $new_values = array( |
|
| 63 | 63 | 'form_key' => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ), |
| 64 | - 'name' => $values->name, |
|
| 65 | - 'description' => $values->description, |
|
| 66 | - 'status' => $template ? 'published' : 'draft', |
|
| 67 | - 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
|
| 68 | - 'editable' => $values->editable ? $values->editable : 0, |
|
| 64 | + 'name' => $values->name, |
|
| 65 | + 'description' => $values->description, |
|
| 66 | + 'status' => $template ? 'published' : 'draft', |
|
| 67 | + 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
|
| 68 | + 'editable' => $values->editable ? $values->editable : 0, |
|
| 69 | 69 | 'created_at' => current_time( 'mysql', 1 ), |
| 70 | - 'is_template' => $template ? 1 : 0, |
|
| 71 | - ); |
|
| 70 | + 'is_template' => $template ? 1 : 0, |
|
| 71 | + ); |
|
| 72 | 72 | |
| 73 | - if ( $blog_id ) { |
|
| 74 | - $new_values['status'] = 'published'; |
|
| 73 | + if ( $blog_id ) { |
|
| 74 | + $new_values['status'] = 'published'; |
|
| 75 | 75 | $new_options = maybe_unserialize( $values->options ); |
| 76 | 76 | $new_options['email_to'] = get_option( 'admin_email' ); |
| 77 | - $new_options['copy'] = false; |
|
| 78 | - $new_values['options'] = $new_options; |
|
| 79 | - } else { |
|
| 80 | - $new_values['options'] = $values->options; |
|
| 81 | - } |
|
| 77 | + $new_options['copy'] = false; |
|
| 78 | + $new_values['options'] = $new_options; |
|
| 79 | + } else { |
|
| 80 | + $new_values['options'] = $values->options; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | if ( is_array( $new_values['options'] ) ) { |
| 84 | 84 | $new_values['options'] = serialize( $new_values['options'] ); |
@@ -86,20 +86,20 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
| 88 | 88 | |
| 89 | - if ( $query_results ) { |
|
| 89 | + if ( $query_results ) { |
|
| 90 | 90 | // Clear form caching |
| 91 | 91 | self::clear_form_cache(); |
| 92 | 92 | |
| 93 | - $form_id = $wpdb->insert_id; |
|
| 93 | + $form_id = $wpdb->insert_id; |
|
| 94 | 94 | FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id ); |
| 95 | 95 | |
| 96 | - // update form settings after fields are created |
|
| 96 | + // update form settings after fields are created |
|
| 97 | 97 | do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) ); |
| 98 | - return $form_id; |
|
| 99 | - } |
|
| 98 | + return $form_id; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return false; |
|
| 102 | - } |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | public static function after_duplicate( $form_id, $values ) { |
| 105 | 105 | $new_opts = maybe_unserialize( $values['options'] ); |
@@ -111,48 +111,48 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id ); |
| 113 | 113 | |
| 114 | - if ( $new_opts != $values['options'] ) { |
|
| 115 | - global $wpdb; |
|
| 114 | + if ( $new_opts != $values['options'] ) { |
|
| 115 | + global $wpdb; |
|
| 116 | 116 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) ); |
| 117 | - } |
|
| 118 | - } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @return int|boolean |
|
| 122 | - */ |
|
| 123 | - public static function update( $id, $values, $create_link = false ) { |
|
| 124 | - global $wpdb; |
|
| 120 | + /** |
|
| 121 | + * @return int|boolean |
|
| 122 | + */ |
|
| 123 | + public static function update( $id, $values, $create_link = false ) { |
|
| 124 | + global $wpdb; |
|
| 125 | 125 | |
| 126 | - if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
| 127 | - $values['status'] = 'published'; |
|
| 128 | - } |
|
| 126 | + if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
| 127 | + $values['status'] = 'published'; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | if ( isset( $values['form_key'] ) ) { |
| 131 | 131 | $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id ); |
| 132 | - } |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
| 135 | 135 | |
| 136 | 136 | $new_values = self::set_update_options( array(), $values ); |
| 137 | 137 | |
| 138 | - foreach ( $values as $value_key => $value ) { |
|
| 138 | + foreach ( $values as $value_key => $value ) { |
|
| 139 | 139 | if ( $value_key && in_array( $value_key, $form_fields ) ) { |
| 140 | 140 | $new_values[ $value_key ] = $value; |
| 141 | - } |
|
| 142 | - } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
| 145 | - $new_values['status'] = $values['new_status']; |
|
| 146 | - } |
|
| 144 | + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
| 145 | + $new_values['status'] = $values['new_status']; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - if ( ! empty( $new_values ) ) { |
|
| 148 | + if ( ! empty( $new_values ) ) { |
|
| 149 | 149 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) ); |
| 150 | - if ( $query_results ) { |
|
| 150 | + if ( $query_results ) { |
|
| 151 | 151 | self::clear_form_cache(); |
| 152 | - } |
|
| 153 | - } else { |
|
| 154 | - $query_results = true; |
|
| 155 | - } |
|
| 152 | + } |
|
| 153 | + } else { |
|
| 154 | + $query_results = true; |
|
| 155 | + } |
|
| 156 | 156 | unset( $new_values ); |
| 157 | 157 | |
| 158 | 158 | $values = self::update_fields( $id, $values ); |
@@ -160,16 +160,16 @@ discard block |
||
| 160 | 160 | do_action( 'frm_update_form', $id, $values ); |
| 161 | 161 | do_action( 'frm_update_form_' . $id, $values ); |
| 162 | 162 | |
| 163 | - return $query_results; |
|
| 164 | - } |
|
| 163 | + return $query_results; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * @return array |
|
| 168 | - */ |
|
| 166 | + /** |
|
| 167 | + * @return array |
|
| 168 | + */ |
|
| 169 | 169 | public static function set_update_options( $new_values, $values ) { |
| 170 | 170 | if ( ! isset( $values['options'] ) ) { |
| 171 | - return $new_values; |
|
| 172 | - } |
|
| 171 | + return $new_values; |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
| 175 | 175 | FrmFormsHelper::fill_form_options( $options, $values ); |
@@ -183,17 +183,17 @@ discard block |
||
| 183 | 183 | $new_values['options'] = serialize( $options ); |
| 184 | 184 | |
| 185 | 185 | return $new_values; |
| 186 | - } |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * @return array |
|
| 191 | - */ |
|
| 189 | + /** |
|
| 190 | + * @return array |
|
| 191 | + */ |
|
| 192 | 192 | public static function update_fields( $id, $values ) { |
| 193 | 193 | |
| 194 | 194 | if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) { |
| 195 | - return $values; |
|
| 196 | - } |
|
| 195 | + return $values; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | 198 | $all_fields = FrmField::get_all_for_form( $id ); |
| 199 | 199 | if ( empty( $all_fields ) ) { |
@@ -204,26 +204,26 @@ discard block |
||
| 204 | 204 | $values['item_meta'] = array(); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - $field_array = array(); |
|
| 208 | - $existing_keys = array_keys( $values['item_meta'] ); |
|
| 209 | - foreach ( $all_fields as $fid ) { |
|
| 207 | + $field_array = array(); |
|
| 208 | + $existing_keys = array_keys( $values['item_meta'] ); |
|
| 209 | + foreach ( $all_fields as $fid ) { |
|
| 210 | 210 | if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) { |
| 211 | 211 | $values['item_meta'][ $fid->id ] = ''; |
| 212 | - } |
|
| 212 | + } |
|
| 213 | 213 | $field_array[ $fid->id ] = $fid; |
| 214 | - } |
|
| 214 | + } |
|
| 215 | 215 | unset( $all_fields ); |
| 216 | 216 | |
| 217 | - foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
| 217 | + foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
| 218 | 218 | if ( isset( $field_array[ $field_id ] ) ) { |
| 219 | 219 | $field = $field_array[ $field_id ]; |
| 220 | - } else { |
|
| 220 | + } else { |
|
| 221 | 221 | $field = FrmField::getOne( $field_id ); |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - if ( ! $field ) { |
|
| 225 | - continue; |
|
| 226 | - } |
|
| 224 | + if ( ! $field ) { |
|
| 225 | + continue; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
| 229 | 229 | if ( $is_settings_page ) { |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | foreach ( $update_options as $opt => $default ) { |
| 243 | 243 | $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default; |
| 244 | 244 | self::sanitize_field_opt( $opt, $field->field_options[ $opt ] ); |
| 245 | - } |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | 247 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| 248 | 248 | $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
@@ -257,11 +257,11 @@ discard block |
||
| 257 | 257 | FrmField::update( $field_id, $new_field ); |
| 258 | 258 | |
| 259 | 259 | FrmField::delete_form_transient( $field->form_id ); |
| 260 | - } |
|
| 260 | + } |
|
| 261 | 261 | self::clear_form_cache(); |
| 262 | 262 | |
| 263 | - return $values; |
|
| 264 | - } |
|
| 263 | + return $values; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | private static function sanitize_field_opt( $opt, &$value ) { |
| 267 | 267 | if ( is_string( $value ) ) { |
@@ -328,21 +328,21 @@ discard block |
||
| 328 | 328 | return apply_filters( 'frm_form_strings', $strings, $form ); |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * @param string $status |
|
| 333 | - * @return int|boolean |
|
| 334 | - */ |
|
| 331 | + /** |
|
| 332 | + * @param string $status |
|
| 333 | + * @return int|boolean |
|
| 334 | + */ |
|
| 335 | 335 | public static function set_status( $id, $status ) { |
| 336 | - if ( 'trash' == $status ) { |
|
| 336 | + if ( 'trash' == $status ) { |
|
| 337 | 337 | return self::trash( $id ); |
| 338 | - } |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | 340 | $statuses = array( 'published', 'draft', 'trash' ); |
| 341 | - if ( ! in_array( $status, $statuses ) ) { |
|
| 342 | - return false; |
|
| 343 | - } |
|
| 341 | + if ( ! in_array( $status, $statuses ) ) { |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - global $wpdb; |
|
| 345 | + global $wpdb; |
|
| 346 | 346 | |
| 347 | 347 | if ( is_array( $id ) ) { |
| 348 | 348 | $where = array( |
@@ -354,33 +354,33 @@ discard block |
||
| 354 | 354 | array_unshift( $where['values'], $status ); |
| 355 | 355 | |
| 356 | 356 | $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok. |
| 357 | - } else { |
|
| 357 | + } else { |
|
| 358 | 358 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) ); |
| 359 | 359 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) ); |
| 360 | - } |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - if ( $query_results ) { |
|
| 362 | + if ( $query_results ) { |
|
| 363 | 363 | self::clear_form_cache(); |
| 364 | - } |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - return $query_results; |
|
| 367 | - } |
|
| 366 | + return $query_results; |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | - /** |
|
| 370 | - * @return int|boolean |
|
| 371 | - */ |
|
| 369 | + /** |
|
| 370 | + * @return int|boolean |
|
| 371 | + */ |
|
| 372 | 372 | public static function trash( $id ) { |
| 373 | - if ( ! EMPTY_TRASH_DAYS ) { |
|
| 374 | - return self::destroy( $id ); |
|
| 375 | - } |
|
| 373 | + if ( ! EMPTY_TRASH_DAYS ) { |
|
| 374 | + return self::destroy( $id ); |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | 377 | $form = self::getOne( $id ); |
| 378 | - if ( ! $form ) { |
|
| 379 | - return false; |
|
| 380 | - } |
|
| 378 | + if ( ! $form ) { |
|
| 379 | + return false; |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | - $options = $form->options; |
|
| 383 | - $options['trash_time'] = time(); |
|
| 382 | + $options = $form->options; |
|
| 383 | + $options['trash_time'] = time(); |
|
| 384 | 384 | |
| 385 | 385 | global $wpdb; |
| 386 | 386 | $query_results = $wpdb->update( |
@@ -405,39 +405,39 @@ discard block |
||
| 405 | 405 | ) |
| 406 | 406 | ); |
| 407 | 407 | |
| 408 | - if ( $query_results ) { |
|
| 408 | + if ( $query_results ) { |
|
| 409 | 409 | self::clear_form_cache(); |
| 410 | - } |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | - return $query_results; |
|
| 413 | - } |
|
| 412 | + return $query_results; |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | - /** |
|
| 416 | - * @return int|boolean |
|
| 417 | - */ |
|
| 415 | + /** |
|
| 416 | + * @return int|boolean |
|
| 417 | + */ |
|
| 418 | 418 | public static function destroy( $id ) { |
| 419 | - global $wpdb; |
|
| 419 | + global $wpdb; |
|
| 420 | 420 | |
| 421 | 421 | $form = self::getOne( $id ); |
| 422 | - if ( ! $form ) { |
|
| 423 | - return false; |
|
| 424 | - } |
|
| 422 | + if ( ! $form ) { |
|
| 423 | + return false; |
|
| 424 | + } |
|
| 425 | 425 | $id = $form->id; |
| 426 | 426 | |
| 427 | - // Disconnect the entries from this form |
|
| 427 | + // Disconnect the entries from this form |
|
| 428 | 428 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
| 429 | 429 | foreach ( $entries as $entry_id ) { |
| 430 | 430 | FrmEntry::destroy( $entry_id ); |
| 431 | 431 | unset( $entry_id ); |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - // Disconnect the fields from this form |
|
| 434 | + // Disconnect the fields from this form |
|
| 435 | 435 | $wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) ); |
| 436 | 436 | |
| 437 | 437 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
| 438 | - if ( $query_results ) { |
|
| 439 | - // Delete all form actions linked to this form |
|
| 440 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 438 | + if ( $query_results ) { |
|
| 439 | + // Delete all form actions linked to this form |
|
| 440 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 441 | 441 | $action_control->destroy( $id, 'all' ); |
| 442 | 442 | |
| 443 | 443 | // Clear form caching |
@@ -445,10 +445,10 @@ discard block |
||
| 445 | 445 | |
| 446 | 446 | do_action( 'frm_destroy_form', $id ); |
| 447 | 447 | do_action( 'frm_destroy_form_' . $id ); |
| 448 | - } |
|
| 448 | + } |
|
| 449 | 449 | |
| 450 | - return $query_results; |
|
| 451 | - } |
|
| 450 | + return $query_results; |
|
| 451 | + } |
|
| 452 | 452 | |
| 453 | 453 | /** |
| 454 | 454 | * Delete trashed forms based on how long they have been trashed |
@@ -481,48 +481,48 @@ discard block |
||
| 481 | 481 | return $count; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - /** |
|
| 485 | - * @return string form name |
|
| 486 | - */ |
|
| 487 | - public static function getName( $id ) { |
|
| 484 | + /** |
|
| 485 | + * @return string form name |
|
| 486 | + */ |
|
| 487 | + public static function getName( $id ) { |
|
| 488 | 488 | $form = FrmDb::check_cache( $id, 'frm_form' ); |
| 489 | - if ( $form ) { |
|
| 489 | + if ( $form ) { |
|
| 490 | 490 | $r = stripslashes( $form->name ); |
| 491 | - return $r; |
|
| 492 | - } |
|
| 491 | + return $r; |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | - $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
| 495 | - $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
| 494 | + $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
| 495 | + $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
| 496 | 496 | $r = stripslashes( $r ); |
| 497 | 497 | |
| 498 | - return $r; |
|
| 499 | - } |
|
| 498 | + return $r; |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | - /** |
|
| 501 | + /** |
|
| 502 | 502 | * @since 3.0 |
| 503 | - * @param string $key |
|
| 504 | - * @return int form id |
|
| 505 | - */ |
|
| 503 | + * @param string $key |
|
| 504 | + * @return int form id |
|
| 505 | + */ |
|
| 506 | 506 | public static function get_id_by_key( $key ) { |
| 507 | 507 | return (int) FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
| 508 | - } |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | - /** |
|
| 510 | + /** |
|
| 511 | 511 | * @since 3.0 |
| 512 | - * @param int $id |
|
| 513 | - * @return string form key |
|
| 514 | - */ |
|
| 512 | + * @param int $id |
|
| 513 | + * @return string form key |
|
| 514 | + */ |
|
| 515 | 515 | public static function get_key_by_id( $id ) { |
| 516 | - $id = (int) $id; |
|
| 516 | + $id = (int) $id; |
|
| 517 | 517 | $cache = FrmDb::check_cache( $id, 'frm_form' ); |
| 518 | - if ( $cache ) { |
|
| 519 | - return $cache->form_key; |
|
| 520 | - } |
|
| 518 | + if ( $cache ) { |
|
| 519 | + return $cache->form_key; |
|
| 520 | + } |
|
| 521 | 521 | |
| 522 | - $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
| 522 | + $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
| 523 | 523 | |
| 524 | - return $key; |
|
| 525 | - } |
|
| 524 | + return $key; |
|
| 525 | + } |
|
| 526 | 526 | |
| 527 | 527 | /** |
| 528 | 528 | * If $form is numeric, get the form object |
@@ -536,47 +536,47 @@ discard block |
||
| 536 | 536 | } |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - /** |
|
| 540 | - * @return object form |
|
| 541 | - */ |
|
| 542 | - public static function getOne( $id, $blog_id = false ) { |
|
| 543 | - global $wpdb; |
|
| 539 | + /** |
|
| 540 | + * @return object form |
|
| 541 | + */ |
|
| 542 | + public static function getOne( $id, $blog_id = false ) { |
|
| 543 | + global $wpdb; |
|
| 544 | 544 | |
| 545 | - if ( $blog_id && is_multisite() ) { |
|
| 546 | - global $wpmuBaseTablePrefix; |
|
| 545 | + if ( $blog_id && is_multisite() ) { |
|
| 546 | + global $wpmuBaseTablePrefix; |
|
| 547 | 547 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); |
| 548 | 548 | |
| 549 | 549 | $table_name = $prefix . 'frm_forms'; |
| 550 | - } else { |
|
| 550 | + } else { |
|
| 551 | 551 | $table_name = $wpdb->prefix . 'frm_forms'; |
| 552 | 552 | $cache = wp_cache_get( $id, 'frm_form' ); |
| 553 | - if ( $cache ) { |
|
| 553 | + if ( $cache ) { |
|
| 554 | 554 | if ( isset( $cache->options ) ) { |
| 555 | 555 | $cache->options = maybe_unserialize( $cache->options ); |
| 556 | - } |
|
| 556 | + } |
|
| 557 | 557 | |
| 558 | 558 | return stripslashes_deep( $cache ); |
| 559 | - } |
|
| 560 | - } |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | 561 | |
| 562 | 562 | if ( is_numeric( $id ) ) { |
| 563 | - $where = array( 'id' => $id ); |
|
| 564 | - } else { |
|
| 565 | - $where = array( 'form_key' => $id ); |
|
| 566 | - } |
|
| 563 | + $where = array( 'id' => $id ); |
|
| 564 | + } else { |
|
| 565 | + $where = array( 'form_key' => $id ); |
|
| 566 | + } |
|
| 567 | 567 | |
| 568 | - $results = FrmDb::get_row( $table_name, $where ); |
|
| 568 | + $results = FrmDb::get_row( $table_name, $where ); |
|
| 569 | 569 | |
| 570 | 570 | if ( isset( $results->options ) ) { |
| 571 | 571 | FrmDb::set_cache( $results->id, $results, 'frm_form' ); |
| 572 | 572 | $results->options = maybe_unserialize( $results->options ); |
| 573 | - } |
|
| 573 | + } |
|
| 574 | 574 | return stripslashes_deep( $results ); |
| 575 | - } |
|
| 575 | + } |
|
| 576 | 576 | |
| 577 | - /** |
|
| 578 | - * @return object|array of objects |
|
| 579 | - */ |
|
| 577 | + /** |
|
| 578 | + * @return object|array of objects |
|
| 579 | + */ |
|
| 580 | 580 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
| 581 | 581 | if ( is_array( $where ) && ! empty( $where ) ) { |
| 582 | 582 | if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) ) { |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | return stripslashes_deep( $results ); |
| 609 | - } |
|
| 609 | + } |
|
| 610 | 610 | |
| 611 | 611 | /** |
| 612 | 612 | * Get all published forms |
@@ -625,18 +625,18 @@ discard block |
||
| 625 | 625 | return $forms; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - /** |
|
| 629 | - * @return object count of forms |
|
| 630 | - */ |
|
| 631 | - public static function get_count() { |
|
| 632 | - global $wpdb; |
|
| 628 | + /** |
|
| 629 | + * @return object count of forms |
|
| 630 | + */ |
|
| 631 | + public static function get_count() { |
|
| 632 | + global $wpdb; |
|
| 633 | 633 | |
| 634 | - $cache_key = 'frm_form_counts'; |
|
| 634 | + $cache_key = 'frm_form_counts'; |
|
| 635 | 635 | |
| 636 | - $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
| 637 | - if ( false !== $counts ) { |
|
| 638 | - return $counts; |
|
| 639 | - } |
|
| 636 | + $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
| 637 | + if ( false !== $counts ) { |
|
| 638 | + return $counts; |
|
| 639 | + } |
|
| 640 | 640 | |
| 641 | 641 | $results = (array) FrmDb::get_results( |
| 642 | 642 | 'frm_forms', |
@@ -649,31 +649,31 @@ discard block |
||
| 649 | 649 | ); |
| 650 | 650 | |
| 651 | 651 | $statuses = array( 'published', 'draft', 'template', 'trash' ); |
| 652 | - $counts = array_fill_keys( $statuses, 0 ); |
|
| 652 | + $counts = array_fill_keys( $statuses, 0 ); |
|
| 653 | 653 | |
| 654 | - foreach ( $results as $row ) { |
|
| 655 | - if ( 'trash' != $row->status ) { |
|
| 656 | - if ( $row->is_template ) { |
|
| 654 | + foreach ( $results as $row ) { |
|
| 655 | + if ( 'trash' != $row->status ) { |
|
| 656 | + if ( $row->is_template ) { |
|
| 657 | 657 | $counts['template']++; |
| 658 | - } else { |
|
| 658 | + } else { |
|
| 659 | 659 | $counts['published']++; |
| 660 | - } |
|
| 661 | - } else { |
|
| 660 | + } |
|
| 661 | + } else { |
|
| 662 | 662 | $counts['trash']++; |
| 663 | - } |
|
| 663 | + } |
|
| 664 | 664 | |
| 665 | - if ( 'draft' == $row->status ) { |
|
| 665 | + if ( 'draft' == $row->status ) { |
|
| 666 | 666 | $counts['draft']++; |
| 667 | - } |
|
| 667 | + } |
|
| 668 | 668 | |
| 669 | 669 | unset( $row ); |
| 670 | - } |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | - $counts = (object) $counts; |
|
| 672 | + $counts = (object) $counts; |
|
| 673 | 673 | FrmDb::set_cache( $cache_key, $counts, 'frm_form' ); |
| 674 | 674 | |
| 675 | - return $counts; |
|
| 676 | - } |
|
| 675 | + return $counts; |
|
| 676 | + } |
|
| 677 | 677 | |
| 678 | 678 | /** |
| 679 | 679 | * Clear form caching |
@@ -686,14 +686,14 @@ discard block |
||
| 686 | 686 | FrmDb::cache_delete_group( 'frm_form' ); |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | - /** |
|
| 690 | - * @return array of errors |
|
| 691 | - */ |
|
| 689 | + /** |
|
| 690 | + * @return array of errors |
|
| 691 | + */ |
|
| 692 | 692 | public static function validate( $values ) { |
| 693 | - $errors = array(); |
|
| 693 | + $errors = array(); |
|
| 694 | 694 | |
| 695 | 695 | return apply_filters( 'frm_validate_form', $errors, $values ); |
| 696 | - } |
|
| 696 | + } |
|
| 697 | 697 | |
| 698 | 698 | public static function get_params( $form = null ) { |
| 699 | 699 | global $frm_vars; |
@@ -1,33 +1,33 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmSettings { |
| 4 | - public $option_name = 'frm_options'; |
|
| 5 | - public $menu; |
|
| 6 | - public $mu_menu; |
|
| 7 | - public $use_html; |
|
| 8 | - public $jquery_css; |
|
| 9 | - public $accordion_js; |
|
| 4 | + public $option_name = 'frm_options'; |
|
| 5 | + public $menu; |
|
| 6 | + public $mu_menu; |
|
| 7 | + public $use_html; |
|
| 8 | + public $jquery_css; |
|
| 9 | + public $accordion_js; |
|
| 10 | 10 | public $fade_form; |
| 11 | 11 | public $old_css; |
| 12 | 12 | |
| 13 | - public $success_msg; |
|
| 14 | - public $blank_msg; |
|
| 15 | - public $unique_msg; |
|
| 16 | - public $invalid_msg; |
|
| 17 | - public $failed_msg; |
|
| 18 | - public $submit_value; |
|
| 19 | - public $login_msg; |
|
| 20 | - public $admin_permission; |
|
| 21 | - |
|
| 22 | - public $email_to; |
|
| 23 | - public $load_style; |
|
| 24 | - public $custom_style; |
|
| 25 | - |
|
| 26 | - public $pubkey; |
|
| 27 | - public $privkey; |
|
| 28 | - public $re_lang; |
|
| 13 | + public $success_msg; |
|
| 14 | + public $blank_msg; |
|
| 15 | + public $unique_msg; |
|
| 16 | + public $invalid_msg; |
|
| 17 | + public $failed_msg; |
|
| 18 | + public $submit_value; |
|
| 19 | + public $login_msg; |
|
| 20 | + public $admin_permission; |
|
| 21 | + |
|
| 22 | + public $email_to; |
|
| 23 | + public $load_style; |
|
| 24 | + public $custom_style; |
|
| 25 | + |
|
| 26 | + public $pubkey; |
|
| 27 | + public $privkey; |
|
| 28 | + public $re_lang; |
|
| 29 | 29 | public $re_type; |
| 30 | - public $re_msg; |
|
| 30 | + public $re_msg; |
|
| 31 | 31 | public $re_multi; |
| 32 | 32 | |
| 33 | 33 | public $no_ips; |
@@ -45,20 +45,20 @@ discard block |
||
| 45 | 45 | $settings = $this->translate_settings( $settings ); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - foreach ( $settings as $setting_name => $setting ) { |
|
| 49 | - $this->{$setting_name} = $setting; |
|
| 48 | + foreach ( $settings as $setting_name => $setting ) { |
|
| 49 | + $this->{$setting_name} = $setting; |
|
| 50 | 50 | unset( $setting_name, $setting ); |
| 51 | - } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $this->set_default_options(); |
|
| 53 | + $this->set_default_options(); |
|
| 54 | 54 | |
| 55 | 55 | $this->maybe_filter_for_form( $args ); |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | private function translate_settings( $settings ) { |
| 59 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
| 59 | + if ( $settings ) { //workaround for W3 total cache conflict |
|
| 60 | 60 | return unserialize( serialize( $settings ) ); |
| 61 | - } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | $settings = get_option( $this->option_name ); |
| 64 | 64 | if ( is_object( $settings ) ) { |
@@ -66,98 +66,98 @@ discard block |
||
| 66 | 66 | return $settings; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - // If unserializing didn't work |
|
| 70 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
| 69 | + // If unserializing didn't work |
|
| 70 | + if ( $settings ) { //workaround for W3 total cache conflict |
|
| 71 | 71 | $settings = unserialize( serialize( $settings ) ); |
| 72 | - } else { |
|
| 73 | - $settings = $this; |
|
| 74 | - } |
|
| 72 | + } else { |
|
| 73 | + $settings = $this; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | update_option( $this->option_name, $settings ); |
| 77 | 77 | set_transient( $this->option_name, $settings ); |
| 78 | 78 | |
| 79 | - return $settings; |
|
| 80 | - } |
|
| 79 | + return $settings; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 82 | + /** |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | 85 | public function default_options() { |
| 86 | - return array( |
|
| 87 | - 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ), |
|
| 88 | - 'mu_menu' => 0, |
|
| 89 | - 'use_html' => true, |
|
| 90 | - 'jquery_css' => false, |
|
| 91 | - 'accordion_js' => false, |
|
| 86 | + return array( |
|
| 87 | + 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ), |
|
| 88 | + 'mu_menu' => 0, |
|
| 89 | + 'use_html' => true, |
|
| 90 | + 'jquery_css' => false, |
|
| 91 | + 'accordion_js' => false, |
|
| 92 | 92 | 'fade_form' => false, |
| 93 | 93 | 'old_css' => true, |
| 94 | 94 | |
| 95 | 95 | 're_multi' => 0, |
| 96 | 96 | |
| 97 | - 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ), |
|
| 98 | - 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ), |
|
| 99 | - 'unique_msg' => __( 'This value must be unique.', 'formidable' ), |
|
| 100 | - 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ), |
|
| 101 | - 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ), |
|
| 102 | - 'submit_value' => __( 'Submit', 'formidable' ), |
|
| 103 | - 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ), |
|
| 104 | - 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ), |
|
| 97 | + 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ), |
|
| 98 | + 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ), |
|
| 99 | + 'unique_msg' => __( 'This value must be unique.', 'formidable' ), |
|
| 100 | + 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ), |
|
| 101 | + 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ), |
|
| 102 | + 'submit_value' => __( 'Submit', 'formidable' ), |
|
| 103 | + 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ), |
|
| 104 | + 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ), |
|
| 105 | 105 | |
| 106 | - 'email_to' => '[admin_email]', |
|
| 106 | + 'email_to' => '[admin_email]', |
|
| 107 | 107 | 'no_ips' => 0, |
| 108 | 108 | 'tracking' => FrmAppHelper::pro_is_installed(), |
| 109 | - ); |
|
| 110 | - } |
|
| 109 | + ); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | 112 | private function set_default_options() { |
| 113 | - $this->fill_recaptcha_settings(); |
|
| 113 | + $this->fill_recaptcha_settings(); |
|
| 114 | 114 | |
| 115 | 115 | if ( ! isset( $this->load_style ) ) { |
| 116 | 116 | if ( ! isset( $this->custom_style ) ) { |
| 117 | - $this->custom_style = true; |
|
| 118 | - } |
|
| 117 | + $this->custom_style = true; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - $this->load_style = 'all'; |
|
| 121 | - } |
|
| 120 | + $this->load_style = 'all'; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - $this->fill_with_defaults(); |
|
| 123 | + $this->fill_with_defaults(); |
|
| 124 | 124 | |
| 125 | - if ( is_multisite() && is_admin() ) { |
|
| 125 | + if ( is_multisite() && is_admin() ) { |
|
| 126 | 126 | $mu_menu = get_site_option( 'frm_admin_menu_name' ); |
| 127 | 127 | if ( $mu_menu && ! empty( $mu_menu ) ) { |
| 128 | - $this->menu = $mu_menu; |
|
| 129 | - $this->mu_menu = 1; |
|
| 130 | - } |
|
| 131 | - } |
|
| 128 | + $this->menu = $mu_menu; |
|
| 129 | + $this->mu_menu = 1; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | 133 | $frm_roles = FrmAppHelper::frm_capabilities( 'pro' ); |
| 134 | 134 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 135 | 135 | if ( ! isset( $this->$frm_role ) ) { |
| 136 | - $this->$frm_role = 'administrator'; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - } |
|
| 136 | + $this->$frm_role = 'administrator'; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | public function fill_with_defaults( $params = array() ) { |
| 142 | - $settings = $this->default_options(); |
|
| 142 | + $settings = $this->default_options(); |
|
| 143 | 143 | |
| 144 | - foreach ( $settings as $setting => $default ) { |
|
| 144 | + foreach ( $settings as $setting => $default ) { |
|
| 145 | 145 | if ( isset( $params[ 'frm_' . $setting ] ) ) { |
| 146 | 146 | $this->{$setting} = $params[ 'frm_' . $setting ]; |
| 147 | 147 | } elseif ( ! isset( $this->{$setting} ) ) { |
| 148 | - $this->{$setting} = $default; |
|
| 149 | - } |
|
| 148 | + $this->{$setting} = $default; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | 151 | if ( $setting == 'menu' && empty( $this->{$setting} ) ) { |
| 152 | 152 | $this->{$setting} = $default; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | unset( $setting, $default ); |
| 156 | - } |
|
| 157 | - } |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - private function fill_recaptcha_settings() { |
|
| 160 | - $privkey = ''; |
|
| 159 | + private function fill_recaptcha_settings() { |
|
| 160 | + $privkey = ''; |
|
| 161 | 161 | $re_lang = ''; |
| 162 | 162 | |
| 163 | 163 | if ( ! isset( $this->pubkey ) ) { |
@@ -169,21 +169,21 @@ discard block |
||
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) { |
| 172 | - $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' ); |
|
| 173 | - } |
|
| 172 | + $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' ); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | if ( ! isset( $this->privkey ) ) { |
| 176 | - $this->privkey = $privkey; |
|
| 177 | - } |
|
| 176 | + $this->privkey = $privkey; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | if ( ! isset( $this->re_lang ) ) { |
| 180 | - $this->re_lang = $re_lang; |
|
| 181 | - } |
|
| 180 | + $this->re_lang = $re_lang; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | if ( ! isset( $this->re_type ) ) { |
| 184 | 184 | $this->re_type = ''; |
| 185 | 185 | } |
| 186 | - } |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | /** |
| 189 | 189 | * Get values that may be shown on the front-end without an override in the form settings. |
@@ -213,9 +213,9 @@ discard block |
||
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - public function validate( $params, $errors ) { |
|
| 217 | - return apply_filters( 'frm_validate_settings', $errors, $params ); |
|
| 218 | - } |
|
| 216 | + public function validate( $params, $errors ) { |
|
| 217 | + return apply_filters( 'frm_validate_settings', $errors, $params ); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | 220 | public function update( $params ) { |
| 221 | 221 | $this->fill_with_defaults( $params ); |
@@ -229,51 +229,51 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | $this->update_roles( $params ); |
| 231 | 231 | |
| 232 | - do_action( 'frm_update_settings', $params ); |
|
| 232 | + do_action( 'frm_update_settings', $params ); |
|
| 233 | 233 | |
| 234 | 234 | if ( function_exists( 'get_filesystem_method' ) ) { |
| 235 | 235 | // save styling settings in case fallback setting changes |
| 236 | 236 | $frm_style = new FrmStyle(); |
| 237 | 237 | $frm_style->update( 'default' ); |
| 238 | 238 | } |
| 239 | - } |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | 241 | private function update_settings( $params ) { |
| 242 | 242 | $this->pubkey = trim( $params['frm_pubkey'] ); |
| 243 | - $this->privkey = $params['frm_privkey']; |
|
| 243 | + $this->privkey = $params['frm_privkey']; |
|
| 244 | 244 | $this->re_type = $params['frm_re_type']; |
| 245 | - $this->re_lang = $params['frm_re_lang']; |
|
| 245 | + $this->re_lang = $params['frm_re_lang']; |
|
| 246 | 246 | |
| 247 | - $this->load_style = $params['frm_load_style']; |
|
| 247 | + $this->load_style = $params['frm_load_style']; |
|
| 248 | 248 | |
| 249 | 249 | $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'old_css', 'no_ips', 'tracking' ); |
| 250 | 250 | foreach ( $checkboxes as $set ) { |
| 251 | 251 | $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0; |
| 252 | 252 | } |
| 253 | - } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | 255 | private function update_roles( $params ) { |
| 256 | - global $wp_roles; |
|
| 256 | + global $wp_roles; |
|
| 257 | 257 | |
| 258 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 259 | - $roles = get_editable_roles(); |
|
| 260 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 261 | - $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
|
| 258 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 259 | + $roles = get_editable_roles(); |
|
| 260 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 261 | + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
|
| 262 | 262 | |
| 263 | - // Make sure administrators always have permissions |
|
| 264 | - if ( ! in_array( 'administrator', $this->$frm_role ) ) { |
|
| 263 | + // Make sure administrators always have permissions |
|
| 264 | + if ( ! in_array( 'administrator', $this->$frm_role ) ) { |
|
| 265 | 265 | array_push( $this->$frm_role, 'administrator' ); |
| 266 | - } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - foreach ( $roles as $role => $details ) { |
|
| 268 | + foreach ( $roles as $role => $details ) { |
|
| 269 | 269 | if ( in_array( $role, $this->$frm_role ) ) { |
| 270 | - $wp_roles->add_cap( $role, $frm_role ); |
|
| 271 | - } else { |
|
| 272 | - $wp_roles->remove_cap( $role, $frm_role ); |
|
| 273 | - } |
|
| 274 | - } |
|
| 270 | + $wp_roles->add_cap( $role, $frm_role ); |
|
| 271 | + } else { |
|
| 272 | + $wp_roles->remove_cap( $role, $frm_role ); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | 275 | } |
| 276 | - } |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | 278 | public function store() { |
| 279 | 279 | // Save the posted value in the database |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | $settings = $this->default_options(); |
| 143 | 143 | |
| 144 | 144 | foreach ( $settings as $setting => $default ) { |
| 145 | - if ( isset( $params[ 'frm_' . $setting ] ) ) { |
|
| 146 | - $this->{$setting} = $params[ 'frm_' . $setting ]; |
|
| 145 | + if ( isset( $params['frm_' . $setting] ) ) { |
|
| 146 | + $this->{$setting} = $params['frm_' . $setting]; |
|
| 147 | 147 | } elseif ( ! isset( $this->{$setting} ) ) { |
| 148 | 148 | $this->{$setting} = $default; |
| 149 | 149 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'old_css', 'no_ips', 'tracking' ); |
| 250 | 250 | foreach ( $checkboxes as $set ) { |
| 251 | - $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0; |
|
| 251 | + $this->$set = isset( $params['frm_' . $set] ) ? $params['frm_' . $set] : 0; |
|
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | $frm_roles = FrmAppHelper::frm_capabilities(); |
| 259 | 259 | $roles = get_editable_roles(); |
| 260 | 260 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 261 | - $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
|
| 261 | + $this->$frm_role = (array) ( isset( $params[$frm_role] ) ? $params[$frm_role] : 'administrator' ); |
|
| 262 | 262 | |
| 263 | 263 | // Make sure administrators always have permissions |
| 264 | 264 | if ( ! in_array( 'administrator', $this->$frm_role ) ) { |
@@ -6,11 +6,11 @@ discard block |
||
| 6 | 6 | class FrmEntry { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * Create a new entry |
|
| 10 | - * |
|
| 11 | - * @param array $values |
|
| 12 | - * @return int | boolean $entry_id |
|
| 13 | - */ |
|
| 9 | + * Create a new entry |
|
| 10 | + * |
|
| 11 | + * @param array $values |
|
| 12 | + * @return int | boolean $entry_id |
|
| 13 | + */ |
|
| 14 | 14 | public static function create( $values ) { |
| 15 | 15 | $entry_id = self::create_entry( $values, 'standard' ); |
| 16 | 16 | |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | - * Create a new entry with some differences depending on type |
|
| 22 | - * |
|
| 23 | - * @param array $values |
|
| 24 | - * @param string $type |
|
| 25 | - * @return int | boolean $entry_id |
|
| 26 | - */ |
|
| 21 | + * Create a new entry with some differences depending on type |
|
| 22 | + * |
|
| 23 | + * @param array $values |
|
| 24 | + * @param string $type |
|
| 25 | + * @return int | boolean $entry_id |
|
| 26 | + */ |
|
| 27 | 27 | private static function create_entry( $values, $type ) { |
| 28 | 28 | $new_values = self::before_insert_entry_in_database( $values, $type ); |
| 29 | 29 | |
@@ -49,40 +49,40 @@ discard block |
||
| 49 | 49 | return false; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - $check_val = $new_values; |
|
| 52 | + $check_val = $new_values; |
|
| 53 | 53 | $check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) ); |
| 54 | 54 | |
| 55 | 55 | unset( $check_val['created_at'], $check_val['updated_at'] ); |
| 56 | 56 | unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
| 57 | 57 | |
| 58 | - if ( $new_values['item_key'] == $new_values['name'] ) { |
|
| 58 | + if ( $new_values['item_key'] == $new_values['name'] ) { |
|
| 59 | 59 | unset( $check_val['name'] ); |
| 60 | - } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - global $wpdb; |
|
| 62 | + global $wpdb; |
|
| 63 | 63 | $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) ); |
| 64 | 64 | |
| 65 | 65 | if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) { |
| 66 | - return false; |
|
| 67 | - } |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $is_duplicate = false; |
|
| 70 | - foreach ( $entry_exists as $entry_exist ) { |
|
| 71 | - $is_duplicate = true; |
|
| 69 | + $is_duplicate = false; |
|
| 70 | + foreach ( $entry_exists as $entry_exist ) { |
|
| 71 | + $is_duplicate = true; |
|
| 72 | 72 | |
| 73 | 73 | // make sure it's a duplicate |
| 74 | 74 | $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist ); |
| 75 | - $field_metas = array(); |
|
| 76 | - foreach ( $metas as $meta ) { |
|
| 75 | + $field_metas = array(); |
|
| 76 | + foreach ( $metas as $meta ) { |
|
| 77 | 77 | $field_metas[ $meta->field_id ] = $meta->meta_value; |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // If prev entry is empty and current entry is not, they are not duplicates |
|
| 81 | - $filtered_vals = array_filter( $values['item_meta'] ); |
|
| 80 | + // If prev entry is empty and current entry is not, they are not duplicates |
|
| 81 | + $filtered_vals = array_filter( $values['item_meta'] ); |
|
| 82 | 82 | $field_metas = array_filter( $field_metas ); |
| 83 | - if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 83 | + if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | // compare serialized values and not arrays |
| 88 | 88 | $new_meta = array_map( 'maybe_serialize', $filtered_vals ); |
@@ -99,20 +99,20 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $diff = array_diff_assoc( $field_metas, $new_meta ); |
| 102 | - foreach ( $diff as $field_id => $meta_value ) { |
|
| 102 | + foreach ( $diff as $field_id => $meta_value ) { |
|
| 103 | 103 | if ( ! empty( $meta_value ) ) { |
| 104 | - $is_duplicate = false; |
|
| 105 | - continue; |
|
| 106 | - } |
|
| 107 | - } |
|
| 104 | + $is_duplicate = false; |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - if ( $is_duplicate ) { |
|
| 109 | + if ( $is_duplicate ) { |
|
| 110 | 110 | break; |
| 111 | - } |
|
| 112 | - } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return $is_duplicate; |
|
| 115 | - } |
|
| 114 | + return $is_duplicate; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * Determine if an entry needs to be checked as a possible duplicate |
@@ -157,32 +157,32 @@ discard block |
||
| 157 | 157 | $new_values['updated_at'] = $new_values['created_at']; |
| 158 | 158 | |
| 159 | 159 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values ); |
| 160 | - if ( ! $query_results ) { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 160 | + if ( ! $query_results ) { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - $entry_id = $wpdb->insert_id; |
|
| 164 | + $entry_id = $wpdb->insert_id; |
|
| 165 | 165 | |
| 166 | - global $frm_vars; |
|
| 166 | + global $frm_vars; |
|
| 167 | 167 | if ( ! isset( $frm_vars['saved_entries'] ) ) { |
| 168 | - $frm_vars['saved_entries'] = array(); |
|
| 169 | - } |
|
| 170 | - $frm_vars['saved_entries'][] = (int) $entry_id; |
|
| 168 | + $frm_vars['saved_entries'] = array(); |
|
| 169 | + } |
|
| 170 | + $frm_vars['saved_entries'][] = (int) $entry_id; |
|
| 171 | 171 | |
| 172 | 172 | FrmEntryMeta::duplicate_entry_metas( $id, $entry_id ); |
| 173 | 173 | self::clear_cache(); |
| 174 | 174 | |
| 175 | 175 | do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) ); |
| 176 | - return $entry_id; |
|
| 177 | - } |
|
| 176 | + return $entry_id; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | - * Update an entry (not via XML) |
|
| 181 | - * |
|
| 182 | - * @param int $id |
|
| 183 | - * @param array $values |
|
| 184 | - * @return boolean|int $update_results |
|
| 185 | - */ |
|
| 180 | + * Update an entry (not via XML) |
|
| 181 | + * |
|
| 182 | + * @param int $id |
|
| 183 | + * @param array $values |
|
| 184 | + * @return boolean|int $update_results |
|
| 185 | + */ |
|
| 186 | 186 | public static function update( $id, $values ) { |
| 187 | 187 | $update_results = self::update_entry( $id, $values, 'standard' ); |
| 188 | 188 | |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
| 193 | - * Update an entry with some differences depending on the update type |
|
| 194 | - * |
|
| 195 | - * @since 2.0.16 |
|
| 196 | - * |
|
| 197 | - * @param int $id |
|
| 198 | - * @param array $values |
|
| 199 | - * @return boolean|int $query_results |
|
| 200 | - */ |
|
| 193 | + * Update an entry with some differences depending on the update type |
|
| 194 | + * |
|
| 195 | + * @since 2.0.16 |
|
| 196 | + * |
|
| 197 | + * @param int $id |
|
| 198 | + * @param array $values |
|
| 199 | + * @return boolean|int $query_results |
|
| 200 | + */ |
|
| 201 | 201 | private static function update_entry( $id, $values, $update_type ) { |
| 202 | 202 | global $wpdb; |
| 203 | 203 | |
@@ -216,14 +216,14 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | public static function destroy( $id ) { |
| 219 | - global $wpdb; |
|
| 220 | - $id = (int) $id; |
|
| 219 | + global $wpdb; |
|
| 220 | + $id = (int) $id; |
|
| 221 | 221 | |
| 222 | 222 | $entry = self::getOne( $id ); |
| 223 | - if ( ! $entry ) { |
|
| 224 | - $result = false; |
|
| 225 | - return $result; |
|
| 226 | - } |
|
| 223 | + if ( ! $entry ) { |
|
| 224 | + $result = false; |
|
| 225 | + return $result; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | do_action( 'frm_before_destroy_entry', $id, $entry ); |
| 229 | 229 | |
@@ -232,18 +232,18 @@ discard block |
||
| 232 | 232 | |
| 233 | 233 | self::clear_cache(); |
| 234 | 234 | |
| 235 | - return $result; |
|
| 236 | - } |
|
| 235 | + return $result; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | 238 | public static function update_form( $id, $value, $form_id ) { |
| 239 | - global $wpdb; |
|
| 239 | + global $wpdb; |
|
| 240 | 240 | $form_id = isset( $value ) ? $form_id : null; |
| 241 | 241 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
| 242 | 242 | if ( $result ) { |
| 243 | 243 | self::clear_cache(); |
| 244 | 244 | } |
| 245 | - return $result; |
|
| 246 | - } |
|
| 245 | + return $result; |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | 248 | /** |
| 249 | 249 | * Clear entry caching |
@@ -287,19 +287,19 @@ discard block |
||
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | public static function getOne( $id, $meta = false ) { |
| 290 | - global $wpdb; |
|
| 290 | + global $wpdb; |
|
| 291 | 291 | |
| 292 | - $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
| 292 | + $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
| 293 | 293 | LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE "; |
| 294 | 294 | |
| 295 | 295 | $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s'; |
| 296 | - $query_args = array( $id ); |
|
| 297 | - $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok. |
|
| 296 | + $query_args = array( $id ); |
|
| 297 | + $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok. |
|
| 298 | 298 | |
| 299 | - if ( ! $meta ) { |
|
| 299 | + if ( ! $meta ) { |
|
| 300 | 300 | $entry = FrmDb::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' ); |
| 301 | 301 | return stripslashes_deep( $entry ); |
| 302 | - } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | 304 | $entry = FrmDb::check_cache( $id, 'frm_entry' ); |
| 305 | 305 | if ( $entry !== false ) { |
@@ -310,14 +310,14 @@ discard block |
||
| 310 | 310 | $entry = self::get_meta( $entry ); |
| 311 | 311 | |
| 312 | 312 | return stripslashes_deep( $entry ); |
| 313 | - } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | public static function get_meta( $entry ) { |
| 316 | - if ( ! $entry ) { |
|
| 317 | - return $entry; |
|
| 318 | - } |
|
| 316 | + if ( ! $entry ) { |
|
| 317 | + return $entry; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - global $wpdb; |
|
| 320 | + global $wpdb; |
|
| 321 | 321 | $metas = FrmDb::get_results( |
| 322 | 322 | $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', |
| 323 | 323 | array( |
@@ -327,56 +327,56 @@ discard block |
||
| 327 | 327 | 'field_id, meta_value, field_key, item_id' |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | - $entry->metas = array(); |
|
| 330 | + $entry->metas = array(); |
|
| 331 | 331 | |
| 332 | 332 | $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) ); |
| 333 | - foreach ( $metas as $meta_val ) { |
|
| 334 | - if ( $meta_val->item_id == $entry->id ) { |
|
| 333 | + foreach ( $metas as $meta_val ) { |
|
| 334 | + if ( $meta_val->item_id == $entry->id ) { |
|
| 335 | 335 | $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
| 336 | 336 | if ( $include_key ) { |
| 337 | 337 | $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
| 338 | 338 | } |
| 339 | - continue; |
|
| 340 | - } |
|
| 339 | + continue; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - // include sub entries in an array |
|
| 342 | + // include sub entries in an array |
|
| 343 | 343 | if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
| 344 | 344 | $entry->metas[ $meta_val->field_id ] = array(); |
| 345 | - } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | 347 | $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
| 348 | 348 | |
| 349 | 349 | unset( $meta_val ); |
| 350 | - } |
|
| 350 | + } |
|
| 351 | 351 | unset( $metas ); |
| 352 | 352 | |
| 353 | 353 | FrmDb::set_cache( $entry->id, $entry, 'frm_entry' ); |
| 354 | 354 | |
| 355 | - return $entry; |
|
| 356 | - } |
|
| 355 | + return $entry; |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * @param string $id |
|
| 360 | - */ |
|
| 358 | + /** |
|
| 359 | + * @param string $id |
|
| 360 | + */ |
|
| 361 | 361 | public static function exists( $id ) { |
| 362 | - global $wpdb; |
|
| 362 | + global $wpdb; |
|
| 363 | 363 | |
| 364 | - if ( FrmDb::check_cache( $id, 'frm_entry' ) ) { |
|
| 365 | - $exists = true; |
|
| 366 | - return $exists; |
|
| 367 | - } |
|
| 364 | + if ( FrmDb::check_cache( $id, 'frm_entry' ) ) { |
|
| 365 | + $exists = true; |
|
| 366 | + return $exists; |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | 369 | if ( is_numeric( $id ) ) { |
| 370 | - $where = array( 'id' => $id ); |
|
| 371 | - } else { |
|
| 372 | - $where = array( 'item_key' => $id ); |
|
| 373 | - } |
|
| 370 | + $where = array( 'id' => $id ); |
|
| 371 | + } else { |
|
| 372 | + $where = array( 'item_key' => $id ); |
|
| 373 | + } |
|
| 374 | 374 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
| 375 | 375 | |
| 376 | 376 | return ( $id && $id > 0 ); |
| 377 | - } |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
| 379 | + public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
| 380 | 380 | global $wpdb; |
| 381 | 381 | |
| 382 | 382 | $limit = FrmDb::esc_limit( $limit ); |
@@ -384,21 +384,21 @@ discard block |
||
| 384 | 384 | $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form; |
| 385 | 385 | $entries = wp_cache_get( $cache_key, 'frm_entry' ); |
| 386 | 386 | |
| 387 | - if ( false === $entries ) { |
|
| 388 | - $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
| 387 | + if ( false === $entries ) { |
|
| 388 | + $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
| 389 | 389 | $table = $wpdb->prefix . 'frm_items it '; |
| 390 | 390 | |
| 391 | - if ( $inc_form ) { |
|
| 392 | - $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
| 393 | - $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
| 394 | - } |
|
| 391 | + if ( $inc_form ) { |
|
| 392 | + $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
| 393 | + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
| 397 | - // sort by a requested field |
|
| 398 | - $field_id = (int) $order_matches[1]; |
|
| 396 | + if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
| 397 | + // sort by a requested field |
|
| 398 | + $field_id = (int) $order_matches[1]; |
|
| 399 | 399 | $fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id; |
| 400 | 400 | unset( $order_matches, $field_id ); |
| 401 | - } |
|
| 401 | + } |
|
| 402 | 402 | |
| 403 | 403 | // prepare the query |
| 404 | 404 | $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
@@ -407,45 +407,45 @@ discard block |
||
| 407 | 407 | unset( $query ); |
| 408 | 408 | |
| 409 | 409 | FrmDb::set_cache( $cache_key, $entries, 'frm_entry' ); |
| 410 | - } |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | - if ( ! $meta || ! $entries ) { |
|
| 412 | + if ( ! $meta || ! $entries ) { |
|
| 413 | 413 | return stripslashes_deep( $entries ); |
| 414 | - } |
|
| 414 | + } |
|
| 415 | 415 | unset( $meta ); |
| 416 | 416 | |
| 417 | 417 | if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) { |
| 418 | 418 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
| 419 | - } |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - $meta_where = array( 'field_id !' => 0 ); |
|
| 421 | + $meta_where = array( 'field_id !' => 0 ); |
|
| 422 | 422 | if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) { |
| 423 | - $meta_where['fi.form_id'] = $where['it.form_id']; |
|
| 424 | - } else { |
|
| 425 | - $meta_where['item_id'] = array_keys( $entries ); |
|
| 426 | - } |
|
| 423 | + $meta_where['fi.form_id'] = $where['it.form_id']; |
|
| 424 | + } else { |
|
| 425 | + $meta_where['item_id'] = array_keys( $entries ); |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | - $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
| 428 | + $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
| 429 | 429 | |
| 430 | - unset( $meta_where ); |
|
| 430 | + unset( $meta_where ); |
|
| 431 | 431 | |
| 432 | - if ( ! $metas ) { |
|
| 432 | + if ( ! $metas ) { |
|
| 433 | 433 | return stripslashes_deep( $entries ); |
| 434 | - } |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - foreach ( $metas as $m_key => $meta_val ) { |
|
| 437 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
| 438 | - continue; |
|
| 439 | - } |
|
| 436 | + foreach ( $metas as $m_key => $meta_val ) { |
|
| 437 | + if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
| 438 | + continue; |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
| 441 | + if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
| 442 | 442 | $entries[ $meta_val->item_id ]->metas = array(); |
| 443 | - } |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | 445 | $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
| 446 | 446 | |
| 447 | 447 | unset( $m_key, $meta_val ); |
| 448 | - } |
|
| 448 | + } |
|
| 449 | 449 | |
| 450 | 450 | if ( ! FrmAppHelper::prevent_caching() ) { |
| 451 | 451 | foreach ( $entries as $entry ) { |
@@ -455,33 +455,33 @@ discard block |
||
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | return stripslashes_deep( $entries ); |
| 458 | - } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - // Pagination Methods |
|
| 460 | + // Pagination Methods |
|
| 461 | 461 | /** |
| 462 | 462 | * @param int|array|string If int, use the form id. |
| 463 | 463 | */ |
| 464 | - public static function getRecordCount( $where = '' ) { |
|
| 465 | - global $wpdb; |
|
| 464 | + public static function getRecordCount( $where = '' ) { |
|
| 465 | + global $wpdb; |
|
| 466 | 466 | $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; |
| 467 | 467 | |
| 468 | 468 | if ( is_numeric( $where ) ) { |
| 469 | - $table_join = 'frm_items'; |
|
| 470 | - $where = array( 'form_id' => $where ); |
|
| 471 | - } |
|
| 469 | + $table_join = 'frm_items'; |
|
| 470 | + $where = array( 'form_id' => $where ); |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - if ( is_array( $where ) ) { |
|
| 474 | - $count = FrmDb::get_count( $table_join, $where ); |
|
| 475 | - } else { |
|
| 473 | + if ( is_array( $where ) ) { |
|
| 474 | + $count = FrmDb::get_count( $table_join, $where ); |
|
| 475 | + } else { |
|
| 476 | 476 | $cache_key = 'count_' . maybe_serialize( $where ); |
| 477 | 477 | $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where ); |
| 478 | 478 | $count = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' ); |
| 479 | - } |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - return $count; |
|
| 482 | - } |
|
| 481 | + return $count; |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | - public static function getPageCount( $p_size, $where = '' ) { |
|
| 484 | + public static function getPageCount( $p_size, $where = '' ) { |
|
| 485 | 485 | $p_size = (int) $p_size; |
| 486 | 486 | $count = 1; |
| 487 | 487 | if ( $p_size ) { |
@@ -492,16 +492,16 @@ discard block |
||
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | return $count; |
| 495 | - } |
|
| 495 | + } |
|
| 496 | 496 | |
| 497 | 497 | /** |
| 498 | - * Prepare the data before inserting it into the database |
|
| 499 | - * |
|
| 500 | - * @since 2.0.16 |
|
| 501 | - * @param array $values |
|
| 502 | - * @param string $type |
|
| 503 | - * @return array $new_values |
|
| 504 | - */ |
|
| 498 | + * Prepare the data before inserting it into the database |
|
| 499 | + * |
|
| 500 | + * @since 2.0.16 |
|
| 501 | + * @param array $values |
|
| 502 | + * @param string $type |
|
| 503 | + * @return array $new_values |
|
| 504 | + */ |
|
| 505 | 505 | private static function before_insert_entry_in_database( &$values, $type ) { |
| 506 | 506 | |
| 507 | 507 | self::sanitize_entry_post( $values ); |
@@ -516,13 +516,13 @@ discard block |
||
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
| 519 | - * Create an entry and perform after create actions |
|
| 520 | - * |
|
| 521 | - * @since 2.0.16 |
|
| 522 | - * @param array $values |
|
| 523 | - * @param array $new_values |
|
| 524 | - * @return boolean|int $entry_id |
|
| 525 | - */ |
|
| 519 | + * Create an entry and perform after create actions |
|
| 520 | + * |
|
| 521 | + * @since 2.0.16 |
|
| 522 | + * @param array $values |
|
| 523 | + * @param array $new_values |
|
| 524 | + * @return boolean|int $entry_id |
|
| 525 | + */ |
|
| 526 | 526 | private static function continue_to_create_entry( $values, $new_values ) { |
| 527 | 527 | $entry_id = self::insert_entry_into_database( $new_values ); |
| 528 | 528 | if ( ! $entry_id ) { |
@@ -534,37 +534,37 @@ discard block |
||
| 534 | 534 | return $entry_id; |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - /** |
|
| 538 | - * Sanitize the POST values before we use them |
|
| 539 | - * |
|
| 540 | - * @since 2.0 |
|
| 541 | - * @param array $values The POST values by reference |
|
| 542 | - */ |
|
| 543 | - public static function sanitize_entry_post( &$values ) { |
|
| 544 | - $sanitize_method = array( |
|
| 545 | - 'form_id' => 'absint', |
|
| 546 | - 'frm_action' => 'sanitize_title', |
|
| 547 | - 'form_key' => 'sanitize_title', |
|
| 548 | - 'item_key' => 'sanitize_title', |
|
| 549 | - 'item_name' => 'sanitize_text_field', |
|
| 550 | - 'frm_saving_draft' => 'absint', |
|
| 551 | - 'is_draft' => 'absint', |
|
| 552 | - 'post_id' => 'absint', |
|
| 553 | - 'parent_item_id' => 'absint', |
|
| 554 | - 'created_at' => 'sanitize_text_field', |
|
| 555 | - 'updated_at' => 'sanitize_text_field', |
|
| 556 | - ); |
|
| 557 | - |
|
| 558 | - FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Prepare the new values for inserting into the database |
|
| 563 | - * |
|
| 564 | - * @since 2.0.16 |
|
| 565 | - * @param array $values |
|
| 566 | - * @return array $new_values |
|
| 567 | - */ |
|
| 537 | + /** |
|
| 538 | + * Sanitize the POST values before we use them |
|
| 539 | + * |
|
| 540 | + * @since 2.0 |
|
| 541 | + * @param array $values The POST values by reference |
|
| 542 | + */ |
|
| 543 | + public static function sanitize_entry_post( &$values ) { |
|
| 544 | + $sanitize_method = array( |
|
| 545 | + 'form_id' => 'absint', |
|
| 546 | + 'frm_action' => 'sanitize_title', |
|
| 547 | + 'form_key' => 'sanitize_title', |
|
| 548 | + 'item_key' => 'sanitize_title', |
|
| 549 | + 'item_name' => 'sanitize_text_field', |
|
| 550 | + 'frm_saving_draft' => 'absint', |
|
| 551 | + 'is_draft' => 'absint', |
|
| 552 | + 'post_id' => 'absint', |
|
| 553 | + 'parent_item_id' => 'absint', |
|
| 554 | + 'created_at' => 'sanitize_text_field', |
|
| 555 | + 'updated_at' => 'sanitize_text_field', |
|
| 556 | + ); |
|
| 557 | + |
|
| 558 | + FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Prepare the new values for inserting into the database |
|
| 563 | + * |
|
| 564 | + * @since 2.0.16 |
|
| 565 | + * @param array $values |
|
| 566 | + * @return array $new_values |
|
| 567 | + */ |
|
| 568 | 568 | private static function package_entry_data( &$values ) { |
| 569 | 569 | global $wpdb; |
| 570 | 570 | |
@@ -617,34 +617,34 @@ discard block |
||
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
| 620 | - * Get the is_draft value for a new entry |
|
| 621 | - * |
|
| 622 | - * @since 2.0.16 |
|
| 623 | - * @param array $values |
|
| 624 | - * @return int |
|
| 625 | - */ |
|
| 620 | + * Get the is_draft value for a new entry |
|
| 621 | + * |
|
| 622 | + * @since 2.0.16 |
|
| 623 | + * @param array $values |
|
| 624 | + * @return int |
|
| 625 | + */ |
|
| 626 | 626 | private static function get_is_draft_value( $values ) { |
| 627 | 627 | return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | /** |
| 631 | - * Get the created_at value for a new entry |
|
| 632 | - * |
|
| 633 | - * @since 2.0.16 |
|
| 634 | - * @param array $values |
|
| 635 | - * @return string |
|
| 636 | - */ |
|
| 631 | + * Get the created_at value for a new entry |
|
| 632 | + * |
|
| 633 | + * @since 2.0.16 |
|
| 634 | + * @param array $values |
|
| 635 | + * @return string |
|
| 636 | + */ |
|
| 637 | 637 | private static function get_created_at( $values ) { |
| 638 | 638 | return self::get_entry_value( $values, 'created_at', current_time( 'mysql', 1 ) ); |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
| 642 | - * Get the updated_at value for a new entry |
|
| 643 | - * |
|
| 644 | - * @since 2.0.16 |
|
| 645 | - * @param array $values |
|
| 646 | - * @return string |
|
| 647 | - */ |
|
| 642 | + * Get the updated_at value for a new entry |
|
| 643 | + * |
|
| 644 | + * @since 2.0.16 |
|
| 645 | + * @param array $values |
|
| 646 | + * @return string |
|
| 647 | + */ |
|
| 648 | 648 | private static function get_updated_at( $values ) { |
| 649 | 649 | if ( isset( $values['updated_at'] ) ) { |
| 650 | 650 | $updated_at = $values['updated_at']; |
@@ -656,12 +656,12 @@ discard block |
||
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
| 659 | - * Get the description value for a new entry |
|
| 660 | - * |
|
| 661 | - * @since 2.0.16 |
|
| 662 | - * @param array $values |
|
| 663 | - * @return string |
|
| 664 | - */ |
|
| 659 | + * Get the description value for a new entry |
|
| 660 | + * |
|
| 661 | + * @since 2.0.16 |
|
| 662 | + * @param array $values |
|
| 663 | + * @return string |
|
| 664 | + */ |
|
| 665 | 665 | private static function get_entry_description( $values ) { |
| 666 | 666 | if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) { |
| 667 | 667 | $description = maybe_serialize( $values['description'] ); |
@@ -678,12 +678,12 @@ discard block |
||
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
| 681 | - * Get the user_id value for a new entry |
|
| 682 | - * |
|
| 683 | - * @since 2.0.16 |
|
| 684 | - * @param array $values |
|
| 685 | - * @return int |
|
| 686 | - */ |
|
| 681 | + * Get the user_id value for a new entry |
|
| 682 | + * |
|
| 683 | + * @since 2.0.16 |
|
| 684 | + * @param array $values |
|
| 685 | + * @return int |
|
| 686 | + */ |
|
| 687 | 687 | private static function get_entry_user_id( $values ) { |
| 688 | 688 | if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) { |
| 689 | 689 | $user_id = $values['frm_user_id']; |
@@ -696,12 +696,12 @@ discard block |
||
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
| 699 | - * Insert new entry into the database |
|
| 700 | - * |
|
| 701 | - * @since 2.0.16 |
|
| 702 | - * @param array $new_values |
|
| 703 | - * @return int | boolean $entry_id |
|
| 704 | - */ |
|
| 699 | + * Insert new entry into the database |
|
| 700 | + * |
|
| 701 | + * @since 2.0.16 |
|
| 702 | + * @param array $new_values |
|
| 703 | + * @return int | boolean $entry_id |
|
| 704 | + */ |
|
| 705 | 705 | private static function insert_entry_into_database( $new_values ) { |
| 706 | 706 | global $wpdb; |
| 707 | 707 | |
@@ -717,11 +717,11 @@ discard block |
||
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
| 720 | - * Add the new entry to global $frm_vars |
|
| 721 | - * |
|
| 722 | - * @since 2.0.16 |
|
| 723 | - * @param int $entry_id |
|
| 724 | - */ |
|
| 720 | + * Add the new entry to global $frm_vars |
|
| 721 | + * |
|
| 722 | + * @since 2.0.16 |
|
| 723 | + * @param int $entry_id |
|
| 724 | + */ |
|
| 725 | 725 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
| 726 | 726 | global $frm_vars; |
| 727 | 727 | |
@@ -733,12 +733,12 @@ discard block |
||
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | /** |
| 736 | - * Add entry metas, if there are any |
|
| 737 | - * |
|
| 738 | - * @since 2.0.16 |
|
| 739 | - * @param array $values |
|
| 740 | - * @param int $entry_id |
|
| 741 | - */ |
|
| 736 | + * Add entry metas, if there are any |
|
| 737 | + * |
|
| 738 | + * @since 2.0.16 |
|
| 739 | + * @param array $values |
|
| 740 | + * @param int $entry_id |
|
| 741 | + */ |
|
| 742 | 742 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
| 743 | 743 | if ( isset( $values['item_meta'] ) ) { |
| 744 | 744 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
@@ -746,12 +746,12 @@ discard block |
||
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /** |
| 749 | - * Trigger frm_after_create_entry hooks |
|
| 750 | - * |
|
| 751 | - * @since 2.0.16 |
|
| 752 | - * @param int $entry_id |
|
| 753 | - * @param array $new_values |
|
| 754 | - */ |
|
| 749 | + * Trigger frm_after_create_entry hooks |
|
| 750 | + * |
|
| 751 | + * @since 2.0.16 |
|
| 752 | + * @param int $entry_id |
|
| 753 | + * @param array $new_values |
|
| 754 | + */ |
|
| 755 | 755 | private static function after_entry_created_actions( $entry_id, $values, $new_values ) { |
| 756 | 756 | // this is a child entry |
| 757 | 757 | $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
@@ -761,13 +761,13 @@ discard block |
||
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
| 764 | - * Actions to perform immediately after an entry is inserted in the frm_items database |
|
| 765 | - * |
|
| 766 | - * @since 2.0.16 |
|
| 767 | - * @param array $values |
|
| 768 | - * @param array $new_values |
|
| 769 | - * @param int $entry_id |
|
| 770 | - */ |
|
| 764 | + * Actions to perform immediately after an entry is inserted in the frm_items database |
|
| 765 | + * |
|
| 766 | + * @since 2.0.16 |
|
| 767 | + * @param array $values |
|
| 768 | + * @param array $new_values |
|
| 769 | + * @param int $entry_id |
|
| 770 | + */ |
|
| 771 | 771 | private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) { |
| 772 | 772 | |
| 773 | 773 | self::add_new_entry_to_frm_vars( $entry_id ); |
@@ -780,14 +780,14 @@ discard block |
||
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
| 783 | - * Perform some actions right before updating an entry |
|
| 784 | - * |
|
| 785 | - * @since 2.0.16 |
|
| 786 | - * @param int $id |
|
| 787 | - * @param array $values |
|
| 788 | - * @param string $update_type |
|
| 789 | - * @return boolean $update |
|
| 790 | - */ |
|
| 783 | + * Perform some actions right before updating an entry |
|
| 784 | + * |
|
| 785 | + * @since 2.0.16 |
|
| 786 | + * @param int $id |
|
| 787 | + * @param array $values |
|
| 788 | + * @param string $update_type |
|
| 789 | + * @return boolean $update |
|
| 790 | + */ |
|
| 791 | 791 | private static function before_update_entry( $id, &$values, $update_type ) { |
| 792 | 792 | $update = true; |
| 793 | 793 | |
@@ -805,13 +805,13 @@ discard block |
||
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | /** |
| 808 | - * Package the entry data for updating |
|
| 809 | - * |
|
| 810 | - * @since 2.0.16 |
|
| 811 | - * @param int $id |
|
| 812 | - * @param array $values |
|
| 813 | - * @return array $new_values |
|
| 814 | - */ |
|
| 808 | + * Package the entry data for updating |
|
| 809 | + * |
|
| 810 | + * @since 2.0.16 |
|
| 811 | + * @param int $id |
|
| 812 | + * @param array $values |
|
| 813 | + * @return array $new_values |
|
| 814 | + */ |
|
| 815 | 815 | private static function package_entry_to_update( $id, $values ) { |
| 816 | 816 | global $wpdb; |
| 817 | 817 | |
@@ -845,14 +845,14 @@ discard block |
||
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | /** |
| 848 | - * Perform some actions right after updating an entry |
|
| 849 | - * |
|
| 850 | - * @since 2.0.16 |
|
| 851 | - * @param boolean|int $query_results |
|
| 852 | - * @param int $id |
|
| 853 | - * @param array $values |
|
| 854 | - * @param array $new_values |
|
| 855 | - */ |
|
| 848 | + * Perform some actions right after updating an entry |
|
| 849 | + * |
|
| 850 | + * @since 2.0.16 |
|
| 851 | + * @param boolean|int $query_results |
|
| 852 | + * @param int $id |
|
| 853 | + * @param array $values |
|
| 854 | + * @param array $new_values |
|
| 855 | + */ |
|
| 856 | 856 | private static function after_update_entry( $query_results, $id, $values, $new_values ) { |
| 857 | 857 | if ( $query_results ) { |
| 858 | 858 | self::clear_cache(); |
@@ -874,13 +874,13 @@ discard block |
||
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | /** |
| 877 | - * Create entry from an XML import |
|
| 878 | - * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
| 879 | - * |
|
| 880 | - * @since 2.0.16 |
|
| 881 | - * @param array $values |
|
| 882 | - * @return int | boolean $entry_id |
|
| 883 | - */ |
|
| 877 | + * Create entry from an XML import |
|
| 878 | + * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
| 879 | + * |
|
| 880 | + * @since 2.0.16 |
|
| 881 | + * @param array $values |
|
| 882 | + * @return int | boolean $entry_id |
|
| 883 | + */ |
|
| 884 | 884 | public static function create_entry_from_xml( $values ) { |
| 885 | 885 | $entry_id = self::create_entry( $values, 'xml' ); |
| 886 | 886 | |
@@ -888,14 +888,14 @@ discard block |
||
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | /** |
| 891 | - * Update entry from an XML import |
|
| 892 | - * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
| 893 | - * |
|
| 894 | - * @since 2.0.16 |
|
| 895 | - * @param int $id |
|
| 896 | - * @param array $values |
|
| 897 | - * @return int | boolean $updated |
|
| 898 | - */ |
|
| 891 | + * Update entry from an XML import |
|
| 892 | + * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
| 893 | + * |
|
| 894 | + * @since 2.0.16 |
|
| 895 | + * @param int $id |
|
| 896 | + * @param array $values |
|
| 897 | + * @return int | boolean $updated |
|
| 898 | + */ |
|
| 899 | 899 | public static function update_entry_from_xml( $id, $values ) { |
| 900 | 900 | $updated = self::update_entry( $id, $values, 'xml' ); |
| 901 | 901 | |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | return $wpdb->get_charset_collate(); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - private function create_tables() { |
|
| 78 | - $charset_collate = $this->collation(); |
|
| 79 | - $sql = array(); |
|
| 77 | + private function create_tables() { |
|
| 78 | + $charset_collate = $this->collation(); |
|
| 79 | + $sql = array(); |
|
| 80 | 80 | |
| 81 | - /* Create/Upgrade Fields Table */ |
|
| 81 | + /* Create/Upgrade Fields Table */ |
|
| 82 | 82 | $sql[] = 'CREATE TABLE ' . $this->fields . ' ( |
| 83 | 83 | id BIGINT(20) NOT NULL auto_increment, |
| 84 | 84 | field_key varchar(100) default NULL, |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | UNIQUE KEY field_key (field_key) |
| 98 | 98 | )'; |
| 99 | 99 | |
| 100 | - /* Create/Upgrade Forms Table */ |
|
| 100 | + /* Create/Upgrade Forms Table */ |
|
| 101 | 101 | $sql[] = 'CREATE TABLE ' . $this->forms . ' ( |
| 102 | 102 | id int(11) NOT NULL auto_increment, |
| 103 | 103 | form_key varchar(100) default NULL, |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | UNIQUE KEY form_key (form_key) |
| 116 | 116 | )'; |
| 117 | 117 | |
| 118 | - /* Create/Upgrade Items Table */ |
|
| 118 | + /* Create/Upgrade Items Table */ |
|
| 119 | 119 | $sql[] = 'CREATE TABLE ' . $this->entries . ' ( |
| 120 | 120 | id BIGINT(20) NOT NULL auto_increment, |
| 121 | 121 | item_key varchar(100) default NULL, |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | UNIQUE KEY item_key (item_key) |
| 139 | 139 | )'; |
| 140 | 140 | |
| 141 | - /* Create/Upgrade Meta Table */ |
|
| 141 | + /* Create/Upgrade Meta Table */ |
|
| 142 | 142 | $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' ( |
| 143 | 143 | id BIGINT(20) NOT NULL auto_increment, |
| 144 | 144 | meta_value longtext default NULL, |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | KEY item_id (item_id) |
| 151 | 151 | )'; |
| 152 | 152 | |
| 153 | - foreach ( $sql as $q ) { |
|
| 153 | + foreach ( $sql as $q ) { |
|
| 154 | 154 | if ( function_exists( 'dbDelta' ) ) { |
| 155 | 155 | dbDelta( $q . $charset_collate . ';' ); |
| 156 | 156 | } else { |
@@ -158,8 +158,8 @@ discard block |
||
| 158 | 158 | $wpdb->query( $q . $charset_collate ); // WPCS: unprepared SQL ok. |
| 159 | 159 | } |
| 160 | 160 | unset( $q ); |
| 161 | - } |
|
| 162 | - } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | 164 | private function maybe_create_contact_form() { |
| 165 | 165 | $form_exists = FrmForm::get_id_by_key( 'contact-form' ); |
@@ -215,13 +215,13 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - public function uninstall() { |
|
| 218 | + public function uninstall() { |
|
| 219 | 219 | if ( ! current_user_can( 'administrator' ) ) { |
| 220 | - $frm_settings = FrmAppHelper::get_settings(); |
|
| 220 | + $frm_settings = FrmAppHelper::get_settings(); |
|
| 221 | 221 | wp_die( esc_html( $frm_settings->admin_permission ) ); |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - global $wpdb, $wp_roles; |
|
| 224 | + global $wpdb, $wp_roles; |
|
| 225 | 225 | |
| 226 | 226 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // WPCS: unprepared SQL ok. |
| 227 | 227 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // WPCS: unprepared SQL ok. |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | delete_option( 'frm_lite_settings_upgrade' ); |
| 235 | 235 | delete_option( 'frm-usage-uuid' ); |
| 236 | 236 | |
| 237 | - //delete roles |
|
| 238 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 239 | - $roles = get_editable_roles(); |
|
| 240 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 241 | - foreach ( $roles as $role => $details ) { |
|
| 242 | - $wp_roles->remove_cap( $role, $frm_role ); |
|
| 237 | + //delete roles |
|
| 238 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 239 | + $roles = get_editable_roles(); |
|
| 240 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 241 | + foreach ( $roles as $role => $details ) { |
|
| 242 | + $wp_roles->remove_cap( $role, $frm_role ); |
|
| 243 | 243 | unset( $role, $details ); |
| 244 | 244 | } |
| 245 | 245 | unset( $frm_role, $frm_role_description ); |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) ); |
| 268 | 268 | |
| 269 | 269 | do_action( 'frm_after_uninstall' ); |
| 270 | - return true; |
|
| 271 | - } |
|
| 270 | + return true; |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | 273 | /** |
| 274 | 274 | * Delete uneeded default templates |
@@ -450,42 +450,42 @@ discard block |
||
| 450 | 450 | $size .= 'px'; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - /** |
|
| 454 | - * Migrate post and email notification settings into actions |
|
| 455 | - */ |
|
| 456 | - private function migrate_to_16() { |
|
| 457 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Old email settings format: |
|
| 461 | - * email_to: Email or field id |
|
| 462 | - * also_email_to: array of fields ids |
|
| 463 | - * reply_to: Email, field id, 'custom' |
|
| 464 | - * cust_reply_to: string |
|
| 465 | - * reply_to_name: field id, 'custom' |
|
| 466 | - * cust_reply_to_name: string |
|
| 467 | - * plain_text: 0|1 |
|
| 468 | - * email_message: string or '' |
|
| 469 | - * email_subject: string or '' |
|
| 470 | - * inc_user_info: 0|1 |
|
| 471 | - * update_email: 0, 1, 2 |
|
| 472 | - * |
|
| 473 | - * Old autoresponder settings format: |
|
| 474 | - * auto_responder: 0|1 |
|
| 475 | - * ar_email_message: string or '' |
|
| 476 | - * ar_email_to: field id |
|
| 477 | - * ar_plain_text: 0|1 |
|
| 478 | - * ar_reply_to_name: string |
|
| 479 | - * ar_reply_to: string |
|
| 480 | - * ar_email_subject: string |
|
| 481 | - * ar_update_email: 0, 1, 2 |
|
| 482 | - * |
|
| 483 | - * New email settings: |
|
| 484 | - * post_content: json settings |
|
| 485 | - * post_title: form id |
|
| 486 | - * post_excerpt: message |
|
| 487 | - */ |
|
| 488 | - foreach ( $forms as $form ) { |
|
| 453 | + /** |
|
| 454 | + * Migrate post and email notification settings into actions |
|
| 455 | + */ |
|
| 456 | + private function migrate_to_16() { |
|
| 457 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Old email settings format: |
|
| 461 | + * email_to: Email or field id |
|
| 462 | + * also_email_to: array of fields ids |
|
| 463 | + * reply_to: Email, field id, 'custom' |
|
| 464 | + * cust_reply_to: string |
|
| 465 | + * reply_to_name: field id, 'custom' |
|
| 466 | + * cust_reply_to_name: string |
|
| 467 | + * plain_text: 0|1 |
|
| 468 | + * email_message: string or '' |
|
| 469 | + * email_subject: string or '' |
|
| 470 | + * inc_user_info: 0|1 |
|
| 471 | + * update_email: 0, 1, 2 |
|
| 472 | + * |
|
| 473 | + * Old autoresponder settings format: |
|
| 474 | + * auto_responder: 0|1 |
|
| 475 | + * ar_email_message: string or '' |
|
| 476 | + * ar_email_to: field id |
|
| 477 | + * ar_plain_text: 0|1 |
|
| 478 | + * ar_reply_to_name: string |
|
| 479 | + * ar_reply_to: string |
|
| 480 | + * ar_email_subject: string |
|
| 481 | + * ar_update_email: 0, 1, 2 |
|
| 482 | + * |
|
| 483 | + * New email settings: |
|
| 484 | + * post_content: json settings |
|
| 485 | + * post_title: form id |
|
| 486 | + * post_excerpt: message |
|
| 487 | + */ |
|
| 488 | + foreach ( $forms as $form ) { |
|
| 489 | 489 | if ( $form->is_template && $form->default_template ) { |
| 490 | 490 | // don't migrate the default templates since the email will be added anyway |
| 491 | 491 | continue; |
@@ -494,19 +494,19 @@ discard block |
||
| 494 | 494 | // Format form options |
| 495 | 495 | $form_options = maybe_unserialize( $form->options ); |
| 496 | 496 | |
| 497 | - // Migrate settings to actions |
|
| 498 | - FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
|
| 499 | - } |
|
| 500 | - } |
|
| 497 | + // Migrate settings to actions |
|
| 498 | + FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | 501 | |
| 502 | - private function migrate_to_11() { |
|
| 503 | - global $wpdb; |
|
| 502 | + private function migrate_to_11() { |
|
| 503 | + global $wpdb; |
|
| 504 | 504 | |
| 505 | 505 | $forms = FrmDb::get_results( $this->forms, array(), 'id, options' ); |
| 506 | 506 | |
| 507 | - $sending = __( 'Sending', 'formidable' ); |
|
| 507 | + $sending = __( 'Sending', 'formidable' ); |
|
| 508 | 508 | $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; |
| 509 | - $old_default_html = <<<DEFAULT_HTML |
|
| 509 | + $old_default_html = <<<DEFAULT_HTML |
|
| 510 | 510 | <div class="frm_submit"> |
| 511 | 511 | [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button] |
| 512 | 512 | <input type="submit" value="[button_label]" [button_action] /> |
@@ -516,21 +516,21 @@ discard block |
||
| 516 | 516 | unset( $sending, $img ); |
| 517 | 517 | |
| 518 | 518 | $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
| 519 | - $draft_link = FrmFormsHelper::get_draft_link(); |
|
| 519 | + $draft_link = FrmFormsHelper::get_draft_link(); |
|
| 520 | 520 | foreach ( $forms as $form ) { |
| 521 | 521 | $form->options = maybe_unserialize( $form->options ); |
| 522 | 522 | if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) { |
| 523 | - continue; |
|
| 524 | - } |
|
| 523 | + continue; |
|
| 524 | + } |
|
| 525 | 525 | |
| 526 | - if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
|
| 527 | - $form->options['submit_html'] = $new_default_html; |
|
| 526 | + if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
|
| 527 | + $form->options['submit_html'] = $new_default_html; |
|
| 528 | 528 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 529 | 529 | } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) { |
| 530 | 530 | $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
| 531 | 531 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 532 | - } |
|
| 532 | + } |
|
| 533 | 533 | unset( $form ); |
| 534 | - } |
|
| 535 | - } |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | 536 | } |
@@ -2,92 +2,92 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class FrmHooksController { |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * Trigger plugin-wide hook loading |
|
| 7 | - */ |
|
| 8 | - public static function trigger_load_hook( $hooks = 'load_hooks' ) { |
|
| 9 | - $controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) ); |
|
| 10 | - |
|
| 11 | - $trigger_hooks = $hooks; |
|
| 12 | - $hooks = (array) $hooks; |
|
| 13 | - |
|
| 14 | - if ( 'load_hooks' == $trigger_hooks ) { |
|
| 15 | - if ( is_admin() ) { |
|
| 16 | - $hooks[] = 'load_admin_hooks'; |
|
| 17 | - if ( defined( 'DOING_AJAX' ) ) { |
|
| 18 | - $hooks[] = 'load_ajax_hooks'; |
|
| 19 | - $hooks[] = 'load_form_hooks'; |
|
| 20 | - } |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - if ( is_multisite() ) { |
|
| 24 | - $hooks[] = 'load_multisite_hooks'; |
|
| 25 | - } |
|
| 26 | - } else { |
|
| 27 | - // Make sure the hooks are only triggered once |
|
| 28 | - add_filter( 'frm' . str_replace( 'load', '', $trigger_hooks ) . '_loaded', '__return_true' ); |
|
| 29 | - } |
|
| 30 | - unset( $trigger_hooks ); |
|
| 31 | - |
|
| 32 | - // Instansiate Controllers |
|
| 33 | - foreach ( $controllers as $c ) { |
|
| 34 | - foreach ( $hooks as $hook ) { |
|
| 5 | + /** |
|
| 6 | + * Trigger plugin-wide hook loading |
|
| 7 | + */ |
|
| 8 | + public static function trigger_load_hook( $hooks = 'load_hooks' ) { |
|
| 9 | + $controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) ); |
|
| 10 | + |
|
| 11 | + $trigger_hooks = $hooks; |
|
| 12 | + $hooks = (array) $hooks; |
|
| 13 | + |
|
| 14 | + if ( 'load_hooks' == $trigger_hooks ) { |
|
| 15 | + if ( is_admin() ) { |
|
| 16 | + $hooks[] = 'load_admin_hooks'; |
|
| 17 | + if ( defined( 'DOING_AJAX' ) ) { |
|
| 18 | + $hooks[] = 'load_ajax_hooks'; |
|
| 19 | + $hooks[] = 'load_form_hooks'; |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + if ( is_multisite() ) { |
|
| 24 | + $hooks[] = 'load_multisite_hooks'; |
|
| 25 | + } |
|
| 26 | + } else { |
|
| 27 | + // Make sure the hooks are only triggered once |
|
| 28 | + add_filter( 'frm' . str_replace( 'load', '', $trigger_hooks ) . '_loaded', '__return_true' ); |
|
| 29 | + } |
|
| 30 | + unset( $trigger_hooks ); |
|
| 31 | + |
|
| 32 | + // Instansiate Controllers |
|
| 33 | + foreach ( $controllers as $c ) { |
|
| 34 | + foreach ( $hooks as $hook ) { |
|
| 35 | 35 | call_user_func( array( $c, $hook ) ); |
| 36 | 36 | unset( $hook ); |
| 37 | - } |
|
| 37 | + } |
|
| 38 | 38 | unset( $c ); |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public static function trigger_load_form_hooks() { |
|
| 44 | - self::trigger_load_hook( 'load_form_hooks' ); |
|
| 45 | - } |
|
| 43 | + public static function trigger_load_form_hooks() { |
|
| 44 | + self::trigger_load_hook( 'load_form_hooks' ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | public static function load_hooks() { |
| 48 | 48 | add_action( 'rest_api_init', 'FrmAppController::create_rest_routes', 0 ); |
| 49 | - add_action( 'plugins_loaded', 'FrmAppController::load_lang' ); |
|
| 49 | + add_action( 'plugins_loaded', 'FrmAppController::load_lang' ); |
|
| 50 | 50 | add_filter( 'widget_text', 'do_shortcode' ); |
| 51 | 51 | |
| 52 | - // Entries controller |
|
| 53 | - add_action( 'wp_loaded', 'FrmEntriesController::process_entry', 10, 0 ); |
|
| 54 | - add_action( 'frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100 ); |
|
| 52 | + // Entries controller |
|
| 53 | + add_action( 'wp_loaded', 'FrmEntriesController::process_entry', 10, 0 ); |
|
| 54 | + add_action( 'frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100 ); |
|
| 55 | 55 | |
| 56 | - // Form Actions Controller |
|
| 57 | - add_action( 'init', 'FrmFormActionsController::register_post_types', 1 ); |
|
| 56 | + // Form Actions Controller |
|
| 57 | + add_action( 'init', 'FrmFormActionsController::register_post_types', 1 ); |
|
| 58 | 58 | add_action( 'frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 3 ); |
| 59 | 59 | |
| 60 | - // Forms Controller |
|
| 61 | - add_action( 'widgets_init', 'FrmFormsController::register_widgets' ); |
|
| 60 | + // Forms Controller |
|
| 61 | + add_action( 'widgets_init', 'FrmFormsController::register_widgets' ); |
|
| 62 | 62 | add_action( 'init', 'FrmFormsController::front_head' ); |
| 63 | - add_filter( 'frm_content', 'FrmFormsController::filter_content', 10, 3 ); |
|
| 64 | - add_filter( 'frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3 ); |
|
| 65 | - add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' ); |
|
| 63 | + add_filter( 'frm_content', 'FrmFormsController::filter_content', 10, 3 ); |
|
| 64 | + add_filter( 'frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3 ); |
|
| 65 | + add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' ); |
|
| 66 | 66 | add_action( 'wp_footer', 'FrmFormsController::footer_js', 1, 0 ); |
| 67 | 67 | |
| 68 | 68 | add_action( 'wp_scheduled_delete', 'FrmForm::scheduled_delete' ); |
| 69 | 69 | |
| 70 | - // Form Shortcodes |
|
| 71 | - add_shortcode( 'formidable', 'FrmFormsController::get_form_shortcode' ); |
|
| 70 | + // Form Shortcodes |
|
| 71 | + add_shortcode( 'formidable', 'FrmFormsController::get_form_shortcode' ); |
|
| 72 | 72 | |
| 73 | - // Styles Controller |
|
| 74 | - add_action( 'init', 'FrmStylesController::register_post_types', 0 ); |
|
| 75 | - add_filter( 'frm_get_style_opts', 'FrmStylesController::get_style_opts' ); |
|
| 76 | - add_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 ); |
|
| 77 | - add_filter( 'frm_show_entry_styles', 'FrmStylesController::show_entry_styles' ); |
|
| 73 | + // Styles Controller |
|
| 74 | + add_action( 'init', 'FrmStylesController::register_post_types', 0 ); |
|
| 75 | + add_filter( 'frm_get_style_opts', 'FrmStylesController::get_style_opts' ); |
|
| 76 | + add_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 ); |
|
| 77 | + add_filter( 'frm_show_entry_styles', 'FrmStylesController::show_entry_styles' ); |
|
| 78 | 78 | |
| 79 | 79 | //Simple Blocks Controller |
| 80 | 80 | add_action( 'init', 'FrmSimpleBlocksController::register_simple_form_block' ); |
| 81 | 81 | |
| 82 | 82 | add_filter( 'cron_schedules', 'FrmUsageController::add_schedules' ); |
| 83 | 83 | add_action( 'formidable_send_usage', 'FrmUsageController::send_snapshot' ); |
| 84 | - } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | public static function load_admin_hooks() { |
| 87 | - add_action( 'admin_menu', 'FrmAppController::menu', 1 ); |
|
| 87 | + add_action( 'admin_menu', 'FrmAppController::menu', 1 ); |
|
| 88 | 88 | add_filter( 'admin_body_class', 'FrmAppController::add_admin_class', 999 ); |
| 89 | - add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' ); |
|
| 90 | - add_action( 'admin_notices', 'FrmAppController::pro_get_started_headline' ); |
|
| 89 | + add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' ); |
|
| 90 | + add_action( 'admin_notices', 'FrmAppController::pro_get_started_headline' ); |
|
| 91 | 91 | add_action( 'admin_init', 'FrmAppController::admin_init', 11 ); |
| 92 | 92 | add_filter( 'plugin_action_links_' . FrmAppHelper::plugin_folder() . '/formidable.php', 'FrmAppController::settings_link' ); |
| 93 | 93 | add_filter( 'admin_footer_text', 'FrmAppController::set_footer_text' ); |
@@ -98,54 +98,54 @@ discard block |
||
| 98 | 98 | add_action( 'admin_menu', 'FrmAddonsController::menu', 100 ); |
| 99 | 99 | add_filter( 'pre_set_site_transient_update_plugins', 'FrmAddonsController::check_update' ); |
| 100 | 100 | |
| 101 | - // Entries Controller |
|
| 102 | - add_action( 'admin_menu', 'FrmEntriesController::menu', 12 ); |
|
| 103 | - add_filter( 'contextual_help', 'FrmEntriesController::contextual_help', 10, 3 ); |
|
| 104 | - add_filter( 'set-screen-option', 'FrmEntriesController::save_per_page', 10, 3 ); |
|
| 105 | - add_filter( 'update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5 ); |
|
| 106 | - add_action( 'updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4 ); |
|
| 107 | - |
|
| 108 | - // Form Actions Controller |
|
| 109 | - if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
| 110 | - add_action( 'frm_before_update_form_settings', 'FrmFormActionsController::update_settings' ); |
|
| 111 | - } |
|
| 112 | - add_action( 'frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3 ); |
|
| 113 | - |
|
| 114 | - // Forms Controller |
|
| 115 | - add_action( 'admin_menu', 'FrmFormsController::menu', 10 ); |
|
| 116 | - add_action( 'admin_head-toplevel_page_formidable', 'FrmFormsController::head' ); |
|
| 117 | - |
|
| 118 | - add_filter( 'set-screen-option', 'FrmFormsController::save_per_page', 10, 3 ); |
|
| 119 | - add_action( 'admin_footer', 'FrmFormsController::insert_form_popup' ); |
|
| 101 | + // Entries Controller |
|
| 102 | + add_action( 'admin_menu', 'FrmEntriesController::menu', 12 ); |
|
| 103 | + add_filter( 'contextual_help', 'FrmEntriesController::contextual_help', 10, 3 ); |
|
| 104 | + add_filter( 'set-screen-option', 'FrmEntriesController::save_per_page', 10, 3 ); |
|
| 105 | + add_filter( 'update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5 ); |
|
| 106 | + add_action( 'updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4 ); |
|
| 107 | + |
|
| 108 | + // Form Actions Controller |
|
| 109 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
| 110 | + add_action( 'frm_before_update_form_settings', 'FrmFormActionsController::update_settings' ); |
|
| 111 | + } |
|
| 112 | + add_action( 'frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3 ); |
|
| 113 | + |
|
| 114 | + // Forms Controller |
|
| 115 | + add_action( 'admin_menu', 'FrmFormsController::menu', 10 ); |
|
| 116 | + add_action( 'admin_head-toplevel_page_formidable', 'FrmFormsController::head' ); |
|
| 117 | + |
|
| 118 | + add_filter( 'set-screen-option', 'FrmFormsController::save_per_page', 10, 3 ); |
|
| 119 | + add_action( 'admin_footer', 'FrmFormsController::insert_form_popup' ); |
|
| 120 | 120 | add_action( 'media_buttons', 'FrmFormsController::insert_form_button' ); |
| 121 | 121 | add_action( 'et_pb_admin_excluded_shortcodes', 'FrmFormsController::prevent_divi_conflict' ); |
| 122 | 122 | |
| 123 | - // Forms Model |
|
| 124 | - add_action( 'frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2 ); |
|
| 123 | + // Forms Model |
|
| 124 | + add_action( 'frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2 ); |
|
| 125 | 125 | |
| 126 | - // Settings Controller |
|
| 127 | - add_action( 'admin_menu', 'FrmSettingsController::menu', 45 ); |
|
| 128 | - add_action( 'frm_before_settings', 'FrmSettingsController::license_box' ); |
|
| 126 | + // Settings Controller |
|
| 127 | + add_action( 'admin_menu', 'FrmSettingsController::menu', 45 ); |
|
| 128 | + add_action( 'frm_before_settings', 'FrmSettingsController::license_box' ); |
|
| 129 | 129 | add_action( 'frm_after_settings', 'FrmSettingsController::settings_cta' ); |
| 130 | 130 | add_action( 'wp_ajax_frm_settings_tab', 'FrmSettingsController::load_settings_tab' ); |
| 131 | 131 | |
| 132 | - // Styles Controller |
|
| 133 | - add_action( 'admin_menu', 'FrmStylesController::menu', 14 ); |
|
| 134 | - add_action( 'admin_init', 'FrmStylesController::admin_init' ); |
|
| 132 | + // Styles Controller |
|
| 133 | + add_action( 'admin_menu', 'FrmStylesController::menu', 14 ); |
|
| 134 | + add_action( 'admin_init', 'FrmStylesController::admin_init' ); |
|
| 135 | 135 | |
| 136 | - // XML Controller |
|
| 137 | - add_action( 'admin_menu', 'FrmXMLController::menu', 41 ); |
|
| 136 | + // XML Controller |
|
| 137 | + add_action( 'admin_menu', 'FrmXMLController::menu', 41 ); |
|
| 138 | 138 | |
| 139 | 139 | // Simple Blocks Controller |
| 140 | 140 | add_action( 'enqueue_block_editor_assets', 'FrmSimpleBlocksController::block_editor_assets' ); |
| 141 | 141 | |
| 142 | 142 | add_action( 'admin_init', 'FrmUsageController::schedule_send' ); |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | public static function load_ajax_hooks() { |
| 146 | 146 | add_action( 'wp_ajax_frm_install', 'FrmAppController::ajax_install' ); |
| 147 | - add_action( 'wp_ajax_frm_uninstall', 'FrmAppController::uninstall' ); |
|
| 148 | - add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' ); |
|
| 147 | + add_action( 'wp_ajax_frm_uninstall', 'FrmAppController::uninstall' ); |
|
| 148 | + add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' ); |
|
| 149 | 149 | |
| 150 | 150 | // Addons |
| 151 | 151 | add_action( 'wp_ajax_frm_addon_activate', 'FrmAddon::activate' ); |
@@ -153,70 +153,70 @@ discard block |
||
| 153 | 153 | add_action( 'wp_ajax_frm_install_addon', 'FrmAddonsController::ajax_install_addon' ); |
| 154 | 154 | add_action( 'wp_ajax_frm_activate_addon', 'FrmAddonsController::ajax_activate_addon' ); |
| 155 | 155 | |
| 156 | - // Fields Controller |
|
| 157 | - add_action( 'wp_ajax_frm_load_field', 'FrmFieldsController::load_field' ); |
|
| 158 | - add_action( 'wp_ajax_frm_insert_field', 'FrmFieldsController::create' ); |
|
| 159 | - add_action( 'wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option' ); |
|
| 160 | - add_action( 'wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate' ); |
|
| 161 | - add_action( 'wp_ajax_frm_delete_field', 'FrmFieldsController::destroy' ); |
|
| 162 | - add_action( 'wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option' ); |
|
| 163 | - add_action( 'wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices' ); |
|
| 164 | - add_action( 'wp_ajax_frm_import_options', 'FrmFieldsController::import_options' ); |
|
| 165 | - add_action( 'wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order' ); |
|
| 166 | - |
|
| 167 | - // Form Actions Controller |
|
| 168 | - add_action( 'wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action' ); |
|
| 169 | - add_action( 'wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action' ); |
|
| 170 | - |
|
| 171 | - // Forms Controller |
|
| 156 | + // Fields Controller |
|
| 157 | + add_action( 'wp_ajax_frm_load_field', 'FrmFieldsController::load_field' ); |
|
| 158 | + add_action( 'wp_ajax_frm_insert_field', 'FrmFieldsController::create' ); |
|
| 159 | + add_action( 'wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option' ); |
|
| 160 | + add_action( 'wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate' ); |
|
| 161 | + add_action( 'wp_ajax_frm_delete_field', 'FrmFieldsController::destroy' ); |
|
| 162 | + add_action( 'wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option' ); |
|
| 163 | + add_action( 'wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices' ); |
|
| 164 | + add_action( 'wp_ajax_frm_import_options', 'FrmFieldsController::import_options' ); |
|
| 165 | + add_action( 'wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order' ); |
|
| 166 | + |
|
| 167 | + // Form Actions Controller |
|
| 168 | + add_action( 'wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action' ); |
|
| 169 | + add_action( 'wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action' ); |
|
| 170 | + |
|
| 171 | + // Forms Controller |
|
| 172 | 172 | add_action( 'wp_ajax_frm_save_form', 'FrmFormsController::route' ); |
| 173 | - add_action( 'wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' ); |
|
| 174 | - add_action( 'wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' ); |
|
| 175 | - add_action( 'wp_ajax_frm_forms_preview', 'FrmFormsController::preview' ); |
|
| 176 | - add_action( 'wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' ); |
|
| 173 | + add_action( 'wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' ); |
|
| 174 | + add_action( 'wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' ); |
|
| 175 | + add_action( 'wp_ajax_frm_forms_preview', 'FrmFormsController::preview' ); |
|
| 176 | + add_action( 'wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' ); |
|
| 177 | 177 | add_action( 'wp_ajax_frm_forms_trash', 'FrmFormsController::ajax_trash' ); |
| 178 | 178 | add_action( 'wp_ajax_frm_build_template', 'FrmFormsController::build_template' ); |
| 179 | 179 | |
| 180 | 180 | // Settings |
| 181 | 181 | add_action( 'wp_ajax_frm_lite_settings_upgrade', 'FrmSettingsController::settings_cta_dismiss' ); |
| 182 | 182 | |
| 183 | - // Styles Controller |
|
| 184 | - add_action( 'wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling' ); |
|
| 185 | - add_action( 'wp_ajax_frm_change_styling', 'FrmStylesController::change_styling' ); |
|
| 186 | - add_action( 'wp_ajax_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
| 187 | - add_action( 'wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
| 183 | + // Styles Controller |
|
| 184 | + add_action( 'wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling' ); |
|
| 185 | + add_action( 'wp_ajax_frm_change_styling', 'FrmStylesController::change_styling' ); |
|
| 186 | + add_action( 'wp_ajax_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
| 187 | + add_action( 'wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
| 188 | 188 | add_action( 'wp_ajax_frmpro_css', 'FrmStylesController::load_saved_css' ); |
| 189 | 189 | add_action( 'wp_ajax_nopriv_frmpro_css', 'FrmStylesController::load_saved_css' ); |
| 190 | 190 | |
| 191 | - // XML Controller |
|
| 191 | + // XML Controller |
|
| 192 | 192 | add_action( 'wp_ajax_frm_install_template', 'FrmXMLController::install_template' ); |
| 193 | 193 | add_action( 'wp_ajax_frm_entries_csv', 'FrmXMLController::csv' ); |
| 194 | 194 | add_action( 'wp_ajax_nopriv_frm_entries_csv', 'FrmXMLController::csv' ); |
| 195 | - add_action( 'wp_ajax_frm_export_xml', 'FrmXMLController::export_xml' ); |
|
| 196 | - } |
|
| 195 | + add_action( 'wp_ajax_frm_export_xml', 'FrmXMLController::export_xml' ); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | 198 | public static function load_form_hooks() { |
| 199 | - // Fields Controller |
|
| 200 | - add_filter( 'frm_field_type', 'FrmFieldsController::change_type' ); |
|
| 201 | - add_action( 'frm_field_input_html', 'FrmFieldsController::input_html' ); |
|
| 202 | - add_filter( 'frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3 ); |
|
| 203 | - add_filter( 'frm_field_label_seen', 'FrmFieldsController::check_label' ); |
|
| 199 | + // Fields Controller |
|
| 200 | + add_filter( 'frm_field_type', 'FrmFieldsController::change_type' ); |
|
| 201 | + add_action( 'frm_field_input_html', 'FrmFieldsController::input_html' ); |
|
| 202 | + add_filter( 'frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3 ); |
|
| 203 | + add_filter( 'frm_field_label_seen', 'FrmFieldsController::check_label' ); |
|
| 204 | 204 | |
| 205 | 205 | // Forms Controller |
| 206 | 206 | add_filter( 'frm_form_classes', 'FrmFormsController::form_classes' ); |
| 207 | 207 | |
| 208 | - // Styles Controller |
|
| 209 | - add_filter( 'frm_use_important_width', 'FrmStylesController::important_style', 10, 2 ); |
|
| 210 | - } |
|
| 208 | + // Styles Controller |
|
| 209 | + add_filter( 'frm_use_important_width', 'FrmStylesController::important_style', 10, 2 ); |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | 212 | public static function load_view_hooks() { |
| 213 | - // Hooks go here when a view is loaded |
|
| 214 | - } |
|
| 213 | + // Hooks go here when a view is loaded |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | 216 | public static function load_multisite_hooks() { |
| 217 | 217 | add_action( 'wpmu_upgrade_site', 'FrmAppController::network_upgrade_site' ); |
| 218 | 218 | |
| 219 | - // drop tables when mu site is deleted |
|
| 220 | - add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' ); |
|
| 221 | - } |
|
| 219 | + // drop tables when mu site is deleted |
|
| 220 | + add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' ); |
|
| 221 | + } |
|
| 222 | 222 | } |