ClassicPress 2.1.0 Release Notes

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:

/**
 * Scripts
 */

Immediately under that, try adding this:

		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;
			}
		}

Again, this won’t upset anything if Bricks is run on WP because the condition won’t be fulfilled there, so the code won’t do anything.

1 Like

@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.

2 Likes

@timkaye Which file do I change using this code?

Same file as before: ~/includes/setup.php

1 Like

I’ve tried it, and finally the problem is solved! Thank you for helping until now. I’ll try to report to Bricks Builder about this.

Have a wonderful day. :innocent:

1 Like

Congrats :-))

1 Like

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;
}

Would like to report that Bricks Builder 1.11 runs with the code snippet hack above ror CP 2.2; however, the post widget throws an error.

Working with shortcodes to output posts as an alternative.

Still testing all other components.

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.

1 Like

I just want to mention a thank you to all who have worked on this update and keeping ClassicPress moving along. :pray:

Like many here, I am pleased to have a viable alternative to WordPress.

2 Likes

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.

2 Likes

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

Then I suspect you have something else going on there. I suggest clearing caches and checking for a theme or other plugin conflict.

I have only 1 plugin: Polylang and Bricks as only theme, clearing caches din not make any difference.

It’s working for everyone else. Where did you put the code?

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 );
	}

I wouldn’t put it there. It needs to go somewhere that ensures that it loads before Bricks starts up. I’d put it in an mu-plugin.

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:

<?php
/*
  Plugin Name: Bricks Builder Fixer for ClassicPress
*/

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;
	}
}

but just got the following error message:

*** edited to make it easier to read by @tpnsolutions ***

You need to put the inside a function, just as you had it before (but choose a different name) and hook it to the same hook as before.

Hi again,

I put it inside the function “fix_bricks_in_cp()”, in file “fix-bricks-in-cp.php”, in “wp-content\mu-plugins”:

// begins file
public function fix_bricks_in_cp() {
/**
* Fix Bricks Builder in ClassicPress
*/

// 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;
	}
}

}

fix_bricks_in_cp();

// ends file

but got an error message:
public function fix_bricks_in_cp() { /** * Fix Bricks Builder in ClassicPress / // 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; } } } fix_bricks_in_cp();