Title: Avoid using WP_error as string
Last modified: August 21, 2016

---

# Avoid using WP_error as string

 *  [codenegar](https://wordpress.org/support/users/codenegar/)
 * (@codenegar)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/avoid-using-wp_error-as-string/)
 * Hi,
 * At file all-in-one-seo-pack\aioseop_class.php Line 1392 the plugin just checks
   URL is not empty, and it doesn’t check if URL contains errors.
    Here is the original
   line: if ( !empty( $url ) ) Here is a better version of it if ( !empty( $url )&&!
   is_wp_error( $url ) )
 * Could you change this line in the next update?
    Thanks.
 * [http://wordpress.org/plugins/all-in-one-seo-pack/](http://wordpress.org/plugins/all-in-one-seo-pack/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Peter Baylies](https://wordpress.org/support/users/pbaylies/)
 * (@pbaylies)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/avoid-using-wp_error-as-string/#post-4324276)
 * codenegar,
 * Are you running into an issue where the URL is getting set as a WP_Error object?
   The functions used here such as get_permalink() and get_post_type_archive_link()
   return false on error, so is_empty() is generally sufficient here. If you can
   provide a case where it isn’t, sure, I’ll change it, but I’d like to know if 
   or why this is happening for you.
 *  Thread Starter [codenegar](https://wordpress.org/support/users/codenegar/)
 * (@codenegar)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/avoid-using-wp_error-as-string/#post-4324352)
 * I have a plugin that generates pages on the fly, it uses WordPress search and
   custom taxonomies to create pages with custom posts.
    Some users can’t load pages
   when your plugin is active, I debugged the code and found that your plugin uses
   $url variable as string (in fact it’s a wp_error object in those cases). I need
   to edit each your plugin, but it’s more bullet proof for your plugin to avoid
   using wp_error as string.
 *  [Peter Baylies](https://wordpress.org/support/users/pbaylies/)
 * (@pbaylies)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/avoid-using-wp_error-as-string/#post-4324353)
 * codenegar,
 * Can you tell me how $url gets set as a WP_Error() object? Is that happening in
   the aiosp_mrt_get_url() function or in some other code? I’ll consider adding 
   a check for this, but it’d help to know where or how this is taking place. You
   should also be able to fix this by using the aioseop_canonical_url filter.
 *  Thread Starter [codenegar](https://wordpress.org/support/users/codenegar/)
 * (@codenegar)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/avoid-using-wp_error-as-string/#post-4324360)
 * Thank you.
    I did another debug and found that errors happen in aiosp_mrt_get_url
   function. At line 1821 when it looks for a taxonomy and a term, if the term is
   empty, get_term_link return an error. If you add here a condition to check $term,
   $taxonomy are not empty, it would be much bullet proof code.
 *  [Peter Baylies](https://wordpress.org/support/users/pbaylies/)
 * (@pbaylies)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/avoid-using-wp_error-as-string/#post-4324361)
 * codenegar,
 * Thanks for that; I’ll add some better error checking and handling of this in 
   the next release, which should be out soon.
 *  Thread Starter [codenegar](https://wordpress.org/support/users/codenegar/)
 * (@codenegar)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/avoid-using-wp_error-as-string/#post-4324362)
 * Great. Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Avoid using WP_error as string’ is closed to new replies.

 * ![](https://ps.w.org/all-in-one-seo-pack/assets/icon.svg?rev=2443290)
 * [All in One SEO – Powerful SEO Plugin to Boost SEO Rankings & Increase Traffic](https://wordpress.org/plugins/all-in-one-seo-pack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/all-in-one-seo-pack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/all-in-one-seo-pack/)
 * [Active Topics](https://wordpress.org/support/plugin/all-in-one-seo-pack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/all-in-one-seo-pack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/all-in-one-seo-pack/reviews/)

## Tags

 * [wp_error](https://wordpress.org/support/topic-tag/wp_error/)

 * 6 replies
 * 2 participants
 * Last reply from: [codenegar](https://wordpress.org/support/users/codenegar/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/avoid-using-wp_error-as-string/#post-4324362)
 * Status: not resolved