$data ) { $slug = dirname( $file ); if ( '.' === $slug ) { $slug = basename( $file, '.php' ); } if ( 'robotstxt-manager' === $slug ) { return is_plugin_active( $file ); } } return false; } /** * Register hooks. * * @since 1.2.1 * * @return void */ public function init(): void { add_action( 'admin_init', array( $this, 'handle_dismiss' ) ); add_action( 'admin_notices', array( $this, 'render_notice' ) ); add_action( 'network_admin_notices', array( $this, 'render_notice' ) ); } /** * Persist the notice dismissal for the current user. * * Runs on admin_init; the notice check on admin_notices (fired later in * the same request) then omits the notice immediately. * * @since 1.2.1 * * @return void */ public function handle_dismiss(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! isset( $_GET[ self::DISMISS_ARG ] ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } check_admin_referer( self::DISMISS_ACTION ); update_user_meta( get_current_user_id(), self::DISMISS_META, 1 ); } /** * Render the dismissible notice on the Plugins list page. * * Hooked to both `admin_notices` (single-site Plugins page) and * `network_admin_notices` (Multisite network Plugins page); both screens * share the `plugins` screen base. * * @since 1.2.1 * * @return void */ public function render_notice(): void { $screen = get_current_screen(); if ( null === $screen || 'plugins' !== $screen->base ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } if ( self::is_manager_active() ) { return; } if ( get_user_meta( get_current_user_id(), self::DISMISS_META, true ) ) { return; } $dismiss_url = wp_nonce_url( add_query_arg( array( self::DISMISS_ARG => 1 ) ), self::DISMISS_ACTION ); ?>