Skip to content

Commit

Permalink
* HOT FIX: Fix for fatal error if Beaver Builder Pro is installed and…
Browse files Browse the repository at this point in the history
… Compatibility Manager is enabled.
  • Loading branch information
jawngee committed May 6, 2021
1 parent dc901e6 commit d1435f7
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 60 deletions.
14 changes: 14 additions & 0 deletions classes/Tools/ToolsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,20 @@ public function addMenus( $networkMode, $networkAdminMenu )
'media-cloud-settings-' . $toolId,
[ $this, 'renderSettings' ]
);
} else {

if ( $toolId == 'integrations' ) {
$displayedSettings[] = $toolId;
add_submenu_page(
'media-cloud',
$tool->toolInfo['name'] . ' Settings',
$tool->toolInfo['name'],
'manage_options',
'media-cloud-settings-' . $toolId,
[ $this, 'renderSettings' ]
);
}

}

}
Expand Down
128 changes: 71 additions & 57 deletions classes/Utilities/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ function discoverHooks($hooks) {
$line = 0;
$type = 'unknown';
$hookCallable = null;
$filename = null;
if (is_array($hookData['function'])) {
$type = 'array';
$hookCallable = [
Expand All @@ -479,46 +480,93 @@ function discoverHooks($hooks) {
'method' => $hookData['function'][1]
];

$ref = new \ReflectionClass($hookData['function'][0]);
$filename = $ref->getFileName();
$line = $ref->getStartLine();
try {
$ref = new \ReflectionClass($hookData['function'][0]);
$filename = $ref->getFileName();
$line = $ref->getStartLine();
} catch (\Exception $ex) {
Logger::error("Error discovering hook: ".$ex->getMessage(), [], __METHOD__, __LINE__);
}
} else if (is_string($hookData['function'])) {
$type = 'function';
$hookCallable = [
'function' => $hookData['function']
];

$ref = new \ReflectionFunction($hookData['function']);
$filename = $ref->getFileName();
$line = $ref->getStartLine();
try {
$ref = new \ReflectionFunction($hookData['function']);
$filename = $ref->getFileName();
$line = $ref->getStartLine();
} catch (\Exception $ex) {
Logger::error("Error discovering hook: ".$ex->getMessage(), [], __METHOD__, __LINE__);
}
} else if ($hookData['function'] instanceof \Closure) {
$type = 'closure';
$hookCallable = [];

$ref = new \ReflectionFunction($hookData['function']);
$line = $ref->getStartLine();
$filename = $ref->getFileName();
if ($ref->isClosure() && !empty($ref->getClosureThis())) {
if (strpos(get_class($ref->getClosureThis()), 'MediaCloud') === 0) {
continue;
try {
$ref = new \ReflectionFunction($hookData['function']);
$line = $ref->getStartLine();
$filename = $ref->getFileName();
if ($ref->isClosure() && !empty($ref->getClosureThis())) {
if (strpos(get_class($ref->getClosureThis()), 'MediaCloud') === 0) {
continue;
}
}
} catch (\Exception $ex) {
Logger::error("Error discovering hook: ".$ex->getMessage(), [], __METHOD__, __LINE__);
}
}

if (strpos($filename, WP_PLUGIN_DIR) !== false) {
$filename = ltrim(str_replace(WP_PLUGIN_DIR, '', $filename), '/');
$filenameParts = explode('/', $filename);
$pluginFolder = array_shift($filenameParts);
if (!empty($filename)) {
if (strpos($filename, WP_PLUGIN_DIR) !== false) {
$filename = ltrim(str_replace(WP_PLUGIN_DIR, '', $filename), '/');
$filenameParts = explode('/', $filename);
$pluginFolder = array_shift($filenameParts);

$plugins = get_plugins('/'.$pluginFolder);
if (count($plugins) > 0) {
$plugin = array_values($plugins)[0];

$plugins = get_plugins('/'.$pluginFolder);
if (count($plugins) > 0) {
$plugin = array_values($plugins)[0];
$hash = md5(serialize([
'hook' => $hookName,
'priority' => $priority,
'type' => 'plugin',
'plugin' => $pluginFolder,
'callableType' => $type,
'callable' => $hookCallable,
]));

if (!in_array($hash, $hashes)) {
$hashes[] = $hash;

$foundHooks[] = [
'hook' => $hookName,
'priority' => $priority,
'type' => 'plugin',
'plugin' => $pluginFolder,
'name' => $plugin['Name'],
'callableType' => $type,
'callable' => $hookCallable,
'realCallable' => $hookData['function'],
'basename' => pathinfo('/'.$filename, PATHINFO_BASENAME),
'filename' => '/'.$filename,
'line' => $line,
'hash' => $hash
];
}
}
} else if (strpos($filename, $themeDir) !== false) {
$themeInfo = wp_get_theme();
$filename = ltrim(str_replace($themeDir, '', $filename), '/');
$filenameParts = explode('/', $filename);
$themeFolder = array_shift($filenameParts);

$hash = md5(serialize([
'hook' => $hookName,
'priority' => $priority,
'type' => 'plugin',
'plugin' => $pluginFolder,
'plugin' => $themeFolder,
'callableType' => $type,
'callable' => $hookCallable,
]));
Expand All @@ -529,9 +577,9 @@ function discoverHooks($hooks) {
$foundHooks[] = [
'hook' => $hookName,
'priority' => $priority,
'type' => 'plugin',
'plugin' => $pluginFolder,
'name' => $plugin['Name'],
'type' => 'theme',
'plugin' => $themeFolder,
'name' => $themeInfo->get('Name'),
'callableType' => $type,
'callable' => $hookCallable,
'realCallable' => $hookData['function'],
Expand All @@ -542,45 +590,11 @@ function discoverHooks($hooks) {
];
}
}
} else if (strpos($filename, $themeDir) !== false) {
$themeInfo = wp_get_theme();
$filename = ltrim(str_replace($themeDir, '', $filename), '/');
$filenameParts = explode('/', $filename);
$themeFolder = array_shift($filenameParts);

$hash = md5(serialize([
'hook' => $hookName,
'priority' => $priority,
'type' => 'plugin',
'plugin' => $themeFolder,
'callableType' => $type,
'callable' => $hookCallable,
]));

if (!in_array($hash, $hashes)) {
$hashes[] = $hash;

$foundHooks[] = [
'hook' => $hookName,
'priority' => $priority,
'type' => 'theme',
'plugin' => $themeFolder,
'name' => $themeInfo->get('Name'),
'callableType' => $type,
'callable' => $hookCallable,
'realCallable' => $hookData['function'],
'basename' => pathinfo('/'.$filename, PATHINFO_BASENAME),
'filename' => '/'.$filename,
'line' => $line,
'hash' => $hash
];
}
}
}
}
}

$time = microtime(true) - $time;
return $foundHooks;
}

Expand Down
4 changes: 2 additions & 2 deletions ilab-media-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/interfacelab/ilab-media-tools
Description: Automatically upload media to Amazon S3 and integrate with Imgix, a real-time image processing CDN. Boosts site performance and simplifies workflows.
Author: interfacelab
Version: 4.2.23
Version: 4.2.25
Author URI: http://interfacelab.io
*/
// Copyright (c) 2016 Interfacelab LLC. All rights reserved.
Expand Down Expand Up @@ -94,7 +94,7 @@
}

// Version Defines
define( 'MEDIA_CLOUD_VERSION', '4.2.23' );
define( 'MEDIA_CLOUD_VERSION', '4.2.25' );
define( 'MEDIA_CLOUD_INFO_VERSION', '4.0.2' );
define( 'MCLOUD_IS_BETA', false );
// Directory defines
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires at least: 4.9
Tested up to: 5.7
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Stable tag: 4.2.23
Stable tag: 4.2.25
Requires PHP: 7.1

Automatically store media on Amazon S3, Google Cloud Storage, DigitalOcean Spaces + others. Serve CSS/JS assets through CDNs. Integrate with Imgix.
Expand Down Expand Up @@ -105,6 +105,12 @@ Imgix is a content delivery network with a twist. In addition to distributing y

== Changelog ==

= 4.2.25 =

* HOT FIX: Fix for fatal error if Beaver Builder Pro is installed and Compatibility Manager is enabled.
* Fix for EDD integration with variable product pricing
* Added option to EDD integration that enables downloading the original unscaled image when the download is an image.

= 4.2.23 =

* More fixes for srcset generation.
Expand Down

0 comments on commit d1435f7

Please sign in to comment.