Version Description
- Update Github Action to publish from github to WP.org.
Download this release
Release Info
Developer | joshuadnelson |
Plugin | Scripts To Footer |
Version | 0.6.4.1 |
Comparing to | |
See all releases |
Code changes from version 0.6.3 to 0.6.4.1
- CHANGELOG.md +9 -1
- admin/admin-settings.php +1 -1
- readme.txt +15 -3
- scripts-to-footer.php +117 -63
- uninstall.php +1 -1
CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1 |
### Changelog
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
##### 0.6.3 - 9-12-18
|
4 |
Moved the 'set_header_scripts' function into a 'wp_head' add_action to allow for conditional checks to work within the 'stf_exclude_scripts' filter.
|
5 |
|
@@ -16,7 +24,7 @@ Updates custom taxonomy check for custom taxonomy archives and some error loggin
|
|
16 |
- Add this changelog as a separate file.
|
17 |
- Change the custom post type filter. Refer to updated [FAQ](https://github.com/joshuadavidnelson/scripts-to-footer/#faq) and [documentation](https://github.com/joshuadavidnelson/scripts-to-footer/wiki).
|
18 |
- Add support for custom taxonomy archives.
|
19 |
-
- Change the exclude filter, to be more relevant to the new options. Older filter is
|
20 |
- Update the post meta for disabling the plugin on specific posts/pages.
|
21 |
- Add Github Updater support.
|
22 |
- Removed CMB and built metaboxes the old fashion way.
|
1 |
### Changelog
|
2 |
|
3 |
+
##### 0.6.4.1 - 4-14-20
|
4 |
+
- Update Github Action to publish from github to WP.org.
|
5 |
+
|
6 |
+
##### 0.6.4 - 4-14-20
|
7 |
+
- Removed unnecessary logging functions and added a debug check before logging anything.
|
8 |
+
- Tidy up code spacing and inline-documentation.
|
9 |
+
- Added `STF_DEBUG` for use in error logging function with `WP_DEBUG`, both must be `true` before error logging is output to the debug.log file.
|
10 |
+
|
11 |
##### 0.6.3 - 9-12-18
|
12 |
Moved the 'set_header_scripts' function into a 'wp_head' add_action to allow for conditional checks to work within the 'stf_exclude_scripts' filter.
|
13 |
|
24 |
- Add this changelog as a separate file.
|
25 |
- Change the custom post type filter. Refer to updated [FAQ](https://github.com/joshuadavidnelson/scripts-to-footer/#faq) and [documentation](https://github.com/joshuadavidnelson/scripts-to-footer/wiki).
|
26 |
- Add support for custom taxonomy archives.
|
27 |
+
- Change the exclude filter, to be more relevant to the new options. Older filter is deprecated, but still supported for backwards compatibility.
|
28 |
- Update the post meta for disabling the plugin on specific posts/pages.
|
29 |
- Add Github Updater support.
|
30 |
- Removed CMB and built metaboxes the old fashion way.
|
admin/admin-settings.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* @package Scripts_To_Footer
|
6 |
* @subpackage Scripts_To_Footer_Settings
|
7 |
* @author Joshua David Nelson <josh@joshuadnelson.com>
|
8 |
-
* @copyright Copyright (c)
|
9 |
* @license http://www.opensource.org/licenses/gpl-license.php GPL-2.0+
|
10 |
* @link http://joshuadnelson.com/scripts-to-footer-plugin
|
11 |
**/
|
5 |
* @package Scripts_To_Footer
|
6 |
* @subpackage Scripts_To_Footer_Settings
|
7 |
* @author Joshua David Nelson <josh@joshuadnelson.com>
|
8 |
+
* @copyright Copyright (c) 2020, Joshua David Nelson
|
9 |
* @license http://www.opensource.org/licenses/gpl-license.php GPL-2.0+
|
10 |
* @link http://joshuadnelson.com/scripts-to-footer-plugin
|
11 |
**/
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: joshuadnelson
|
|
3 |
Tags: javascript, footer, speed, head, performance
|
4 |
Donate link: http://jdn.im/donate
|
5 |
Requires at least: 3.1.0
|
6 |
-
Tested up to: 4
|
7 |
-
Stable tag: 0.6.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -111,6 +111,14 @@ Please feel free to open a [Github Issue](https://github.com/joshuadavidnelson/s
|
|
111 |
|
112 |
== Changelog ==
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
= 0.6.3 =
|
115 |
Moved the 'set_header_scripts' function into a 'wp_head' add_action to allow for conditional checks to work within the 'stf_exclude_scripts' filter.
|
116 |
|
@@ -128,7 +136,7 @@ Large number of improvements:
|
|
128 |
- Add a changelog as a separate file.
|
129 |
- Change the custom post type filter. Refer to updated [FAQ](https://github.com/joshuadavidnelson/scripts-to-footer/#faq) and [documentation](https://github.com/joshuadavidnelson/scripts-to-footer/wiki).
|
130 |
- Add support for custom taxonomy archives.
|
131 |
-
- Change the exclude filter, to be more relevant to the new options. Older filter is
|
132 |
- Update the post meta for disabling the plugin on specific posts/pages.
|
133 |
- Add Github Updater support.
|
134 |
- Removed CMB and built metaboxes the old fashion way.
|
@@ -151,6 +159,10 @@ Initial release
|
|
151 |
|
152 |
== Upgrade Notice ==
|
153 |
|
|
|
|
|
|
|
|
|
154 |
= 0.6.3 =
|
155 |
Moved the 'set_header_scripts' function into a 'wp_head' add_action to allow for conditional checks to work within the 'stf_exclude_scripts' filter.
|
156 |
|
3 |
Tags: javascript, footer, speed, head, performance
|
4 |
Donate link: http://jdn.im/donate
|
5 |
Requires at least: 3.1.0
|
6 |
+
Tested up to: 5.4
|
7 |
+
Stable tag: 0.6.4.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
111 |
|
112 |
== Changelog ==
|
113 |
|
114 |
+
= 0.6.4.1 =
|
115 |
+
- Update Github Action to publish from github to WP.org.
|
116 |
+
|
117 |
+
= 0.6.4 =
|
118 |
+
- Removed unnecessary logging functions and added a debug check before logging anything.
|
119 |
+
- Tidy up code spacing and inline-documentation.
|
120 |
+
- Added `STF_DEBUG` for use in error logging function with `WP_DEBUG`, both must be `true` before error logging is output to the debug.log file.
|
121 |
+
|
122 |
= 0.6.3 =
|
123 |
Moved the 'set_header_scripts' function into a 'wp_head' add_action to allow for conditional checks to work within the 'stf_exclude_scripts' filter.
|
124 |
|
136 |
- Add a changelog as a separate file.
|
137 |
- Change the custom post type filter. Refer to updated [FAQ](https://github.com/joshuadavidnelson/scripts-to-footer/#faq) and [documentation](https://github.com/joshuadavidnelson/scripts-to-footer/wiki).
|
138 |
- Add support for custom taxonomy archives.
|
139 |
+
- Change the exclude filter, to be more relevant to the new options. Older filter is deprecated, but still supported for backwards compatibility.
|
140 |
- Update the post meta for disabling the plugin on specific posts/pages.
|
141 |
- Add Github Updater support.
|
142 |
- Removed CMB and built metaboxes the old fashion way.
|
159 |
|
160 |
== Upgrade Notice ==
|
161 |
|
162 |
+
= 0.6.4 =
|
163 |
+
- Removed unnecessary logging functions and added a debug check before logging anything.
|
164 |
+
- Tidy up code spacing and inline-documentation.
|
165 |
+
|
166 |
= 0.6.3 =
|
167 |
Moved the 'set_header_scripts' function into a 'wp_head' add_action to allow for conditional checks to work within the 'stf_exclude_scripts' filter.
|
168 |
|
scripts-to-footer.php
CHANGED
@@ -4,14 +4,14 @@
|
|
4 |
*
|
5 |
* @package Scripts_To_Footer
|
6 |
* @author Joshua David Nelson <josh@joshuadnelson.com>
|
7 |
-
* @copyright Copyright (c)
|
8 |
* @license http://www.opensource.org/licenses/gpl-license.php GPL-2.0+
|
9 |
* @link http://joshuadnelson.com/scripts-to-footer-plugin
|
10 |
*
|
11 |
* Plugin Name: Scripts-To-Footer
|
12 |
* Plugin URI: http://wordpress.org/plugins/scripts-to-footerphp/
|
13 |
* Description: Moves scripts to the footer to decrease page load times, while keeping stylesheets in the header. Requires that plugins and theme correctly utilizes wp_enqueue_scripts hook. Can be disabled via a checkbox on specific pages and posts.
|
14 |
-
* Version: 0.6.
|
15 |
* Author: Joshua David Nelson
|
16 |
* Author URI: http://joshuadnelson.com
|
17 |
* License: GPL2
|
@@ -22,9 +22,7 @@
|
|
22 |
|
23 |
/**
|
24 |
* Prevent direct access to this file.
|
25 |
-
|
26 |
-
* @since 0.2
|
27 |
-
**/
|
28 |
if( !defined( 'ABSPATH' ) ) {
|
29 |
exit( 'You are not allowed to access this file directly.' );
|
30 |
}
|
@@ -32,38 +30,43 @@ if( !defined( 'ABSPATH' ) ) {
|
|
32 |
/**
|
33 |
* Define our plugin variables
|
34 |
*
|
35 |
-
* @since 0.2
|
36 |
**/
|
37 |
// Plugin Settings Field
|
38 |
-
if( !defined( 'STF_SETTINGS_FIELD' ) )
|
39 |
define( 'STF_SETTINGS_FIELD', 'scripts-to-footer' );
|
40 |
|
41 |
// Plugin Domain
|
42 |
-
if( !defined( 'STF_DOMAIN' ) )
|
43 |
define( 'STF_DOMAIN', 'stf' );
|
44 |
|
45 |
// Plugin Verison
|
46 |
if( !defined( 'STF_VERSION' ) )
|
47 |
-
define( 'STF_VERSION', '0.6.
|
48 |
|
49 |
// Plugin name
|
50 |
-
if( !defined( 'STF_NAME' ) )
|
51 |
define( 'STF_NAME', trim( dirname( plugin_basename( __FILE__ ) ), '/' ) );
|
52 |
|
53 |
// Plugin Directory
|
54 |
-
if( !defined( 'STF_DIR' ) )
|
55 |
-
define( 'STF_DIR', WP_PLUGIN_DIR . '/' .
|
56 |
|
57 |
// Plugin URL
|
58 |
-
if( !defined( 'STF_URL' ) )
|
59 |
-
define( 'STF_URL', WP_PLUGIN_URL . '/' .
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
/**
|
62 |
* Scripts to Footer Class.
|
63 |
*
|
64 |
* Forces scripts to the footer, unless excluded in the settings page.
|
65 |
*
|
66 |
-
* @since 0.2
|
67 |
*/
|
68 |
global $stf_scripts_to_footer;
|
69 |
$stf_scripts_to_footer = new Scripts_To_Footer();
|
@@ -84,9 +87,10 @@ class Scripts_To_Footer {
|
|
84 |
*
|
85 |
* Registers our activation hook and init hook.
|
86 |
*
|
87 |
-
* @since 0.2
|
88 |
*/
|
89 |
function __construct() {
|
|
|
90 |
add_action( 'admin_init', array( $this, 'check_version' ) );
|
91 |
|
92 |
// Don't run anything else in the plugin, if we're on an incompatible
|
@@ -98,7 +102,8 @@ class Scripts_To_Footer {
|
|
98 |
include_once( STF_DIR . '/admin/admin-settings.php' );
|
99 |
|
100 |
// Make it so
|
101 |
-
|
|
|
102 |
}
|
103 |
|
104 |
/**
|
@@ -111,6 +116,7 @@ class Scripts_To_Footer {
|
|
111 |
* @since 0.6.0
|
112 |
*/
|
113 |
static function activation_check() {
|
|
|
114 |
if ( ! self::compatible_version() ) {
|
115 |
deactivate_plugins( plugin_basename( __FILE__ ) );
|
116 |
wp_die( __( 'Scripts-to-Footer requires WordPress 3.1.0 or higher', 'stf' ) );
|
@@ -127,7 +133,8 @@ class Scripts_To_Footer {
|
|
127 |
|
128 |
// Save current version
|
129 |
update_option( 'stf_version', STF_VERSION );
|
130 |
-
|
|
|
131 |
}
|
132 |
|
133 |
/**
|
@@ -139,6 +146,7 @@ class Scripts_To_Footer {
|
|
139 |
* @since 0.6.0
|
140 |
*/
|
141 |
function check_version() {
|
|
|
142 |
if ( ! self::compatible_version() ) {
|
143 |
if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
|
144 |
deactivate_plugins( plugin_basename( __FILE__ ) );
|
@@ -147,18 +155,19 @@ class Scripts_To_Footer {
|
|
147 |
unset( $_GET['activate'] );
|
148 |
}
|
149 |
}
|
150 |
-
|
|
|
151 |
}
|
152 |
|
153 |
/**
|
154 |
* Display notice on deactivation.
|
155 |
*
|
156 |
* @since 0.6.0
|
157 |
-
*
|
158 |
-
* @return void
|
159 |
*/
|
160 |
function disabled_notice() {
|
161 |
-
|
|
|
|
|
162 |
}
|
163 |
|
164 |
/**
|
@@ -169,13 +178,15 @@ class Scripts_To_Footer {
|
|
169 |
* @return boolean
|
170 |
*/
|
171 |
static function compatible_version() {
|
|
|
172 |
if ( version_compare( $GLOBALS['wp_version'], '3.1.0', '<' ) ) {
|
173 |
return false;
|
174 |
}
|
175 |
|
176 |
// Add sanity checks for other version requirements here
|
177 |
|
178 |
-
|
|
|
179 |
}
|
180 |
|
181 |
/**
|
@@ -184,7 +195,7 @@ class Scripts_To_Footer {
|
|
184 |
* Makes some checks and runs the filter, sets up the admin settings page
|
185 |
* and plugin links.
|
186 |
*
|
187 |
-
* @since 0.2
|
188 |
* @since 0.6.3 moved 'set_header_scripts' into 'wp_head' action.
|
189 |
*/
|
190 |
function init() {
|
@@ -207,7 +218,8 @@ class Scripts_To_Footer {
|
|
207 |
if( function_exists( 'stf_plugin_settings_link' ) ) {
|
208 |
$plugin = plugin_basename(__FILE__);
|
209 |
add_filter( "plugin_action_links_$plugin", 'stf_plugin_settings_link' );
|
210 |
-
|
|
|
211 |
}
|
212 |
|
213 |
/**
|
@@ -216,6 +228,7 @@ class Scripts_To_Footer {
|
|
216 |
* @since 0.6.0
|
217 |
*/
|
218 |
public function set_header_scripts() {
|
|
|
219 |
if( $exclude = stf_get_option( 'stf_jquery_header', false ) ) {
|
220 |
$head_scripts = array( 'jquery' );
|
221 |
} else {
|
@@ -230,25 +243,24 @@ class Scripts_To_Footer {
|
|
230 |
* The holy grail: print select scripts in the header!
|
231 |
*
|
232 |
* @since 0.6.0
|
233 |
-
*
|
234 |
-
* @return void
|
235 |
*/
|
236 |
function print_head_scripts() {
|
237 |
-
|
|
|
238 |
return;
|
239 |
|
240 |
// The main filter, true inacts the plugin, false does not (excludes the page)
|
241 |
-
$include = $this->is_included();
|
242 |
if( $this->is_included() ) {
|
243 |
foreach( $this->header_scripts as $script ) {
|
244 |
-
if( !is_string( $script ) )
|
245 |
continue;
|
246 |
|
247 |
// If the script is enqueued for the page, print it
|
248 |
if( wp_script_is( $script ) )
|
249 |
wp_print_scripts( $script );
|
250 |
}
|
251 |
-
|
|
|
252 |
}
|
253 |
|
254 |
/**
|
@@ -257,7 +269,7 @@ class Scripts_To_Footer {
|
|
257 |
* Checks the singular post/page first, then other common pages
|
258 |
* and compares against any global settings and filters.
|
259 |
*
|
260 |
-
* @since 0.1
|
261 |
**/
|
262 |
function clean_head() {
|
263 |
|
@@ -269,7 +281,7 @@ class Scripts_To_Footer {
|
|
269 |
$include = $this->is_included();
|
270 |
|
271 |
// If this isn't set, then we're missing something
|
272 |
-
if( !isset( $include ) ) {
|
273 |
$this->log_me( 'Something went wrong with the $include variable' );
|
274 |
return;
|
275 |
}
|
@@ -279,7 +291,8 @@ class Scripts_To_Footer {
|
|
279 |
remove_action( 'wp_head', 'wp_print_scripts' );
|
280 |
remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
|
281 |
remove_action( 'wp_head', 'wp_enqueue_scripts', 1 );
|
282 |
-
|
|
|
283 |
}
|
284 |
|
285 |
/**
|
@@ -290,6 +303,7 @@ class Scripts_To_Footer {
|
|
290 |
* @return boolean Default is true.
|
291 |
*/
|
292 |
public function is_included() {
|
|
|
293 |
$include = apply_filters( 'stf_include', true );
|
294 |
|
295 |
if( true === $include ) {
|
@@ -299,7 +313,8 @@ class Scripts_To_Footer {
|
|
299 |
} else {
|
300 |
$this->log_me( 'Non-boolean value in the stf_include filter' );
|
301 |
return true;
|
302 |
-
|
|
|
303 |
}
|
304 |
|
305 |
/**
|
@@ -310,13 +325,16 @@ class Scripts_To_Footer {
|
|
310 |
* @return boolean
|
311 |
*/
|
312 |
function stf_includes() {
|
|
|
313 |
// Collect the information
|
314 |
if( is_singular() || is_page() ) {
|
|
|
315 |
// Make sure we can grab the page/post id
|
316 |
$queried_object_id = get_queried_object_id();
|
317 |
|
318 |
// verify we got a good result
|
319 |
if( absint( $queried_object_id ) && ( $post_type = get_post_type( $queried_object_id ) ) ) {
|
|
|
320 |
// See if post type is supported, if not bail
|
321 |
if( false === $this->post_type_supported( $post_type ) )
|
322 |
return false;
|
@@ -339,25 +357,28 @@ class Scripts_To_Footer {
|
|
339 |
return apply_filters( "stf_{$post_type}", true, $queried_object_id );
|
340 |
|
341 |
} else {
|
342 |
-
$this->log_me( 'Unable to get a correct object id from get_queried_object_id or unable to get post type' );
|
343 |
return false;
|
344 |
}
|
345 |
|
346 |
// Home (blog) page
|
347 |
} elseif( is_home() ) {
|
|
|
348 |
// Grab global setting
|
349 |
$type = 'home';
|
350 |
|
351 |
// Search Result Page
|
352 |
} elseif( is_search() ) {
|
|
|
353 |
$type = 'search';
|
354 |
|
355 |
// 404 Pages
|
356 |
} elseif( is_404() ) {
|
|
|
357 |
$type = '404';
|
358 |
|
359 |
// Author Archive
|
360 |
} elseif( is_author() ) {
|
|
|
361 |
$type = 'author_archive';
|
362 |
|
363 |
// Category Archive
|
@@ -366,7 +387,6 @@ class Scripts_To_Footer {
|
|
366 |
if( $this->tax_supported( 'category' ) ) {
|
367 |
$type = "category_archive";
|
368 |
} else {
|
369 |
-
$this->log_me( 'Error in category check' );
|
370 |
return false;
|
371 |
}
|
372 |
|
@@ -376,7 +396,6 @@ class Scripts_To_Footer {
|
|
376 |
if( $this->tax_supported( 'post_tag' ) ) {
|
377 |
$type = "post_tag_archive";
|
378 |
} else {
|
379 |
-
$this->log_me( 'Error in tag check' );
|
380 |
return false;
|
381 |
}
|
382 |
|
@@ -391,7 +410,6 @@ class Scripts_To_Footer {
|
|
391 |
if( isset( $tax->name ) && $this->tax_supported( $tax->name ) ) {
|
392 |
$type = "{$tax->name}_archive";
|
393 |
} else {
|
394 |
-
$this->log_me( 'Error in taxonomy check' );
|
395 |
return false;
|
396 |
}
|
397 |
|
@@ -402,34 +420,41 @@ class Scripts_To_Footer {
|
|
402 |
if( $this->post_type_supported( $post_type ) ) {
|
403 |
$type = "{$post_type}_archive";
|
404 |
} else {
|
405 |
-
$this->log_me( 'Error in post type check check' );
|
406 |
return false;
|
407 |
}
|
408 |
|
409 |
// Generic archives (date, author, etc)
|
410 |
} elseif( is_archive() ) {
|
|
|
411 |
$type = 'archive';
|
412 |
|
413 |
// if all else fails return false
|
414 |
} else {
|
415 |
-
|
|
|
|
|
416 |
}
|
417 |
|
418 |
// Get the option and return the result with a filter to override
|
419 |
if( isset( $type ) && is_string( $type ) ) {
|
|
|
420 |
// Filter to *exclude* a type of page, return the opposite
|
421 |
$exclude = stf_get_option( "stf_exclude_{$type}", false );
|
422 |
if( $exclude ) {
|
423 |
$include = false;
|
424 |
} else {
|
425 |
$include = true;
|
426 |
-
|
|
|
427 |
return apply_filters( "stf_{$type}", $include );
|
428 |
|
429 |
} else {
|
|
|
430 |
$this->log_me( 'invalid $type element' );
|
431 |
-
|
432 |
-
|
|
|
|
|
433 |
}
|
434 |
|
435 |
/**
|
@@ -440,13 +465,14 @@ class Scripts_To_Footer {
|
|
440 |
* @return array Supported posts
|
441 |
*/
|
442 |
public function post_types_supported() {
|
|
|
443 |
$post_types = apply_filters( 'scripts_to_footer_post_types', array( 'page', 'post' ) );
|
444 |
if( is_array( $post_types ) ) {
|
445 |
return $post_types;
|
446 |
} else {
|
447 |
-
$this->log_me( 'Invalid post types returned in scripts_to_footer_post_types filter' );
|
448 |
return false;
|
449 |
-
|
|
|
450 |
}
|
451 |
|
452 |
/**
|
@@ -457,12 +483,14 @@ class Scripts_To_Footer {
|
|
457 |
* @return array Supported posts
|
458 |
*/
|
459 |
public function post_type_supported( $post_type ) {
|
|
|
460 |
$post_types = $this->post_types_supported();
|
461 |
if( is_array( $post_types ) && is_string( $post_type ) && in_array( $post_type, $post_types ) ) {
|
462 |
return true;
|
463 |
} else {
|
464 |
return false;
|
465 |
-
|
|
|
466 |
}
|
467 |
|
468 |
/**
|
@@ -473,13 +501,14 @@ class Scripts_To_Footer {
|
|
473 |
* @return array Supported posts
|
474 |
*/
|
475 |
public function taxonomies_supported() {
|
|
|
476 |
$taxes = apply_filters( 'scripts_to_footer_taxonomies', array( 'category', 'post_tag' ) );
|
477 |
if( is_array( $taxes ) ) {
|
478 |
return $taxes;
|
479 |
} else {
|
480 |
-
$this->log_me( 'Invalid taxonomies returned in scripts_to_footer_taxonomies filter' );
|
481 |
return false;
|
482 |
-
|
|
|
483 |
}
|
484 |
|
485 |
/**
|
@@ -490,12 +519,14 @@ class Scripts_To_Footer {
|
|
490 |
* @return array Supported posts
|
491 |
*/
|
492 |
public function tax_supported( $taxonomy ) {
|
|
|
493 |
$taxes = $this->taxonomies_supported();
|
494 |
if( is_array( $taxes ) && is_string( $taxonomy ) && in_array( $taxonomy, $taxes ) ) {
|
495 |
return true;
|
496 |
} else {
|
497 |
return false;
|
498 |
-
|
|
|
499 |
}
|
500 |
|
501 |
/**
|
@@ -506,47 +537,66 @@ class Scripts_To_Footer {
|
|
506 |
* @param string $message
|
507 |
*/
|
508 |
public function log_me( $message ) {
|
509 |
-
|
|
|
510 |
if ( is_array( $message ) || is_object( $message ) ) {
|
511 |
error_log( 'Scripts-to-Footer Plugin Error: ' . print_r( $message, true ) );
|
512 |
} else {
|
513 |
error_log( 'Scripts-to-Footer Plugin Error: ' . $message );
|
514 |
}
|
515 |
-
|
516 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
517 |
}
|
518 |
|
519 |
/**
|
520 |
* Add various links to plugin page
|
521 |
*
|
522 |
-
* @since 0.2
|
523 |
*
|
524 |
* @param $links
|
525 |
* @param $file
|
526 |
*
|
527 |
* @return strings plugin links
|
528 |
*/
|
529 |
-
if( !function_exists( 'stf_plugin_links' ) ) {
|
530 |
function stf_plugin_links( $links, $file ) {
|
|
|
531 |
static $this_plugin;
|
532 |
|
533 |
/** Capability Check */
|
534 |
if( ! current_user_can( 'install_plugins' ) )
|
535 |
return $links;
|
536 |
|
537 |
-
if(
|
538 |
$this_plugin = plugin_basename(__FILE__);
|
539 |
-
}
|
540 |
|
541 |
if( $file == $this_plugin ) {
|
|
|
542 |
$links[] = '<a href="http://wordpress.org/support/plugin/scripts-to-footerphp" title="' . __( 'Support', STF_DOMAIN ) . '">' . __( 'Support', STF_DOMAIN ) . '</a>';
|
543 |
|
544 |
$links[] = '<a href="https://github.com/joshuadavidnelson/scripts-to-footer/wiki" title="' . __( 'Documentation', STF_DOMAIN ) . '" target="_blank">' . __( 'Documentation', STF_DOMAIN ) . '</a>';
|
545 |
|
546 |
-
|
|
|
547 |
}
|
548 |
|
549 |
-
|
|
|
550 |
}
|
551 |
}
|
552 |
|
@@ -560,8 +610,12 @@ if( !function_exists( 'stf_plugin_links' ) ) {
|
|
560 |
*/
|
561 |
if( !function_exists( 'stf_plugin_settings_link' ) ) {
|
562 |
function stf_plugin_settings_link( $links ) {
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
|
|
|
|
|
|
|
|
567 |
}
|
4 |
*
|
5 |
* @package Scripts_To_Footer
|
6 |
* @author Joshua David Nelson <josh@joshuadnelson.com>
|
7 |
+
* @copyright Copyright (c) 2020, Joshua David Nelson
|
8 |
* @license http://www.opensource.org/licenses/gpl-license.php GPL-2.0+
|
9 |
* @link http://joshuadnelson.com/scripts-to-footer-plugin
|
10 |
*
|
11 |
* Plugin Name: Scripts-To-Footer
|
12 |
* Plugin URI: http://wordpress.org/plugins/scripts-to-footerphp/
|
13 |
* Description: Moves scripts to the footer to decrease page load times, while keeping stylesheets in the header. Requires that plugins and theme correctly utilizes wp_enqueue_scripts hook. Can be disabled via a checkbox on specific pages and posts.
|
14 |
+
* Version: 0.6.4.1
|
15 |
* Author: Joshua David Nelson
|
16 |
* Author URI: http://joshuadnelson.com
|
17 |
* License: GPL2
|
22 |
|
23 |
/**
|
24 |
* Prevent direct access to this file.
|
25 |
+
**/
|
|
|
|
|
26 |
if( !defined( 'ABSPATH' ) ) {
|
27 |
exit( 'You are not allowed to access this file directly.' );
|
28 |
}
|
30 |
/**
|
31 |
* Define our plugin variables
|
32 |
*
|
33 |
+
* @since 0.2.0
|
34 |
**/
|
35 |
// Plugin Settings Field
|
36 |
+
if( ! defined( 'STF_SETTINGS_FIELD' ) )
|
37 |
define( 'STF_SETTINGS_FIELD', 'scripts-to-footer' );
|
38 |
|
39 |
// Plugin Domain
|
40 |
+
if( ! defined( 'STF_DOMAIN' ) )
|
41 |
define( 'STF_DOMAIN', 'stf' );
|
42 |
|
43 |
// Plugin Verison
|
44 |
if( !defined( 'STF_VERSION' ) )
|
45 |
+
define( 'STF_VERSION', '0.6.4.1' );
|
46 |
|
47 |
// Plugin name
|
48 |
+
if( ! defined( 'STF_NAME' ) )
|
49 |
define( 'STF_NAME', trim( dirname( plugin_basename( __FILE__ ) ), '/' ) );
|
50 |
|
51 |
// Plugin Directory
|
52 |
+
if( ! defined( 'STF_DIR' ) )
|
53 |
+
define( 'STF_DIR', WP_PLUGIN_DIR . '/' . trim( dirname( plugin_basename( __FILE__ ) ), '/' ) );
|
54 |
|
55 |
// Plugin URL
|
56 |
+
if( ! defined( 'STF_URL' ) )
|
57 |
+
define( 'STF_URL', WP_PLUGIN_URL . '/' . trim( dirname( plugin_basename( __FILE__ ) ), '/' ) );
|
58 |
+
|
59 |
+
// Custom Debug Constant, intented for developer use
|
60 |
+
if( ! defined( 'STF_DEBUG' ) )
|
61 |
+
define( 'STF_DEBUG', false );
|
62 |
+
|
63 |
|
64 |
/**
|
65 |
* Scripts to Footer Class.
|
66 |
*
|
67 |
* Forces scripts to the footer, unless excluded in the settings page.
|
68 |
*
|
69 |
+
* @since 0.2.0
|
70 |
*/
|
71 |
global $stf_scripts_to_footer;
|
72 |
$stf_scripts_to_footer = new Scripts_To_Footer();
|
87 |
*
|
88 |
* Registers our activation hook and init hook.
|
89 |
*
|
90 |
+
* @since 0.2.0
|
91 |
*/
|
92 |
function __construct() {
|
93 |
+
|
94 |
add_action( 'admin_init', array( $this, 'check_version' ) );
|
95 |
|
96 |
// Don't run anything else in the plugin, if we're on an incompatible
|
102 |
include_once( STF_DIR . '/admin/admin-settings.php' );
|
103 |
|
104 |
// Make it so
|
105 |
+
add_action( 'init', array( $this, 'init' ) );
|
106 |
+
|
107 |
}
|
108 |
|
109 |
/**
|
116 |
* @since 0.6.0
|
117 |
*/
|
118 |
static function activation_check() {
|
119 |
+
|
120 |
if ( ! self::compatible_version() ) {
|
121 |
deactivate_plugins( plugin_basename( __FILE__ ) );
|
122 |
wp_die( __( 'Scripts-to-Footer requires WordPress 3.1.0 or higher', 'stf' ) );
|
133 |
|
134 |
// Save current version
|
135 |
update_option( 'stf_version', STF_VERSION );
|
136 |
+
}
|
137 |
+
|
138 |
}
|
139 |
|
140 |
/**
|
146 |
* @since 0.6.0
|
147 |
*/
|
148 |
function check_version() {
|
149 |
+
|
150 |
if ( ! self::compatible_version() ) {
|
151 |
if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
|
152 |
deactivate_plugins( plugin_basename( __FILE__ ) );
|
155 |
unset( $_GET['activate'] );
|
156 |
}
|
157 |
}
|
158 |
+
}
|
159 |
+
|
160 |
}
|
161 |
|
162 |
/**
|
163 |
* Display notice on deactivation.
|
164 |
*
|
165 |
* @since 0.6.0
|
|
|
|
|
166 |
*/
|
167 |
function disabled_notice() {
|
168 |
+
|
169 |
+
echo '<strong>' . esc_html__( 'Scripts-to-Footer requires WordPress 3.1.0 or higher.', STF_DOMAIN ) . '</strong>';
|
170 |
+
|
171 |
}
|
172 |
|
173 |
/**
|
178 |
* @return boolean
|
179 |
*/
|
180 |
static function compatible_version() {
|
181 |
+
|
182 |
if ( version_compare( $GLOBALS['wp_version'], '3.1.0', '<' ) ) {
|
183 |
return false;
|
184 |
}
|
185 |
|
186 |
// Add sanity checks for other version requirements here
|
187 |
|
188 |
+
return true;
|
189 |
+
|
190 |
}
|
191 |
|
192 |
/**
|
195 |
* Makes some checks and runs the filter, sets up the admin settings page
|
196 |
* and plugin links.
|
197 |
*
|
198 |
+
* @since 0.2.0
|
199 |
* @since 0.6.3 moved 'set_header_scripts' into 'wp_head' action.
|
200 |
*/
|
201 |
function init() {
|
218 |
if( function_exists( 'stf_plugin_settings_link' ) ) {
|
219 |
$plugin = plugin_basename(__FILE__);
|
220 |
add_filter( "plugin_action_links_$plugin", 'stf_plugin_settings_link' );
|
221 |
+
}
|
222 |
+
|
223 |
}
|
224 |
|
225 |
/**
|
228 |
* @since 0.6.0
|
229 |
*/
|
230 |
public function set_header_scripts() {
|
231 |
+
|
232 |
if( $exclude = stf_get_option( 'stf_jquery_header', false ) ) {
|
233 |
$head_scripts = array( 'jquery' );
|
234 |
} else {
|
243 |
* The holy grail: print select scripts in the header!
|
244 |
*
|
245 |
* @since 0.6.0
|
|
|
|
|
246 |
*/
|
247 |
function print_head_scripts() {
|
248 |
+
|
249 |
+
if( ! isset( $this->header_scripts ) || empty( $this->header_scripts ) || ! is_array( $this->header_scripts ) )
|
250 |
return;
|
251 |
|
252 |
// The main filter, true inacts the plugin, false does not (excludes the page)
|
|
|
253 |
if( $this->is_included() ) {
|
254 |
foreach( $this->header_scripts as $script ) {
|
255 |
+
if( ! is_string( $script ) )
|
256 |
continue;
|
257 |
|
258 |
// If the script is enqueued for the page, print it
|
259 |
if( wp_script_is( $script ) )
|
260 |
wp_print_scripts( $script );
|
261 |
}
|
262 |
+
}
|
263 |
+
|
264 |
}
|
265 |
|
266 |
/**
|
269 |
* Checks the singular post/page first, then other common pages
|
270 |
* and compares against any global settings and filters.
|
271 |
*
|
272 |
+
* @since 0.1.0
|
273 |
**/
|
274 |
function clean_head() {
|
275 |
|
281 |
$include = $this->is_included();
|
282 |
|
283 |
// If this isn't set, then we're missing something
|
284 |
+
if( ! isset( $include ) ) {
|
285 |
$this->log_me( 'Something went wrong with the $include variable' );
|
286 |
return;
|
287 |
}
|
291 |
remove_action( 'wp_head', 'wp_print_scripts' );
|
292 |
remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
|
293 |
remove_action( 'wp_head', 'wp_enqueue_scripts', 1 );
|
294 |
+
}
|
295 |
+
|
296 |
}
|
297 |
|
298 |
/**
|
303 |
* @return boolean Default is true.
|
304 |
*/
|
305 |
public function is_included() {
|
306 |
+
|
307 |
$include = apply_filters( 'stf_include', true );
|
308 |
|
309 |
if( true === $include ) {
|
313 |
} else {
|
314 |
$this->log_me( 'Non-boolean value in the stf_include filter' );
|
315 |
return true;
|
316 |
+
}
|
317 |
+
|
318 |
}
|
319 |
|
320 |
/**
|
325 |
* @return boolean
|
326 |
*/
|
327 |
function stf_includes() {
|
328 |
+
|
329 |
// Collect the information
|
330 |
if( is_singular() || is_page() ) {
|
331 |
+
|
332 |
// Make sure we can grab the page/post id
|
333 |
$queried_object_id = get_queried_object_id();
|
334 |
|
335 |
// verify we got a good result
|
336 |
if( absint( $queried_object_id ) && ( $post_type = get_post_type( $queried_object_id ) ) ) {
|
337 |
+
|
338 |
// See if post type is supported, if not bail
|
339 |
if( false === $this->post_type_supported( $post_type ) )
|
340 |
return false;
|
357 |
return apply_filters( "stf_{$post_type}", true, $queried_object_id );
|
358 |
|
359 |
} else {
|
|
|
360 |
return false;
|
361 |
}
|
362 |
|
363 |
// Home (blog) page
|
364 |
} elseif( is_home() ) {
|
365 |
+
|
366 |
// Grab global setting
|
367 |
$type = 'home';
|
368 |
|
369 |
// Search Result Page
|
370 |
} elseif( is_search() ) {
|
371 |
+
|
372 |
$type = 'search';
|
373 |
|
374 |
// 404 Pages
|
375 |
} elseif( is_404() ) {
|
376 |
+
|
377 |
$type = '404';
|
378 |
|
379 |
// Author Archive
|
380 |
} elseif( is_author() ) {
|
381 |
+
|
382 |
$type = 'author_archive';
|
383 |
|
384 |
// Category Archive
|
387 |
if( $this->tax_supported( 'category' ) ) {
|
388 |
$type = "category_archive";
|
389 |
} else {
|
|
|
390 |
return false;
|
391 |
}
|
392 |
|
396 |
if( $this->tax_supported( 'post_tag' ) ) {
|
397 |
$type = "post_tag_archive";
|
398 |
} else {
|
|
|
399 |
return false;
|
400 |
}
|
401 |
|
410 |
if( isset( $tax->name ) && $this->tax_supported( $tax->name ) ) {
|
411 |
$type = "{$tax->name}_archive";
|
412 |
} else {
|
|
|
413 |
return false;
|
414 |
}
|
415 |
|
420 |
if( $this->post_type_supported( $post_type ) ) {
|
421 |
$type = "{$post_type}_archive";
|
422 |
} else {
|
|
|
423 |
return false;
|
424 |
}
|
425 |
|
426 |
// Generic archives (date, author, etc)
|
427 |
} elseif( is_archive() ) {
|
428 |
+
|
429 |
$type = 'archive';
|
430 |
|
431 |
// if all else fails return false
|
432 |
} else {
|
433 |
+
|
434 |
+
return false;
|
435 |
+
|
436 |
}
|
437 |
|
438 |
// Get the option and return the result with a filter to override
|
439 |
if( isset( $type ) && is_string( $type ) ) {
|
440 |
+
|
441 |
// Filter to *exclude* a type of page, return the opposite
|
442 |
$exclude = stf_get_option( "stf_exclude_{$type}", false );
|
443 |
if( $exclude ) {
|
444 |
$include = false;
|
445 |
} else {
|
446 |
$include = true;
|
447 |
+
}
|
448 |
+
|
449 |
return apply_filters( "stf_{$type}", $include );
|
450 |
|
451 |
} else {
|
452 |
+
|
453 |
$this->log_me( 'invalid $type element' );
|
454 |
+
return false;
|
455 |
+
|
456 |
+
}
|
457 |
+
|
458 |
}
|
459 |
|
460 |
/**
|
465 |
* @return array Supported posts
|
466 |
*/
|
467 |
public function post_types_supported() {
|
468 |
+
|
469 |
$post_types = apply_filters( 'scripts_to_footer_post_types', array( 'page', 'post' ) );
|
470 |
if( is_array( $post_types ) ) {
|
471 |
return $post_types;
|
472 |
} else {
|
|
|
473 |
return false;
|
474 |
+
}
|
475 |
+
|
476 |
}
|
477 |
|
478 |
/**
|
483 |
* @return array Supported posts
|
484 |
*/
|
485 |
public function post_type_supported( $post_type ) {
|
486 |
+
|
487 |
$post_types = $this->post_types_supported();
|
488 |
if( is_array( $post_types ) && is_string( $post_type ) && in_array( $post_type, $post_types ) ) {
|
489 |
return true;
|
490 |
} else {
|
491 |
return false;
|
492 |
+
}
|
493 |
+
|
494 |
}
|
495 |
|
496 |
/**
|
501 |
* @return array Supported posts
|
502 |
*/
|
503 |
public function taxonomies_supported() {
|
504 |
+
|
505 |
$taxes = apply_filters( 'scripts_to_footer_taxonomies', array( 'category', 'post_tag' ) );
|
506 |
if( is_array( $taxes ) ) {
|
507 |
return $taxes;
|
508 |
} else {
|
|
|
509 |
return false;
|
510 |
+
}
|
511 |
+
|
512 |
}
|
513 |
|
514 |
/**
|
519 |
* @return array Supported posts
|
520 |
*/
|
521 |
public function tax_supported( $taxonomy ) {
|
522 |
+
|
523 |
$taxes = $this->taxonomies_supported();
|
524 |
if( is_array( $taxes ) && is_string( $taxonomy ) && in_array( $taxonomy, $taxes ) ) {
|
525 |
return true;
|
526 |
} else {
|
527 |
return false;
|
528 |
+
}
|
529 |
+
|
530 |
}
|
531 |
|
532 |
/**
|
537 |
* @param string $message
|
538 |
*/
|
539 |
public function log_me( $message ) {
|
540 |
+
|
541 |
+
if ( $this->debug() ) {
|
542 |
if ( is_array( $message ) || is_object( $message ) ) {
|
543 |
error_log( 'Scripts-to-Footer Plugin Error: ' . print_r( $message, true ) );
|
544 |
} else {
|
545 |
error_log( 'Scripts-to-Footer Plugin Error: ' . $message );
|
546 |
}
|
547 |
+
}
|
548 |
+
|
549 |
+
}
|
550 |
+
|
551 |
+
/**
|
552 |
+
* Check to see if we're in a debug mode.
|
553 |
+
*
|
554 |
+
* @since 0.6.5
|
555 |
+
*
|
556 |
+
* @return bool
|
557 |
+
*/
|
558 |
+
private function debug() {
|
559 |
+
|
560 |
+
return defined( 'WP_DEBUG' ) && true === WP_DEBUG
|
561 |
+
&& defined( 'STF_DEBUG' ) && true === STF_DEBUG;
|
562 |
+
|
563 |
+
}
|
564 |
}
|
565 |
|
566 |
/**
|
567 |
* Add various links to plugin page
|
568 |
*
|
569 |
+
* @since 0.2.0
|
570 |
*
|
571 |
* @param $links
|
572 |
* @param $file
|
573 |
*
|
574 |
* @return strings plugin links
|
575 |
*/
|
576 |
+
if( ! function_exists( 'stf_plugin_links' ) ) {
|
577 |
function stf_plugin_links( $links, $file ) {
|
578 |
+
|
579 |
static $this_plugin;
|
580 |
|
581 |
/** Capability Check */
|
582 |
if( ! current_user_can( 'install_plugins' ) )
|
583 |
return $links;
|
584 |
|
585 |
+
if( ! $this_plugin )
|
586 |
$this_plugin = plugin_basename(__FILE__);
|
|
|
587 |
|
588 |
if( $file == $this_plugin ) {
|
589 |
+
|
590 |
$links[] = '<a href="http://wordpress.org/support/plugin/scripts-to-footerphp" title="' . __( 'Support', STF_DOMAIN ) . '">' . __( 'Support', STF_DOMAIN ) . '</a>';
|
591 |
|
592 |
$links[] = '<a href="https://github.com/joshuadavidnelson/scripts-to-footer/wiki" title="' . __( 'Documentation', STF_DOMAIN ) . '" target="_blank">' . __( 'Documentation', STF_DOMAIN ) . '</a>';
|
593 |
|
594 |
+
$links[] = '<a href="http://jdn.im/donate" title="' . __( 'Donate', STF_DOMAIN ) . '">' . __( 'Donate', STF_DOMAIN ) . '</a>';
|
595 |
+
|
596 |
}
|
597 |
|
598 |
+
return $links;
|
599 |
+
|
600 |
}
|
601 |
}
|
602 |
|
610 |
*/
|
611 |
if( !function_exists( 'stf_plugin_settings_link' ) ) {
|
612 |
function stf_plugin_settings_link( $links ) {
|
613 |
+
|
614 |
+
$settings_link = '<a href="options-general.php?page=' . STF_SETTINGS_FIELD . '">Settings</a>';
|
615 |
+
|
616 |
+
array_unshift( $links, $settings_link );
|
617 |
+
|
618 |
+
return $links;
|
619 |
+
|
620 |
+
}
|
621 |
}
|
uninstall.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* @package Scripts_To_Footer
|
6 |
* @subpackage Uninstall
|
7 |
* @author Joshua David Nelson <josh@joshuadnelson.com>
|
8 |
-
* @copyright Copyright (c)
|
9 |
* @license http://www.opensource.org/licenses/gpl-license.php GPL-2.0+
|
10 |
* @link http://joshuadnelson.com/scripts-to-footer-plugin
|
11 |
*
|
5 |
* @package Scripts_To_Footer
|
6 |
* @subpackage Uninstall
|
7 |
* @author Joshua David Nelson <josh@joshuadnelson.com>
|
8 |
+
* @copyright Copyright (c) 2020, Joshua David Nelson
|
9 |
* @license http://www.opensource.org/licenses/gpl-license.php GPL-2.0+
|
10 |
* @link http://joshuadnelson.com/scripts-to-footer-plugin
|
11 |
*
|