args['after'] ) ) { $offset = substr( base64_decode( $this->args['after'] ), strlen( 'arrayconnection:' ) ); } elseif ( ! empty( $this->args['before'] ) ) { $offset = substr( base64_decode( $this->args['before'] ), strlen( 'arrayconnection:' ) ); } return $offset; } /** * Get the IDs from the source * * @return array|mixed|null */ public function get_ids() { $ids = []; $queried = $this->get_query(); if ( empty( $queried ) ) { return $ids; } foreach ( $queried as $key => $item ) { $ids[ $key ] = $item; } return $ids; } /** * @return array */ public function get_query_args() { return $this->query_args; } /** * Get the items from the source * * @return array|mixed|null */ public function get_query() { $query_args = $this->get_query_args(); return array_keys( wp_get_themes( $query_args ) ); } /** * Get the nodes from the query. * * We slice the array to match the amount of items that was asked for, as we over-fetched * by 1 item to calculate pageInfo. * * For backward pagination, we reverse the order of nodes. * * @return array * @throws \Exception */ public function get_nodes() { $nodes = parent::get_nodes(); if ( isset( $this->args['after'] ) ) { $key = array_search( $this->get_offset(), array_keys( $nodes ), true ); $nodes = array_slice( $nodes, $key + 1, null, true ); } if ( isset( $this->args['before'] ) ) { $nodes = array_reverse( $nodes ); $key = array_search( $this->get_offset(), array_keys( $nodes ), true ); $nodes = array_slice( $nodes, $key + 1, null, true ); $nodes = array_reverse( $nodes ); } $nodes = array_slice( $nodes, 0, $this->query_amount, true ); return ! empty( $this->args['last'] ) ? array_filter( array_reverse( $nodes, true ) ) : $nodes; } /** * The name of the loader to load the data * * @return string */ public function get_loader_name() { return 'theme'; } /** * Determine if the offset used for pagination is valid * * @param mixed $offset * * @return bool */ public function is_valid_offset( $offset ) { return true; } /** * Determine if the query should execute * * @return bool */ public function should_execute() { return true; } /** * Creates the connection for themes * * @param mixed $source The query results of the query calling this relation * @param array $args Query arguments * @param AppContext $context The AppContext object * @param ResolveInfo $info The ResolveInfo object * * @since 0.5.0 * @return array * @throws \Exception */ public static function resolve( $source, array $args, AppContext $context, ResolveInfo $info ) { $themes_array = []; $themes = wp_get_themes(); if ( is_array( $themes ) && ! empty( $themes ) ) { foreach ( $themes as $theme ) { $theme_obj = DataSource::resolve_theme( $theme->get_stylesheet() ); if ( 'private' !== $theme_obj->get_visibility() ) { $themes_array[] = $theme_obj; } } } $connection = Relay::connectionFromArray( $themes_array, $args ); $nodes = []; if ( ! empty( $connection['edges'] ) && is_array( $connection['edges'] ) ) { foreach ( $connection['edges'] as $edge ) { $nodes[] = ! empty( $edge['node'] ) ? $edge['node'] : null; } } $connection['nodes'] = ! empty( $nodes ) ? $nodes : null; return ! empty( $themes_array ) ? $connection : []; } }