Prevent class_exists() from calling autoloaders.
The update checker uses class_exists in several ways: - As a guard clause around `class Whatever` definitions. This ensures we don't try to define a class that has already been loaded by a different plugin. In this case, autoloading is not necessary because we already know how to load the class. Also, we *want to* load our version of that class if possible - the version that gets loaded by somebody else's autoloader might be different and incompatible. - As a guard clause before `require` statements that include a class. This is conceptually the same as the previous example. - To enable optional features if Debug Bar is active. The latest compatible version of Debug Bar doesn't use autoloading, so it would again be unnecessary in this case.
This commit is contained in:
parent
acb8476be2
commit
317a45dc45
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
if ( !class_exists('PluginUpdateCheckerPanel') && class_exists('Debug_Bar_Panel') ) {
|
||||
if ( !class_exists('PluginUpdateCheckerPanel', false) && class_exists('Debug_Bar_Panel', false) ) {
|
||||
|
||||
/**
|
||||
* A Debug Bar panel for the plugin update checker.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
if ( !class_exists('PucDebugBarPlugin') ) {
|
||||
if ( !class_exists('PucDebugBarPlugin', false) ) {
|
||||
|
||||
class PucDebugBarPlugin {
|
||||
/** @var PluginUpdateChecker */
|
||||
|
|
@ -23,7 +23,7 @@ class PucDebugBarPlugin {
|
|||
*/
|
||||
public function addDebugBarPanel($panels) {
|
||||
require_once dirname(__FILE__) . '/debug-bar-panel.php';
|
||||
if ( current_user_can('update_plugins') && class_exists('PluginUpdateCheckerPanel') ) {
|
||||
if ( current_user_can('update_plugins') && class_exists('PluginUpdateCheckerPanel', false) ) {
|
||||
$panels[] = new PluginUpdateCheckerPanel($this->updateChecker);
|
||||
}
|
||||
return $panels;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
if ( !class_exists('PucGitHubChecker_2_0') ):
|
||||
if ( !class_exists('PucGitHubChecker_2_0', false) ):
|
||||
|
||||
class PucGitHubChecker_2_0 extends PluginUpdateChecker_2_0 {
|
||||
/**
|
||||
|
|
@ -254,7 +254,7 @@ class PucGitHubChecker_2_0 extends PluginUpdateChecker_2_0 {
|
|||
* @return string
|
||||
*/
|
||||
protected function parseMarkdown($markdown) {
|
||||
if ( !class_exists('Parsedown') ) {
|
||||
if ( !class_exists('Parsedown', false) ) {
|
||||
require_once(dirname(__FILE__) . '/vendor/Parsedown.php');
|
||||
}
|
||||
|
||||
|
|
@ -406,7 +406,7 @@ class PucGitHubChecker_2_0 extends PluginUpdateChecker_2_0 {
|
|||
}
|
||||
|
||||
protected function parseReadme($content) {
|
||||
if ( !class_exists('PucReadmeParser') ) {
|
||||
if ( !class_exists('PucReadmeParser', false) ) {
|
||||
require_once(dirname(__FILE__) . '/vendor/readme-parser.php');
|
||||
}
|
||||
$parser = new PucReadmeParser();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
* Released under the MIT license. See license.txt for details.
|
||||
*/
|
||||
|
||||
if ( !class_exists('PluginUpdateChecker_2_0') ):
|
||||
if ( !class_exists('PluginUpdateChecker_2_0', false) ):
|
||||
|
||||
/**
|
||||
* A custom plugin update checker.
|
||||
|
|
@ -845,7 +845,7 @@ class PluginUpdateChecker_2_0 {
|
|||
* Initialize the update checker Debug Bar plugin/add-on thingy.
|
||||
*/
|
||||
public function initDebugBarPanel() {
|
||||
if ( class_exists('Debug_Bar') ) {
|
||||
if ( class_exists('Debug_Bar', false) ) {
|
||||
require_once dirname(__FILE__) . '/debug-bar-plugin.php';
|
||||
$this->debugBarPlugin = new PucDebugBarPlugin($this);
|
||||
}
|
||||
|
|
@ -854,7 +854,7 @@ class PluginUpdateChecker_2_0 {
|
|||
|
||||
endif;
|
||||
|
||||
if ( !class_exists('PluginInfo_2_0') ):
|
||||
if ( !class_exists('PluginInfo_2_0', false) ):
|
||||
|
||||
/**
|
||||
* A container class for holding and transforming various plugin metadata.
|
||||
|
|
@ -984,7 +984,7 @@ class PluginInfo_2_0 {
|
|||
|
||||
endif;
|
||||
|
||||
if ( !class_exists('PluginUpdate_2_0') ):
|
||||
if ( !class_exists('PluginUpdate_2_0', false) ):
|
||||
|
||||
/**
|
||||
* A simple container class for holding information about an available update.
|
||||
|
|
@ -1100,7 +1100,7 @@ class PluginUpdate_2_0 {
|
|||
|
||||
endif;
|
||||
|
||||
if ( !class_exists('PucFactory') ):
|
||||
if ( !class_exists('PucFactory', false) ):
|
||||
|
||||
/**
|
||||
* A factory that builds instances of other classes from this library.
|
||||
|
|
@ -1201,14 +1201,14 @@ PucFactory::addVersion('PucGitHubChecker', 'PucGitHubChecker_2_0', '2.0');
|
|||
* Create non-versioned variants of the update checker classes. This allows for backwards
|
||||
* compatibility with versions that did not use a factory, and it simplifies doc-comments.
|
||||
*/
|
||||
if ( !class_exists('PluginUpdateChecker') ) {
|
||||
if ( !class_exists('PluginUpdateChecker', false) ) {
|
||||
class PluginUpdateChecker extends PluginUpdateChecker_2_0 { }
|
||||
}
|
||||
|
||||
if ( !class_exists('PluginUpdate') ) {
|
||||
if ( !class_exists('PluginUpdate', false) ) {
|
||||
class PluginUpdate extends PluginUpdate_2_0 {}
|
||||
}
|
||||
|
||||
if ( !class_exists('PluginInfo') ) {
|
||||
if ( !class_exists('PluginInfo', false) ) {
|
||||
class PluginInfo extends PluginInfo_2_0 {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ Class PucReadmeParser {
|
|||
$text = call_user_func( array( __CLASS__, 'code_trick' ), $text, $markdown ); // A better parser than Markdown's for: backticks -> CODE
|
||||
|
||||
if ( $markdown ) { // Parse markdown.
|
||||
if ( !class_exists('Parsedown') ) {
|
||||
if ( !class_exists('Parsedown', false) ) {
|
||||
require_once(dirname(__FILE__) . '/Parsedown.php');
|
||||
}
|
||||
$instance = Parsedown::instance();
|
||||
|
|
|
|||
Loading…
Reference in New Issue