Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Oct 9, 2023
2 parents bfc0530 + 905683d commit 865e1a3
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 307 deletions.
20 changes: 0 additions & 20 deletions classes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,6 @@ public function __construct( $plugin ) {
)
);

/**
* Uninstall Streams and Deactivate plugin.
*
* @todo Confirm if variable assignment is necessary.
*/
$uninstall = $this->plugin->db->driver->purge_storage( $this->plugin );

// Auto purge setup.
add_action( 'wp_loaded', array( $this, 'purge_schedule_setup' ) );
add_action(
Expand Down Expand Up @@ -472,7 +465,6 @@ public function admin_enqueue_scripts( $hook ) {
'i18n' => array(
'confirm_purge' => esc_html__( 'Are you sure you want to delete all Stream activity records from the database? This cannot be undone.', 'stream' ),
'confirm_defaults' => esc_html__( 'Are you sure you want to reset all site settings to default? This cannot be undone.', 'stream' ),
'confirm_uninstall' => esc_html__( 'Are you sure you want to uninstall and deactivate Stream? This will delete all Stream tables from the database and cannot be undone.', 'stream' ),
),
'locale' => esc_js( $locale ),
'gmt_offset' => get_option( 'gmt_offset' ),
Expand Down Expand Up @@ -822,18 +814,6 @@ public function plugin_action_links( $links, $file ) {

$links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) );

if ( ! defined( 'DISALLOW_FILE_MODS' ) || false === DISALLOW_FILE_MODS ) {
$url = add_query_arg(
array(
'action' => 'wp_stream_uninstall',
'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
),
admin_url( 'admin-ajax.php' )
);

$links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) );
}

return $links;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/class-alerts-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function manage_columns( $columns ) {
public function column_data( $column_name, $post_id ) {

$alert = $this->plugin->alerts->get_alert( $post_id );
if ( ! $alert ) {
if ( false === $alert ) {
return;
}

Expand Down
47 changes: 34 additions & 13 deletions classes/class-alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class Alerts {
*/
const ALERTS_TRIGGERED_META_KEY = 'wp_stream_alerts_triggered';

/**
* Capability required to access alerts.
*/
const CAPABILITY = 'manage_options';

/**
* Holds Instance of plugin object
*
Expand Down Expand Up @@ -280,6 +285,10 @@ public function check_records( $record_id, $recordarr ) {
foreach ( $alerts->posts as $alert ) {
$alert = $this->get_alert( $alert->ID );

if ( false === $alert ) {
continue;
}

$status = $alert->check_record( $record_id, $recordarr );
if ( $status ) {
$alert->send_alert( $record_id, $recordarr ); // @todo send_alert expects int, not array.
Expand Down Expand Up @@ -363,14 +372,14 @@ public function register_post_type() {
'show_in_menu' => false, // @see modify_admin_menu
'supports' => false,
'capabilities' => array(
'publish_posts' => 'manage_options',
'edit_others_posts' => 'manage_options',
'delete_posts' => 'manage_options',
'delete_others_posts' => 'manage_options',
'read_private_posts' => 'manage_options',
'edit_post' => 'manage_options',
'delete_post' => 'manage_options',
'read_post' => 'manage_options',
'publish_posts' => self::CAPABILITY,
'edit_others_posts' => self::CAPABILITY,
'delete_posts' => self::CAPABILITY,
'delete_others_posts' => self::CAPABILITY,
'read_private_posts' => self::CAPABILITY,
'edit_post' => self::CAPABILITY,
'delete_post' => self::CAPABILITY,
'read_post' => self::CAPABILITY,
),
);

Expand Down Expand Up @@ -444,7 +453,7 @@ public function register_menu() {
$this->plugin->admin->records_page_slug,
__( 'Alerts', 'stream' ),
__( 'Alerts', 'stream' ),
'manage_options',
self::CAPABILITY,
'edit.php?post_type=wp_stream_alerts'
);
}
Expand Down Expand Up @@ -512,8 +521,10 @@ public function display_notification_box( $post = array() ) {
$alert = null;
$alert_type = 'none';
if ( is_object( $post ) ) {
$alert = $this->get_alert( $post->ID );
$alert_type = $alert->alert_type;
$alert = $this->get_alert( $post->ID );
if ( false !== $alert ) {
$alert_type = $alert->alert_type;
}
}
$form = new Form_Generator();

Expand Down Expand Up @@ -550,11 +561,18 @@ public function display_notification_box( $post = array() ) {
* @return void
*/
public function load_alerts_settings() {
if ( ! current_user_can( self::CAPABILITY ) ) {
wp_send_json_error(
array(
'message' => 'You do not have permission to do this.',
)
);
}
$alert = array();
$post_id = wp_stream_filter_input( INPUT_POST, 'post_id' );
if ( ! empty( $post_id ) ) {
$alert = $this->get_alert( $post_id );
if ( ! $alert ) {
if ( false === $alert ) {
wp_send_json_error(
array(
'message' => 'Could not find alert.',
Expand Down Expand Up @@ -594,11 +612,14 @@ public function load_alerts_settings() {
* @return void
*/
public function display_triggers_box( $post = array() ) {
$alert = false;
if ( is_object( $post ) ) {
$alert = $this->get_alert( $post->ID );
} else {
}
if ( false === $alert ) {
$alert = array();
}

$form = new Form_Generator();
do_action( 'wp_stream_alert_trigger_form_display', $form, $alert );
// @TODO use human readable text.
Expand Down
7 changes: 1 addition & 6 deletions classes/class-db-driver-wpdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,8 @@ public function setup_storage( $plugin ) {
* Purge storage.
*
* @param \WP_Stream\Plugin $plugin Instance of the plugin.
* @return \WP_Stream\Uninstall
*/
public function purge_storage( $plugin ) {
$uninstall = new Uninstall( $plugin );
add_action( 'wp_ajax_wp_stream_uninstall', array( $uninstall, 'uninstall' ) );

return $uninstall;
// @TODO: Not doing anything here until the deactivation/uninstall flow has been rethought.
}

}
2 changes: 1 addition & 1 deletion classes/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Plugin {
*
* @const string
*/
const VERSION = '3.9.2';
const VERSION = '3.9.3';

/**
* WP-CLI command
Expand Down
Loading

0 comments on commit 865e1a3

Please sign in to comment.