allcaps['read_product'])) { wp_die(); } $post = Request::getData(); $data = array(); $result = array(); if (isset($post['lines'])) { $data['lines'] = uslp_a4bRecursiveSanitizeTextField($post['lines']); } if (isset($post['raw'])) { $data['raw'] = sanitize_textarea_field($post['raw']); } $data['fieldSource'] = isset($post['fieldSource']) ? sanitize_text_field($post['fieldSource']) : 'posts'; $validationRules = array('lines' => 'array', 'raw' => 'complexCodeValue', 'fieldSource' => 'string'); $data = Validator::create($data, $validationRules, true)->validate(); update_user_meta(get_current_user_id(), 'uslp_bulk_list_raw', $data['raw']); $postsUtils = new PostsUtils(); foreach ($data['lines'] as &$postField) { unset($postField['success']); $result[] = $postsUtils->getPostIdByField($postField, $data['fieldSource']); } uslp_a4bJsonResponse($result); } public function getProductVariations() { Request::checkNonce(); if (empty(wp_get_current_user()->allcaps['read_product'])) { wp_die(); } $post = Request::getData(); $data = array(); $result = array("variations" => array()); try { if (isset($post['productId'])) { $data['productId'] = sanitize_text_field($post['productId']); } $validator = Validator::create($data, array('productId' => 'numeric|required')); $data = $validator->validate(); if (!current_user_can('read_product', $data['productId'])) { wp_die(); } if (empty($data) || !is_admin() || !current_user_can('read_product', $data['productId'])) { uslp_a4bJsonResponse($result); } $product = \wc_get_product($data['productId']); $children = $product->get_children(); foreach ($children as $variationId) { $variation = get_post($variationId); if ($variation->post_type == "product_variation") { $result["variations"][] = array( "id" => $variationId, "name" => $variation->post_excerpt, ); } } } catch (\Throwable $th) { } uslp_a4bJsonResponse($result); } }