diff --git a/includes/class-user-meta.php b/includes/class-user-meta.php index 26d80bd..baf54af 100644 --- a/includes/class-user-meta.php +++ b/includes/class-user-meta.php @@ -21,7 +21,7 @@ add_action( 'pre_get_users', [ $this, 'sort_by_meta' ] ); add_filter( 'bulk_actions-users', [ $this, 'register_bulk_actions' ] ); add_filter( 'handle_bulk_actions-users', [ $this, 'handle_bulk_actions' ], 10, 3 ); - add_action( 'restrict_manage_users', [ $this, 'filter_dropdown' ] ); + add_filter( 'views_users', [ $this, 'subscription_views' ] ); add_action( 'pre_get_users', [ $this, 'filter_users' ] ); } @@ -33,6 +33,124 @@ return WP_OJS_SSO_Plugin::get_option( 'user_meta_label', __( 'OJS Subscription', 'wp-ojs-sso-bridge' ) ); } + /** + * @param string $filter One of active, requested, none. + * @return array> + */ + private function get_subscription_meta_query( $filter ) { + $key = $this->meta_key(); + + switch ( $filter ) { + case 'active': + return [ + [ + 'key' => $key, + 'value' => '1', + 'compare' => '=', + ], + ]; + case 'requested': + return [ + [ + 'key' => 'ojs_subscription_requested', + 'value' => '1', + 'compare' => '=', + ], + [ + 'relation' => 'OR', + [ + 'key' => $key, + 'compare' => 'NOT EXISTS', + ], + [ + 'key' => $key, + 'value' => '1', + 'compare' => '!=', + ], + ], + ]; + case 'none': + return [ + [ + 'relation' => 'OR', + [ + 'key' => 'ojs_subscription_requested', + 'compare' => 'NOT EXISTS', + ], + [ + 'key' => 'ojs_subscription_requested', + 'value' => '1', + 'compare' => '!=', + ], + ], + ]; + } + + return []; + } + + /** + * @param string $filter One of active, requested, none. + * @return int + */ + private function count_users_by_subscription_filter( $filter ) { + $meta_query = $this->get_subscription_meta_query( $filter ); + if ( empty( $meta_query ) ) { + return 0; + } + + $query = new WP_User_Query( + [ + 'fields' => 'ID', + 'number' => 1, + 'count_total' => true, + 'meta_query' => $meta_query, + ] + ); + + return (int) $query->get_total(); + } + + /** + * Quick-filter links above the users list (alongside role views). + * + * @param array $views Existing views. + * @return array + */ + public function subscription_views( $views ) { + if ( ! is_admin() ) { + return $views; + } + + $current = isset( $_GET['ojs_sub_filter'] ) ? sanitize_key( wp_unslash( $_GET['ojs_sub_filter'] ) ) : ''; + $base = admin_url( 'users.php' ); + + $filters = [ + 'requested' => __( 'Subscription requested', 'wp-ojs-sso-bridge' ), + 'active' => __( 'Active subscription', 'wp-ojs-sso-bridge' ), + ]; + + foreach ( $filters as $slug => $label ) { + $count = $this->count_users_by_subscription_filter( $slug ); + $url = add_query_arg( 'ojs_sub_filter', $slug, $base ); + $text = sprintf( + /* translators: 1: filter label, 2: number of users */ + __( '%1$s (%2$s)', 'wp-ojs-sso-bridge' ), + $label, + number_format_i18n( $count ) + ); + + $views[ 'ojs_sub_' . $slug ] = sprintf( + '%s', + esc_url( $url ), + ( $current === $slug ) ? ' class="current"' : '', + $text + ); + } + + return $views; + } + public function add_column( $columns ) { $columns['ojs_subscription'] = $this->meta_label(); $columns['ojs_sub_files'] = __( 'Subscription documents', 'wp-ojs-sso-bridge' ); @@ -159,52 +277,29 @@ return $redirect_to; } - public function filter_dropdown( $which ) { - if ( 'top' !== $which ) { - return; - } - $current = $_GET['ojs_sub_filter'] ?? ''; - ?> - - meta_key(); - $meta_query = $query->get( 'meta_query' ) ?: []; + $clauses = $this->get_subscription_meta_query( $filter ); + if ( empty( $clauses ) ) { + return; + } - switch ( $filter ) { - case 'active': - $meta_query[] = [ 'key' => $key, 'value' => '1', 'compare' => '=' ]; - break; - case 'requested': - $meta_query[] = [ 'key' => 'ojs_subscription_requested', 'value' => '1', 'compare' => '=' ]; - $meta_query[] = [ - 'relation' => 'OR', - [ 'key' => $key, 'compare' => 'NOT EXISTS' ], - [ 'key' => $key, 'value' => '1', 'compare' => '!=' ], - ]; - break; - case 'none': - $meta_query[] = [ - 'relation' => 'OR', - [ 'key' => 'ojs_subscription_requested', 'compare' => 'NOT EXISTS' ], - [ 'key' => 'ojs_subscription_requested', 'value' => '1', 'compare' => '!=' ], - ]; - break; + $meta_query = $query->get( 'meta_query' ) ?: []; + foreach ( $clauses as $clause ) { + $meta_query[] = $clause; } $query->set( 'meta_query', $meta_query ); diff --git a/languages/wp-ojs-sso-bridge-it_IT.po b/languages/wp-ojs-sso-bridge-it_IT.po index ff8e7b7..4d1d59c 100644 --- a/languages/wp-ojs-sso-bridge-it_IT.po +++ b/languages/wp-ojs-sso-bridge-it_IT.po @@ -3,7 +3,7 @@ # This file is distributed under the GPL-2.0-or-later. msgid "" msgstr "" -"Project-Id-Version: WP OJS SSO Bridge 1.1.0\n" +"Project-Id-Version: WP OJS SSO Bridge 1.2.0\n" "PO-Revision-Date: 2026-04-16T00:00:00+00:00\n" "Last-Translator: GuIT \n" "Language-Team: Italian\n" @@ -96,6 +96,15 @@ msgid "Deactivate OJS Subscription" msgstr "Disattiva sottoscrizione OJS" +msgid "Subscription requested" +msgstr "Richiesta sottoscrizione" + +msgid "Active subscription" +msgstr "Sottoscrizione attiva" + +msgid "%1$s (%2$s)" +msgstr "%1$s (%2$s)" + msgid "All subscriptions" msgstr "Tutte le sottoscrizioni" diff --git a/languages/wp-ojs-sso-bridge.pot b/languages/wp-ojs-sso-bridge.pot index b6b454e..75cc7c7 100644 --- a/languages/wp-ojs-sso-bridge.pot +++ b/languages/wp-ojs-sso-bridge.pot @@ -2,7 +2,7 @@ # This file is distributed under the GPL-2.0-or-later. msgid "" msgstr "" -"Project-Id-Version: WP OJS SSO Bridge 1.0.0\n" +"Project-Id-Version: WP OJS SSO Bridge 1.2.0\n" "Report-Msgid-Bugs-To: https://github.com/nicola-arrigoni/wp-ojs-sso-bridge\n" "POT-Creation-Date: 2026-04-16T00:00:00+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" @@ -99,6 +99,16 @@ msgid "Deactivate OJS Subscription" msgstr "" +#: includes/class-user-meta.php +msgid "Subscription requested" +msgstr "" + +msgid "Active subscription" +msgstr "" + +msgid "%1$s (%2$s)" +msgstr "" + msgid "All subscriptions" msgstr "" diff --git a/readme.txt b/readme.txt index 6fa75de..5fc3c2c 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Requires at least: 6.0 Tested up to: 6.8 Requires PHP: 7.4 -Stable tag: 1.1.0 +Stable tag: 1.2.0 License: GPL-2.0-or-later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -36,6 +36,10 @@ == Changelog == += 1.2.0 = +* Quick-filter links on the Users screen: "Subscription requested" and "Active subscription" (with counts). +* Removed the hard-to-find subscription dropdown above the users table. + = 1.1.0 = * Ricevuta bonifico obbligatoria per la richiesta di sottoscrizione: upload in Media in `file-utenti/{slug-utente}/bonifico`. * Documento studente: stesso meccanismo in `file-utenti/{slug-utente}/certificato` (i vecchi file sotto `ojs-sso-bridge/{id}/` restano scaricabili fino a sostituzione). diff --git a/wp-ojs-sso-bridge.php b/wp-ojs-sso-bridge.php index 0dabb44..aff5dd5 100644 --- a/wp-ojs-sso-bridge.php +++ b/wp-ojs-sso-bridge.php @@ -3,7 +3,7 @@ * Plugin Name: WP OJS SSO Bridge * Plugin URI: https://github.com/nicola-arrigoni/wp-ojs-sso-bridge * Description: Bridges WordPress and Open Journal Systems (OJS) via OpenID Connect. Manages journal subscription status on WordPress users and exposes it as an OIDC claim so OJS can grant or deny access to protected issues. - * Version: 1.1.0 + * Version: 1.2.0 * Requires at least: 6.0 * Requires PHP: 7.4 * Author: GuIT – Gruppo Utilizzatori Italiani di TeX @@ -18,7 +18,7 @@ exit; } -define( 'WP_OJS_SSO_VERSION', '1.1.0' ); +define( 'WP_OJS_SSO_VERSION', '1.2.0' ); define( 'WP_OJS_SSO_FILE', __FILE__ ); define( 'WP_OJS_SSO_DIR', plugin_dir_path( __FILE__ ) ); define( 'WP_OJS_SSO_URL', plugin_dir_url( __FILE__ ) );