Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

[WIP] Post editor enhancements #222

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open

Conversation

mohdsayed
Copy link
Contributor

No description provided.

@westonruter
Copy link
Contributor

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() {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

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

Successfully merging this pull request may close these issues.

2 participants