PluginProbe
Property Hive / 1.4.5
Property Hive v1.4.5
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / class-ph-frontend-scripts.php

class-ph-frontend-scripts.php in Property Hive 1.4.5, at includes/class-ph-frontend-scripts.php

149 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 /**
8 * Handle frontend forms
9 *
10 * @class PH_Frontend_Scripts
11 * @version 1.0.0
12 * @package PropertyHive/Classes/
13 * @category Class
14 * @author PropertyHive
15 */
16 class PH_Frontend_Scripts {
17
18 /**
19 * Hook in methods
20 */
21 public static function init() {
22 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) );
23 add_action( 'wp_print_scripts', array( __CLASS__, 'check_jquery' ), 25 );
24 add_action( 'wp_print_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
25 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
26 }
27
28 /**
29 * Get styles for the frontend
30 * @return array
31 */
32 public static function get_styles() {
33 return apply_filters( 'propertyhive_enqueue_styles', array(
34 /*'propertyhive-layout' => array(
35 'src' => str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/css/propertyhive-layout.css',
36 'deps' => '',
37 'version' => PH_VERSION,
38 'media' => 'all'
39 ),
40 'propertyhive-smallscreen' => array(
41 'src' => str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/css/propertyhive-smallscreen.css',
42 'deps' => 'propertyhive-layout',
43 'version' => PH_VERSION,
44 'media' => 'only screen and (max-width: ' . apply_filters( 'propertyhive_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')'
45 ),*/
46 'propertyhive-general' => array(
47 'src' => str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/css/propertyhive.css',
48 'deps' => '',
49 'version' => PH_VERSION,
50 'media' => 'all'
51 ),
52 ) );
53 }
54
55 /**
56 * Register/queue frontend scripts.
57 *
58 * @access public
59 * @return void
60 */
61 public static function load_scripts() {
62 global $post;
63
64 //$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
65 $suffix = '';
66 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
67 $frontend_script_path = $assets_path . 'js/frontend/';
68
69 // Register any scripts for later use, or used as dependencies
70 wp_register_script( 'jquery-cookie', $assets_path . 'js/jquery-cookie/jquery.cookie' . $suffix . '.js', array( 'jquery' ), '1.3.1', true );
71
72 if ( is_property() ) {
73 wp_enqueue_script( 'prettyPhoto', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array( 'jquery' ), '3.1.5', true );
74 wp_enqueue_script( 'prettyPhoto-init', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array( 'jquery','prettyPhoto' ), PH_VERSION, true );
75 wp_enqueue_style( 'propertyhive_prettyPhoto_css', $assets_path . 'css/prettyPhoto.css' );
76
77 wp_enqueue_script( 'flexslider', $assets_path . 'js/flexslider/jquery.flexslider' . $suffix . '.js', array( 'jquery' ), '2.2.2', true );
78 wp_enqueue_script( 'flexslider-init', $assets_path . 'js/flexslider/jquery.flexslider.init' . $suffix . '.js', array( 'jquery','flexslider' ), PH_VERSION, true );
79 wp_enqueue_style( 'flexslider_css', $assets_path . 'css/flexslider.css' );
80
81 wp_enqueue_script( 'propertyhive_actions', $frontend_script_path . 'actions' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true );
82
83 wp_enqueue_script( 'ph-single-property' );
84 }
85
86 // Global frontend scripts
87 wp_enqueue_script( 'propertyhive_search', $frontend_script_path . 'search' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true );
88 wp_enqueue_script( 'propertyhive_make_enquiry', $frontend_script_path . 'make-enquiry' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true );
89 //wp_enqueue_script( 'propertyhive', $frontend_script_path . 'propertyhive' . $suffix . '.js', array( 'jquery' ), PH_VERSION, true );
90
91 // CSS Styles
92 $enqueue_styles = self::get_styles();
93
94 if ( $enqueue_styles ) {
95 foreach ( $enqueue_styles as $handle => $args ) {
96 wp_enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'] );
97 }
98 }
99 }
100
101 /**
102 * Localize scripts only when enqueued
103 */
104 public static function localize_printed_scripts() {
105 global $wp;
106
107 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
108
109 if ( wp_script_is( 'propertyhive_make_enquiry' ) ) {
110 wp_localize_script( 'propertyhive_make_enquiry', 'propertyhive_make_property_enquiry_params', apply_filters( 'propertyhive_make_property_enquiry_params', array(
111 'ajax_url' => PH()->ajax_url()
112 ) ) );
113 }
114
115 if ( wp_script_is( 'propertyhive_account' ) ) {
116 wp_localize_script( 'propertyhive_account', 'propertyhive_account_params', apply_filters( 'propertyhive_account_params', array(
117 'ajax_url' => PH()->ajax_url(),
118 'my_account_url' => get_permalink( ph_get_page_id('my_account') ),
119 'login_nonce' => wp_create_nonce( "ph_login" ),
120 'register_nonce' => wp_create_nonce( "ph_register" ),
121 'details_nonce' => wp_create_nonce( "ph_details" ),
122 'requirements_nonce' => wp_create_nonce( "ph_requirements" ),
123 ) ) );
124 }
125 }
126
127 /**
128 * PH requires jQuery 1.8 since it uses functions like .on() for events and .parseHTML.
129 * If, by the time wp_print_scrips is called, jQuery is outdated (i.e not
130 * using the version in core) we need to deregister it and register the
131 * core version of the file.
132 *
133 * @access public
134 * @return void
135 */
136 public static function check_jquery() {
137 global $wp_scripts;
138
139 // Enforce minimum version of jQuery
140 if ( ! empty( $wp_scripts->registered['jquery']->ver ) && ! empty( $wp_scripts->registered['jquery']->src ) && 0 >= version_compare( $wp_scripts->registered['jquery']->ver, '1.8' ) ) {
141 wp_deregister_script( 'jquery' );
142 wp_register_script( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.8' );
143 wp_enqueue_script( 'jquery' );
144 }
145 }
146 }
147
148 PH_Frontend_Scripts::init();
149