diff --git a/classes/controllers/FrmAddonsController.php b/classes/controllers/FrmAddonsController.php index c241b637b6..455649c71a 100644 --- a/classes/controllers/FrmAddonsController.php +++ b/classes/controllers/FrmAddonsController.php @@ -194,10 +194,12 @@ protected static function organize_and_get_categories() { // Extract the elements to move foreach ( $plans as $plan ) { - if ( isset( self::$categories[ $plan ] ) ) { - $bottom_categories[ $plan ] = self::$categories[ $plan ]; - unset( self::$categories[ $plan ] ); + if ( ! isset( self::$categories[ $plan ] ) ) { + continue; } + + $bottom_categories[ $plan ] = self::$categories[ $plan ]; + unset( self::$categories[ $plan ] ); } $special_categories = array(); diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 2b59f6e0ac..5e974abdb0 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -874,10 +874,12 @@ private static function enqueue_builder_assets( $plugin_url, $version ) { * @return void */ private static function enqueue_global_settings_scripts( $page ) { - if ( 'formidable-settings' === $page ) { - wp_enqueue_style( 'wp-color-picker' ); - wp_enqueue_script( 'formidable_settings' ); + if ( 'formidable-settings' !== $page ) { + return; } + + wp_enqueue_style( 'wp-color-picker' ); + wp_enqueue_script( 'formidable_settings' ); } /** @@ -1182,12 +1184,14 @@ public static function network_upgrade_site( $blog_id = 0 ) { * @return void */ private static function maybe_add_wp_site_health() { - if ( ! class_exists( 'WP_Site_Health' ) ) { - $wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php'; + if ( class_exists( 'WP_Site_Health' ) ) { + return; + } - if ( file_exists( $wp_site_health_path ) ) { - require_once $wp_site_health_path; - } + $wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php'; + + if ( file_exists( $wp_site_health_path ) ) { + require_once $wp_site_health_path; } } diff --git a/classes/controllers/FrmDashboardController.php b/classes/controllers/FrmDashboardController.php index a0e3e0e363..052b1fd1a2 100644 --- a/classes/controllers/FrmDashboardController.php +++ b/classes/controllers/FrmDashboardController.php @@ -428,12 +428,15 @@ private static function view_args_inbox() { */ private static function inbox_prepare_messages( $data ) { foreach ( $data as $key => $messages ) { - if ( in_array( $key, array( 'unread', 'dismissed' ), true ) ) { - foreach ( $messages as $key_msg => $message ) { - $data[ $key ][ $key_msg ]['cta'] = self::inbox_clean_messages_cta( $message['cta'] ); - } + if ( ! in_array( $key, array( 'unread', 'dismissed' ), true ) ) { + continue; + } + + foreach ( $messages as $key_msg => $message ) { + $data[ $key ][ $key_msg ]['cta'] = self::inbox_clean_messages_cta( $message['cta'] ); } } + return $data; } diff --git a/classes/controllers/FrmEntriesController.php b/classes/controllers/FrmEntriesController.php index 36ef5584f8..03881f34fc 100644 --- a/classes/controllers/FrmEntriesController.php +++ b/classes/controllers/FrmEntriesController.php @@ -553,15 +553,17 @@ private static function user_hidden_columns_for_form( $form_id, $result ) { $hidden = array(); foreach ( (array) $result as $r ) { - if ( $r ) { - list( $form_prefix, $field_key ) = explode( '_', $r ); + if ( ! $r ) { + continue; + } - if ( (int) $form_prefix === (int) $form_id ) { - $hidden[] = $r; - } + list( $form_prefix, $field_key ) = explode( '_', $r ); - unset( $form_prefix ); + if ( (int) $form_prefix === (int) $form_id ) { + $hidden[] = $r; } + + unset( $form_prefix ); } return $hidden; @@ -654,13 +656,15 @@ public static function display_list( $message = '', $errors = array() ) { * @return void */ private static function get_delete_form_time( $form, &$errors ) { - if ( 'trash' === $form->status ) { - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, $form->options['trash_time'] ?? time() ); - - /* translators: %1$s: Time string */ - $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete ); + if ( 'trash' !== $form->status ) { + return; } + + $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, $form->options['trash_time'] ?? time() ); + + /* translators: %1$s: Time string */ + $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete ); } /** diff --git a/classes/controllers/FrmFormActionsController.php b/classes/controllers/FrmFormActionsController.php index c7a149185f..05da258b6c 100644 --- a/classes/controllers/FrmFormActionsController.php +++ b/classes/controllers/FrmFormActionsController.php @@ -600,12 +600,15 @@ public static function update_settings( $form_id ) { * @return void */ public static function delete_missing_actions( $old_actions ) { - if ( $old_actions ) { - foreach ( $old_actions as $old_id ) { - wp_delete_post( $old_id ); - } - FrmDb::cache_delete_group( 'frm_actions' ); + if ( ! $old_actions ) { + return; } + + foreach ( $old_actions as $old_id ) { + wp_delete_post( $old_id ); + } + + FrmDb::cache_delete_group( 'frm_actions' ); } /** diff --git a/classes/controllers/FrmFormTemplatesController.php b/classes/controllers/FrmFormTemplatesController.php index a0b3bcefdc..487368d2bd 100644 --- a/classes/controllers/FrmFormTemplatesController.php +++ b/classes/controllers/FrmFormTemplatesController.php @@ -592,10 +592,12 @@ private static function organize_and_set_categories() { */ private static function assign_featured_templates() { foreach ( self::FEATURED_TEMPLATES_IDS as $key ) { - if ( isset( self::$templates[ $key ] ) ) { - self::$templates[ $key ]['is_featured'] = true; - self::$featured_templates[] = self::$templates[ $key ]; + if ( ! isset( self::$templates[ $key ] ) ) { + continue; } + + self::$templates[ $key ]['is_featured'] = true; + self::$featured_templates[] = self::$templates[ $key ]; } } diff --git a/classes/controllers/FrmFormsController.php b/classes/controllers/FrmFormsController.php index 4bed7c2e2f..bc6799e307 100644 --- a/classes/controllers/FrmFormsController.php +++ b/classes/controllers/FrmFormsController.php @@ -765,14 +765,16 @@ private static function load_direct_preview() { * @return void */ public static function maybe_block_preview( $form_key ) { - if ( FrmFormsHelper::should_block_preview( $form_key ) ) { - $error = __( 'You do not have permission to view this form', 'formidable' ); - wp_die( - '

' . esc_html( $error ) . '

', - '

' . esc_html( $error ) . '

', - 403 - ); + if ( ! FrmFormsHelper::should_block_preview( $form_key ) ) { + return; } + + $error = __( 'You do not have permission to view this form', 'formidable' ); + wp_die( + '

' . esc_html( $error ) . '

', + '

' . esc_html( $error ) . '

', + 403 + ); } /** @@ -1996,13 +1998,15 @@ public static function replace_form_name_shortcodes( $string, $form ) { * @return void */ private static function get_entry_by_param( &$entry ) { - if ( ! $entry || ! is_object( $entry ) ) { - if ( ! $entry || ! is_numeric( $entry ) ) { - $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' ); - } + if ( $entry && is_object( $entry ) ) { + return; + } - FrmEntry::maybe_get_entry( $entry ); + if ( ! $entry || ! is_numeric( $entry ) ) { + $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' ); } + + FrmEntry::maybe_get_entry( $entry ); } /** diff --git a/classes/controllers/FrmInboxController.php b/classes/controllers/FrmInboxController.php index 10fe9145ef..29bc3d160b 100644 --- a/classes/controllers/FrmInboxController.php +++ b/classes/controllers/FrmInboxController.php @@ -110,9 +110,11 @@ private static function add_tracking_request() { * @return void */ private static function remove_free_template_message() { - if ( ! FrmAppHelper::pro_is_installed() ) { - $message = new FrmInbox(); - $message->dismiss( 'free_templates' ); + if ( FrmAppHelper::pro_is_installed() ) { + return; } + + $message = new FrmInbox(); + $message->dismiss( 'free_templates' ); } } diff --git a/classes/controllers/FrmSettingsController.php b/classes/controllers/FrmSettingsController.php index c9c4fa78f4..16b3f83c48 100644 --- a/classes/controllers/FrmSettingsController.php +++ b/classes/controllers/FrmSettingsController.php @@ -214,10 +214,12 @@ private static function remove_payments_sections( &$sections ) { $payment_section_keys = array( 'paypal', 'square', 'stripe', 'authorize_net' ); foreach ( $sections as $key => $section ) { - if ( in_array( $key, $payment_section_keys, true ) ) { - self::$removed_payments_sections[ $key ] = $section; - unset( $sections[ $key ] ); + if ( ! in_array( $key, $payment_section_keys, true ) ) { + continue; } + + self::$removed_payments_sections[ $key ] = $section; + unset( $sections[ $key ] ); } uksort( self::$removed_payments_sections, array( self::class, 'payment_sections_sort_callback' ) ); diff --git a/classes/helpers/FrmAppHelper.php b/classes/helpers/FrmAppHelper.php index ee6f5cf3ce..601e26f4c3 100644 --- a/classes/helpers/FrmAppHelper.php +++ b/classes/helpers/FrmAppHelper.php @@ -1514,10 +1514,12 @@ public static function include_svg() { */ public static function array_to_html_params( $atts, $echo = false ) { $callback = function () use ( $atts ) { - if ( $atts ) { - foreach ( $atts as $key => $value ) { - echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; - } + if ( ! $atts ) { + return; + } + + foreach ( $atts as $key => $value ) { + echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; } }; return self::clip( $callback, $echo ); @@ -2355,13 +2357,15 @@ public static function maybe_add_permissions() { * @return void */ public static function force_capability( $cap = 'frm_change_settings' ) { - if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) { - $role = get_role( 'administrator' ); - $frm_roles = self::frm_capabilities(); + if ( ! current_user_can( 'administrator' ) || current_user_can( $cap ) ) { + return; + } - foreach ( $frm_roles as $frm_role => $frm_role_description ) { - $role->add_cap( $frm_role ); - } + $role = get_role( 'administrator' ); + $frm_roles = self::frm_capabilities(); + + foreach ( $frm_roles as $frm_role => $frm_role_description ) { + $role->add_cap( $frm_role ); } } diff --git a/classes/helpers/FrmCSVExportHelper.php b/classes/helpers/FrmCSVExportHelper.php index eae8d7a1d9..eb50ed5e08 100644 --- a/classes/helpers/FrmCSVExportHelper.php +++ b/classes/helpers/FrmCSVExportHelper.php @@ -618,15 +618,17 @@ private static function fill_missing_repeater_metas( $metas, &$entries ) { } foreach ( self::$fields_by_repeater_id[ $repeater_id ] as $repeater_child ) { - if ( ! isset( $metas[ $repeater_child->id ] ) ) { - $metas[ $repeater_child->id ] = ''; + if ( isset( $metas[ $repeater_child->id ] ) ) { + continue; + } - if ( ! isset( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) || ! is_array( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) ) { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong - $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] = array(); - } + $metas[ $repeater_child->id ] = ''; - $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ][] = ''; + if ( ! isset( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) || ! is_array( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) ) { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong + $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] = array(); } + + $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ][] = ''; } return $metas; diff --git a/classes/helpers/FrmFieldsHelper.php b/classes/helpers/FrmFieldsHelper.php index 2c0ee9305c..8595e2d023 100644 --- a/classes/helpers/FrmFieldsHelper.php +++ b/classes/helpers/FrmFieldsHelper.php @@ -1825,16 +1825,18 @@ public static function switch_field_ids( $val ) { } foreach ( $val as $k => $v ) { - if ( is_string( $v ) ) { - if ( 'custom_html' === $k ) { - $val[ $k ] = self::switch_ids_except_strings( $replace, $replace_with, array( '[if description]', '[description]', '[/if description]' ), $v ); - unset( $k, $v ); - continue; - } + if ( ! is_string( $v ) ) { + continue; + } - $val[ $k ] = str_replace( $replace, $replace_with, $v ); + if ( 'custom_html' === $k ) { + $val[ $k ] = self::switch_ids_except_strings( $replace, $replace_with, array( '[if description]', '[description]', '[/if description]' ), $v ); unset( $k, $v ); + continue; } + + $val[ $k ] = str_replace( $replace, $replace_with, $v ); + unset( $k, $v ); } return $val; diff --git a/classes/helpers/FrmListHelper.php b/classes/helpers/FrmListHelper.php index b78657494b..e12ae93f3f 100644 --- a/classes/helpers/FrmListHelper.php +++ b/classes/helpers/FrmListHelper.php @@ -305,10 +305,12 @@ public function search_box( $text, $input_id ) { * @return void */ private function hidden_search_inputs( $param_name ) { - if ( ! empty( $_REQUEST[ $param_name ] ) ) { - $value = sanitize_text_field( wp_unslash( $_REQUEST[ $param_name ] ) ); - echo ''; + if ( empty( $_REQUEST[ $param_name ] ) ) { + return; } + + $value = sanitize_text_field( wp_unslash( $_REQUEST[ $param_name ] ) ); + echo ''; } /** diff --git a/classes/helpers/FrmXMLHelper.php b/classes/helpers/FrmXMLHelper.php index f792872bdd..d8f4c79cf4 100644 --- a/classes/helpers/FrmXMLHelper.php +++ b/classes/helpers/FrmXMLHelper.php @@ -133,11 +133,13 @@ public static function import_xml_now( $xml, $installing_template = false ) { foreach ( array( 'term', 'form', 'view' ) as $item_type ) { // Grab cats, tags, and terms, or forms or posts. - if ( isset( $xml->{$item_type} ) ) { - $function_name = 'import_xml_' . $item_type . 's'; - $imported = self::$function_name( $xml->{$item_type}, $imported ); - unset( $function_name, $xml->{$item_type} ); + if ( ! isset( $xml->{$item_type} ) ) { + continue; } + + $function_name = 'import_xml_' . $item_type . 's'; + $imported = self::$function_name( $xml->{$item_type}, $imported ); + unset( $function_name, $xml->{$item_type} ); } $imported = apply_filters( 'frm_importing_xml', $imported, $xml ); @@ -465,12 +467,14 @@ private static function track_imported_child_forms( $form_id, $parent_form_id, & */ private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) { foreach ( $child_forms as $child_form_id => $old_parent_form_id ) { - if ( isset( $imported_forms[ $old_parent_form_id ] ) && (int) $imported_forms[ $old_parent_form_id ] !== (int) $old_parent_form_id ) { - // Update all children with this old parent_form_id - $new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ]; - FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) ); - do_action( 'frm_update_child_form_parent_id', $child_form_id, $new_parent_form_id ); + if ( ! isset( $imported_forms[ $old_parent_form_id ] ) || (int) $imported_forms[ $old_parent_form_id ] === (int) $old_parent_form_id ) { + continue; } + + // Update all children with this old parent_form_id + $new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ]; + FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) ); + do_action( 'frm_update_child_form_parent_id', $child_form_id, $new_parent_form_id ); } } @@ -1513,13 +1517,15 @@ private static function update_postmeta( &$post, $post_id ) { * @param int $post_id */ private static function update_layout( &$post, $post_id ) { - if ( is_callable( 'FrmViewsLayout::maybe_create_layouts_for_view' ) ) { - $listing_layout = ! empty( $post['layout']['listing'] ) ? json_decode( $post['layout']['listing'], true ) : array(); - $detail_layout = ! empty( $post['layout']['detail'] ) ? json_decode( $post['layout']['detail'], true ) : array(); + if ( ! is_callable( 'FrmViewsLayout::maybe_create_layouts_for_view' ) ) { + return; + } - if ( $listing_layout || $detail_layout ) { - FrmViewsLayout::maybe_create_layouts_for_view( $post_id, $listing_layout, $detail_layout ); - } + $listing_layout = ! empty( $post['layout']['listing'] ) ? json_decode( $post['layout']['listing'], true ) : array(); + $detail_layout = ! empty( $post['layout']['detail'] ) ? json_decode( $post['layout']['detail'], true ) : array(); + + if ( $listing_layout || $detail_layout ) { + FrmViewsLayout::maybe_create_layouts_for_view( $post_id, $listing_layout, $detail_layout ); } } @@ -1832,10 +1838,12 @@ private static function add_image_src_to_image_options( $field ) { } foreach ( $options as $key => $option ) { - if ( is_array( $option ) && ! empty( $option['image'] ) ) { - $options[ $key ]['src'] = wp_get_attachment_url( $option['image'] ); - $updated = true; + if ( ! is_array( $option ) || empty( $option['image'] ) ) { + continue; } + + $options[ $key ]['src'] = wp_get_attachment_url( $option['image'] ); + $updated = true; } if ( $updated ) { diff --git a/classes/models/FrmAddon.php b/classes/models/FrmAddon.php index a47b45b0e1..6fd18d8fdb 100644 --- a/classes/models/FrmAddon.php +++ b/classes/models/FrmAddon.php @@ -632,13 +632,15 @@ private function clear_old_plugin_version( &$version_info ) { * @return void */ private function maybe_use_beta_url( &$version_info ) { - if ( $this->get_beta && ! empty( $version_info->beta ) ) { - $version_info->new_version = $version_info->beta['version']; - $version_info->package = $version_info->beta['package']; + if ( ! $this->get_beta || empty( $version_info->beta ) ) { + return; + } - if ( ! empty( $version_info->plugin ) ) { - $version_info->plugin = $version_info->beta['plugin']; - } + $version_info->new_version = $version_info->beta['version']; + $version_info->package = $version_info->beta['package']; + + if ( ! empty( $version_info->plugin ) ) { + $version_info->plugin = $version_info->beta['plugin']; } } diff --git a/classes/models/FrmAntiSpam.php b/classes/models/FrmAntiSpam.php index 4615a7b728..99f3ee28bb 100644 --- a/classes/models/FrmAntiSpam.php +++ b/classes/models/FrmAntiSpam.php @@ -315,10 +315,12 @@ private static function clear_wp_fastest_cache() { * @return void */ private static function clear_wp_super_cache() { - if ( function_exists( 'wp_cache_clean_cache' ) ) { - global $file_prefix; - wp_cache_clean_cache( $file_prefix, true ); + if ( ! function_exists( 'wp_cache_clean_cache' ) ) { + return; } + + global $file_prefix; + wp_cache_clean_cache( $file_prefix, true ); } /** diff --git a/classes/models/FrmCreateFile.php b/classes/models/FrmCreateFile.php index 334d8aea60..0b8f74517d 100644 --- a/classes/models/FrmCreateFile.php +++ b/classes/models/FrmCreateFile.php @@ -107,14 +107,16 @@ public function create_file( $file_content ) { * @return void */ public function append_file( $file_content ) { - if ( $this->has_permission ) { - if ( file_exists( $this->new_file_path ) ) { - $existing_content = $this->get_contents(); - $file_content = $existing_content . $file_content; - } + if ( ! $this->has_permission ) { + return; + } - $this->create_file( $file_content ); + if ( file_exists( $this->new_file_path ) ) { + $existing_content = $this->get_contents(); + $file_content = $existing_content . $file_content; } + + $this->create_file( $file_content ); } /** @@ -127,14 +129,16 @@ public function append_file( $file_content ) { * @return void */ public function combine_files( $file_names ) { - if ( $this->has_permission ) { - $content = ''; + if ( ! $this->has_permission ) { + return; + } - foreach ( $file_names as $file_name ) { - $content .= $this->get_contents( $file_name ) . "\n"; - } - $this->create_file( $content ); + $content = ''; + + foreach ( $file_names as $file_name ) { + $content .= $this->get_contents( $file_name ) . "\n"; } + $this->create_file( $content ); } /** diff --git a/classes/models/FrmDb.php b/classes/models/FrmDb.php index 2922f4c017..72bb7a5903 100644 --- a/classes/models/FrmDb.php +++ b/classes/models/FrmDb.php @@ -732,10 +732,12 @@ public static function check_cache( $cache_key, $group = '', $query = '', $type * @return void */ public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) { - if ( ! FrmAppHelper::prevent_caching() ) { - self::add_key_to_group_cache( $cache_key, $group ); - wp_cache_set( $cache_key, $results, $group, $time ); + if ( FrmAppHelper::prevent_caching() ) { + return; } + + self::add_key_to_group_cache( $cache_key, $group ); + wp_cache_set( $cache_key, $results, $group, $time ); } /** diff --git a/classes/models/FrmEntryFormatter.php b/classes/models/FrmEntryFormatter.php index e550d0cff5..26547da99f 100644 --- a/classes/models/FrmEntryFormatter.php +++ b/classes/models/FrmEntryFormatter.php @@ -789,16 +789,18 @@ protected function package_value_args( $field_value ) { * @return void */ protected function add_user_info_to_html_table( &$content ) { - if ( $this->include_user_info ) { - foreach ( $this->entry_values->get_user_info() as $user_info ) { - $value_args = array( - 'label' => $user_info['label'], - 'value' => $user_info['value'], - 'field_type' => 'none', - ); - - $this->add_html_row( $value_args, $content ); - } + if ( ! $this->include_user_info ) { + return; + } + + foreach ( $this->entry_values->get_user_info() as $user_info ) { + $value_args = array( + 'label' => $user_info['label'], + 'value' => $user_info['value'], + 'field_type' => 'none', + ); + + $this->add_html_row( $value_args, $content ); } } @@ -812,10 +814,12 @@ protected function add_user_info_to_html_table( &$content ) { * @return void */ protected function add_user_info_to_plain_text_content( &$content ) { - if ( $this->include_user_info ) { - foreach ( $this->entry_values->get_user_info() as $user_info ) { - $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content ); - } + if ( ! $this->include_user_info ) { + return; + } + + foreach ( $this->entry_values->get_user_info() as $user_info ) { + $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content ); } } diff --git a/classes/models/FrmEntryValidate.php b/classes/models/FrmEntryValidate.php index ddc08f6e8d..2558d9cf6a 100644 --- a/classes/models/FrmEntryValidate.php +++ b/classes/models/FrmEntryValidate.php @@ -91,11 +91,13 @@ private static function maybe_fix_item_meta() { */ private static function set_item_key( &$values ) { // phpcs:ignore Universal.Operators.StrictComparisons - if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) { - global $wpdb; - $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); - $_POST['item_key'] = $values['item_key']; + if ( isset( $values['item_key'] ) && $values['item_key'] != '' ) { + return; } + + global $wpdb; + $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); + $_POST['item_key'] = $values['item_key']; } /** diff --git a/classes/models/FrmField.php b/classes/models/FrmField.php index 8ce59c98d2..8e53173bfe 100644 --- a/classes/models/FrmField.php +++ b/classes/models/FrmField.php @@ -690,13 +690,15 @@ public static function update( $id, $values ) { // Serialize array values foreach ( array( 'field_options', 'options' ) as $opt ) { - if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) { - if ( 'field_options' === $opt ) { - $values[ $opt ] = self::maybe_filter_options( $values[ $opt ] ); - } + if ( ! isset( $values[ $opt ] ) || ! is_array( $values[ $opt ] ) ) { + continue; + } - $values[ $opt ] = serialize( $values[ $opt ] ); + if ( 'field_options' === $opt ) { + $values[ $opt ] = self::maybe_filter_options( $values[ $opt ] ); } + + $values[ $opt ] = serialize( $values[ $opt ] ); } if ( isset( $values['default_value'] ) && is_array( $values['default_value'] ) ) { @@ -1001,15 +1003,17 @@ public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'ex * @return void */ private static function maybe_include_repeating_fields( $inc_repeat, &$where ) { - if ( $inc_repeat === 'include' ) { - $form_id = $where['fi.form_id']; - $where[] = array( - 'or' => 1, - 'fi.form_id' => $form_id, - 'fr.parent_form_id' => $form_id, - ); - unset( $where['fi.form_id'] ); + if ( $inc_repeat !== 'include' ) { + return; } + + $form_id = $where['fi.form_id']; + $where[] = array( + 'or' => 1, + 'fi.form_id' => $form_id, + 'fr.parent_form_id' => $form_id, + ); + unset( $where['fi.form_id'] ); } /** diff --git a/classes/models/FrmFieldFormHtml.php b/classes/models/FrmFieldFormHtml.php index f4d66b04db..32ca4f120f 100644 --- a/classes/models/FrmFieldFormHtml.php +++ b/classes/models/FrmFieldFormHtml.php @@ -361,15 +361,17 @@ private function replace_required_class() { * @return void */ private function replace_form_shortcodes() { - if ( $this->form ) { - $form = (array) $this->form; + if ( ! $this->form ) { + return; + } - // Replace [form_key]. - $this->html = str_replace( '[form_key]', $form['form_key'], $this->html ); + $form = (array) $this->form; - // Replace [form_name]. - $this->html = str_replace( '[form_name]', $form['name'], $this->html ); - } + // Replace [form_key]. + $this->html = str_replace( '[form_key]', $form['form_key'], $this->html ); + + // Replace [form_name]. + $this->html = str_replace( '[form_name]', $form['name'], $this->html ); } /** diff --git a/classes/models/FrmFieldValue.php b/classes/models/FrmFieldValue.php index b88724f333..1768c375a0 100644 --- a/classes/models/FrmFieldValue.php +++ b/classes/models/FrmFieldValue.php @@ -223,10 +223,12 @@ public function get_displayed_value() { * @return void */ protected function generate_displayed_value_for_field_type( $atts ) { - if ( ! FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) { - $field_obj = FrmFieldFactory::get_field_object( $this->field ); - $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts ); + if ( FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) { + return; } + + $field_obj = FrmFieldFactory::get_field_object( $this->field ); + $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts ); } /** diff --git a/classes/models/FrmForm.php b/classes/models/FrmForm.php index f2ce1e152b..a3c9721079 100644 --- a/classes/models/FrmForm.php +++ b/classes/models/FrmForm.php @@ -407,10 +407,12 @@ public static function update_fields( $id, $values ) { // phpcs:ignore SlevomatC if ( ! FrmAppHelper::allow_unfiltered_html() && isset( $values['field_options'][ 'options_' . $field_id ] ) && is_array( $values['field_options'][ 'options_' . $field_id ] ) ) { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong foreach ( $values['field_options'][ 'options_' . $field_id ] as $option_key => $option ) { - if ( is_array( $option ) ) { - foreach ( $option as $key => $item ) { - $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' ); - } + if ( ! is_array( $option ) ) { + continue; + } + + foreach ( $option as $key => $item ) { + $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' ); } } } @@ -439,17 +441,19 @@ public static function update_fields( $id, $values ) { // phpcs:ignore SlevomatC * @return void */ private static function maybe_update_max_option( $field, $values, &$new_field ) { - if ( $field->type === 'textarea' && - ! empty( $values['field_options'][ 'type_' . $field->id ] ) && - in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) { - $new_field['field_options']['max'] = ''; - - /** - * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads. - * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting. - */ - $_POST['field_options'][ 'max_' . $field->id ] = ''; + if ( $field->type !== 'textarea' || + empty( $values['field_options'][ 'type_' . $field->id ] ) || + ! in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) { + return; } + + $new_field['field_options']['max'] = ''; + + /** + * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads. + * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting. + */ + $_POST['field_options'][ 'max_' . $field->id ] = ''; } /** diff --git a/classes/models/FrmFormAction.php b/classes/models/FrmFormAction.php index 90c2ab80d2..0f0ec7d1f7 100644 --- a/classes/models/FrmFormAction.php +++ b/classes/models/FrmFormAction.php @@ -801,12 +801,14 @@ public function prepare_action( $action ) { $action->post_content += $default_values; foreach ( $default_values as $k => $vals ) { - if ( is_array( $vals ) && $vals ) { - if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { - continue; - } - $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); + if ( ! is_array( $vals ) || ! $vals ) { + continue; } + + if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { + continue; + } + $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); } if ( ! is_array( $action->post_content['event'] ) ) { @@ -907,10 +909,12 @@ public function migrate_to_2( $form, $update = 'update' ) { // Fill with existing options foreach ( $action->post_content as $name => $val ) { - if ( isset( $form->options[ $name ] ) ) { - $action->post_content[ $name ] = $form->options[ $name ]; - unset( $form->options[ $name ] ); + if ( ! isset( $form->options[ $name ] ) ) { + continue; } + + $action->post_content[ $name ] = $form->options[ $name ]; + unset( $form->options[ $name ] ); } $action = $this->migrate_values( $action, $form ); diff --git a/classes/models/FrmInbox.php b/classes/models/FrmInbox.php index 008a4428a8..348e769434 100644 --- a/classes/models/FrmInbox.php +++ b/classes/models/FrmInbox.php @@ -400,10 +400,12 @@ public function unread_html( $filtered = true ) { * @return void */ public function remove( $key ) { - if ( isset( self::$messages[ $key ] ) ) { - unset( self::$messages[ $key ] ); - $this->update_list(); + if ( ! isset( self::$messages[ $key ] ) ) { + return; } + + unset( self::$messages[ $key ] ); + $this->update_list(); } /** diff --git a/classes/models/FrmMigrate.php b/classes/models/FrmMigrate.php index d4562c7321..1432ad6c7c 100644 --- a/classes/models/FrmMigrate.php +++ b/classes/models/FrmMigrate.php @@ -385,10 +385,12 @@ private function migrate_data( $old_db_version ) { $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 ); foreach ( $migrations as $migration ) { - if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { - $function_name = 'migrate_to_' . $migration; - $this->$function_name(); + if ( FrmAppHelper::$db_version < $migration || $old_db_version >= $migration ) { + continue; } + + $function_name = 'migrate_to_' . $migration; + $this->$function_name(); } } diff --git a/classes/models/FrmPluginSearch.php b/classes/models/FrmPluginSearch.php index 039db6f66d..b146effadd 100644 --- a/classes/models/FrmPluginSearch.php +++ b/classes/models/FrmPluginSearch.php @@ -34,13 +34,15 @@ public function __construct() { */ public function start( $screen ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - if ( 'plugin-install' === $screen->base && ( ! isset( $_GET['paged'] ) || 1 === intval( $_GET['paged'] ) ) ) { - add_filter( 'plugins_api_result', array( $this, 'inject_suggestion' ), 10, 3 ); - add_filter( 'self_admin_url', array( $this, 'plugin_details' ) ); - add_filter( 'plugin_install_action_links', array( $this, 'insert_related_links' ), 10, 2 ); - add_action( 'admin_enqueue_scripts', array( $this, 'load_plugins_search_script' ) ); - $this->maybe_dismiss(); + if ( 'plugin-install' !== $screen->base || ( isset( $_GET['paged'] ) && 1 !== intval( $_GET['paged'] ) ) ) { + return; } + + add_filter( 'plugins_api_result', array( $this, 'inject_suggestion' ), 10, 3 ); + add_filter( 'self_admin_url', array( $this, 'plugin_details' ) ); + add_filter( 'plugin_install_action_links', array( $this, 'insert_related_links' ), 10, 2 ); + add_action( 'admin_enqueue_scripts', array( $this, 'load_plugins_search_script' ) ); + $this->maybe_dismiss(); } /** diff --git a/classes/models/FrmSettings.php b/classes/models/FrmSettings.php index 221da2398f..88b1208426 100644 --- a/classes/models/FrmSettings.php +++ b/classes/models/FrmSettings.php @@ -510,13 +510,15 @@ public function translatable_strings() { * @return void */ public function maybe_filter_for_form( $args ) { - if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) { - $this->current_form = $args['current_form']; + if ( ! isset( $args['current_form'] ) || ! is_numeric( $args['current_form'] ) ) { + return; + } - foreach ( $this->translatable_strings() as $string ) { - $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this ); - $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this ); - } + $this->current_form = $args['current_form']; + + foreach ( $this->translatable_strings() as $string ) { + $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this ); + $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this ); } } diff --git a/classes/models/FrmTableHTMLGenerator.php b/classes/models/FrmTableHTMLGenerator.php index 6b1fe824e0..6ef76af415 100644 --- a/classes/models/FrmTableHTMLGenerator.php +++ b/classes/models/FrmTableHTMLGenerator.php @@ -204,13 +204,15 @@ private function init_table_style() { * @return void */ private function init_td_style() { - if ( $this->use_inline_style === true ) { - $td_style_attributes = 'text-align:' . ( $this->direction === 'rtl' ? 'right' : 'left' ) . ';'; - $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:' . $this->cell_padding . ';vertical-align:top;'; - $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';'; - - $this->td_style = ' style="' . esc_attr( $td_style_attributes ) . '"'; + if ( $this->use_inline_style !== true ) { + return; } + + $td_style_attributes = 'text-align:' . ( $this->direction === 'rtl' ? 'right' : 'left' ) . ';'; + $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:' . $this->cell_padding . ';vertical-align:top;'; + $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';'; + + $this->td_style = ' style="' . esc_attr( $td_style_attributes ) . '"'; } /** diff --git a/classes/models/FrmUsage.php b/classes/models/FrmUsage.php index 7054422427..2d3c86acd4 100644 --- a/classes/models/FrmUsage.php +++ b/classes/models/FrmUsage.php @@ -482,25 +482,28 @@ private function forms() { ); foreach ( $settings as $setting ) { - if ( isset( $form->options[ $setting ] ) ) { - if ( 'custom_style' === $setting ) { - $style->id = $form->options[ $setting ]; - - if ( ! $style->id ) { - $style_name = 0; - } elseif ( 1 === intval( $style->id ) ) { - $style_name = 'formidable-style'; - } else { - $style_post = $style->get_one(); - $style_name = $style_post ? $style_post->post_name : 'formidable-style'; - } - - $new_form[ $setting ] = $style_name; - } else { - $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] ); - } + if ( ! isset( $form->options[ $setting ] ) ) { + continue; } - } + + if ( 'custom_style' !== $setting ) { + $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] ); + continue; + } + + $style->id = $form->options[ $setting ]; + + if ( ! $style->id ) { + $style_name = 0; + } elseif ( 1 === intval( $style->id ) ) { + $style_name = 'formidable-style'; + } else { + $style_post = $style->get_one(); + $style_name = $style_post ? $style_post->post_name : 'formidable-style'; + } + + $new_form[ $setting ] = $style_name; + }//end foreach $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) ); }//end foreach diff --git a/classes/models/fields/FrmFieldCombo.php b/classes/models/fields/FrmFieldCombo.php index d418ee5d0d..f9523d9cd6 100644 --- a/classes/models/fields/FrmFieldCombo.php +++ b/classes/models/fields/FrmFieldCombo.php @@ -444,10 +444,12 @@ public function validate( $args ) { // Validate not empty. foreach ( $sub_fields as $name => $sub_field ) { - if ( empty( $sub_field['optional'] ) && empty( $args['value'][ $name ] ) ) { - $errors[ 'field' . $args['id'] . '-' . $name ] = ''; - $errors[ 'field' . $args['id'] ] = $blank_msg; + if ( ! empty( $sub_field['optional'] ) || ! empty( $args['value'][ $name ] ) ) { + continue; } + + $errors[ 'field' . $args['id'] . '-' . $name ] = ''; + $errors[ 'field' . $args['id'] ] = $blank_msg; } return $errors; diff --git a/classes/models/fields/FrmFieldNumber.php b/classes/models/fields/FrmFieldNumber.php index ed64b243b4..4598612430 100644 --- a/classes/models/fields/FrmFieldNumber.php +++ b/classes/models/fields/FrmFieldNumber.php @@ -166,10 +166,12 @@ protected function check_value_is_valid_with_step( $value, $step ) { * @return void */ private function remove_commas_from_number( &$args ) { - if ( str_contains( $args['value'], ',' ) ) { - $args['value'] = str_replace( ',', '', $args['value'] ); - FrmEntriesHelper::set_posted_value( $this->field, $args['value'], $args ); + if ( ! str_contains( $args['value'], ',' ) ) { + return; } + + $args['value'] = str_replace( ',', '', $args['value'] ); + FrmEntriesHelper::set_posted_value( $this->field, $args['value'], $args ); } /** diff --git a/classes/models/fields/FrmFieldType.php b/classes/models/fields/FrmFieldType.php index 2fdc8ebcb6..a7cc7d0dd2 100644 --- a/classes/models/fields/FrmFieldType.php +++ b/classes/models/fields/FrmFieldType.php @@ -129,12 +129,14 @@ public function __get( $key ) { * @return void */ protected function set_type( $type ) { - if ( ! $this->type ) { - $this->type = $this->get_field_column( 'type' ); + if ( $this->type ) { + return; + } - if ( ! $this->type && $type ) { - $this->type = $type; - } + $this->type = $this->get_field_column( 'type' ); + + if ( ! $this->type && $type ) { + $this->type = $type; } } @@ -1875,10 +1877,12 @@ protected function get_multi_opts_for_import( $value ) { $options = array_reverse( $options ); foreach ( $options as $option ) { - if ( isset( $option['value'] ) && str_contains( $filtered_checked, $option['value'] ) ) { - $csv_values_checked[] = $option['value']; - $filtered_checked = str_replace( $option['value'], '', $filtered_checked ); + if ( ! isset( $option['value'] ) || ! str_contains( $filtered_checked, $option['value'] ) ) { + continue; } + + $csv_values_checked[] = $option['value']; + $filtered_checked = str_replace( $option['value'], '', $filtered_checked ); } $csv_values_checked = array_reverse( $csv_values_checked ); diff --git a/phpcs.xml b/phpcs.xml index cd3fcac9ae..20af048a87 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -168,7 +168,6 @@ - diff --git a/stripe/helpers/FrmTransLiteAppHelper.php b/stripe/helpers/FrmTransLiteAppHelper.php index 66192042e2..561d6c30c2 100755 --- a/stripe/helpers/FrmTransLiteAppHelper.php +++ b/stripe/helpers/FrmTransLiteAppHelper.php @@ -389,18 +389,20 @@ public static function get_user_link( $user_id ) { * @return void */ public static function show_in_table( $value, $label ) { - if ( $value ) { - // phpcs:disable Generic.WhiteSpace.ScopeIndent - ?> - - : - - - - - + + : + + + + + default_options(); foreach ( $settings as $setting => $default ) { - if ( isset( $params[ 'frm_' . $this->param() . '_' . $setting ] ) ) { - $value = $params[ 'frm_' . $this->param() . '_' . $setting ]; + if ( ! isset( $params[ 'frm_' . $this->param() . '_' . $setting ] ) ) { + continue; + } - // Clean up any accumulated backslashes from previous bug. - // @see https://github.com/Strategy11/formidable-pro/issues/6294 - if ( 'processing_message' === $setting ) { - $value = str_replace( '\\', '', $value ); - } + $value = $params[ 'frm_' . $this->param() . '_' . $setting ]; - $this->settings->{$setting} = sanitize_text_field( $value ); + // Clean up any accumulated backslashes from previous bug. + // @see https://github.com/Strategy11/formidable-pro/issues/6294 + if ( 'processing_message' === $setting ) { + $value = str_replace( '\\', '', $value ); } + + $this->settings->{$setting} = sanitize_text_field( $value ); } $this->settings->test_mode = isset( $params['frm_strp_test_mode'] ) ? absint( $params['frm_strp_test_mode'] ) : 0; diff --git a/stripe/models/FrmTransLiteDb.php b/stripe/models/FrmTransLiteDb.php index 8d3c805b39..b50120b690 100755 --- a/stripe/models/FrmTransLiteDb.php +++ b/stripe/models/FrmTransLiteDb.php @@ -313,10 +313,12 @@ private function migrate_data( $old_db_version ) { $migrations = array( 4 ); foreach ( $migrations as $migration ) { - if ( $this->db_version >= $migration && $old_db_version < $migration ) { - $function_name = 'migrate_to_' . $migration; - $this->$function_name(); + if ( $this->db_version < $migration || $old_db_version >= $migration ) { + continue; } + + $function_name = 'migrate_to_' . $migration; + $this->$function_name(); } } diff --git a/tests/phpunit/test_wordpress_plugin_tests.php b/tests/phpunit/test_wordpress_plugin_tests.php index 1147f0667d..94e6caf08b 100644 --- a/tests/phpunit/test_wordpress_plugin_tests.php +++ b/tests/phpunit/test_wordpress_plugin_tests.php @@ -7,11 +7,13 @@ public function test_plugin_activated() { } public function test_wpml_install() { - if ( is_callable( 'FrmProCopy::install' ) ) { - $copy = new FrmProCopy(); - $copy->install(); - self::do_tables_exist( true ); + if ( ! is_callable( 'FrmProCopy::install' ) ) { + return; } + + $copy = new FrmProCopy(); + $copy->install(); + self::do_tables_exist( true ); } }