jQuery error (tinyMCE is not defined) on Wordpress admin panel

后端 未结 4 653
忘了有多久
忘了有多久 2021-01-06 11:36

After upgrading Wordpress from 3.2 to 3.5 i am getting jQuery error on admin side. below is the error.

Error: ReferenceError: tinyMCE is not defined
Source F         


        
4条回答
  •  情深已故
    2021-01-06 12:05

    For anyone else that comes across this and is pulling their hair out a bit, @dale3h's answer was the solution for me.

    If you have a function in your functions.php which hooks into the script_loader_tag filter and doesn't always return the appropriate parts of the original tag markup, or has a bug in it of some kind, it can make some scripts fail to load because scripts to be output to the page are run through this filter first.

    Something I've done to avoid this is whitelist script handles depending on what extra attributes I want to give them, so the work can be done conditionally (leaving all other scripts intact):

    // Manage extra attibutes for enqueued scripts
    function foo_script_extras( $tag, $handle, $src ){
    
        $whitelist = array(
            'js-font-awesome-core'  => array(
                'sri'   => 'sha384-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
                'defer' => true
            ),
            'js-font-awesome-light' => array(
                'sri'   => 'sha384-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
                'defer' => true
            ),
            'js-popper'             => array(
                'sri'   => 'sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ'
            ),
            'js-bootstrap'          => array(
                'sri'   => 'sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm'
            ),
            'js-gtag'               => array(
                'async' => true
            )
        );
    
        // Construct the script if we want to give it extra attributes
        if( array_key_exists( $handle, $whitelist ) ){
    
            // Extra markup
            $extra  = '';
            $mods   = $whitelist[$handle];
    
            // Check for SRI
            if( array_key_exists( 'sri', $mods ) ){
                $extra .= ' integrity="' . $mods['sri'] . '" crossorigin="anonymous"';
            }
    
            // Check for deferral
            if( array_key_exists( 'defer', $mods ) ){
                $extra .= ' defer';
            }
    
            // Check for async
            if( array_key_exists( 'async', $mods ) ){
                $extra .= ' async';
            }
    
            // Reutrn full script tag
            return '';
    
        }else{
    
            // Return the tag as-is otherwise to avoid breaking it
            return $tag;
    
        }
    
    }
    add_filter( 'script_loader_tag', 'foo_script_extras', 10, 3 );
    

    This is not a terribly general solution in terms of checking for which attributes to add to the whitelisted handles, and I would have used something along the lines of "for each attribute of a whitelisted handle, add the key if it's a bool and is true, else add it's value" but SRI needs two attributes (integrity and crossorigin) so I've left it for now.

    Additionally, if you don't see /wp-includes/js/tinymce/ somewhere in your page markup (similar to what @Mar said, but the exact script name can change between versions it seems) then that script ain't loading!

提交回复
热议问题