Complex classes like FrmFormsController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FrmFormsController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class FrmFormsController { |
||
| 7 | |||
| 8 | public static function menu() { |
||
| 9 | $menu_label = __( 'Forms', 'formidable' ); |
||
| 10 | if ( ! FrmAppHelper::pro_is_installed() ) { |
||
| 11 | $menu_label .= ' (Lite)'; |
||
| 12 | } |
||
| 13 | add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' ); |
||
| 14 | |||
| 15 | self::maybe_load_listing_hooks(); |
||
| 16 | } |
||
| 17 | |||
| 18 | public static function maybe_load_listing_hooks() { |
||
| 19 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
||
| 20 | if ( ! empty( $action ) && ! in_array( $action, array( 'list', 'trash', 'untrash', 'destroy' ) ) ) { |
||
| 21 | return; |
||
| 22 | } |
||
| 23 | |||
| 24 | add_filter( 'get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' ); |
||
| 25 | |||
| 26 | add_filter( 'manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 ); |
||
| 27 | add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' ); |
||
| 28 | } |
||
| 29 | |||
| 30 | public static function head() { |
||
| 31 | if ( wp_is_mobile() ) { |
||
| 32 | wp_enqueue_script( 'jquery-touch-punch' ); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | public static function register_widgets() { |
||
| 37 | require_once( FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php' ); |
||
| 38 | register_widget( 'FrmShowForm' ); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Show a message about conditional logic |
||
| 43 | * |
||
| 44 | * @since 4.06.03 |
||
| 45 | */ |
||
| 46 | public static function logic_tip() { |
||
| 47 | echo '<a href="javascript:void(0)" class="frm_noallow frm_show_upgrade frm_add_logic_link" data-upgrade="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '" data-message="' . esc_attr__( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', 'formidable' ) . esc_attr( ' <img src="https://cdn.formidableforms.com/wp-content/themes/fp2015git/images/survey/survey-logic.png" srcset="https://cdn.formidableforms.com/wp-content/themes/fp2015git/images/survey/[email protected] 2x" alt="Conditional Logic options"/>' ) . '" data-medium="builder" data-content="logic">'; |
||
| 48 | FrmAppHelper::icon_by_class( 'frmfont frm_swap_icon' ); |
||
| 49 | esc_html_e( 'Add Conditional Logic', 'formidable' ); |
||
| 50 | echo '</a>'; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * By default, Divi processes form shortcodes on the edit post page. |
||
| 55 | * Now that won't do. |
||
| 56 | * |
||
| 57 | * @since 3.01 |
||
| 58 | */ |
||
| 59 | public static function prevent_divi_conflict( $shortcodes ) { |
||
| 60 | $shortcodes[] = 'formidable'; |
||
| 61 | |||
| 62 | return $shortcodes; |
||
| 63 | } |
||
| 64 | |||
| 65 | public static function list_form() { |
||
| 66 | FrmAppHelper::permission_check( 'frm_view_forms' ); |
||
| 67 | |||
| 68 | $message = ''; |
||
| 69 | $params = FrmForm::list_page_params(); |
||
| 70 | $errors = self::process_bulk_form_actions( array() ); |
||
| 71 | if ( isset( $errors['message'] ) ) { |
||
| 72 | $message = $errors['message']; |
||
| 73 | unset( $errors['message'] ); |
||
| 74 | } |
||
| 75 | $errors = apply_filters( 'frm_admin_list_form_action', $errors ); |
||
| 76 | |||
| 77 | return self::display_forms_list( $params, $message, $errors ); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Load the scripts before a modal can be triggered. |
||
| 82 | * |
||
| 83 | * @since 4.0 |
||
| 84 | */ |
||
| 85 | private static function init_modal() { |
||
| 86 | wp_enqueue_script( 'jquery-ui-dialog' ); |
||
| 87 | wp_enqueue_style( 'jquery-ui-dialog' ); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Create the default email action |
||
| 92 | * |
||
| 93 | * @since 2.02.11 |
||
| 94 | * |
||
| 95 | * @param object $form |
||
| 96 | */ |
||
| 97 | private static function create_default_email_action( $form ) { |
||
| 98 | FrmForm::maybe_get_form( $form ); |
||
| 99 | $create_email = apply_filters( 'frm_create_default_email_action', true, $form ); |
||
| 100 | |||
| 101 | if ( $create_email ) { |
||
| 102 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
||
| 103 | $action_control->create( $form->id ); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | public static function edit( $values = false ) { |
||
| 108 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
||
| 109 | |||
| 110 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
||
| 111 | |||
| 112 | return self::get_edit_vars( $id ); |
||
| 113 | } |
||
| 114 | |||
| 115 | public static function settings( $id = false, $message = '' ) { |
||
| 116 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
||
| 117 | |||
| 118 | if ( ! $id || ! is_numeric( $id ) ) { |
||
| 119 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
||
| 120 | } |
||
| 121 | |||
| 122 | return self::get_settings_vars( $id, array(), $message ); |
||
| 123 | } |
||
| 124 | |||
| 125 | public static function update_settings() { |
||
| 126 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
||
| 127 | |||
| 128 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
||
| 129 | |||
| 130 | $errors = FrmForm::validate( $_POST ); |
||
| 131 | $warnings = FrmFormsHelper::check_for_warnings( $_POST ); |
||
| 132 | |||
| 133 | if ( count( $errors ) > 0 ) { |
||
| 134 | return self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); |
||
| 135 | } |
||
| 136 | |||
| 137 | do_action( 'frm_before_update_form_settings', $id ); |
||
| 138 | |||
| 139 | FrmForm::update( $id, $_POST ); |
||
| 140 | |||
| 141 | $message = __( 'Settings Successfully Updated', 'formidable' ); |
||
| 142 | |||
| 143 | return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); |
||
| 144 | } |
||
| 145 | |||
| 146 | public static function update( $values = array() ) { |
||
| 147 | if ( empty( $values ) ) { |
||
| 148 | $values = $_POST; |
||
| 149 | } |
||
| 150 | |||
| 151 | // Set radio button and checkbox meta equal to "other" value. |
||
| 152 | if ( FrmAppHelper::pro_is_installed() ) { |
||
| 153 | $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
||
| 154 | } |
||
| 155 | |||
| 156 | $errors = FrmForm::validate( $values ); |
||
| 157 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' ); |
||
| 158 | if ( $permission_error !== false ) { |
||
| 159 | $errors['form'] = $permission_error; |
||
| 160 | } |
||
| 161 | |||
| 162 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
||
| 163 | |||
| 164 | if ( count( $errors ) > 0 ) { |
||
| 165 | return self::get_edit_vars( $id, $errors ); |
||
| 166 | } else { |
||
| 167 | FrmForm::update( $id, $values ); |
||
| 168 | $message = __( 'Form was successfully updated.', 'formidable' ); |
||
| 169 | |||
| 170 | if ( self::is_too_long( $values ) ) { |
||
| 171 | $message .= '<br/> ' . sprintf( |
||
| 172 | /* translators: %1$s: Start link HTML, %2$s: end link HTML */ |
||
| 173 | __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ), |
||
| 174 | '<a href="https://formidableforms.com/knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/?utm_source=WordPress&utm_medium=builder&utm_campaign=liteplugin" target="_blank" rel="noopener">', |
||
| 175 | '</a>' |
||
| 176 | ); |
||
| 177 | } |
||
| 178 | |||
| 179 | if ( defined( 'DOING_AJAX' ) ) { |
||
| 180 | wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // WPCS: XSS ok. |
||
| 181 | } |
||
| 182 | |||
| 183 | return self::get_edit_vars( $id, array(), $message ); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Check if the value at the end of the form was included. |
||
| 189 | * If it's missing, it means other values at the end of the form |
||
| 190 | * were likely not saved either. |
||
| 191 | * |
||
| 192 | * @since 3.06.01 |
||
| 193 | */ |
||
| 194 | private static function is_too_long( $values ) { |
||
| 195 | return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] ); |
||
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Redirect to the url for creating from a template |
||
| 200 | * Also delete the current form |
||
| 201 | * |
||
| 202 | * @since 2.0 |
||
| 203 | * @deprecated 3.06 |
||
| 204 | */ |
||
| 205 | public static function _create_from_template() { |
||
| 206 | _deprecated_function( __FUNCTION__, '3.06' ); |
||
| 207 | |||
| 208 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
||
| 209 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
||
| 210 | |||
| 211 | $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' ); |
||
| 212 | $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
||
| 213 | |||
| 214 | if ( $current_form ) { |
||
| 215 | FrmForm::destroy( $current_form ); |
||
| 216 | } |
||
| 217 | |||
| 218 | echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) ); |
||
| 219 | wp_die(); |
||
| 220 | } |
||
| 221 | |||
| 222 | public static function duplicate() { |
||
| 223 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
||
| 224 | |||
| 225 | $params = FrmForm::list_page_params(); |
||
| 226 | $form = FrmForm::duplicate( $params['id'], $params['template'], true ); |
||
| 227 | $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' ); |
||
| 228 | if ( $form ) { |
||
| 229 | return self::get_edit_vars( $form, array(), $message, true ); |
||
| 230 | } else { |
||
| 231 | return self::display_forms_list( $params, __( 'There was a problem creating the new template.', 'formidable' ) ); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | public static function page_preview() { |
||
| 236 | $params = FrmForm::list_page_params(); |
||
| 237 | if ( ! $params['form'] ) { |
||
| 238 | return; |
||
| 239 | } |
||
| 240 | |||
| 241 | $form = FrmForm::getOne( $params['form'] ); |
||
| 242 | if ( $form ) { |
||
| 243 | return self::show_form( $form->id, '', true, true ); |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @since 3.0 |
||
| 249 | */ |
||
| 250 | public static function show_page_preview() { |
||
| 251 | echo self::page_preview(); // WPCS: XSS ok. |
||
| 252 | } |
||
| 253 | |||
| 254 | public static function preview() { |
||
| 255 | do_action( 'frm_wp' ); |
||
| 256 | |||
| 257 | global $frm_vars; |
||
| 258 | $frm_vars['preview'] = true; |
||
| 259 | |||
| 260 | self::load_wp(); |
||
| 261 | |||
| 262 | $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' ); |
||
| 263 | if ( $include_theme ) { |
||
| 264 | self::set_preview_query(); |
||
| 265 | self::load_theme_preview(); |
||
| 266 | } else { |
||
| 267 | self::load_direct_preview(); |
||
| 268 | } |
||
| 269 | |||
| 270 | wp_die(); |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @since 3.0 |
||
| 275 | */ |
||
| 276 | private static function load_wp() { |
||
| 277 | if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) { |
||
| 278 | global $wp; |
||
| 279 | $root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ); |
||
| 280 | include_once( $root . '/wp-config.php' ); |
||
| 281 | $wp->init(); |
||
| 282 | $wp->register_globals(); |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 286 | private static function set_preview_query() { |
||
| 287 | $random_page = get_posts( |
||
| 288 | array( |
||
| 289 | 'numberposts' => 1, |
||
| 290 | 'orderby' => 'date', |
||
| 291 | 'order' => 'ASC', |
||
| 292 | 'post_type' => 'page', |
||
| 293 | ) |
||
| 294 | ); |
||
| 295 | |||
| 296 | if ( ! empty( $random_page ) ) { |
||
| 297 | $random_page = reset( $random_page ); |
||
| 298 | query_posts( |
||
| 299 | array( |
||
| 300 | 'post_type' => 'page', |
||
| 301 | 'page_id' => $random_page->ID, |
||
| 302 | ) |
||
| 303 | ); |
||
| 304 | } |
||
| 305 | } |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @since 3.0 |
||
| 309 | */ |
||
| 310 | private static function load_theme_preview() { |
||
| 311 | add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 ); |
||
| 312 | add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 ); |
||
| 313 | add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 ); |
||
| 314 | add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' ); |
||
| 315 | add_filter( 'is_active_sidebar', '__return_false' ); |
||
| 316 | FrmStylesController::enqueue_css( 'enqueue', true ); |
||
| 317 | get_template_part( 'page' ); |
||
| 318 | } |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Set the page title for the theme preview page |
||
| 322 | * |
||
| 323 | * @since 3.0 |
||
| 324 | */ |
||
| 325 | public static function preview_page_title( $title ) { |
||
| 326 | if ( in_the_loop() ) { |
||
| 327 | $title = self::preview_title( $title ); |
||
| 328 | } |
||
| 329 | |||
| 330 | return $title; |
||
| 331 | } |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Set the page title for the theme preview page |
||
| 335 | * |
||
| 336 | * @since 3.0 |
||
| 337 | */ |
||
| 338 | public static function preview_title( $title ) { |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Set the page content for the theme preview page |
||
| 344 | * |
||
| 345 | * @since 3.0 |
||
| 346 | */ |
||
| 347 | public static function preview_content( $content ) { |
||
| 348 | if ( in_the_loop() ) { |
||
| 349 | $content = self::show_page_preview(); |
||
|
|
|||
| 350 | } |
||
| 351 | |||
| 352 | return $content; |
||
| 353 | } |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @since 3.0 |
||
| 357 | */ |
||
| 358 | private static function load_direct_preview() { |
||
| 359 | header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
||
| 360 | |||
| 361 | $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' ); |
||
| 362 | if ( $key == '' ) { |
||
| 363 | $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' ); |
||
| 364 | } |
||
| 365 | |||
| 373 | |||
| 374 | public static function untrash() { |
||
| 377 | |||
| 378 | public static function bulk_untrash( $ids ) { |
||
| 388 | |||
| 389 | /** |
||
| 390 | * @since 3.06 |
||
| 391 | */ |
||
| 392 | public static function ajax_trash() { |
||
| 399 | |||
| 400 | public static function trash() { |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @param string $status |
||
| 406 | * |
||
| 407 | * @return int The number of forms changed |
||
| 408 | */ |
||
| 409 | public static function change_form_status( $status ) { |
||
| 454 | |||
| 455 | public static function bulk_trash( $ids ) { |
||
| 481 | |||
| 482 | public static function destroy() { |
||
| 500 | |||
| 501 | public static function bulk_destroy( $ids ) { |
||
| 517 | |||
| 518 | private static function delete_all() { |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Create a new form from the modal. |
||
| 537 | * |
||
| 538 | * @since 4.0 |
||
| 539 | */ |
||
| 540 | public static function build_new_form() { |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Create a custom template from a form |
||
| 563 | * |
||
| 564 | * @since 3.06 |
||
| 565 | */ |
||
| 566 | public static function build_template() { |
||
| 593 | |||
| 594 | /** |
||
| 595 | * Before creating a new form, get the name and description from the modal. |
||
| 596 | * |
||
| 597 | * @since 4.0 |
||
| 598 | */ |
||
| 599 | private static function get_modal_values() { |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Inserts Formidable button |
||
| 611 | * Hook exists since 2.5.0 |
||
| 612 | * |
||
| 613 | * @since 2.0.15 |
||
| 614 | */ |
||
| 615 | public static function insert_form_button() { |
||
| 625 | |||
| 626 | public static function insert_form_popup() { |
||
| 645 | |||
| 646 | public static function get_shortcode_opts() { |
||
| 692 | |||
| 693 | public static function display_forms_list( $params = array(), $message = '', $errors = array() ) { |
||
| 716 | |||
| 717 | public static function get_columns( $columns ) { |
||
| 753 | |||
| 754 | public static function get_sortable_columns() { |
||
| 763 | |||
| 764 | public static function hidden_columns( $hidden_columns ) { |
||
| 779 | |||
| 780 | public static function save_per_page( $save, $option, $value ) { |
||
| 787 | |||
| 788 | /** |
||
| 789 | * @return bool |
||
| 790 | */ |
||
| 791 | public static function expired() { |
||
| 792 | global $frm_expired; |
||
| 793 | return $frm_expired; |
||
| 794 | } |
||
| 795 | |||
| 796 | /** |
||
| 797 | * Get data from api before rendering it so that we can flag the modal as expired |
||
| 798 | */ |
||
| 799 | public static function before_list_templates() { |
||
| 800 | global $frm_templates; |
||
| 801 | global $frm_expired; |
||
| 802 | global $frm_license_type; |
||
| 803 | |||
| 804 | $api = new FrmFormTemplateApi(); |
||
| 805 | $frm_templates = $api->get_api_info(); |
||
| 806 | $expired = false; |
||
| 807 | $license_type = ''; |
||
| 808 | if ( isset( $frm_templates['error'] ) ) { |
||
| 809 | $error = $frm_templates['error']['message']; |
||
| 810 | $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error ); |
||
| 811 | $expired = 'expired' === $frm_templates['error']['code']; |
||
| 812 | $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : ''; |
||
| 813 | unset( $frm_templates['error'] ); |
||
| 814 | } |
||
| 815 | |||
| 816 | $frm_expired = $expired; |
||
| 817 | $frm_license_type = $license_type; |
||
| 818 | } |
||
| 819 | |||
| 820 | public static function list_templates() { |
||
| 821 | global $frm_templates; |
||
| 822 | global $frm_expired; |
||
| 823 | global $frm_license_type; |
||
| 824 | |||
| 825 | $templates = $frm_templates; |
||
| 826 | $custom_templates = array(); |
||
| 827 | $templates_by_category = array(); |
||
| 828 | |||
| 829 | self::add_user_templates( $custom_templates ); |
||
| 830 | |||
| 831 | foreach ( $templates as $template ) { |
||
| 832 | if ( ! isset( $template['categories'] ) ) { |
||
| 833 | continue; |
||
| 834 | } |
||
| 835 | |||
| 836 | foreach ( $template['categories'] as $category ) { |
||
| 837 | if ( ! isset( $templates_by_category[ $category ] ) ) { |
||
| 838 | $templates_by_category[ $category ] = array(); |
||
| 839 | } |
||
| 840 | |||
| 841 | $templates_by_category[ $category ][] = $template; |
||
| 842 | } |
||
| 843 | } |
||
| 844 | unset( $template ); |
||
| 845 | |||
| 846 | // Subcategories that are included elsewhere. |
||
| 847 | $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' ); |
||
| 848 | |||
| 849 | $categories = array_keys( $templates_by_category ); |
||
| 850 | $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() ); |
||
| 851 | $categories = array_diff( $categories, $redundant_cats ); |
||
| 852 | sort( $categories ); |
||
| 853 | |||
| 854 | array_walk( |
||
| 855 | $custom_templates, |
||
| 856 | function( &$template ) { |
||
| 857 | $template['custom'] = true; |
||
| 858 | } |
||
| 859 | ); |
||
| 860 | |||
| 861 | $my_templates_translation = __( 'My Templates', 'formidable' ); |
||
| 862 | $categories = array_merge( array( $my_templates_translation ), $categories ); |
||
| 863 | $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' ); |
||
| 864 | $expired = $frm_expired; |
||
| 865 | $license_type = $frm_license_type; |
||
| 866 | $args = compact( 'pricing', 'license_type' ); |
||
| 867 | $where = apply_filters( 'frm_forms_dropdown', array(), '' ); |
||
| 868 | $forms = FrmForm::get_published_forms( $where ); |
||
| 869 | $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/'; |
||
| 870 | |||
| 871 | $templates_by_category[ $my_templates_translation ] = $custom_templates; |
||
| 872 | |||
| 873 | unset( $pricing, $license_type, $where ); |
||
| 874 | wp_enqueue_script( 'accordion' ); // register accordion for template groups |
||
| 875 | require $view_path . 'list-templates.php'; |
||
| 876 | } |
||
| 877 | |||
| 878 | /** |
||
| 879 | * @since 4.03.01 |
||
| 880 | */ |
||
| 881 | private static function get_template_categories( $templates ) { |
||
| 882 | $categories = array(); |
||
| 883 | foreach ( $templates as $template ) { |
||
| 884 | if ( isset( $template['categories'] ) ) { |
||
| 885 | $categories = array_merge( $categories, $template['categories'] ); |
||
| 886 | } |
||
| 887 | } |
||
| 888 | $exclude_cats = FrmFormsHelper::ignore_template_categories(); |
||
| 889 | $categories = array_unique( $categories ); |
||
| 890 | $categories = array_diff( $categories, $exclude_cats ); |
||
| 891 | sort( $categories ); |
||
| 892 | return $categories; |
||
| 893 | } |
||
| 894 | |||
| 895 | private static function add_user_templates( &$templates ) { |
||
| 896 | $user_templates = array( |
||
| 897 | 'is_template' => 1, |
||
| 898 | 'default_template' => 0, |
||
| 899 | ); |
||
| 900 | $user_templates = FrmForm::getAll( $user_templates, 'name' ); |
||
| 901 | foreach ( $user_templates as $template ) { |
||
| 902 | $template = array( |
||
| 903 | 'id' => $template->id, |
||
| 904 | 'name' => $template->name, |
||
| 905 | 'key' => $template->form_key, |
||
| 906 | 'description' => $template->description, |
||
| 907 | 'url' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ), |
||
| 908 | 'released' => $template->created_at, |
||
| 909 | 'installed' => 1, |
||
| 910 | ); |
||
| 911 | array_unshift( $templates, $template ); |
||
| 912 | unset( $template ); |
||
| 913 | } |
||
| 914 | } |
||
| 915 | |||
| 916 | private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { |
||
| 917 | global $frm_vars; |
||
| 918 | |||
| 919 | $form = FrmForm::getOne( $id ); |
||
| 920 | if ( ! $form ) { |
||
| 921 | wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) ); |
||
| 922 | } |
||
| 923 | |||
| 924 | if ( $form->parent_form_id ) { |
||
| 925 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
||
| 926 | wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) ); |
||
| 927 | } |
||
| 928 | |||
| 929 | $frm_field_selection = FrmField::field_selection(); |
||
| 930 | |||
| 931 | $fields = FrmField::get_all_for_form( $form->id ); |
||
| 932 | |||
| 933 | // Automatically add end section fields if they don't exist (2.0 migration). |
||
| 934 | $reset_fields = false; |
||
| 935 | FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
||
| 936 | |||
| 937 | if ( $reset_fields ) { |
||
| 938 | $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
||
| 939 | } |
||
| 940 | |||
| 941 | unset( $end_section_values, $last_order, $open, $reset_fields ); |
||
| 942 | |||
| 943 | $args = array( 'parent_form_id' => $form->id ); |
||
| 944 | $values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true, array(), $args ); |
||
| 945 | $values['fields'] = $fields; |
||
| 946 | |||
| 947 | $edit_message = __( 'Form was successfully updated.', 'formidable' ); |
||
| 948 | if ( $form->is_template && $message == $edit_message ) { |
||
| 949 | $message = __( 'Template was successfully updated.', 'formidable' ); |
||
| 950 | } |
||
| 951 | |||
| 952 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
||
| 953 | $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] ); |
||
| 954 | |||
| 955 | if ( defined( 'DOING_AJAX' ) ) { |
||
| 956 | wp_die(); |
||
| 957 | } else { |
||
| 958 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); |
||
| 959 | } |
||
| 960 | } |
||
| 961 | |||
| 962 | public static function get_settings_vars( $id, $errors = array(), $args = array() ) { |
||
| 963 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
||
| 964 | |||
| 965 | global $frm_vars; |
||
| 966 | |||
| 967 | if ( ! is_array( $args ) ) { |
||
| 968 | // For reverse compatibility. |
||
| 969 | $args = array( |
||
| 970 | 'message' => $args, |
||
| 971 | ); |
||
| 972 | } |
||
| 973 | |||
| 974 | $defaults = array( |
||
| 975 | 'message' => '', |
||
| 976 | 'warnings' => array(), |
||
| 977 | ); |
||
| 978 | $args = array_merge( $defaults, $args ); |
||
| 979 | $message = $args['message']; |
||
| 980 | $warnings = $args['warnings']; |
||
| 981 | |||
| 982 | $form = FrmForm::getOne( $id ); |
||
| 983 | $fields = FrmField::get_all_for_form( $id ); |
||
| 984 | $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true ); |
||
| 985 | |||
| 986 | self::clean_submit_html( $values ); |
||
| 987 | |||
| 988 | $sections = self::get_settings_tabs( $values ); |
||
| 989 | $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' ); |
||
| 990 | |||
| 991 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' ); |
||
| 992 | } |
||
| 993 | |||
| 994 | /** |
||
| 995 | * @since 4.0 |
||
| 996 | */ |
||
| 997 | public static function form_publish_button( $atts ) { |
||
| 998 | $values = $atts['values']; |
||
| 999 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' ); |
||
| 1000 | } |
||
| 1001 | |||
| 1002 | /** |
||
| 1003 | * Get a list of all the settings tabs for the form settings page. |
||
| 1004 | * |
||
| 1005 | * @since 4.0 |
||
| 1006 | * |
||
| 1007 | * @param array $values |
||
| 1008 | * @return array |
||
| 1009 | */ |
||
| 1010 | private static function get_settings_tabs( $values ) { |
||
| 1011 | $sections = array( |
||
| 1012 | 'advanced' => array( |
||
| 1013 | 'name' => __( 'General', 'formidable' ), |
||
| 1014 | 'title' => __( 'General Form Settings', 'formidable' ), |
||
| 1015 | 'function' => array( __CLASS__, 'advanced_settings' ), |
||
| 1016 | 'icon' => 'frm_icon_font frm_settings_icon', |
||
| 1017 | ), |
||
| 1018 | 'email' => array( |
||
| 1019 | 'name' => __( 'Actions & Notifications', 'formidable' ), |
||
| 1020 | 'function' => array( 'FrmFormActionsController', 'email_settings' ), |
||
| 1021 | 'id' => 'frm_notification_settings', |
||
| 1022 | 'icon' => 'frm_icon_font frm_mail_bulk_icon', |
||
| 1023 | ), |
||
| 1024 | 'permissions' => array( |
||
| 1025 | 'name' => __( 'Form Permissions', 'formidable' ), |
||
| 1026 | 'icon' => 'frm_icon_font frm_lock_icon', |
||
| 1027 | 'html_class' => 'frm_show_upgrade frm_noallow', |
||
| 1028 | 'data' => array( |
||
| 1029 | 'medium' => 'permissions', |
||
| 1030 | 'upgrade' => __( 'Form Permissions', 'formidable' ), |
||
| 1031 | 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ), |
||
| 1032 | ), |
||
| 1033 | ), |
||
| 1034 | 'scheduling' => array( |
||
| 1035 | 'name' => __( 'Form Scheduling', 'formidable' ), |
||
| 1036 | 'icon' => 'frm_icon_font frm_calendar_icon', |
||
| 1037 | 'html_class' => 'frm_show_upgrade frm_noallow', |
||
| 1038 | 'data' => array( |
||
| 1039 | 'medium' => 'scheduling', |
||
| 1040 | 'upgrade' => __( 'Form scheduling settings', 'formidable' ), |
||
| 1041 | ), |
||
| 1042 | ), |
||
| 1043 | 'buttons' => array( |
||
| 1044 | 'name' => __( 'Styling & Buttons', 'formidable' ), |
||
| 1045 | 'class' => __CLASS__, |
||
| 1046 | 'function' => 'buttons_settings', |
||
| 1047 | 'icon' => 'frm_icon_font frm_pallet_icon', |
||
| 1048 | ), |
||
| 1049 | 'html' => array( |
||
| 1050 | 'name' => __( 'Customize HTML', 'formidable' ), |
||
| 1051 | 'class' => __CLASS__, |
||
| 1052 | 'function' => 'html_settings', |
||
| 1053 | 'icon' => 'frm_icon_font frm_code_icon', |
||
| 1054 | ), |
||
| 1055 | ); |
||
| 1056 | |||
| 1057 | $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values ); |
||
| 1058 | |||
| 1059 | if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) { |
||
| 1060 | // Prevent settings from showing in 2 spots. |
||
| 1061 | unset( $sections['permissions'], $sections['scheduling'] ); |
||
| 1062 | } |
||
| 1063 | |||
| 1064 | foreach ( $sections as $key => $section ) { |
||
| 1065 | $defaults = array( |
||
| 1066 | 'html_class' => '', |
||
| 1067 | 'name' => ucfirst( $key ), |
||
| 1068 | 'icon' => 'frm_icon_font frm_settings_icon', |
||
| 1069 | ); |
||
| 1070 | |||
| 1071 | $section = array_merge( $defaults, $section ); |
||
| 1072 | |||
| 1073 | if ( ! isset( $section['anchor'] ) ) { |
||
| 1074 | $section['anchor'] = $key; |
||
| 1075 | } |
||
| 1076 | $section['anchor'] .= '_settings'; |
||
| 1077 | |||
| 1078 | if ( ! isset( $section['title'] ) ) { |
||
| 1079 | $section['title'] = $section['name']; |
||
| 1080 | } |
||
| 1081 | |||
| 1082 | if ( ! isset( $section['id'] ) ) { |
||
| 1083 | $section['id'] = $section['anchor']; |
||
| 1084 | } |
||
| 1085 | |||
| 1086 | $sections[ $key ] = $section; |
||
| 1087 | } |
||
| 1088 | |||
| 1089 | return $sections; |
||
| 1090 | } |
||
| 1091 | |||
| 1092 | /** |
||
| 1093 | * @since 4.0 |
||
| 1094 | * |
||
| 1095 | * @param array $values |
||
| 1096 | */ |
||
| 1097 | public static function advanced_settings( $values ) { |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * @since 4.0 |
||
| 1105 | * |
||
| 1106 | * @param array $values |
||
| 1107 | */ |
||
| 1108 | public static function buttons_settings( $values ) { |
||
| 1116 | |||
| 1117 | /** |
||
| 1118 | * @since 4.0 |
||
| 1119 | * |
||
| 1120 | * @param array $values |
||
| 1121 | */ |
||
| 1122 | public static function html_settings( $values ) { |
||
| 1125 | |||
| 1126 | /** |
||
| 1127 | * Replace old Submit Button href with new href to avoid errors in Chrome |
||
| 1128 | * |
||
| 1129 | * @since 2.03.08 |
||
| 1130 | * |
||
| 1131 | * @param array|boolean $values |
||
| 1132 | */ |
||
| 1133 | private static function clean_submit_html( &$values ) { |
||
| 1138 | |||
| 1139 | public static function mb_tags_box( $form_id, $class = '' ) { |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * @since 3.04.01 |
||
| 1155 | */ |
||
| 1156 | private static function advanced_helpers( $atts ) { |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Get an array of the options to display in the advanced tab |
||
| 1189 | * of the customization panel |
||
| 1190 | * |
||
| 1191 | * @since 2.0.6 |
||
| 1192 | */ |
||
| 1193 | private static function get_advanced_shortcodes() { |
||
| 1216 | |||
| 1217 | /** |
||
| 1218 | * @since 3.04.01 |
||
| 1219 | */ |
||
| 1220 | private static function user_shortcodes() { |
||
| 1234 | |||
| 1235 | /** |
||
| 1236 | * Get an array of the helper shortcodes to display in the customization panel |
||
| 1237 | * |
||
| 1238 | * @since 2.0.6 |
||
| 1239 | */ |
||
| 1240 | private static function get_shortcode_helpers( $settings_tab ) { |
||
| 1273 | |||
| 1274 | /** |
||
| 1275 | * Insert the form class setting into the form |
||
| 1276 | */ |
||
| 1277 | public static function form_classes( $form ) { |
||
| 1286 | |||
| 1287 | public static function get_email_html() { |
||
| 1300 | |||
| 1301 | public static function filter_content( $content, $form, $entry = false ) { |
||
| 1316 | |||
| 1317 | private static function get_entry_by_param( &$entry ) { |
||
| 1326 | |||
| 1327 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
||
| 1330 | |||
| 1331 | public static function process_bulk_form_actions( $errors ) { |
||
| 1382 | |||
| 1383 | public static function route() { |
||
| 1459 | |||
| 1460 | public static function json_error( $errors ) { |
||
| 1465 | |||
| 1466 | /** |
||
| 1467 | * Education for premium features. |
||
| 1468 | * |
||
| 1469 | * @since 4.05 |
||
| 1470 | */ |
||
| 1471 | public static function add_form_style_tab_options() { |
||
| 1474 | |||
| 1475 | /** |
||
| 1476 | * Add education about views. |
||
| 1477 | * |
||
| 1478 | * @since 4.07 |
||
| 1479 | */ |
||
| 1480 | public static function no_views( $values = array() ) { |
||
| 1487 | |||
| 1488 | /** |
||
| 1489 | * Add education about reports. |
||
| 1490 | * |
||
| 1491 | * @since 4.07 |
||
| 1492 | */ |
||
| 1493 | public static function no_reports( $values = array() ) { |
||
| 1499 | |||
| 1500 | /* FRONT-END FORMS */ |
||
| 1501 | public static function admin_bar_css() { |
||
| 1511 | |||
| 1512 | /** |
||
| 1513 | * @since 4.05.02 |
||
| 1514 | */ |
||
| 1515 | private static function move_menu_to_footer() { |
||
| 1521 | |||
| 1522 | public static function admin_bar_configure() { |
||
| 1543 | |||
| 1544 | /** |
||
| 1545 | * @since 2.05.07 |
||
| 1546 | */ |
||
| 1547 | public static function add_menu_to_admin_bar() { |
||
| 1561 | |||
| 1562 | /** |
||
| 1563 | * @since 2.05.07 |
||
| 1564 | */ |
||
| 1565 | private static function add_forms_to_admin_bar( $actions ) { |
||
| 1582 | |||
| 1583 | /** |
||
| 1584 | * The formidable shortcode |
||
| 1585 | * |
||
| 1586 | * @param array $atts The params from the shortcode. |
||
| 1587 | */ |
||
| 1588 | public static function get_form_shortcode( $atts ) { |
||
| 1614 | |||
| 1615 | public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
||
| 1654 | |||
| 1655 | private static function maybe_get_form_to_show( $id ) { |
||
| 1667 | |||
| 1668 | private static function is_viewable_draft_form( $form ) { |
||
| 1671 | |||
| 1672 | public static function get_form( $form, $title, $description, $atts = array() ) { |
||
| 1687 | |||
| 1688 | public static function enqueue_scripts( $params ) { |
||
| 1691 | |||
| 1692 | public static function get_form_contents( $form, $title, $description, $atts ) { |
||
| 1731 | |||
| 1732 | /** |
||
| 1733 | * If the form was processed earlier (init), get the generated errors |
||
| 1734 | * |
||
| 1735 | * @since 2.05 |
||
| 1736 | */ |
||
| 1737 | private static function get_saved_errors( $form, $params ) { |
||
| 1748 | |||
| 1749 | /** |
||
| 1750 | * @since 2.2.7 |
||
| 1751 | */ |
||
| 1752 | public static function just_created_entry( $form_id ) { |
||
| 1757 | |||
| 1758 | /** |
||
| 1759 | * @since 3.0 |
||
| 1760 | */ |
||
| 1761 | private static function get_confirmation_method( $atts ) { |
||
| 1772 | |||
| 1773 | public static function maybe_trigger_redirect( $form, $params, $args ) { |
||
| 1790 | |||
| 1791 | public static function trigger_redirect( $form, $params, $args ) { |
||
| 1805 | |||
| 1806 | /** |
||
| 1807 | * Used when the success action is not 'message' |
||
| 1808 | * |
||
| 1809 | * @since 2.05 |
||
| 1810 | */ |
||
| 1811 | public static function run_success_action( $args ) { |
||
| 1828 | |||
| 1829 | /** |
||
| 1830 | * @since 3.0 |
||
| 1831 | */ |
||
| 1832 | private static function load_page_after_submit( $args ) { |
||
| 1844 | |||
| 1845 | /** |
||
| 1846 | * @since 3.0 |
||
| 1847 | */ |
||
| 1848 | private static function redirect_after_submit( $args ) { |
||
| 1883 | |||
| 1884 | /** |
||
| 1885 | * @since 3.0 |
||
| 1886 | * |
||
| 1887 | * @param string $success_url |
||
| 1888 | * @param string $success_msg |
||
| 1889 | * @param array $args |
||
| 1890 | */ |
||
| 1891 | private static function get_redirect_message( $success_url, $success_msg, $args ) { |
||
| 1905 | |||
| 1906 | /** |
||
| 1907 | * Prepare to show the success message and empty form after submit |
||
| 1908 | * |
||
| 1909 | * @since 2.05 |
||
| 1910 | */ |
||
| 1911 | public static function show_message_after_save( $atts ) { |
||
| 1920 | |||
| 1921 | /** |
||
| 1922 | * Show an empty form |
||
| 1923 | * |
||
| 1924 | * @since 2.05 |
||
| 1925 | */ |
||
| 1926 | private static function show_form_after_submit( $args ) { |
||
| 1954 | |||
| 1955 | /** |
||
| 1956 | * @return string - 'before', 'after', or 'submit' |
||
| 1957 | * |
||
| 1958 | * @since 4.05.02 |
||
| 1959 | */ |
||
| 1960 | private static function message_placement( $form, $message ) { |
||
| 1978 | |||
| 1979 | /** |
||
| 1980 | * Get all the values needed on the new.php entry page |
||
| 1981 | * |
||
| 1982 | * @since 2.05 |
||
| 1983 | */ |
||
| 1984 | private static function fill_atts_for_form_display( &$args ) { |
||
| 1996 | |||
| 1997 | /** |
||
| 1998 | * Show the success message without the form |
||
| 1999 | * |
||
| 2000 | * @since 2.05 |
||
| 2001 | */ |
||
| 2002 | private static function show_lone_success_messsage( $atts ) { |
||
| 2015 | |||
| 2016 | /** |
||
| 2017 | * Prepare the success message before it's shown |
||
| 2018 | * |
||
| 2019 | * @since 2.05 |
||
| 2020 | */ |
||
| 2021 | private static function prepare_submit_message( $form, $entry_id ) { |
||
| 2036 | |||
| 2037 | public static function front_head() { |
||
| 2057 | |||
| 2058 | /** |
||
| 2059 | * @since 3.0 |
||
| 2060 | */ |
||
| 2061 | public static function has_combo_js_file() { |
||
| 2064 | |||
| 2065 | public static function maybe_load_css( $form, $this_load, $global_load ) { |
||
| 2078 | |||
| 2079 | /** |
||
| 2080 | * If css is loaded only on applicable pages, include it before the form loads |
||
| 2081 | * to prevent a flash of unstyled form. |
||
| 2082 | * |
||
| 2083 | * @since 4.01 |
||
| 2084 | */ |
||
| 2085 | private static function load_late_css() { |
||
| 2097 | |||
| 2098 | public static function defer_script_loading( $tag, $handle ) { |
||
| 2105 | |||
| 2106 | public static function footer_js( $location = 'footer' ) { |
||
| 2116 | |||
| 2117 | /** |
||
| 2118 | * @since 2.0.8 |
||
| 2119 | */ |
||
| 2120 | private static function maybe_minimize_form( $atts, &$content ) { |
||
| 2126 | |||
| 2127 | /** |
||
| 2128 | * @since 2.0.8 |
||
| 2129 | * @return boolean |
||
| 2130 | */ |
||
| 2131 | private static function is_minification_on( $atts ) { |
||
| 2134 | |||
| 2135 | /** |
||
| 2136 | * @deprecated 4.0 |
||
| 2137 | */ |
||
| 2138 | public static function new_form( $values = array() ) { |
||
| 2141 | |||
| 2142 | /** |
||
| 2143 | * @deprecated 4.0 |
||
| 2144 | */ |
||
| 2145 | public static function create( $values = array() ) { |
||
| 2149 | |||
| 2150 | /** |
||
| 2151 | * @deprecated 1.07.05 |
||
| 2152 | * @codeCoverageIgnore |
||
| 2153 | */ |
||
| 2154 | public static function add_default_templates( $path, $default = true, $template = true ) { |
||
| 2157 | |||
| 2158 | /** |
||
| 2159 | * @deprecated 3.0 |
||
| 2160 | * @codeCoverageIgnore |
||
| 2161 | */ |
||
| 2162 | public static function bulk_create_template( $ids ) { |
||
| 2165 | |||
| 2166 | /** |
||
| 2167 | * @deprecated 2.03 |
||
| 2168 | * @codeCoverageIgnore |
||
| 2169 | */ |
||
| 2170 | public static function register_pro_scripts() { |
||
| 2173 | |||
| 2174 | /** |
||
| 2175 | * @deprecated 3.0 |
||
| 2176 | * @codeCoverageIgnore |
||
| 2177 | */ |
||
| 2178 | public static function edit_key() { |
||
| 2181 | |||
| 2182 | /** |
||
| 2183 | * @deprecated 3.0 |
||
| 2184 | * @codeCoverageIgnore |
||
| 2185 | */ |
||
| 2186 | public static function edit_description() { |
||
| 2189 | |||
| 2190 | /** |
||
| 2191 | * @deprecated 4.08 |
||
| 2192 | * @since 3.06 |
||
| 2193 | */ |
||
| 2194 | public static function add_new() { |
||
| 2195 | _deprecated_function( __FUNCTION__, '4.08' ); |
||
| 2196 | } |
||
| 2197 | } |
||
| 2198 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.