| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | +// phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] ph_clean | |
| 3 | +// ph_clean() recursively sanitizes text; presence, shape and unslashing checks remain separate. | |
| 4 | + | |
| 2 | 5 | /** |
| 3 | 6 | * Load assets. |
| 4 | 7 | * |
| 5 | 8 | * @author PropertyHive |
| @@ -14,8 +17,9 @@ | ||
| 14 | 17 | |
| 15 | 18 | /** |
| 16 | 19 | * PH_Admin_Assets Class |
| 17 | 20 | */ |
| 21 | +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Admin_Assets; preserving the existing PH_* class name is required for plugin and extension compatibility. | |
| 18 | 22 | class PH_Admin_Assets { |
| 19 | 23 | |
| 20 | 24 | /** |
| 21 | 25 | * Hook in tabs. |
| @@ -34,9 +38,9 @@ | ||
| 34 | 38 | // Sitewide menu CSS |
| 35 | 39 | //wp_enqueue_style( 'propertyhive_admin_menu_styles', PH()->plugin_url() . '/assets/css/menu.css', array(), PH_VERSION ); |
| 36 | 40 | |
| 37 | 41 | $screen = get_current_screen(); |
| 38 | - | |
| 42 | + | |
| 39 | 43 | if ( in_array( $screen->id, ph_get_screen_ids() ) ) { |
| 40 | 44 | |
| 41 | 45 | $jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2'; |
| 42 | 46 | |
| @@ -50,14 +54,65 @@ | ||
| 50 | 54 | |
| 51 | 55 | wp_enqueue_style( 'chosen', PH()->plugin_url() . '/assets/css/chosen.css', array(), PH_VERSION ); |
| 52 | 56 | |
| 53 | 57 | wp_enqueue_style( 'multiselect', PH()->plugin_url() . '/assets/css/jquery.multiselect.css', array(), '2.4.18' ); |
| 58 | + | |
| 59 | + if ( apply_filters('propertyhive_disable_notes_mention', false) === false ) | |
| 60 | + { | |
| 61 | + wp_enqueue_style( 'tinymce-mention', PH()->plugin_url() . '/assets/js/tinymce-mention-plugin/autocomplete.css', array(), PH_VERSION ); | |
| 62 | + } | |
| 63 | + | |
| 64 | + if ( get_option('propertyhive_maps_provider') == 'mapbox' ) | |
| 65 | + { | |
| 66 | + wp_enqueue_style('mapbox', PH()->plugin_url() . '/assets/js/mapbox/mapbox-gl.css', array(), '3.8.0' ); | |
| 67 | + } | |
| 54 | 68 | } |
| 55 | 69 | |
| 70 | + if ( in_array( $screen->id, array( 'property' ) ) ) | |
| 71 | + { | |
| 72 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tour asset selection; no data is changed. | |
| 73 | + if ( isset( $_GET['tutorial'] ) && is_string( $_GET['tutorial'] ) && sanitize_text_field( wp_unslash( $_GET['tutorial'] ) ) === 'yes' ) | |
| 74 | + { | |
| 75 | + wp_register_style( 'tour-css', PH()->plugin_url() . '/assets/css/tours/style.css', array(), '1.0.1' ); | |
| 76 | + wp_register_style( 'driver-css', PH()->plugin_url() . '/assets/css/tours/driver-js.css', array(), '1.0.1' ); | |
| 77 | + wp_enqueue_style( 'tour-css' ); | |
| 78 | + wp_enqueue_style( 'driver-css' ); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + if ( in_array( $screen->id, array( 'edit-contact', 'edit-enquiry', 'edit-appraisal', 'edit-viewing', 'edit-offer', 'edit-sale', 'edit-key_date' ) ) ) | |
| 83 | + { | |
| 84 | + wp_enqueue_style( 'daterangepicker.css', PH()->plugin_url() . '/assets/js/daterangepicker/daterangepicker.css', array(), '3.1.0' ); | |
| 85 | + } | |
| 86 | + | |
| 87 | + if ( in_array( $screen->id, array( 'edit-key_date') ) ) | |
| 88 | + { | |
| 89 | + wp_enqueue_style( 'admin-hide-default-post-data.css', PH()->plugin_url() . '/assets/css/admin-hide-default-post-data.css', array(), PH_VERSION ); | |
| 90 | + } | |
| 91 | + | |
| 92 | + if ( | |
| 93 | + get_option('propertyhive_module_disabled_viewings', '') != 'yes' && | |
| 94 | + in_array( $screen->id, array( 'property', 'contact' ) ) | |
| 95 | + ) | |
| 96 | + { | |
| 97 | + wp_enqueue_style( 'propertyhive_fancybox_css', PH()->plugin_url() . '/assets/css/jquery.fancybox.css', array(), '3.5.7' ); | |
| 98 | + } | |
| 99 | + | |
| 56 | 100 | /*if ( in_array( $screen->id, array( 'dashboard' ) ) ) { |
| 57 | 101 | wp_enqueue_style( 'propertyhive_admin_dashboard_styles', PH()->plugin_url() . '/assets/css/dashboard.css', array(), PH_VERSION ); |
| 58 | 102 | }*/ |
| 59 | 103 | |
| 104 | + if ( $screen->id === 'plugins' ) | |
| 105 | + { | |
| 106 | + // Enqueue the CSS file | |
| 107 | + wp_enqueue_style( | |
| 108 | + 'propertyhive_deactivate_survey', | |
| 109 | + PH()->plugin_url() . '/assets/css/deactivate-survey.css', | |
| 110 | + array(), | |
| 111 | + '1.0.0' | |
| 112 | + ); | |
| 113 | + } | |
| 114 | + | |
| 60 | 115 | do_action( 'propertyhive_admin_css' ); |
| 61 | 116 | } |
| 62 | 117 | |
| 63 | 118 | |
| @@ -64,39 +119,94 @@ | ||
| 64 | 119 | /** |
| 65 | 120 | * Enqueue scripts |
| 66 | 121 | */ |
| 67 | 122 | public function admin_scripts() { |
| 68 | - global $wp_query, $post; | |
| 123 | + global $wp_query, $post, $tabs; | |
| 69 | 124 | |
| 70 | 125 | $screen = get_current_screen(); |
| 71 | - $ph_screen_id = sanitize_title( __( 'PropertyHive', 'propertyhive' ) ); | |
| 72 | 126 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 73 | 127 | |
| 74 | 128 | // Register scripts |
| 75 | - wp_register_script( 'propertyhive_dashboard', PH()->plugin_url() . '/assets/js/admin/dashboard' . /*$suffix .*/ '.js', array( 'jquery' ), PH_VERSION ); | |
| 129 | + wp_register_script( 'propertyhive_dashboard', PH()->plugin_url() . '/assets/js/admin/dashboard' . /*$suffix .*/ '.js', array( 'jquery' ), PH_VERSION, true ); | |
| 76 | 130 | |
| 77 | - wp_register_script( 'propertyhive_admin', PH()->plugin_url() . '/assets/js/admin/admin' . /*$suffix .*/ '.js', array( 'jquery', 'jquery-tiptip' ), PH_VERSION ); | |
| 131 | + wp_register_script( 'propertyhive_admin', PH()->plugin_url() . '/assets/js/admin/admin' . /*$suffix .*/ '.js', array( 'jquery', 'jquery-tiptip' ), PH_VERSION, true ); | |
| 78 | 132 | |
| 79 | 133 | wp_register_script( 'jquery-tiptip', PH()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . /*$suffix .*/ '.js', array( 'jquery' ), PH_VERSION, true ); |
| 80 | 134 | |
| 81 | - wp_register_script( 'propertyhive_admin_meta_boxes', PH()->plugin_url() . '/assets/js/admin/meta-boxes' . /*$suffix .*/ '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable' ), PH_VERSION ); | |
| 135 | + wp_register_script( 'propertyhive_admin_meta_boxes', PH()->plugin_url() . '/assets/js/admin/meta-boxes' . /*$suffix .*/ '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable' ), PH_VERSION, true ); | |
| 82 | 136 | |
| 83 | - wp_register_script( 'propertyhive_admin_settings', PH()->plugin_url() . '/assets/js/admin/settings' . /*$suffix .*/ '.js', array( 'jquery', 'wp-color-picker' ), PH_VERSION ); | |
| 137 | + wp_register_script( 'propertyhive_admin_settings', PH()->plugin_url() . '/assets/js/admin/settings' . /*$suffix .*/ '.js', array( 'jquery', 'wp-color-picker' ), PH_VERSION, true ); | |
| 84 | 138 | |
| 85 | - wp_register_script( 'ajax-chosen', PH()->plugin_url() . '/assets/js/chosen/ajax-chosen.jquery' . /*$suffix .*/ '.js', array('jquery', 'chosen'), PH_VERSION ); | |
| 139 | + wp_register_script( 'propertyhive_admin_recently_viewed', PH()->plugin_url() . '/assets/js/admin/recently-viewed' . /*$suffix .*/ '.js', array( 'jquery' ), PH_VERSION, true ); | |
| 86 | 140 | |
| 87 | - wp_register_script( 'chosen', PH()->plugin_url() . '/assets/js/chosen/chosen.jquery' . /*$suffix .*/ '.js', array('jquery'), PH_VERSION ); | |
| 141 | + wp_register_script( 'ajax-chosen', PH()->plugin_url() . '/assets/js/chosen/ajax-chosen.jquery' . /*$suffix .*/ '.js', array('jquery', 'chosen'), PH_VERSION, true ); | |
| 88 | 142 | |
| 89 | - wp_register_script( 'multiselect', PH()->plugin_url() . '/assets/js/multiselect/jquery.multiselect' . /*$suffix .*/ '.js', array('jquery'), '2.4.18' ); | |
| 143 | + wp_register_script( 'chosen', PH()->plugin_url() . '/assets/js/chosen/chosen.jquery' . /*$suffix .*/ '.js', array('jquery'), PH_VERSION, true ); | |
| 90 | 144 | |
| 91 | - wp_register_script( 'flot', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), PH_VERSION ); | |
| 92 | - wp_register_script( 'flot-resize', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION ); | |
| 93 | - wp_register_script( 'flot-time', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION ); | |
| 145 | + wp_register_script( 'multiselect', PH()->plugin_url() . '/assets/js/multiselect/jquery.multiselect' . /*$suffix .*/ '.js', array('jquery'), '2.4.18', true ); | |
| 146 | + | |
| 147 | + wp_register_script( 'flot', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true ); | |
| 148 | + wp_register_script( 'flot-resize', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION, true ); | |
| 149 | + wp_register_script( 'flot-time', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION, true ); | |
| 94 | 150 | //wp_register_script( 'flot-pie', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION ); |
| 95 | 151 | //wp_register_script( 'flot-stack', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION ); |
| 96 | 152 | |
| 97 | 153 | wp_enqueue_script( 'propertyhive_admin' ); |
| 98 | 154 | |
| 155 | + $params = array(); | |
| 156 | + | |
| 157 | + // Add a bit better support for Gutenberg if enabled somehow (i.e. using Houzez) to load AJAX grids | |
| 158 | + if ( | |
| 159 | + isset($post->ID) && | |
| 160 | + function_exists( 'use_block_editor_for_post_type' ) && | |
| 161 | + use_block_editor_for_post_type( get_post_type($post->ID) ) && | |
| 162 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only classic/block editor selection controls the scripts loaded. | |
| 163 | + !isset( $_GET['classic-editor'] ) && | |
| 164 | + is_array($tabs) && | |
| 165 | + !empty($tabs) | |
| 166 | + ) | |
| 167 | + { | |
| 168 | + $ajax_actions = array(); | |
| 169 | + | |
| 170 | + foreach ( $tabs as $key => $tab ) | |
| 171 | + { | |
| 172 | + if ( isset($tab['ajax_actions']) && !empty($tab['ajax_actions']) ) | |
| 173 | + { | |
| 174 | + foreach ( $tab['ajax_actions'] as $ajax_action ) | |
| 175 | + { | |
| 176 | + $ajax_actions[] = $ajax_action; | |
| 177 | + } | |
| 178 | + } | |
| 179 | + } | |
| 180 | + | |
| 181 | + if ( !empty($ajax_actions) ) | |
| 182 | + { | |
| 183 | + $params = array( | |
| 184 | + 'ajax_actions' => $ajax_actions, | |
| 185 | + 'post_id' => $post->ID, | |
| 186 | + ); | |
| 187 | + | |
| 188 | + } | |
| 189 | + } | |
| 190 | + | |
| 191 | + wp_localize_script( 'propertyhive_admin', 'propertyhive_admin', $params ); | |
| 192 | + | |
| 193 | + $recently_viewed = get_user_meta( get_current_user_id(), '_propertyhive_recently_viewed', TRUE ); | |
| 194 | + if ( !is_array($recently_viewed) ) | |
| 195 | + { | |
| 196 | + $recently_viewed = array(); | |
| 197 | + } | |
| 198 | + | |
| 199 | + $params = array( | |
| 200 | + 'recently_viewed' => $recently_viewed, | |
| 201 | + ); | |
| 202 | + wp_localize_script( 'propertyhive_admin_recently_viewed', 'propertyhive_admin_recently_viewed', $params ); | |
| 203 | + | |
| 204 | + wp_localize_script( 'multiselect', 'propertyhive_multiselect_params', apply_filters( 'propertyhive_multiselect_params', array( | |
| 205 | + 'search' => false, | |
| 206 | + 'selected_text' => __( 'selected', 'propertyhive' ), | |
| 207 | + ) ) ); | |
| 208 | + | |
| 99 | 209 | // PropertyHive admin pages |
| 100 | 210 | if ( in_array( $screen->id, array( 'dashboard' ) ) ) |
| 101 | 211 | { |
| 102 | 212 | wp_enqueue_script( 'propertyhive_dashboard' ); |
| @@ -106,31 +216,170 @@ | ||
| 106 | 216 | ); |
| 107 | 217 | wp_localize_script( 'propertyhive_dashboard', 'propertyhive_dashboard', $params ); |
| 108 | 218 | } |
| 109 | 219 | |
| 220 | + if ( in_array( $screen->id, array( 'edit-contact', 'edit-enquiry', 'edit-appraisal', 'edit-viewing', 'edit-offer', 'edit-sale', 'edit-key_date' ) ) ) | |
| 221 | + { | |
| 222 | + wp_enqueue_script( 'moment' ); | |
| 223 | + wp_enqueue_script( 'daterangepicker.js', PH()->plugin_url() . '/assets/js/daterangepicker/daterangepicker.js', array( 'jquery', 'moment' ), '3.1.0', true ); | |
| 224 | + wp_enqueue_script( 'date_range_filter.js', PH()->plugin_url() . '/assets/js/admin/date_range_filter.js', array( 'jquery', 'moment', 'daterangepicker.js' ), PH_VERSION, true ); | |
| 225 | + } | |
| 226 | + | |
| 227 | + if ( in_array( $screen->id, array( 'edit-key_date' ) ) ) | |
| 228 | + { | |
| 229 | + wp_enqueue_script( 'inline-edit-key_date.js', PH()->plugin_url() . '/assets/js/admin/inline-edit-key_date.js', array('jquery'), PH_VERSION, true ); | |
| 230 | + } | |
| 231 | + | |
| 232 | + if ( | |
| 233 | + get_option('propertyhive_module_disabled_viewings', '') != 'yes' && | |
| 234 | + in_array( $screen->id, array( 'property', 'contact' ) ) | |
| 235 | + ) | |
| 236 | + { | |
| 237 | + wp_enqueue_script( 'propertyhive_fancybox', PH()->plugin_url() . '/assets/js/fancybox/jquery.fancybox.js', array('jquery'), '3.5.7', true ); | |
| 238 | + } | |
| 239 | + | |
| 240 | + if ( in_array( $screen->id, array( 'property' ) ) ) | |
| 241 | + { | |
| 242 | + if ( ! class_exists( '_WP_Editors', false ) ) | |
| 243 | + { | |
| 244 | + require( ABSPATH . WPINC . '/class-wp-editor.php' ); | |
| 245 | + } | |
| 246 | + add_action( 'admin_print_footer_scripts', array( '_WP_Editors', 'print_default_editor_scripts' ) ); | |
| 247 | + | |
| 248 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tour asset selection; no data is changed. | |
| 249 | + if ( isset( $_GET['tutorial'] ) && is_string( $_GET['tutorial'] ) && sanitize_text_field( wp_unslash( $_GET['tutorial'] ) ) === 'yes' ) | |
| 250 | + { | |
| 251 | + wp_enqueue_script( 'driver-js', PH()->plugin_url() . '/assets/js/tours/driver-js.js', array(), '1.0.1', true ); | |
| 252 | + wp_register_script( 'tour', PH()->plugin_url() . '/assets/js/tours/tour.js', array( 'driver-js' ), '1.0.1', true ); | |
| 253 | + wp_enqueue_script( 'tour' ); | |
| 254 | + | |
| 255 | + $tours = [ | |
| 256 | + 'add-property' => [ | |
| 257 | + [ | |
| 258 | + 'element' => '#title', | |
| 259 | + 'popover' => [ | |
| 260 | + 'title' => __( 'Enter the Property\'s Display Address', 'propertyhive' ), | |
| 261 | + 'description' => __( 'This is the title or address that will be shown publicly. Make it clear and appealing for your audience.', 'propertyhive' ), | |
| 262 | + 'side' => 'bottom', | |
| 263 | + ], | |
| 264 | + ], | |
| 265 | + [ | |
| 266 | + 'element' => '#propertyhive_metabox_tabs', | |
| 267 | + 'popover' => [ | |
| 268 | + 'title' => __( 'Explore the Property Record', 'propertyhive' ), | |
| 269 | + 'description' => __( 'The property record is organized into sections for easy navigation. Use these tabs to switch between sections.<br><br>Go ahead, try clicking them now.', 'propertyhive' ), | |
| 270 | + 'side' => 'bottom', | |
| 271 | + 'onPrevClick' => 'revert_to_first_tab', | |
| 272 | + 'onNextClick' => 'revert_to_first_tab', | |
| 273 | + ], | |
| 274 | + ], | |
| 275 | + [ | |
| 276 | + 'element' => '#propertyhive-property-address', | |
| 277 | + 'popover' => [ | |
| 278 | + 'title' => __( 'Enter the Property Details', 'propertyhive' ), | |
| 279 | + 'description' => __( 'Use these fields to input essential property information like address, price, bedrooms, and more. You can also upload images to showcase the property.', 'propertyhive' ), | |
| 280 | + 'side' => 'top', | |
| 281 | + 'onNextClick' => 'revert_to_third_tab', | |
| 282 | + ], | |
| 283 | + ], | |
| 284 | + [ | |
| 285 | + 'element' => '#\\_on_market', | |
| 286 | + 'popover' => [ | |
| 287 | + 'title' => __( 'Put it on the Market', 'propertyhive' ), | |
| 288 | + 'description' => __( 'For a property to show on your website it will need to be set to \'On Market\' under the \'Marketing\' tab.', 'propertyhive' ), | |
| 289 | + 'side' => 'top', | |
| 290 | + 'onPrevClick' => 'revert_to_first_tab', | |
| 291 | + 'onNextClick' => 'revert_to_first_tab', | |
| 292 | + ], | |
| 293 | + ], | |
| 294 | + [ | |
| 295 | + 'element' => '#submitdiv', | |
| 296 | + 'popover' => [ | |
| 297 | + 'title' => __( 'Publish your Property', 'propertyhive' ), | |
| 298 | + 'description' => __( 'When you\'re done and are ready to save your changes, simply click \'Publish\'', 'propertyhive' ), | |
| 299 | + 'side' => 'left', | |
| 300 | + 'onPrevClick' => 'revert_to_third_tab', | |
| 301 | + ], | |
| 302 | + ], | |
| 303 | + ], | |
| 304 | + ]; | |
| 305 | + wp_localize_script( | |
| 306 | + 'tour', | |
| 307 | + 'tour_plugin', | |
| 308 | + array( | |
| 309 | + 'tours' => $tours, | |
| 310 | + ) | |
| 311 | + ); | |
| 312 | + } | |
| 313 | + } | |
| 314 | + | |
| 110 | 315 | if ( in_array( $screen->id, ph_get_screen_ids() ) ) |
| 111 | 316 | { |
| 112 | 317 | wp_enqueue_script( 'ajax-chosen' ); |
| 113 | 318 | wp_enqueue_script( 'chosen' ); |
| 114 | 319 | wp_enqueue_script( 'jquery-ui-sortable' ); |
| 320 | + wp_enqueue_script( 'wp-tinymce' ); | |
| 115 | 321 | |
| 116 | - $api_key = get_option('propertyhive_google_maps_api_key'); | |
| 117 | - wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3'); | |
| 118 | - wp_enqueue_script('googlemaps'); | |
| 322 | + if ( get_option('propertyhive_maps_provider') == 'mapbox' ) | |
| 323 | + { | |
| 324 | + wp_register_script('mapbox', PH()->plugin_url() . '/assets/js/mapbox/mapbox-gl.js', false, '3.8.0', true ); | |
| 325 | + wp_enqueue_script('mapbox'); | |
| 119 | 326 | |
| 327 | + if ( get_option('propertyhive_geocoding_provider') == '' ) | |
| 328 | + { | |
| 329 | + $api_key = get_option('propertyhive_google_maps_geocoding_api_key'); | |
| 330 | + wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3', true ); | |
| 331 | + wp_enqueue_script('googlemaps'); | |
| 332 | + } | |
| 333 | + } | |
| 334 | + elseif ( get_option('propertyhive_maps_provider') == 'osm' ) | |
| 335 | + { | |
| 336 | + wp_register_style('leaflet', PH()->plugin_url() . '/assets/js/leaflet/leaflet.css', array(), '1.9.4'); | |
| 337 | + wp_enqueue_style('leaflet'); | |
| 338 | + | |
| 339 | + wp_register_script('leaflet', PH()->plugin_url() . '/assets/js/leaflet/leaflet.js', array(), '1.9.4', false); | |
| 340 | + wp_enqueue_script('leaflet'); | |
| 341 | + | |
| 342 | + if ( get_option('propertyhive_geocoding_provider') == '' ) | |
| 343 | + { | |
| 344 | + $api_key = get_option('propertyhive_google_maps_geocoding_api_key'); | |
| 345 | + wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3', true ); | |
| 346 | + wp_enqueue_script('googlemaps'); | |
| 347 | + } | |
| 348 | + } | |
| 349 | + else | |
| 350 | + { | |
| 351 | + $api_key = get_option('propertyhive_google_maps_api_key'); | |
| 352 | + wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3', true ); | |
| 353 | + wp_enqueue_script('googlemaps'); | |
| 354 | + } | |
| 355 | + | |
| 120 | 356 | wp_enqueue_media(); |
| 121 | 357 | wp_enqueue_script( 'propertyhive_admin_meta_boxes' ); |
| 358 | + wp_enqueue_script( 'propertyhive_admin_recently_viewed' ); | |
| 122 | 359 | wp_enqueue_script( 'jquery-ui-datepicker' ); |
| 123 | 360 | wp_enqueue_script( 'jquery-ui-autocomplete' ); |
| 124 | 361 | wp_enqueue_script( 'ajax-chosen' ); |
| 125 | 362 | wp_enqueue_script( 'chosen' ); |
| 126 | - | |
| 363 | + | |
| 127 | 364 | $params = array( |
| 128 | 365 | 'plugin_url' => PH()->plugin_url(), |
| 129 | 366 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 130 | 367 | 'post_id' => isset( $post->ID ) ? $post->ID : '', |
| 368 | + 'get_notes_nonce' => wp_create_nonce("get-notes"), | |
| 369 | + 'pin_note_nonce' => wp_create_nonce("pin-note"), | |
| 131 | 370 | 'add_note_nonce' => wp_create_nonce("add-note"), |
| 132 | 371 | 'delete_note_nonce' => wp_create_nonce("delete-note"), |
| 372 | + 'add_key_date_nonce' => wp_create_nonce( 'propertyhive-add-key-date' ), | |
| 373 | + 'export_sub_grid_nonce' => wp_create_nonce( 'propertyhive-export-sub-grid' ), | |
| 374 | + 'viewing_details_meta_nonce' => wp_create_nonce( 'viewing-details-meta-box' ), | |
| 375 | + 'viewing_actions_nonce' => wp_create_nonce( 'viewing-actions' ), | |
| 376 | + 'save_key_date_nonce' => wp_create_nonce( 'save-key-date' ), | |
| 377 | + 'delete_key_date_nonce' => wp_create_nonce( 'delete-key-date' ), | |
| 378 | + 'check_duplicate_reference_number_nonce' => wp_create_nonce("check-duplicate-reference-number"), | |
| 379 | + 'enable_description_editor' => apply_filters('propertyhive_enable_description_editor', false), | |
| 380 | + 'leasehold_tenures' => apply_filters('propertyhive_leasehold_tenure_names', array( 'leasehold', 'share of freehold' ) ), | |
| 381 | + 'disable_notes_mention' => apply_filters('propertyhive_disable_notes_mention', false), | |
| 133 | 382 | ); |
| 134 | 383 | wp_localize_script( 'propertyhive_admin_meta_boxes', 'propertyhive_admin_meta_boxes', $params ); |
| 135 | 384 | |
| 136 | 385 | if ( is_rtl() ) |
| @@ -137,8 +386,13 @@ | ||
| 137 | 386 | { |
| 138 | 387 | wp_enqueue_script( 'chosen-rtl', PH()->plugin_url() . '/assets/js/chosen/chosen-rtl' . /*$suffix .*/ '.js', array( 'jquery' ), PH_VERSION, true ); |
| 139 | 388 | } |
| 140 | 389 | } |
| 390 | + | |
| 391 | + if ( in_array( $screen->id, array('profile', 'user', 'user-edit') ) ) | |
| 392 | + { | |
| 393 | + wp_enqueue_media(); | |
| 394 | + } | |
| 141 | 395 | |
| 142 | 396 | if ( strpos($screen->id, 'page_ph-settings') !== FALSE ) |
| 143 | 397 | { |
| 144 | 398 | wp_enqueue_script( 'propertyhive_admin_settings' ); |
| @@ -149,10 +403,22 @@ | ||
| 149 | 403 | 'primary_department_not_active_warning' => __( 'The chosen primary department has not been selected as active', 'propertyhive' ), |
| 150 | 404 | 'no_countries_selected' => __( 'Please select which countries you operate in', 'propertyhive' ), |
| 151 | 405 | 'default_country_not_in_selected' => __( 'The default country hasn\'t been selected as a country you operate in', 'propertyhive' ), |
| 152 | 406 | 'admin_url' => admin_url(), |
| 153 | - 'taxonomy_section' => ( ( isset($_GET['section']) ) ? sanitize_text_field($_GET['section']) : '' ), | |
| 407 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only settings section passed through WordPress script localization. | |
| 408 | + 'taxonomy_section' => isset( $_GET['section'] ) && is_string( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : '', | |
| 409 | + 'ajax_nonce' => wp_create_nonce("updates"), | |
| 410 | + 'features_settings_url' => admin_url('admin.php?page=ph-settings&tab=features'), | |
| 154 | 411 | ); |
| 412 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Settings tab determines whether the existing license status is refreshed. | |
| 413 | + if ( isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) && sanitize_text_field( wp_unslash( $_GET['tab'] ) ) === 'licensekey' ) | |
| 414 | + { | |
| 415 | + $params['valid_pro_license_key'] = PH()->license->is_valid_pro_license_key(true); | |
| 416 | + } | |
| 417 | + else | |
| 418 | + { | |
| 419 | + $params['valid_pro_license_key'] = PH()->license->is_valid_pro_license_key(); | |
| 420 | + } | |
| 155 | 421 | wp_localize_script( 'propertyhive_admin_settings', 'propertyhive_admin_settings', $params ); |
| 156 | 422 | } |
| 157 | 423 | |
| 158 | 424 | // Reports Pages |
| @@ -166,8 +432,45 @@ | ||
| 166 | 432 | wp_enqueue_script( 'flot-time' ); |
| 167 | 433 | //wp_enqueue_script( 'flot-pie' ); |
| 168 | 434 | //wp_enqueue_script( 'flot-stack' ); |
| 169 | 435 | } |
| 436 | + | |
| 437 | + if ( $screen->id === 'plugins' ) | |
| 438 | + { | |
| 439 | + // Enqueue the JavaScript file | |
| 440 | + wp_enqueue_script( | |
| 441 | + 'propertyhive_deactivate_survey', | |
| 442 | + PH()->plugin_url() . '/assets/js/deactivate-survey.js', | |
| 443 | + array('jquery'), // Depend on jQuery | |
| 444 | + '1.0.0', | |
| 445 | + true // Load in footer | |
| 446 | + ); | |
| 447 | + | |
| 448 | + wp_localize_script('propertyhive_deactivate_survey', 'deactivation_survey', array( | |
| 449 | + 'nonce' => wp_create_nonce('deactivate-survey'), | |
| 450 | + | |
| 451 | + 'modalTitle' => __('If you have a moment, please let us know why you are deactivating:', 'propertyhive'), | |
| 452 | + 'modalHeader' => __('Quick Feedback', 'propertyhive'), | |
| 453 | + 'skipDeactivate' => __('Skip & Deactivate', 'propertyhive'), | |
| 454 | + 'cancel' => __('Cancel', 'propertyhive'), | |
| 455 | + 'deactivate' => __('Submit & Deactivate', 'propertyhive'), | |
| 456 | + | |
| 457 | + 'brokeSite' => __('The plugin broke my site', 'propertyhive'), | |
| 458 | + 'confusing' => __('The plugin is confusing', 'propertyhive'), | |
| 459 | + 'inadequateSupport' => __('The support/documentation is inadequate', 'propertyhive'), | |
| 460 | + 'poorPerformance' => __('The plugin is too slow/affects performance', 'propertyhive'), | |
| 461 | + 'notNeeded' => __('I no longer need the plugin', 'propertyhive'), | |
| 462 | + 'betterPlugin' => __('I found a better plugin', 'propertyhive'), | |
| 463 | + 'temporary' => __('It\'s a temporary deactivation', 'propertyhive'), | |
| 464 | + 'other' => __('Other', 'propertyhive'), | |
| 465 | + | |
| 466 | + 'brokeSiteLabel' => __('Oh no! Can you tell us more? (optional)', 'propertyhive'), | |
| 467 | + 'betterPluginLabel' => __('What\'s the plugin\'s name? (optional)', 'propertyhive'), | |
| 468 | + 'otherLabel' => __('Additional feedback or comments: (optional)', 'propertyhive'), | |
| 469 | + | |
| 470 | + 'anonymous' => __('Anonymous feedback', 'propertyhive'), | |
| 471 | + )); | |
| 472 | + } | |
| 170 | 473 | } |
| 171 | 474 | |
| 172 | 475 | } |
| 173 | 476 | |
| @@ -172,5 +475,5 @@ | ||
| 172 | 475 | } |
| 173 | 476 | |
| 174 | 477 | endif; |
| 175 | 478 | |
| 176 | -return new PH_Admin_Assets(); | |
| 479 | +return new PH_Admin_Assets(); | |