WordPress.org

Ready to get started?Download WordPress

Forums

Trouble when updating to 3.3 or 3.3.1 [Warning: Headers Already Sent] (8 posts)

  1. consultor
    Member
    Posted 2 years ago #

    updating from 3.2.1 to 3.3 or 3.3.1 gives me the following warning

    wp_register_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks. Please see Debugging in WordPress for more information. (Este mensaje se añadió en la versión 3.3.) in /.../wp-includes/functions.php on line 3587

    I know turning off debug mode and followed the updating instructions , but i manage clients sites who oversees technical issues and debug mode should prove an optimal job...

    similar issue was reported here:
    http://wordpress.org/support/topic/major-trouble-with-33-update-cant-access-wp-admin?replies=4#post-2561750... .

    any ideas how can be fixed this error [headers already sent] ?

  2. Peter Wooster
    Member
    Posted 2 years ago #

    As I answered on that thread, try turning off debug. That should allow you to complete the upgrade. If the problem returns after the upgrade is complete you will need to contact the plugin author.

    This register warning is new to 3.3 I believe. One of plugins I use is doing this at present, so I should be able to post a proper fix once I sort that out.

    /peter

  3. consultor
    Member
    Posted 2 years ago #

    thanks pkwooster

    debug mode turned off is not the solution I look for

    I run dev and production environment doing clones of my wp 3.2.1 site with Duplicator plugin [backup manager], and then trying the following for updating:

    I deactivated all plugins before update, same warning after install
    I deleted all plugins before update, same warning after install

    I tried update from 3.2.1 to 3.3 or 3.3.1, same warning.

    what else should I try?

  4. Peter Wooster
    Member
    Posted 2 years ago #

    I've sorted it out, in my case it's in the theme. The code is in functions.php and looks like:

    if(!is_admin()){
           wp_deregister_script('jquery');
           wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"), false, '1.7.1');
           wp_enqueue_script('jquery');
           wp_deregister_script('jquery-ui');
           wp_register_script('jquery-ui',("http//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"), false, '1.8.16');
           wp_enqueue_script('jquery-ui');
        }

    The correct code is:

    function enqueue_scripts() {
           wp_deregister_script('jquery');
           wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"), false, '1.7.1');
           wp_enqueue_script('jquery');
           wp_deregister_script('jquery-ui');
           wp_register_script('jquery-ui',("http//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"), false, '1.8.16');
           wp_enqueue_script('jquery-ui');
     }
    add_action('wp_enqueue_scripts', 'enqueue_scripts');

    The wp_enqueue_scripts action is mentioned in the error message but isn't documented in the plugin api yet. What it does is described in the comments in script_loader.php

    * Wrapper for do_action('wp_enqueue_scripts')
     *
     * Allows plugins to queue scripts for the front end using wp_enqueue_script().
     * Runs first in wp_head() where all is_home(), is_page(), etc. functions are available.
     *
     * @since 2.8

    So all you need to do is find the call to wp_register_script that is not inside an action function that is in open code or in a function that is called before init or wp_enqueue_scripts. Then change the code to be called from the action.

    /peter

  5. consultor
    Member
    Posted 2 years ago #

    thanks peter

    using Corona theme but no related refeence in its functions.php file

    in wp-includes/script-loader.php file, I have the following call:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    I don't know what to modify

  6. Peter Wooster
    Member
    Posted 2 years ago #

    The problem is likely to be in the theme or a plugin. In my other post on this topic I provide a way to determine what is causing the problem. You need to make the code that produces the error to throw an exception instead when wp_register_script or wp_deregister_script is called improperly.

    Here is the code in wp-includes/functions.php near line 3484:

    function _doing_it_wrong( $function, $message, $version ) {
    	do_action( 'doing_it_wrong_run', $function, $message, $version );
    	// Allow plugin to filter the output error trigger
    	if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
    throw(new Exception('Testing'));  // line added to force an exception <<<<<<<<<<<<<<<<<<
                	$version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version );
    		$message .= ' ' . __( 'Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.' );
    		trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
    	}
    }

    After you do this the site will dump a stack trace and die. The stack trace will include the line that caused the error instead of just the line that's reporting it. That report will look something like what I get on my site when the code is wrong:

    Fatal error: Uncaught exception 'Exception' with message 'Testing' in /Users/peter/NetBeansProjects/Devondev/wp-includes/functions.php:3585
    Stack trace:
    #0 /Users/peter/NetBeansProjects/Devondev/wp-includes/functions.wp-scripts.php(110): _doing_it_wrong('wp_deregister_s...', 'Scripts and sty...', '3.3')
    #1 /Users/peter/NetBeansProjects/Devondev/wp-content/themes/devondev/functions.php(291): wp_deregister_script('jquery')
    …

    The string starting with #1 is the user function that called wp_deregister_script improperly. It was in the devondev theme at line 291 in functions.php.

    /peter

  7. Peter Wooster
    Member
    Posted 2 years ago #

    I'm putting together a plugin that will let you control the way errors are displayed without having to hack at the WordPress core. I'll let you know when it's ready.

    /peter

  8. Peter Wooster
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic