From 0ade48c6a71d34316273ec06719eed0f2944f10c Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 13 May 2024 13:36:54 -0300 Subject: [PATCH 1/3] Add some comments to forms controller --- classes/controllers/FrmFormsController.php | 51 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/classes/controllers/FrmFormsController.php b/classes/controllers/FrmFormsController.php index b94f69b15b..a3461c15a2 100644 --- a/classes/controllers/FrmFormsController.php +++ b/classes/controllers/FrmFormsController.php @@ -447,6 +447,8 @@ private static function set_post_global( $page ) { /** * @since 3.0 + * + * @return void */ private static function load_theme_preview() { add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 ); @@ -480,6 +482,8 @@ public static function preview_block_theme_body_classnames( $classes ) { /** * Not every theme supports get_template_part( 'page' ). * When this is not supported, false is returned, and we can handle a fallback. + * + * @return void */ private static function fallback_when_page_template_part_is_not_supported_by_theme() { if ( have_posts() ) { @@ -551,9 +555,12 @@ public static function preview_page_title( $title ) { } /** - * Set the page title for the theme preview page + * Set the page title for the theme preview page. * * @since 3.0 + * + * @param string $title + * @return string */ public static function preview_title( $title ) { return __( 'Form Preview', 'formidable' ); @@ -716,6 +723,10 @@ public static function change_form_status( $status ) { self::display_forms_list( $params, $message ); } + /** + * @param array $ids + * @return string + */ public static function bulk_trash( $ids ) { FrmAppHelper::permission_check( 'frm_delete_forms' ); @@ -762,6 +773,10 @@ public static function destroy() { self::display_forms_list( $params, $message ); } + /** + * @param array $ids + * @return string + */ public static function bulk_destroy( $ids ) { FrmAppHelper::permission_check( 'frm_delete_forms' ); @@ -851,6 +866,8 @@ public static function build_new_form() { * Before creating a new form, get the name and description from the modal. * * @since 4.0 + * + * @return array */ public static function get_modal_values() { $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); @@ -867,6 +884,8 @@ public static function get_modal_values() { * Hook exists since 2.5.0 * * @since 2.0.15 + * + * @return void */ public static function insert_form_button() { if ( current_user_can( 'frm_view_forms' ) ) { @@ -1035,6 +1054,9 @@ public static function get_columns( $columns ) { return $columns; } + /** + * @return array + */ public static function get_sortable_columns() { return array( 'id' => 'id', @@ -1077,6 +1099,13 @@ public static function save_per_page( $save, $option, $value ) { return $save; } + /** + * @param int|string $id + * @param array $errors + * @param string $message + * @param bool $create_link + * @return void + */ private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { global $frm_vars; @@ -1162,6 +1191,10 @@ private static function get_edit_vars( $id, $errors = array(), $message = '', $c require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php'; } + /** + * @param array $fields + * @return array + */ public static function update_form_builder_fields( $fields, $form ) { foreach ( $fields as $field ) { $field->do_not_include_icons = true; @@ -1175,6 +1208,12 @@ public static function maybe_update_form_builder_message( &$message ) { } } + /** + * @param int|string $id + * @param array $errors + * @param array|string $args + * @return void + */ public static function get_settings_vars( $id, $errors = array(), $args = array() ) { FrmAppHelper::permission_check( 'frm_edit_forms' ); @@ -1464,7 +1503,7 @@ private static function advanced_helpers( $atts ) { ); $user_fields = self::user_shortcodes(); - if ( ! empty( $user_fields ) ) { + if ( $user_fields ) { $user_helpers = array(); foreach ( $user_fields as $uk => $uf ) { $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf; @@ -1691,6 +1730,10 @@ public static function replace_content_shortcodes( $content, $entry, $shortcodes return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); } + /** + * @param array $errors + * @return array + */ public static function process_bulk_form_actions( $errors ) { if ( ! $_REQUEST ) { return $errors; @@ -1758,7 +1801,7 @@ public static function route() { if ( empty( $json_vars ) ) { // json decoding failed so we should return an error message. $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); - if ( 'edit' == $action ) { + if ( 'edit' === $action ) { $action = 'update'; } @@ -1991,7 +2034,7 @@ private static function add_forms_to_admin_bar( $actions ) { */ public static function get_form_shortcode( $atts ) { global $frm_vars; - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) { + if ( ! empty( $frm_vars['skip_shortcode'] ) ) { $sc = '[formidable'; $sc .= FrmAppHelper::array_to_html_params( $atts ); return $sc . ']'; From 03351f3846e95223f443d14c24f19bf4932eb5c5 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 13 May 2024 13:40:28 -0300 Subject: [PATCH 2/3] Clean up more --- classes/controllers/FrmFormsController.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/classes/controllers/FrmFormsController.php b/classes/controllers/FrmFormsController.php index a3461c15a2..df70af8726 100644 --- a/classes/controllers/FrmFormsController.php +++ b/classes/controllers/FrmFormsController.php @@ -164,12 +164,15 @@ private static function create_submit_button_field( $form ) { ); } + /** + * @return void + */ public static function edit( $values = false ) { FrmAppHelper::permission_check( 'frm_edit_forms' ); $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); - return self::get_edit_vars( $id ); + self::get_edit_vars( $id ); } public static function settings( $id = false, $message = '' ) { @@ -233,6 +236,9 @@ private static function antispam_was_on( $form_id ) { return ! empty( $form->options['antispam'] ); } + /** + * @return void + */ public static function update( $values = array() ) { if ( empty( $values ) ) { $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing @@ -252,7 +258,8 @@ public static function update( $values = array() ) { $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); if ( count( $errors ) > 0 ) { - return self::get_edit_vars( $id, $errors ); + self::get_edit_vars( $id, $errors ); + return; } self::maybe_remove_draft_option_from_fields( $id ); @@ -273,7 +280,7 @@ public static function update( $values = array() ) { wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } - return self::get_edit_vars( $id, array(), $message ); + self::get_edit_vars( $id, array(), $message ); } /** From a7d565e93a8f024ad1a8923f49bdeb4fdfe36aeb Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 13 May 2024 13:42:13 -0300 Subject: [PATCH 3/3] Clean up more --- classes/controllers/FrmFormsController.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/classes/controllers/FrmFormsController.php b/classes/controllers/FrmFormsController.php index df70af8726..49de781bdc 100644 --- a/classes/controllers/FrmFormsController.php +++ b/classes/controllers/FrmFormsController.php @@ -175,6 +175,11 @@ public static function edit( $values = false ) { self::get_edit_vars( $id ); } + /** + * @param mixed $id + * @param string $message + * @return void + */ public static function settings( $id = false, $message = '' ) { FrmAppHelper::permission_check( 'frm_edit_forms' ); @@ -184,7 +189,7 @@ public static function settings( $id = false, $message = '' ) { FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id ); - return self::get_settings_vars( $id, array(), $message ); + self::get_settings_vars( $id, array(), $message ); } public static function update_settings() { @@ -208,7 +213,8 @@ public static function update_settings() { $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( count( $errors ) > 0 ) { - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); + self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); + return; } do_action( 'frm_before_update_form_settings', $id ); @@ -224,7 +230,7 @@ public static function update_settings() { $message = __( 'Settings Successfully Updated', 'formidable' ); - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); } /**