__( 'Store policies', 'agent-adapt' ), 'description' => __( 'The store\'s published policies (returns and refunds, terms, privacy) as plain text, with the store\'s currency and country.', 'agent-adapt' ), 'method' => 'GET', 'path' => '/store/policies', 'response' => array( 'type' => 'object', 'properties' => array( 'store' => array( 'type' => 'object' ), 'policies' => array( 'type' => 'array', 'items' => array( 'type' => 'object' ) ), ), ), 'handler' => array( __CLASS__, 'policies' ), ) ); } /** * store.policies * * @param AgentAdapt_Context $context Who is asking. * @param array $p Params (none). * @return array */ public static function policies( AgentAdapt_Context $context, array $p ): array { $pages = array( 'refund_returns' => (int) get_option( 'woocommerce_refund_returns_page_id', 0 ), 'terms' => (int) wc_terms_and_conditions_page_id(), 'privacy' => (int) get_option( 'wp_page_for_privacy_policy', 0 ), ); $policies = array(); foreach ( $pages as $type => $id ) { $post = $id ? get_post( $id ) : null; if ( ! $post || 'publish' !== $post->post_status || post_password_required( $post ) ) { continue; } $policies[] = array( 'type' => $type, 'title' => AgentAdapt_Catalog::text( get_the_title( $post ) ), 'url' => (string) get_permalink( $post ), 'updated' => get_post_modified_time( 'c', true, $post ), 'text' => AgentAdapt_Catalog::text( strip_shortcodes( do_blocks( (string) $post->post_content ) ), self::MAX_TEXT ), ); } AgentAdapt_Events::record( 'store.policies', $context ); return array( 'store' => array( 'name' => wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ), 'url' => home_url( '/' ), 'currency' => get_woocommerce_currency(), 'country' => WC()->countries ? WC()->countries->get_base_country() : '', ), 'policies' => $policies, ); } }