Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP warning messages #338

Closed
cinghaman opened this issue Mar 27, 2019 · 10 comments
Closed

PHP warning messages #338

cinghaman opened this issue Mar 27, 2019 · 10 comments

Comments

@cinghaman
Copy link

I keep seeing PHP warning messages on top of all the pages, I have already updated wp-config.php file with
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_DISPLAY', false );

And also added log_errors = Off in .user.ini file
I have checked my phpinfo.php file as well and it shows error as off.

The server is azure, can you please point me how to disable these warnings

@patrickebates
Copy link
Member

Sounds like you might have themes and/or plugins which are not ready for PHP 7.2. What happens if you lower the PHP version to 7.1 or 7.0? I am assuming you are running the site on Azure Web Apps, so the setting will be found in Application Settings.

@cinghaman
Copy link
Author

@patrickebates I am using PHP Version 7.0.33
These are the warning which is showing up

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1474

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1474

Warning: array_merge(): Argument #1 is not an array in D:\home\site\wwwroot\wp-includes\fields_map.php on line 200

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1655

Warning: array_merge(): Argument #1 is not an array in D:\home\site\wwwroot\wp-includes\fields_map.php on line 200

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1655

@patrickebates
Copy link
Member

Not sure what you are seeing there. Is this a new site, or something which has been running for some time?

@cinghaman
Copy link
Author

It's an old site has been running for a while
I get long list of these warning and then the full site loads, functionality wise everything is working but can't find a way to disable/hide these php warning

and also not sure why settings for debug are not being picked from wp-config.php

@patrickebates
Copy link
Member

Look for a file /wp-includes/fields_map.parsed_types.php and if you find it, rename it. Let's see if that has an impact.

@cinghaman
Copy link
Author

@patrickebates when i rename it, the site crashes, and in any case i should not be messing with core files as when the WP gets updated it would be overwritten

@cinghaman
Copy link
Author

Issue is with these two plugins
WP Google Maps
Ultimate Member

Looks like the function they use does not work with the configuration of projectnami WordPress.

@patrickebates
Copy link
Member

patrickebates commented Mar 27, 2019

fields_map.parsed_types.php is not directly a part of PN core. It's like a log of modifications made to schema for tables which plugins have tried to create. We've seen a few issues where that file can become corrupt (usually when one of the logged plugins has been updated), so removing or renaming it triggers the creation of a new, empty file.

Your case seems different, and probably was related to the plugins as you pointed out. Some plugins simply don't work with Project Nami.

@tsdexter
Copy link

tsdexter commented Jan 6, 2020

@cinghaman did you ever find a fix for this? We have the same issue and are temporarily working around it by removing the errors/warnings from the final wordpress output like this which is essentially splitting the PHP output on the <DOCTYPE> tag and removing the first part which is the PHP warnings - as well, we've found some cases where there are errors within the HTML content, for those ones we have to added the individual errors to the array below to have them replaced with empty strings:

  /** remove warning/error output from wordpress/azure bug */
  public function filterDisplayErrorsOutput($string) {
    $returnString = '';
    if (wp_doing_ajax()) {
      // remove errors that show up in ajax calls
      $errorRemoved = str_replace('Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1476', "", $string);
      $returnString = trim($errorRemoved);
    } else {
      if (strpos($string, '<!DOCTYPE html>') !== false) {
        $newoutput = explode("<!DOCTYPE html>", $string);
        $returnString = "<!DOCTYPE html>" . $newoutput[1];
      } else if (strpos($string, '<?xml version="1.0" encoding="UTF-8"?>') !== false) {
        // filter XML / RSS output separately from HTML
        $newoutput = explode('<?xml version="1.0" encoding="UTF-8"?>', $string);
        $returnString = '<?xml version="1.0" encoding="UTF-8"?>' . $newoutput[1];
      } else {
        $returnString = $string;
      }
    }
   
    // remove errors within the HTML output
    $filtered = str_replace(
      array(
        'Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1283',
        'Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1476'
      ),
      array(""),
      $returnString
    );
    return trim($filtered);
  }

Then we call it in a final_output filter like this:

add_filter('final_output', function ($output) {
  global $gct;
  return $gct->filterDisplayErrorsOutput($output);
});

final_output is called from a mu-plugin like this which essentially adds all of the PHP output to a buffer and allows you to modify it before it's sent to the browser.

/**
 * Output Buffering
 *
 * Buffers the entire WP process, capturing the final output for manipulation.
 */

ob_start();

add_action('shutdown', function () {
  $final = '';

  // We'll need to get the number of ob levels we're in, so that we can iterate over each, collecting
  // that buffer's output into the final output.
  $levels = ob_get_level();

  for ($i = 0; $i < $levels; $i++) {
    $final .= ob_get_clean();
  }

  // Apply any filters to the final output
  echo apply_filters('final_output', $final);
}, 0);

Lastly, we've modified the PN Blob Cache plugin as it sends the PHP output to Azure blob cache before the output_filter is run so the errors/warnings get cached - we made a PR here: ProjectNami/projectnami-blob-cache#18

This is run with a filter like this:

add_filter('pn_cached_content', function ($content, $url, $key) {
  global $gct;

  // add some meta tags so we know if it's a cache hit or PHP hit as well as the cached URL and key for deleting/debugging directly in azure blob storage 
  $modified_content = str_replace("<head>", "<head>\n<meta name=\"FILTEREDCACHE\">\n<meta name=\"CACHEURL\" content=\"{$url}\">\n<meta name=\"CACHEKEY\" content=\"{$key}\">", $content);
  
  // filter the warnings with the function from above
  return $gct->filterDisplayErrorsOutput($modified_content);
}, 1, 3);

@cinghaman
Copy link
Author

@tsdexter unfortunately no, I abandoned the project in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants