plugin = $plugin;
add_filter( 'bulk_actions-edit-wp_stream_alerts', array( $this, 'suppress_bulk_actions' ), 10, 1 );
add_filter( 'disable_months_dropdown', array( $this, 'suppress_months_dropdown' ), 10, 2 );
add_filter( 'post_row_actions', array( $this, 'suppress_quick_edit' ), 10, 1 );
// @todo Make more specific
if ( is_admin() ) {
add_filter( 'request', array( $this, 'parse_request' ), 10, 2 );
}
add_filter( 'views_edit-wp_stream_alerts', array( $this, 'manage_views' ) );
add_filter( 'manage_wp_stream_alerts_posts_columns', array( $this, 'manage_columns' ) );
add_action( 'manage_wp_stream_alerts_posts_custom_column', array( $this, 'column_data' ), 10, 2 );
add_action( 'quick_edit_custom_box', array( $this, 'display_custom_quick_edit' ), 10, 2 );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_filter( 'wp_insert_post_data', array( $this, 'save_alert_inline_edit' ), 99, 2 );
}
/**
* Default to wp_stream_enabled and wp_stream_disabled when querying for alerts
*
* @filter request
*
* @param array $query_vars Arguments for query to populate table.
* @return array
*/
public function parse_request( $query_vars ) {
$screen = \get_current_screen();
if ( 'edit-wp_stream_alerts' === $screen->id && Alerts::POST_TYPE === $query_vars['post_type'] && empty( $query_vars['post_status'] ) ) {
$query_vars['post_status'] = array( 'wp_stream_enabled', 'wp_stream_disabled' );
}
return $query_vars;
}
/**
* Manage views on the alerts list view
*
* @filter views_edit-wp_stream_alerts
*
* @param array $views View links HTML.
* @return array
*/
public function manage_views( $views ) {
if ( array_key_exists( 'trash', $views ) ) {
$trash = $views['trash'];
unset( $views['trash'] );
$views['trash'] = $trash;
}
return $views;
}
/**
* Manages columns on the alerts list view
*
* @filter manage_wp_stream_alerts_posts_columns
*
* @param array $columns Column id -> title array.
* @return array
*/
public function manage_columns( $columns ) {
$columns = array(
'cb' => $columns['cb'],
'alert_trigger' => __( 'Trigger', 'stream' ),
'alert_type' => __( 'Type', 'stream' ),
'alert_status' => __( 'Status', 'stream' ),
);
return $columns;
}
/**
* Fills in column data for custom columns.
*
* @action manage_wp_stream_alerts_posts_custom_column
*
* @param string $column_name Column name to show data for.
* @param int $post_id The post being processed.
* @return mixed
*/
public function column_data( $column_name, $post_id ) {
$alert = $this->plugin->alerts->get_alert( $post_id );
if ( ! $alert ) {
return;
}
switch ( $column_name ) {
case 'alert_trigger':
$values = array();
foreach ( $this->plugin->alerts->alert_triggers as $trigger_type => $trigger_obj ) {
$value = $trigger_obj->get_display_value( 'list_table', $alert );
$values[] = '' . esc_html( $value ) . '';
}
?>
custom_column_actions( $post_id ) ); ?>
alert_meta['trigger_connector'] ) ) {
$trigger_connector = $alert->alert_meta['trigger_connector'];
} else {
$trigger_connector = '';
}
if ( ! empty( $alert->alert_meta['trigger_context'] ) ) {
$trigger_context = $alert->alert_meta['trigger_context'];
} else {
$trigger_context = '';
}
if ( ! empty( $alert->alert_meta['trigger_action'] ) ) {
$trigger_action = $alert->alert_meta['trigger_action'];
} else {
$trigger_action = '';
}
?>
custom_column_actions( $post_id ) );
break;
case 'alert_type':
$alert_type = $alert->alert_type;
if ( ! empty( $this->plugin->alerts->alert_types[ $alert_type ]->name ) ) {
$alert_name = $this->plugin->alerts->alert_types[ $alert_type ]->name;
} else {
$alert_name = 'Untitled Alert';
}
?>
alert_meta['color'] ) ) {
?>
alert_meta['email_recipient'] ) ) {
?>
alert_meta['email_subject'] ) ) {
?>
alert_meta['event_name'] ) ) {
?>
alert_meta['maker_key'] ) ) {
?>
alert_meta['slack_webhook'] ) ) {
?>
alert_meta['slack_channel'] ) ) {
?>
alert_meta['slack_username'] ) ) {
?>
alert_meta['slack_icon'] ) ) {
?>
label );
}
?>
id ) {
return;
}
wp_nonce_field( plugin_basename( __FILE__ ), Alerts::POST_TYPE . '_edit_nonce' );
$box_type = array(
'triggers',
'notification',
'submit',
);
?>
id ) {
return;
}
$min = wp_stream_min_suffix();
wp_register_script(
'wp-stream-alerts-list-js',
$this->plugin->locations['url'] . 'ui/js/alerts-list.' . $min . 'js',
array(
'wp-stream-alerts',
'jquery',
),
$this->plugin->get_version(),
false
);
wp_register_style(
'wp-stream-alerts-list-css',
$this->plugin->locations['url'] . 'ui/css/alerts-list.' . $min . 'css',
array(),
$this->plugin->get_version()
);
wp_enqueue_script( 'wp-stream-alerts-list-js' );
wp_enqueue_style( 'wp-stream-alerts-list-css' );
wp_enqueue_style( 'wp-stream-select2' );
}
/**
* Save alert meta after using the inline editor.
*
* @param array $data Filtered post data.
* @param array $postarr Raw post data.
*
* @return array
*/
public function save_alert_inline_edit( $data, $postarr ) {
if ( did_action( 'customize_preview_init' ) || empty( $postarr['ID'] ) ) {
return $data;
}
$post_id = $postarr['ID'];
$post_type = wp_stream_filter_input( INPUT_POST, 'post_type' );
if ( Alerts::POST_TYPE !== $post_type ) {
return $data;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $data;
}
$nonce = wp_stream_filter_input( INPUT_POST, Alerts::POST_TYPE . '_edit_nonce' );
if ( null === $nonce || ! wp_verify_nonce( $nonce, plugin_basename( __FILE__ ) ) ) {
return $data;
}
$trigger_author = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_author' );
$trigger_connector_and_context = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_connector_or_context' );
$trigger_connector_and_context_split = explode( '-', $trigger_connector_and_context );
$trigger_connector = $trigger_connector_and_context_split[0];
$trigger_context = $trigger_connector_and_context_split[1];
$trigger_action = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_action' );
$alert_type = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_type' );
$alert_status = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_status' );
$data['post_status'] = $alert_status;
update_post_meta( $post_id, 'alert_type', $alert_type );
$alert_meta = array(
'trigger_author' => $trigger_author,
'trigger_connector' => $trigger_connector,
'trigger_action' => $trigger_action,
'trigger_context' => $trigger_context,
);
$alert_meta = apply_filters( 'wp_stream_alerts_save_meta', $alert_meta, $alert_type );
update_post_meta( $post_id, 'alert_meta', $alert_meta );
return $data;
}
}