Updates the endpoint to fetch marketing knowledgebase posts.
This commit is contained in:
parent
48016efaa6
commit
0e65ea53cc
|
@ -136,43 +136,29 @@ class MarketingSpecs {
|
||||||
/**
|
/**
|
||||||
* Load knowledge base posts from WooCommerce.com
|
* Load knowledge base posts from WooCommerce.com
|
||||||
*
|
*
|
||||||
* @param string|null $term Term of posts to retrieve.
|
* @param string|null $topic The topic of marketing knowledgebase to retrieve.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_knowledge_base_posts( ?string $term ): array {
|
public function get_knowledge_base_posts( ?string $topic ): array {
|
||||||
$terms = array(
|
$available_topics = array( 'marketing', 'coupons' );
|
||||||
'marketing' => array(
|
|
||||||
'taxonomy' => 'category',
|
|
||||||
'term_id' => 1744,
|
|
||||||
'argument' => 'categories',
|
|
||||||
),
|
|
||||||
'coupons' => array(
|
|
||||||
'taxonomy' => 'post_tag',
|
|
||||||
'term_id' => 1377,
|
|
||||||
'argument' => 'tags',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Default to the marketing category (if no term is set on the kb component).
|
// Default to the marketing topic (if no topic is set on the kb component).
|
||||||
if ( empty( $term ) || ! array_key_exists( $term, $terms ) ) {
|
if ( empty( $topic ) || ! in_array( $topic, $available_topics, true ) ) {
|
||||||
$term = 'marketing';
|
$topic = 'marketing';
|
||||||
}
|
}
|
||||||
|
|
||||||
$term_id = $terms[ $term ]['term_id'];
|
$kb_transient = self::KNOWLEDGE_BASE_TRANSIENT . '_' . strtolower( $topic );
|
||||||
$argument = $terms[ $term ]['argument'];
|
|
||||||
$kb_transient = self::KNOWLEDGE_BASE_TRANSIENT . '_' . strtolower( $term );
|
|
||||||
|
|
||||||
$posts = get_transient( $kb_transient );
|
$posts = get_transient( $kb_transient );
|
||||||
|
|
||||||
if ( false === $posts ) {
|
if ( false === $posts ) {
|
||||||
$request_url = add_query_arg(
|
$request_url = add_query_arg(
|
||||||
array(
|
array(
|
||||||
$argument => $term_id,
|
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 8,
|
'per_page' => 8,
|
||||||
'_embed' => 1,
|
'_embed' => 1,
|
||||||
),
|
),
|
||||||
'https://woocommerce.com/wp-json/wp/v2/posts?utm_medium=product'
|
'https://woocommerce.com/wccom/marketing-knowledgebase/v1/posts/' . $topic
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = wp_remote_get(
|
$request = wp_remote_get(
|
||||||
|
|
Loading…
Reference in New Issue