Skip to content

Commit

Permalink
add id audit for product categories and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed May 12, 2023
1 parent b1f8b0d commit e10b552
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
29 changes: 29 additions & 0 deletions includes/API/Product_Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,33 @@ public function product_categories_response( WP_REST_Response $response, object

return $response;
}

/**
* Returns array of all product category ids
*
* @param array $fields
*
* @return array
*/
public function get_all_posts( array $fields = array() ): array {
$args = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'fields' => 'ids',
);

$product_category_ids = get_terms( $args );

// Convert the array of cat IDs to an array of objects with cat IDs as integers
return array_map( array( $this, 'format_id' ), $product_category_ids );
}

/**
* @param string $product_category_id
*
* @return object
*/
private function format_id( string $product_category_id ): object {
return (object) array( 'id' => (int) $product_category_id );
}
}
29 changes: 29 additions & 0 deletions includes/API/Product_Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,33 @@ public function product_tags_response( WP_REST_Response $response, object $item,

return $response;
}

/**
* Returns array of all product tag ids
*
* @param array $fields
*
* @return array
*/
public function get_all_posts( array $fields = array() ): array {
$args = array(
'taxonomy' => 'product_tag',
'hide_empty' => false,
'fields' => 'ids',
);

$product_tag_ids = get_terms( $args );

// Convert the array of tag IDs to an array of objects with tag IDs as integers
return array_map( array( $this, 'format_id' ), $product_tag_ids );
}

/**
* @param string $product_tag_id
*
* @return object
*/
private function format_id( string $product_tag_id ): object {
return (object) array( 'id' => (int) $product_tag_id );
}
}
8 changes: 5 additions & 3 deletions includes/Gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct() {
* BEWARE: some gateways/themes/plugins call this very early on every page!!
* We cannot guarantee that $wp is set, so we cannot use woocommerce_pos_request.
*
* @param $gateways
* @param array | null $gateways
*
* @return array
*/
Expand All @@ -49,11 +49,13 @@ public function payment_gateways( array $gateways ) {
* - Order and set default order
* - Also going to remove icons from the gateways
*
* @param array $gateways
* - BUG: a user with WooCommerce Blocks is getting null for $gateways?
*
* @param array | null $gateways
*
* @return array
*/
public function available_payment_gateways( array $gateways ): array {
public function available_payment_gateways( ?array $gateways ): array {
// early exit
if ( ! woocommerce_pos_request() ) {
return $gateways;
Expand Down

0 comments on commit e10b552

Please sign in to comment.