Skip to content

Commit

Permalink
Add option to disable automatic status (#141)
Browse files Browse the repository at this point in the history
* Add option to disable automatic status

* Add description

* Add updated notice
  • Loading branch information
akirk authored Dec 30, 2022
1 parent 9ffdb87 commit 87f8517
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 16 deletions.
38 changes: 28 additions & 10 deletions friends-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@
margin-bottom: .5em;
}

.friends-notice b.headline:before, #friends-welcome-panel h2:before {
.friends-body summary {
cursor: pointer;
}

.friends-notice b.headline:before,
#friends-welcome-panel h2:before {
content: "\f307";
color: #82878c;
font-family: dashicons;
Expand All @@ -73,7 +78,7 @@
position: relative;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-decoration: none!important;
text-decoration: none !important;
vertical-align: top;
}

Expand Down Expand Up @@ -109,31 +114,42 @@ table.feed-table.widefat .check-column {
min-width: 5em;
font-weight: bold;
}

table.reader-table .check-column {
width: 5em;
vertical-align: top;
text-align: center;
}
table.feed-table.widefat td, table.feed-table.widefat th {

table.feed-table.widefat td,
table.feed-table.widefat th {
padding: .5em;
}

table.feed-table.widefat th, table.feed-table.widefat th.check-column {
table.feed-table.widefat th,
table.feed-table.widefat th.check-column {
vertical-align: bottom;
}

table.feed-table.widefat td.nowrap, table.feed-table.widefat th.nowrap {
table.feed-table.widefat td.nowrap,
table.feed-table.widefat th.nowrap {
white-space: nowrap;
}

#available-widgets [class*="friends-widget"] .widget-title:before { content: "\f307"; }
#available-widgets [class*="friends-widget"] .widget-title:before {
content: "\f307";
}

a.friends-auth-link span.dashicons, button.friends-auth-link span.dashicons {
a.friends-auth-link span.dashicons,
button.friends-auth-link span.dashicons {
color: #32c170;
margin-left: 6px;
}

a.explanation-friends-auth-link:hover, a.friends-auth-link :hover, a.friends-auth-link:hover span.dashicons, button.friends-auth-link:hover span.dashicons {
a.explanation-friends-auth-link:hover,
a.friends-auth-link :hover,
a.friends-auth-link:hover span.dashicons,
button.friends-auth-link:hover span.dashicons {
color: #32c170;
}

Expand All @@ -142,15 +158,17 @@ tr.lastlog td {
margin-bottom: 2em;
}

.friends-plugin-installer .plugin-card .desc, .friends-plugin-installer .plugin-card .name {
.friends-plugin-installer .plugin-card .desc,
.friends-plugin-installer .plugin-card .name {
margin: auto;
}

span.disabled {
color: #999;
}

span#friends_enable_retention_days_line, span#friends_enable_retention_number_line {
span#friends_enable_retention_days_line,
span#friends_enable_retention_number_line {
cursor: pointer;
}

Expand Down
44 changes: 40 additions & 4 deletions includes/class-automatic-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ public function __construct( Friends $friends ) {
* Register the WordPress hooks
*/
private function register_hooks() {
add_action( 'friends_user_post_reaction', array( $this, 'post_reaction' ), 10, 2 );
add_action( 'set_user_role', array( $this, 'new_friend_user' ), 20, 3 );
add_action( 'set', array( $this, 'new_friend_user' ), 10, 2 );
add_action( 'admin_menu', array( $this, 'admin_menu' ), 20 );
add_action( 'friends_admin_tabs', array( $this, 'admin_tabs' ), 20 );
add_filter( 'handle_bulk_actions-edit-post', array( $this, 'bulk_publish' ), 10, 3 );

if ( ! get_option( 'friends_automatic_status_disabled' ) ) {
return;
}
add_action( 'friends_user_post_reaction', array( $this, 'post_reaction' ), 10, 2 );
add_action( 'set_user_role', array( $this, 'new_friend_user' ), 20, 3 );
add_action( 'set', array( $this, 'new_friend_user' ), 10, 2 );
}

/**
Expand All @@ -64,7 +68,7 @@ public function admin_menu() {
);

add_action( 'load-' . $page_type . '_page_friends-auto-status', array( $this, 'redirect_to_post_format_url' ) );

add_action( 'load-' . $page_type . '_page_friends-auto-status', array( $this, 'process_settings' ) );
}

/**
Expand Down Expand Up @@ -95,6 +99,28 @@ public function redirect_to_post_format_url() {
}
}

public function process_settings() {
if ( empty( $_REQUEST ) || ! isset( $_REQUEST['_wpnonce'] ) ) {
return;
}

if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'friends-automatic-status' ) ) {
return;
}

if ( isset( $_POST['enabled'] ) && $_POST['enabled'] ) {
delete_option( 'friends_automatic_status_disabled' );
} else {
update_option( 'friends_automatic_status_disabled', 1 );
}

if ( isset( $_GET['_wp_http_referer'] ) ) {
wp_safe_redirect( wp_get_referer() );
} else {
wp_safe_redirect( add_query_arg( 'updated', '1', remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
}
}

/**
* This displays the Automatically Generated Statuses admin page.
*/
Expand Down Expand Up @@ -213,6 +239,16 @@ function( $actions, $post ) {
'title' => __( 'Friends', 'friends' ),
)
);

if ( isset( $_GET['updated'] ) ) {
?>
<div id="message" class="updated notice is-dismissible"><p><?php esc_html_e( 'Settings were updated.', 'friends' ); ?></p></div>
<?php
} elseif ( isset( $_GET['error'] ) ) {
?>
<div id="message" class="updated error is-dismissible"><p><?php esc_html_e( 'An error occurred.', 'friends' ); ?></p></div>
<?php
}
Friends::template_loader()->get_template_part( 'admin/automatic-status-list-table', false, compact( 'wp_list_table', 'post_type' ) );
Friends::template_loader()->get_template_part( 'admin/settings-footer' );
}
Expand Down
22 changes: 21 additions & 1 deletion templates/admin/automatic-status-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@
<hr class="wp-header-end">

<p><?php esc_html_e( 'For certain actions that you take in the Friends plugin, a status post is created automatically. Here you can review them and publish them as you like.', 'friends' ); ?></p>
<details>
<summary><?php esc_html_e( /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ 'Settings' ); ?></summary>
<form method="post">
<?php wp_nonce_field( 'friends-automatic-status' ); ?>
<table class="form-table">
<tbody>
<tr>
<td><input type="checkbox" name="enabled" <?php checked( ! get_option( 'friends_automatic_status_disabled' ) ); ?> id="automatic-status-enabled" />
<label for="automatic-status-enabled"><?php esc_html_e( 'Enable automatic status', 'friends' ); ?></label>
<p class="description"><?php esc_html_e( 'When disabled, no draft posts will be automatically created.', '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>
</details>

<?php $args['wp_list_table']->views(); ?>

Expand All @@ -38,4 +58,4 @@
}
?>

</div>
</div>
2 changes: 1 addition & 1 deletion templates/admin/settings-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'friends_admin_tabs',
array(
__( 'Welcome', 'friends' ) => 'friends',
__( 'Settings', 'friends' ) => 'friends-settings',
__( 'Settings' ) => 'friends-settings', // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
__( 'Notification Manager', 'friends' ) => 'friends-notification-manager',
)
);
Expand Down

0 comments on commit 87f8517

Please sign in to comment.