• Hi guys,

    I am a theme developer and recently I’ve got a support ticket that your plugin is causing PHP errors with my theme.

    My theme is coded using strict PHP 7 standards and the PHP error reports an unexpected argument type returned into template_include WordPress filter hook. It seems like your plugin is returning NULL instead of expected string argument type.

    Could you please have a look at the code of your plugin and fix the issue? It seems the issue may be caused by WCFMmp_Rewrites->store_template() method within core/class-wcfmmp-rewrite.php file. The method is full of return statements and the possible fix could be to prepend actual returned value with (string) like so: return (string) $whatever_here;. This will force the output of string type as expected by WordPress (and my themes).

    Thanks and regards,

    Oliver

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WC Lovers

    (@wclovers)

    Fatal error:
    Uncaught TypeError:
    Argument 1 passed to WebManDesign\Eimear\Plugin\WooCommerce\Single::product_page_template_load() must be of the type string, null given,
    called in C:\wamp64\www\eimear\wp-includes\class-wp-hook.php on line 287
    and defined in C:\wamp64\www\eimear\wp-content\themes\eimear\includes\Plugin\WooCommerce\Single.php on line 168

    – But this error is for WooCommerce single product page.

    WCFM does not have any effect on this page templates. This is no way relate to store page and WCFMmp_Rewrites->store_template()

    Still if you thing some changes required then know me.

    function store_template( $template ) {
    		global $WCFM, $WCFMmp;
    		
    		if ( !WCFMmp_Dependencies::woocommerce_plugin_active_check() ) {
    			return $template;
    		}
    		
    		if( $WCFMmp->store_template_loaded ) return $template;
    		
    		$store_name = get_query_var( $this->wcfm_store_url );
    
    		if ( !empty( $store_name ) ) {
    			$store_user = get_user_by( 'slug', $store_name );
    			
    			remove_filter( 'template_include', array( 'WC_Template_Loader', 'template_loader' ) );
    			$WCFMmp->store_template_loaded = true;
    			
    			// no user found
    			if ( ! $store_user ) {
    				return get_404_template();
    			}
    
    			// check if the user is seller
    			if ( ! wcfm_is_vendor( $store_user->ID ) ) {
    				return get_404_template();
    			}
    			
    			// Disable Store URL Visit
    			if( apply_filters( 'wcfm_is_disable_store_url_access', false ) ) {
    				wp_safe_redirect( get_permalink( wc_get_page_id( 'shop' ) ) );
    				exit;
    			}
    			
    			// Check is store Online
    			$is_store_offline = get_user_meta( $store_user->ID, '_wcfm_store_offline', true );
    			$is_store_offline = apply_filters( 'wcfmmp_is_store_offline', $is_store_offline, $store_user->ID );
    			if ( $is_store_offline ) {
    				return get_404_template();
    			}
    			
    			// WCFM Marketplace Elementor Compatibility
    			$wcfmem_template = apply_filters( 'wcfmem_locate_store_template', '' );
    			if( $wcfmem_template ) return $wcfmem_template;
    			
    			// Dive Theme Builder Support
    			if( function_exists( 'et_theme_builder_frontend_override_template' ) ) {
    				$layouts         = et_theme_builder_get_template_layouts();
    				$override_header = et_theme_builder_overrides_layout( ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE );
    				$override_footer = et_theme_builder_overrides_layout( ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE );
    				if ( $override_header || $override_footer ) {
    					add_action( 'get_header', 'et_theme_builder_frontend_override_header' );
    					add_action( 'get_footer', 'et_theme_builder_frontend_override_footer' );
    						
    					et_theme_builder_frontend_enqueue_styles( $layouts );
    				}
    			}
    			
    			if ( get_query_var( $this->store_endpoint('about') ) ) {
    				return $WCFMmp->template->get_template( 'store/wcfmmp-view-store.php', array( 'store_tab' => 'about' ) );
    			} elseif ( get_query_var( $this->store_endpoint('policies') ) ) {
    				return $WCFMmp->template->get_template( 'store/wcfmmp-view-store.php', array( 'store_tab' => 'policies' ) );
    			} elseif ( get_query_var( $this->store_endpoint('reviews') ) ) {
    				return $WCFMmp->template->get_template( 'store/wcfmmp-view-store.php', array( 'store_tab' => 'reviews' ) );
    			} elseif ( get_query_var( $this->store_endpoint('followers') ) ) {
    				return $WCFMmp->template->get_template( 'store/wcfmmp-view-store.php', array( 'store_tab' => 'followers' ) );
    			} elseif ( get_query_var( $this->store_endpoint('followings') ) ) {
    				return $WCFMmp->template->get_template( 'store/wcfmmp-view-store.php', array( 'store_tab' => 'followings' ) );
    			} elseif ( get_query_var( $this->store_endpoint('articles') ) ) {
    				return $WCFMmp->template->get_template( 'store/wcfmmp-view-store.php', array( 'store_tab' => 'articles' ) );
    			} else {
    				return $WCFMmp->template->get_template( 'store/wcfmmp-view-store.php', array( 'store_tab' => apply_filters( 'wcfmmp_store_default_query_vars', apply_filters( 'wcfmp_store_default_query_vars', 'products', $store_user->ID ), 'products', $store_user->ID ) ) );
    			}
    		}
    
    		return $template;
    	}
    Thread Starter WebMan Design | Oliver Juhas

    (@webmandesign)

    Hi,

    – But this error is for WooCommerce single product page. WCFM does not have any effect on this page templates. This is no way relate to store page and WCFMmp_Rewrites->store_template()

    I’m sorry, but it is related and the issue is not for WooCommerce single product page. It’s just a name of the theme method that makes you think so.

    To explain, WordPress template_include filter hook is being executed on every front-end page. The WebManDesign\Eimear\Plugin\WooCommerce\Single::product_page_template_load() method is the first one that is being queued to the filter right after your plugin filters it. And as your plugin outputs NULL instead of string and the WebManDesign\Eimear\Plugin\WooCommerce\Single::product_page_template_load() receives NULL while it strictly expects string (as according to WordPress documentation and code) the PHP throws error. It has nothing to do with WooCommerce single product page or any other page for that matter.

    Still if you thing some changes required then know me.

    I’ve checked your plugin code and found the source of the issue:

    All of your $WCFMmp->template->get_template() methods return NULL. Actually, I’m not really sure why you are using theme with return $WCFMmp->template->get_template(...); as the method does not even contain any return statement within itself and that’s actually why it defaults to returning NULL in PHP.

    To fix the issue, please add return (string) $located; as the last line into the WCFMmp_Template->get_template() method within core/class-wcfmmp-template.php file.

    Also, I have found similar method WCFM_Template->get_template() in core/class-wcfm-template.php file of your other plugin wc-frontend-manager. The issue is the same: the method does not return anything, which is interpreted by PHP as NULL. If these methods are used in WordPress’ template_include filter hook, they should always return string.

    Please fix all of such methods in all of your plugins (where applicable).

    Thank you.

    Best regards,

    Oliver

    Thread Starter WebMan Design | Oliver Juhas

    (@webmandesign)

    Hi guys,

    Any update on this please?

    Thanks and regards,

    Oliver

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP error with `template_include` filter hook’ is closed to new replies.