WordPress.org

Ready to get started?Download WordPress

Forums

Simple Pull Quote
wp_enqueue_script missing dependency (2 posts)

  1. Aaron D. Campbell
    Member
    Posted 1 year ago #

    When you enqueue simple-pull-quote.js you should set 'quicktags' as a dependency since it needs the 'edButtons' variable that is created there. Adding one more parameter with to the call takes care of it:

    function simplePullQuotes() {
    	wp_enqueue_script(
    		'simple-pull-quotes',
    		plugin_dir_url(__FILE__) . 'simple-pull-quote.js',
    		array('quicktags')
    	);
    }

    Without that, the button on the HTML editor doesn't work if the pull-quote JS is loaded before quicktags. Also, on many pages it causes a JS error which makes the flyout nav not work properly.

    Another suggestion would be to write a function to determine if that JS should be loaded (only needed if there's an editor to add buttons to). After the Deadline adds a button like you, and it uses a function like this to determine if it should:

    /* Helper used to check if javascript should be added to page. Helps avoid bloat in admin */
    function AtD_should_load_on_page() {
    	global $pagenow, $current_screen;
    
    	$pages = array( 'post.php', 'post-new.php', 'page.php', 'page-new.php', 'admin.php', 'profile.php' );
    
    	if ( in_array( $pagenow, $pages ) ) {
    		if ( isset( $current_screen->post_type ) && $current_screen->post_type ) {
    			return post_type_supports( $current_screen->post_type, 'editor' );
    		}
    		return true;
    	}
    
    	return apply_filters( 'atd_load_scripts', false );
    }

    http://wordpress.org/extend/plugins/simple-pull-quote/

  2. Toby Cryns (@themightymo)
    Member
    Plugin Author

    Posted 1 year ago #

    @aaroncampbell - Thank you so much for this advice and code samples. I will release a fix next week.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.