Fixing Common PHP Notices and Warnings in Yoast Duplicate Post
Content
If you've enabled WordPress debugging, you might have noticed PHP notices or warnings related to the Yoast Duplicate Post plugin. These messages, while often not breaking your site, can clutter your debug logs and indicate underlying code issues. Based on community reports, here are the most common ones and how to address them.
Common Error: "Trying to get property of non-object"
This is one of the most frequently reported issues. You'll typically see it in your debug log referencing lines 123 and 149 in the duplicate-post-common.php file.
Notice: Trying to get property 'post_type' of non-object in .../duplicate-post/duplicate-post-common.php on line 123
Notice: Trying to get property 'post_type' of non-object in .../duplicate-post/duplicate-post-common.php on line 149
Why This Happens
This error occurs when the plugin tries to check if a post type is enabled for duplication, but the $post variable it's checking is either not defined or is not a valid post object. This can happen on certain admin pages that aren't related to posts (like settings pages for other plugins) or if a post ID in a URL parameter is invalid.
How to Fix It
The Yoast Duplicate Post team has acknowledged this issue. A permanent fix involves adding a conditional check to ensure the $post variable exists and is an object before trying to access its post_type property. This fix has been implemented in newer versions of the plugin.
Solution: Update the Plugin
The first and simplest step is to ensure you are running the latest version of Yoast Duplicate Post. The development team has addressed this specific notice in subsequent updates. Updating often resolves the issue immediately.
Other Common PHP Messages and Fixes
1. Strict Standards Warning (Assignment by Reference)
Strict Standards: Only variables should be assigned by reference in .../duplicate-post/duplicate-post-common.php on line 31
Cause: This is a code style warning triggered by PHP 5.4 and above, related to how a variable is assigned.
Fix: This was fixed in a plugin update. The line was changed from something like if ( !$post = &get_post( $id ) ) to if ( !$post = get_post( $id ) ). Updating the plugin resolves this.
2. Undefined Property Warning ($dp-rewrite-republish)
PHP Warning: Undefined property: stdClass::$dp-rewrite-republish in .../class-wp-posts-list-table.php on line 309
Cause: This can sometimes indicate a conflict with another plugin, such as the Groups plugin.
Fix: Check for plugin conflicts by deactivating other plugins one by one to identify the culprit. Also, ensure Duplicate Post is updated, as the team has released patches for similar issues in the past.
3. Fatal Error: in_array() Argument Must Be Array
PHP Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, bool given in .../admin-functions.php:149
Cause: A function tries to use the result of get_option() as an array, but the option sometimes returns false instead.
Fix: The code should be modified to provide a default array value if the option returns false. This was addressed in a plugin update.
General Troubleshooting Steps
- Update Everything: Always ensure you are using the latest version of WordPress, the Yoast Duplicate Post plugin, and your theme. Many of these notices are patched in subsequent releases.
- Check for Conflicts: Temporarily switch to a default WordPress theme (like Twenty Twenty-Four) and disable all other plugins. If the notices disappear, reactivate your themes and plugins one by one to find the source of the conflict.
- Review Your Debug Log: The specific file and line number in the error message are your best clues for finding a solution or checking if it has been patched.
Most of these warnings are minor code issues that don't affect functionality but are best practice to fix. The Yoast Duplicate Post team has historically been responsive to these community-reported bugs and often includes fixes in regular updates.
Related Support Threads Support
-
bad link in noticehttps://wordpress.org/support/topic/bad-link-in-notice/
-
Issue with Contact Form 7 even if only activated for posts and pageshttps://wordpress.org/support/topic/issue-with-contact-form-7-even-if-only-activated-for-posts-and-pages/
-
Duplicate post with numbers of podshttps://wordpress.org/support/topic/duplicate-post-with-numbers-of-pods/
-
PHP ERRORhttps://wordpress.org/support/topic/%ef%bc%b0%ef%bc%a8%ef%bc%b0%e3%80%80%ef%bc%a5%ef%bc%b2%ef%bc%b2%ef%bc%af%ef%bc%b2/
-
Warning message on Yoast Duplicate Posthttps://wordpress.org/support/topic/warning-message-on-yoast-duplicate-post/
-
[Plugin: Duplicate Post] Very Minor bughttps://wordpress.org/support/topic/plugin-duplicate-post-very-minor-bug/
-
[Plugin: Duplicate Post] Deprecated Notice on Upgradehttps://wordpress.org/support/topic/plugin-duplicate-post-deprecated-notice-on-upgrade/
-
[Plugin: Duplicate Post] Notices on v2.2: Undefined variable post; Trying to get property of non-objhttps://wordpress.org/support/topic/plugin-duplicate-post-notices-on-v22-undefined-variable-post-trying-to-get-property-of-non-object/
-
Possible SQL Injectionhttps://wordpress.org/support/topic/possible-sql-injection-2/
-
Undefined property: stdClass::$dp-rewrite-republishhttps://wordpress.org/support/topic/undefined-property-stdclassdp-rewrite-republish/
-
[Plugin: Duplicate Post] Notice in 2.2https://wordpress.org/support/topic/plugin-duplicate-post-notice-in-22/
-
duplicate_post_show_update_notice() should have a disable filterhttps://wordpress.org/support/topic/duplicate_post_show_update_notice-should-have-a-disable-filter/
-
Excerpt problemhttps://wordpress.org/support/topic/excerpt-problem-9/
-
PHP 7 compatibilityhttps://wordpress.org/support/topic/php-7-compatibility-69/
-
get_currentuserinfo is deprecated since version 4.5! Use wp_get_current_user()https://wordpress.org/support/topic/get_currentuserinfo-is-deprecated-since-version-45-use-wp_get_current_user/
-
PHP Fatal error: Uncaught TypeError: in_array() … admin-functions.php:149https://wordpress.org/support/topic/php-fatal-error-uncaught-typeerror-in_array-admin-functions-php149/
-
Broken in wp 3.8—throws errorhttps://wordpress.org/support/topic/broken-in-wp-38-throws-error/
-
Please suppress notices for unset parametershttps://wordpress.org/support/topic/please-suppress-notices-for-unset-parameters/
-
[Plugin: Duplicate Post] PHP Errorshttps://wordpress.org/support/topic/plugin-duplicate-post-php-errors/
-
[Plugin: Duplicate Post] array_diff() problemhttps://wordpress.org/support/topic/plugin-duplicate-post-array_diff-problem/
-
Notice: Trying to get property ‘base’ of non-objecthttps://wordpress.org/support/topic/notice-trying-to-get-property-base-of-non-object-2/
-
duplicate-post call counthttps://wordpress.org/support/topic/duplicate-post-call-count/
-
Typo in hook documentationhttps://wordpress.org/support/topic/typo-in-hook-documentation/
-
Bugfix/upgrade: Duplicate Post removes the backslashes from contenthttps://wordpress.org/support/topic/bugfixupgrade-duplicate-post-removes-the-backslashes-from-content/
-
Error: Trying to get property ‘post_type’ of non-objecthttps://wordpress.org/support/topic/error-trying-to-get-property-post_type-of-non-object/
-
Cross Site Scripting / XSS vulnerabilityhttps://wordpress.org/support/topic/cross-site-scripting-xss-vulnerability-2/
-
Error when install pluginhttps://wordpress.org/support/topic/error-when-install-plugin-4/
-
Undefined Variable Line 308https://wordpress.org/support/topic/undefined-variable-line-308/
-
Installation Errorhttps://wordpress.org/support/topic/installation-error-72/
-
Errors with WordPress 3.6https://wordpress.org/support/topic/errors-with-wordpress-36/
-
Notice: Undefined property: WP_Post_Type::$post_typehttps://wordpress.org/support/topic/notice-undefined-property-wp_post_typepost_type/
-
Strict Standards errorhttps://wordpress.org/support/topic/strict-standards-error-8/
-
has_cap in duplicate-post-options.phphttps://wordpress.org/support/topic/has_cap-in-duplicate-post-optionsphp/
-
[Plugin: Duplicate Post] Undefined index on options pagehttps://wordpress.org/support/topic/plugin-duplicate-post-undefined-index-on-options-page/
-
Small bug reporthttps://wordpress.org/support/topic/small-bug-report/
-
label ux bughttps://wordpress.org/support/topic/label-ux-bug/
-
New Installation – Strict Standards Warningshttps://wordpress.org/support/topic/new-installation-strict-standards-warnings/
-
Some Bug exits on latest versionhttps://wordpress.org/support/topic/some-bug-exits-on-latest-version/
-
Trying to get property of non-objecthttps://wordpress.org/support/topic/trying-to-get-property-of-non-object-56/