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

Conversation

ChrisFlannagan
Copy link

Change the hook for init of the plugin from plugins_loaded to after_setup_theme so those who include cmb2 in their theme can use it

Add php storm files to gitignore

@ChrisFlannagan
Copy link
Author

@jcchavezs Hey, I've never really used phpsniffer much sorry about all the commits. Just had to make a change to get this working in a theme so figured I'd send you a PR

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants