WP_REST_Server::READABLE, 'callback' => array( __CLASS__, 'status' ), 'permission_callback' => array( __CLASS__, 'may_see_site_report' ), ) ); register_rest_route( self::NAMESPACE, '/updates', array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( __CLASS__, 'updates' ), 'permission_callback' => array( __CLASS__, 'may_see_updates' ), 'args' => array( 'refresh' => array( 'type' => 'boolean', 'default' => false, ), ), ) ); } /** * Who may read the report: those WordPress lets open Site Health, which shows the * same versions, the same file-system facts and whether updates are available. * Not edit_posts (a Contributor has it), and not the update capabilities: * WordPress removes those on a site that disallows file changes, which is exactly * where the report's file_mods_allowed matters. */ public static function may_see_site_report() { return current_user_can( 'view_site_health_checks' ); } /** Who may read the list of updates: those WordPress lets open its Updates screen. */ public static function may_see_updates() { return current_user_can( 'update_plugins' ) || current_user_can( 'update_themes' ); } public static function status() { $pending = Automatio_Connect_Updates::pending_updates(); return rest_ensure_response( array( 'plugin_version' => AUTOMATIO_CONNECT_VERSION, 'wordpress_version' => get_bloginfo( 'version' ), 'php_version' => PHP_VERSION, 'file_mods_allowed' => Automatio_Connect_Updates::file_mods_allowed(), 'pending_updates' => array( 'plugins' => count( $pending['plugins'] ), 'themes' => count( $pending['themes'] ), ), ) ); } public static function updates( WP_REST_Request $request ) { if ( $request->get_param( 'refresh' ) ) { Automatio_Connect_Updates::refresh_updates(); } return rest_ensure_response( Automatio_Connect_Updates::pending_updates() ); } }