简体   繁体   中英

Wordpress - 'strpos() empty needle' and 'cannot modify header' warnings

Months ago, I have placed a 301 redirect rule in my .htaccess file to redirect all the www request to a non-www request.

The problem is two days ago, when I tried to access my example.net site using www.example.net I get the following warnings in the page and website is not loaded.

http://i.stack.imgur.com/nXBMF.png

Here are the corresponding lines:

1. Plugin.php Line 647 = if ( strpos( $file, $realdir ) === 0 ){

Full function:

/**
 * Gets the basename of a plugin.
 *
 * This method extracts the name of a plugin from its filename.
 *
 * @since 1.5.0
 *
 * @param string $file The filename of plugin.
 * @return string The name of a plugin.
 */
function plugin_basename( $file ) {
    global $wp_plugin_paths;

    foreach ( $wp_plugin_paths as $dir => $realdir ) {
        if ( strpos( $file, $realdir ) === 0 ) { /** LINE 646 */
            $file = $dir . substr( $file, strlen( $realdir ) );
        }
    }

    $file = wp_normalize_path( $file );
    $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
    $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );

    $file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
    $file = trim($file, '/');
    return $file;
}

2. Pluggable.php Line 1178 = header("Location: $location", true, $status);

Full file: http://pastebin.com/0zMJZxV0

I use WordPress only to write some articles. My PHP knowledge is very basic and limited only to locate errors.

Please help me figure out the problem with this. As I have read from the Codex FAQ, they say that empty strings may be a culprit for the pluggable.php error. But I have no idea how to locate it and I have attached the file for your reference.

Please provide your suggestions to avoid this error in the future. Thanks in advance.

3. EDIT - wp setting file: (the error line - include_once( $plugin ); )

// Load active plugins.
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
    wp_register_plugin_realpath( $plugin );
    include_once( $plugin );
}
unset( $plugin );

The issue with the header information has been discussed in here: Cannot modify header information error in Wordpress . Could you give this a try and see whether this solves this part of your problem?.

On the other issue: try var_dump ($file) (for instance -- or echo $file ) to see what they actually contain.

Check your configuration path of plugins :

var_dump($wp_plugin_paths);

You've got an error because $realdir is empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM