• Resolved happysolicitor

    (@happysolicitor)


    To my surprise, when creating a new admin page, the syntax highlighting isn’t loaded when I use the wp_editor() method.

    Going through your code I see in the PHP script for the plugin that you have hardcoded which pages it can display on:

    	public function __construct () {
    		add_action( 'admin_init', array(&$this, 'hesh_set_options') );
    		add_action( 'wp_ajax_'.$this->formProcessName, array(&$this, 'hesh_options_form_process'));
    		// Load only on certain pages
    		if (
    			!strstr($_SERVER['SCRIPT_NAME'], 'post.php') && 
    			!strstr($_SERVER['SCRIPT_NAME'], 'post-new.php') &&
    			!strstr($_SERVER['SCRIPT_NAME'], 'editor.php')
    		) return;
    		add_action( 'admin_enqueue_scripts', array(&$this, 'hesh_admin_enqueue_scripts' ) );
    		add_action( 'admin_footer', array(&$this, 'hesh_output_form') );
    		add_action( 'admin_notices', array(&$this, 'display_survey_notice' ));
    	}

    I would expect the syntax highlighting to be used anywhere that the TinyMCE editor is loaded. Instead, unless the page follows the strict restrictions you’ve made, then it won’t load.

    Is there at least a flag I can set in my theme or plugin to allow it to load on custom pages?

    Why not let people set these rules themselves in the editor’s settings?

    All in all, it seems silly to me that a plugin that’s supposed to expand the functionality of the editor will only do so if you’re on specific pages.

    I could understand this as default behavior with settings for choosing additional pages, but hard coding this in is kind of silly.

    In fact, I can’t even force the script to load because you’re using the hooks and enqueuing ONLY if it’s one of those pages.

    May I suggest that you instead ALWAYS add the hook and register the script separately?

    Then you could use enqueue separately only when the page rules match.

    Why?

    Because this would allow me to enqueue the necessary scripts from my theme or plugin and it would execute where I want it to ignore your rules.

    As it stands now, your hook is a part of the constructor and the page rules are tied directly to the constructor so the script isn’t registered or enqueued unless those page rules match.

    Hopefully I’ve misunderstood something?

    Is there anything I can do now to force the editor’s syntax highlighting to function on custom admin pages?

Viewing 1 replies (of 1 total)
  • Plugin Author James Bradford

    (@arniebradfo)

    A quick fix would be to comment out the ‘Load only on certain pages’ check in the constructor of your copy of the plugin:

    public function __construct () {
    	add_action( 'admin_init', array(&$this, 'hesh_set_options') );
    	add_action( 'wp_ajax_'.$this->formProcessName, array(&$this, 'hesh_options_form_process'));
    	// Load only on certain pages
    	// if (
    	//	!strstr($_SERVER['SCRIPT_NAME'], 'post.php') && 
    	//	!strstr($_SERVER['SCRIPT_NAME'], 'post-new.php') &&
    	//	!strstr($_SERVER['SCRIPT_NAME'], 'editor.php')
    	// ) return;
    	add_action( 'admin_enqueue_scripts', array(&$this, 'hesh_admin_enqueue_scripts' ) );
    	add_action( 'admin_footer', array(&$this, 'hesh_output_form') );
    	add_action( 'admin_notices', array(&$this, 'display_survey_notice' ));
    }

    That will make it load on every admin page.

    But help me out here @happysolicitor,

    Go to the github repo, fork it, replace the ‘Load only on certain pages’ check with an ‘is TinyMCE enqueued’ check, and submit a pull request. I’ll test it and release an update.

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘Force execution for custom admin pages?’ is closed to new replies.