Skip to content
Draft
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions includes/class-sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static function trash_hook( $post_id ) {
public static function trash_post( $post_id ) {
add_post_meta(
$post_id,
'webmention_canonical_url',
'_webmention_canonical_url',
get_permalink( $post_id ),
true
);
Expand All @@ -156,7 +156,7 @@ public static function trash_post( $post_id ) {
* @return void
*/
public static function untrash_post( $post_id ) {
delete_post_meta( $post_id, 'webmention_canonical_url' );
delete_post_meta( $post_id, '_webmention_canonical_url' );
}

/**
Expand Down Expand Up @@ -237,7 +237,7 @@ public static function send_webmentions( $post_id ) {
return;
}

$source = get_post_meta( $post_id, 'webmention_canonical_url', true );
$source = get_post_meta( $post_id, '_webmention_canonical_url', true );

if ( ! $source ) {
$source = get_permalink( $post_id );
Expand Down
35 changes: 35 additions & 0 deletions includes/class-upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public static function maybe_upgrade() {
if ( version_compare( $version_from_db, '1.0.1', '<' ) ) {
self::migrate_to_1_0_1();
}
if ( version_compare( $version_from_db, '5.7.0', '<' ) ) {
self::migrate_to_5_7_0();
}

/**
* Fires when the system has to be migrated.
Expand All @@ -124,6 +127,24 @@ public static function maybe_upgrade() {
self::unlock();
}

/**
* Rename post meta keys.
*
* @param string $old_key The old postmeta key.
* @param string $new_key The new postmeta key.
*/
public static function update_postmeta_key( $old_key, $new_key ) {
global $wpdb;

$wpdb->update(
$wpdb->postmeta,
array( 'meta_key' => $new_key ),
array( 'meta_key' => $old_key ),
array( '%s' ),
array( '%s' )
);
}

/**
* Rename meta keys.
*
Expand Down Expand Up @@ -226,4 +247,18 @@ public static function migrate_to_1_0_1() {
}
}
}

/**
* Migrate to version 5.7.0
*
* Prefix the `webmention_canonical_url` post meta key with an underscore
* so it is hidden from the Custom Fields UI dropdown.
*
* @since 5.7.0
*
* @return void
*/
public static function migrate_to_5_7_0() {
self::update_postmeta_key( 'webmention_canonical_url', '_webmention_canonical_url' );
}
}