| @@ -19,8 +19,9 @@ | ||
| 19 | 19 | * Hook in methods |
| 20 | 20 | */ |
| 21 | 21 | public static function init() { |
| 22 | 22 | add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) ); |
| 23 | + add_filter( 'script_loader_tag', array( __CLASS__, 'embed_script_attributes' ), 10, 2 ); | |
| 23 | 24 | add_action( 'wp_print_scripts', array( __CLASS__, 'check_jquery' ), 25 ); |
| 24 | 25 | add_action( 'wp_print_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 ); |
| 25 | 26 | add_action( 'wp_print_footer_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 ); |
| 26 | 27 | } |
| @@ -25,8 +26,22 @@ | ||
| 25 | 26 | add_action( 'wp_print_footer_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 ); |
| 26 | 27 | } |
| 27 | 28 | |
| 28 | 29 | /** |
| 30 | + * Preserve the provider attributes used by the original Reel embeds. | |
| 31 | + */ | |
| 32 | + public static function embed_script_attributes( $tag, $handle ) { | |
| 33 | + if ( 'propertyhive-instagram-embed' === $handle ) { | |
| 34 | + return str_replace( '<script ', '<script async ', $tag ); | |
| 35 | + } | |
| 36 | + if ( 'propertyhive-facebook-embed' === $handle ) { | |
| 37 | + $tag = str_replace( array( 'id="propertyhive-facebook-embed-js"', "id='propertyhive-facebook-embed-js'" ), 'id="facebook-jssdk"', $tag ); | |
| 38 | + return str_replace( '<script ', '<script async defer crossorigin="anonymous" ', $tag ); | |
| 39 | + } | |
| 40 | + return $tag; | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 29 | 44 | * Get styles for the frontend |
| 30 | 45 | * @return array |
| 31 | 46 | */ |
| 32 | 47 | public static function get_styles() { |
| @@ -56,11 +71,15 @@ | ||
| 56 | 71 | |
| 57 | 72 | // Register any scripts for later use, or used as dependencies |
| 58 | 73 | wp_register_script( 'jquery-cookie', $assets_path . 'js/jquery-cookie/jquery.cookie' . $suffix . '.js', array( 'jquery' ), '1.3.1', true ); |
| 59 | 74 | |
| 60 | - wp_register_script( 'propertyhive_fancybox', $assets_path . 'js/fancybox/jquery.fancybox' . $suffix . '.js', array( 'jquery' ), '3.3.5', true ); | |
| 61 | - wp_register_style( 'propertyhive_fancybox_css', $assets_path . 'css/jquery.fancybox' . $suffix . '.css', array(), '3.3.5' ); | |
| 75 | + wp_register_script( 'propertyhive_fancybox', $assets_path . 'js/fancybox/jquery.fancybox' . $suffix . '.js', array( 'jquery' ), '3.5.7', true ); | |
| 76 | + wp_register_style( 'propertyhive_fancybox_css', $assets_path . 'css/jquery.fancybox' . $suffix . '.css', array(), '3.5.7' ); | |
| 62 | 77 | |
| 78 | + wp_register_script( 'tiny_slider', $assets_path . 'js/tiny-slider/tiny-slider.js', array( 'jquery' ), '2.9.4', true ); | |
| 79 | + wp_register_script( 'propertyhive_carousel', $assets_path . 'js/frontend/carousel.js', array( 'jquery' ), PH_VERSION, true ); | |
| 80 | + wp_register_style( 'tiny_slider_css', $assets_path . 'js/tiny-slider/tiny-slider.css', array(), '2.9.4' ); | |
| 81 | + | |
| 63 | 82 | if ( get_option('propertyhive_lettings_fees_display_search_results', '') == 'yes' ) |
| 64 | 83 | { |
| 65 | 84 | wp_enqueue_script( 'propertyhive_fancybox' ); |
| 66 | 85 | wp_enqueue_style( 'propertyhive_fancybox_css' ); |
| @@ -65,17 +84,16 @@ | ||
| 65 | 84 | wp_enqueue_script( 'propertyhive_fancybox' ); |
| 66 | 85 | wp_enqueue_style( 'propertyhive_fancybox_css' ); |
| 67 | 86 | } |
| 68 | 87 | |
| 69 | - if ( is_property() ) { | |
| 88 | + if ( is_property() ) | |
| 89 | + { | |
| 70 | 90 | wp_enqueue_script( 'propertyhive_fancybox' ); |
| 71 | 91 | wp_enqueue_style( 'propertyhive_fancybox_css' ); |
| 72 | 92 | |
| 73 | - wp_enqueue_script( 'flexslider', $assets_path . 'js/flexslider/jquery.flexslider' . $suffix . '.js', array( 'jquery' ), '2.2.2', true ); | |
| 93 | + wp_enqueue_script( 'flexslider', $assets_path . 'js/flexslider/jquery.flexslider' . $suffix . '.js', array( 'jquery' ), '2.7.2', true ); | |
| 74 | 94 | wp_enqueue_script( 'flexslider-init', $assets_path . 'js/flexslider/jquery.flexslider.init' . $suffix . '.js', array( 'jquery','flexslider' ), PH_VERSION, true ); |
| 75 | - wp_enqueue_style( 'flexslider_css', $assets_path . 'css/flexslider.css' ); | |
| 76 | - | |
| 77 | - wp_enqueue_script( 'ph-single-property' ); | |
| 95 | + wp_enqueue_style( 'flexslider_css', $assets_path . 'css/flexslider.css', array(), '2.7.2' ); | |
| 78 | 96 | } |
| 79 | 97 | |
| 80 | 98 | // Global frontend scripts |
| 81 | 99 | wp_enqueue_script( 'propertyhive_search', $frontend_script_path . 'search' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true ); |
| @@ -81,8 +99,25 @@ | ||
| 81 | 99 | wp_enqueue_script( 'propertyhive_search', $frontend_script_path . 'search' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true ); |
| 82 | 100 | wp_enqueue_script( 'propertyhive_make_enquiry', $frontend_script_path . 'make-enquiry' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true ); |
| 83 | 101 | //wp_enqueue_script( 'propertyhive', $frontend_script_path . 'propertyhive' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true ); |
| 84 | 102 | |
| 103 | + $captcha_service = get_option( 'propertyhive_captcha_service', '' ); | |
| 104 | + if ( $captcha_service == 'turnstile' ) | |
| 105 | + { | |
| 106 | + if ( get_option( 'propertyhive_captcha_site_key', '' ) != '' && get_option( 'propertyhive_captcha_secret', '' ) != '' ) | |
| 107 | + { | |
| 108 | + // phpcs:ignore PluginCheck.CodeAnalysis.EnqueuedResourceOffloading.OffloadedContent -- Required by the configured Cloudflare Turnstile service. | |
| 109 | + wp_enqueue_script( 'turnstile', 'https://challenges.cloudflare.com/turnstile/v0/api.js?onload=ph_init_turnstile', array(), PH_VERSION, array( 'strategy' => 'defer', 'in_footer' => true ) ); | |
| 110 | + } | |
| 111 | + } | |
| 112 | + | |
| 113 | + wp_register_script( 'multiselect', $assets_path . 'js/multiselect/jquery.multiselect' . /*$suffix .*/ '.js', array('jquery'), '2.4.18', true ); | |
| 114 | + wp_enqueue_style( 'multiselect', $assets_path . 'css/jquery.multiselect.css', array(), '2.4.18' ); | |
| 115 | + | |
| 116 | + wp_register_script( 'propertyhive_dynamic_population', $assets_path . 'js/frontend/dynamic-population' . /*$suffix .*/ '.js', array('jquery'), '1.0.0', true ); | |
| 117 | + | |
| 118 | + wp_enqueue_script( 'propertyhive_utm_tracker', $assets_path . 'js/frontend/utm-tracker' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true ); | |
| 119 | + | |
| 85 | 120 | // CSS Styles |
| 86 | 121 | $enqueue_styles = self::get_styles(); |
| 87 | 122 | |
| 88 | 123 | if ( $enqueue_styles ) { |
| @@ -99,22 +134,80 @@ | ||
| 99 | 134 | global $wp; |
| 100 | 135 | |
| 101 | 136 | $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/'; |
| 102 | 137 | |
| 103 | - if ( wp_script_is( 'propertyhive_make_enquiry' ) ) { | |
| 104 | - wp_localize_script( 'propertyhive_make_enquiry', 'propertyhive_make_property_enquiry_params', apply_filters( 'propertyhive_make_property_enquiry_params', array( | |
| 105 | - 'ajax_url' => PH()->ajax_url() | |
| 106 | - ) ) ); | |
| 138 | + if ( wp_script_is( 'propertyhive_search' ) ) | |
| 139 | + { | |
| 140 | + $params = array( | |
| 141 | + 'custom_departments' => ph_get_custom_departments(), | |
| 142 | + 'do_image_resize' => false, | |
| 143 | + 'image_ratio' => 2 / 3, | |
| 144 | + ); | |
| 145 | + | |
| 146 | + $current_settings = get_option( 'propertyhive_template_assistant', array() ); | |
| 147 | + | |
| 148 | + if ( | |
| 149 | + is_post_type_archive('property') | |
| 150 | + || | |
| 151 | + ( isset($current_settings['search_result_css_all_pages']) && $current_settings['search_result_css_all_pages'] == 'yes' ) | |
| 152 | + ) | |
| 153 | + { | |
| 154 | + if ( | |
| 155 | + isset($current_settings['search_result_layout']) && | |
| 156 | + isset($current_settings['search_result_layout']) == 2 | |
| 157 | + ) | |
| 158 | + { | |
| 159 | + $params['do_image_resize'] = true; | |
| 160 | + } | |
| 161 | + } | |
| 162 | + | |
| 163 | + $params = apply_filters( 'propertyhive_search_params', $params ); | |
| 164 | + $params = apply_filters( 'propertyhive_template_assistant_script_params', $params ); | |
| 165 | + | |
| 166 | + wp_localize_script( 'propertyhive_search', 'propertyhive_search_params', $params ); | |
| 107 | 167 | } |
| 108 | 168 | |
| 109 | - if ( wp_script_is( 'propertyhive_account' ) ) { | |
| 110 | - wp_localize_script( 'propertyhive_account', 'propertyhive_account_params', apply_filters( 'propertyhive_account_params', array( | |
| 169 | + if ( wp_script_is( 'propertyhive_make_enquiry' ) ) | |
| 170 | + { | |
| 171 | + $data = array( | |
| 172 | + 'ajax_url' => PH()->ajax_url(), | |
| 173 | + 'default_validation_error_message' => esc_html(__( 'Please ensure all required fields have been completed', 'propertyhive' )), | |
| 174 | + ); | |
| 175 | + if ( get_option('propertyhive_captcha_service', '') != '' ) | |
| 176 | + { | |
| 177 | + $data['captcha_service'] = get_option('propertyhive_captcha_service', ''); | |
| 178 | + $data['recaptcha_site_key'] = get_option('propertyhive_captcha_site_key', 'recaptcha-v3'); | |
| 179 | + } | |
| 180 | + wp_localize_script( 'propertyhive_make_enquiry', 'propertyhive_make_property_enquiry_params', apply_filters( 'propertyhive_make_property_enquiry_params', $data ) ); | |
| 181 | + } | |
| 182 | + | |
| 183 | + if ( wp_script_is( 'propertyhive_account' ) ) | |
| 184 | + { | |
| 185 | + $data = array( | |
| 111 | 186 | 'ajax_url' => PH()->ajax_url(), |
| 112 | 187 | 'my_account_url' => get_permalink( ph_get_page_id('my_account') ), |
| 188 | + 'custom_departments' => ph_get_custom_departments(), | |
| 113 | 189 | 'login_nonce' => wp_create_nonce( "ph_login" ), |
| 190 | + 'lost_password_nonce' => wp_create_nonce( "ph_lost_password" ), | |
| 191 | + 'reset_password_nonce' => wp_create_nonce( "ph_reset_password" ), | |
| 114 | 192 | 'register_nonce' => wp_create_nonce( "ph_register" ), |
| 115 | - 'details_nonce' => wp_create_nonce( "ph_details" ), | |
| 193 | + 'userdetails_nonce' => wp_create_nonce( "ph_userdetails" ), | |
| 116 | 194 | 'requirements_nonce' => wp_create_nonce( "ph_requirements" ), |
| 195 | + 'default_validation_error_message' => esc_html(__( 'Please ensure all required fields have been completed', 'propertyhive' )), | |
| 196 | + ); | |
| 197 | + if ( get_option('propertyhive_captcha_service', '') != '' ) | |
| 198 | + { | |
| 199 | + $data['captcha_service'] = get_option('propertyhive_captcha_service', ''); | |
| 200 | + $data['recaptcha_site_key'] = get_option('propertyhive_captcha_site_key', 'recaptcha-v3'); | |
| 201 | + } | |
| 202 | + | |
| 203 | + wp_localize_script( 'propertyhive_account', 'propertyhive_account_params', apply_filters( 'propertyhive_account_params', $data ) ); | |
| 204 | + } | |
| 205 | + | |
| 206 | + if ( wp_script_is( 'multiselect' ) ) { | |
| 207 | + wp_localize_script( 'multiselect', 'propertyhive_multiselect_params', apply_filters( 'propertyhive_multiselect_params', array( | |
| 208 | + 'search' => false, | |
| 209 | + 'selected_text' => __( 'selected', 'propertyhive' ), | |
| 117 | 210 | ) ) ); |
| 118 | 211 | } |
| 119 | 212 | } |
| 120 | 213 | |
| @@ -132,9 +225,9 @@ | ||
| 132 | 225 | |
| 133 | 226 | // Enforce minimum version of jQuery |
| 134 | 227 | if ( ! empty( $wp_scripts->registered['jquery']->ver ) && ! empty( $wp_scripts->registered['jquery']->src ) && 0 >= version_compare( $wp_scripts->registered['jquery']->ver, '1.8' ) ) { |
| 135 | 228 | wp_deregister_script( 'jquery' ); |
| 136 | - wp_register_script( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.8' ); | |
| 229 | + wp_register_script( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.8', false ); | |
| 137 | 230 | wp_enqueue_script( 'jquery' ); |
| 138 | 231 | } |
| 139 | 232 | } |
| 140 | 233 | } |