diff --git a/activitypub.php b/activitypub.php index 3939d29b..46e1faca 100644 --- a/activitypub.php +++ b/activitypub.php @@ -21,7 +21,7 @@ use function Activitypub\site_supports_blocks; require_once __DIR__ . '/includes/compat.php'; require_once __DIR__ . '/includes/functions.php'; -\define( 'ACTIVITYPUB_PLUGIN_VERSION', '2.6.1' ); +\define( 'ACTIVITYPUB_PLUGIN_VERSION', '2.7.0' ); /** * Initialize the plugin constants. diff --git a/includes/class-admin.php b/includes/class-admin.php index 5a213ef1..3acaffdc 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -155,10 +155,10 @@ class Admin { wp_enqueue_media(); wp_enqueue_script( 'activitypub-header-image' ); - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-user-settings.php' ); + \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-settings.php' ); break; case 'followers': - \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-user-followers-list.php' ); + \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-followers-list.php' ); break; case 'welcome': default: @@ -288,8 +288,8 @@ class Admin { // Blog-User Settings \register_setting( - 'activitypub_blog_user', - 'activitypub_blog_user_description', + 'activitypub_blog', + 'activitypub_blog_description', array( 'type' => 'string', 'description' => \esc_html__( 'The Description of the Blog-User', 'activitypub' ), @@ -298,8 +298,8 @@ class Admin { ) ); \register_setting( - 'activitypub_blog_user', - 'activitypub_blog_user_identifier', + 'activitypub_blog', + 'activitypub_blog_identifier', array( 'type' => 'string', 'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ), @@ -329,8 +329,8 @@ class Admin { if ( $user->results ) { add_settings_error( - 'activitypub_blog_user_identifier', - 'activitypub_blog_user_identifier', + 'activitypub_blog_identifier', + 'activitypub_blog_identifier', \esc_html__( 'You cannot use an existing author\'s name for the blog profile ID.', 'activitypub' ), 'error' ); @@ -343,7 +343,7 @@ class Admin { ) ); \register_setting( - 'activitypub_blog_user', + 'activitypub_blog', 'activitypub_header_image', array( 'type' => 'integer', @@ -362,7 +362,7 @@ class Admin { } public static function add_profile( $user ) { - $description = get_user_meta( $user->ID, 'activitypub_user_description', true ); + $description = \get_user_option( 'activitypub_description', $user->ID ); wp_enqueue_media(); wp_enqueue_script( 'activitypub-header-image' ); @@ -396,11 +396,11 @@ class Admin { ) { return false; } - $description = ! empty( $_POST['activitypub_user_description'] ) ? sanitize_text_field( wp_unslash( $_POST['activitypub_user_description'] ) ) : false; + $description = ! empty( $_POST['activitypub_description'] ) ? sanitize_text_field( wp_unslash( $_POST['activitypub_description'] ) ) : false; if ( $description ) { - update_user_meta( $user_id, 'activitypub_user_description', $description ); + \update_user_option( $user_id, 'activitypub_description', $description ); } else { - delete_user_meta( $user_id, 'activitypub_user_description' ); + \delete_user_option( $user_id, 'activitypub_description' ); } $header_image = ! empty( $_POST['activitypub_header_image'] ) ? sanitize_text_field( wp_unslash( $_POST['activitypub_header_image'] ) ) : false; diff --git a/includes/class-migration.php b/includes/class-migration.php index 0e12ac11..9efd1f64 100644 --- a/includes/class-migration.php +++ b/includes/class-migration.php @@ -132,6 +132,9 @@ class Migration { if ( version_compare( $version_from_db, '2.3.0', '<' ) ) { self::migrate_from_2_2_0(); } + if ( version_compare( $version_from_db, '2.7.0', '<' ) ) { + self::migrate_from_2_6_0(); + } update_option( 'activitypub_db_version', self::get_target_version() ); @@ -255,6 +258,20 @@ class Migration { self::add_activitypub_capability(); } + /** + * Rename DB fields + * + * @return void + */ + private static function migrate_from_2_6_0() { + wp_cache_flush(); + + self::update_usermeta_key( 'activitypub_user_description', 'activitypub_description' ); + + self::update_options_key( 'activitypub_blog_user_description', 'activitypub_blog_description' ); + self::update_options_key( 'activitypub_blog_user_identifier', 'activitypub_blog_identifier' ); + } + /** * Set the defaults needed for the plugin to work * @@ -284,4 +301,40 @@ class Migration { $user->add_cap( 'activitypub' ); } } + + /** + * Rename meta keys. + * + * @param string $old The old commentmeta key + * @param string $new The new commentmeta key + */ + private static function update_usermeta_key( $old, $new ) { // phpcs:ignore + global $wpdb; + + $wpdb->update( // phpcs:ignore + $wpdb->usermeta, + array( 'meta_key' => $new ), // phpcs:ignore + array( 'meta_key' => $old ), // phpcs:ignore + array( '%s' ), + array( '%s' ) + ); + } + + /** + * Rename option keys. + * + * @param string $old The old option key + * @param string $new The new option key + */ + private static function update_options_key( $old, $new ) { // phpcs:ignore + global $wpdb; + + $wpdb->update( // phpcs:ignore + $wpdb->options, + array( 'option_name' => $new ), // phpcs:ignore + array( 'option_name' => $old ), // phpcs:ignore + array( '%s' ), + array( '%s' ) + ); + } } diff --git a/includes/collection/class-users.php b/includes/collection/class-users.php index e4596b87..d0672a04 100644 --- a/includes/collection/class-users.php +++ b/includes/collection/class-users.php @@ -76,7 +76,7 @@ class Users { return new Blog(); } - if ( get_option( 'activitypub_blog_user_identifier' ) === $username ) { + if ( get_option( 'activitypub_blog_identifier' ) === $username ) { return new Blog(); } diff --git a/includes/model/class-blog.php b/includes/model/class-blog.php index eb20155a..5665f819 100644 --- a/includes/model/class-blog.php +++ b/includes/model/class-blog.php @@ -132,7 +132,7 @@ class Blog extends Actor { * @return string The User-Description. */ public function get_summary() { - $summary = \get_option( 'activitypub_blog_user_description', null ); + $summary = \get_option( 'activitypub_blog_description', null ); if ( ! $summary ) { $summary = \get_bloginfo( 'description' ); @@ -188,7 +188,7 @@ class Blog extends Actor { * @return string The User-Name. */ public function get_preferred_username() { - $username = \get_option( 'activitypub_blog_user_identifier' ); + $username = \get_option( 'activitypub_blog_identifier' ); if ( $username ) { return $username; diff --git a/templates/blog-user-followers-list.php b/templates/blog-followers-list.php similarity index 100% rename from templates/blog-user-followers-list.php rename to templates/blog-followers-list.php diff --git a/templates/blog-user-settings.php b/templates/blog-settings.php similarity index 90% rename from templates/blog-user-settings.php rename to templates/blog-settings.php index 578d6ff5..efdf2bad 100644 --- a/templates/blog-user-settings.php +++ b/templates/blog-settings.php @@ -13,7 +13,7 @@
- +

@@ -94,8 +94,8 @@ -