Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option to Disable Friendships #294

Merged
merged 6 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
336 changes: 208 additions & 128 deletions includes/class-admin.php

Large diffs are not rendered by default.

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
10 changes: 10 additions & 0 deletions includes/class-friends.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,16 @@ public static function upgrade_plugin( $upgrader_object, $options ) {
}
$previous_version = get_option( 'friends_plugin_version' );

if ( version_compare( $previous_version, '2.9.0', '<' ) ) {
$users = User_Query::all_associated_users();
foreach ( $users->get_results() as $user ) {
if ( ! ( $user instanceof Subscription ) ) {
// We have a user that is not a virtual user, so the friendship functionality had been used.
update_option( 'friends_enable_wp_friendships', 1 );
break;
}
}
}
if ( version_compare( $previous_version, '0.20.1', '<' ) ) {
$users = User_Query::all_associated_users();
foreach ( $users->get_results() as $user ) {
Expand Down
61 changes: 61 additions & 0 deletions templates/admin/import-export.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* This template contains the Friends Settings.
*
* @package Friends
*/

do_action( 'friends_settings_before_form' );

?>
<form method="post">
<?php wp_nonce_field( 'friends-settings' ); ?>
<table class="form-table">
<tbody>
<tr>
<th scope="row" rowspan="2"><?php esc_html_e( 'Feed Reader', 'friends' ); ?></th>
<td>
<span>
<?php
// translators: %s is a URL.
echo wp_kses( sprintf( __( 'Download the <a href=%s>Private OPML file (contains private urls!)</a> and import it to your feed reader.', 'friends' ), esc_url( home_url( '/friends/opml/?auth=' . $args['private_rss_key'] ) ) ), array( 'a' => array( 'href' => array() ) ) );
?>
</span>
<span>
<?php
// translators: %s is a URL.
echo wp_kses( sprintf( __( 'Alternative: <a href=%s>Public OPML file (only public urls)</a>.', 'friends' ), esc_url( home_url( '/friends/opml/?public' ) ) ), array( 'a' => array( 'href' => array() ) ) );
?>
</span>
<p class="description">
<?php
echo __( 'If your feed reader supports it, you can also subscribe to this URL as the OPML file gets updated as you add or remove friends.', 'friends' );
?>
</p>
</td>
</tr>
<tr>
<td>
<span>
<?php
// translators: %s is a URL.
echo wp_kses( sprintf( __( 'You can also subscribe to a <a href=%s>compiled RSS feed of friend posts</a>.', 'friends' ), esc_url( home_url( '/friends/feed/?auth=' . $args['private_rss_key'] ) ) ), array( 'a' => array( 'href' => array() ) ) );
?>
</span>
<p class="description">
<?php
echo __( 'Please be careful what you do with these feeds as they might contain private posts of your friends.', 'friends' );
?>
</p>

</td>
</tr>
</tbody>
</table>
<?php do_action( 'friends_settings_form_bottom' ); ?>
<p class="submit">
<input type="submit" id="submit" class="button button-primary" value="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Save Changes' ); ?>">
</p>
</form>
<?php
do_action( 'friends_settings_after_form' );
87 changes: 62 additions & 25 deletions templates/admin/notification-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,64 @@
* @package Friends
*/

if ( $args['no_new_post_notification'] ) : ?>
<p class="description"><?php esc_html_e( 'You have generally disabled new post notifications for yourself.', 'friends' ); ?> <a href="<?php echo esc_url( $args['friends_settings_url'] ); ?>"><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( '(Edit)' ); ?></a></p>
<?php endif; ?>
?><form method="post">
<?php wp_nonce_field( 'notification-manager' ); ?>
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<?php
esc_html_e( 'E-Mail Notifications', 'friends' );
?>
</th>
<td>
<fieldset>
<label for="friend_request_notification">
<input name="friend_request_notification" type="checkbox" id="friend_request_notification" value="1" <?php checked( '1', ! $args['no_friend_request_notification'] ); ?>>
<span><?php esc_html_e( 'Friend Requests', 'friends' ); ?></span>
</label>
<br />
<label for="new_post_notification">
<input name="new_post_notification" type="checkbox" id="new_post_notification" value="1" <?php checked( '1', ! $args['no_new_post_notification'] ); ?>>
<span><?php esc_html_e( 'New Posts', 'friends' ); ?></span>
</label>
</fieldset>
<p class="description"><?php esc_html_e( 'When you disable post notifications, their individual configuration is disabled also.', 'friends' ); ?></p>
</td>
</tr>
<tr>
<th scope="row">
<?php
esc_html_e( 'Keyword Notifications', 'friends' );
?>
</th>
<td>
<fieldset>

<p class="description">
<span>
<?php
if ( $args['active_keywords'] ) {
echo esc_html(
sprintf(
// translators: %1$s is the number of active keywords, %2$s is the list of those keywords.
_n( 'There is %1$s active keyword: %2$s', 'There are %1$s active keywords: %2$s', count( $args['active_keywords'] ), 'friends' ),
count( $args['active_keywords'] ),
esc_html( implode( ', ', $args['active_keywords'] ) )
)
);
} else {
esc_html_e( 'No notification keywords have been specified.', 'friends' );
}
?>
</span>
<a href="<?php echo esc_url( $args['friends_settings_url'] ); ?>"><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( '(Edit)' ); ?></a>
</p>
<ol id="keyword-notifications">
<li id="keyword-template" style="display: none">
<input type="checkbox" name="notification_keywords_enabled[0]" value="1" checked />
<input type="text" name="notification_keywords[0]" value="" placeholder="<?php esc_html_e( 'Keyword (regex allowed)', 'friends' ); ?>">
</li>
<?php foreach ( $args['notification_keywords'] as $i => $entry ) : ?>
<li>
<input type="checkbox" name="notification_keywords_enabled[<?php echo esc_attr( $i + 1 ); ?>]" value="1" <?php checked( $entry['enabled'] ); ?> />
<input type="text" name="notification_keywords[<?php echo esc_attr( $i + 1 ); ?>]" value="<?php echo esc_attr( $entry['keyword'] ); ?>" placeholder="<?php esc_html_e( 'Keyword (regex allowed)', 'friends' ); ?>">
</li>
<?php endforeach; ?>
</ol>
<a href="" id="admin-add-keyword"><?php esc_html_e( 'Add a notification keyword', 'friends' ); ?></a>
</fieldset>
<p class="description"><?php esc_html_e( 'Empty keywords will be deleted after saving. You can temporarily disable them with the checkbox.', 'friends' ); ?></p>
</td>
</tr>
</tbody>
</table>
<p class="submit">
<input type="submit" id="submit" class="button button-primary" value="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Save Changes' ); ?>">
</p>

<form method="post">
<?php wp_nonce_field( 'notification-manager' ); ?>
<h2><?php esc_html_e( 'Individual Friend Settings', 'friends' ); ?></h2>
<table class="wp-list-table widefat fixed striped" style="margin-top: 2em; margin-bottom: 2em; margin-right: 1em">
<thead>
<tr>
Expand All @@ -53,8 +85,13 @@
<input name="show_on_friends_page[<?php echo esc_attr( $friend_user->user_login ); ?>]" type="checkbox" id="show_on_friends_page" value="1" <?php checked( '1', ! in_array( $friend_user->user_login, $args['hide_from_friends_page'] ) ); ?> />
</td>
<td class="column-email-notification">
<input name="new_post_notification[<?php echo esc_attr( $friend_user->user_login ); ?>]" type="checkbox" id="friends_new_post_notification" value="1" <?php checked( '1', ! get_user_option( 'friends_no_new_post_notification_' . $friend_user->user_login ) ); ?> <?php echo $args['no_new_post_notification'] ? 'disabled="disabled"' : ''; ?>
<?php if ( $args['no_new_post_notification'] ) : ?>
<input disabled="disabled" type="checkbox" <?php checked( '1', ! get_user_option( 'friends_no_new_post_notification_' . $friend_user->user_login ) ); ?> />
<input name="new_friend_post_notification[<?php echo esc_attr( $friend_user->user_login ); ?>]" type="hidden" value="<?php echo get_user_option( 'friends_no_new_post_notification_' . $friend_user->user_login ) ? '0' : '1'; ?>" />
<?php else : ?>
<input name="new_friend_post_notification[<?php echo esc_attr( $friend_user->user_login ); ?>]" type="checkbox" id="friends_new_friend_post_notification" value="1" <?php checked( '1', ! get_user_option( 'friends_no_new_post_notification_' . $friend_user->user_login ) ); ?> <?php echo $args['no_new_post_notification'] ? 'disabled="disabled"' : ''; ?>
/>
<?php endif; ?>
</td>
<td class="column-keyword-notification">
<input name="keyword_notification[<?php echo esc_attr( $friend_user->user_login ); ?>]" type="checkbox" id="friends_keyword_notification" value="1" <?php checked( '1', ! get_user_option( 'friends_no_keyword_notification_' . $friend_user->user_login ) ); ?> <?php echo $args['no_keyword_notification'] ? 'disabled="disabled"' : ''; ?>
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
8 changes: 5 additions & 3 deletions templates/admin/settings-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
$args['menu'] = apply_filters(
'friends_admin_tabs',
array(
__( 'Welcome', 'friends' ) => 'friends',
__( 'Settings' ) => 'friends-settings', // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
__( 'Notification Manager', 'friends' ) => 'friends-notification-manager',
__( 'Welcome', 'friends' ) => 'friends',
__( 'Settings' ) => 'friends-settings', // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
__( 'Friendships', 'friends' ) => 'friends-wp-friendships',
__( 'Notifications', 'friends' ) => 'friends-notification-manager',
__( 'Import/Export', 'friends' ) => 'friends-import-export',
)
);
}
Expand Down
Loading
Loading