| @@ -1,7 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; | |
| 3 | - | |
| 4 | 2 | function accua_form_Load($class) { |
| 5 | 3 | if (substr($class,0,10) === 'AccuaForm_') { |
| 6 | 4 | $class = substr($class, 10); |
| 7 | 5 | $file = ACCUA_FORMS_DIR . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . str_replace("_", DIRECTORY_SEPARATOR, $class) . ".php"; |
| @@ -16,104 +14,30 @@ | ||
| 16 | 14 | require_once('AccuaForm.php'); |
| 17 | 15 | |
| 18 | 16 | define('ACCUA_FORM_API_PLUGIN_TEXTDOMAIN_PATH', dirname( plugin_basename( __FILE__ ) ) . '/languages/'); |
| 19 | 17 | |
| 20 | -add_action('wp_enqueue_scripts', 'accua_form_enqueue_scripts_and_styles'); | |
| 21 | -add_action('admin_enqueue_scripts', 'accua_form_enqueue_scripts_and_styles'); | |
| 22 | -add_action('login_enqueue_scripts', 'accua_form_enqueue_scripts_and_styles'); | |
| 23 | -function accua_form_enqueue_scripts_and_styles(){ | |
| 18 | +add_action( 'wp_print_scripts', 'accua_form_init_scripts'); | |
| 19 | +function accua_form_init_scripts(){ | |
| 20 | + wp_enqueue_script('jquery'); | |
| 21 | + AccuaForm_Element_ColorPicker::maybe_load_colorPicker_scripts(); | |
| 22 | +} | |
| 23 | + | |
| 24 | +add_action('wp_enqueue_scripts', 'accua_form_enqueue_styles'); | |
| 25 | +add_action('admin_enqueue_scripts', 'accua_form_enqueue_styles'); | |
| 26 | +add_action('login_enqueue_scripts', 'accua_form_enqueue_styles'); | |
| 27 | +add_action('wp_print_styles', 'accua_form_enqueue_styles'); | |
| 28 | +function accua_form_enqueue_styles(){ | |
| 24 | 29 | static $first = TRUE; |
| 25 | 30 | if ($first) { |
| 26 | - wp_enqueue_script('jquery'); | |
| 27 | - | |
| 28 | - // In admin context, use WordPress's wp-color-picker (has all dependencies available) | |
| 29 | - if (is_admin()) { | |
| 30 | - wp_enqueue_style('wp-color-picker'); | |
| 31 | - wp_enqueue_script('wp-color-picker'); | |
| 32 | - } | |
| 33 | - // On frontend, we use HTML5 native color input (no JS dependencies needed) | |
| 34 | - // This is WCAG 2.2 AA compliant, keyboard accessible, and works in all modern browsers | |
| 35 | - | |
| 36 | - wp_enqueue_style('accua-forms-api-base', plugins_url('assets/css/frontend.css', ACCUA_FORMS_FILE), array(), ACCUA_FORMS_CSS_VERSION); | |
| 37 | - | |
| 38 | - // Accessible file upload with drag & drop (WCAG 2.2 AA compliant) | |
| 39 | - wp_enqueue_script( | |
| 40 | - 'accua-file-upload', | |
| 41 | - plugins_url('assets/js/frontend/file-upload.js', ACCUA_FORMS_FILE), | |
| 42 | - array(), // No dependencies - vanilla JS | |
| 43 | - ACCUA_FORMS_JS_VERSION, | |
| 44 | - true // Load in footer | |
| 45 | - ); | |
| 46 | - | |
| 47 | - // Localized strings for file upload | |
| 48 | - wp_localize_script('accua-file-upload', 'accuaFileUploadL10n', array( | |
| 49 | - 'fileTooLarge' => __('File exceeds maximum allowed size', 'contact-forms'), | |
| 50 | - 'invalidType' => __('File type not allowed', 'contact-forms'), | |
| 51 | - 'fileAdded' => __('File added', 'contact-forms'), | |
| 52 | - 'filesAdded' => __('files added', 'contact-forms'), | |
| 53 | - 'fileRemoved' => __('File removed', 'contact-forms'), | |
| 54 | - 'errors' => __('Errors', 'contact-forms'), | |
| 55 | - 'removeFile' => __('Remove', 'contact-forms'), | |
| 56 | - )); | |
| 57 | - | |
| 58 | - // libphonenumber-js for phone validation (min bundle, ~175KB) | |
| 59 | - wp_enqueue_script( | |
| 60 | - 'libphonenumber', | |
| 61 | - plugins_url('assets/js/frontend/libphonenumber-min.js', ACCUA_FORMS_FILE), | |
| 62 | - array(), // No dependencies | |
| 63 | - '1.12.5', // libphonenumber-js version | |
| 64 | - true // Load in footer | |
| 65 | - ); | |
| 66 | - | |
| 67 | - // Phone validation for telephone fields (WCAG 2.2 AA compliant) | |
| 68 | - // Uses libphonenumber-js for proper international phone validation | |
| 69 | - wp_enqueue_script( | |
| 70 | - 'accua-phone-validation', | |
| 71 | - plugins_url('assets/js/frontend/phone-validation.js', ACCUA_FORMS_FILE), | |
| 72 | - array('jquery', 'libphonenumber'), | |
| 73 | - ACCUA_FORMS_JS_VERSION, | |
| 74 | - true // Load in footer | |
| 75 | - ); | |
| 76 | - | |
| 77 | - // Localized strings for phone validation | |
| 78 | - wp_localize_script('accua-phone-validation', 'accuaPhoneL10n', array( | |
| 79 | - 'phoneError' => __('Please enter a valid phone number (e.g. +39 333 1234567)', 'contact-forms'), | |
| 80 | - )); | |
| 81 | - | |
| 82 | - // Post select - AJAX searchable dropdown for post-select fields (WCAG 2.2 AA compliant) | |
| 83 | - wp_enqueue_script( | |
| 84 | - 'accua-post-select', | |
| 85 | - plugins_url('assets/js/frontend/post-select.js', ACCUA_FORMS_FILE), | |
| 86 | - array(), // No dependencies - vanilla JS | |
| 87 | - ACCUA_FORMS_JS_VERSION, | |
| 88 | - true // Load in footer | |
| 89 | - ); | |
| 90 | - | |
| 91 | - // Localized strings for post select | |
| 92 | - wp_localize_script('accua-post-select', 'accuaPostSelectI18n', array( | |
| 93 | - 'select' => __('Select...', 'contact-forms'), | |
| 94 | - 'search' => __('Search...', 'contact-forms'), | |
| 95 | - 'loading' => __('Loading...', 'contact-forms'), | |
| 96 | - 'noResults' => __('No results found', 'contact-forms'), | |
| 97 | - 'loadMore' => __('Loading more...', 'contact-forms'), | |
| 98 | - )); | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * Action fired after Contact Forms enqueues its scripts and styles. | |
| 102 | - * External plugins can use this to enqueue their own field-specific assets. | |
| 103 | - */ | |
| 104 | - do_action( 'accua_forms_enqueue_scripts' ); | |
| 105 | - | |
| 31 | + AccuaForm_Element_ColorPicker::maybe_load_colorPicker_styles(); | |
| 32 | + wp_enqueue_style('accua-forms-api-base', plugins_url('accua-form-api.css', ACCUA_FORMS_FILE), array(), ACCUA_FORMS_CSS_VERSION); | |
| 106 | 33 | $first = FALSE; |
| 107 | 34 | } |
| 108 | 35 | } |
| 109 | 36 | |
| 110 | -// Runs at init priority 5 so that: | |
| 111 | -// 1. Translations are safe to use (after_setup_theme has fired before init). | |
| 112 | -// 2. SMTP plugins (WP Mail SMTP etc.) have already registered their phpmailer_init hooks | |
| 113 | -// at plugins_loaded priority ≤ 10, so emails sent here still go through SMTP. | |
| 114 | -add_action('init', 'accua_form_init', 5); | |
| 37 | +add_action('plugins_loaded', 'accua_form_init'); | |
| 115 | 38 | function accua_form_init(){ |
| 39 | + load_plugin_textdomain( 'contact-forms', false, ACCUA_FORM_API_PLUGIN_TEXTDOMAIN_PATH); | |
| 116 | 40 | if (!defined('DOING_CRON')) { |
| 117 | 41 | AccuaForm::isValid(); |
| 118 | 42 | } |
| 119 | 43 | } |
| @@ -121,20 +45,15 @@ | ||
| 121 | 45 | add_action('wp_ajax_accua_form_submit', 'accua_form_ajax_submit_handler'); |
| 122 | 46 | add_action('wp_ajax_nopriv_accua_form_submit', 'accua_form_ajax_submit_handler'); |
| 123 | 47 | function accua_form_ajax_submit_handler(){ |
| 124 | 48 | header('Content-Type: text/html; charset='.get_option('blog_charset')); |
| 125 | - header('Cache-Control: no-transform'); | |
| 126 | 49 | |
| 127 | 50 | echo '<html><head></head><body><pre id="accua-form-ajax-response">'; |
| 128 | 51 | |
| 129 | - $result = AccuaForm::ajaxSubmit(); | |
| 130 | - | |
| 131 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON encoded data for JavaScript consumption | |
| 132 | - print _accua_forms_json_encode($result); | |
| 52 | + print _accua_forms_json_encode(AccuaForm::ajaxSubmit()); | |
| 133 | 53 | |
| 134 | 54 | echo '</pre><div id="accua-form-ajax-response-loaded"></div>'; |
| 135 | 55 | |
| 136 | - // phpcs:disable PluginCheck.CodeAnalysis.Heredoc.NotAllowed -- Heredoc for inline JavaScript | |
| 137 | 56 | echo <<<EOJS |
| 138 | 57 | <script type="text/javascript"> |
| 139 | 58 | <!-- |
| 140 | 59 | try { |
| @@ -143,9 +62,8 @@ | ||
| 143 | 62 | } |
| 144 | 63 | // --> |
| 145 | 64 | </script> |
| 146 | 65 | EOJS; |
| 147 | - // phpcs:enable PluginCheck.CodeAnalysis.Heredoc.NotAllowed | |
| 148 | 66 | |
| 149 | 67 | echo '</body></html>'; |
| 150 | 68 | die(''); |
| 151 | 69 | } |