PluginProbe
Plugin Groups / 1.2.2
Plugin Groups v1.2.2
trunk 1.0.3 1.1.0 1.2.1 1.2.2 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.9 3.0.0
plugin-groups / classes / class-plugin-groups.php

class-plugin-groups.php in Plugin Groups 1.2.2, at classes/class-plugin-groups.php

217 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Groups.
4 *
5 * @package Plugin_Groups
6 * @author David Cramer <david@digilab.co.za>
7 * @license GPL-2.0+
8 * @link
9 * @copyright 2015 David Cramer <david@digilab.co.za>
10 */
11
12 /**
13 * Plugin class.
14 *
15 * @package Plugin_Groups
16 * @author David Cramer <david@digilab.co.za>
17 */
18 class Plugin_Groups {
19
20 /**
21 * The slug for this plugin
22 *
23 * @since 0.0.1
24 * @var string
25 */
26 protected $plugin_slug = 'plugin-groups';
27
28 /**
29 * Holds class isntance
30 *
31 * @since 0.0.1
32 * @var object|Plugin_Groups
33 */
34 protected static $instance = null;
35
36 /**
37 * Holds the option screen prefix
38 *
39 * @since 0.0.1
40 * @var string
41 */
42 protected $plugin_screen_hook_suffix = null;
43
44 protected $capability = 'manage_options';
45 protected $multisite = '';
46
47 /**
48 * Initialize the plugin by setting localization, filters, and
49 * administration functions.
50 *
51 * @since 0.0.1
52 * @access private
53 */
54 private function __construct() {
55
56 // Load plugin text domain
57 add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
58
59 // Activate plugin when new blog is added
60 add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
61 // Replace scripts.
62
63 add_action( 'wp_default_scripts', array( $this, 'replace_scripts' ), - 1 );
64 // Load admin style sheet and JavaScript.
65 add_action(
66 'admin_enqueue_scripts',
67 array(
68 $this,
69 'enqueue_admin_stylescripts',
70 )
71 );
72
73 }
74
75 /**
76 * Return an instance of this class.
77 *
78 * @since 0.0.1
79 * @return object|Plugin_Groups A single instance of this class.
80 */
81 public static function get_instance() {
82
83 // If the single instance hasn't been set, set it now.
84 if ( null == self::$instance ) {
85 self::$instance = new self;
86 }
87
88 return self::$instance;
89 }
90
91 /**
92 * Load the plugin text domain for translation.
93 *
94 * @since 0.0.1
95 */
96 public function load_plugin_textdomain() {
97
98 load_plugin_textdomain( $this->plugin_slug, false, basename( PLORG_PATH ) . '/languages' );
99
100 }
101
102 /**
103 * Migrate compat WP 5.6 +
104 *
105 * @since 1.2.2
106 */
107 public function replace_scripts( $scripts ) {
108 $ver = get_bloginfo( 'version' );
109 if ( ! version_compare( '5.6', $ver, '<=' ) || ! self::is_plugin_group_screen() ) {
110 return;
111 }
112
113 $assets_url = PLORG_URL . '/assets/js/';
114 self::set_script( $scripts, 'jquery-migrate', $assets_url . 'jquery-migrate/jquery-migrate-1.4.1-wp.js', array(), '1.4.1-wp' );
115 self::set_script( $scripts, 'jquery-core', $assets_url . 'jquery/jquery-1.12.4-wp.js', array(), '1.12.4-wp' );
116 self::set_script( $scripts, 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '1.12.4-wp' );
117
118 // All the jQuery UI stuff comes here.
119 self::set_script( $scripts, 'jquery-ui-core', $assets_url . 'jquery-ui/core.min.js', array( 'jquery' ), '1.11.4-wp', 1 );
120 self::set_script( $scripts, 'jquery-effects-core', $assets_url . 'jquery-ui/effect.min.js', array( 'jquery' ), '1.11.4-wp', 1 );
121 self::set_script( $scripts, 'jquery-ui-autocomplete', $assets_url . 'jquery-ui/autocomplete.min.js', array( 'jquery-ui-menu', 'wp-a11y' ), '1.11.4-wp', 1 );
122 self::set_script( $scripts, 'jquery-ui-menu', $assets_url . 'jquery-ui/menu.min.js', array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position' ), '1.11.4-wp', 1 );
123 self::set_script( $scripts, 'jquery-ui-sortable', $assets_url . 'jquery-ui/sortable.min.js', array( 'jquery-ui-mouse' ), '1.11.4-wp', 1 );
124 self::set_script( $scripts, 'jquery-ui-widget', $assets_url . 'jquery-ui/widget.min.js', array( 'jquery' ), '1.11.4-wp', 1 );
125
126 }
127
128 /**
129 * Pre-register scripts on 'wp_default_scripts' action, they won't be overwritten by $wp_scripts->add().
130 *
131 * @since 1.2.2
132 */
133 private static function set_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
134 $script = $scripts->query( $handle, 'registered' );
135
136 if ( $script ) {
137 // If already added
138 $script->src = $src;
139 $script->deps = $deps;
140 $script->ver = $ver;
141 $script->args = $in_footer;
142
143 unset( $script->extra['group'] );
144
145 if ( $in_footer ) {
146 $script->add_data( 'group', 1 );
147 }
148 } else {
149 // Add the script
150 if ( $in_footer ) {
151 $scripts->add( $handle, $src, $deps, $ver, 1 );
152 } else {
153 $scripts->add( $handle, $src, $deps, $ver );
154 }
155 }
156 }
157
158 /**
159 * Check if we're in the plugins screen.
160 *
161 * @since 1.2.2
162 * @return bool
163 */
164 public static function is_plugin_group_screen() {
165 $return = false;
166 if ( PLORG_SLUG === self::current_page() ) {
167 $return = true;
168 }
169
170 return $return;
171 }
172
173 /**
174 * Get the name of the current admin page query_var.
175 *
176 * @since 1.2.2
177 * @return string|null
178 */
179 public static function current_page() {
180 $return = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
181 if ( is_null( $return ) && function_exists( 'get_current_screen' ) ) {
182 $screen = get_current_screen();
183 $return = $screen->base;
184 }
185
186 return $return;
187 }
188
189 /**
190 * Register and enqueue admin-specific style sheet.
191 *
192 * @since 0.0.1
193 * @return null
194 */
195 public function enqueue_admin_stylescripts() {
196
197 if ( self::is_plugin_group_screen() ) {
198
199 wp_enqueue_style( 'plugin_groups-core-style', PLORG_URL . '/assets/css/styles.css' );
200 wp_enqueue_style( 'plugin_groups-baldrick-modals', PLORG_URL . '/assets/css/modals.css' );
201 wp_enqueue_script( 'plugin_groups-wp-baldrick', PLORG_URL . '/assets/js/wp-baldrick-full.js', array( 'jquery' ), false, true );
202 wp_enqueue_script( 'jquery-ui-autocomplete' );
203 wp_enqueue_script( 'jquery-ui-sortable' );
204 wp_enqueue_script( 'plugin_groups-core-script', PLORG_URL . '/assets/js/scripts.js', array( 'plugin_groups-wp-baldrick' ), false );
205 wp_enqueue_style( 'wp-color-picker' );
206 wp_enqueue_script( 'wp-color-picker' );
207 wp_enqueue_style( 'plugin_groups-select2-style', PLORG_URL . 'assets/css/select2.css' );
208 wp_enqueue_script( 'plugin_groups-select2-script', PLORG_URL . 'assets/js/select2.min.js', array( 'jquery' ), false, true );
209 }
210
211 if ( 'plugins' === self::current_page() ) {
212 wp_enqueue_script( 'plugin_groups-bulk', PLORG_URL . '/assets/js/bulk.js', array( 'jquery' ), false );
213 wp_enqueue_style( 'plugin_groups-editor', PLORG_URL . 'assets/css/edit.css' );
214 }
215 }
216 }
217