Skip to content

Commit

Permalink
Don't show settings menu items when not in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Mar 11, 2024
1 parent 2a2c18f commit 5e05cde
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
6 changes: 6 additions & 0 deletions includes/class-access-control.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public static function private_rss_is_authenticated() {
* @return int|bool The user id or false.
*/
public function verify_token( $token, $until, $auth ) {
if ( ! get_option( 'friends_enable_wp_friendships' ) ) {
return false;
}
$user_id = get_option( 'friends_in_token_' . $token );
if ( ! $user_id ) {
$me = User::get_user( User::get_user_login_for_url( $token ) );
Expand Down Expand Up @@ -136,6 +139,9 @@ public function verify_token( $token, $until, $auth ) {
* Log in a friend via URL parameter
*/
public function remote_login() {
if ( ! get_option( 'friends_enable_wp_friendships' ) ) {
return false;
}
if ( ! isset( $_GET['friend_auth'] ) ) {
return;
}
Expand Down
17 changes: 10 additions & 7 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,22 @@ public function admin_menu() {
add_menu_page( 'friends', $menu_title, $required_role, 'friends', null, 'dashicons-groups', 3 );
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain
add_submenu_page( 'friends', __( 'Home' ), __( 'Home' ), $required_role, 'friends', array( $this, 'render_admin_home' ) );
add_action( 'load-' . $page_type . '_page_friends-page', array( $this, 'redirect_to_friends_page' ) );
add_submenu_page( 'friends', __( 'Add New Friend', 'friends' ), __( 'Add New Friend', 'friends' ), $required_role, 'add-friend', array( $this, 'render_admin_add_friend' ) );
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain
add_submenu_page( 'friends', __( 'Settings' ), __( 'Settings' ), $required_role, 'friends-settings', array( $this, 'render_admin_settings' ) );
add_action( 'load-' . $page_type . '_page_friends-page', array( $this, 'redirect_to_friends_page' ) );
add_submenu_page( 'friends', __( 'Notification Manager', 'friends' ), __( 'Notification Manager', 'friends' ), $required_role, 'friends-notification-manager', array( $this, 'render_admin_notification_manager' ) );
if ( isset( $_GET['page'] ) && in_array( $_GET['page'], apply_filters( 'friends_admin_settings_slugs', array( 'friends-settings', 'friends-notification-manager', 'friends-wp-friendships', 'friends-import-export' ) ) ) ) {
add_submenu_page( 'friends', __( 'Notification Manager', 'friends' ), '- ' . __( 'Notification Manager', 'friends' ), $required_role, 'friends-notification-manager', array( $this, 'render_admin_notification_manager' ) );
add_submenu_page( 'friends', __( 'Friendships', 'friends' ), '- ' . __( 'Friendships', 'friends' ), $required_role, 'friends-wp-friendships', array( $this, 'render_admin_wp_friendship_settings' ) );
add_submenu_page( 'friends', __( 'Import/Export', 'friends' ), '- ' . __( 'Import/Export', 'friends' ), $required_role, 'friends-import-export', array( $this, 'render_admin_import_export' ) );
do_action( 'friends_admin_menu_settings', $page_type );
}
add_action( 'load-' . $page_type . '_page_friends-notification-manager', array( $this, 'process_admin_notification_manager' ) );
add_action( 'load-' . $page_type . '_page_friends-import-export', array( $this, 'process_admin_import_export' ) );
add_action( 'load-' . $page_type . '_page_friends-settings', array( $this, 'process_admin_settings' ) );
if ( get_option( 'friends_enable_wp_friendships' ) ) {
add_submenu_page( 'friends', __( 'Friendships', 'friends' ), __( 'Friendships', 'friends' ), $required_role, 'friends-wp-friendships', array( $this, 'render_admin_wp_friendship_settings' ) );
add_action( 'load-' . $page_type . '_page_friends-wp-friendships', array( $this, 'process_admin_wp_friendship_settings' ) );
}
add_submenu_page( 'friends', __( 'Import/Export', 'friends' ), __( 'Import/Export', 'friends' ), $required_role, 'friends-import-export', array( $this, 'render_admin_import_export' ) );
add_action( 'load-' . $page_type . '_page_friends-import-export', array( $this, 'process_admin_import_export' ) );
add_submenu_page( 'friends', __( 'Add New Friend', 'friends' ), __( 'Add New Friend', 'friends' ), $required_role, 'add-friend', array( $this, 'render_admin_add_friend' ) );
add_action( 'load-' . $page_type . '_page_friends-settings', array( $this, 'process_admin_settings' ) );

add_submenu_page( 'friends', __( 'Friends & Requests', 'friends' ), __( 'Friends & Requests', 'friends' ), $required_role, 'friends-list', array( $this, 'render_friends_list' ) );

Expand Down
13 changes: 5 additions & 8 deletions includes/class-automatic-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct( Friends $friends ) {
* Register the WordPress hooks
*/
private function register_hooks() {
add_action( 'admin_menu', array( $this, 'admin_menu' ), 20 );
add_action( 'friends_admin_menu_settings', array( $this, 'friends_admin_menu_settings' ), 20 );
add_action( 'friends_admin_tabs', array( $this, 'admin_tabs' ), 20 );
add_filter( 'handle_bulk_actions-edit-post', array( $this, 'bulk_publish' ), 10, 3 );

Expand All @@ -53,17 +53,14 @@ private function register_hooks() {

/**
* Add the admin menu to the sidebar.
*
* @param string $page_type The page type.
*/
public function admin_menu() {
$unread_badge = $this->friends->admin->get_unread_badge();

$menu_title = __( 'Friends', 'friends' ) . $unread_badge;
$page_type = sanitize_title( $menu_title );

public function friends_admin_menu_settings( $page_type ) {
add_submenu_page(
'friends',
__( 'Automatic Status', 'friends' ),
__( 'Automatic Status', 'friends' ),
'- ' . __( 'Automatic Status', 'friends' ),
Friends::required_menu_role(),
'friends-auto-status',
array( $this, 'validate_drafts' )
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/select-feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
</p>
</td>
</tr>
<?php else : ?>
<?php elseif ( get_option( 'friends_enable_wp_friendships' ) ) : ?>
<tr>
<th scope="row"><label for="friendship"><?php esc_html_e( 'Friendship', 'friends' ); ?></label></th>
<td>
Expand Down

0 comments on commit 5e05cde

Please sign in to comment.