From e0083b357a25812ae8cb7034954bad7f0bae60ce Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 12 Jun 2024 05:51:09 +0200 Subject: [PATCH 1/3] Fix the missing namespace in the main plugin file --- enable-mastodon-apps.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/enable-mastodon-apps.php b/enable-mastodon-apps.php index da6d753..22e8e71 100644 --- a/enable-mastodon-apps.php +++ b/enable-mastodon-apps.php @@ -13,6 +13,9 @@ * @package Enable_Mastodon_Apps */ +namespace Enable_Mastodon_Apps; +use OAuth2; + defined( 'ABSPATH' ) || exit; define( 'ENABLE_MASTODON_APPS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'ENABLE_MASTODON_APPS_VERSION', '0.9.2' ); @@ -59,8 +62,11 @@ function ( $full_class ) { add_action( 'init', function () { - new Enable_Mastodon_Apps\Mastodon_API(); - new Enable_Mastodon_Apps\Integration\Pixelfed(); - new Enable_Mastodon_Apps\Comment_CPT(); + new Mastodon_API(); + new Integration\Pixelfed(); + new Comment_CPT(); } ); +if ( is_admin() && version_compare( get_option( 'ema_plugin_version', ENABLE_MASTODON_APPS_VERSION ), '<' ) ) { + add_action( 'admin_init', array( __NAMESPACE__ . '\Mastodon_Admin', 'upgrade_plugin' ) ); +} From f15b721835b32640fdd5d5ef58db0c7ddb59a916 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 12 Jun 2024 05:53:42 +0200 Subject: [PATCH 2/3] Ensure to leave other posts alone --- includes/class-mastodon-admin.php | 4 +++- tests/test-comments-cpt.php | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/includes/class-mastodon-admin.php b/includes/class-mastodon-admin.php index d34d7ee..04995a4 100644 --- a/includes/class-mastodon-admin.php +++ b/includes/class-mastodon-admin.php @@ -471,7 +471,9 @@ public static function upgrade_plugin( $override_old_version = false ) { } $comment = get_comment( $comment_id ); if ( ! $comment || 1 !== intval( $comment->comment_approved ) ) { - wp_delete_post( $comment_post->ID, true ); + if ( Comment_CPT::CPT === get_post_type( $comment_post->ID ) ) { + wp_delete_post( $comment_post->ID, true ); + } } } } diff --git a/tests/test-comments-cpt.php b/tests/test-comments-cpt.php index 48e4e23..1341273 100644 --- a/tests/test-comments-cpt.php +++ b/tests/test-comments-cpt.php @@ -143,11 +143,17 @@ public function test_upgrade() { ) ); + $post_count = wp_count_posts(); + $this->assertEquals( 1, $post_count->publish ); $old_count = wp_count_posts( Comment_CPT::CPT ); $this->assertEquals( 2, $old_count->publish ); Mastodon_Admin::upgrade_plugin( '0.9.0' ); + wp_cache_delete( _count_posts_cache_key(), 'counts' ); + $post_count = wp_count_posts(); + $this->assertEquals( 1, $post_count->publish ); + wp_cache_delete( _count_posts_cache_key( Comment_CPT::CPT ), 'counts' ); $new_count = wp_count_posts( Comment_CPT::CPT ); $this->assertEquals( 1, $new_count->publish ); From 8c01942f069486baf95af9fdcdb68628e95d6d92 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 12 Jun 2024 06:00:22 +0200 Subject: [PATCH 3/3] Version bump + Changelog --- CHANGELOG.md | 3 +++ README.md | 5 ++++- enable-mastodon-apps.php | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d6f487..935b325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### 0.9.3 +- Bring back the upgrade code. + ### 0.9.2 - Quick fix to disable the upgrade script to avoid errors. diff --git a/README.md b/README.md index 04366ee..5e1fb0d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - Tested up to: 6.5 - Requires PHP: 7.4 - License: [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) -- Stable tag: 0.9.2 +- Stable tag: 0.9.3 Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance. @@ -97,6 +97,9 @@ Endpoints around interacting with non-local users require the [ActivityPub plugi ## Changelog +### 0.9.3 +- Bring back the upgrade code. + ### 0.9.2 - Quick fix to disable the upgrade script to avoid errors. diff --git a/enable-mastodon-apps.php b/enable-mastodon-apps.php index 22e8e71..4da0dd5 100644 --- a/enable-mastodon-apps.php +++ b/enable-mastodon-apps.php @@ -3,7 +3,7 @@ * Plugin name: Enable Mastodon Apps * Plugin author: Alex Kirk * Plugin URI: https://github.com/akirk/enable-mastodon-apps - * Version: 0.9.2 + * Version: 0.9.3 * * Description: Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance. * @@ -18,7 +18,7 @@ defined( 'ABSPATH' ) || exit; define( 'ENABLE_MASTODON_APPS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); -define( 'ENABLE_MASTODON_APPS_VERSION', '0.9.2' ); +define( 'ENABLE_MASTODON_APPS_VERSION', '0.9.3' ); require __DIR__ . '/vendor/bshaffer/oauth2-server-php/src/OAuth2/Autoloader.php'; OAuth2\Autoloader::register(); @@ -67,6 +67,7 @@ function () { new Comment_CPT(); } ); + if ( is_admin() && version_compare( get_option( 'ema_plugin_version', ENABLE_MASTODON_APPS_VERSION ), '<' ) ) { add_action( 'admin_init', array( __NAMESPACE__ . '\Mastodon_Admin', 'upgrade_plugin' ) ); }