'GET', 'callback' => array( __CLASS__, 'forms' ), 'permission_callback' => static function () { return current_user_can( 'edit_posts' ); }, 'args' => array( 'refresh' => array( 'type' => 'boolean', 'default' => false, ), ), ) ); } /** * The forms and projects. `can_manage` says whether this user may connect the site and refresh * the list (`refresh=1`, administrators only). * * @param WP_REST_Request $request The request. * @return array{connected: bool, available: bool, can_manage: bool, forms: array, projects: array} */ public static function forms( $request ) { $can_manage = current_user_can( 'manage_options' ); if ( ! Connection::is_active() ) { return array( 'connected' => false, 'available' => false, 'can_manage' => $can_manage, 'forms' => array(), 'projects' => array(), ); } $refresh = $can_manage && is_object( $request ) && method_exists( $request, 'get_param' ) && $request->get_param( 'refresh' ); $list = Forms::get( (bool) $refresh ); if ( null === $list ) { return array( 'connected' => true, 'available' => false, 'can_manage' => $can_manage, 'forms' => array(), 'projects' => array(), ); } return array( 'connected' => true, 'available' => true, 'can_manage' => $can_manage, 'forms' => array_map( static function ( $form ) { return array( 'id' => $form['id'], 'name' => $form['name'], 'project' => $form['project'], ); }, $list['forms'] ), 'projects' => $list['projects'], ); } }