Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/Models/class-inbound-smart-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Parsely\Utils\Utils;
use ReflectionClass;
use WP_Post;
use WP_Error;

/**
* Model for Inbound Smart Link.
Expand Down Expand Up @@ -812,7 +813,7 @@ public function apply() {
true
);

if ( is_wp_error( $updated_post ) ) {
if ( is_wp_error( $updated_post ) && ! $this->is_ignorable_update_error( $updated_post ) ) {
return $updated_post;
}

Expand Down Expand Up @@ -942,7 +943,7 @@ public function remove( $restore_original_link = false, $delete_smart_link = tru
true
);

if ( is_wp_error( $updated_post ) ) {
if ( is_wp_error( $updated_post ) && ! $this->is_ignorable_update_error( $updated_post ) ) {
return $updated_post;
}

Expand Down Expand Up @@ -1280,4 +1281,27 @@ private function is_the_same_line( string $line1, string $line2 ): bool {

return $text1 === $text2;
}

/**
* Checks if a WP_Error from wp_update_post() is ignorable.
*
* @since 3.19.0
*
* @param WP_Error $error The error to check.
* @return bool True if the error is ignorable, false otherwise.
*/
private function is_ignorable_update_error( WP_Error $error ): bool {
// The 'invalid_page_template' error can be returned from wp_update_post()
// if the saved page template is a custom type that no longer exists.
// This error is returned *after* the post has been updated with a new smart
// link, so we can safely ignore it.
//
// The post will use the 'default' page template if a custom type
// doesn't exist anyway.
if ( 'invalid_page_template' === $error->get_error_code() ) {
return true;
}

return false;
}
}
Loading