WC_REST_Product_Shipping_Classes_Controller::suggest_slug
Callback function for the slug-suggestion endpoint.
Method of the class: WC_REST_Product_Shipping_Classes_Controller{}
No Hooks.
Returns
String. The suggested slug.
Usage
$WC_REST_Product_Shipping_Classes_Controller = new WC_REST_Product_Shipping_Classes_Controller(); $WC_REST_Product_Shipping_Classes_Controller->suggest_slug( $request );
- $request(WP_REST_Request) (required)
- Full details about the request.
WC_REST_Product_Shipping_Classes_Controller::suggest_slug() WC REST Product Shipping Classes Controller::suggest slug code WC 10.6.2
public function suggest_slug( $request ) {
$name = $request['name'];
$slug = sanitize_title( $name ); // potential slug.
$term = get_term_by( 'slug', $slug, $this->taxonomy );
/*
* If the term exists, creates a unique slug
* based on the name provided.
* Otherwise, returns the sanitized name.
*/
if ( isset( $term->slug ) ) {
/*
* Pass a Term object that has only the taxonomy property,
* to induce the wp_unique_term_slug() function to generate a unique slug.
* Otherwise, the function will return the same slug.
* @see https://core.trac.wordpress.org/browser/tags/6.5/src/wp-includes/taxonomy.php#L3130
* @see https://github.com/WordPress/wordpress-develop/blob/a1b1e0339eb6dfa72a30933cac2a1c6ad2bbfe96/src/wp-includes/taxonomy.php#L3078-L3156
*/
$slug = wp_unique_term_slug( $slug, (object) array( 'taxonomy' => $this->taxonomy ) );
}
return rest_ensure_response( $slug );
}