Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will not work when including cmb2 in a theme #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
composer.lock
.idea
4 changes: 2 additions & 2 deletions cmb2-conditionals.php → class-cmb2-conditionals.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ protected function filter_field_data_to_save( $data_to_save, $field_id, $conditi
* check can be removed once the min version for this plugin has been upped to 4.4.}}
*/
if ( ( function_exists( 'wp_installing' ) && wp_installing() === false ) || ( ! function_exists( 'wp_installing' ) && ( ! defined( 'WP_INSTALLING' ) || WP_INSTALLING === false ) ) ) {
add_action( 'plugins_loaded', 'cmb2_conditionals_init' );
add_action( 'after_setup_theme', 'cmb2_conditionals_init' );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something like:

if ( did_action( 'plugins_loaded' ) === 0 ) {
	add_action( 'plugins_loaded', 'cmb2_conditionals_init' );
} elseif ( did_action( 'after_setup_theme' ) === 0 ) {
	add_action( 'after_setup_theme', 'cmb2_conditionals_init' );
} else {
	cmb2_conditionals_init();
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like that could work with the class check. You think all those checks are necessary though? Would there be a time when after_setup_theme would be too late to init that you can think of?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrfnl K, gave it a shot but that doesn't work as it's still initializing before the theme loads CMB2 so the javascript never gets loaded. If you'll want this to be compatible with theme embeds you'll need to do something like this PR suggests.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any feedback on this one @jrfnl?

}

if ( ! function_exists( 'cmb2_conditionals_init' ) ) {
Expand All @@ -264,4 +264,4 @@ function cmb2_conditionals_init() {
$cmb2_conditionals = new CMB2_Conditionals();
}
}
} /* End of class-exists wrapper. */
} // End if().