The problem here is that there are so many scripts being run here, that it seems if we upset one then the rest malfunctions. So, rather than attempt to get the scripts running in the correct order by manually specifying what depends on what, I think the best approach is to have Bricks simply reset the scripts to the order it’s expecting.
In order to do that, please revert that line to what it was before. Then, just above it, you’ll see a heading:
@timkaye - I have tested and can confirm this seems to fix things. Amazing work trawling through such a massive code set and that’s an impressive and elegant fix solution.
@byzt - Please do give that a try and maybe escalate that to Bricks developers, having reviewed their code the dependency management could do with some TLC.
I have no idea if key sorting the an array while iterating though it could cause a problem (or even if it’s necessary to do so) but it jumped out at me as something I’ve had edge case problems in the past.
Anyway if it does cause problems here’s an alternative.
global $wp_scripts;
$deps = $wp_scripts->registered['media-views']->deps;
$foundKey = false;
// Find the element and mark the position
foreach ( $deps as $key => $dep ) {
if ( $dep === 'sortable-js' ) {
$foundKey = $key;
break;
}
}
// Modify the array after the iteration
if ( $foundKey !== false ) {
unset( $deps[$foundKey] );
$deps[$foundKey] = 'jquery-ui-sortable';
ksort( $deps );
$wp_scripts->registered['media-views']->deps = $deps;
}
You probably need to apply the same snippet somewhere else in the code to have it work with the widget. If you’d like me to take another look, you’ll need to send me a copy of the plugin zip file.
Hello,
I have a license of Bricks Builder, so asked Bricks developers to make Bricks full compatible to ClassicPress, because that is good for both.
Thanks.
Hello,
I tried your fix (ClassicPress 2.3.1, Bricks 1.11.1.1) but did not work, the error with images still there: editing a page with bricks, insert image component, then when click on “SELECT IMAGE” nothing happens.
Thanks
Hello,
I put the code inside “setup.php” (C:\Users\user\Local Sites\bricks-classicpress\app\public\wp-content\themes\bricks\includes), here is a part of that file:
/**
* On theme deactivation
*
* Delete license data transient (hack to manually flush license data before transient expires)
*
* TODO: Add redirect after theme deactivation to collect feedback via 'https://codex.wordpress.org/Plugin_API/Action_Reference/switch_theme'
*
* @since 1.0
*/
public function switch_theme() {
delete_transient( 'bricks_license_status' );
}
/**
* Register styles and scripts to enqueue in builder and frontend respectively
*
* @since 1.0
*/
public function enqueue_scripts() {
/**
* Styles
*/
// Load frontend CSS files OR inline styles (default: inline style)
if ( Database::get_setting( 'cssLoading' ) !== 'file' || bricks_is_builder() ) {
wp_enqueue_style( 'bricks-frontend', BRICKS_URL_ASSETS . 'css/frontend.min.css', [], filemtime( BRICKS_PATH_ASSETS . 'css/frontend.min.css' ) );
} else {
wp_enqueue_style( 'bricks-frontend', BRICKS_URL_ASSETS . 'css/frontend-light.min.css', [], filemtime( BRICKS_PATH_ASSETS . 'css/frontend-light.min.css' ) );
}
if ( is_rtl() ) {
wp_enqueue_style( 'bricks-frontend-rtl', BRICKS_URL_ASSETS . 'css/frontend-rtl.min.css', [], filemtime( BRICKS_PATH_ASSETS . 'css/frontend-rtl.min.css' ) );
}
/**
* Scripts
*/
global $wp_scripts;
$deps = $wp_scripts->registered['media-views']->deps;
foreach ( $deps as $key => $dep ) {
if ( $dep === 'sortable-js' ) {
unset( $deps[$key] );
$deps[$key] = 'jquery-ui-sortable';
ksort( $deps );
$wp_scripts->registered['media-views']->deps = $deps;
break;
}
}
// Contains common JS libraries & Bricks-specific frontend.js init scripts
wp_enqueue_script( 'bricks-scripts', BRICKS_URL_ASSETS . 'js/bricks.min.js', [], filemtime( BRICKS_PATH_ASSETS . 'js/bricks.min.js' ), true );
// Enqueue query filters JS (@since 1.9.6)
if ( Helpers::enabled_query_filters() ) {
wp_enqueue_script( 'bricks-filters', BRICKS_URL_ASSETS . 'js/filters.min.js', [ 'bricks-scripts' ], filemtime( BRICKS_PATH_ASSETS . 'js/filters.min.js' ), true );
}
// Element Form (setting: enableRecaptcha)
$recaptcha_api_key = Database::$global_settings['apiKeyGoogleRecaptcha'] ?? false;
$recaptcha_language = Database::$global_settings['recaptchaLanguage'] ?? false;
if ( ! bricks_is_builder() && $recaptcha_api_key ) {
$recaptcha_script_url = "https://www.google.com/recaptcha/api.js?render=$recaptcha_api_key";
if ( $recaptcha_language ) {
$recaptcha_script_url .= "&hl=$recaptcha_language";
}
wp_register_script( 'bricks-google-recaptcha', $recaptcha_script_url, null, true );
}
Hi,
I put the code in the file “bricks-builder-fixer-for-classicpress.php”, then put that file inside of “wp-content\mu-plugins” folder, the content of “bricks-builder-fixer-for-classicpress.php” is: