@@ -8,101 +8,101 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Ingredients_Taxonomy_Recipe_Lift_Strategy implements Recipe_Lift_Strategy { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var Ingredients_Client |
|
| 13 | - */ |
|
| 14 | - private $ingredients_client; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @var Notices |
|
| 18 | - */ |
|
| 19 | - private $notices; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var Content_Service |
|
| 23 | - */ |
|
| 24 | - private $content_service; |
|
| 25 | - |
|
| 26 | - public function __construct( Ingredients_Client $ingredients_client, Notices $notices, Content_Service $content_service ) { |
|
| 27 | - $this->ingredients_client = $ingredients_client; |
|
| 28 | - $this->notices = $notices; |
|
| 29 | - $this->content_service = $content_service; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function run() { |
|
| 33 | - $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) ); |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var WP_Term[] $terms |
|
| 37 | - */ |
|
| 38 | - $terms = get_terms( |
|
| 39 | - array( |
|
| 40 | - 'taxonomy' => 'wprm_ingredient', |
|
| 41 | - 'fields' => 'all', |
|
| 42 | - 'hide_empty' => false, |
|
| 43 | - ) |
|
| 44 | - ); |
|
| 45 | - $filtered_terms = $this->terms_without_about_jsonld( $terms ); |
|
| 46 | - $filtered_terms_names = array_map( array( $this, 'term_name' ), $filtered_terms ); |
|
| 47 | - $ingredients = $this->ingredients_client->ingredients( $filtered_terms_names ); |
|
| 48 | - |
|
| 49 | - foreach ( $ingredients as $key => $value ) { |
|
| 50 | - $term = get_term_by( 'name', $key, 'wprm_ingredient' ); |
|
| 51 | - if ( ! isset( $term ) ) { |
|
| 52 | - continue; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - $this->content_service->set_about_jsonld( |
|
| 56 | - Wordpress_Content_Id::create_term( $term->term_id ), |
|
| 57 | - $value |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @@todo update notification with progress |
|
| 62 | - */ |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // Clean up caches. |
|
| 66 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @@todo add notification that procedure is complete, with information about the number of processed items vs |
|
| 70 | - * total items |
|
| 71 | - */ |
|
| 72 | - $count_terms = count( $filtered_terms ); |
|
| 73 | - $count_lifted_terms = count( $ingredients ); |
|
| 74 | - /* translators: 1: The number of lifted ingredients, 2: The total number of ingredients. */ |
|
| 75 | - $this->notices->queue( 'info', sprintf( __( 'WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift' ), $count_lifted_terms, $count_terms ) ); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param $terms WP_Term[] An array of terms. |
|
| 80 | - * |
|
| 81 | - * @return WP_Term[] |
|
| 82 | - */ |
|
| 83 | - private function terms_without_about_jsonld( $terms ) { |
|
| 84 | - return array_filter( $terms, array( $this, 'term_has_not_about_jsonld' ) ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param $term WP_Term |
|
| 89 | - * |
|
| 90 | - * @return bool true if the term has an about_jsonld otherwise false. |
|
| 91 | - */ |
|
| 92 | - private function term_has_not_about_jsonld( $term ) { |
|
| 93 | - $about_jsonld = $this->content_service->get_about_jsonld( |
|
| 94 | - Wordpress_Content_Id::create_term( $term->term_id ) |
|
| 95 | - ); |
|
| 96 | - |
|
| 97 | - return $about_jsonld === null; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param $term WP_Term |
|
| 102 | - * |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public function term_name( $term ) { |
|
| 106 | - return $term->name; |
|
| 107 | - } |
|
| 11 | + /** |
|
| 12 | + * @var Ingredients_Client |
|
| 13 | + */ |
|
| 14 | + private $ingredients_client; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @var Notices |
|
| 18 | + */ |
|
| 19 | + private $notices; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var Content_Service |
|
| 23 | + */ |
|
| 24 | + private $content_service; |
|
| 25 | + |
|
| 26 | + public function __construct( Ingredients_Client $ingredients_client, Notices $notices, Content_Service $content_service ) { |
|
| 27 | + $this->ingredients_client = $ingredients_client; |
|
| 28 | + $this->notices = $notices; |
|
| 29 | + $this->content_service = $content_service; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function run() { |
|
| 33 | + $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) ); |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var WP_Term[] $terms |
|
| 37 | + */ |
|
| 38 | + $terms = get_terms( |
|
| 39 | + array( |
|
| 40 | + 'taxonomy' => 'wprm_ingredient', |
|
| 41 | + 'fields' => 'all', |
|
| 42 | + 'hide_empty' => false, |
|
| 43 | + ) |
|
| 44 | + ); |
|
| 45 | + $filtered_terms = $this->terms_without_about_jsonld( $terms ); |
|
| 46 | + $filtered_terms_names = array_map( array( $this, 'term_name' ), $filtered_terms ); |
|
| 47 | + $ingredients = $this->ingredients_client->ingredients( $filtered_terms_names ); |
|
| 48 | + |
|
| 49 | + foreach ( $ingredients as $key => $value ) { |
|
| 50 | + $term = get_term_by( 'name', $key, 'wprm_ingredient' ); |
|
| 51 | + if ( ! isset( $term ) ) { |
|
| 52 | + continue; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + $this->content_service->set_about_jsonld( |
|
| 56 | + Wordpress_Content_Id::create_term( $term->term_id ), |
|
| 57 | + $value |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @@todo update notification with progress |
|
| 62 | + */ |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // Clean up caches. |
|
| 66 | + do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @@todo add notification that procedure is complete, with information about the number of processed items vs |
|
| 70 | + * total items |
|
| 71 | + */ |
|
| 72 | + $count_terms = count( $filtered_terms ); |
|
| 73 | + $count_lifted_terms = count( $ingredients ); |
|
| 74 | + /* translators: 1: The number of lifted ingredients, 2: The total number of ingredients. */ |
|
| 75 | + $this->notices->queue( 'info', sprintf( __( 'WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift' ), $count_lifted_terms, $count_terms ) ); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param $terms WP_Term[] An array of terms. |
|
| 80 | + * |
|
| 81 | + * @return WP_Term[] |
|
| 82 | + */ |
|
| 83 | + private function terms_without_about_jsonld( $terms ) { |
|
| 84 | + return array_filter( $terms, array( $this, 'term_has_not_about_jsonld' ) ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param $term WP_Term |
|
| 89 | + * |
|
| 90 | + * @return bool true if the term has an about_jsonld otherwise false. |
|
| 91 | + */ |
|
| 92 | + private function term_has_not_about_jsonld( $term ) { |
|
| 93 | + $about_jsonld = $this->content_service->get_about_jsonld( |
|
| 94 | + Wordpress_Content_Id::create_term( $term->term_id ) |
|
| 95 | + ); |
|
| 96 | + |
|
| 97 | + return $about_jsonld === null; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param $term WP_Term |
|
| 102 | + * |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public function term_name( $term ) { |
|
| 106 | + return $term->name; |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -23,37 +23,37 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | private $content_service; |
| 25 | 25 | |
| 26 | - public function __construct( Ingredients_Client $ingredients_client, Notices $notices, Content_Service $content_service ) { |
|
| 26 | + public function __construct(Ingredients_Client $ingredients_client, Notices $notices, Content_Service $content_service) { |
|
| 27 | 27 | $this->ingredients_client = $ingredients_client; |
| 28 | 28 | $this->notices = $notices; |
| 29 | 29 | $this->content_service = $content_service; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function run() { |
| 33 | - $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) ); |
|
| 33 | + $this->notices->queue('info', __('WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift')); |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * @var WP_Term[] $terms |
| 37 | 37 | */ |
| 38 | - $terms = get_terms( |
|
| 38 | + $terms = get_terms( |
|
| 39 | 39 | array( |
| 40 | 40 | 'taxonomy' => 'wprm_ingredient', |
| 41 | 41 | 'fields' => 'all', |
| 42 | 42 | 'hide_empty' => false, |
| 43 | 43 | ) |
| 44 | 44 | ); |
| 45 | - $filtered_terms = $this->terms_without_about_jsonld( $terms ); |
|
| 46 | - $filtered_terms_names = array_map( array( $this, 'term_name' ), $filtered_terms ); |
|
| 47 | - $ingredients = $this->ingredients_client->ingredients( $filtered_terms_names ); |
|
| 45 | + $filtered_terms = $this->terms_without_about_jsonld($terms); |
|
| 46 | + $filtered_terms_names = array_map(array($this, 'term_name'), $filtered_terms); |
|
| 47 | + $ingredients = $this->ingredients_client->ingredients($filtered_terms_names); |
|
| 48 | 48 | |
| 49 | - foreach ( $ingredients as $key => $value ) { |
|
| 50 | - $term = get_term_by( 'name', $key, 'wprm_ingredient' ); |
|
| 51 | - if ( ! isset( $term ) ) { |
|
| 49 | + foreach ($ingredients as $key => $value) { |
|
| 50 | + $term = get_term_by('name', $key, 'wprm_ingredient'); |
|
| 51 | + if ( ! isset($term)) { |
|
| 52 | 52 | continue; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $this->content_service->set_about_jsonld( |
| 56 | - Wordpress_Content_Id::create_term( $term->term_id ), |
|
| 56 | + Wordpress_Content_Id::create_term($term->term_id), |
|
| 57 | 57 | $value |
| 58 | 58 | ); |
| 59 | 59 | |
@@ -63,16 +63,16 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // Clean up caches. |
| 66 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 66 | + do_action('wl_ttl_cache_cleaner__flush'); |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @@todo add notification that procedure is complete, with information about the number of processed items vs |
| 70 | 70 | * total items |
| 71 | 71 | */ |
| 72 | - $count_terms = count( $filtered_terms ); |
|
| 73 | - $count_lifted_terms = count( $ingredients ); |
|
| 72 | + $count_terms = count($filtered_terms); |
|
| 73 | + $count_lifted_terms = count($ingredients); |
|
| 74 | 74 | /* translators: 1: The number of lifted ingredients, 2: The total number of ingredients. */ |
| 75 | - $this->notices->queue( 'info', sprintf( __( 'WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift' ), $count_lifted_terms, $count_terms ) ); |
|
| 75 | + $this->notices->queue('info', sprintf(__('WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift'), $count_lifted_terms, $count_terms)); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return WP_Term[] |
| 82 | 82 | */ |
| 83 | - private function terms_without_about_jsonld( $terms ) { |
|
| 84 | - return array_filter( $terms, array( $this, 'term_has_not_about_jsonld' ) ); |
|
| 83 | + private function terms_without_about_jsonld($terms) { |
|
| 84 | + return array_filter($terms, array($this, 'term_has_not_about_jsonld')); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return bool true if the term has an about_jsonld otherwise false. |
| 91 | 91 | */ |
| 92 | - private function term_has_not_about_jsonld( $term ) { |
|
| 92 | + private function term_has_not_about_jsonld($term) { |
|
| 93 | 93 | $about_jsonld = $this->content_service->get_about_jsonld( |
| 94 | - Wordpress_Content_Id::create_term( $term->term_id ) |
|
| 94 | + Wordpress_Content_Id::create_term($term->term_id) |
|
| 95 | 95 | ); |
| 96 | 96 | |
| 97 | 97 | return $about_jsonld === null; |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @return string |
| 104 | 104 | */ |
| 105 | - public function term_name( $term ) { |
|
| 105 | + public function term_name($term) { |
|
| 106 | 106 | return $term->name; |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -10,82 +10,82 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Food_Kg_Term_Entity_Runner implements Runner { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var Food_Kg_Ingredients_Term_Store |
|
| 15 | - */ |
|
| 16 | - private $store; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @var Content_Service |
|
| 20 | - */ |
|
| 21 | - private $content_service; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var Ingredients_Client |
|
| 25 | - */ |
|
| 26 | - private $ingredients_client; |
|
| 27 | - |
|
| 28 | - public function __construct( Food_Kg_Ingredients_Term_Store $store, Content_Service $content_service, Ingredients_Client $ingredients_client ) { |
|
| 29 | - $this->store = $store; |
|
| 30 | - $this->content_service = $content_service; |
|
| 31 | - $this->ingredients_client = $ingredients_client; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 35 | - public function run( $last_id ) { |
|
| 36 | - |
|
| 37 | - $items = $this->store->list_items( $last_id, 100 ); |
|
| 38 | - $names = array_column( |
|
| 39 | - array_map( |
|
| 40 | - function ( $item ) { |
|
| 41 | - return (array) $item; |
|
| 42 | - }, |
|
| 43 | - $items |
|
| 44 | - ), |
|
| 45 | - 'name' |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - $ingredients = $this->ingredients_client->ingredients( $names ); |
|
| 49 | - |
|
| 50 | - foreach ( $ingredients as $key => $value ) { |
|
| 51 | - $term = get_term_by( 'name', $key, 'wprm_ingredient' ); |
|
| 52 | - if ( ! isset( $term ) || $this->term_has_about_jsonld( $term ) ) { |
|
| 53 | - continue; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $content_id = Wordpress_Content_Id::create_term( $term->term_id ); |
|
| 57 | - $this->content_service->set_about_jsonld( $content_id, $value ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $count = count( $items ); |
|
| 61 | - $last_item = end( $items ); |
|
| 62 | - $last_item_id = ( isset( $last_item->term_id ) ? $last_item->term_id : null ); |
|
| 63 | - |
|
| 64 | - return array( $count, $last_item_id ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Get the total number of posts to process. |
|
| 69 | - * |
|
| 70 | - * We only count published posts. |
|
| 71 | - * |
|
| 72 | - * @return int |
|
| 73 | - */ |
|
| 74 | - public function get_total() { |
|
| 75 | - return $this->store->get_total(); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param $term WP_Term |
|
| 80 | - * |
|
| 81 | - * @return bool true if the term has an about_jsonld otherwise false. |
|
| 82 | - */ |
|
| 83 | - private function term_has_about_jsonld( $term ) { |
|
| 84 | - $about_jsonld = $this->content_service->get_about_jsonld( |
|
| 85 | - Wordpress_Content_Id::create_term( $term->term_id ) |
|
| 86 | - ); |
|
| 87 | - |
|
| 88 | - return $about_jsonld !== null; |
|
| 89 | - } |
|
| 13 | + /** |
|
| 14 | + * @var Food_Kg_Ingredients_Term_Store |
|
| 15 | + */ |
|
| 16 | + private $store; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @var Content_Service |
|
| 20 | + */ |
|
| 21 | + private $content_service; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var Ingredients_Client |
|
| 25 | + */ |
|
| 26 | + private $ingredients_client; |
|
| 27 | + |
|
| 28 | + public function __construct( Food_Kg_Ingredients_Term_Store $store, Content_Service $content_service, Ingredients_Client $ingredients_client ) { |
|
| 29 | + $this->store = $store; |
|
| 30 | + $this->content_service = $content_service; |
|
| 31 | + $this->ingredients_client = $ingredients_client; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 35 | + public function run( $last_id ) { |
|
| 36 | + |
|
| 37 | + $items = $this->store->list_items( $last_id, 100 ); |
|
| 38 | + $names = array_column( |
|
| 39 | + array_map( |
|
| 40 | + function ( $item ) { |
|
| 41 | + return (array) $item; |
|
| 42 | + }, |
|
| 43 | + $items |
|
| 44 | + ), |
|
| 45 | + 'name' |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + $ingredients = $this->ingredients_client->ingredients( $names ); |
|
| 49 | + |
|
| 50 | + foreach ( $ingredients as $key => $value ) { |
|
| 51 | + $term = get_term_by( 'name', $key, 'wprm_ingredient' ); |
|
| 52 | + if ( ! isset( $term ) || $this->term_has_about_jsonld( $term ) ) { |
|
| 53 | + continue; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $content_id = Wordpress_Content_Id::create_term( $term->term_id ); |
|
| 57 | + $this->content_service->set_about_jsonld( $content_id, $value ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $count = count( $items ); |
|
| 61 | + $last_item = end( $items ); |
|
| 62 | + $last_item_id = ( isset( $last_item->term_id ) ? $last_item->term_id : null ); |
|
| 63 | + |
|
| 64 | + return array( $count, $last_item_id ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Get the total number of posts to process. |
|
| 69 | + * |
|
| 70 | + * We only count published posts. |
|
| 71 | + * |
|
| 72 | + * @return int |
|
| 73 | + */ |
|
| 74 | + public function get_total() { |
|
| 75 | + return $this->store->get_total(); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param $term WP_Term |
|
| 80 | + * |
|
| 81 | + * @return bool true if the term has an about_jsonld otherwise false. |
|
| 82 | + */ |
|
| 83 | + private function term_has_about_jsonld( $term ) { |
|
| 84 | + $about_jsonld = $this->content_service->get_about_jsonld( |
|
| 85 | + Wordpress_Content_Id::create_term( $term->term_id ) |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + return $about_jsonld !== null; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |
@@ -25,19 +25,19 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | private $ingredients_client; |
| 27 | 27 | |
| 28 | - public function __construct( Food_Kg_Ingredients_Term_Store $store, Content_Service $content_service, Ingredients_Client $ingredients_client ) { |
|
| 28 | + public function __construct(Food_Kg_Ingredients_Term_Store $store, Content_Service $content_service, Ingredients_Client $ingredients_client) { |
|
| 29 | 29 | $this->store = $store; |
| 30 | 30 | $this->content_service = $content_service; |
| 31 | 31 | $this->ingredients_client = $ingredients_client; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 35 | - public function run( $last_id ) { |
|
| 35 | + public function run($last_id) { |
|
| 36 | 36 | |
| 37 | - $items = $this->store->list_items( $last_id, 100 ); |
|
| 37 | + $items = $this->store->list_items($last_id, 100); |
|
| 38 | 38 | $names = array_column( |
| 39 | 39 | array_map( |
| 40 | - function ( $item ) { |
|
| 40 | + function($item) { |
|
| 41 | 41 | return (array) $item; |
| 42 | 42 | }, |
| 43 | 43 | $items |
@@ -45,23 +45,23 @@ discard block |
||
| 45 | 45 | 'name' |
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | - $ingredients = $this->ingredients_client->ingredients( $names ); |
|
| 48 | + $ingredients = $this->ingredients_client->ingredients($names); |
|
| 49 | 49 | |
| 50 | - foreach ( $ingredients as $key => $value ) { |
|
| 51 | - $term = get_term_by( 'name', $key, 'wprm_ingredient' ); |
|
| 52 | - if ( ! isset( $term ) || $this->term_has_about_jsonld( $term ) ) { |
|
| 50 | + foreach ($ingredients as $key => $value) { |
|
| 51 | + $term = get_term_by('name', $key, 'wprm_ingredient'); |
|
| 52 | + if ( ! isset($term) || $this->term_has_about_jsonld($term)) { |
|
| 53 | 53 | continue; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $content_id = Wordpress_Content_Id::create_term( $term->term_id ); |
|
| 57 | - $this->content_service->set_about_jsonld( $content_id, $value ); |
|
| 56 | + $content_id = Wordpress_Content_Id::create_term($term->term_id); |
|
| 57 | + $this->content_service->set_about_jsonld($content_id, $value); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $count = count( $items ); |
|
| 61 | - $last_item = end( $items ); |
|
| 62 | - $last_item_id = ( isset( $last_item->term_id ) ? $last_item->term_id : null ); |
|
| 60 | + $count = count($items); |
|
| 61 | + $last_item = end($items); |
|
| 62 | + $last_item_id = (isset($last_item->term_id) ? $last_item->term_id : null); |
|
| 63 | 63 | |
| 64 | - return array( $count, $last_item_id ); |
|
| 64 | + return array($count, $last_item_id); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return bool true if the term has an about_jsonld otherwise false. |
| 82 | 82 | */ |
| 83 | - private function term_has_about_jsonld( $term ) { |
|
| 83 | + private function term_has_about_jsonld($term) { |
|
| 84 | 84 | $about_jsonld = $this->content_service->get_about_jsonld( |
| 85 | - Wordpress_Content_Id::create_term( $term->term_id ) |
|
| 85 | + Wordpress_Content_Id::create_term($term->term_id) |
|
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | 88 | return $about_jsonld !== null; |