$tools['refresh_remote_inbox_notifications'] = array( 'name' => __( 'Refresh Remote Inbox Notifications', 'woocommerce' ), 'button' => __( 'Refresh', 'woocommerce' ), 'desc' => __( 'This will refresh the remote inbox notifications', 'woocommerce' ), 'callback' => function () { RemoteInboxNotificationsDataSourcePoller::get_instance()->read_specs_from_data_sources(); RemoteInboxNotificationsEngine::run(); return __( 'Remote inbox notifications have been refreshed', 'woocommerce' ); }, ); $tools['delete_inbox_notification'] = array( 'name' => __( 'Delete an Inbox Notification', 'woocommerce' ), 'button' => __( 'Delete', 'woocommerce' ), 'desc' => __( 'This will delete an inbox notification by slug', 'woocommerce' ), 'selector' => array( 'description' => __( 'Select an inbox notification to delete:', 'woocommerce' ), 'class' => 'wc-product-search', 'search_action' => 'woocommerce_json_inbox_notifications_search', 'name' => 'delete_inbox_notification_note_id', 'placeholder' => esc_attr__( 'Search for an inbox notification…', 'woocommerce' ), ), 'callback' => function () { check_ajax_referer( 'debug_action', '_wpnonce' ); if ( ! isset( $_GET['delete_inbox_notification_note_id'] ) ) { return __( 'No inbox notification selected', 'woocommerce' ); } $note_id = wc_clean( sanitize_text_field( wp_unslash( $_GET['delete_inbox_notification_note_id'] ) ) ); $note = Notes::get_note( $note_id ); if ( ! $note ) { return __( 'Inbox notification not found', 'woocommerce' ); } $note->delete( true ); return __( 'Inbox notification has been deleted', 'woocommerce' ); }, ); return $tools; } /** * Add ajax action for remote inbox notification search. * * @return void */ private static function ajax_action_inbox_notification_search() { global $wpdb; check_ajax_referer( 'search-products', 'security' ); if ( ! isset( $_GET['term'] ) ) { wp_send_json( array() ); } $search = wc_clean( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); $results = $wpdb->get_results( $wpdb->prepare( "SELECT note_id, name FROM {$wpdb->prefix}wc_admin_notes WHERE name LIKE %s", '%' . $wpdb->esc_like( $search ) . '%' ) ); $rows = array(); foreach ( $results as $result ) { $rows[ $result->note_id ] = $result->name; } wp_send_json( $rows ); } }