-
Notifications
You must be signed in to change notification settings - Fork 37
[WIP] Post editor enhancements #222
base: develop
Are you sure you want to change the base?
Conversation
FYI: There are merge conflicts. |
@@ -51,6 +51,94 @@ public function enqueue() { | |||
} | |||
|
|||
/** | |||
* Hooked to `customize_controls_enqueue_scripts` from `WP_Customize_Posts` class. | |||
*/ | |||
public static function enqueue_scripts() { |
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.
@sayedwp Actually, maybe you should switch back to using the non-static
enqueue()
method, but then have a static
class variable to capture whether the enqueue has been called:
static protected $enqueued = false;
public function enqueue() {
if ( self::$enqueued ) {
return;
}
self::$enqueued = true;
// ...
}
Then you can avoid WP_Customize_Posts
from having direct awareness of this class's methods and so could remove:
add_action( 'customize_controls_enqueue_scripts', array( 'WP_Customize_Post_Editor_Control', 'enqueue_scripts' ) );
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.
@westonruter enqueue
method never executes until we add control using add_control
. So currently enqueue
is just sitting there and not doing anything, we are enqueueing the script as a dependency from register_scripts
in Customize_Posts_Plugin
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.
OK, good point. I'd consider this a deficiency in the WP_Customize_Manager::register_control_type()
that it doesn't call the enqueue
method.
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 think that's because when we register the control type, it just renders the template
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-customize-manager.php#L1517-L1543
However the actual enqueue method is called when we use add_control
of WP_Customize_Manager
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-customize-manager.php#L1633-L1636
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-customize-manager.php#L1471-L1479
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.
Also we should be able to use customize_controls_enqueue_scripts
from inside the WP_Customize_Post_Editor_Control
construct but we cannot do that because render_control_template
is hooked into customize_controls_print_footer_scripts
which is at the footer and customize_controls_enqueue_scripts
is in the header, so already late.
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-customize-manager.php#L301
https://github.com/WordPress/WordPress/blob/master/wp-admin/customize.php#L63-L185
However if we use add_control
I think then it should be working because its hooked into customize_register
.
No description provided.