| @@ -4,16 +4,23 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmEntriesController { |
| 7 | 7 | |
| 8 | + /** | |
| 9 | + * @return void | |
| 10 | + */ | |
| 8 | 11 | public static function menu() { |
| 9 | 12 | FrmAppHelper::force_capability( 'frm_view_entries' ); |
| 10 | 13 | |
| 11 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); | |
| 14 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 12 | 15 | |
| 13 | - $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed(); | |
| 14 | - if ( ! $views_installed ) { | |
| 15 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' ); | |
| 16 | + $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed(); | |
| 17 | + | |
| 18 | + if ( $views_installed ) { | |
| 19 | + self::maybe_redirect_to_views_index(); | |
| 20 | + } else { | |
| 21 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 22 | + self::maybe_redirect_to_views_upsell(); | |
| 16 | 23 | } |
| 17 | 24 | |
| 18 | 25 | if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) { |
| 19 | 26 | self::load_manage_entries_hooks(); |
| @@ -20,24 +27,98 @@ | ||
| 20 | 27 | } |
| 21 | 28 | } |
| 22 | 29 | |
| 23 | 30 | /** |
| 31 | + * This function is called when views is installed. | |
| 32 | + * The Views add-on uses a different URL for the Views tab than the upsell page. | |
| 33 | + * If the user is on the upsell page, instead of showing a permission error on reload, | |
| 34 | + * redirect to the views index page. | |
| 35 | + * | |
| 36 | + * @since 6.14.1 | |
| 37 | + * | |
| 38 | + * @return void | |
| 39 | + */ | |
| 40 | + private static function maybe_redirect_to_views_index() { | |
| 41 | + if ( ! FrmAppHelper::is_admin_page( 'formidable-views' ) ) { | |
| 42 | + return; | |
| 43 | + } | |
| 44 | + | |
| 45 | + $query_args = array( | |
| 46 | + 'post_type' => 'frm_display', | |
| 47 | + ); | |
| 48 | + $query_args = self::add_url_params_to_views_redirect_query_args( $query_args ); | |
| 49 | + | |
| 50 | + wp_safe_redirect( add_query_arg( $query_args, admin_url( 'edit.php' ) ) ); | |
| 51 | + die(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * This function is called when views is inactive. | |
| 56 | + * A user may deactivate views but then try to reload the views index. | |
| 57 | + * Instead of showing a permission error, redirect to the views upsell page. | |
| 58 | + * | |
| 59 | + * @since 6.14.1 | |
| 60 | + * | |
| 61 | + * @return void | |
| 62 | + */ | |
| 63 | + private static function maybe_redirect_to_views_upsell() { | |
| 64 | + global $pagenow; | |
| 65 | + | |
| 66 | + if ( 'edit.php' !== $pagenow || 'frm_display' !== FrmAppHelper::simple_get( 'post_type' ) ) { | |
| 67 | + return; | |
| 68 | + } | |
| 69 | + | |
| 70 | + $query_args = array( | |
| 71 | + 'page' => 'formidable-views', | |
| 72 | + ); | |
| 73 | + $query_args = self::add_url_params_to_views_redirect_query_args( $query_args ); | |
| 74 | + | |
| 75 | + wp_safe_redirect( add_query_arg( $query_args, admin_url( 'admin.php' ) ) ); | |
| 76 | + die(); | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * @since 6.14.1 | |
| 81 | + * | |
| 82 | + * @param array $query_args | |
| 83 | + * | |
| 84 | + * @return array | |
| 85 | + */ | |
| 86 | + private static function add_url_params_to_views_redirect_query_args( $query_args ) { | |
| 87 | + $query_args['show_nav'] = FrmAppHelper::simple_get( 'show_nav', 'absint', 0 ); | |
| 88 | + $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 ); | |
| 89 | + | |
| 90 | + if ( $form_id ) { | |
| 91 | + $query_args['form'] = $form_id; | |
| 92 | + } | |
| 93 | + | |
| 94 | + return $query_args; | |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 24 | 98 | * @since 2.05.07 |
| 99 | + * | |
| 100 | + * @return void | |
| 25 | 101 | */ |
| 26 | 102 | private static function load_manage_entries_hooks() { |
| 27 | - if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) { | |
| 28 | - $menu_name = FrmAppHelper::get_menu_name(); | |
| 29 | - $base = self::base_column_key( $menu_name ); | |
| 103 | + if ( in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) { | |
| 104 | + add_filter( 'screen_options_show_screen', self::class . '::remove_screen_options', 10, 2 ); | |
| 105 | + return; | |
| 106 | + } | |
| 30 | 107 | |
| 31 | - add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' ); | |
| 32 | - add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' ); | |
| 33 | - add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' ); | |
| 34 | - } else { | |
| 35 | - add_filter( 'screen_options_show_screen', __CLASS__ . '::remove_screen_options', 10, 2 ); | |
| 36 | - } | |
| 108 | + $menu_name = FrmAppHelper::get_menu_name(); | |
| 109 | + $base = self::base_column_key( $menu_name ); | |
| 110 | + | |
| 111 | + add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' ); | |
| 112 | + add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' ); | |
| 113 | + add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' ); | |
| 37 | 114 | } |
| 38 | 115 | |
| 39 | - /* Display in Back End */ | |
| 116 | + /** | |
| 117 | + * Display in Back End. | |
| 118 | + * | |
| 119 | + * @return mixed | |
| 120 | + */ | |
| 40 | 121 | public static function route() { |
| 41 | 122 | $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' ); |
| 42 | 123 | FrmAppHelper::include_svg(); |
| 43 | 124 | |
| @@ -47,13 +128,15 @@ | ||
| 47 | 128 | return self::$action(); |
| 48 | 129 | |
| 49 | 130 | default: |
| 50 | 131 | do_action( 'frm_entry_action_route', $action ); |
| 132 | + | |
| 51 | 133 | if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) { |
| 52 | - return; | |
| 134 | + return null; | |
| 53 | 135 | } |
| 54 | 136 | |
| 55 | - return self::display_list(); | |
| 137 | + self::display_list(); | |
| 138 | + return null; | |
| 56 | 139 | } |
| 57 | 140 | } |
| 58 | 141 | |
| 59 | 142 | /** |
| @@ -60,18 +143,30 @@ | ||
| 60 | 143 | * Prevent the "screen options" tab from showing when |
| 61 | 144 | * editing or creating an entry |
| 62 | 145 | * |
| 63 | 146 | * @since 3.0 |
| 147 | + * | |
| 148 | + * @param bool $show_screen Whether to show the screen options tab. | |
| 149 | + * @param object $screen The current screen object. | |
| 150 | + * | |
| 151 | + * @return bool | |
| 64 | 152 | */ |
| 65 | 153 | public static function remove_screen_options( $show_screen, $screen ) { |
| 66 | - $menu_name = sanitize_title( FrmAppHelper::get_menu_name() ); | |
| 67 | - if ( $screen->id == $menu_name . '_page_formidable-entries' ) { | |
| 68 | - $show_screen = false; | |
| 154 | + $menu_name = sanitize_title( FrmAppHelper::get_menu_name() ); | |
| 155 | + $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); | |
| 156 | + | |
| 157 | + if ( $screen->id === $menu_name . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries' ) { | |
| 158 | + return false; | |
| 69 | 159 | } |
| 70 | 160 | |
| 71 | 161 | return $show_screen; |
| 72 | 162 | } |
| 73 | 163 | |
| 164 | + /** | |
| 165 | + * @param array $columns | |
| 166 | + * | |
| 167 | + * @return array | |
| 168 | + */ | |
| 74 | 169 | public static function manage_columns( $columns ) { |
| 75 | 170 | global $frm_vars; |
| 76 | 171 | $form_id = FrmForm::get_current_form_id(); |
| 77 | 172 | |
| @@ -80,25 +175,26 @@ | ||
| 80 | 175 | |
| 81 | 176 | if ( $form_id ) { |
| 82 | 177 | self::get_columns_for_form( $form_id, $columns ); |
| 83 | 178 | } else { |
| 84 | - $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' ); | |
| 85 | - $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' ); | |
| 86 | - $columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' ); | |
| 179 | + $columns[ $form_id . '_form_id' ] = esc_html__( 'Form', 'formidable' ); | |
| 180 | + $columns[ $form_id . '_name' ] = esc_html__( 'Entry Name', 'formidable' ); | |
| 181 | + $columns[ $form_id . '_user_id' ] = esc_html__( 'Created By', 'formidable' ); | |
| 87 | 182 | } |
| 88 | 183 | |
| 89 | - $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' ); | |
| 90 | - $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' ); | |
| 184 | + $columns[ $form_id . '_is_draft' ] = esc_html__( 'Entry Status', 'formidable' ); | |
| 185 | + $columns[ $form_id . '_created_at' ] = esc_html__( 'Entry creation date', 'formidable' ); | |
| 186 | + $columns[ $form_id . '_updated_at' ] = esc_html__( 'Entry update date', 'formidable' ); | |
| 91 | 187 | self::maybe_add_ip_col( $form_id, $columns ); |
| 92 | 188 | |
| 93 | 189 | $frm_vars['cols'] = $columns; |
| 190 | + $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); | |
| 94 | 191 | |
| 95 | - $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); | |
| 96 | - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) { | |
| 192 | + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ), true ) ) { | |
| 97 | 193 | add_screen_option( |
| 98 | 194 | 'per_page', |
| 99 | 195 | array( |
| 100 | - 'label' => __( 'Entries', 'formidable' ), | |
| 196 | + 'label' => esc_html__( 'Entries', 'formidable' ), | |
| 101 | 197 | 'default' => 20, |
| 102 | 198 | 'option' => 'formidable_page_formidable_entries_per_page', |
| 103 | 199 | ) |
| 104 | 200 | ); |
| @@ -106,8 +202,14 @@ | ||
| 106 | 202 | |
| 107 | 203 | return $columns; |
| 108 | 204 | } |
| 109 | 205 | |
| 206 | + /** | |
| 207 | + * @param int|string $form_id | |
| 208 | + * @param array $columns | |
| 209 | + * | |
| 210 | + * @return void | |
| 211 | + */ | |
| 110 | 212 | private static function get_columns_for_form( $form_id, &$columns ) { |
| 111 | 213 | $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' ); |
| 112 | 214 | |
| 113 | 215 | /** |
| @@ -124,9 +226,10 @@ | ||
| 124 | 226 | if ( FrmField::is_no_save_field( $form_col->type ) ) { |
| 125 | 227 | continue; |
| 126 | 228 | } |
| 127 | 229 | |
| 128 | - $has_child_fields = $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ); | |
| 230 | + $has_child_fields = $form_col->type === 'form' && ! empty( $form_col->field_options['form_select'] ); | |
| 231 | + | |
| 129 | 232 | if ( $has_child_fields ) { |
| 130 | 233 | self::add_subform_cols( $form_col, $form_id, $columns ); |
| 131 | 234 | } else { |
| 132 | 235 | self::add_field_cols( $form_col, $form_id, $columns ); |
| @@ -135,12 +238,19 @@ | ||
| 135 | 238 | } |
| 136 | 239 | |
| 137 | 240 | /** |
| 138 | 241 | * @since 3.01 |
| 242 | + * | |
| 243 | + * @param object $field The field object. | |
| 244 | + * @param int|string $form_id The form ID. | |
| 245 | + * @param array $columns The columns array. | |
| 246 | + * | |
| 247 | + * @return void | |
| 139 | 248 | */ |
| 140 | 249 | private static function add_subform_cols( $field, $form_id, &$columns ) { |
| 141 | 250 | $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] ); |
| 142 | - if ( empty( $sub_form_cols ) ) { | |
| 251 | + | |
| 252 | + if ( ! $sub_form_cols ) { | |
| 143 | 253 | return; |
| 144 | 254 | } |
| 145 | 255 | |
| 146 | 256 | foreach ( $sub_form_cols as $k => $sub_form_col ) { |
| @@ -147,8 +257,9 @@ | ||
| 147 | 257 | if ( FrmField::is_no_save_field( $sub_form_col->type ) ) { |
| 148 | 258 | unset( $sub_form_cols[ $k ] ); |
| 149 | 259 | continue; |
| 150 | 260 | } |
| 261 | + | |
| 151 | 262 | $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $field->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
| 152 | 263 | unset( $sub_form_col ); |
| 153 | 264 | } |
| 154 | 265 | } |
| @@ -154,24 +265,62 @@ | ||
| 154 | 265 | } |
| 155 | 266 | |
| 156 | 267 | /** |
| 157 | 268 | * @since 3.01 |
| 269 | + * | |
| 270 | + * @param object $field The field object. | |
| 271 | + * @param int|string $form_id The form ID. | |
| 272 | + * @param array $columns The columns array. | |
| 273 | + * | |
| 274 | + * @return void | |
| 158 | 275 | */ |
| 159 | 276 | private static function add_field_cols( $field, $form_id, &$columns ) { |
| 160 | 277 | $col_id = $field->field_key; |
| 161 | - if ( $field->form_id != $form_id ) { | |
| 278 | + | |
| 279 | + if ( (int) $field->form_id !== (int) $form_id ) { | |
| 162 | 280 | $col_id .= '-_-form' . $field->form_id; |
| 163 | 281 | } |
| 164 | 282 | |
| 165 | - $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' ); | |
| 166 | - $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] == 'post_status'; | |
| 167 | - if ( $has_separate_value && ! $is_post_status ) { | |
| 168 | - $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 ); | |
| 283 | + $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' ); | |
| 284 | + $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status'; | |
| 285 | + $include_column_for_sep_val = $has_separate_value && ! $is_post_status; | |
| 286 | + | |
| 287 | + if ( $include_column_for_sep_val ) { | |
| 288 | + $columns[ $form_id . '_frmsep_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val ); | |
| 169 | 289 | } |
| 170 | 290 | |
| 171 | - $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 ); | |
| 291 | + $columns[ $form_id . '_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, false ); | |
| 172 | 292 | } |
| 173 | 293 | |
| 294 | + /** | |
| 295 | + * Appends "(Value)" or "(Label)" to the field name if it's an option field that has a separate value/label. | |
| 296 | + * | |
| 297 | + * @since 6.25.1 | |
| 298 | + * | |
| 299 | + * @param object $field | |
| 300 | + * @param bool $include_column_for_sep_val | |
| 301 | + * @param bool $is_value | |
| 302 | + * | |
| 303 | + * @return string | |
| 304 | + */ | |
| 305 | + private static function maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, $is_value = true ) { | |
| 306 | + $field_name = FrmAppHelper::truncate( $field->name, 35 ); | |
| 307 | + | |
| 308 | + if ( ! $include_column_for_sep_val || ! in_array( $field->type, array( 'select', 'radio', 'checkbox', 'product', 'ranking' ), true ) ) { | |
| 309 | + return $field_name; | |
| 310 | + } | |
| 311 | + | |
| 312 | + $append_text = $is_value ? esc_html__( 'value', 'formidable' ) : esc_html__( 'label', 'formidable' ); | |
| 313 | + | |
| 314 | + return sprintf( '%s (%s)', $field_name, $append_text ); | |
| 315 | + } | |
| 316 | + | |
| 317 | + /** | |
| 318 | + * @param int|string $form_id The form ID. | |
| 319 | + * @param array $columns The columns array. | |
| 320 | + * | |
| 321 | + * @return void | |
| 322 | + */ | |
| 174 | 323 | private static function maybe_add_ip_col( $form_id, &$columns ) { |
| 175 | 324 | if ( FrmAppHelper::ips_saved() ) { |
| 176 | 325 | $columns[ $form_id . '_ip' ] = 'IP'; |
| 177 | 326 | } |
| @@ -176,21 +325,32 @@ | ||
| 176 | 325 | $columns[ $form_id . '_ip' ] = 'IP'; |
| 177 | 326 | } |
| 178 | 327 | } |
| 179 | 328 | |
| 329 | + /** | |
| 330 | + * @param bool $check The check value. | |
| 331 | + * @param int $object_id The object ID. | |
| 332 | + * @param string $meta_key The meta key. | |
| 333 | + * @param mixed $meta_value The meta value. | |
| 334 | + * @param mixed $prev_value The previous value. | |
| 335 | + * | |
| 336 | + * @return bool | |
| 337 | + */ | |
| 180 | 338 | public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) { |
| 181 | 339 | $this_page_name = self::hidden_column_key(); |
| 340 | + | |
| 341 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 182 | 342 | if ( $meta_key != $this_page_name || $meta_value == $prev_value ) { |
| 183 | 343 | return $check; |
| 184 | 344 | } |
| 185 | 345 | |
| 186 | - if ( empty( $prev_value ) ) { | |
| 346 | + if ( ! $prev_value ) { | |
| 187 | 347 | $prev_value = get_metadata( 'user', $object_id, $meta_key, true ); |
| 188 | 348 | } |
| 189 | 349 | |
| 190 | 350 | global $frm_vars; |
| 191 | - //add a check so we don't create a loop | |
| 192 | - $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; | |
| 351 | + // Add a check so we don't create a loop. | |
| 352 | + $frm_vars['prev_hidden_cols'] = ! empty( $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; | |
| 193 | 353 | |
| 194 | 354 | return $check; |
| 195 | 355 | } |
| 196 | 356 | |
| @@ -195,23 +355,34 @@ | ||
| 195 | 355 | } |
| 196 | 356 | |
| 197 | 357 | /** |
| 198 | 358 | * Add hidden columns back from other forms |
| 359 | + * | |
| 360 | + * @param int $meta_id The meta ID. | |
| 361 | + * @param int $object_id The object ID. | |
| 362 | + * @param string $meta_key The meta key. | |
| 363 | + * @param array $meta_value The meta value. | |
| 364 | + * | |
| 365 | + * @return void | |
| 199 | 366 | */ |
| 200 | 367 | public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) { |
| 201 | 368 | $this_page_name = self::hidden_column_key(); |
| 369 | + | |
| 370 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 202 | 371 | if ( $meta_key != $this_page_name ) { |
| 203 | 372 | return; |
| 204 | 373 | } |
| 205 | 374 | |
| 206 | 375 | global $frm_vars; |
| 207 | - if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) { | |
| 208 | - return; // Don't continue if there's no previous value. | |
| 376 | + | |
| 377 | + if ( empty( $frm_vars['prev_hidden_cols'] ) ) { | |
| 378 | + // Don't continue if there's no previous value. | |
| 379 | + return; | |
| 209 | 380 | } |
| 210 | 381 | |
| 211 | 382 | foreach ( $meta_value as $mk => $mv ) { |
| 212 | 383 | // Remove blank values. |
| 213 | - if ( empty( $mv ) ) { | |
| 384 | + if ( ! $mv ) { | |
| 214 | 385 | unset( $meta_value[ $mk ] ); |
| 215 | 386 | } |
| 216 | 387 | } |
| 217 | 388 | |
| @@ -220,9 +391,10 @@ | ||
| 220 | 391 | $cur_form_prefix = $cur_form_prefix[0]; |
| 221 | 392 | $save = false; |
| 222 | 393 | |
| 223 | 394 | foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) { |
| 224 | - if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) { | |
| 395 | + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 396 | + if ( ! $prev_hidden || in_array( $prev_hidden, $meta_value ) ) { | |
| 225 | 397 | // Don't add blank cols or process included cols. |
| 226 | 398 | continue; |
| 227 | 399 | } |
| 228 | 400 | |
| @@ -227,9 +399,10 @@ | ||
| 227 | 399 | } |
| 228 | 400 | |
| 229 | 401 | $form_prefix = explode( '_', $prev_hidden ); |
| 230 | 402 | $form_prefix = $form_prefix[0]; |
| 231 | - if ( $form_prefix == $cur_form_prefix ) { | |
| 403 | + | |
| 404 | + if ( $form_prefix === $cur_form_prefix ) { | |
| 232 | 405 | // Don't add back columns that are meant to be hidden. |
| 233 | 406 | continue; |
| 234 | 407 | } |
| 235 | 408 | |
| @@ -237,42 +410,62 @@ | ||
| 237 | 410 | $save = true; |
| 238 | 411 | unset( $form_prefix ); |
| 239 | 412 | } |
| 240 | 413 | |
| 241 | - if ( $save ) { | |
| 242 | - $user_id = get_current_user_id(); | |
| 243 | - update_user_option( $user_id, $this_page_name, $meta_value, true ); | |
| 414 | + if ( ! $save ) { | |
| 415 | + return; | |
| 244 | 416 | } |
| 417 | + | |
| 418 | + update_user_option( get_current_user_id(), $this_page_name, $meta_value, true ); | |
| 245 | 419 | } |
| 246 | 420 | |
| 247 | 421 | /** |
| 248 | 422 | * @since 2.05.07 |
| 423 | + * | |
| 424 | + * @param string $menu_name | |
| 425 | + * | |
| 426 | + * @return string | |
| 249 | 427 | */ |
| 250 | 428 | private static function hidden_column_key( $menu_name = '' ) { |
| 251 | 429 | $base = self::base_column_key( $menu_name ); |
| 252 | - | |
| 253 | 430 | return 'manage' . $base . 'columnshidden'; |
| 254 | 431 | } |
| 255 | 432 | |
| 256 | 433 | /** |
| 257 | 434 | * @since 2.05.07 |
| 435 | + * | |
| 436 | + * @param string $menu_name | |
| 437 | + * | |
| 438 | + * @return string | |
| 258 | 439 | */ |
| 259 | 440 | private static function base_column_key( $menu_name = '' ) { |
| 260 | - if ( empty( $menu_name ) ) { | |
| 441 | + if ( ! $menu_name ) { | |
| 261 | 442 | $menu_name = FrmAppHelper::get_menu_name(); |
| 262 | 443 | } |
| 263 | 444 | |
| 264 | - return sanitize_title( $menu_name ) . '_page_formidable-entries'; | |
| 445 | + $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); | |
| 446 | + | |
| 447 | + return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries'; | |
| 265 | 448 | } |
| 266 | 449 | |
| 450 | + /** | |
| 451 | + * @param int $save | |
| 452 | + * @param string $option | |
| 453 | + * @param string $value | |
| 454 | + * | |
| 455 | + * @return int | |
| 456 | + */ | |
| 267 | 457 | public static function save_per_page( $save, $option, $value ) { |
| 268 | - if ( $option == 'formidable_page_formidable_entries_per_page' ) { | |
| 269 | - $save = (int) $value; | |
| 458 | + if ( $option === 'formidable_page_formidable_entries_per_page' ) { | |
| 459 | + return (int) $value; | |
| 270 | 460 | } |
| 271 | 461 | |
| 272 | 462 | return $save; |
| 273 | 463 | } |
| 274 | 464 | |
| 465 | + /** | |
| 466 | + * @return array | |
| 467 | + */ | |
| 275 | 468 | public static function sortable_columns() { |
| 276 | 469 | $form_id = FrmForm::get_current_form_id(); |
| 277 | 470 | $fields = FrmField::get_all_for_form( $form_id ); |
| 278 | 471 | |
| @@ -284,8 +477,14 @@ | ||
| 284 | 477 | $form_id . '_item_key' => 'item_key', |
| 285 | 478 | $form_id . '_is_draft' => 'is_draft', |
| 286 | 479 | ); |
| 287 | 480 | |
| 481 | + if ( ! $form_id ) { | |
| 482 | + $columns[ $form_id . '_user_id' ] = 'user_id'; | |
| 483 | + $columns[ $form_id . '_name' ] = 'name'; | |
| 484 | + $columns[ $form_id . '_form_id' ] = 'form_id'; | |
| 485 | + } | |
| 486 | + | |
| 288 | 487 | foreach ( $fields as $field ) { |
| 289 | 488 | if ( self::field_supports_sorting( $field ) ) { |
| 290 | 489 | $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id; |
| 291 | 490 | } |
| @@ -298,8 +497,9 @@ | ||
| 298 | 497 | * Can't sort on checkboxes because they are sorted serialized. |
| 299 | 498 | * Some post content can be sorted but not everything. |
| 300 | 499 | * |
| 301 | 500 | * @param stdClass $field |
| 501 | + * | |
| 302 | 502 | * @return bool |
| 303 | 503 | */ |
| 304 | 504 | private static function field_supports_sorting( $field ) { |
| 305 | 505 | $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] ); |
| @@ -307,11 +507,14 @@ | ||
| 307 | 507 | } |
| 308 | 508 | |
| 309 | 509 | /** |
| 310 | 510 | * @param mixed $result Option value from database for hidden columns in entries table. |
| 511 | + * | |
| 311 | 512 | * @return array |
| 312 | 513 | */ |
| 313 | 514 | public static function hidden_columns( $result ) { |
| 515 | + global $frm_vars; | |
| 516 | + | |
| 314 | 517 | if ( ! is_array( $result ) ) { |
| 315 | 518 | // Force an unexpected value to be an array. |
| 316 | 519 | // Since $result is a filtered option and gets saved to the database, it's possible it could be a string. |
| 317 | 520 | // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error. |
| @@ -317,21 +520,16 @@ | ||
| 317 | 520 | // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error. |
| 318 | 521 | $result = array(); |
| 319 | 522 | } |
| 320 | 523 | |
| 321 | - $form_id = FrmForm::get_current_form_id(); | |
| 524 | + $form_id = FrmForm::get_current_form_id(); | |
| 525 | + $hidden = self::user_hidden_columns_for_form( $form_id, $result ); | |
| 526 | + $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0; | |
| 527 | + $max_columns = 11; | |
| 322 | 528 | |
| 323 | - $hidden = self::user_hidden_columns_for_form( $form_id, $result ); | |
| 324 | - | |
| 325 | - global $frm_vars; | |
| 326 | - $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0; | |
| 327 | - | |
| 328 | - if ( ! empty( $hidden ) ) { | |
| 329 | - $result = $hidden; | |
| 330 | - $i = $i - count( $result ); | |
| 331 | - $max_columns = 11; | |
| 332 | - } else { | |
| 333 | - $max_columns = 8; | |
| 529 | + if ( $hidden ) { | |
| 530 | + $result = $hidden; | |
| 531 | + $i = $i - count( $result ); | |
| 334 | 532 | } |
| 335 | 533 | |
| 336 | 534 | if ( $i <= $max_columns ) { |
| 337 | 535 | return $result; |
| @@ -343,21 +541,29 @@ | ||
| 343 | 541 | } |
| 344 | 542 | |
| 345 | 543 | /** |
| 346 | 544 | * @since 2.05.07 |
| 545 | + * | |
| 546 | + * @param int|string $form_id | |
| 547 | + * @param mixed $result | |
| 548 | + * | |
| 549 | + * @return array | |
| 347 | 550 | */ |
| 348 | 551 | private static function user_hidden_columns_for_form( $form_id, $result ) { |
| 349 | 552 | $hidden = array(); |
| 553 | + | |
| 350 | 554 | foreach ( (array) $result as $r ) { |
| 351 | - if ( ! empty( $r ) ) { | |
| 352 | - list( $form_prefix, $field_key ) = explode( '_', $r ); | |
| 555 | + if ( ! $r ) { | |
| 556 | + continue; | |
| 557 | + } | |
| 353 | 558 | |
| 354 | - if ( (int) $form_prefix == (int) $form_id ) { | |
| 355 | - $hidden[] = $r; | |
| 356 | - } | |
| 559 | + list( $form_prefix, $field_key ) = explode( '_', $r ); | |
| 357 | 560 | |
| 358 | - unset( $form_prefix ); | |
| 561 | + if ( (int) $form_prefix === (int) $form_id ) { | |
| 562 | + $hidden[] = $r; | |
| 359 | 563 | } |
| 564 | + | |
| 565 | + unset( $form_prefix ); | |
| 360 | 566 | } |
| 361 | 567 | |
| 362 | 568 | return $hidden; |
| 363 | 569 | } |
| @@ -365,8 +571,13 @@ | ||
| 365 | 571 | /** |
| 366 | 572 | * Remove some columns by default when there are too many |
| 367 | 573 | * |
| 368 | 574 | * @since 2.05.07 |
| 575 | + * | |
| 576 | + * @param array $atts | |
| 577 | + * @param array $result | |
| 578 | + * | |
| 579 | + * @return void | |
| 369 | 580 | */ |
| 370 | 581 | private static function remove_excess_cols( $atts, &$result ) { |
| 371 | 582 | global $frm_vars; |
| 372 | 583 | |
| @@ -374,19 +585,18 @@ | ||
| 374 | 585 | $atts['form_id'] . '_item_key' => '', |
| 375 | 586 | $atts['form_id'] . '_id' => '', |
| 376 | 587 | ); |
| 377 | 588 | $cols = $remove_first + array_reverse( $frm_vars['cols'], true ); |
| 589 | + $i = $atts['i']; | |
| 378 | 590 | |
| 379 | - $i = $atts['i']; | |
| 380 | - | |
| 381 | 591 | foreach ( $cols as $col_key => $col ) { |
| 382 | 592 | if ( $i <= $atts['max_columns'] ) { |
| 383 | 593 | break; |
| 384 | 594 | } |
| 385 | 595 | |
| 386 | - if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) { | |
| 596 | + if ( ! $result || ! in_array( $col_key, $result, true ) ) { | |
| 387 | 597 | $result[] = $col_key; |
| 388 | - $i--; | |
| 598 | + --$i; | |
| 389 | 599 | } |
| 390 | 600 | |
| 391 | 601 | unset( $col_key, $col ); |
| 392 | 602 | } |
| @@ -391,8 +601,14 @@ | ||
| 391 | 601 | unset( $col_key, $col ); |
| 392 | 602 | } |
| 393 | 603 | } |
| 394 | 604 | |
| 605 | + /** | |
| 606 | + * @param string $message | |
| 607 | + * @param array $errors | |
| 608 | + * | |
| 609 | + * @return void | |
| 610 | + */ | |
| 395 | 611 | public static function display_list( $message = '', $errors = array() ) { |
| 396 | 612 | global $wpdb, $frm_vars; |
| 397 | 613 | |
| 398 | 614 | $form = FrmForm::maybe_get_current_form(); |
| @@ -404,28 +620,29 @@ | ||
| 404 | 620 | |
| 405 | 621 | self::get_delete_form_time( $form, $errors ); |
| 406 | 622 | } |
| 407 | 623 | |
| 408 | - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); | |
| 409 | - | |
| 624 | + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); | |
| 410 | 625 | $wp_list_table = new $table_class( array( 'params' => $params ) ); |
| 626 | + $pagenum = $wp_list_table->get_pagenum(); | |
| 411 | 627 | |
| 412 | - $pagenum = $wp_list_table->get_pagenum(); | |
| 413 | - | |
| 414 | 628 | $wp_list_table->prepare_items(); |
| 415 | 629 | |
| 416 | 630 | $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
| 631 | + | |
| 417 | 632 | if ( $pagenum > $total_pages && $total_pages > 0 ) { |
| 418 | 633 | $url = add_query_arg( 'paged', $total_pages ); |
| 634 | + | |
| 419 | 635 | if ( headers_sent() ) { |
| 420 | 636 | FrmAppHelper::js_redirect( $url, true ); |
| 421 | 637 | } else { |
| 422 | - wp_redirect( esc_url_raw( $url ) ); | |
| 638 | + wp_safe_redirect( esc_url_raw( $url ) ); | |
| 423 | 639 | } |
| 640 | + | |
| 424 | 641 | die(); |
| 425 | 642 | } |
| 426 | 643 | |
| 427 | - if ( empty( $message ) && isset( $_GET['import-message'] ) ) { | |
| 644 | + if ( ! $message && isset( $_GET['import-message'] ) ) { | |
| 428 | 645 | $message = __( 'Your import is complete', 'formidable' ); |
| 429 | 646 | } |
| 430 | 647 | |
| 431 | 648 | require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php'; |
| @@ -430,19 +647,33 @@ | ||
| 430 | 647 | |
| 431 | 648 | require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php'; |
| 432 | 649 | } |
| 433 | 650 | |
| 651 | + /** | |
| 652 | + * @param object $form | |
| 653 | + * @param array $errors | |
| 654 | + * | |
| 655 | + * @return void | |
| 656 | + */ | |
| 434 | 657 | private static function get_delete_form_time( $form, &$errors ) { |
| 435 | - if ( 'trash' == $form->status ) { | |
| 436 | - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); | |
| 437 | - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) ); | |
| 658 | + if ( 'trash' !== $form->status ) { | |
| 659 | + return; | |
| 660 | + } | |
| 438 | 661 | |
| 439 | - /* translators: %1$s: Time string */ | |
| 440 | - $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 ); | |
| 441 | - } | |
| 662 | + $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); | |
| 663 | + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, $form->options['trash_time'] ?? time() ); | |
| 664 | + | |
| 665 | + /* translators: %1$s: Time string */ | |
| 666 | + $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 ); | |
| 442 | 667 | } |
| 443 | 668 | |
| 444 | - /* Back End CRUD */ | |
| 669 | + /** | |
| 670 | + * Back End CRUD. | |
| 671 | + * | |
| 672 | + * @param int $id | |
| 673 | + * | |
| 674 | + * @return void | |
| 675 | + */ | |
| 445 | 676 | public static function show( $id = 0 ) { |
| 446 | 677 | FrmAppHelper::permission_check( 'frm_view_entries' ); |
| 447 | 678 | |
| 448 | 679 | if ( ! $id ) { |
| @@ -453,17 +684,22 @@ | ||
| 453 | 684 | } |
| 454 | 685 | } |
| 455 | 686 | |
| 456 | 687 | $entry = FrmEntry::getOne( $id, true ); |
| 688 | + | |
| 457 | 689 | if ( ! $entry ) { |
| 458 | - echo '<div id="form_show_entry_page" class="wrap">' . | |
| 459 | - esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) . | |
| 460 | - '</div>'; | |
| 461 | - | |
| 690 | + FrmAppController::show_error_modal( | |
| 691 | + array( | |
| 692 | + 'title' => __( 'You can\'t view the entry', 'formidable' ), | |
| 693 | + 'body' => __( 'You are trying to view an entry that does not exist', 'formidable' ), | |
| 694 | + 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 695 | + ) | |
| 696 | + ); | |
| 462 | 697 | return; |
| 463 | 698 | } |
| 464 | 699 | |
| 465 | 700 | $data = $entry->description; |
| 701 | + | |
| 466 | 702 | if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
| 467 | 703 | $data = array( 'referrer' => $data ); |
| 468 | 704 | } |
| 469 | 705 | |
| @@ -469,9 +705,9 @@ | ||
| 469 | 705 | |
| 470 | 706 | $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' ); |
| 471 | 707 | $form = FrmForm::getOne( $entry->form_id ); |
| 472 | 708 | |
| 473 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' ); | |
| 709 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php'; | |
| 474 | 710 | } |
| 475 | 711 | |
| 476 | 712 | /** |
| 477 | 713 | * Destroy an entry from the admin page. |
| @@ -480,19 +716,27 @@ | ||
| 480 | 716 | * @return void |
| 481 | 717 | */ |
| 482 | 718 | public static function destroy() { |
| 483 | 719 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 ); |
| 720 | + | |
| 484 | 721 | if ( false !== $permission_error ) { |
| 485 | - wp_die( esc_html( $permission_error ) ); | |
| 722 | + $error_args = array( | |
| 723 | + 'title' => __( 'Verification failed', 'formidable' ), | |
| 724 | + 'body' => $permission_error, | |
| 725 | + 'cancel_url' => admin_url( 'admin.php?page=formidable-entries' ), | |
| 726 | + ); | |
| 727 | + FrmAppController::show_error_modal( $error_args ); | |
| 728 | + return; | |
| 486 | 729 | } |
| 487 | 730 | |
| 488 | 731 | $params = FrmForm::get_admin_params(); |
| 489 | 732 | |
| 490 | - if ( isset( $params['keep_post'] ) && $params['keep_post'] ) { | |
| 733 | + if ( ! empty( $params['keep_post'] ) ) { | |
| 491 | 734 | self::unlink_post( $params['id'] ); |
| 492 | 735 | } |
| 493 | 736 | |
| 494 | 737 | $message = ''; |
| 738 | + | |
| 495 | 739 | if ( FrmEntry::destroy( $params['id'] ) ) { |
| 496 | 740 | $message = __( 'Entry was successfully deleted', 'formidable' ); |
| 497 | 741 | } |
| 498 | 742 | |
| @@ -499,20 +743,17 @@ | ||
| 499 | 743 | self::display_list( $message ); |
| 500 | 744 | } |
| 501 | 745 | |
| 502 | 746 | /** |
| 503 | - * @deprecated 4.02.04 - Moved to Pro since it was unused in Lite. | |
| 747 | + * @param array|string $errors | |
| 748 | + * @param bool $ajax | |
| 749 | + * | |
| 750 | + * @return void | |
| 504 | 751 | */ |
| 505 | - public static function destroy_all() { | |
| 506 | - _deprecated_function( __METHOD__, '4.02.04', 'FrmProEntriesController::destroy_all' ); | |
| 507 | - if ( is_callable( 'FrmProEntriesController::destroy_all' ) ) { | |
| 508 | - FrmProEntriesController::destroy_all(); | |
| 509 | - } | |
| 510 | - } | |
| 511 | - | |
| 512 | 752 | public static function process_entry( $errors = '', $ajax = false ) { |
| 513 | 753 | $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); |
| 514 | - if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 754 | + | |
| 755 | + if ( FrmAppHelper::is_admin() || empty( $_POST ) || ! $form_id || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 515 | 756 | return; |
| 516 | 757 | } |
| 517 | 758 | |
| 518 | 759 | global $frm_vars; |
| @@ -517,12 +758,19 @@ | ||
| 517 | 758 | |
| 518 | 759 | global $frm_vars; |
| 519 | 760 | |
| 520 | 761 | $form = FrmForm::getOne( $form_id ); |
| 762 | + | |
| 521 | 763 | if ( ! $form ) { |
| 522 | 764 | return; |
| 523 | 765 | } |
| 524 | 766 | |
| 767 | + $is_preview = 'frm_forms_preview' === FrmAppHelper::simple_get( 'action' ); | |
| 768 | + | |
| 769 | + if ( $is_preview && FrmFormsHelper::should_block_preview( $form->form_key ) ) { | |
| 770 | + return; | |
| 771 | + } | |
| 772 | + | |
| 525 | 773 | $params = FrmForm::get_params( $form ); |
| 526 | 774 | |
| 527 | 775 | if ( ! isset( $frm_vars['form_params'] ) ) { |
| 528 | 776 | $frm_vars['form_params'] = array(); |
| @@ -532,8 +780,9 @@ | ||
| 532 | 780 | if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) { |
| 533 | 781 | return; |
| 534 | 782 | } |
| 535 | 783 | |
| 784 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 536 | 785 | if ( $errors == '' && ! $ajax ) { |
| 537 | 786 | $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 538 | 787 | } |
| 539 | 788 | |
| @@ -546,26 +795,28 @@ | ||
| 546 | 795 | $errors = apply_filters( 'frm_entries_before_create', $errors, $form ); |
| 547 | 796 | |
| 548 | 797 | $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors ); |
| 549 | 798 | |
| 550 | - if ( empty( $errors ) ) { | |
| 551 | - $_POST['frm_skip_cookie'] = 1; | |
| 552 | - $do_success = false; | |
| 553 | - if ( $params['action'] === 'create' ) { | |
| 554 | - if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { | |
| 555 | - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 799 | + if ( $errors ) { | |
| 800 | + return; | |
| 801 | + } | |
| 556 | 802 | |
| 557 | - $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id']; | |
| 558 | - $do_success = true; | |
| 559 | - } | |
| 560 | - } | |
| 803 | + $_POST['frm_skip_cookie'] = 1; | |
| 804 | + $do_success = false; | |
| 561 | 805 | |
| 562 | - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); | |
| 563 | - if ( $do_success ) { | |
| 564 | - FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) ); | |
| 565 | - } | |
| 566 | - unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 806 | + if ( $params['action'] === 'create' && apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { | |
| 807 | + $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 808 | + | |
| 809 | + $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id']; | |
| 810 | + $do_success = true; | |
| 567 | 811 | } |
| 812 | + | |
| 813 | + do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); | |
| 814 | + | |
| 815 | + if ( $do_success ) { | |
| 816 | + FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) ); | |
| 817 | + } | |
| 818 | + unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 568 | 819 | } |
| 569 | 820 | |
| 570 | 821 | /** |
| 571 | 822 | * Escape url entities before redirect |
| @@ -579,11 +830,19 @@ | ||
| 579 | 830 | public static function prepare_redirect_url( $url ) { |
| 580 | 831 | return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url ); |
| 581 | 832 | } |
| 582 | 833 | |
| 834 | + /** | |
| 835 | + * Delete entry if redirected. | |
| 836 | + * | |
| 837 | + * @param string $url | |
| 838 | + * @param object $form | |
| 839 | + * @param array $atts | |
| 840 | + * | |
| 841 | + * @return string | |
| 842 | + */ | |
| 583 | 843 | public static function delete_entry_before_redirect( $url, $form, $atts ) { |
| 584 | 844 | self::_delete_entry( $atts['id'], $form ); |
| 585 | - | |
| 586 | 845 | return $url; |
| 587 | 846 | } |
| 588 | 847 | |
| 589 | 848 | /** |
| @@ -589,13 +848,23 @@ | ||
| 589 | 848 | /** |
| 590 | 849 | * Delete entry if not redirected. |
| 591 | 850 | * |
| 592 | 851 | * @param array $atts |
| 852 | + * | |
| 853 | + * @return void | |
| 593 | 854 | */ |
| 594 | 855 | public static function delete_entry_after_save( $atts ) { |
| 595 | 856 | self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
| 596 | 857 | } |
| 597 | 858 | |
| 859 | + /** | |
| 860 | + * Delete entry if not redirected. | |
| 861 | + * | |
| 862 | + * @param int $entry_id | |
| 863 | + * @param object $form | |
| 864 | + * | |
| 865 | + * @return void | |
| 866 | + */ | |
| 598 | 867 | private static function _delete_entry( $entry_id, $form ) { |
| 599 | 868 | if ( ! $form ) { |
| 600 | 869 | return; |
| 601 | 870 | } |
| @@ -600,16 +869,23 @@ | ||
| 600 | 869 | return; |
| 601 | 870 | } |
| 602 | 871 | |
| 603 | 872 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 604 | - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { | |
| 605 | - self::unlink_post( $entry_id ); | |
| 606 | - FrmEntry::destroy( $entry_id ); | |
| 873 | + | |
| 874 | + if ( empty( $form->options['no_save'] ) ) { | |
| 875 | + return; | |
| 607 | 876 | } |
| 877 | + | |
| 878 | + self::unlink_post( $entry_id ); | |
| 879 | + FrmEntry::destroy( $entry_id ); | |
| 608 | 880 | } |
| 609 | 881 | |
| 610 | 882 | /** |
| 611 | 883 | * Unlink entry from post |
| 884 | + * | |
| 885 | + * @param int $entry_id | |
| 886 | + * | |
| 887 | + * @return void | |
| 612 | 888 | */ |
| 613 | 889 | private static function unlink_post( $entry_id ) { |
| 614 | 890 | global $wpdb; |
| 615 | 891 | $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) ); |
| @@ -616,9 +892,9 @@ | ||
| 616 | 892 | FrmEntry::clear_cache(); |
| 617 | 893 | } |
| 618 | 894 | |
| 619 | 895 | /** |
| 620 | - * @param $atts | |
| 896 | + * @param array $atts | |
| 621 | 897 | * |
| 622 | 898 | * @return array|string |
| 623 | 899 | */ |
| 624 | 900 | public static function show_entry_shortcode( $atts ) { |
| @@ -645,39 +921,39 @@ | ||
| 645 | 921 | 'exclude_fields' => '', |
| 646 | 922 | 'include_fields' => '', |
| 647 | 923 | 'include_extras' => '', |
| 648 | 924 | 'inline_style' => 1, |
| 649 | - 'child_array' => false, // return embedded fields as nested array | |
| 925 | + 'table_style' => '', | |
| 926 | + // Return embedded fields as nested array. | |
| 927 | + 'child_array' => false, | |
| 650 | 928 | 'line_breaks' => true, |
| 651 | 929 | 'array_separator' => ', ', |
| 652 | 930 | ); |
| 653 | 931 | $defaults = apply_filters( 'frm_show_entry_defaults', $defaults ); |
| 932 | + $atts = shortcode_atts( $defaults, $atts ); | |
| 654 | 933 | |
| 655 | - $atts = shortcode_atts( $defaults, $atts ); | |
| 656 | - | |
| 657 | 934 | if ( $atts['default_email'] ) { |
| 658 | - $shortcode_atts = array( | |
| 935 | + $shortcode_atts = array( | |
| 659 | 936 | 'format' => $atts['format'], |
| 660 | 937 | 'plain_text' => $atts['plain_text'], |
| 661 | 938 | ); |
| 662 | - | |
| 663 | 939 | $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts ); |
| 664 | - $formatted_entry = $entry_formatter->content(); | |
| 940 | + return $entry_formatter->content(); | |
| 941 | + } | |
| 665 | 942 | |
| 666 | - } else { | |
| 943 | + $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts ); | |
| 667 | 944 | |
| 668 | - $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts ); | |
| 669 | - $formatted_entry = $entry_formatter->get_formatted_entry_values(); | |
| 670 | - | |
| 671 | - } | |
| 672 | - | |
| 673 | - return $formatted_entry; | |
| 945 | + return $entry_formatter->get_formatted_entry_values(); | |
| 674 | 946 | } |
| 675 | 947 | |
| 948 | + /** | |
| 949 | + * @param false|object $entry | |
| 950 | + * | |
| 951 | + * @return void | |
| 952 | + */ | |
| 676 | 953 | public static function entry_sidebar( $entry = false ) { |
| 677 | - $data = array(); | |
| 678 | - $id = 0; | |
| 679 | - | |
| 954 | + $data = array(); | |
| 955 | + $id = 0; | |
| 680 | 956 | $date_format = get_option( 'date_format' ); |
| 681 | 957 | $time_format = get_option( 'time_format' ); |
| 682 | 958 | |
| 683 | 959 | if ( $entry ) { |
| @@ -682,8 +958,9 @@ | ||
| 682 | 958 | |
| 683 | 959 | if ( $entry ) { |
| 684 | 960 | $id = $entry->id; |
| 685 | 961 | $data = $entry->description; |
| 962 | + | |
| 686 | 963 | if ( isset( $data['browser'] ) ) { |
| 687 | 964 | $browser = FrmEntriesHelper::get_browser( $data['browser'] ); |
| 688 | 965 | } |
| 689 | 966 | /** |
| @@ -689,20 +966,14 @@ | ||
| 689 | 966 | /** |
| 690 | 967 | * Add or remove information in the entry sidebar. |
| 691 | 968 | * |
| 692 | 969 | * @since 5.5.2 |
| 970 | + * | |
| 693 | 971 | * @param array $data |
| 972 | + * @param array{entry:\stdClass} $entry | |
| 694 | 973 | */ |
| 695 | 974 | $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) ); |
| 696 | 975 | } |
| 697 | 976 | |
| 698 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' ); | |
| 699 | - } | |
| 700 | - | |
| 701 | - /** | |
| 702 | - * @deprecated 4.0 | |
| 703 | - */ | |
| 704 | - public static function contextual_help( $help, $screen_id, $screen ) { | |
| 705 | - _deprecated_function( __METHOD__, '4.0' ); | |
| 706 | - return $help; | |
| 977 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php'; | |
| 707 | 978 | } |
| 708 | 979 | } |