@@ -2,89 +2,89 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class FrmHooksController { |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * Trigger plugin-wide hook loading |
|
| 7 | - */ |
|
| 8 | - public static function trigger_load_hook( $hooks = 'load_hooks' ) { |
|
| 9 | - $controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) ); |
|
| 10 | - |
|
| 11 | - $trigger_hooks = $hooks; |
|
| 12 | - $hooks = (array) $hooks; |
|
| 13 | - |
|
| 14 | - if ( 'load_hooks' == $trigger_hooks ) { |
|
| 15 | - if ( is_admin() ) { |
|
| 16 | - $hooks[] = 'load_admin_hooks'; |
|
| 17 | - if ( defined( 'DOING_AJAX' ) ) { |
|
| 18 | - $hooks[] = 'load_ajax_hooks'; |
|
| 19 | - $hooks[] = 'load_form_hooks'; |
|
| 20 | - } |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - if ( is_multisite() ) { |
|
| 24 | - $hooks[] = 'load_multisite_hooks'; |
|
| 25 | - } |
|
| 26 | - } else { |
|
| 27 | - // Make sure the hooks are only triggered once |
|
| 28 | - add_filter( 'frm' . str_replace( 'load', '', $trigger_hooks ) . '_loaded', '__return_true' ); |
|
| 29 | - } |
|
| 30 | - unset( $trigger_hooks ); |
|
| 31 | - |
|
| 32 | - // Instansiate Controllers |
|
| 33 | - foreach ( $controllers as $c ) { |
|
| 34 | - foreach ( $hooks as $hook ) { |
|
| 5 | + /** |
|
| 6 | + * Trigger plugin-wide hook loading |
|
| 7 | + */ |
|
| 8 | + public static function trigger_load_hook( $hooks = 'load_hooks' ) { |
|
| 9 | + $controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) ); |
|
| 10 | + |
|
| 11 | + $trigger_hooks = $hooks; |
|
| 12 | + $hooks = (array) $hooks; |
|
| 13 | + |
|
| 14 | + if ( 'load_hooks' == $trigger_hooks ) { |
|
| 15 | + if ( is_admin() ) { |
|
| 16 | + $hooks[] = 'load_admin_hooks'; |
|
| 17 | + if ( defined( 'DOING_AJAX' ) ) { |
|
| 18 | + $hooks[] = 'load_ajax_hooks'; |
|
| 19 | + $hooks[] = 'load_form_hooks'; |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + if ( is_multisite() ) { |
|
| 24 | + $hooks[] = 'load_multisite_hooks'; |
|
| 25 | + } |
|
| 26 | + } else { |
|
| 27 | + // Make sure the hooks are only triggered once |
|
| 28 | + add_filter( 'frm' . str_replace( 'load', '', $trigger_hooks ) . '_loaded', '__return_true' ); |
|
| 29 | + } |
|
| 30 | + unset( $trigger_hooks ); |
|
| 31 | + |
|
| 32 | + // Instansiate Controllers |
|
| 33 | + foreach ( $controllers as $c ) { |
|
| 34 | + foreach ( $hooks as $hook ) { |
|
| 35 | 35 | call_user_func( array( $c, $hook ) ); |
| 36 | 36 | unset( $hook ); |
| 37 | - } |
|
| 37 | + } |
|
| 38 | 38 | unset( $c ); |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public static function trigger_load_form_hooks() { |
|
| 44 | - self::trigger_load_hook( 'load_form_hooks' ); |
|
| 45 | - } |
|
| 43 | + public static function trigger_load_form_hooks() { |
|
| 44 | + self::trigger_load_hook( 'load_form_hooks' ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | public static function load_hooks() { |
| 48 | 48 | add_action( 'rest_api_init', 'FrmAppController::create_rest_routes', 0 ); |
| 49 | - add_action( 'plugins_loaded', 'FrmAppController::load_lang' ); |
|
| 49 | + add_action( 'plugins_loaded', 'FrmAppController::load_lang' ); |
|
| 50 | 50 | add_filter( 'widget_text', 'do_shortcode' ); |
| 51 | 51 | |
| 52 | - // Entries controller |
|
| 53 | - add_action( 'wp_loaded', 'FrmEntriesController::process_entry', 10, 0 ); |
|
| 54 | - add_action( 'frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100 ); |
|
| 52 | + // Entries controller |
|
| 53 | + add_action( 'wp_loaded', 'FrmEntriesController::process_entry', 10, 0 ); |
|
| 54 | + add_action( 'frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100 ); |
|
| 55 | 55 | |
| 56 | - // Form Actions Controller |
|
| 57 | - add_action( 'init', 'FrmFormActionsController::register_post_types', 1 ); |
|
| 56 | + // Form Actions Controller |
|
| 57 | + add_action( 'init', 'FrmFormActionsController::register_post_types', 1 ); |
|
| 58 | 58 | add_action( 'frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 3 ); |
| 59 | 59 | |
| 60 | - // Forms Controller |
|
| 61 | - add_action( 'widgets_init', 'FrmFormsController::register_widgets' ); |
|
| 60 | + // Forms Controller |
|
| 61 | + add_action( 'widgets_init', 'FrmFormsController::register_widgets' ); |
|
| 62 | 62 | add_action( 'init', 'FrmFormsController::front_head' ); |
| 63 | - add_filter( 'frm_content', 'FrmFormsController::filter_content', 10, 3 ); |
|
| 64 | - add_filter( 'frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3 ); |
|
| 65 | - add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' ); |
|
| 63 | + add_filter( 'frm_content', 'FrmFormsController::filter_content', 10, 3 ); |
|
| 64 | + add_filter( 'frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3 ); |
|
| 65 | + add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' ); |
|
| 66 | 66 | add_action( 'wp_footer', 'FrmFormsController::footer_js', 1, 0 ); |
| 67 | 67 | |
| 68 | 68 | add_action( 'wp_scheduled_delete', 'FrmForm::scheduled_delete' ); |
| 69 | 69 | |
| 70 | - // Form Shortcodes |
|
| 71 | - add_shortcode( 'formidable', 'FrmFormsController::get_form_shortcode' ); |
|
| 70 | + // Form Shortcodes |
|
| 71 | + add_shortcode( 'formidable', 'FrmFormsController::get_form_shortcode' ); |
|
| 72 | 72 | |
| 73 | - // Styles Controller |
|
| 74 | - add_action( 'init', 'FrmStylesController::register_post_types', 0 ); |
|
| 75 | - add_filter( 'frm_get_style_opts', 'FrmStylesController::get_style_opts' ); |
|
| 76 | - add_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 ); |
|
| 77 | - add_filter( 'frm_show_entry_styles', 'FrmStylesController::show_entry_styles' ); |
|
| 73 | + // Styles Controller |
|
| 74 | + add_action( 'init', 'FrmStylesController::register_post_types', 0 ); |
|
| 75 | + add_filter( 'frm_get_style_opts', 'FrmStylesController::get_style_opts' ); |
|
| 76 | + add_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 ); |
|
| 77 | + add_filter( 'frm_show_entry_styles', 'FrmStylesController::show_entry_styles' ); |
|
| 78 | 78 | |
| 79 | 79 | //Simple Blocks Controller |
| 80 | 80 | add_action( 'init', 'FrmSimpleBlocksController::register_simple_form_block' ); |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | public static function load_admin_hooks() { |
| 84 | - add_action( 'admin_menu', 'FrmAppController::menu', 1 ); |
|
| 84 | + add_action( 'admin_menu', 'FrmAppController::menu', 1 ); |
|
| 85 | 85 | add_filter( 'admin_body_class', 'FrmAppController::add_admin_class', 999 ); |
| 86 | - add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' ); |
|
| 87 | - add_action( 'admin_notices', 'FrmAppController::pro_get_started_headline' ); |
|
| 86 | + add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' ); |
|
| 87 | + add_action( 'admin_notices', 'FrmAppController::pro_get_started_headline' ); |
|
| 88 | 88 | add_action( 'admin_init', 'FrmAppController::admin_init', 11 ); |
| 89 | 89 | add_filter( 'plugin_action_links_' . FrmAppHelper::plugin_folder() . '/formidable.php', 'FrmAppController::settings_link' ); |
| 90 | 90 | add_filter( 'admin_footer_text', 'FrmAppController::set_footer_text' ); |
@@ -95,120 +95,120 @@ discard block |
||
| 95 | 95 | add_action( 'admin_menu', 'FrmAddonsController::menu', 100 ); |
| 96 | 96 | add_filter( 'pre_set_site_transient_update_plugins', 'FrmAddonsController::check_update' ); |
| 97 | 97 | |
| 98 | - // Entries Controller |
|
| 99 | - add_action( 'admin_menu', 'FrmEntriesController::menu', 12 ); |
|
| 100 | - add_filter( 'contextual_help', 'FrmEntriesController::contextual_help', 10, 3 ); |
|
| 101 | - add_filter( 'set-screen-option', 'FrmEntriesController::save_per_page', 10, 3 ); |
|
| 102 | - add_filter( 'update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5 ); |
|
| 103 | - add_action( 'updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4 ); |
|
| 104 | - |
|
| 105 | - // Form Actions Controller |
|
| 106 | - if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
| 107 | - add_action( 'frm_before_update_form_settings', 'FrmFormActionsController::update_settings' ); |
|
| 108 | - } |
|
| 109 | - add_action( 'frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3 ); |
|
| 110 | - |
|
| 111 | - // Forms Controller |
|
| 112 | - add_action( 'admin_menu', 'FrmFormsController::menu', 10 ); |
|
| 113 | - add_action( 'admin_head-toplevel_page_formidable', 'FrmFormsController::head' ); |
|
| 114 | - |
|
| 115 | - add_filter( 'set-screen-option', 'FrmFormsController::save_per_page', 10, 3 ); |
|
| 116 | - add_action( 'admin_footer', 'FrmFormsController::insert_form_popup' ); |
|
| 98 | + // Entries Controller |
|
| 99 | + add_action( 'admin_menu', 'FrmEntriesController::menu', 12 ); |
|
| 100 | + add_filter( 'contextual_help', 'FrmEntriesController::contextual_help', 10, 3 ); |
|
| 101 | + add_filter( 'set-screen-option', 'FrmEntriesController::save_per_page', 10, 3 ); |
|
| 102 | + add_filter( 'update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5 ); |
|
| 103 | + add_action( 'updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4 ); |
|
| 104 | + |
|
| 105 | + // Form Actions Controller |
|
| 106 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
| 107 | + add_action( 'frm_before_update_form_settings', 'FrmFormActionsController::update_settings' ); |
|
| 108 | + } |
|
| 109 | + add_action( 'frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3 ); |
|
| 110 | + |
|
| 111 | + // Forms Controller |
|
| 112 | + add_action( 'admin_menu', 'FrmFormsController::menu', 10 ); |
|
| 113 | + add_action( 'admin_head-toplevel_page_formidable', 'FrmFormsController::head' ); |
|
| 114 | + |
|
| 115 | + add_filter( 'set-screen-option', 'FrmFormsController::save_per_page', 10, 3 ); |
|
| 116 | + add_action( 'admin_footer', 'FrmFormsController::insert_form_popup' ); |
|
| 117 | 117 | add_action( 'media_buttons', 'FrmFormsController::insert_form_button' ); |
| 118 | 118 | add_action( 'et_pb_admin_excluded_shortcodes', 'FrmFormsController::prevent_divi_conflict' ); |
| 119 | 119 | |
| 120 | - // Forms Model |
|
| 121 | - add_action( 'frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2 ); |
|
| 120 | + // Forms Model |
|
| 121 | + add_action( 'frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2 ); |
|
| 122 | 122 | |
| 123 | - // Settings Controller |
|
| 124 | - add_action( 'admin_menu', 'FrmSettingsController::menu', 45 ); |
|
| 125 | - add_action( 'frm_before_settings', 'FrmSettingsController::license_box' ); |
|
| 123 | + // Settings Controller |
|
| 124 | + add_action( 'admin_menu', 'FrmSettingsController::menu', 45 ); |
|
| 125 | + add_action( 'frm_before_settings', 'FrmSettingsController::license_box' ); |
|
| 126 | 126 | add_action( 'frm_after_settings', 'FrmSettingsController::settings_cta' ); |
| 127 | 127 | add_action( 'wp_ajax_frm_settings_tab', 'FrmSettingsController::load_settings_tab' ); |
| 128 | 128 | |
| 129 | - // Styles Controller |
|
| 130 | - add_action( 'admin_menu', 'FrmStylesController::menu', 14 ); |
|
| 131 | - add_action( 'admin_init', 'FrmStylesController::admin_init' ); |
|
| 129 | + // Styles Controller |
|
| 130 | + add_action( 'admin_menu', 'FrmStylesController::menu', 14 ); |
|
| 131 | + add_action( 'admin_init', 'FrmStylesController::admin_init' ); |
|
| 132 | 132 | |
| 133 | - // XML Controller |
|
| 134 | - add_action( 'admin_menu', 'FrmXMLController::menu', 41 ); |
|
| 133 | + // XML Controller |
|
| 134 | + add_action( 'admin_menu', 'FrmXMLController::menu', 41 ); |
|
| 135 | 135 | |
| 136 | 136 | // Simple Blocks Controller |
| 137 | 137 | add_action( 'enqueue_block_editor_assets', 'FrmSimpleBlocksController::block_editor_assets' ); |
| 138 | - } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | public static function load_ajax_hooks() { |
| 141 | 141 | add_action( 'wp_ajax_frm_install', 'FrmAppController::ajax_install' ); |
| 142 | - add_action( 'wp_ajax_frm_uninstall', 'FrmAppController::uninstall' ); |
|
| 143 | - add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' ); |
|
| 142 | + add_action( 'wp_ajax_frm_uninstall', 'FrmAppController::uninstall' ); |
|
| 143 | + add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' ); |
|
| 144 | 144 | |
| 145 | 145 | // Addons |
| 146 | 146 | add_action( 'wp_ajax_frm_addon_activate', 'FrmAddon::activate' ); |
| 147 | 147 | add_action( 'wp_ajax_frm_addon_deactivate', 'FrmAddon::deactivate' ); |
| 148 | 148 | add_action( 'wp_ajax_frm_install_addon', 'FrmAddonsController::ajax_install_addon' ); |
| 149 | 149 | |
| 150 | - // Fields Controller |
|
| 151 | - add_action( 'wp_ajax_frm_load_field', 'FrmFieldsController::load_field' ); |
|
| 152 | - add_action( 'wp_ajax_frm_insert_field', 'FrmFieldsController::create' ); |
|
| 153 | - add_action( 'wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option' ); |
|
| 154 | - add_action( 'wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate' ); |
|
| 155 | - add_action( 'wp_ajax_frm_delete_field', 'FrmFieldsController::destroy' ); |
|
| 156 | - add_action( 'wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option' ); |
|
| 157 | - add_action( 'wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices' ); |
|
| 158 | - add_action( 'wp_ajax_frm_import_options', 'FrmFieldsController::import_options' ); |
|
| 159 | - add_action( 'wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order' ); |
|
| 160 | - |
|
| 161 | - // Form Actions Controller |
|
| 162 | - add_action( 'wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action' ); |
|
| 163 | - add_action( 'wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action' ); |
|
| 164 | - |
|
| 165 | - // Forms Controller |
|
| 150 | + // Fields Controller |
|
| 151 | + add_action( 'wp_ajax_frm_load_field', 'FrmFieldsController::load_field' ); |
|
| 152 | + add_action( 'wp_ajax_frm_insert_field', 'FrmFieldsController::create' ); |
|
| 153 | + add_action( 'wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option' ); |
|
| 154 | + add_action( 'wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate' ); |
|
| 155 | + add_action( 'wp_ajax_frm_delete_field', 'FrmFieldsController::destroy' ); |
|
| 156 | + add_action( 'wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option' ); |
|
| 157 | + add_action( 'wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices' ); |
|
| 158 | + add_action( 'wp_ajax_frm_import_options', 'FrmFieldsController::import_options' ); |
|
| 159 | + add_action( 'wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order' ); |
|
| 160 | + |
|
| 161 | + // Form Actions Controller |
|
| 162 | + add_action( 'wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action' ); |
|
| 163 | + add_action( 'wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action' ); |
|
| 164 | + |
|
| 165 | + // Forms Controller |
|
| 166 | 166 | add_action( 'wp_ajax_frm_create_from_template', 'FrmFormsController::_create_from_template' ); |
| 167 | 167 | add_action( 'wp_ajax_frm_save_form', 'FrmFormsController::route' ); |
| 168 | - add_action( 'wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' ); |
|
| 169 | - add_action( 'wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' ); |
|
| 170 | - add_action( 'wp_ajax_frm_forms_preview', 'FrmFormsController::preview' ); |
|
| 171 | - add_action( 'wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' ); |
|
| 168 | + add_action( 'wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' ); |
|
| 169 | + add_action( 'wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' ); |
|
| 170 | + add_action( 'wp_ajax_frm_forms_preview', 'FrmFormsController::preview' ); |
|
| 171 | + add_action( 'wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' ); |
|
| 172 | 172 | |
| 173 | 173 | // Settings |
| 174 | 174 | add_action( 'wp_ajax_frm_lite_settings_upgrade', 'FrmSettingsController::settings_cta_dismiss' ); |
| 175 | 175 | |
| 176 | - // Styles Controller |
|
| 177 | - add_action( 'wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling' ); |
|
| 178 | - add_action( 'wp_ajax_frm_change_styling', 'FrmStylesController::change_styling' ); |
|
| 179 | - add_action( 'wp_ajax_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
| 180 | - add_action( 'wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
| 176 | + // Styles Controller |
|
| 177 | + add_action( 'wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling' ); |
|
| 178 | + add_action( 'wp_ajax_frm_change_styling', 'FrmStylesController::change_styling' ); |
|
| 179 | + add_action( 'wp_ajax_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
| 180 | + add_action( 'wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
| 181 | 181 | add_action( 'wp_ajax_frmpro_css', 'FrmStylesController::load_saved_css' ); |
| 182 | 182 | add_action( 'wp_ajax_nopriv_frmpro_css', 'FrmStylesController::load_saved_css' ); |
| 183 | 183 | |
| 184 | - // XML Controller |
|
| 184 | + // XML Controller |
|
| 185 | 185 | add_action( 'wp_ajax_frm_entries_csv', 'FrmXMLController::csv' ); |
| 186 | 186 | add_action( 'wp_ajax_nopriv_frm_entries_csv', 'FrmXMLController::csv' ); |
| 187 | - add_action( 'wp_ajax_frm_export_xml', 'FrmXMLController::export_xml' ); |
|
| 188 | - } |
|
| 187 | + add_action( 'wp_ajax_frm_export_xml', 'FrmXMLController::export_xml' ); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | public static function load_form_hooks() { |
| 191 | - // Fields Controller |
|
| 192 | - add_filter( 'frm_field_type', 'FrmFieldsController::change_type' ); |
|
| 193 | - add_action( 'frm_field_input_html', 'FrmFieldsController::input_html' ); |
|
| 194 | - add_filter( 'frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3 ); |
|
| 195 | - add_filter( 'frm_field_label_seen', 'FrmFieldsController::check_label' ); |
|
| 191 | + // Fields Controller |
|
| 192 | + add_filter( 'frm_field_type', 'FrmFieldsController::change_type' ); |
|
| 193 | + add_action( 'frm_field_input_html', 'FrmFieldsController::input_html' ); |
|
| 194 | + add_filter( 'frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3 ); |
|
| 195 | + add_filter( 'frm_field_label_seen', 'FrmFieldsController::check_label' ); |
|
| 196 | 196 | |
| 197 | 197 | // Forms Controller |
| 198 | 198 | add_filter( 'frm_form_classes', 'FrmFormsController::form_classes' ); |
| 199 | 199 | |
| 200 | - // Styles Controller |
|
| 201 | - add_filter( 'frm_use_important_width', 'FrmStylesController::important_style', 10, 2 ); |
|
| 202 | - } |
|
| 200 | + // Styles Controller |
|
| 201 | + add_filter( 'frm_use_important_width', 'FrmStylesController::important_style', 10, 2 ); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | 204 | public static function load_view_hooks() { |
| 205 | - // Hooks go here when a view is loaded |
|
| 206 | - } |
|
| 205 | + // Hooks go here when a view is loaded |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | public static function load_multisite_hooks() { |
| 209 | 209 | add_action( 'wpmu_upgrade_site', 'FrmAppController::network_upgrade_site' ); |
| 210 | 210 | |
| 211 | - // drop tables when mu site is deleted |
|
| 212 | - add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' ); |
|
| 213 | - } |
|
| 211 | + // drop tables when mu site is deleted |
|
| 212 | + add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' ); |
|
| 213 | + } |
|
| 214 | 214 | } |
@@ -874,6 +874,7 @@ discard block |
||
| 874 | 874 | * Get an array of the helper shortcodes to display in the customization panel |
| 875 | 875 | * |
| 876 | 876 | * @since 2.0.6 |
| 877 | + * @param boolean $settings_tab |
|
| 877 | 878 | */ |
| 878 | 879 | private static function get_shortcode_helpers( $settings_tab ) { |
| 879 | 880 | $entry_shortcodes = array( |
@@ -952,6 +953,9 @@ discard block |
||
| 952 | 953 | return $content; |
| 953 | 954 | } |
| 954 | 955 | |
| 956 | + /** |
|
| 957 | + * @param boolean $entry |
|
| 958 | + */ |
|
| 955 | 959 | private static function get_entry_by_param( &$entry ) { |
| 956 | 960 | if ( ! $entry || ! is_object( $entry ) ) { |
| 957 | 961 | if ( ! $entry || ! is_numeric( $entry ) ) { |
@@ -1235,6 +1239,9 @@ discard block |
||
| 1235 | 1239 | return $form; |
| 1236 | 1240 | } |
| 1237 | 1241 | |
| 1242 | + /** |
|
| 1243 | + * @param string $id |
|
| 1244 | + */ |
|
| 1238 | 1245 | private static function maybe_get_form_to_show( $id ) { |
| 1239 | 1246 | $form = false; |
| 1240 | 1247 | |
@@ -1648,6 +1655,7 @@ discard block |
||
| 1648 | 1655 | |
| 1649 | 1656 | /** |
| 1650 | 1657 | * @since 2.0.8 |
| 1658 | + * @param string $content |
|
| 1651 | 1659 | */ |
| 1652 | 1660 | private static function maybe_minimize_form( $atts, &$content ) { |
| 1653 | 1661 | // check if minimizing is turned on |
@@ -276,6 +276,9 @@ discard block |
||
| 276 | 276 | return $this->alter_builder_classes( $classes ); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | + /** |
|
| 280 | + * @param string $classes |
|
| 281 | + */ |
|
| 279 | 282 | protected function alter_builder_classes( $classes ) { |
| 280 | 283 | return $classes; |
| 281 | 284 | } |
@@ -470,6 +473,11 @@ discard block |
||
| 470 | 473 | return $html; |
| 471 | 474 | } |
| 472 | 475 | |
| 476 | + /** |
|
| 477 | + * @param string $html |
|
| 478 | + * |
|
| 479 | + * @return string |
|
| 480 | + */ |
|
| 473 | 481 | protected function after_replace_html_shortcodes( $args, $html ) { |
| 474 | 482 | return $html; |
| 475 | 483 | } |
@@ -765,6 +773,7 @@ discard block |
||
| 765 | 773 | * Link input to field description for screen readers |
| 766 | 774 | * |
| 767 | 775 | * @since 3.0 |
| 776 | + * @param string $input_html |
|
| 768 | 777 | */ |
| 769 | 778 | protected function add_aria_description( $args, &$input_html ) { |
| 770 | 779 | if ( $this->get_field_column( 'description' ) != '' ) { |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmFormActionsController { |
| 4 | - public static $action_post_type = 'frm_form_actions'; |
|
| 5 | - public static $registered_actions; |
|
| 4 | + public static $action_post_type = 'frm_form_actions'; |
|
| 5 | + public static $registered_actions; |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Variables saved in the post: |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * menu_order: form id |
| 11 | 11 | * post_excerpt: action type |
| 12 | 12 | */ |
| 13 | - public static function register_post_types() { |
|
| 13 | + public static function register_post_types() { |
|
| 14 | 14 | register_post_type( |
| 15 | 15 | self::$action_post_type, |
| 16 | 16 | array( |
@@ -27,84 +27,84 @@ discard block |
||
| 27 | 27 | ) |
| 28 | 28 | ); |
| 29 | 29 | |
| 30 | - self::actions_init(); |
|
| 31 | - } |
|
| 30 | + self::actions_init(); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public static function actions_init() { |
|
| 34 | - self::$registered_actions = new Frm_Form_Action_Factory(); |
|
| 35 | - self::register_actions(); |
|
| 36 | - do_action( 'frm_form_actions_init' ); |
|
| 37 | - } |
|
| 33 | + public static function actions_init() { |
|
| 34 | + self::$registered_actions = new Frm_Form_Action_Factory(); |
|
| 35 | + self::register_actions(); |
|
| 36 | + do_action( 'frm_form_actions_init' ); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public static function register_actions() { |
|
| 39 | + public static function register_actions() { |
|
| 40 | 40 | $action_classes = array( |
| 41 | - 'email' => 'FrmEmailAction', |
|
| 42 | - 'wppost' => 'FrmDefPostAction', |
|
| 43 | - 'register' => 'FrmDefRegAction', |
|
| 44 | - 'paypal' => 'FrmDefPayPalAction', |
|
| 45 | - //'aweber' => 'FrmDefAweberAction', |
|
| 46 | - 'mailchimp' => 'FrmDefMlcmpAction', |
|
| 47 | - 'twilio' => 'FrmDefTwilioAction', |
|
| 48 | - 'payment' => 'FrmDefHrsAction', |
|
| 49 | - ); |
|
| 41 | + 'email' => 'FrmEmailAction', |
|
| 42 | + 'wppost' => 'FrmDefPostAction', |
|
| 43 | + 'register' => 'FrmDefRegAction', |
|
| 44 | + 'paypal' => 'FrmDefPayPalAction', |
|
| 45 | + //'aweber' => 'FrmDefAweberAction', |
|
| 46 | + 'mailchimp' => 'FrmDefMlcmpAction', |
|
| 47 | + 'twilio' => 'FrmDefTwilioAction', |
|
| 48 | + 'payment' => 'FrmDefHrsAction', |
|
| 49 | + ); |
|
| 50 | 50 | $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes ); |
| 51 | 51 | |
| 52 | 52 | include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php' ); |
| 53 | 53 | include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php' ); |
| 54 | 54 | |
| 55 | - foreach ( $action_classes as $action_class ) { |
|
| 55 | + foreach ( $action_classes as $action_class ) { |
|
| 56 | 56 | self::$registered_actions->register( $action_class ); |
| 57 | - } |
|
| 58 | - } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | public static function get_form_actions( $action = 'all' ) { |
| 61 | - $temp_actions = self::$registered_actions; |
|
| 61 | + $temp_actions = self::$registered_actions; |
|
| 62 | 62 | if ( empty( $temp_actions ) ) { |
| 63 | - self::actions_init(); |
|
| 64 | - $temp_actions = self::$registered_actions->actions; |
|
| 65 | - } else { |
|
| 66 | - $temp_actions = $temp_actions->actions; |
|
| 67 | - } |
|
| 63 | + self::actions_init(); |
|
| 64 | + $temp_actions = self::$registered_actions->actions; |
|
| 65 | + } else { |
|
| 66 | + $temp_actions = $temp_actions->actions; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $actions = array(); |
|
| 69 | + $actions = array(); |
|
| 70 | 70 | |
| 71 | - foreach ( $temp_actions as $a ) { |
|
| 72 | - if ( 'all' != $action && $a->id_base == $action ) { |
|
| 73 | - return $a; |
|
| 74 | - } |
|
| 71 | + foreach ( $temp_actions as $a ) { |
|
| 72 | + if ( 'all' != $action && $a->id_base == $action ) { |
|
| 73 | + return $a; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | $actions[ $a->id_base ] = $a; |
| 77 | - } |
|
| 78 | - unset( $temp_actions, $a ); |
|
| 79 | - |
|
| 80 | - $action_limit = 10; |
|
| 81 | - if ( count( $actions ) <= $action_limit ) { |
|
| 82 | - return $actions; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - // remove the last few inactive icons if there are too many |
|
| 86 | - $temp_actions = $actions; |
|
| 87 | - arsort( $temp_actions ); |
|
| 88 | - foreach ( $temp_actions as $type => $a ) { |
|
| 89 | - if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) { |
|
| 77 | + } |
|
| 78 | + unset( $temp_actions, $a ); |
|
| 79 | + |
|
| 80 | + $action_limit = 10; |
|
| 81 | + if ( count( $actions ) <= $action_limit ) { |
|
| 82 | + return $actions; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + // remove the last few inactive icons if there are too many |
|
| 86 | + $temp_actions = $actions; |
|
| 87 | + arsort( $temp_actions ); |
|
| 88 | + foreach ( $temp_actions as $type => $a ) { |
|
| 89 | + if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) { |
|
| 90 | 90 | unset( $actions[ $type ] ); |
| 91 | - if ( count( $actions ) <= $action_limit ) { |
|
| 92 | - break; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - unset( $type, $a ); |
|
| 96 | - } |
|
| 91 | + if ( count( $actions ) <= $action_limit ) { |
|
| 92 | + break; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + unset( $type, $a ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - return $actions; |
|
| 99 | - } |
|
| 98 | + return $actions; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * @since 2.0 |
| 103 | 103 | */ |
| 104 | - public static function list_actions( $form, $values ) { |
|
| 105 | - if ( empty( $form ) ) { |
|
| 106 | - return; |
|
| 107 | - } |
|
| 104 | + public static function list_actions( $form, $values ) { |
|
| 105 | + if ( empty( $form ) ) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * Use this hook to migrate old settings into a new action |
@@ -118,72 +118,72 @@ discard block |
||
| 118 | 118 | ); |
| 119 | 119 | $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters ); |
| 120 | 120 | |
| 121 | - $action_controls = self::get_form_actions(); |
|
| 121 | + $action_controls = self::get_form_actions(); |
|
| 122 | 122 | |
| 123 | - $action_map = array(); |
|
| 123 | + $action_map = array(); |
|
| 124 | 124 | |
| 125 | 125 | foreach ( $action_controls as $key => $control ) { |
| 126 | - $action_map[ $control->id_base ] = $key; |
|
| 127 | - } |
|
| 126 | + $action_map[ $control->id_base ] = $key; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - foreach ( $form_actions as $action ) { |
|
| 130 | - if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
|
| 131 | - // don't try and show settings if action no longer exists |
|
| 132 | - continue; |
|
| 133 | - } |
|
| 129 | + foreach ( $form_actions as $action ) { |
|
| 130 | + if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
|
| 131 | + // don't try and show settings if action no longer exists |
|
| 132 | + continue; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
|
| 136 | - } |
|
| 137 | - } |
|
| 135 | + self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
| 140 | 140 | $action_control->_set( $action_key ); |
| 141 | 141 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' ); |
| 142 | - } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - public static function add_form_action() { |
|
| 144 | + public static function add_form_action() { |
|
| 145 | 145 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 146 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 146 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 147 | 147 | |
| 148 | - global $frm_vars; |
|
| 148 | + global $frm_vars; |
|
| 149 | 149 | |
| 150 | 150 | $action_key = absint( $_POST['list_id'] ); |
| 151 | - $action_type = sanitize_text_field( $_POST['type'] ); |
|
| 151 | + $action_type = sanitize_text_field( $_POST['type'] ); |
|
| 152 | 152 | |
| 153 | - $action_control = self::get_form_actions( $action_type ); |
|
| 153 | + $action_control = self::get_form_actions( $action_type ); |
|
| 154 | 154 | $action_control->_set( $action_key ); |
| 155 | 155 | |
| 156 | - $form_id = absint( $_POST['form_id'] ); |
|
| 156 | + $form_id = absint( $_POST['form_id'] ); |
|
| 157 | 157 | |
| 158 | 158 | $form_action = $action_control->prepare_new( $form_id ); |
| 159 | 159 | |
| 160 | - $values = array(); |
|
| 160 | + $values = array(); |
|
| 161 | 161 | $form = self::fields_to_values( $form_id, $values ); |
| 162 | 162 | |
| 163 | 163 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' ); |
| 164 | - wp_die(); |
|
| 165 | - } |
|
| 164 | + wp_die(); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - public static function fill_action() { |
|
| 167 | + public static function fill_action() { |
|
| 168 | 168 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 169 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 169 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 170 | 170 | |
| 171 | - $action_key = absint( $_POST['action_id'] ); |
|
| 172 | - $action_type = sanitize_text_field( $_POST['action_type'] ); |
|
| 171 | + $action_key = absint( $_POST['action_id'] ); |
|
| 172 | + $action_type = sanitize_text_field( $_POST['action_type'] ); |
|
| 173 | 173 | |
| 174 | - $action_control = self::get_form_actions( $action_type ); |
|
| 174 | + $action_control = self::get_form_actions( $action_type ); |
|
| 175 | 175 | if ( empty( $action_control ) ) { |
| 176 | - wp_die(); |
|
| 177 | - } |
|
| 176 | + wp_die(); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - $form_action = $action_control->get_single_action( $action_key ); |
|
| 179 | + $form_action = $action_control->get_single_action( $action_key ); |
|
| 180 | 180 | |
| 181 | - $values = array(); |
|
| 181 | + $values = array(); |
|
| 182 | 182 | $form = self::fields_to_values( $form_action->menu_order, $values ); |
| 183 | 183 | |
| 184 | 184 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' ); |
| 185 | - wp_die(); |
|
| 186 | - } |
|
| 185 | + wp_die(); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | private static function fields_to_values( $form_id, array &$values ) { |
| 189 | 189 | $form = FrmForm::getOne( $form_id ); |
@@ -194,19 +194,19 @@ discard block |
||
| 194 | 194 | ); |
| 195 | 195 | |
| 196 | 196 | $fields = FrmField::get_all_for_form( $form->id ); |
| 197 | - foreach ( $fields as $k => $f ) { |
|
| 198 | - $f = (array) $f; |
|
| 199 | - $opts = (array) $f['field_options']; |
|
| 197 | + foreach ( $fields as $k => $f ) { |
|
| 198 | + $f = (array) $f; |
|
| 199 | + $opts = (array) $f['field_options']; |
|
| 200 | 200 | $f = array_merge( $opts, $f ); |
| 201 | - if ( ! isset( $f['post_field'] ) ) { |
|
| 202 | - $f['post_field'] = ''; |
|
| 203 | - } |
|
| 204 | - $values['fields'][] = $f; |
|
| 201 | + if ( ! isset( $f['post_field'] ) ) { |
|
| 202 | + $f['post_field'] = ''; |
|
| 203 | + } |
|
| 204 | + $values['fields'][] = $f; |
|
| 205 | 205 | unset( $k, $f ); |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return $form; |
|
| 209 | - } |
|
| 208 | + return $form; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | public static function update_settings( $form_id ) { |
| 212 | 212 | $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
@@ -214,9 +214,9 @@ discard block |
||
| 214 | 214 | wp_die( esc_html__( 'You do not have permission to do that', 'formidable' ) ); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - global $wpdb; |
|
| 217 | + global $wpdb; |
|
| 218 | 218 | |
| 219 | - $registered_actions = self::$registered_actions->actions; |
|
| 219 | + $registered_actions = self::$registered_actions->actions; |
|
| 220 | 220 | |
| 221 | 221 | $old_actions = FrmDb::get_col( |
| 222 | 222 | $wpdb->posts, |
@@ -226,23 +226,23 @@ discard block |
||
| 226 | 226 | ), |
| 227 | 227 | 'ID' |
| 228 | 228 | ); |
| 229 | - $new_actions = array(); |
|
| 229 | + $new_actions = array(); |
|
| 230 | 230 | |
| 231 | - foreach ( $registered_actions as $registered_action ) { |
|
| 231 | + foreach ( $registered_actions as $registered_action ) { |
|
| 232 | 232 | $action_ids = $registered_action->update_callback( $form_id ); |
| 233 | - if ( ! empty( $action_ids ) ) { |
|
| 234 | - $new_actions[] = $action_ids; |
|
| 235 | - } |
|
| 236 | - } |
|
| 233 | + if ( ! empty( $action_ids ) ) { |
|
| 234 | + $new_actions[] = $action_ids; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - //Only use array_merge if there are new actions |
|
| 239 | - if ( ! empty( $new_actions ) ) { |
|
| 240 | - $new_actions = call_user_func_array( 'array_merge', $new_actions ); |
|
| 241 | - } |
|
| 242 | - $old_actions = array_diff( $old_actions, $new_actions ); |
|
| 238 | + //Only use array_merge if there are new actions |
|
| 239 | + if ( ! empty( $new_actions ) ) { |
|
| 240 | + $new_actions = call_user_func_array( 'array_merge', $new_actions ); |
|
| 241 | + } |
|
| 242 | + $old_actions = array_diff( $old_actions, $new_actions ); |
|
| 243 | 243 | |
| 244 | 244 | self::delete_missing_actions( $old_actions ); |
| 245 | - } |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | 247 | public static function delete_missing_actions( $old_actions ) { |
| 248 | 248 | if ( ! empty( $old_actions ) ) { |
@@ -262,22 +262,22 @@ discard block |
||
| 262 | 262 | self::trigger_actions( $event, $form_id, $entry_id, 'all', $args ); |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * @param string $event |
|
| 267 | - */ |
|
| 265 | + /** |
|
| 266 | + * @param string $event |
|
| 267 | + */ |
|
| 268 | 268 | public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) { |
| 269 | 269 | $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type ); |
| 270 | 270 | |
| 271 | 271 | if ( empty( $form_actions ) ) { |
| 272 | - return; |
|
| 273 | - } |
|
| 272 | + return; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | 275 | FrmForm::maybe_get_form( $form ); |
| 276 | 276 | |
| 277 | - $link_settings = self::get_form_actions( $type ); |
|
| 278 | - if ( 'all' != $type ) { |
|
| 279 | - $link_settings = array( $type => $link_settings ); |
|
| 280 | - } |
|
| 277 | + $link_settings = self::get_form_actions( $type ); |
|
| 278 | + if ( 'all' != $type ) { |
|
| 279 | + $link_settings = array( $type => $link_settings ); |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | 282 | $stored_actions = array(); |
| 283 | 283 | $action_priority = array(); |
@@ -288,17 +288,17 @@ discard block |
||
| 288 | 288 | $this_event = $event; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - foreach ( $form_actions as $action ) { |
|
| 291 | + foreach ( $form_actions as $action ) { |
|
| 292 | 292 | |
| 293 | 293 | $skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) ); |
| 294 | 294 | $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) ); |
| 295 | 295 | if ( $skip_this_action ) { |
| 296 | - continue; |
|
| 297 | - } |
|
| 296 | + continue; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - if ( ! is_object( $entry ) ) { |
|
| 300 | - $entry = FrmEntry::getOne( $entry, true ); |
|
| 301 | - } |
|
| 299 | + if ( ! is_object( $entry ) ) { |
|
| 300 | + $entry = FrmEntry::getOne( $entry, true ); |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | 303 | if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) { |
| 304 | 304 | continue; |
@@ -312,64 +312,64 @@ discard block |
||
| 312 | 312 | if ( ! $trigger_children ) { |
| 313 | 313 | continue; |
| 314 | 314 | } |
| 315 | - } |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - // check conditional logic |
|
| 317 | + // check conditional logic |
|
| 318 | 318 | $stop = FrmFormAction::action_conditions_met( $action, $entry ); |
| 319 | - if ( $stop ) { |
|
| 320 | - continue; |
|
| 321 | - } |
|
| 319 | + if ( $stop ) { |
|
| 320 | + continue; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - // store actions so they can be triggered with the correct priority |
|
| 324 | - $stored_actions[ $action->ID ] = $action; |
|
| 325 | - $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
|
| 323 | + // store actions so they can be triggered with the correct priority |
|
| 324 | + $stored_actions[ $action->ID ] = $action; |
|
| 325 | + $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
|
| 326 | 326 | |
| 327 | 327 | unset( $action ); |
| 328 | - } |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - if ( ! empty( $stored_actions ) ) { |
|
| 330 | + if ( ! empty( $stored_actions ) ) { |
|
| 331 | 331 | asort( $action_priority ); |
| 332 | 332 | |
| 333 | - // make sure hooks are loaded |
|
| 334 | - new FrmNotification(); |
|
| 333 | + // make sure hooks are loaded |
|
| 334 | + new FrmNotification(); |
|
| 335 | 335 | |
| 336 | - foreach ( $action_priority as $action_id => $priority ) { |
|
| 337 | - $action = $stored_actions[ $action_id ]; |
|
| 336 | + foreach ( $action_priority as $action_id => $priority ) { |
|
| 337 | + $action = $stored_actions[ $action_id ]; |
|
| 338 | 338 | do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event ); |
| 339 | 339 | do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form ); |
| 340 | 340 | |
| 341 | - // If post is created, get updated $entry object |
|
| 342 | - if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { |
|
| 341 | + // If post is created, get updated $entry object |
|
| 342 | + if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { |
|
| 343 | 343 | $entry = FrmEntry::getOne( $entry->id, true ); |
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | 349 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 350 | 350 | if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) { |
| 351 | - // continue if we know which actions to copy |
|
| 352 | - return; |
|
| 353 | - } |
|
| 351 | + // continue if we know which actions to copy |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | 355 | $action_controls = self::get_form_actions(); |
| 356 | 356 | |
| 357 | - foreach ( $action_controls as $action_control ) { |
|
| 358 | - $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
|
| 359 | - unset( $action_control ); |
|
| 360 | - } |
|
| 361 | - } |
|
| 357 | + foreach ( $action_controls as $action_control ) { |
|
| 358 | + $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
|
| 359 | + unset( $action_control ); |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | - public static function limit_by_type( $where ) { |
|
| 364 | - global $frm_vars, $wpdb; |
|
| 363 | + public static function limit_by_type( $where ) { |
|
| 364 | + global $frm_vars, $wpdb; |
|
| 365 | 365 | |
| 366 | - if ( ! isset( $frm_vars['action_type'] ) ) { |
|
| 367 | - return $where; |
|
| 368 | - } |
|
| 366 | + if ( ! isset( $frm_vars['action_type'] ) ) { |
|
| 367 | + return $where; |
|
| 368 | + } |
|
| 369 | 369 | |
| 370 | - $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
|
| 371 | - return $where; |
|
| 372 | - } |
|
| 370 | + $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
|
| 371 | + return $where; |
|
| 372 | + } |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | foreach ( $keys as $key ) { |
| 397 | 397 | // don't register new action if old action with the same id is already registered |
| 398 | 398 | if ( ! isset( $this->actions[ $key ] ) ) { |
| 399 | - $this->actions[ $key ]->_register(); |
|
| 399 | + $this->actions[ $key ]->_register(); |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | } |
@@ -149,41 +149,41 @@ discard block |
||
| 149 | 149 | return apply_filters( 'frm_pro_available_fields', $fields ); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - public static function create( $values, $return = true ) { |
|
| 153 | - global $wpdb, $frm_duplicate_ids; |
|
| 152 | + public static function create( $values, $return = true ) { |
|
| 153 | + global $wpdb, $frm_duplicate_ids; |
|
| 154 | 154 | |
| 155 | - $new_values = array(); |
|
| 155 | + $new_values = array(); |
|
| 156 | 156 | $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name']; |
| 157 | 157 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
| 158 | 158 | |
| 159 | 159 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
| 160 | 160 | $new_values[ $col ] = $values[ $col ]; |
| 161 | - } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - $new_values['options'] = $values['options']; |
|
| 163 | + $new_values['options'] = $values['options']; |
|
| 164 | 164 | |
| 165 | 165 | $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null; |
| 166 | 166 | $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0; |
| 167 | 167 | $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
| 168 | - $new_values['field_options'] = $values['field_options']; |
|
| 168 | + $new_values['field_options'] = $values['field_options']; |
|
| 169 | 169 | $new_values['created_at'] = current_time( 'mysql', 1 ); |
| 170 | 170 | |
| 171 | 171 | if ( isset( $values['id'] ) ) { |
| 172 | 172 | $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
| 173 | 173 | $new_values = apply_filters( 'frm_duplicated_field', $new_values ); |
| 174 | - } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | self::preserve_format_option_backslashes( $new_values ); |
| 177 | 177 | |
| 178 | 178 | foreach ( $new_values as $k => $v ) { |
| 179 | - if ( is_array( $v ) ) { |
|
| 179 | + if ( is_array( $v ) ) { |
|
| 180 | 180 | $new_values[ $k ] = serialize( $v ); |
| 181 | 181 | } |
| 182 | - unset( $k, $v ); |
|
| 183 | - } |
|
| 182 | + unset( $k, $v ); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - //if(isset($values['id']) and is_numeric($values['id'])) |
|
| 186 | - // $new_values['id'] = $values['id']; |
|
| 185 | + //if(isset($values['id']) and is_numeric($values['id'])) |
|
| 186 | + // $new_values['id'] = $values['id']; |
|
| 187 | 187 | |
| 188 | 188 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values ); |
| 189 | 189 | $new_id = 0; |
@@ -204,10 +204,10 @@ discard block |
||
| 204 | 204 | } else { |
| 205 | 205 | return false; |
| 206 | 206 | } |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
| 210 | - global $frm_duplicate_ids; |
|
| 209 | + public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
| 210 | + global $frm_duplicate_ids; |
|
| 211 | 211 | |
| 212 | 212 | $where = array( |
| 213 | 213 | array( |
@@ -218,14 +218,14 @@ discard block |
||
| 218 | 218 | ); |
| 219 | 219 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
| 220 | 220 | |
| 221 | - foreach ( (array) $fields as $field ) { |
|
| 221 | + foreach ( (array) $fields as $field ) { |
|
| 222 | 222 | $new_key = $copy_keys ? $field->field_key : ''; |
| 223 | 223 | if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) { |
| 224 | 224 | $new_key = rtrim( $new_key, 2 ); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $values = array(); |
|
| 228 | - FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
| 227 | + $values = array(); |
|
| 228 | + FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
| 229 | 229 | |
| 230 | 230 | // If this is a repeating section, create new form |
| 231 | 231 | if ( self::is_repeating_field( $field ) ) { |
@@ -256,11 +256,11 @@ discard block |
||
| 256 | 256 | $frm_duplicate_ids[ $field->id ] = $new_id; |
| 257 | 257 | $frm_duplicate_ids[ $field->field_key ] = $new_id; |
| 258 | 258 | unset( $field ); |
| 259 | - } |
|
| 260 | - } |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | 262 | public static function update( $id, $values ) { |
| 263 | - global $wpdb; |
|
| 263 | + global $wpdb; |
|
| 264 | 264 | |
| 265 | 265 | $id = absint( $id ); |
| 266 | 266 | |
@@ -269,8 +269,8 @@ discard block |
||
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | if ( isset( $values['required'] ) ) { |
| 272 | - $values['required'] = (int) $values['required']; |
|
| 273 | - } |
|
| 272 | + $values['required'] = (int) $values['required']; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | 275 | self::preserve_format_option_backslashes( $values ); |
| 276 | 276 | |
@@ -292,41 +292,41 @@ discard block |
||
| 292 | 292 | |
| 293 | 293 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) ); |
| 294 | 294 | |
| 295 | - $form_id = 0; |
|
| 295 | + $form_id = 0; |
|
| 296 | 296 | if ( isset( $values['form_id'] ) ) { |
| 297 | - $form_id = absint( $values['form_id'] ); |
|
| 297 | + $form_id = absint( $values['form_id'] ); |
|
| 298 | 298 | } else { |
| 299 | 299 | $field = self::getOne( $id ); |
| 300 | - if ( $field ) { |
|
| 301 | - $form_id = $field->form_id; |
|
| 302 | - } |
|
| 300 | + if ( $field ) { |
|
| 301 | + $form_id = $field->form_id; |
|
| 302 | + } |
|
| 303 | 303 | unset( $field ); |
| 304 | - } |
|
| 304 | + } |
|
| 305 | 305 | unset( $values ); |
| 306 | 306 | |
| 307 | 307 | if ( $query_results ) { |
| 308 | - wp_cache_delete( $id, 'frm_field' ); |
|
| 309 | - if ( $form_id ) { |
|
| 310 | - self::delete_form_transient( $form_id ); |
|
| 311 | - } |
|
| 312 | - } |
|
| 308 | + wp_cache_delete( $id, 'frm_field' ); |
|
| 309 | + if ( $form_id ) { |
|
| 310 | + self::delete_form_transient( $form_id ); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - return $query_results; |
|
| 315 | - } |
|
| 314 | + return $query_results; |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | 317 | /** |
| 318 | - * Keep backslashes in the phone format option |
|
| 319 | - * |
|
| 320 | - * @since 2.0.8 |
|
| 321 | - * @param $values array - pass by reference |
|
| 322 | - */ |
|
| 318 | + * Keep backslashes in the phone format option |
|
| 319 | + * |
|
| 320 | + * @since 2.0.8 |
|
| 321 | + * @param $values array - pass by reference |
|
| 322 | + */ |
|
| 323 | 323 | private static function preserve_format_option_backslashes( &$values ) { |
| 324 | 324 | if ( isset( $values['field_options']['format'] ) ) { |
| 325 | 325 | $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] ); |
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - public static function destroy( $id ) { |
|
| 329 | + public static function destroy( $id ) { |
|
| 330 | 330 | global $wpdb; |
| 331 | 331 | |
| 332 | 332 | do_action( 'frm_before_destroy_field', $id ); |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | |
| 342 | 342 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) ); |
| 343 | 343 | return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) ); |
| 344 | - } |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | 346 | public static function delete_form_transient( $form_id ) { |
| 347 | 347 | $form_id = absint( $form_id ); |
@@ -356,10 +356,10 @@ discard block |
||
| 356 | 356 | FrmDb::cache_delete_group( 'frm_field' ); |
| 357 | 357 | |
| 358 | 358 | $form = FrmForm::getOne( $form_id ); |
| 359 | - if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) { |
|
| 360 | - self::delete_form_transient( $form->parent_form_id ); |
|
| 361 | - } |
|
| 362 | - } |
|
| 359 | + if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) { |
|
| 360 | + self::delete_form_transient( $form->parent_form_id ); |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | 364 | /** |
| 365 | 365 | * If $field is numeric, get the field object |
@@ -375,27 +375,27 @@ discard block |
||
| 375 | 375 | return null; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - global $wpdb; |
|
| 378 | + global $wpdb; |
|
| 379 | 379 | |
| 380 | 380 | $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s'; |
| 381 | 381 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); // WPCS: unprepared SQL ok. |
| 382 | 382 | |
| 383 | - $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
| 383 | + $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
| 384 | 384 | |
| 385 | 385 | if ( empty( $results ) ) { |
| 386 | - return $results; |
|
| 387 | - } |
|
| 386 | + return $results; |
|
| 387 | + } |
|
| 388 | 388 | |
| 389 | 389 | if ( is_numeric( $id ) ) { |
| 390 | 390 | FrmDb::set_cache( $results->field_key, $results, 'frm_field' ); |
| 391 | - } else if ( $results ) { |
|
| 391 | + } else if ( $results ) { |
|
| 392 | 392 | FrmDb::set_cache( $results->id, $results, 'frm_field' ); |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | 395 | self::prepare_options( $results ); |
| 396 | 396 | |
| 397 | 397 | return stripslashes_deep( $results ); |
| 398 | - } |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | 401 | * Get the field type by key or id |
@@ -403,26 +403,26 @@ discard block |
||
| 403 | 403 | * @param int|string The field id or key |
| 404 | 404 | * @param mixed $col The name of the column in the fields database table |
| 405 | 405 | */ |
| 406 | - public static function get_type( $id, $col = 'type' ) { |
|
| 407 | - $field = FrmDb::check_cache( $id, 'frm_field' ); |
|
| 408 | - if ( $field ) { |
|
| 409 | - $type = $field->{$col}; |
|
| 410 | - } else { |
|
| 406 | + public static function get_type( $id, $col = 'type' ) { |
|
| 407 | + $field = FrmDb::check_cache( $id, 'frm_field' ); |
|
| 408 | + if ( $field ) { |
|
| 409 | + $type = $field->{$col}; |
|
| 410 | + } else { |
|
| 411 | 411 | $where = array( |
| 412 | 412 | 'or' => 1, |
| 413 | 413 | 'id' => $id, |
| 414 | 414 | 'field_key' => $id, |
| 415 | 415 | ); |
| 416 | 416 | $type = FrmDb::get_var( 'frm_fields', $where, $col ); |
| 417 | - } |
|
| 417 | + } |
|
| 418 | 418 | |
| 419 | - return $type; |
|
| 420 | - } |
|
| 419 | + return $type; |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | 422 | public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) { |
| 423 | - if ( ! $form_id ) { |
|
| 424 | - return array(); |
|
| 425 | - } |
|
| 423 | + if ( ! $form_id ) { |
|
| 424 | + return array(); |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | 427 | $results = self::get_fields_from_transients( |
| 428 | 428 | $form_id, |
@@ -432,30 +432,30 @@ discard block |
||
| 432 | 432 | ) |
| 433 | 433 | ); |
| 434 | 434 | if ( ! empty( $results ) ) { |
| 435 | - $fields = array(); |
|
| 436 | - $count = 0; |
|
| 437 | - foreach ( $results as $result ) { |
|
| 438 | - if ( $type != $result->type ) { |
|
| 439 | - continue; |
|
| 440 | - } |
|
| 435 | + $fields = array(); |
|
| 436 | + $count = 0; |
|
| 437 | + foreach ( $results as $result ) { |
|
| 438 | + if ( $type != $result->type ) { |
|
| 439 | + continue; |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | 442 | $fields[ $result->id ] = $result; |
| 443 | - $count++; |
|
| 444 | - if ( $limit == 1 ) { |
|
| 445 | - $fields = $result; |
|
| 446 | - break; |
|
| 447 | - } |
|
| 443 | + $count++; |
|
| 444 | + if ( $limit == 1 ) { |
|
| 445 | + $fields = $result; |
|
| 446 | + break; |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | 449 | if ( ! empty( $limit ) && $count >= $limit ) { |
| 450 | - break; |
|
| 451 | - } |
|
| 450 | + break; |
|
| 451 | + } |
|
| 452 | 452 | |
| 453 | 453 | unset( $result ); |
| 454 | 454 | } |
| 455 | 455 | return stripslashes_deep( $fields ); |
| 456 | - } |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | - self::$use_cache = false; |
|
| 458 | + self::$use_cache = false; |
|
| 459 | 459 | |
| 460 | 460 | $where = array( |
| 461 | 461 | 'fi.form_id' => (int) $form_id, |
@@ -463,59 +463,59 @@ discard block |
||
| 463 | 463 | ); |
| 464 | 464 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
| 465 | 465 | $results = self::getAll( $where, 'field_order', $limit ); |
| 466 | - self::$use_cache = true; |
|
| 466 | + self::$use_cache = true; |
|
| 467 | 467 | self::include_sub_fields( $results, $inc_sub, $type ); |
| 468 | 468 | |
| 469 | - return $results; |
|
| 470 | - } |
|
| 469 | + return $results; |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | 472 | public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) { |
| 473 | - if ( ! (int) $form_id ) { |
|
| 474 | - return array(); |
|
| 475 | - } |
|
| 473 | + if ( ! (int) $form_id ) { |
|
| 474 | + return array(); |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | 477 | $results = self::get_fields_from_transients( $form_id, compact( 'inc_embed', 'inc_repeat' ) ); |
| 478 | 478 | if ( ! empty( $results ) ) { |
| 479 | 479 | if ( empty( $limit ) ) { |
| 480 | 480 | return $results; |
| 481 | - } |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - $fields = array(); |
|
| 484 | - $count = 0; |
|
| 485 | - foreach ( $results as $result ) { |
|
| 483 | + $fields = array(); |
|
| 484 | + $count = 0; |
|
| 485 | + foreach ( $results as $result ) { |
|
| 486 | 486 | $count++; |
| 487 | 487 | $fields[ $result->id ] = $result; |
| 488 | 488 | if ( ! empty( $limit ) && $count >= $limit ) { |
| 489 | - break; |
|
| 490 | - } |
|
| 491 | - } |
|
| 489 | + break; |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | 493 | return $fields; |
| 494 | - } |
|
| 494 | + } |
|
| 495 | 495 | |
| 496 | - self::$use_cache = false; |
|
| 496 | + self::$use_cache = false; |
|
| 497 | 497 | |
| 498 | 498 | $where = array( 'fi.form_id' => absint( $form_id ) ); |
| 499 | 499 | self::maybe_include_repeating_fields( $inc_repeat, $where ); |
| 500 | 500 | $results = self::getAll( $where, 'field_order', $limit ); |
| 501 | 501 | |
| 502 | - self::$use_cache = true; |
|
| 502 | + self::$use_cache = true; |
|
| 503 | 503 | |
| 504 | 504 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
| 505 | 505 | |
| 506 | 506 | if ( empty( $limit ) ) { |
| 507 | 507 | self::set_field_transient( $results, $form_id, 0, compact( 'inc_embed', 'inc_repeat' ) ); |
| 508 | - } |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | 510 | return $results; |
| 511 | - } |
|
| 511 | + } |
|
| 512 | 512 | |
| 513 | 513 | /** |
| 514 | - * If repeating fields should be included, adjust $where accordingly |
|
| 515 | - * |
|
| 516 | - * @param string $inc_repeat |
|
| 517 | - * @param array $where - pass by reference |
|
| 518 | - */ |
|
| 514 | + * If repeating fields should be included, adjust $where accordingly |
|
| 515 | + * |
|
| 516 | + * @param string $inc_repeat |
|
| 517 | + * @param array $where - pass by reference |
|
| 518 | + */ |
|
| 519 | 519 | private static function maybe_include_repeating_fields( $inc_repeat, &$where ) { |
| 520 | 520 | if ( $inc_repeat == 'include' ) { |
| 521 | 521 | $form_id = $where['fi.form_id']; |
@@ -530,21 +530,21 @@ discard block |
||
| 530 | 530 | |
| 531 | 531 | public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) { |
| 532 | 532 | if ( 'include' != $inc_embed || empty( $results ) ) { |
| 533 | - return; |
|
| 534 | - } |
|
| 533 | + return; |
|
| 534 | + } |
|
| 535 | 535 | |
| 536 | - $form_fields = $results; |
|
| 536 | + $form_fields = $results; |
|
| 537 | 537 | $index_offset = 1; |
| 538 | - foreach ( $form_fields as $k => $field ) { |
|
| 538 | + foreach ( $form_fields as $k => $field ) { |
|
| 539 | 539 | if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) { |
| 540 | - continue; |
|
| 541 | - } |
|
| 540 | + continue; |
|
| 541 | + } |
|
| 542 | 542 | |
| 543 | - if ( $type == 'all' ) { |
|
| 544 | - $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
| 545 | - } else { |
|
| 543 | + if ( $type == 'all' ) { |
|
| 544 | + $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
| 545 | + } else { |
|
| 546 | 546 | $sub_fields = self::get_all_types_in_form( $field->form_id, $type ); |
| 547 | - } |
|
| 547 | + } |
|
| 548 | 548 | |
| 549 | 549 | if ( ! empty( $sub_fields ) ) { |
| 550 | 550 | $index = $k + $index_offset; |
@@ -552,35 +552,35 @@ discard block |
||
| 552 | 552 | array_splice( $results, $index, 0, $sub_fields ); |
| 553 | 553 | } |
| 554 | 554 | unset( $field, $sub_fields ); |
| 555 | - } |
|
| 556 | - } |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | 557 | |
| 558 | 558 | public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) { |
| 559 | 559 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
| 560 | - if ( self::$use_cache ) { |
|
| 561 | - // make sure old cache doesn't get saved as a transient |
|
| 560 | + if ( self::$use_cache ) { |
|
| 561 | + // make sure old cache doesn't get saved as a transient |
|
| 562 | 562 | $results = wp_cache_get( $cache_key, 'frm_field' ); |
| 563 | - if ( false !== $results ) { |
|
| 563 | + if ( false !== $results ) { |
|
| 564 | 564 | return stripslashes_deep( $results ); |
| 565 | - } |
|
| 566 | - } |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | 567 | |
| 568 | - global $wpdb; |
|
| 568 | + global $wpdb; |
|
| 569 | 569 | |
| 570 | - if ( $blog_id && is_multisite() ) { |
|
| 571 | - global $wpmuBaseTablePrefix; |
|
| 572 | - if ( $wpmuBaseTablePrefix ) { |
|
| 570 | + if ( $blog_id && is_multisite() ) { |
|
| 571 | + global $wpmuBaseTablePrefix; |
|
| 572 | + if ( $wpmuBaseTablePrefix ) { |
|
| 573 | 573 | $prefix = $wpmuBaseTablePrefix . $blog_id . '_'; |
| 574 | - } else { |
|
| 575 | - $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
| 576 | - } |
|
| 574 | + } else { |
|
| 575 | + $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
| 576 | + } |
|
| 577 | 577 | |
| 578 | 578 | $table_name = $prefix . 'frm_fields'; |
| 579 | 579 | $form_table_name = $prefix . 'frm_forms'; |
| 580 | 580 | } else { |
| 581 | 581 | $table_name = $wpdb->prefix . 'frm_fields'; |
| 582 | 582 | $form_table_name = $wpdb->prefix . 'frm_forms'; |
| 583 | - } |
|
| 583 | + } |
|
| 584 | 584 | |
| 585 | 585 | if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) { |
| 586 | 586 | $order_by = ' ORDER BY ' . $order_by; |
@@ -588,8 +588,8 @@ discard block |
||
| 588 | 588 | |
| 589 | 589 | $limit = FrmDb::esc_limit( $limit ); |
| 590 | 590 | |
| 591 | - $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
|
| 592 | - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
| 591 | + $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
|
| 592 | + $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
| 593 | 593 | |
| 594 | 594 | if ( is_array( $where ) ) { |
| 595 | 595 | $args = array( |
@@ -603,8 +603,8 @@ discard block |
||
| 603 | 603 | |
| 604 | 604 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
| 605 | 605 | $results = $wpdb->$function_name( $query ); |
| 606 | - } |
|
| 607 | - unset( $where ); |
|
| 606 | + } |
|
| 607 | + unset( $where ); |
|
| 608 | 608 | |
| 609 | 609 | self::format_field_results( $results ); |
| 610 | 610 | |
@@ -857,8 +857,8 @@ discard block |
||
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
| 860 | - * @since 2.0.09 |
|
| 861 | - */ |
|
| 860 | + * @since 2.0.09 |
|
| 861 | + */ |
|
| 862 | 862 | public static function is_repeating_field( $field ) { |
| 863 | 863 | if ( is_array( $field ) ) { |
| 864 | 864 | $is_repeating_field = ( 'divider' == $field['type'] ); |
@@ -868,14 +868,14 @@ discard block |
||
| 868 | 868 | return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) ); |
| 869 | 869 | } |
| 870 | 870 | |
| 871 | - /** |
|
| 872 | - * @param string $key |
|
| 873 | - * @return int field id |
|
| 874 | - */ |
|
| 871 | + /** |
|
| 872 | + * @param string $key |
|
| 873 | + * @return int field id |
|
| 874 | + */ |
|
| 875 | 875 | public static function get_id_by_key( $key ) { |
| 876 | - $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
| 877 | - return $id; |
|
| 878 | - } |
|
| 876 | + $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
| 877 | + return $id; |
|
| 878 | + } |
|
| 879 | 879 | |
| 880 | 880 | /** |
| 881 | 881 | * @param string $id |
@@ -1,18 +1,18 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmEntryValidate { |
| 4 | - public static function validate( $values, $exclude = false ) { |
|
| 5 | - FrmEntry::sanitize_entry_post( $values ); |
|
| 6 | - $errors = array(); |
|
| 4 | + public static function validate( $values, $exclude = false ) { |
|
| 5 | + FrmEntry::sanitize_entry_post( $values ); |
|
| 6 | + $errors = array(); |
|
| 7 | 7 | |
| 8 | 8 | if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) { |
| 9 | - $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
| 10 | - return $errors; |
|
| 11 | - } |
|
| 9 | + $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
| 10 | + return $errors; |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | 13 | if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) { |
| 14 | - $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
| 15 | - } |
|
| 14 | + $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | 17 | self::set_item_key( $values ); |
| 18 | 18 | |
@@ -57,24 +57,24 @@ discard block |
||
| 57 | 57 | return FrmField::getAll( $where, 'field_order' ); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
| 61 | - $defaults = array( |
|
| 62 | - 'id' => $posted_field->id, |
|
| 63 | - 'parent_field_id' => '', // the id of the repeat or embed form |
|
| 64 | - 'key_pointer' => '', // the pointer in the posted array |
|
| 65 | - 'exclude' => array(), // exclude these field types from validation |
|
| 66 | - ); |
|
| 67 | - $args = wp_parse_args( $args, $defaults ); |
|
| 60 | + public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
| 61 | + $defaults = array( |
|
| 62 | + 'id' => $posted_field->id, |
|
| 63 | + 'parent_field_id' => '', // the id of the repeat or embed form |
|
| 64 | + 'key_pointer' => '', // the pointer in the posted array |
|
| 65 | + 'exclude' => array(), // exclude these field types from validation |
|
| 66 | + ); |
|
| 67 | + $args = wp_parse_args( $args, $defaults ); |
|
| 68 | 68 | |
| 69 | 69 | if ( empty( $args['parent_field_id'] ) ) { |
| 70 | 70 | $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
| 71 | - } else { |
|
| 72 | - // value is from a nested form |
|
| 73 | - $value = $values; |
|
| 74 | - } |
|
| 71 | + } else { |
|
| 72 | + // value is from a nested form |
|
| 73 | + $value = $values; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // Check for values in "Other" fields |
|
| 77 | - FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
| 76 | + // Check for values in "Other" fields |
|
| 77 | + FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
| 78 | 78 | |
| 79 | 79 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
| 80 | 80 | |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | $value = trim( $value ); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ( $posted_field->required == '1' && FrmAppHelper::is_empty_value( $value ) ) { |
|
| 90 | + if ( $posted_field->required == '1' && FrmAppHelper::is_empty_value( $value ) ) { |
|
| 91 | 91 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
| 92 | - } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { // WPCS: CSRF ok. |
|
| 93 | - $_POST['item_name'] = $value; |
|
| 94 | - } |
|
| 92 | + } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { // WPCS: CSRF ok. |
|
| 93 | + $_POST['item_name'] = $value; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | FrmEntriesHelper::set_posted_value( $posted_field, $value, $args ); |
| 97 | 97 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
| 105 | 105 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) { |
| 109 | 109 | $is_default = ( FrmField::is_option_true_in_object( $field, 'default_blank' ) && $value == $field->default_value ); |
@@ -213,26 +213,26 @@ discard block |
||
| 213 | 213 | * @param array $values |
| 214 | 214 | * @param array $errors by reference |
| 215 | 215 | */ |
| 216 | - public static function spam_check( $exclude, $values, &$errors ) { |
|
| 217 | - if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
| 218 | - // only check spam if there are no other errors |
|
| 219 | - return; |
|
| 220 | - } |
|
| 216 | + public static function spam_check( $exclude, $values, &$errors ) { |
|
| 217 | + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
| 218 | + // only check spam if there are no other errors |
|
| 219 | + return; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | 222 | if ( self::is_honeypot_spam() || self::is_spam_bot() ) { |
| 223 | 223 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if ( self::blacklist_check( $values ) ) { |
|
| 227 | - $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
| 228 | - } |
|
| 226 | + if ( self::blacklist_check( $values ) ) { |
|
| 227 | + $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - if ( self::is_akismet_spam( $values ) ) { |
|
| 230 | + if ( self::is_akismet_spam( $values ) ) { |
|
| 231 | 231 | if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) { |
| 232 | 232 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
| 233 | 233 | } |
| 234 | - } |
|
| 235 | - } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | 237 | private static function is_honeypot_spam() { |
| 238 | 238 | $honeypot_value = FrmAppHelper::get_param( 'frm_verify', '', 'get', 'sanitize_text_field' ); |
@@ -254,15 +254,15 @@ discard block |
||
| 254 | 254 | return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - public static function blacklist_check( $values ) { |
|
| 257 | + public static function blacklist_check( $values ) { |
|
| 258 | 258 | if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) { |
| 259 | - return false; |
|
| 260 | - } |
|
| 259 | + return false; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
| 263 | - if ( empty( $mod_keys ) ) { |
|
| 264 | - return false; |
|
| 265 | - } |
|
| 262 | + $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
| 263 | + if ( empty( $mod_keys ) ) { |
|
| 264 | + return false; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | $content = FrmEntriesHelper::entry_array_to_string( $values ); |
| 268 | 268 | if ( empty( $content ) ) { |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | $user_info = self::get_spam_check_user_info( $values ); |
| 275 | 275 | |
| 276 | 276 | return wp_blacklist_check( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent ); |
| 277 | - } |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | 279 | /** |
| 280 | 280 | * Check entries for Akismet spam |
@@ -6,11 +6,11 @@ discard block |
||
| 6 | 6 | class FrmEntry { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * Create a new entry |
|
| 10 | - * |
|
| 11 | - * @param array $values |
|
| 12 | - * @return int | boolean $entry_id |
|
| 13 | - */ |
|
| 9 | + * Create a new entry |
|
| 10 | + * |
|
| 11 | + * @param array $values |
|
| 12 | + * @return int | boolean $entry_id |
|
| 13 | + */ |
|
| 14 | 14 | public static function create( $values ) { |
| 15 | 15 | $entry_id = self::create_entry( $values, 'standard' ); |
| 16 | 16 | |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | - * Create a new entry with some differences depending on type |
|
| 22 | - * |
|
| 23 | - * @param array $values |
|
| 24 | - * @param string $type |
|
| 25 | - * @return int | boolean $entry_id |
|
| 26 | - */ |
|
| 21 | + * Create a new entry with some differences depending on type |
|
| 22 | + * |
|
| 23 | + * @param array $values |
|
| 24 | + * @param string $type |
|
| 25 | + * @return int | boolean $entry_id |
|
| 26 | + */ |
|
| 27 | 27 | private static function create_entry( $values, $type ) { |
| 28 | 28 | $new_values = self::before_insert_entry_in_database( $values, $type ); |
| 29 | 29 | |
@@ -49,40 +49,40 @@ discard block |
||
| 49 | 49 | return false; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - $check_val = $new_values; |
|
| 52 | + $check_val = $new_values; |
|
| 53 | 53 | $check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) ); |
| 54 | 54 | |
| 55 | 55 | unset( $check_val['created_at'], $check_val['updated_at'] ); |
| 56 | 56 | unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
| 57 | 57 | |
| 58 | - if ( $new_values['item_key'] == $new_values['name'] ) { |
|
| 58 | + if ( $new_values['item_key'] == $new_values['name'] ) { |
|
| 59 | 59 | unset( $check_val['name'] ); |
| 60 | - } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - global $wpdb; |
|
| 62 | + global $wpdb; |
|
| 63 | 63 | $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) ); |
| 64 | 64 | |
| 65 | 65 | if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) { |
| 66 | - return false; |
|
| 67 | - } |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $is_duplicate = false; |
|
| 70 | - foreach ( $entry_exists as $entry_exist ) { |
|
| 71 | - $is_duplicate = true; |
|
| 69 | + $is_duplicate = false; |
|
| 70 | + foreach ( $entry_exists as $entry_exist ) { |
|
| 71 | + $is_duplicate = true; |
|
| 72 | 72 | |
| 73 | 73 | // make sure it's a duplicate |
| 74 | 74 | $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist ); |
| 75 | - $field_metas = array(); |
|
| 76 | - foreach ( $metas as $meta ) { |
|
| 75 | + $field_metas = array(); |
|
| 76 | + foreach ( $metas as $meta ) { |
|
| 77 | 77 | $field_metas[ $meta->field_id ] = $meta->meta_value; |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // If prev entry is empty and current entry is not, they are not duplicates |
|
| 81 | - $filtered_vals = array_filter( $values['item_meta'] ); |
|
| 80 | + // If prev entry is empty and current entry is not, they are not duplicates |
|
| 81 | + $filtered_vals = array_filter( $values['item_meta'] ); |
|
| 82 | 82 | $field_metas = array_filter( $field_metas ); |
| 83 | - if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 83 | + if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | // compare serialized values and not arrays |
| 88 | 88 | $new_meta = array_map( 'maybe_serialize', $filtered_vals ); |
@@ -99,20 +99,20 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $diff = array_diff_assoc( $field_metas, $new_meta ); |
| 102 | - foreach ( $diff as $field_id => $meta_value ) { |
|
| 102 | + foreach ( $diff as $field_id => $meta_value ) { |
|
| 103 | 103 | if ( ! empty( $meta_value ) ) { |
| 104 | - $is_duplicate = false; |
|
| 105 | - continue; |
|
| 106 | - } |
|
| 107 | - } |
|
| 104 | + $is_duplicate = false; |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - if ( $is_duplicate ) { |
|
| 109 | + if ( $is_duplicate ) { |
|
| 110 | 110 | break; |
| 111 | - } |
|
| 112 | - } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return $is_duplicate; |
|
| 115 | - } |
|
| 114 | + return $is_duplicate; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * Determine if an entry needs to be checked as a possible duplicate |
@@ -157,32 +157,32 @@ discard block |
||
| 157 | 157 | $new_values['updated_at'] = $new_values['created_at']; |
| 158 | 158 | |
| 159 | 159 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values ); |
| 160 | - if ( ! $query_results ) { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 160 | + if ( ! $query_results ) { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - $entry_id = $wpdb->insert_id; |
|
| 164 | + $entry_id = $wpdb->insert_id; |
|
| 165 | 165 | |
| 166 | - global $frm_vars; |
|
| 166 | + global $frm_vars; |
|
| 167 | 167 | if ( ! isset( $frm_vars['saved_entries'] ) ) { |
| 168 | - $frm_vars['saved_entries'] = array(); |
|
| 169 | - } |
|
| 170 | - $frm_vars['saved_entries'][] = (int) $entry_id; |
|
| 168 | + $frm_vars['saved_entries'] = array(); |
|
| 169 | + } |
|
| 170 | + $frm_vars['saved_entries'][] = (int) $entry_id; |
|
| 171 | 171 | |
| 172 | 172 | FrmEntryMeta::duplicate_entry_metas( $id, $entry_id ); |
| 173 | 173 | self::clear_cache(); |
| 174 | 174 | |
| 175 | 175 | do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) ); |
| 176 | - return $entry_id; |
|
| 177 | - } |
|
| 176 | + return $entry_id; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | - * Update an entry (not via XML) |
|
| 181 | - * |
|
| 182 | - * @param int $id |
|
| 183 | - * @param array $values |
|
| 184 | - * @return boolean|int $update_results |
|
| 185 | - */ |
|
| 180 | + * Update an entry (not via XML) |
|
| 181 | + * |
|
| 182 | + * @param int $id |
|
| 183 | + * @param array $values |
|
| 184 | + * @return boolean|int $update_results |
|
| 185 | + */ |
|
| 186 | 186 | public static function update( $id, $values ) { |
| 187 | 187 | $update_results = self::update_entry( $id, $values, 'standard' ); |
| 188 | 188 | |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
| 193 | - * Update an entry with some differences depending on the update type |
|
| 194 | - * |
|
| 195 | - * @since 2.0.16 |
|
| 196 | - * |
|
| 197 | - * @param int $id |
|
| 198 | - * @param array $values |
|
| 199 | - * @return boolean|int $query_results |
|
| 200 | - */ |
|
| 193 | + * Update an entry with some differences depending on the update type |
|
| 194 | + * |
|
| 195 | + * @since 2.0.16 |
|
| 196 | + * |
|
| 197 | + * @param int $id |
|
| 198 | + * @param array $values |
|
| 199 | + * @return boolean|int $query_results |
|
| 200 | + */ |
|
| 201 | 201 | private static function update_entry( $id, $values, $update_type ) { |
| 202 | 202 | global $wpdb; |
| 203 | 203 | |
@@ -216,14 +216,14 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | public static function destroy( $id ) { |
| 219 | - global $wpdb; |
|
| 220 | - $id = (int) $id; |
|
| 219 | + global $wpdb; |
|
| 220 | + $id = (int) $id; |
|
| 221 | 221 | |
| 222 | 222 | $entry = self::getOne( $id ); |
| 223 | - if ( ! $entry ) { |
|
| 224 | - $result = false; |
|
| 225 | - return $result; |
|
| 226 | - } |
|
| 223 | + if ( ! $entry ) { |
|
| 224 | + $result = false; |
|
| 225 | + return $result; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | do_action( 'frm_before_destroy_entry', $id, $entry ); |
| 229 | 229 | |
@@ -232,18 +232,18 @@ discard block |
||
| 232 | 232 | |
| 233 | 233 | self::clear_cache(); |
| 234 | 234 | |
| 235 | - return $result; |
|
| 236 | - } |
|
| 235 | + return $result; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | 238 | public static function update_form( $id, $value, $form_id ) { |
| 239 | - global $wpdb; |
|
| 239 | + global $wpdb; |
|
| 240 | 240 | $form_id = isset( $value ) ? $form_id : null; |
| 241 | 241 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
| 242 | 242 | if ( $result ) { |
| 243 | 243 | self::clear_cache(); |
| 244 | 244 | } |
| 245 | - return $result; |
|
| 246 | - } |
|
| 245 | + return $result; |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | 248 | /** |
| 249 | 249 | * Clear entry caching |
@@ -287,19 +287,19 @@ discard block |
||
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | public static function getOne( $id, $meta = false ) { |
| 290 | - global $wpdb; |
|
| 290 | + global $wpdb; |
|
| 291 | 291 | |
| 292 | - $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
| 292 | + $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
| 293 | 293 | LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE "; |
| 294 | 294 | |
| 295 | 295 | $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s'; |
| 296 | - $query_args = array( $id ); |
|
| 297 | - $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok. |
|
| 296 | + $query_args = array( $id ); |
|
| 297 | + $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok. |
|
| 298 | 298 | |
| 299 | - if ( ! $meta ) { |
|
| 299 | + if ( ! $meta ) { |
|
| 300 | 300 | $entry = FrmDb::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' ); |
| 301 | 301 | return stripslashes_deep( $entry ); |
| 302 | - } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | 304 | $entry = FrmDb::check_cache( $id, 'frm_entry' ); |
| 305 | 305 | if ( $entry !== false ) { |
@@ -310,14 +310,14 @@ discard block |
||
| 310 | 310 | $entry = self::get_meta( $entry ); |
| 311 | 311 | |
| 312 | 312 | return stripslashes_deep( $entry ); |
| 313 | - } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | public static function get_meta( $entry ) { |
| 316 | - if ( ! $entry ) { |
|
| 317 | - return $entry; |
|
| 318 | - } |
|
| 316 | + if ( ! $entry ) { |
|
| 317 | + return $entry; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - global $wpdb; |
|
| 320 | + global $wpdb; |
|
| 321 | 321 | $metas = FrmDb::get_results( |
| 322 | 322 | $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', |
| 323 | 323 | array( |
@@ -327,56 +327,56 @@ discard block |
||
| 327 | 327 | 'field_id, meta_value, field_key, item_id' |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | - $entry->metas = array(); |
|
| 330 | + $entry->metas = array(); |
|
| 331 | 331 | |
| 332 | 332 | $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) ); |
| 333 | - foreach ( $metas as $meta_val ) { |
|
| 334 | - if ( $meta_val->item_id == $entry->id ) { |
|
| 333 | + foreach ( $metas as $meta_val ) { |
|
| 334 | + if ( $meta_val->item_id == $entry->id ) { |
|
| 335 | 335 | $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
| 336 | 336 | if ( $include_key ) { |
| 337 | 337 | $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
| 338 | 338 | } |
| 339 | - continue; |
|
| 340 | - } |
|
| 339 | + continue; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - // include sub entries in an array |
|
| 342 | + // include sub entries in an array |
|
| 343 | 343 | if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
| 344 | 344 | $entry->metas[ $meta_val->field_id ] = array(); |
| 345 | - } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | 347 | $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
| 348 | 348 | |
| 349 | 349 | unset( $meta_val ); |
| 350 | - } |
|
| 350 | + } |
|
| 351 | 351 | unset( $metas ); |
| 352 | 352 | |
| 353 | 353 | FrmDb::set_cache( $entry->id, $entry, 'frm_entry' ); |
| 354 | 354 | |
| 355 | - return $entry; |
|
| 356 | - } |
|
| 355 | + return $entry; |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * @param string $id |
|
| 360 | - */ |
|
| 358 | + /** |
|
| 359 | + * @param string $id |
|
| 360 | + */ |
|
| 361 | 361 | public static function exists( $id ) { |
| 362 | - global $wpdb; |
|
| 362 | + global $wpdb; |
|
| 363 | 363 | |
| 364 | - if ( FrmDb::check_cache( $id, 'frm_entry' ) ) { |
|
| 365 | - $exists = true; |
|
| 366 | - return $exists; |
|
| 367 | - } |
|
| 364 | + if ( FrmDb::check_cache( $id, 'frm_entry' ) ) { |
|
| 365 | + $exists = true; |
|
| 366 | + return $exists; |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | 369 | if ( is_numeric( $id ) ) { |
| 370 | - $where = array( 'id' => $id ); |
|
| 371 | - } else { |
|
| 372 | - $where = array( 'item_key' => $id ); |
|
| 373 | - } |
|
| 370 | + $where = array( 'id' => $id ); |
|
| 371 | + } else { |
|
| 372 | + $where = array( 'item_key' => $id ); |
|
| 373 | + } |
|
| 374 | 374 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
| 375 | 375 | |
| 376 | 376 | return ( $id && $id > 0 ); |
| 377 | - } |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
| 379 | + public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
| 380 | 380 | global $wpdb; |
| 381 | 381 | |
| 382 | 382 | $limit = FrmDb::esc_limit( $limit ); |
@@ -384,21 +384,21 @@ discard block |
||
| 384 | 384 | $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form; |
| 385 | 385 | $entries = wp_cache_get( $cache_key, 'frm_entry' ); |
| 386 | 386 | |
| 387 | - if ( false === $entries ) { |
|
| 388 | - $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
| 387 | + if ( false === $entries ) { |
|
| 388 | + $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
| 389 | 389 | $table = $wpdb->prefix . 'frm_items it '; |
| 390 | 390 | |
| 391 | - if ( $inc_form ) { |
|
| 392 | - $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
| 393 | - $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
| 394 | - } |
|
| 391 | + if ( $inc_form ) { |
|
| 392 | + $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
| 393 | + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
| 397 | - // sort by a requested field |
|
| 398 | - $field_id = (int) $order_matches[1]; |
|
| 396 | + if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
| 397 | + // sort by a requested field |
|
| 398 | + $field_id = (int) $order_matches[1]; |
|
| 399 | 399 | $fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id; |
| 400 | 400 | unset( $order_matches, $field_id ); |
| 401 | - } |
|
| 401 | + } |
|
| 402 | 402 | |
| 403 | 403 | // prepare the query |
| 404 | 404 | $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
@@ -407,45 +407,45 @@ discard block |
||
| 407 | 407 | unset( $query ); |
| 408 | 408 | |
| 409 | 409 | FrmDb::set_cache( $cache_key, $entries, 'frm_entry' ); |
| 410 | - } |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | - if ( ! $meta || ! $entries ) { |
|
| 412 | + if ( ! $meta || ! $entries ) { |
|
| 413 | 413 | return stripslashes_deep( $entries ); |
| 414 | - } |
|
| 414 | + } |
|
| 415 | 415 | unset( $meta ); |
| 416 | 416 | |
| 417 | 417 | if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) { |
| 418 | 418 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
| 419 | - } |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - $meta_where = array( 'field_id !' => 0 ); |
|
| 421 | + $meta_where = array( 'field_id !' => 0 ); |
|
| 422 | 422 | if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) { |
| 423 | - $meta_where['fi.form_id'] = $where['it.form_id']; |
|
| 424 | - } else { |
|
| 425 | - $meta_where['item_id'] = array_keys( $entries ); |
|
| 426 | - } |
|
| 423 | + $meta_where['fi.form_id'] = $where['it.form_id']; |
|
| 424 | + } else { |
|
| 425 | + $meta_where['item_id'] = array_keys( $entries ); |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | - $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
| 428 | + $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
| 429 | 429 | |
| 430 | - unset( $meta_where ); |
|
| 430 | + unset( $meta_where ); |
|
| 431 | 431 | |
| 432 | - if ( ! $metas ) { |
|
| 432 | + if ( ! $metas ) { |
|
| 433 | 433 | return stripslashes_deep( $entries ); |
| 434 | - } |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - foreach ( $metas as $m_key => $meta_val ) { |
|
| 437 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
| 438 | - continue; |
|
| 439 | - } |
|
| 436 | + foreach ( $metas as $m_key => $meta_val ) { |
|
| 437 | + if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
| 438 | + continue; |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
| 441 | + if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
| 442 | 442 | $entries[ $meta_val->item_id ]->metas = array(); |
| 443 | - } |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | 445 | $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
| 446 | 446 | |
| 447 | 447 | unset( $m_key, $meta_val ); |
| 448 | - } |
|
| 448 | + } |
|
| 449 | 449 | |
| 450 | 450 | if ( ! FrmAppHelper::prevent_caching() ) { |
| 451 | 451 | foreach ( $entries as $entry ) { |
@@ -455,30 +455,30 @@ discard block |
||
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | return stripslashes_deep( $entries ); |
| 458 | - } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - // Pagination Methods |
|
| 461 | - public static function getRecordCount( $where = '' ) { |
|
| 462 | - global $wpdb; |
|
| 460 | + // Pagination Methods |
|
| 461 | + public static function getRecordCount( $where = '' ) { |
|
| 462 | + global $wpdb; |
|
| 463 | 463 | $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; |
| 464 | 464 | |
| 465 | 465 | if ( is_numeric( $where ) ) { |
| 466 | - $table_join = 'frm_items'; |
|
| 467 | - $where = array( 'form_id' => $where ); |
|
| 468 | - } |
|
| 466 | + $table_join = 'frm_items'; |
|
| 467 | + $where = array( 'form_id' => $where ); |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | - if ( is_array( $where ) ) { |
|
| 471 | - $count = FrmDb::get_count( $table_join, $where ); |
|
| 472 | - } else { |
|
| 470 | + if ( is_array( $where ) ) { |
|
| 471 | + $count = FrmDb::get_count( $table_join, $where ); |
|
| 472 | + } else { |
|
| 473 | 473 | $cache_key = 'count_' . maybe_serialize( $where ); |
| 474 | 474 | $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where ); |
| 475 | 475 | $count = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' ); |
| 476 | - } |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - return $count; |
|
| 479 | - } |
|
| 478 | + return $count; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - public static function getPageCount( $p_size, $where = '' ) { |
|
| 481 | + public static function getPageCount( $p_size, $where = '' ) { |
|
| 482 | 482 | $p_size = (int) $p_size; |
| 483 | 483 | $count = 1; |
| 484 | 484 | if ( $p_size ) { |
@@ -489,16 +489,16 @@ discard block |
||
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | return $count; |
| 492 | - } |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | 494 | /** |
| 495 | - * Prepare the data before inserting it into the database |
|
| 496 | - * |
|
| 497 | - * @since 2.0.16 |
|
| 498 | - * @param array $values |
|
| 499 | - * @param string $type |
|
| 500 | - * @return array $new_values |
|
| 501 | - */ |
|
| 495 | + * Prepare the data before inserting it into the database |
|
| 496 | + * |
|
| 497 | + * @since 2.0.16 |
|
| 498 | + * @param array $values |
|
| 499 | + * @param string $type |
|
| 500 | + * @return array $new_values |
|
| 501 | + */ |
|
| 502 | 502 | private static function before_insert_entry_in_database( &$values, $type ) { |
| 503 | 503 | |
| 504 | 504 | self::sanitize_entry_post( $values ); |
@@ -513,13 +513,13 @@ discard block |
||
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
| 516 | - * Create an entry and perform after create actions |
|
| 517 | - * |
|
| 518 | - * @since 2.0.16 |
|
| 519 | - * @param array $values |
|
| 520 | - * @param array $new_values |
|
| 521 | - * @return boolean|int $entry_id |
|
| 522 | - */ |
|
| 516 | + * Create an entry and perform after create actions |
|
| 517 | + * |
|
| 518 | + * @since 2.0.16 |
|
| 519 | + * @param array $values |
|
| 520 | + * @param array $new_values |
|
| 521 | + * @return boolean|int $entry_id |
|
| 522 | + */ |
|
| 523 | 523 | private static function continue_to_create_entry( $values, $new_values ) { |
| 524 | 524 | $entry_id = self::insert_entry_into_database( $new_values ); |
| 525 | 525 | if ( ! $entry_id ) { |
@@ -531,37 +531,37 @@ discard block |
||
| 531 | 531 | return $entry_id; |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - /** |
|
| 535 | - * Sanitize the POST values before we use them |
|
| 536 | - * |
|
| 537 | - * @since 2.0 |
|
| 538 | - * @param array $values The POST values by reference |
|
| 539 | - */ |
|
| 540 | - public static function sanitize_entry_post( &$values ) { |
|
| 541 | - $sanitize_method = array( |
|
| 542 | - 'form_id' => 'absint', |
|
| 543 | - 'frm_action' => 'sanitize_title', |
|
| 544 | - 'form_key' => 'sanitize_title', |
|
| 545 | - 'item_key' => 'sanitize_title', |
|
| 546 | - 'item_name' => 'sanitize_text_field', |
|
| 547 | - 'frm_saving_draft' => 'absint', |
|
| 548 | - 'is_draft' => 'absint', |
|
| 549 | - 'post_id' => 'absint', |
|
| 550 | - 'parent_item_id' => 'absint', |
|
| 551 | - 'created_at' => 'sanitize_text_field', |
|
| 552 | - 'updated_at' => 'sanitize_text_field', |
|
| 553 | - ); |
|
| 554 | - |
|
| 555 | - FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
| 556 | - } |
|
| 534 | + /** |
|
| 535 | + * Sanitize the POST values before we use them |
|
| 536 | + * |
|
| 537 | + * @since 2.0 |
|
| 538 | + * @param array $values The POST values by reference |
|
| 539 | + */ |
|
| 540 | + public static function sanitize_entry_post( &$values ) { |
|
| 541 | + $sanitize_method = array( |
|
| 542 | + 'form_id' => 'absint', |
|
| 543 | + 'frm_action' => 'sanitize_title', |
|
| 544 | + 'form_key' => 'sanitize_title', |
|
| 545 | + 'item_key' => 'sanitize_title', |
|
| 546 | + 'item_name' => 'sanitize_text_field', |
|
| 547 | + 'frm_saving_draft' => 'absint', |
|
| 548 | + 'is_draft' => 'absint', |
|
| 549 | + 'post_id' => 'absint', |
|
| 550 | + 'parent_item_id' => 'absint', |
|
| 551 | + 'created_at' => 'sanitize_text_field', |
|
| 552 | + 'updated_at' => 'sanitize_text_field', |
|
| 553 | + ); |
|
| 554 | + |
|
| 555 | + FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
| 556 | + } |
|
| 557 | 557 | |
| 558 | 558 | /** |
| 559 | - * Prepare the new values for inserting into the database |
|
| 560 | - * |
|
| 561 | - * @since 2.0.16 |
|
| 562 | - * @param array $values |
|
| 563 | - * @return array $new_values |
|
| 564 | - */ |
|
| 559 | + * Prepare the new values for inserting into the database |
|
| 560 | + * |
|
| 561 | + * @since 2.0.16 |
|
| 562 | + * @param array $values |
|
| 563 | + * @return array $new_values |
|
| 564 | + */ |
|
| 565 | 565 | private static function package_entry_data( &$values ) { |
| 566 | 566 | global $wpdb; |
| 567 | 567 | |
@@ -614,34 +614,34 @@ discard block |
||
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
| 617 | - * Get the is_draft value for a new entry |
|
| 618 | - * |
|
| 619 | - * @since 2.0.16 |
|
| 620 | - * @param array $values |
|
| 621 | - * @return int |
|
| 622 | - */ |
|
| 617 | + * Get the is_draft value for a new entry |
|
| 618 | + * |
|
| 619 | + * @since 2.0.16 |
|
| 620 | + * @param array $values |
|
| 621 | + * @return int |
|
| 622 | + */ |
|
| 623 | 623 | private static function get_is_draft_value( $values ) { |
| 624 | 624 | return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | /** |
| 628 | - * Get the created_at value for a new entry |
|
| 629 | - * |
|
| 630 | - * @since 2.0.16 |
|
| 631 | - * @param array $values |
|
| 632 | - * @return string |
|
| 633 | - */ |
|
| 628 | + * Get the created_at value for a new entry |
|
| 629 | + * |
|
| 630 | + * @since 2.0.16 |
|
| 631 | + * @param array $values |
|
| 632 | + * @return string |
|
| 633 | + */ |
|
| 634 | 634 | private static function get_created_at( $values ) { |
| 635 | 635 | return self::get_entry_value( $values, 'created_at', current_time( 'mysql', 1 ) ); |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
| 639 | - * Get the updated_at value for a new entry |
|
| 640 | - * |
|
| 641 | - * @since 2.0.16 |
|
| 642 | - * @param array $values |
|
| 643 | - * @return string |
|
| 644 | - */ |
|
| 639 | + * Get the updated_at value for a new entry |
|
| 640 | + * |
|
| 641 | + * @since 2.0.16 |
|
| 642 | + * @param array $values |
|
| 643 | + * @return string |
|
| 644 | + */ |
|
| 645 | 645 | private static function get_updated_at( $values ) { |
| 646 | 646 | if ( isset( $values['updated_at'] ) ) { |
| 647 | 647 | $updated_at = $values['updated_at']; |
@@ -653,12 +653,12 @@ discard block |
||
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
| 656 | - * Get the description value for a new entry |
|
| 657 | - * |
|
| 658 | - * @since 2.0.16 |
|
| 659 | - * @param array $values |
|
| 660 | - * @return string |
|
| 661 | - */ |
|
| 656 | + * Get the description value for a new entry |
|
| 657 | + * |
|
| 658 | + * @since 2.0.16 |
|
| 659 | + * @param array $values |
|
| 660 | + * @return string |
|
| 661 | + */ |
|
| 662 | 662 | private static function get_entry_description( $values ) { |
| 663 | 663 | if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) { |
| 664 | 664 | $description = maybe_serialize( $values['description'] ); |
@@ -675,12 +675,12 @@ discard block |
||
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
| 678 | - * Get the user_id value for a new entry |
|
| 679 | - * |
|
| 680 | - * @since 2.0.16 |
|
| 681 | - * @param array $values |
|
| 682 | - * @return int |
|
| 683 | - */ |
|
| 678 | + * Get the user_id value for a new entry |
|
| 679 | + * |
|
| 680 | + * @since 2.0.16 |
|
| 681 | + * @param array $values |
|
| 682 | + * @return int |
|
| 683 | + */ |
|
| 684 | 684 | private static function get_entry_user_id( $values ) { |
| 685 | 685 | if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) { |
| 686 | 686 | $user_id = $values['frm_user_id']; |
@@ -693,12 +693,12 @@ discard block |
||
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
| 696 | - * Insert new entry into the database |
|
| 697 | - * |
|
| 698 | - * @since 2.0.16 |
|
| 699 | - * @param array $new_values |
|
| 700 | - * @return int | boolean $entry_id |
|
| 701 | - */ |
|
| 696 | + * Insert new entry into the database |
|
| 697 | + * |
|
| 698 | + * @since 2.0.16 |
|
| 699 | + * @param array $new_values |
|
| 700 | + * @return int | boolean $entry_id |
|
| 701 | + */ |
|
| 702 | 702 | private static function insert_entry_into_database( $new_values ) { |
| 703 | 703 | global $wpdb; |
| 704 | 704 | |
@@ -714,11 +714,11 @@ discard block |
||
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
| 717 | - * Add the new entry to global $frm_vars |
|
| 718 | - * |
|
| 719 | - * @since 2.0.16 |
|
| 720 | - * @param int $entry_id |
|
| 721 | - */ |
|
| 717 | + * Add the new entry to global $frm_vars |
|
| 718 | + * |
|
| 719 | + * @since 2.0.16 |
|
| 720 | + * @param int $entry_id |
|
| 721 | + */ |
|
| 722 | 722 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
| 723 | 723 | global $frm_vars; |
| 724 | 724 | |
@@ -730,12 +730,12 @@ discard block |
||
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
| 733 | - * Add entry metas, if there are any |
|
| 734 | - * |
|
| 735 | - * @since 2.0.16 |
|
| 736 | - * @param array $values |
|
| 737 | - * @param int $entry_id |
|
| 738 | - */ |
|
| 733 | + * Add entry metas, if there are any |
|
| 734 | + * |
|
| 735 | + * @since 2.0.16 |
|
| 736 | + * @param array $values |
|
| 737 | + * @param int $entry_id |
|
| 738 | + */ |
|
| 739 | 739 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
| 740 | 740 | if ( isset( $values['item_meta'] ) ) { |
| 741 | 741 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
@@ -743,12 +743,12 @@ discard block |
||
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | /** |
| 746 | - * Trigger frm_after_create_entry hooks |
|
| 747 | - * |
|
| 748 | - * @since 2.0.16 |
|
| 749 | - * @param int $entry_id |
|
| 750 | - * @param array $new_values |
|
| 751 | - */ |
|
| 746 | + * Trigger frm_after_create_entry hooks |
|
| 747 | + * |
|
| 748 | + * @since 2.0.16 |
|
| 749 | + * @param int $entry_id |
|
| 750 | + * @param array $new_values |
|
| 751 | + */ |
|
| 752 | 752 | private static function after_entry_created_actions( $entry_id, $values, $new_values ) { |
| 753 | 753 | // this is a child entry |
| 754 | 754 | $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
@@ -758,13 +758,13 @@ discard block |
||
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | /** |
| 761 | - * Actions to perform immediately after an entry is inserted in the frm_items database |
|
| 762 | - * |
|
| 763 | - * @since 2.0.16 |
|
| 764 | - * @param array $values |
|
| 765 | - * @param array $new_values |
|
| 766 | - * @param int $entry_id |
|
| 767 | - */ |
|
| 761 | + * Actions to perform immediately after an entry is inserted in the frm_items database |
|
| 762 | + * |
|
| 763 | + * @since 2.0.16 |
|
| 764 | + * @param array $values |
|
| 765 | + * @param array $new_values |
|
| 766 | + * @param int $entry_id |
|
| 767 | + */ |
|
| 768 | 768 | private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) { |
| 769 | 769 | |
| 770 | 770 | self::add_new_entry_to_frm_vars( $entry_id ); |
@@ -777,14 +777,14 @@ discard block |
||
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | /** |
| 780 | - * Perform some actions right before updating an entry |
|
| 781 | - * |
|
| 782 | - * @since 2.0.16 |
|
| 783 | - * @param int $id |
|
| 784 | - * @param array $values |
|
| 785 | - * @param string $update_type |
|
| 786 | - * @return boolean $update |
|
| 787 | - */ |
|
| 780 | + * Perform some actions right before updating an entry |
|
| 781 | + * |
|
| 782 | + * @since 2.0.16 |
|
| 783 | + * @param int $id |
|
| 784 | + * @param array $values |
|
| 785 | + * @param string $update_type |
|
| 786 | + * @return boolean $update |
|
| 787 | + */ |
|
| 788 | 788 | private static function before_update_entry( $id, &$values, $update_type ) { |
| 789 | 789 | $update = true; |
| 790 | 790 | |
@@ -802,13 +802,13 @@ discard block |
||
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
| 805 | - * Package the entry data for updating |
|
| 806 | - * |
|
| 807 | - * @since 2.0.16 |
|
| 808 | - * @param int $id |
|
| 809 | - * @param array $values |
|
| 810 | - * @return array $new_values |
|
| 811 | - */ |
|
| 805 | + * Package the entry data for updating |
|
| 806 | + * |
|
| 807 | + * @since 2.0.16 |
|
| 808 | + * @param int $id |
|
| 809 | + * @param array $values |
|
| 810 | + * @return array $new_values |
|
| 811 | + */ |
|
| 812 | 812 | private static function package_entry_to_update( $id, $values ) { |
| 813 | 813 | global $wpdb; |
| 814 | 814 | |
@@ -842,14 +842,14 @@ discard block |
||
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | /** |
| 845 | - * Perform some actions right after updating an entry |
|
| 846 | - * |
|
| 847 | - * @since 2.0.16 |
|
| 848 | - * @param boolean|int $query_results |
|
| 849 | - * @param int $id |
|
| 850 | - * @param array $values |
|
| 851 | - * @param array $new_values |
|
| 852 | - */ |
|
| 845 | + * Perform some actions right after updating an entry |
|
| 846 | + * |
|
| 847 | + * @since 2.0.16 |
|
| 848 | + * @param boolean|int $query_results |
|
| 849 | + * @param int $id |
|
| 850 | + * @param array $values |
|
| 851 | + * @param array $new_values |
|
| 852 | + */ |
|
| 853 | 853 | private static function after_update_entry( $query_results, $id, $values, $new_values ) { |
| 854 | 854 | if ( $query_results ) { |
| 855 | 855 | self::clear_cache(); |
@@ -871,13 +871,13 @@ discard block |
||
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | /** |
| 874 | - * Create entry from an XML import |
|
| 875 | - * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
| 876 | - * |
|
| 877 | - * @since 2.0.16 |
|
| 878 | - * @param array $values |
|
| 879 | - * @return int | boolean $entry_id |
|
| 880 | - */ |
|
| 874 | + * Create entry from an XML import |
|
| 875 | + * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
| 876 | + * |
|
| 877 | + * @since 2.0.16 |
|
| 878 | + * @param array $values |
|
| 879 | + * @return int | boolean $entry_id |
|
| 880 | + */ |
|
| 881 | 881 | public static function create_entry_from_xml( $values ) { |
| 882 | 882 | $entry_id = self::create_entry( $values, 'xml' ); |
| 883 | 883 | |
@@ -885,26 +885,26 @@ discard block |
||
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | /** |
| 888 | - * Update entry from an XML import |
|
| 889 | - * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
| 890 | - * |
|
| 891 | - * @since 2.0.16 |
|
| 892 | - * @param int $id |
|
| 893 | - * @param array $values |
|
| 894 | - * @return int | boolean $updated |
|
| 895 | - */ |
|
| 888 | + * Update entry from an XML import |
|
| 889 | + * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
| 890 | + * |
|
| 891 | + * @since 2.0.16 |
|
| 892 | + * @param int $id |
|
| 893 | + * @param array $values |
|
| 894 | + * @return int | boolean $updated |
|
| 895 | + */ |
|
| 896 | 896 | public static function update_entry_from_xml( $id, $values ) { |
| 897 | 897 | $updated = self::update_entry( $id, $values, 'xml' ); |
| 898 | 898 | |
| 899 | 899 | return $updated; |
| 900 | 900 | } |
| 901 | 901 | |
| 902 | - /** |
|
| 903 | - * @param string $key |
|
| 904 | - * @return int entry_id |
|
| 905 | - */ |
|
| 902 | + /** |
|
| 903 | + * @param string $key |
|
| 904 | + * @return int entry_id |
|
| 905 | + */ |
|
| 906 | 906 | public static function get_id_by_key( $key ) { |
| 907 | - $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
| 908 | - return $entry_id; |
|
| 909 | - } |
|
| 907 | + $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
| 908 | + return $entry_id; |
|
| 909 | + } |
|
| 910 | 910 | } |
@@ -77,11 +77,11 @@ discard block |
||
| 77 | 77 | return $wpdb->get_charset_collate(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - private function create_tables() { |
|
| 81 | - $charset_collate = $this->collation(); |
|
| 82 | - $sql = array(); |
|
| 80 | + private function create_tables() { |
|
| 81 | + $charset_collate = $this->collation(); |
|
| 82 | + $sql = array(); |
|
| 83 | 83 | |
| 84 | - /* Create/Upgrade Fields Table */ |
|
| 84 | + /* Create/Upgrade Fields Table */ |
|
| 85 | 85 | $sql[] = 'CREATE TABLE ' . $this->fields . ' ( |
| 86 | 86 | id BIGINT(20) NOT NULL auto_increment, |
| 87 | 87 | field_key varchar(100) default NULL, |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | UNIQUE KEY field_key (field_key) |
| 101 | 101 | )'; |
| 102 | 102 | |
| 103 | - /* Create/Upgrade Forms Table */ |
|
| 103 | + /* Create/Upgrade Forms Table */ |
|
| 104 | 104 | $sql[] = 'CREATE TABLE ' . $this->forms . ' ( |
| 105 | 105 | id int(11) NOT NULL auto_increment, |
| 106 | 106 | form_key varchar(100) default NULL, |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | UNIQUE KEY form_key (form_key) |
| 119 | 119 | )'; |
| 120 | 120 | |
| 121 | - /* Create/Upgrade Items Table */ |
|
| 121 | + /* Create/Upgrade Items Table */ |
|
| 122 | 122 | $sql[] = 'CREATE TABLE ' . $this->entries . ' ( |
| 123 | 123 | id BIGINT(20) NOT NULL auto_increment, |
| 124 | 124 | item_key varchar(100) default NULL, |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | UNIQUE KEY item_key (item_key) |
| 142 | 142 | )'; |
| 143 | 143 | |
| 144 | - /* Create/Upgrade Meta Table */ |
|
| 144 | + /* Create/Upgrade Meta Table */ |
|
| 145 | 145 | $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' ( |
| 146 | 146 | id BIGINT(20) NOT NULL auto_increment, |
| 147 | 147 | meta_value longtext default NULL, |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | KEY item_id (item_id) |
| 154 | 154 | )'; |
| 155 | 155 | |
| 156 | - foreach ( $sql as $q ) { |
|
| 156 | + foreach ( $sql as $q ) { |
|
| 157 | 157 | if ( function_exists( 'dbDelta' ) ) { |
| 158 | 158 | dbDelta( $q . $charset_collate . ';' ); |
| 159 | 159 | } else { |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | $wpdb->query( $q . $charset_collate ); // WPCS: unprepared SQL ok. |
| 162 | 162 | } |
| 163 | 163 | unset( $q ); |
| 164 | - } |
|
| 165 | - } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | private function maybe_create_contact_form() { |
| 168 | 168 | $template_id = FrmForm::get_id_by_key( 'contact' ); |
@@ -209,13 +209,13 @@ discard block |
||
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - public function uninstall() { |
|
| 212 | + public function uninstall() { |
|
| 213 | 213 | if ( ! current_user_can( 'administrator' ) ) { |
| 214 | - $frm_settings = FrmAppHelper::get_settings(); |
|
| 214 | + $frm_settings = FrmAppHelper::get_settings(); |
|
| 215 | 215 | wp_die( esc_html( $frm_settings->admin_permission ) ); |
| 216 | - } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - global $wpdb, $wp_roles; |
|
| 218 | + global $wpdb, $wp_roles; |
|
| 219 | 219 | |
| 220 | 220 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // WPCS: unprepared SQL ok. |
| 221 | 221 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // WPCS: unprepared SQL ok. |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | delete_option( 'frm_install_running' ); |
| 228 | 228 | delete_option( 'frm_lite_settings_upgrade' ); |
| 229 | 229 | |
| 230 | - //delete roles |
|
| 231 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 232 | - $roles = get_editable_roles(); |
|
| 233 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 234 | - foreach ( $roles as $role => $details ) { |
|
| 235 | - $wp_roles->remove_cap( $role, $frm_role ); |
|
| 230 | + //delete roles |
|
| 231 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 232 | + $roles = get_editable_roles(); |
|
| 233 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 234 | + foreach ( $roles as $role => $details ) { |
|
| 235 | + $wp_roles->remove_cap( $role, $frm_role ); |
|
| 236 | 236 | unset( $role, $details ); |
| 237 | 237 | } |
| 238 | 238 | unset( $frm_role, $frm_role_description ); |
@@ -260,8 +260,8 @@ discard block |
||
| 260 | 260 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) ); |
| 261 | 261 | |
| 262 | 262 | do_action( 'frm_after_uninstall' ); |
| 263 | - return true; |
|
| 264 | - } |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | 267 | * Reverse migration 17 -- Divide by 9 |
@@ -431,42 +431,42 @@ discard block |
||
| 431 | 431 | $size .= 'px'; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - /** |
|
| 435 | - * Migrate post and email notification settings into actions |
|
| 436 | - */ |
|
| 437 | - private function migrate_to_16() { |
|
| 438 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Old email settings format: |
|
| 442 | - * email_to: Email or field id |
|
| 443 | - * also_email_to: array of fields ids |
|
| 444 | - * reply_to: Email, field id, 'custom' |
|
| 445 | - * cust_reply_to: string |
|
| 446 | - * reply_to_name: field id, 'custom' |
|
| 447 | - * cust_reply_to_name: string |
|
| 448 | - * plain_text: 0|1 |
|
| 449 | - * email_message: string or '' |
|
| 450 | - * email_subject: string or '' |
|
| 451 | - * inc_user_info: 0|1 |
|
| 452 | - * update_email: 0, 1, 2 |
|
| 453 | - * |
|
| 454 | - * Old autoresponder settings format: |
|
| 455 | - * auto_responder: 0|1 |
|
| 456 | - * ar_email_message: string or '' |
|
| 457 | - * ar_email_to: field id |
|
| 458 | - * ar_plain_text: 0|1 |
|
| 459 | - * ar_reply_to_name: string |
|
| 460 | - * ar_reply_to: string |
|
| 461 | - * ar_email_subject: string |
|
| 462 | - * ar_update_email: 0, 1, 2 |
|
| 463 | - * |
|
| 464 | - * New email settings: |
|
| 465 | - * post_content: json settings |
|
| 466 | - * post_title: form id |
|
| 467 | - * post_excerpt: message |
|
| 468 | - */ |
|
| 469 | - foreach ( $forms as $form ) { |
|
| 434 | + /** |
|
| 435 | + * Migrate post and email notification settings into actions |
|
| 436 | + */ |
|
| 437 | + private function migrate_to_16() { |
|
| 438 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Old email settings format: |
|
| 442 | + * email_to: Email or field id |
|
| 443 | + * also_email_to: array of fields ids |
|
| 444 | + * reply_to: Email, field id, 'custom' |
|
| 445 | + * cust_reply_to: string |
|
| 446 | + * reply_to_name: field id, 'custom' |
|
| 447 | + * cust_reply_to_name: string |
|
| 448 | + * plain_text: 0|1 |
|
| 449 | + * email_message: string or '' |
|
| 450 | + * email_subject: string or '' |
|
| 451 | + * inc_user_info: 0|1 |
|
| 452 | + * update_email: 0, 1, 2 |
|
| 453 | + * |
|
| 454 | + * Old autoresponder settings format: |
|
| 455 | + * auto_responder: 0|1 |
|
| 456 | + * ar_email_message: string or '' |
|
| 457 | + * ar_email_to: field id |
|
| 458 | + * ar_plain_text: 0|1 |
|
| 459 | + * ar_reply_to_name: string |
|
| 460 | + * ar_reply_to: string |
|
| 461 | + * ar_email_subject: string |
|
| 462 | + * ar_update_email: 0, 1, 2 |
|
| 463 | + * |
|
| 464 | + * New email settings: |
|
| 465 | + * post_content: json settings |
|
| 466 | + * post_title: form id |
|
| 467 | + * post_excerpt: message |
|
| 468 | + */ |
|
| 469 | + foreach ( $forms as $form ) { |
|
| 470 | 470 | if ( $form->is_template && $form->default_template ) { |
| 471 | 471 | // don't migrate the default templates since the email will be added anyway |
| 472 | 472 | continue; |
@@ -475,19 +475,19 @@ discard block |
||
| 475 | 475 | // Format form options |
| 476 | 476 | $form_options = maybe_unserialize( $form->options ); |
| 477 | 477 | |
| 478 | - // Migrate settings to actions |
|
| 479 | - FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
|
| 480 | - } |
|
| 481 | - } |
|
| 478 | + // Migrate settings to actions |
|
| 479 | + FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - private function migrate_to_11() { |
|
| 484 | - global $wpdb; |
|
| 483 | + private function migrate_to_11() { |
|
| 484 | + global $wpdb; |
|
| 485 | 485 | |
| 486 | 486 | $forms = FrmDb::get_results( $this->forms, array(), 'id, options' ); |
| 487 | 487 | |
| 488 | - $sending = __( 'Sending', 'formidable' ); |
|
| 488 | + $sending = __( 'Sending', 'formidable' ); |
|
| 489 | 489 | $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; |
| 490 | - $old_default_html = <<<DEFAULT_HTML |
|
| 490 | + $old_default_html = <<<DEFAULT_HTML |
|
| 491 | 491 | <div class="frm_submit"> |
| 492 | 492 | [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button] |
| 493 | 493 | <input type="submit" value="[button_label]" [button_action] /> |
@@ -497,21 +497,21 @@ discard block |
||
| 497 | 497 | unset( $sending, $img ); |
| 498 | 498 | |
| 499 | 499 | $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
| 500 | - $draft_link = FrmFormsHelper::get_draft_link(); |
|
| 500 | + $draft_link = FrmFormsHelper::get_draft_link(); |
|
| 501 | 501 | foreach ( $forms as $form ) { |
| 502 | 502 | $form->options = maybe_unserialize( $form->options ); |
| 503 | 503 | if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) { |
| 504 | - continue; |
|
| 505 | - } |
|
| 504 | + continue; |
|
| 505 | + } |
|
| 506 | 506 | |
| 507 | - if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
|
| 508 | - $form->options['submit_html'] = $new_default_html; |
|
| 507 | + if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
|
| 508 | + $form->options['submit_html'] = $new_default_html; |
|
| 509 | 509 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 510 | 510 | } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) { |
| 511 | 511 | $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
| 512 | 512 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 513 | - } |
|
| 513 | + } |
|
| 514 | 514 | unset( $form ); |
| 515 | - } |
|
| 516 | - } |
|
| 515 | + } |
|
| 516 | + } |
|
| 517 | 517 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | foreach ( $values as $value_key => $value ) { |
| 140 | 140 | if ( $value_key && in_array( $value_key, $form_fields ) ) { |
| 141 | - $new_values[ $value_key ] = $value; |
|
| 141 | + $new_values[$value_key] = $value; |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
@@ -209,15 +209,15 @@ discard block |
||
| 209 | 209 | $existing_keys = array_keys( $values['item_meta'] ); |
| 210 | 210 | foreach ( $all_fields as $fid ) { |
| 211 | 211 | if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) { |
| 212 | - $values['item_meta'][ $fid->id ] = ''; |
|
| 212 | + $values['item_meta'][$fid->id] = ''; |
|
| 213 | 213 | } |
| 214 | - $field_array[ $fid->id ] = $fid; |
|
| 214 | + $field_array[$fid->id] = $fid; |
|
| 215 | 215 | } |
| 216 | 216 | unset( $all_fields ); |
| 217 | 217 | |
| 218 | 218 | foreach ( $values['item_meta'] as $field_id => $default_value ) { |
| 219 | - if ( isset( $field_array[ $field_id ] ) ) { |
|
| 220 | - $field = $field_array[ $field_id ]; |
|
| 219 | + if ( isset( $field_array[$field_id] ) ) { |
|
| 220 | + $field = $field_array[$field_id]; |
|
| 221 | 221 | } else { |
| 222 | 222 | $field = FrmField::getOne( $field_id ); |
| 223 | 223 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | continue; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
|
| 229 | + $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ); |
|
| 230 | 230 | if ( $is_settings_page ) { |
| 231 | 231 | self::get_settings_page_html( $values, $field ); |
| 232 | 232 | |
@@ -241,12 +241,12 @@ discard block |
||
| 241 | 241 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
| 242 | 242 | |
| 243 | 243 | foreach ( $update_options as $opt => $default ) { |
| 244 | - $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default; |
|
| 245 | - self::sanitize_field_opt( $opt, $field->field_options[ $opt ] ); |
|
| 244 | + $field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? $values['field_options'][$opt . '_' . $field_id] : $default; |
|
| 245 | + self::sanitize_field_opt( $opt, $field->field_options[$opt] ); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| 249 | - $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
|
| 249 | + $default_value = maybe_serialize( $values['item_meta'][$field_id] ); |
|
| 250 | 250 | |
| 251 | 251 | $new_field = array( |
| 252 | 252 | 'field_options' => $field->field_options, |
@@ -279,10 +279,10 @@ discard block |
||
| 279 | 279 | * Updating the settings page |
| 280 | 280 | */ |
| 281 | 281 | private static function get_settings_page_html( $values, &$field ) { |
| 282 | - if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) { |
|
| 282 | + if ( isset( $values['field_options']['custom_html_' . $field->id] ) ) { |
|
| 283 | 283 | $prev_opts = array(); |
| 284 | 284 | $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ); |
| 285 | - $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html; |
|
| 285 | + $field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field->id] ) ? $values['field_options']['custom_html_' . $field->id] : $fallback_html; |
|
| 286 | 286 | } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
| 287 | 287 | $prev_opts = $field->field_options; |
| 288 | 288 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | ); |
| 307 | 307 | foreach ( $field_cols as $col => $default ) { |
| 308 | 308 | $default = ( $default === '' ) ? $field->{$col} : $default; |
| 309 | - $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default; |
|
| 309 | + $new_field[$col] = isset( $values['field_options'][$col . '_' . $field->id] ) ? $values['field_options'][$col . '_' . $field->id] : $default; |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | return self::trash( $id ); |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - $statuses = array( 'published', 'draft', 'trash' ); |
|
| 322 | + $statuses = array( 'published', 'draft', 'trash' ); |
|
| 323 | 323 | if ( ! in_array( $status, $statuses ) ) { |
| 324 | 324 | return false; |
| 325 | 325 | } |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | $form->options = maybe_unserialize( $form->options ); |
| 456 | 456 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
| 457 | 457 | self::destroy( $form->id ); |
| 458 | - $count++; |
|
| 458 | + $count ++; |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | unset( $form ); |
@@ -636,16 +636,16 @@ discard block |
||
| 636 | 636 | foreach ( $results as $row ) { |
| 637 | 637 | if ( 'trash' != $row->status ) { |
| 638 | 638 | if ( $row->is_template ) { |
| 639 | - $counts['template']++; |
|
| 639 | + $counts['template'] ++; |
|
| 640 | 640 | } else { |
| 641 | - $counts['published']++; |
|
| 641 | + $counts['published'] ++; |
|
| 642 | 642 | } |
| 643 | 643 | } else { |
| 644 | - $counts['trash']++; |
|
| 644 | + $counts['trash'] ++; |
|
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | if ( 'draft' == $row->status ) { |
| 648 | - $counts['draft']++; |
|
| 648 | + $counts['draft'] ++; |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | unset( $row ); |
@@ -686,8 +686,8 @@ discard block |
||
| 686 | 686 | self::maybe_get_form( $form ); |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | - if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) { |
|
| 690 | - return $frm_vars['form_params'][ $form->id ]; |
|
| 689 | + if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) { |
|
| 690 | + return $frm_vars['form_params'][$form->id]; |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // WPCS: CSRF ok. |
@@ -716,15 +716,15 @@ discard block |
||
| 716 | 716 | //if there are two forms on the same page, make sure not to submit both |
| 717 | 717 | foreach ( $default_values as $var => $default ) { |
| 718 | 718 | if ( $var == 'action' ) { |
| 719 | - $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
| 719 | + $values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
| 720 | 720 | } else { |
| 721 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 721 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 722 | 722 | } |
| 723 | 723 | unset( $var, $default ); |
| 724 | 724 | } |
| 725 | 725 | } else { |
| 726 | 726 | foreach ( $default_values as $var => $default ) { |
| 727 | - $values[ $var ] = $default; |
|
| 727 | + $values[$var] = $default; |
|
| 728 | 728 | unset( $var, $default ); |
| 729 | 729 | } |
| 730 | 730 | } |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | 'sdir' => '', |
| 749 | 749 | ); |
| 750 | 750 | foreach ( $defaults as $var => $default ) { |
| 751 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 751 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | return $values; |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | 'keep_post' => '', |
| 777 | 777 | ); |
| 778 | 778 | foreach ( $defaults as $var => $default ) { |
| 779 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 779 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | return $values; |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | */ |
| 858 | 858 | public static function get_option( $atts ) { |
| 859 | 859 | $form = $atts['form']; |
| 860 | - return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $atts['default']; |
|
| 860 | + return isset( $form->options[$atts['option']] ) ? $form->options[$atts['option']] : $atts['default']; |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |