• When I activate the plugin I get the following error. My test site has errors being displayed so I can catch things like this.

    Notice: is_feed was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in xtremelysocial.com/test/wp-includes/functions.php on line 3547

    This happens even when I turn OFF all options within the plugin. Meaning it happens even when no javascript, CSS, or HTML is being minified.

    Since the error is happening within WordPress core itself, this is really hard to try to debug. I’m very proficient with PHP and WordPress (I have 4 themes on WordPress.org), but I’d need to be pointed in the right direction from the standpoint of this particular plugin as I’m not familiar with it.

    https://wordpress.org/plugins/wp-minify-fix/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Tim Nicholson

    (@timnicholson)

    I see no way to fix this other than to modify the code. The offending call to is_feed() is done right when the plugin class is created. That’s why just activating the plugin creates the error. Obviously I can remove that check for is_feed(). I’m sure that won’t negatively impact the plugin, but it will call the minification utility for each hit to the RSS feed.

    There has to be a better way to filter on when the minification should occur, but I’ve not written plugins like this to have a good suggestion. Other than the generic suggestion to go ahead and add the init and wp_footer actions, but then check for is_feed() in those functions and bail out. I’m not 100% sure is_feed() can be called in init, though, without literally testing it.

    function WPMinify() {
        // initialize common functions
        $this->c = new WPMinifyCommon($this);
    
        // load translation
        $this->c->load_text_domain();
    
        // register admin scripts
        add_action('admin_init', array($this->c, 'a_register_scripts'));
        add_action('admin_init', array($this->c, 'a_register_styles'));
    
        // check wp version
        add_action('admin_head', array($this->c, 'a_check_version'));
    
        // load admin menu
        add_action('admin_menu', array($this, 'a_menu'));
    
        // register ajax handler
        add_action('wp_ajax_wpm', array($this, 'a_ajax_handler'));
    
        // No need to minify admin stuff
        if (!is_admin() && !is_feed() && !defined('XMLRPC_REQUEST')) {
          // Don't minify if if user passes wp-minify-off=1 in GET parameter
          if (!(isset($_GET['wp-minify-off']) && $_GET['wp-minify-off'])) {
            add_action('init', array($this, 'pre_content'), 99999);
            add_action('wp_footer', array($this, 'post_content'), 99999);
          }
          // advertise hook
          add_action('wp_footer', array($this, 'advertise'));
        }
      }
    Thread Starter Tim Nicholson

    (@timnicholson)

    Ok, that works perfectly. It would be great if you could update the plugin. Get rid of the call to is_feed() where it is. TRN are my initials, so this is how I “mod mark” adds and deletes

    // No need to minify admin stuff
        //TRN:DEL if (!is_admin() && !is_feed() && !defined('XMLRPC_REQUEST')) {
        if (!is_admin() && !defined('XMLRPC_REQUEST')) { //TRN:ADD

    Then add the check in function pre_content() and post_content() like this:

    function pre_content() {
      	if ( is_feed() ) return; //TRN:ADD
        $wpm_options = get_option($this->name);
        if ($wpm_options['uri_exclude'] && count($wpm_options['uri_exclude'])) {
          foreach ($wpm_options['uri_exclude'] as $exclude_pat) {
            $exclude_pat = trim($exclude_pat);
            if (strlen($exclude_pat) > 0 && strpos($_SERVER['REQUEST_URI'], $exclude_pat) !== false) {
              return;
            }
          }
        }
    function post_content() {
      	if ( is_feed() ) return; //TRN:ADD
        // sanity checking
        if ($this->buffer_started) {
          ob_end_flush();
        }
      }

    I’m surprised this error doesn’t happen for everyone using the plugin. I guess maybe most people don’t have a test site or don’t have errors turned on.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Plugin causing PHP errors on is_feed() function’ is closed to new replies.