| 1 |
<?php |
| 2 |
/** |
| 3 |
* Menu file. |
| 4 |
* |
| 5 |
* @package Activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub\WP_Admin; |
| 9 |
|
| 10 |
use function Activitypub\user_can_activitypub; |
| 11 |
|
| 12 |
/** |
| 13 |
* ActivityPub Menu Class. |
| 14 |
*/ |
| 15 |
class Menu { |
| 16 |
|
| 17 |
/** |
| 18 |
* Initialize the Menu class. |
| 19 |
*/ |
| 20 |
public static function init() { |
| 21 |
\add_action( 'admin_menu', array( self::class, 'admin_menu' ) ); |
| 22 |
\add_action( 'admin_bar_menu', array( self::class, 'admin_bar_menu' ), 100 ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Add admin menu entry. |
| 27 |
*/ |
| 28 |
public static function admin_menu() { |
| 29 |
$settings_page = \add_options_page( |
| 30 |
\_x( 'Welcome', 'page title', 'activitypub' ), |
| 31 |
'ActivityPub', |
| 32 |
'manage_options', |
| 33 |
'activitypub', |
| 34 |
array( Settings::class, 'settings_page' ) |
| 35 |
); |
| 36 |
|
| 37 |
\add_action( 'load-' . $settings_page, array( Settings::class, 'add_settings_help_tab' ) ); |
| 38 |
\add_action( 'load-users.php', array( Settings::class, 'add_users_help_tab' ) ); |
| 39 |
\add_action( 'load-' . $settings_page, array( Admin::class, 'add_settings_list_tables' ) ); |
| 40 |
\add_action( 'load-' . $settings_page, array( Screen_Options::class, 'add_settings_list_options' ) ); |
| 41 |
|
| 42 |
if ( \get_option( 'activitypub_reader_ui', '0' ) && \version_compare( \get_bloginfo( 'version' ), '6.9-alpha', '>=' ) ) { |
| 43 |
$app_hook = \add_dashboard_page( |
| 44 |
\__( 'Social Web', 'activitypub' ), |
| 45 |
\__( 'Social Web', 'activitypub' ), |
| 46 |
ACTIVITYPUB_BLOG_MODE === \get_option( 'activitypub_actor_mode' ) ? 'manage_options' : 'activitypub', |
| 47 |
'activitypub-social-web', |
| 48 |
array( App::class, 'render_page' ) |
| 49 |
); |
| 50 |
|
| 51 |
\add_action( 'load-' . $app_hook, array( App::class, 'remove_admin_notices' ) ); |
| 52 |
\add_action( 'admin_print_scripts-' . $app_hook, array( App::class, 'enqueue_scripts' ) ); |
| 53 |
} |
| 54 |
|
| 55 |
// User has to be able to publish posts. |
| 56 |
if ( user_can_activitypub( \get_current_user_id() ) ) { |
| 57 |
$followers_list_page = \add_users_page( |
| 58 |
\__( 'Followers ⁂', 'activitypub' ), |
| 59 |
\__( 'Followers ⁂', 'activitypub' ), |
| 60 |
'activitypub', |
| 61 |
'activitypub-followers-list', |
| 62 |
array( Admin::class, 'followers_list_page' ) |
| 63 |
); |
| 64 |
|
| 65 |
\add_action( 'load-' . $followers_list_page, array( Admin::class, 'add_followers_list_table' ) ); |
| 66 |
\add_action( 'load-' . $followers_list_page, array( Screen_Options::class, 'add_followers_list_options' ) ); |
| 67 |
|
| 68 |
if ( '1' === \get_option( 'activitypub_following_ui', '0' ) ) { |
| 69 |
$following_list_page = \add_users_page( |
| 70 |
\__( 'Following ⁂', 'activitypub' ), |
| 71 |
\__( 'Following ⁂', 'activitypub' ), |
| 72 |
'activitypub', |
| 73 |
'activitypub-following-list', |
| 74 |
array( Admin::class, 'following_list_page' ) |
| 75 |
); |
| 76 |
|
| 77 |
\add_action( 'load-' . $following_list_page, array( Admin::class, 'add_following_list_table' ) ); |
| 78 |
\add_action( 'load-' . $following_list_page, array( Settings::class, 'add_following_help_tab' ) ); |
| 79 |
\add_action( 'load-' . $following_list_page, array( Screen_Options::class, 'add_following_list_options' ) ); |
| 80 |
} |
| 81 |
|
| 82 |
// Only show blocked actors page if user has blocked actors. |
| 83 |
$blocked_actors_list_page = \add_users_page( |
| 84 |
\__( 'Blocked Actors ⁂', 'activitypub' ), |
| 85 |
\__( 'Blocked Actors ⁂', 'activitypub' ), |
| 86 |
'activitypub', |
| 87 |
'activitypub-blocked-actors-list', |
| 88 |
array( Admin::class, 'blocked_actors_list_page' ) |
| 89 |
); |
| 90 |
|
| 91 |
\add_action( 'load-' . $blocked_actors_list_page, array( Admin::class, 'add_blocked_actors_list_table' ) ); |
| 92 |
\add_action( 'load-' . $blocked_actors_list_page, array( Screen_Options::class, 'add_blocked_actors_list_options' ) ); |
| 93 |
|
| 94 |
\add_users_page( |
| 95 |
\__( 'Extra Fields ⁂', 'activitypub' ), |
| 96 |
\__( 'Extra Fields ⁂', 'activitypub' ), |
| 97 |
'activitypub', |
| 98 |
\esc_url( \admin_url( '/edit.php?post_type=ap_extrafield' ) ) |
| 99 |
); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Add Social Web item to the admin bar. |
| 105 |
* |
| 106 |
* @param \WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
| 107 |
*/ |
| 108 |
public static function admin_bar_menu( $wp_admin_bar ) { |
| 109 |
// Only show if reader UI is enabled and WordPress version supports it. |
| 110 |
if ( ! \get_option( 'activitypub_reader_ui', '0' ) || \version_compare( \get_bloginfo( 'version' ), '6.9-alpha', '<' ) ) { |
| 111 |
return; |
| 112 |
} |
| 113 |
|
| 114 |
// Check user capability based on actor mode. |
| 115 |
$capability = ACTIVITYPUB_BLOG_MODE === \get_option( 'activitypub_actor_mode' ) ? 'manage_options' : 'activitypub'; |
| 116 |
if ( ! \current_user_can( $capability ) ) { |
| 117 |
return; |
| 118 |
} |
| 119 |
|
| 120 |
$wp_admin_bar->add_node( |
| 121 |
array( |
| 122 |
'id' => 'activitypub-social-web', |
| 123 |
'title' => \__( 'Social Web', 'activitypub' ), |
| 124 |
'href' => \admin_url( 'admin.php?page=activitypub-social-web' ), |
| 125 |
'meta' => array( |
| 126 |
'class' => 'activitypub-admin-bar-social-web', |
| 127 |
'title' => \__( 'View your Social Web feed', 'activitypub' ), |
| 128 |
), |
| 129 |
) |
| 130 |
); |
| 131 |
|
| 132 |
// Enqueue styles for the admin bar icon. |
| 133 |
\wp_enqueue_style( |
| 134 |
'activitypub-admin-bar-styles', |
| 135 |
\plugins_url( 'assets/css/activitypub-admin-bar.css', ACTIVITYPUB_PLUGIN_FILE ), |
| 136 |
array(), |
| 137 |
ACTIVITYPUB_PLUGIN_VERSION |
| 138 |
); |
| 139 |
} |
| 140 |
} |
| 141 |
|