-
Notifications
You must be signed in to change notification settings - Fork 61
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
Update cmb2-conditionals.php #45
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,13 @@ | |
* | ||
* @wordpress-plugin | ||
* Plugin Name: CMB2 Conditionals | ||
* Plugin URI: https://github.com/jcchavezs/cmb2-conditionals | ||
* Plugin URI: https://github.com/yaronguez/cmb2-conditionals | ||
* Description: Plugin to establish conditional relationships between fields in a CMB2 metabox. | ||
* Author: José Carlos Chávez <[email protected]> | ||
* Author URI: http://github.com/jcchavezs | ||
* Github Plugin URI: https://github.com/jcchavezs/cmb2-conditionals | ||
* Github Plugin URI: https://github.com/yaronguez/cmb2-conditionals | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert the change to the plugin URI. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I performed that commit after making the pull request in order to use this fork on my own site in the meantime. I assumed it wouldn't be added to the request. I'll move it to a different branch instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
* Github Branch: master | ||
* Version: 1.0.4 | ||
* Version: 1.0.5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Version nr changes should be determined by the plugin owner, not by a random PR. Please revert. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I performed that commit after making the pull request in order to use this fork on my own site in the meantime. I assumed it wouldn't be added to the request. I'll move it to a different branch instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
* License: GPL v3 | ||
* | ||
* Copyright (C) 2015, José Carlos Chávez - [email protected] | ||
|
@@ -83,13 +83,10 @@ class CMB2_Conditionals { | |
/** | ||
* Constructor - Set up the actions for the plugin. | ||
*/ | ||
public function __construct() { | ||
if ( ! defined( 'CMB2_LOADED' ) || false === CMB2_LOADED ) { | ||
return; | ||
} | ||
public function __construct() { | ||
|
||
add_action( 'admin_init', array( $this, 'admin_init' ), self::PRIORITY ); | ||
add_action( 'admin_footer', array( $this, 'admin_footer' ), self::PRIORITY ); | ||
add_action( 'cmb2_admin_init', array( $this, 'admin_init' ), self::PRIORITY ); | ||
add_action( 'cmb2_footer_enqueue', array( $this, 'admin_footer' ), self::PRIORITY ); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly (but I could well be wrong), these hooks weren't always available in CMB2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like cmb2_admin_init was added August 30, 2015, during version 2.1.0. cmb2_footer_enqueue was added February 15, 2017 during version 2.2.3.1. The problem with checking the version of CMB2 before adding these hooks is that often times this plugin could be loaded before CMB is, hence the point of the fork to begin with. I'll clearly annotate the requirement and resubmit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the requirement to README.MD. Are there any other areas it should? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For the
That's what the If it doesn't, I would suggest adding an additional if/else within the conditional around that line to also check if ( ( function_exists( 'wp_installing' ) && wp_installing() === false ) || ( ! function_exists( 'wp_installing' ) && ( ! defined( 'WP_INSTALLING' ) || WP_INSTALLING === false ) ) ) {
if ( did_action( 'plugins_loaded' ) > 0 ) {
cmb2_conditionals_init();
} else {
add_action( 'plugins_loaded', 'cmb2_conditionals_init' );
}
}
|
||
foreach ( $this->maybe_required_form_elms as $element ) { | ||
add_filter( "cmb2_{$element}_attributes", array( $this, 'maybe_set_required_attribute' ), self::PRIORITY ); | ||
|
@@ -100,10 +97,7 @@ public function __construct() { | |
* Decide whether to include the js-script or not. | ||
*/ | ||
public function admin_footer() { | ||
if ( ! in_array( $GLOBALS['pagenow'], array( 'post-new.php', 'post.php' ), true ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you removing this ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer necessary. cmb2_footer_enqueue takes care of determining which page the JavaScript should load on. Alternatively, admin_enqueue_scripts is the correct way to add scripts to an admin page, checking the parameter to determine the page rather than admin_footer and checking $GLOBALS['pagenow']. See https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly, there were reasons why this was done this way, not in the least as people apparently are also using this plugin on the front-end. |
||
return; | ||
} | ||
|
||
|
||
wp_enqueue_script( | ||
'cmb2-conditionals', | ||
plugins_url( '/cmb2-conditionals.js', __FILE__ ), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert the change to the plugin URI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I performed that commit after making the pull request in order to use this fork on my own site in the meantime. I assumed it wouldn't be added to the request. I'll move it to a different branch instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.