From 201ee16f37a599684a126f72eb7bc8163ddffced Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 20 Jul 2023 10:12:59 +0200 Subject: [PATCH] fix some issues and re-add "ACTIVITYPUB_SINGLE_USER_MODE" const --- activitypub.php | 3 --- includes/class-activitypub.php | 2 +- includes/class-admin.php | 5 ++++- includes/functions.php | 7 +++++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/activitypub.php b/activitypub.php index 0abf189..472acb7 100644 --- a/activitypub.php +++ b/activitypub.php @@ -29,9 +29,6 @@ function init() { \defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "[ap_title]\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" ); \defined( 'ACTIVITYPUB_SECURE_MODE' ) || \define( 'ACTIVITYPUB_SECURE_MODE', apply_filters( 'activitypub_secure_mode', $value = false ) ); - \defined( 'ACTIVITYPUB_DISABLE_USER' ) || \define( 'ACTIVITYPUB_DISABLE_USER', false ); - \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) || \define( 'ACTIVITYPUB_DISABLE_BLOG_USER', false ); - \define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); \define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); \define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) ); diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 507da58..c16fea2 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -83,7 +83,7 @@ class Activitypub { $json_template = false; // check if user can publish posts - if ( \is_author() && ! Users::get_by_id( \get_the_author_meta( 'ID' ) ) ) { + if ( \is_author() && is_wp_error( Users::get_by_id( \get_the_author_meta( 'ID' ) ) ) ) { return $template; } diff --git a/includes/class-admin.php b/includes/class-admin.php index 98cbb0e..3572f98 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -13,9 +13,12 @@ class Admin { public static function init() { \add_action( 'admin_menu', array( self::class, 'admin_menu' ) ); \add_action( 'admin_init', array( self::class, 'register_settings' ) ); - \add_action( 'show_user_profile', array( self::class, 'add_profile' ) ); \add_action( 'personal_options_update', array( self::class, 'save_user_description' ) ); \add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_scripts' ) ); + + if ( ! is_user_disabled( get_current_user_id() ) ) { + \add_action( 'show_user_profile', array( self::class, 'add_profile' ) ); + } } /** diff --git a/includes/functions.php b/includes/functions.php index ec20e2c..42ca74c 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -281,6 +281,13 @@ function is_activitypub_request() { * @return boolean True if the user is disabled, false otherwise. */ function is_user_disabled( $user_id ) { + if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) ) { + if ( ACTIVITYPUB_SINGLE_USER_MODE ) { + \defined( 'ACTIVITYPUB_DISABLE_USER' ) || \define( 'ACTIVITYPUB_DISABLE_USER', true ); + \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) || \define( 'ACTIVITYPUB_DISABLE_BLOG_USER', false ); + } + } + $return = false; switch ( $user_id ) {