• Resolved Jon Fuller

    (@garconis)


    I’m using the aioseo_description filter to change descriptions based on certain criteria. However, within this function, it’s throwing 2 PHP notices. I’m doing pretty much the exact same thing with the aioseo_title filter, and that function isn’t throwing any notices regarding the post_name or post_parent. Any ideas why these 2 notices would be happening?

    PHP Notice: Trying to get property 'post_name' of non-object in /srv/htdocs/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()'d code on line 10

    PHP Notice: Trying to get property 'post_parent' of non-object in /srv/htdocs/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()'d code on line 13

    Here is the function:

    https://gist.github.com/Garconis/d4ef0e08835e25cef38258399af8ecfc

    Despite the PHP notice, the function is actually working, but I’m hoping to clear up the notice so it doesn’t log it on every page load.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author arnaudbroes

    (@arnaudbroes)

    Hey @garconis,

    Can you try this – https://gist.github.com/arnaudbroes/8b0529204fa94ecc346b108991ea5483

    Note lines 9-11. We use the title/description quite a lot throughout the entire plugin for other features as well (previews, schema, etc.). The filter might be running before the global $post object is set, in which case you can probably just return early since you’ve indicated that the code snippet is working besides for those notices.

    Let me know if that works.

    Plugin Support Steve M

    (@wpsmort)

    Hi @garconis,

    We haven’t heard back from you in a week. I’m going to go ahead and close this thread for now. But if you’d like us to assist, please feel welcome to continue the conversation.

    Thanks! ??

    Thread Starter Jon Fuller

    (@garconis)

    Sorry yes, that resolved the PHP notices, whilst continuing to let the PHP filter to work properly.

    Do you also recommend to do the same thing with the aioseo_title filter (which is essentially the same type of code)? That one isn’t throwing any PHP notices, but didn’t know if the extra code you supplied would be considered best practice (possibly to avoid future issues).

    if ( ! is_a( $post, 'WP_Post' ) ) {
    	return $title;
    }
    • This reply was modified 2 years, 8 months ago by Jon Fuller.
    Plugin Author arnaudbroes

    (@arnaudbroes)

    Hey @garconis,

    I can’t say off the top of my head where the difference lies between the title and description hook in this case, but in any case, yes, I would definitely recommend you to add that extra code to your future code snippets as a best practice.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP notice when using aioseo_description filter’ is closed to new replies.