PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / trunk
WPSSO Core – Complete Schema Markup and Meta Tags vtrunk
22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
wpsso / lib / loader.php

loader.php in WPSSO Core – Complete Schema Markup and Meta Tags trunk, at lib/loader.php

223 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * License: GPLv3
4 * License URI: https://www.gnu.org/licenses/gpl.txt
5 * Copyright 2012-2026 Jean-Sebastien Morisset (https://wpsso.com/)
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9
10 die( 'These aren\'t the droids you\'re looking for.' );
11 }
12
13 if ( ! defined( 'WPSSO_PLUGINDIR' ) ) {
14
15 die( 'Do. Or do not. There is no try.' );
16 }
17
18 if ( ! class_exists( 'SucomPlugin' ) ) {
19
20 require_once WPSSO_PLUGINDIR . 'lib/com/plugin.php';
21 }
22
23 if ( ! class_exists( 'WpssoLoader' ) ) {
24
25 class WpssoLoader {
26
27 private $p; // Wpsso class object.
28
29 /*
30 * Instantiated by Wpsso->set_objects() at init priority 10
31 */
32 public function __construct( &$plugin ) {
33
34 $this->p =& $plugin;
35
36 if ( $this->p->debug->enabled ) {
37
38 $this->p->debug->mark();
39 }
40
41 $this->load_integ();
42
43 $this->load_dist();
44 }
45
46 private function load_integ() {
47
48 if ( $this->p->debug->enabled ) {
49
50 $this->p->debug->mark( 'loading integ modules' ); // Begin timer.
51 }
52
53 foreach ( $this->p->cf[ 'plugin' ] as $ext => $info ) {
54
55 if ( $this->p->debug->enabled ) {
56
57 $this->p->debug->log( 'loading integ modules for ' . $ext );
58 }
59
60 $this->maybe_load_ext_mods( $ext, $sub = 'integ' );
61 }
62
63 if ( $this->p->debug->enabled ) {
64
65 $this->p->debug->mark( 'loading integ modules' ); // End timer.
66 }
67 }
68
69 private function load_dist() {
70
71 if ( $this->p->debug->enabled ) {
72
73 $this->p->debug->mark( 'loading dist modules' ); // Begin timer.
74 }
75
76 $um_check = $this->p->check->is_umver_gt_min(); // Uses a local cache.
77
78 foreach ( $this->p->cf[ 'plugin' ] as $ext => $info ) {
79
80 $GLOBALS[ $ext . '_dist' ] = '';
81 }
82
83 foreach ( $this->p->cf[ 'plugin' ] as $ext => $info ) {
84
85 $sub = $GLOBALS[ $ext . '_dist' ] = 'std' === $GLOBALS[ $ext . '_dist' ] || empty( $info[ 'update_auth' ] ) || ! $um_check ? 'std' :
86 ( 'pro' === $GLOBALS[ $ext . '_dist' ] || 1 === $this->p->check->pp( $ext, true, WPSSO_UNDEF, true, -1 ) ? 'pro' : 'std' );
87
88 if ( $this->p->debug->enabled ) {
89
90 $this->p->debug->log( 'loading dist modules for ' . $ext . ' from ' . $sub );
91 }
92
93 $this->maybe_load_ext_mods( $ext, $sub );
94 }
95
96 if ( $this->p->debug->enabled ) {
97
98 $this->p->debug->mark( 'loading dist modules' ); // End timer.
99 }
100 }
101
102 private function maybe_load_ext_mods( $ext, $sub ) {
103
104 if ( empty( $this->p->cf[ 'plugin' ][ $ext ][ 'lib' ][ $sub ] ) ||
105 ! is_array( $this->p->cf[ 'plugin' ][ $ext ][ 'lib' ][ $sub ] ) ) { // Just in case.
106
107 if ( $this->p->debug->enabled ) {
108
109 $this->p->debug->log( 'no modules found for ' . $ext . '/lib/' . $sub );
110 }
111
112 return;
113 }
114
115 $ext_base = $this->p->cf[ 'plugin' ][ $ext ][ 'base' ];
116
117 if ( ! SucomPlugin::is_plugin_active( $ext_base ) ) { // Just in case.
118
119 if ( $this->p->debug->enabled ) {
120
121 $this->p->debug->log( $ext_base . ' plugin not active or not found' );
122 }
123
124 return;
125 }
126
127 unset( $ext_base );
128
129 foreach ( $this->p->cf[ 'plugin' ][ $ext ][ 'lib' ][ $sub ] as $type => $libs ) {
130
131 $log_prefix = 'loading ' . $ext . '/lib/' . $sub . '/' . $type . ': ';
132
133 foreach ( $libs as $id => $label ) {
134
135 $log_prefix = 'loading ' . $ext . '/lib/' . $sub . '/' . $type . '/' . $id . ': ';
136
137 if ( ! empty( $this->p->avail[ $type ][ $id ] ) ) {
138
139 $lib_path = $sub . '/' . $type . '/' . $id;
140
141 $classname = apply_filters( $ext . '_load_lib', false, $lib_path );
142
143 if ( is_string( $classname ) ) {
144
145 if ( 'none' === $classname ) {
146
147 if ( $this->p->debug->enabled ) {
148
149 $this->p->debug->log( $log_prefix . 'skipped' );
150 }
151
152 continue;
153
154 } elseif ( class_exists( $classname ) ) {
155
156 if ( $this->p->debug->enabled ) {
157
158 $this->p->debug->log( $log_prefix . 'instantiating ' . $classname );
159 }
160
161 new $classname( $this->p );
162
163 } else {
164
165 if ( $this->p->debug->enabled ) {
166
167 $this->p->debug->log( $log_prefix . 'class "' . $classname . '" is missing' );
168 }
169
170 if ( is_admin() && is_object( $this->p->notice ) ) {
171
172 // translators: %1$s is the PHP library path, %2$s is the PHP library class name
173 $this->p->notice->err( sprintf( __( 'Error loading %1$s: Library class "%2$s" is missing.',
174 'wpsso' ), $lib_path, $classname ) );
175 }
176
177 $error_pre = sprintf( __( '%s error:', 'wpsso' ), __METHOD__ );
178
179 $error_msg = sprintf( __( 'Library class "%s" is missing.', 'wpsso' ), $classname );
180
181 SucomUtil::safe_error_log( $error_pre . ' ' . $error_msg );
182 }
183
184 } else {
185
186 if ( $this->p->debug->enabled ) {
187
188 $this->p->debug->log( $log_prefix . 'library class name cannot be determined' );
189 }
190
191 $error_pre = sprintf( __( '%s error:', 'wpsso' ), __METHOD__ );
192
193 $error_msg = sprintf( __( 'Library class name for "%s" cannot be determined.', 'wpsso' ), $lib_path ) . ' ' .
194 __( 'The installed plugin is incomplete or the web server cannot access the required library file.',
195 'wpsso' );
196
197 if ( is_admin() && is_object( $this->p->notice ) ) {
198
199 $this->p->notice->err( $error_msg );
200 }
201
202 SucomUtil::safe_error_log( $error_pre . ' ' . $error_msg );
203 }
204
205 } elseif ( $this->p->debug->enabled ) {
206
207 $this->p->debug->log( $log_prefix . 'avail is false' );
208 }
209 }
210 }
211 }
212
213 public static function load_plugin_std( $plugin, $sub, $id ) {
214
215 $GLOBALS[ 'wpsso_dist' ] = 'std';
216
217 $classname = apply_filters( 'wpsso_load_lib', false, 'std/' . $sub . '/' . $id );
218
219 if ( is_string( $classname ) && class_exists( $classname ) ) new $classname( $plugin );
220 }
221 }
222 }
223