PATH:
home
/
lab2454c
/
adenbic.com
/
wp-content
/
plugins
/
woocommerce
/
includes
/
rest-api
/
Controllers
/
Version3
<?php /** * REST API Product Attributes controller * * Handles requests to the products/attributes endpoint. * * @package WooCommerce\RestApi * @since 2.6.0 */ defined( 'ABSPATH' ) || exit; /** * REST API Product Attributes controller class. * * @package WooCommerce\RestApi * @extends WC_REST_Product_Attributes_V2_Controller */ class WC_REST_Product_Attributes_Controller extends WC_REST_Product_Attributes_V2_Controller { /** * Endpoint namespace. * * @var string */ protected $namespace = 'wc/v3'; /** * Generates a unique slug for a given attribute name. We do this so that we can * create more than one attribute with the same name. * * @param string $attribute_name The attribute name to generate a slug for. * @return string The auto-generated slug */ private function generate_unique_slug( $attribute_name ) { global $wpdb; $root_slug = wc_sanitize_taxonomy_name( $attribute_name ); $results = $wpdb->get_results( $wpdb->prepare( "SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name LIKE %s ORDER BY attribute_id DESC LIMIT 1", $root_slug . '%' ) ); // The slug is already unique! if ( empty( $results ) ) { return $root_slug; } $last_created_slug = $results[0]->attribute_name; $suffix = intval( substr( $last_created_slug, strrpos( $last_created_slug, '-' ) + 1 ) ); return $root_slug . '-' . ( $suffix + 1 ); } /** * Create a single attribute. * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Request|WP_Error */ public function create_item( $request ) { global $wpdb; $generate_slug = stripslashes( $request['generate_slug'] ); $slug = wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ); if ( ! empty( $generate_slug ) && 'true' === $generate_slug ) { $slug = $this->generate_unique_slug( $request['name'] ); } $id = wc_create_attribute( array( 'name' => $request['name'], 'slug' => $slug, 'type' => ! empty( $request['type'] ) ? $request['type'] : 'select', 'order_by' => ! empty( $request['order_by'] ) ? $request['order_by'] : 'menu_order', 'has_archives' => true === $request['has_archives'], ) ); // Checks for errors. if ( is_wp_error( $id ) ) { return new WP_Error( 'woocommerce_rest_cannot_create', $id->get_error_message(), array( 'status' => 400 ) ); } $attribute = $this->get_attribute( $id ); if ( is_wp_error( $attribute ) ) { return $attribute; } $this->update_additional_fields_for_object( $attribute, $request ); /** * Fires after a single product attribute is created or updated via the REST API. * * @param stdObject $attribute Inserted attribute object. * @param WP_REST_Request $request Request object. * @param boolean $creating True when creating attribute, false when updating. */ do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, true ); $request->set_param( 'context', 'edit' ); $response = $this->prepare_item_for_response( $attribute, $request ); $response = rest_ensure_response( $response ); $response->set_status( 201 ); $response->header( 'Location', rest_url( '/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id ) ); return $response; } }
[-] class-wc-rest-customer-downloads-controller.php
[edit]
[-] class-wc-rest-report-coupons-totals-controller.php
[edit]
[-] class-wc-rest-report-sales-controller.php
[edit]
[-] class-wc-rest-setting-options-controller.php
[edit]
[-] class-wc-rest-terms-controller.php
[edit]
[-] class-wc-rest-product-variations-controller.php
[edit]
[-] class-wc-rest-settings-controller.php
[edit]
[-] class-wc-rest-order-refunds-controller.php
[edit]
[-] class-wc-rest-crud-controller.php
[edit]
[-] class-wc-rest-data-countries-controller.php
[edit]
[+]
..
[-] class-wc-rest-shipping-methods-controller.php
[edit]
[-] class-wc-rest-controller.php
[edit]
[-] class-wc-rest-product-attribute-terms-controller.php
[edit]
[-] class-wc-rest-customers-controller.php
[edit]
[-] class-wc-rest-report-orders-totals-controller.php
[edit]
[-] class-wc-rest-network-orders-controller.php
[edit]
[-] class-wc-rest-data-controller.php
[edit]
[-] class-wc-rest-webhooks-controller.php
[edit]
[-] class-wc-rest-tax-classes-controller.php
[edit]
[-] class-wc-rest-report-products-totals-controller.php
[edit]
[-] class-wc-rest-product-shipping-classes-controller.php
[edit]
[-] class-wc-rest-orders-controller.php
[edit]
[-] class-wc-rest-report-customers-totals-controller.php
[edit]
[-] class-wc-rest-system-status-tools-controller.php
[edit]
[-] class-wc-rest-order-notes-controller.php
[edit]
[-] class-wc-rest-product-attributes-controller.php
[edit]
[-] class-wc-rest-coupons-controller.php
[edit]
[-] class-wc-rest-data-continents-controller.php
[edit]
[-] class-wc-rest-products-controller.php
[edit]
[-] class-wc-rest-shipping-zones-controller.php
[edit]
[-] class-wc-rest-report-top-sellers-controller.php
[edit]
[-] class-wc-rest-report-reviews-totals-controller.php
[edit]
[-] class-wc-rest-payment-gateways-controller.php
[edit]
[-] class-wc-rest-system-status-controller.php
[edit]
[-] class-wc-rest-shipping-zones-controller-base.php
[edit]
[-] class-wc-rest-posts-controller.php
[edit]
[-] class-wc-rest-product-tags-controller.php
[edit]
[-] class-wc-rest-shipping-zone-methods-controller.php
[edit]
[-] class-wc-rest-product-reviews-controller.php
[edit]
[-] class-wc-rest-shipping-zone-locations-controller.php
[edit]
[-] class-wc-rest-reports-controller.php
[edit]
[-] class-wc-rest-data-currencies-controller.php
[edit]
[-] class-wc-rest-taxes-controller.php
[edit]
[-] class-wc-rest-product-categories-controller.php
[edit]