is_wpcom = true; $this->wpcom_is_wpcom_only_endpoint = true; // Match the suggest-guidelines endpoint: register on Simple, Atomic, // and WordPress VIP sites only. if ( ! \Jetpack_AI_Helper::is_enabled_for_content_guidelines() ) { return; } add_action( 'rest_api_init', array( $this, 'register_routes' ) ); } /** * Register routes. */ public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'set_dismissed' ), 'permission_callback' => array( $this, 'permission_callback' ), ), ) ); } /** * Permission check. * * Gated to the same capability as the Content Guidelines page (and the * suggest-guidelines endpoint): only admins ever see the banner, so only * they need to dismiss it. * * @return bool */ public function permission_callback() { return current_user_can( 'manage_options' ); } /** * Whether the current user has dismissed the banner. * * Back-compat alias: the admin-page preload reads the flag via * Jetpack_AI_Helper::is_guidelines_banner_dismissed() instead, because * this class is not loaded during admin page loads on Simple sites. * * @return bool */ public static function is_dismissed() { return Jetpack_AI_Helper::is_guidelines_banner_dismissed(); } /** * Mark the banner as dismissed for the current user. * * Dismissal is one-way — the banner has no "show again" control — so this * only ever sets the flag. * * @return WP_REST_Response */ public function set_dismissed() { update_user_meta( get_current_user_id(), self::META_KEY, '1' ); // Just set above — return it directly instead of re-reading the meta. return rest_ensure_response( array( 'dismissed' => true ) ); } } wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Guidelines_Banner_Dismissed' );