PluginProbe
Pronamic Client / trunk
Pronamic Client vtrunk
2.4.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.4.0 1.5.0 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 All 54 releases
pronamic-client / classes / ScriptsModule.php

ScriptsModule.php in Pronamic Client trunk, at classes/ScriptsModule.php

135 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Pronamic\WordPress\PronamicClient;
4
5 class ScriptsModule {
6 /**
7 * Instance of this class.
8 *
9 * @since 1.8.1
10 * @var Tracking
11 */
12 protected static $instance = null;
13
14 /**
15 * Plugin.
16 *
17 * @var Plugin
18 */
19 public $plugin;
20
21 /**
22 * Constructs scripts module.
23 *
24 * @param Plugin $plugin
25 */
26 private function __construct( Plugin $plugin ) {
27 $this->plugin = $plugin;
28
29 // Actions
30 \add_action( 'wp_print_scripts', [ $this, 'patch_swipebox' ] );
31 \add_action( 'wp_print_scripts', [ $this, 'patch_bootstrap' ] );
32 }
33
34 /**
35 * Patch Swipebox.
36 *
37 * In WordPress 5.6 jQuery was updated from 1.12.4 to 3.5.1.
38 * This resulted in an issue with Swipebox, all clicks
39 * resulted in a black overlay.
40 *
41 * @link https://github.com/brutaldesign/swipebox/issues/383
42 * @link https://make.wordpress.org/core/2020/11/05/updating-core-jquery-to-version-3-part-2/
43 * @link https://jquery.com/upgrade-guide/1.9/#selector-property-on-jquery-objects
44 * @link https://developer.wordpress.org/reference/hooks/wp_print_scripts/
45 * @link https://developer.wordpress.org/reference/functions/wp_deregister_script/
46 * @link https://developer.wordpress.org/reference/functions/wp_script_is/
47 * @return void
48 */
49 public function patch_swipebox() {
50 $min = \SCRIPT_DEBUG ? '' : '.min';
51
52 $handles = [
53 /**
54 * Pronamic themes register with the handle name 'swipebox':
55 *
56 * @link https://gitlab.com/pronamic-themes/timmy/-/blob/ed073aa2876e2b0ba9582201d0378a253193edb1/classes/class-scripts.php#L65-72
57 */
58 'swipebox',
59 /**
60 * WordPress plugin 'Easy SwipeBox' register with the handle name 'easy-swipebox':
61 *
62 * @link https://github.com/leopuleo/easy-swipebox/blob/1.1.1/public/class-easy-swipebox-public.php#L135-L148
63 * @link https://github.com/leopuleo/easy-swipebox/blob/1.1.1/includes/class-easy-swipebox.php#L109
64 */
65 'easy-swipebox',
66 ];
67
68 /**
69 * Filter the enqueued scripts.
70 */
71 $handles = \array_filter(
72 $handles,
73 function ( $handle ) {
74 return \wp_script_is( $handle );
75 }
76 );
77
78 foreach ( $handles as $handle ) {
79 \wp_deregister_script( $handle );
80
81 \wp_register_script(
82 $handle,
83 \plugins_url( '../packages/mho79/swipebox/1.4.4/js/jquery.swipebox' . $min . '.js', __FILE__ ),
84 [ 'jquery' ],
85 'mho79-1.4.4',
86 true
87 );
88 }
89 }
90
91 /**
92 * Patch Bootstrap.
93 *
94 * @link https://github.com/twbs/bootstrap/releases/tag/v3.3.7
95 */
96 public function patch_bootstrap() {
97 $min = \SCRIPT_DEBUG ? '' : '.min';
98
99 $handles = [
100 'bootstrap',
101 ];
102
103 $scripts = \wp_scripts();
104
105 foreach ( $handles as $handle ) {
106 if ( ! \array_key_exists( $handle, $scripts->registered ) ) {
107 continue;
108 }
109
110 $script = $scripts->registered[ $handle ];
111
112 if ( \version_compare( $script->ver, '3.3', '>=' ) && \version_compare( $script->ver, '3.3.6', '<=' ) ) {
113 $script->ver = '3.3.7';
114 $script->src = \plugins_url( '../packages/twbs/bootstrap/3.3.7/js/bootstrap' . $min . '.js', __FILE__ );
115 }
116 }
117 }
118
119 /**
120 * Return an instance of this class.
121 *
122 * @since 1.1.0
123 *
124 * @return object A single instance of this class.
125 */
126 public static function get_instance( $plugin = false ) {
127 // If the single instance hasn't been set, set it now.
128 if ( null === self::$instance ) {
129 self::$instance = new self( $plugin );
130 }
131
132 return self::$instance;
133 }
134 }
135