@@ -17,7 +17,7 @@ function __construct() {
1717 $ enqueue_font_awesome = $ this ->get_plugin_option ( 'enqueue_font_awesome ' );
1818 if ( $ enqueue_font_awesome ) {
1919 if ( in_array ( 'frontend ' , $ enqueue_font_awesome ) )
20- add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'enqueue_font_awesome ' ) );
20+ add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'enqueue_font_awesome ' ) );
2121 if ( in_array ( 'backend ' , $ enqueue_font_awesome ) )
2222 add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'enqueue_font_awesome ' ) );
2323 }
@@ -34,10 +34,10 @@ public function enqueue_frontend_scripts() {
3434 $ this ->enqueue_bower_scripts ();
3535
3636 // Enqueuing custom CSS for child theme (Twentysixteen was used for testing)
37- wp_enqueue_style ( 'wordpress-base-plugin ' , $ this -> get_script_url ('assets/css/wordpress-base-plugin.css ' ), null , $ this -> get_script_version ('assets/css/wordpress-base-plugin.css ' ) );
37+ wp_enqueue_style ( 'wordpress-base-plugin ' , Helpers:: get_script_url ( 'assets/css/wordpress-base-plugin.css ' ), null , Helpers:: get_script_version ( 'assets/css/wordpress-base-plugin.css ' ) );
3838
3939 // Enqueue frontend JavaScript
40- wp_enqueue_script ( 'wordpress-base-plugin ' , $ this -> get_script_url ('assets/js/wordpress-base-plugin.js ' ), array ('jquery ' , 'jquery-waituntilexists ' ), $ this -> get_script_version ('assets/js/wordpress-base-plugin.js ' ), true );
40+ wp_enqueue_script ( 'wordpress-base-plugin ' , Helpers:: get_script_url ( 'assets/js/wordpress-base-plugin.js ' ), array ( 'jquery ' , 'jquery-waituntilexists ' ), Helpers:: get_script_version ( 'assets/js/wordpress-base-plugin.js ' ), true );
4141 wp_localize_script ( 'wordpress-base-plugin ' , 'wpbp_ajax_filter_params ' , array ( 'ajax_url ' => admin_url ( 'admin-ajax.php ' ) ) );
4242
4343 }
@@ -52,10 +52,10 @@ public function enqueue_admin_scripts() {
5252 $ this ->enqueue_bower_scripts ();
5353
5454 // Enqueuing custom CSS for child theme (Twentysixteen was used for testing)
55- wp_enqueue_style ( 'wordpress-base-plugin ' , $ this -> get_script_url ('assets/css/wordpress-base-plugin-admin.css ' ), null , $ this -> get_script_version ('assets/css/wordpress-base-plugin-admin.css ' ) );
55+ wp_enqueue_style ( 'wordpress-base-plugin ' , Helpers:: get_script_url ( 'assets/css/wordpress-base-plugin-admin.css ' ), null , Helpers:: get_script_version ( 'assets/css/wordpress-base-plugin-admin.css ' ) );
5656
5757 // Enqueue WP Admin JavaScript
58- wp_enqueue_script ( 'wordpress-base-plugin-admin ' , $ this -> get_script_url ('assets/js/wordpress-base-plugin-admin.js ' ), array ('jquery ' , 'jquery-waituntilexists ' ), $ this -> get_script_version ('assets/js/wordpress-base-plugin-admin.js ' ), true );
58+ wp_enqueue_script ( 'wordpress-base-plugin-admin ' , Helpers:: get_script_url ( 'assets/js/wordpress-base-plugin-admin.js ' ), array ('jquery ' , 'jquery-waituntilexists ' ), Helpers:: get_script_version ( 'assets/js/wordpress-base-plugin-admin.js ' ), true );
5959 wp_localize_script ( 'wordpress-base-plugin-admin ' , 'wpbp_ajax_filter_params ' , array ( 'ajax_url ' => admin_url ( 'admin-ajax.php ' ) ) );
6060
6161 }
@@ -67,7 +67,7 @@ public function enqueue_admin_scripts() {
6767 private function enqueue_bower_scripts () {
6868
6969 // Enqueue common (frontend/backend) JavaScript
70- wp_enqueue_script ( 'jquery-waituntilexists ' , $ this -> get_script_url ('assets/components/jq.waituntilexists/jquery.waitUntilExists.min.js ' , false ), array ('jquery ' ), '0.1.0 ' );
70+ wp_enqueue_script ( 'jquery-waituntilexists ' , Helpers:: get_script_url ( 'assets/components/jq.waituntilexists/jquery.waitUntilExists.min.js ' , false ), array ( 'jquery ' ), '0.1.0 ' );
7171
7272 }
7373
@@ -98,70 +98,4 @@ public function inject_javascript_settings() {
9898
9999 }
100100
101- /**
102- * Returns script ?ver= version based on environment (WP_ENV)
103- *
104- * If WP_ENV is not defined or equals anything other than 'development' or 'staging'
105- * returns $script_version (if defined) else plugin verson. If WP_ENV is defined
106- * as 'development' or 'staging', returns string representing file last modification
107- * date (to discourage browser during development).
108- *
109- * @param string $script The filesystem path (relative to the script location of
110- * calling script) to return the version for.
111- * @param string $script_version (optional) The version that will be returned if
112- * WP_ENV is defined as anything other than 'development' or 'staging'.
113- *
114- * @return string
115- * @since 0.1.0
116- */
117- public function get_script_version ($ script , $ return_minified = false , $ script_version = null ) {
118- $ version = $ script_version ?: self ::$ config ->get ( 'plugin/meta/Version ' );
119- if ($ this ->is_production ()) return $ version ;
120-
121- $ script = $ this ->get_script_path ($ script , $ return_minified );
122- if (file_exists ($ script )) {
123- $ version = date ("ymd-Gis " , filemtime ( $ script ) );
124- }
125-
126- return $ version ;
127- }
128-
129- /**
130- * Returns script path or URL, either regular or minified (if exists).
131- *
132- * If in production mode or if @param $force_minify == true, inserts '.min' to the filename
133- * (if exists), else return script name without (example: style.css vs style.min.css).
134- *
135- * @param string $script The relative (to the plugin folder) path to the script.
136- * @param bool $return_minified If true and is_production() === true then will prefix the
137- * extension with .min. NB! Due to performance reasons, I did not include logic to check
138- * to see if the script_name.min.ext exists, so use only when you know it exists.
139- * @param bool $return_url If true, returns full-qualified URL rather than filesystem path.
140- *
141- * @return string The URL or path to minified or regular $script.
142- * @since 0.1.0
143- */
144- public function get_script_path ($ script , $ return_minified = true , $ return_url = false ) {
145- $ script = trim ($ script , '/ ' );
146- if ($ return_minified && strpos ($ script , '. ' ) && $ this ->is_production ()) {
147- $ script_parts = explode ('. ' , $ script );
148- $ script_extension = end ($ script_parts );
149- array_pop ($ script_parts );
150- $ script = implode ('. ' , $ script_parts ) . '.min. ' . $ script_extension ;
151- }
152-
153- return self ::$ config ->get ( $ return_url ? 'plugin/url ' : 'plugin/path ' ) . $ script ;
154- }
155-
156- /**
157- * Returns absolute URL of $script.
158- *
159- * @param string $script The relative (to the plugin folder) path to the script.
160- * @param bool
161- * @since 0.1.0
162- */
163- public function get_script_url ($ script , $ return_minified = false ) {
164- return $ this ->get_script_path ($ script , $ return_minified , true );
165- }
166-
167101}
0 commit comments