From 619ed993ca9d11eec65bbd2da9ce21a63fea4f89 Mon Sep 17 00:00:00 2001 From: Tobias Jordans Date: Tue, 13 May 2014 11:12:50 +0200 Subject: [PATCH 1/2] Prevent notice about $post being a "non-object" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are situation when $post is not a WP_Post Object. I experienced this in a 0 search result case. This causes a Notice-Warning when „define('WP_DEBUG', true)“: „Notice: Trying to get property of non-object in …wp-content/plugins/wp-facebook-open-graph-protocol/wp-facebook-ogp.php on line 159 Notice: Trying to get property of non-object in …wp-includes/post-template.php on line 29 Notice: Trying to get property of non-object in …wp-content/plugins/wp-facebook-open-graph-protocol/wp-facebook-ogp.php on line 42“ --- wp-facebook-ogp.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wp-facebook-ogp.php b/wp-facebook-ogp.php index 5b4c570..76db409 100644 --- a/wp-facebook-ogp.php +++ b/wp-facebook-ogp.php @@ -37,7 +37,11 @@ function wpfbogp_namespace($output) { // function to call first uploaded image in content function wpfbogp_find_images() { global $post, $posts; - + + if( !is_object($post) || get_class($post) != 'WP_Post' ) { + return []; + } + // Grab content and match first image $content = $post->post_content; $output = preg_match_all( '//i', $content, $matches ); @@ -96,6 +100,11 @@ function wpfbogp_flush_ob() { // build ogp meta function wpfbogp_build_head() { global $post; + + if( !is_object($post) || get_class($post) != 'WP_Post' ) { + return ''; + } + $options = get_option('wpfbogp'); // check to see if you've filled out one of the required fields and announce if not if ( ( ! isset( $options['wpfbogp_admin_ids'] ) || empty( $options['wpfbogp_admin_ids'] ) ) && ( ! isset( $options['wpfbogp_app_id'] ) || empty( $options['wpfbogp_app_id'] ) ) ) { From 96302affca3dc76b30c8c01a973b74b2e68f1139 Mon Sep 17 00:00:00 2001 From: Tobias Jordans Date: Tue, 13 May 2014 16:05:44 +0200 Subject: [PATCH 2/2] Move from [] to array() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My staging system did not like the [] even though development did … --- wp-facebook-ogp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-facebook-ogp.php b/wp-facebook-ogp.php index 76db409..055f36d 100644 --- a/wp-facebook-ogp.php +++ b/wp-facebook-ogp.php @@ -39,7 +39,7 @@ function wpfbogp_find_images() { global $post, $posts; if( !is_object($post) || get_class($post) != 'WP_Post' ) { - return []; + return array(); } // Grab content and match first image