Version Description
(2022-12-07) = * Fixed: Facebook and google template UTF-8 encode error
Download this release
Release Info
Developer | wahid0003 |
Plugin | CTX Feed – WooCommerce Product Feed Manager Plugin |
Version | 4.5.13 |
Comparing to | |
See all releases |
Code changes from version 4.5.12 to 4.5.13
- README.txt +4 -1
- V5/API/RestController.php +52 -46
- V5/API/RestFactory.php +0 -14
- V5/API/V1/AttributesMapping.php +0 -269
- V5/API/V1/CategoryMapping.php +0 -269
- V5/API/V1/{DropDown.php → DropDownOptionsApi.php} +4 -4
- V5/API/V1/DynamicAttributes.php +0 -262
- V5/API/V1/FeedLists.php +3 -41
- V5/API/V1/MerchantConfig.php +12 -7
- V5/API/V1/ProductCategories.php +2 -2
- V5/API/V1/ProductTaxonomy.php +5 -3
- V5/API/V1/ProductTitles.php +2 -1
- V5/API/V1/Settings.php +0 -194
- V5/API/V1/WPOptions.php +0 -199
- includes/classes/class-woo-feed-constants.php +1 -1
- includes/helper.php +5 -1
- woo-feed.php +1 -1
README.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: WooCommerce Product Feed, WooCommerce, Google Shopping, Google Merchant, F
|
|
5 |
Requires at least: 4.4
|
6 |
Tested Up To: 6.1
|
7 |
Requires PHP: 5.6
|
8 |
-
Stable tag: 4.5.
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -590,6 +590,9 @@ Using pro version:
|
|
590 |
|
591 |
== Changelog ==
|
592 |
|
|
|
|
|
|
|
593 |
= 4.5.12 (2022-12-06) =
|
594 |
* Added: Black Friday Notice Banner Remove
|
595 |
* Fixed: Yandex xml format feed generation stuck
|
5 |
Requires at least: 4.4
|
6 |
Tested Up To: 6.1
|
7 |
Requires PHP: 5.6
|
8 |
+
Stable tag: 4.5.13
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
590 |
|
591 |
== Changelog ==
|
592 |
|
593 |
+
= 4.5.13 (2022-12-07) =
|
594 |
+
* Fixed: Facebook and google template UTF-8 encode error
|
595 |
+
|
596 |
= 4.5.12 (2022-12-06) =
|
597 |
* Added: Black Friday Notice Banner Remove
|
598 |
* Fixed: Yandex xml format feed generation stuck
|
V5/API/RestController.php
CHANGED
@@ -2,6 +2,14 @@
|
|
2 |
|
3 |
namespace CTXFeed\V5\API;
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
use \WP_REST_Controller;
|
6 |
use \WP_Error;
|
7 |
|
@@ -26,11 +34,14 @@ class RestController extends WP_REST_Controller {
|
|
26 |
/**
|
27 |
* @var $version ;
|
28 |
*/
|
29 |
-
|
30 |
|
31 |
protected function __construct() {
|
|
|
32 |
$this->namespace = 'ctxfeed/' . $this->version;
|
|
|
33 |
add_action( 'rest_api_init', [ $this, 'register_api' ] );
|
|
|
34 |
add_action( 'rest_api_init', function ( $var ) {
|
35 |
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
|
36 |
}, 15, 1 );
|
@@ -38,6 +49,21 @@ class RestController extends WP_REST_Controller {
|
|
38 |
}
|
39 |
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
/**
|
42 |
* Main RestController Instance.
|
43 |
*
|
@@ -53,6 +79,20 @@ class RestController extends WP_REST_Controller {
|
|
53 |
return self::$_instance;
|
54 |
}
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
/**
|
57 |
* Get single item permission to perform current action.
|
58 |
*
|
@@ -65,35 +105,24 @@ class RestController extends WP_REST_Controller {
|
|
65 |
return true;
|
66 |
}
|
67 |
|
68 |
-
return
|
69 |
-
}
|
70 |
-
|
71 |
-
|
72 |
-
public function register_api() {
|
73 |
-
$uri = trim( $_SERVER['REQUEST_URI'], '/' );
|
74 |
-
$uri = explode( '/', $uri );
|
75 |
-
$namespace = explode( '/', $this->namespace );
|
76 |
-
if ( $namespace[0] === $uri[2] ) {
|
77 |
-
self::load_class( $uri[4] )->register_routes();
|
78 |
-
}
|
79 |
}
|
80 |
|
81 |
-
|
82 |
/**
|
83 |
-
*
|
|
|
|
|
|
|
|
|
84 |
*/
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
88 |
|
89 |
-
|
90 |
-
* Unserializing instances of this class is forbidden.
|
91 |
-
*/
|
92 |
-
final public function __wakeup() {
|
93 |
-
_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'woo-feed' ), WOO_FEED_FREE_VERSION );
|
94 |
}
|
95 |
|
96 |
-
|
97 |
/**
|
98 |
* @param $data
|
99 |
*
|
@@ -209,28 +238,5 @@ class RestController extends WP_REST_Controller {
|
|
209 |
return $response;
|
210 |
}
|
211 |
|
212 |
-
/**
|
213 |
-
* @param $array
|
214 |
-
*
|
215 |
-
* @return bool
|
216 |
-
*/
|
217 |
-
protected function is_assoc( $array ) {
|
218 |
-
if ( array() === $array ) {
|
219 |
-
return false;
|
220 |
-
}
|
221 |
-
|
222 |
-
return ( $array !== array_values( $array ) );
|
223 |
-
}
|
224 |
-
|
225 |
-
public function is_prefix_matched( $string, $prefix ) {
|
226 |
-
return str_starts_with( $string, $prefix );
|
227 |
-
}
|
228 |
|
229 |
-
|
230 |
-
private static function load_class( $class = null ) {
|
231 |
-
$api_class = array_map( 'ucfirst', explode( '_', $class ) );
|
232 |
-
$api_class = implode( '', $api_class );
|
233 |
-
|
234 |
-
return RestFactory::load( $api_class );
|
235 |
-
}
|
236 |
}
|
2 |
|
3 |
namespace CTXFeed\V5\API;
|
4 |
|
5 |
+
|
6 |
+
use CTXFeed\V5\API\V1\DropDownOptionsApi;
|
7 |
+
use CTXFeed\V5\API\V1\FeedLists;
|
8 |
+
use CTXFeed\V5\API\V1\MerchantConfig;
|
9 |
+
use CTXFeed\V5\API\V1\MerchantInfo;
|
10 |
+
use CTXFeed\V5\API\V1\ProductCategories;
|
11 |
+
use CTXFeed\V5\API\V1\ProductTaxonomy;
|
12 |
+
use CTXFeed\V5\API\V1\ProductTitles;
|
13 |
use \WP_REST_Controller;
|
14 |
use \WP_Error;
|
15 |
|
34 |
/**
|
35 |
* @var $version ;
|
36 |
*/
|
37 |
+
public $version = 'v1';
|
38 |
|
39 |
protected function __construct() {
|
40 |
+
|
41 |
$this->namespace = 'ctxfeed/' . $this->version;
|
42 |
+
|
43 |
add_action( 'rest_api_init', [ $this, 'register_api' ] );
|
44 |
+
//Remove CORS headers for REST API that allow arbitrary origins
|
45 |
add_action( 'rest_api_init', function ( $var ) {
|
46 |
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
|
47 |
}, 15, 1 );
|
49 |
}
|
50 |
|
51 |
|
52 |
+
public function register_api() {
|
53 |
+
$classes = [
|
54 |
+
DropDownOptionsApi::instance(),
|
55 |
+
ProductTaxonomy::instance(),
|
56 |
+
ProductTitles::instance(),
|
57 |
+
ProductCategories::instance(),
|
58 |
+
MerchantInfo::instance(),
|
59 |
+
MerchantConfig::instance(),
|
60 |
+
FeedLists::instance(),
|
61 |
+
];
|
62 |
+
foreach ( $classes as $class ) {
|
63 |
+
$class->register_routes();
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
/**
|
68 |
* Main RestController Instance.
|
69 |
*
|
79 |
return self::$_instance;
|
80 |
}
|
81 |
|
82 |
+
/**
|
83 |
+
* Cloning is forbidden.
|
84 |
+
*/
|
85 |
+
final public function __clone() {
|
86 |
+
_doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'woo-feed' ), WOO_FEED_FREE_VERSION );
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Unserializing instances of this class is forbidden.
|
91 |
+
*/
|
92 |
+
final public function __wakeup() {
|
93 |
+
_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'woo-feed' ), WOO_FEED_FREE_VERSION );
|
94 |
+
}
|
95 |
+
|
96 |
/**
|
97 |
* Get single item permission to perform current action.
|
98 |
*
|
105 |
return true;
|
106 |
}
|
107 |
|
108 |
+
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
|
|
|
111 |
/**
|
112 |
+
* Get items permission to perform current action.
|
113 |
+
*
|
114 |
+
* @param $request
|
115 |
+
*
|
116 |
+
* @return bool
|
117 |
*/
|
118 |
+
public function get_items_permissions_check( $request ) {
|
119 |
+
if ( current_user_can( 'manage_options' ) ) {
|
120 |
+
return true;
|
121 |
+
}
|
122 |
|
123 |
+
return false;
|
|
|
|
|
|
|
|
|
124 |
}
|
125 |
|
|
|
126 |
/**
|
127 |
* @param $data
|
128 |
*
|
238 |
return $response;
|
239 |
}
|
240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
}
|
V5/API/RestFactory.php
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace CTXFeed\V5\API;
|
4 |
-
|
5 |
-
class RestFactory {
|
6 |
-
public static function load( $class ) {
|
7 |
-
$class = "\CTXFeed\V5\API\V1\\" . $class;
|
8 |
-
if ( class_exists( $class ) ) {
|
9 |
-
return $class::instance();
|
10 |
-
}else{
|
11 |
-
return null;
|
12 |
-
}
|
13 |
-
}
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
V5/API/V1/AttributesMapping.php
DELETED
@@ -1,269 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace CTXFeed\V5\API\V1;
|
4 |
-
|
5 |
-
use CTXFeed\V5\API\RestController;
|
6 |
-
use \WP_REST_Server;
|
7 |
-
|
8 |
-
class AttributesMapping extends RestController {
|
9 |
-
/**
|
10 |
-
* @var array
|
11 |
-
*/
|
12 |
-
private static $attr_lists = [];
|
13 |
-
/**
|
14 |
-
* @var string
|
15 |
-
*/
|
16 |
-
private static $prefix = 'wp_attr_mapping_';
|
17 |
-
/**
|
18 |
-
* The single instance of the class
|
19 |
-
*
|
20 |
-
* @var AttributesMapping
|
21 |
-
*
|
22 |
-
*/
|
23 |
-
protected static $_instance = null;
|
24 |
-
|
25 |
-
private function __construct() {
|
26 |
-
parent::__construct();
|
27 |
-
$this->rest_base = 'attributes_mapping';
|
28 |
-
}
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Main AttributesMapping Instance.
|
32 |
-
*
|
33 |
-
* Ensures only one instance of AttributesMapping is loaded or can be loaded.
|
34 |
-
*
|
35 |
-
* @return AttributesMapping Main instance
|
36 |
-
*/
|
37 |
-
public static function instance() {
|
38 |
-
if ( is_null( self::$_instance ) ) {
|
39 |
-
self::$_instance = new self();
|
40 |
-
}
|
41 |
-
|
42 |
-
return self::$_instance;
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Register routes.
|
47 |
-
* @return void
|
48 |
-
*/
|
49 |
-
public function register_routes() {
|
50 |
-
register_rest_route(
|
51 |
-
$this->namespace,
|
52 |
-
'/' . $this->rest_base,
|
53 |
-
[
|
54 |
-
/**
|
55 |
-
* @endpoint: wp-json/ctxfeed/v1/attributes_mapping
|
56 |
-
* @description Will get all feed lists
|
57 |
-
*
|
58 |
-
*
|
59 |
-
* @endpoint wp-json/ctxfeed/v1/attributes_mapping/?page=1&per_page=2
|
60 |
-
* @descripton Get paginated value with previous page and next page link
|
61 |
-
*
|
62 |
-
* @endpoint wp-json/ctxfeed/v1/attributes_mapping/?name=wf_feed_google_shopping
|
63 |
-
* @method GET
|
64 |
-
* @descripton Get single attribute
|
65 |
-
*
|
66 |
-
* @param $name String
|
67 |
-
*
|
68 |
-
* @param $page Number
|
69 |
-
* @param $per_page Number
|
70 |
-
*/
|
71 |
-
[
|
72 |
-
'methods' => WP_REST_Server::READABLE,
|
73 |
-
'callback' => [ $this, 'get_items' ],
|
74 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
75 |
-
'args' => [
|
76 |
-
'name' => [
|
77 |
-
'description' => __( 'feed name', 'woo-feed' ),
|
78 |
-
'type' => 'string',
|
79 |
-
'required' => false,
|
80 |
-
'sanitize_callback' => 'sanitize_text_field',
|
81 |
-
'validate_callback' => 'rest_validate_request_arg',
|
82 |
-
],
|
83 |
-
'page' => [
|
84 |
-
'description' => __( 'Page number', 'woo-feed' ),
|
85 |
-
'type' => 'number',
|
86 |
-
'required' => false,
|
87 |
-
'sanitize_callback' => 'absint',
|
88 |
-
'validate_callback' => 'rest_validate_request_arg',
|
89 |
-
],
|
90 |
-
'per_page' => [
|
91 |
-
'description' => __( 'Per page', 'woo-feed' ),
|
92 |
-
'type' => 'number',
|
93 |
-
'required' => false,
|
94 |
-
'sanitize_callback' => 'absint',
|
95 |
-
'validate_callback' => 'rest_validate_request_arg',
|
96 |
-
],
|
97 |
-
],
|
98 |
-
],
|
99 |
-
[
|
100 |
-
'methods' => WP_REST_Server::CREATABLE,
|
101 |
-
'callback' => [ $this, 'create_item' ],
|
102 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
103 |
-
'args' => [],
|
104 |
-
],
|
105 |
-
[
|
106 |
-
'methods' => WP_REST_Server::EDITABLE,
|
107 |
-
'callback' => [ $this, 'update_item' ],
|
108 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
109 |
-
'args' => [],
|
110 |
-
],
|
111 |
-
/**
|
112 |
-
* @endpoint wp-json/ctxfeed/v1/attributes_mapping/?name=wf_feed_google_shopping
|
113 |
-
* @method DELETE
|
114 |
-
* @descripton Delete single attribute
|
115 |
-
*
|
116 |
-
* @param $name String
|
117 |
-
*/
|
118 |
-
[
|
119 |
-
'methods' => WP_REST_Server::DELETABLE,
|
120 |
-
'callback' => [ $this, 'delete_item' ],
|
121 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
122 |
-
'args' => [
|
123 |
-
'name' => [
|
124 |
-
'description' => __( 'feed name', 'woo-feed' ),
|
125 |
-
'type' => 'string',
|
126 |
-
'required' => true,
|
127 |
-
'sanitize_callback' => 'sanitize_text_field',
|
128 |
-
'validate_callback' => 'rest_validate_request_arg',
|
129 |
-
],
|
130 |
-
],
|
131 |
-
],
|
132 |
-
|
133 |
-
]
|
134 |
-
);
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* @param $request
|
139 |
-
*
|
140 |
-
* @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
|
141 |
-
*/
|
142 |
-
public function update_item( $request ) {
|
143 |
-
$body = $request->get_body();
|
144 |
-
$body = (array) json_decode( $body );
|
145 |
-
|
146 |
-
if ( ! $this->is_assoc( $body ) ) {
|
147 |
-
return $this->error( __( 'Option name is missing!', 'woo-feed' ) );
|
148 |
-
}
|
149 |
-
|
150 |
-
return $this->create_item( $request );
|
151 |
-
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* @param $request
|
156 |
-
*
|
157 |
-
* @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
|
158 |
-
*/
|
159 |
-
public function delete_item( $request ) {
|
160 |
-
$name = $request->get_param( 'name' );
|
161 |
-
|
162 |
-
if ( get_option( $name ) ) {
|
163 |
-
delete_option( $name );
|
164 |
-
|
165 |
-
return $this->success( sprintf( __( 'Attribute deleted with name: %s', 'woo-feed' ), $name ) );
|
166 |
-
}
|
167 |
-
|
168 |
-
return $this->error( sprintf( __( 'No attribute found with name: %s', 'woo-feed' ), $name ) );
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* @param $request
|
173 |
-
*
|
174 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
175 |
-
*/
|
176 |
-
public function create_item( $request ) {
|
177 |
-
$option_names = [];
|
178 |
-
$body = $request->get_body();
|
179 |
-
$body = json_decode( $body );
|
180 |
-
// Save option name.
|
181 |
-
foreach ( $body as $option_name => $value ) {
|
182 |
-
if ( ! $this->is_prefix_matched( $option_name, self::$prefix ) ) {
|
183 |
-
return $this->error( __( 'Option name prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ) );
|
184 |
-
}
|
185 |
-
$value = (array) $value;
|
186 |
-
update_option( $option_name, maybe_serialize( $value ) );
|
187 |
-
array_push( $option_names, $option_name );
|
188 |
-
}
|
189 |
-
// Get option name.
|
190 |
-
foreach ( $option_names as $option_name ) {
|
191 |
-
$data[ $option_name ] = maybe_unserialize( get_option( $option_name, false ) );
|
192 |
-
}
|
193 |
-
$this->response['data'] = $data;
|
194 |
-
|
195 |
-
return rest_ensure_response( $this->response );
|
196 |
-
}
|
197 |
-
|
198 |
-
/**
|
199 |
-
* @param $request
|
200 |
-
*
|
201 |
-
* @return \WP_Error|\WP_REST_Response|null
|
202 |
-
*/
|
203 |
-
public function get_item( $request ) {
|
204 |
-
$args = $request->get_params();
|
205 |
-
$feed_name = $args['name'];
|
206 |
-
global $wpdb;
|
207 |
-
$attr_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", $feed_name ), 'ARRAY_A' );
|
208 |
-
$this::$attr_lists = $attr_lists;
|
209 |
-
|
210 |
-
if ( count( $this::$attr_lists ) && $this->is_prefix_matched( $this::$attr_lists[0]['option_name'], self::$prefix ) ) {
|
211 |
-
$item = $this->prepare_item_for_response( $this::$attr_lists[0], $request );
|
212 |
-
|
213 |
-
return $this->success( $item );
|
214 |
-
}
|
215 |
-
|
216 |
-
return $this->error( sprintf( __( 'Not found with: %s or prefix: "'. self::$prefix .'" does\'nt match.', 'woo-feed' ), $feed_name ) );
|
217 |
-
}
|
218 |
-
|
219 |
-
/**
|
220 |
-
*
|
221 |
-
* @param \WP_REST_Request $request Full details about the request.
|
222 |
-
*
|
223 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
224 |
-
*/
|
225 |
-
public function get_items( $request ) {
|
226 |
-
$args = $request->get_params();
|
227 |
-
if ( isset( $args['name'] ) ) {
|
228 |
-
return $this->get_item( $request );
|
229 |
-
}
|
230 |
-
global $wpdb;
|
231 |
-
$attr_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", self::$prefix.'%' ), 'ARRAY_A' );
|
232 |
-
$this::$attr_lists = $attr_lists;
|
233 |
-
|
234 |
-
$data = $this->get_lists( $request );
|
235 |
-
|
236 |
-
$response = rest_ensure_response( $this->response );
|
237 |
-
$response = $this->maybe_add_pagination( $args, $data, $response );
|
238 |
-
|
239 |
-
return $response;
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
-
* @param $request
|
244 |
-
*
|
245 |
-
* @return array
|
246 |
-
*/
|
247 |
-
public function get_lists( $request ) {
|
248 |
-
$lists = [];
|
249 |
-
foreach ( $this::$attr_lists as $attr_list ) {
|
250 |
-
$item = $this->prepare_item_for_response( $attr_list, $request );
|
251 |
-
$lists[] = $item;
|
252 |
-
}
|
253 |
-
|
254 |
-
return $lists;
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
* @param $item
|
259 |
-
* @param $request
|
260 |
-
*
|
261 |
-
* @return void|\WP_Error|\WP_REST_Response
|
262 |
-
*/
|
263 |
-
public function prepare_item_for_response( $item, $request ) {
|
264 |
-
$item['option_value'] = maybe_unserialize( get_option( $item['option_name'] ) );
|
265 |
-
|
266 |
-
return $item;
|
267 |
-
}
|
268 |
-
|
269 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
V5/API/V1/CategoryMapping.php
DELETED
@@ -1,269 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace CTXFeed\V5\API\V1;
|
4 |
-
|
5 |
-
use CTXFeed\V5\API\RestController;
|
6 |
-
use \WP_REST_Server;
|
7 |
-
|
8 |
-
class CategoryMapping extends RestController {
|
9 |
-
/**
|
10 |
-
* @var array
|
11 |
-
*/
|
12 |
-
private static $category_lists = [];
|
13 |
-
/**
|
14 |
-
* @var string
|
15 |
-
*/
|
16 |
-
private static $prefix = 'wf_cmapping_';
|
17 |
-
/**
|
18 |
-
* The single instance of the class
|
19 |
-
*
|
20 |
-
* @var CategoryMapping
|
21 |
-
*
|
22 |
-
*/
|
23 |
-
protected static $_instance = null;
|
24 |
-
|
25 |
-
private function __construct() {
|
26 |
-
parent::__construct();
|
27 |
-
$this->rest_base = 'category_mapping';
|
28 |
-
}
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Main CategoryMapping Instance.
|
32 |
-
*
|
33 |
-
* Ensures only one instance of CategoryMapping is loaded or can be loaded.
|
34 |
-
*
|
35 |
-
* @return CategoryMapping Main instance
|
36 |
-
*/
|
37 |
-
public static function instance() {
|
38 |
-
if ( is_null( self::$_instance ) ) {
|
39 |
-
self::$_instance = new self();
|
40 |
-
}
|
41 |
-
|
42 |
-
return self::$_instance;
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Register routes.
|
47 |
-
* @return void
|
48 |
-
*/
|
49 |
-
public function register_routes() {
|
50 |
-
register_rest_route(
|
51 |
-
$this->namespace,
|
52 |
-
'/' . $this->rest_base,
|
53 |
-
[
|
54 |
-
/**
|
55 |
-
* @endpoint: wp-json/ctxfeed/v1/category_mapping
|
56 |
-
* @description Will get all feed lists
|
57 |
-
*
|
58 |
-
*
|
59 |
-
* @endpoint wp-json/ctxfeed/v1/category_mapping/?page=1&per_page=2
|
60 |
-
* @descripton Get paginated value with previous page and next page link
|
61 |
-
*
|
62 |
-
* @endpoint wp-json/ctxfeed/v1/category_mapping/?name=wf_feed_google_shopping
|
63 |
-
* @method GET
|
64 |
-
* @descripton Get single attribute
|
65 |
-
*
|
66 |
-
* @param $name String
|
67 |
-
*
|
68 |
-
* @param $page Number
|
69 |
-
* @param $per_page Number
|
70 |
-
*/
|
71 |
-
[
|
72 |
-
'methods' => WP_REST_Server::READABLE,
|
73 |
-
'callback' => [ $this, 'get_items' ],
|
74 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
75 |
-
'args' => [
|
76 |
-
'name' => [
|
77 |
-
'description' => __( 'feed name', 'woo-feed' ),
|
78 |
-
'type' => 'string',
|
79 |
-
'required' => false,
|
80 |
-
'sanitize_callback' => 'sanitize_text_field',
|
81 |
-
'validate_callback' => 'rest_validate_request_arg',
|
82 |
-
],
|
83 |
-
'page' => [
|
84 |
-
'description' => __( 'Page number', 'woo-feed' ),
|
85 |
-
'type' => 'number',
|
86 |
-
'required' => false,
|
87 |
-
'sanitize_callback' => 'absint',
|
88 |
-
'validate_callback' => 'rest_validate_request_arg',
|
89 |
-
],
|
90 |
-
'per_page' => [
|
91 |
-
'description' => __( 'Per page', 'woo-feed' ),
|
92 |
-
'type' => 'number',
|
93 |
-
'required' => false,
|
94 |
-
'sanitize_callback' => 'absint',
|
95 |
-
'validate_callback' => 'rest_validate_request_arg',
|
96 |
-
],
|
97 |
-
],
|
98 |
-
],
|
99 |
-
[
|
100 |
-
'methods' => WP_REST_Server::CREATABLE,
|
101 |
-
'callback' => [ $this, 'create_item' ],
|
102 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
103 |
-
'args' => [],
|
104 |
-
],
|
105 |
-
[
|
106 |
-
'methods' => WP_REST_Server::EDITABLE,
|
107 |
-
'callback' => [ $this, 'update_item' ],
|
108 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
109 |
-
'args' => [],
|
110 |
-
],
|
111 |
-
/**
|
112 |
-
* @endpoint wp-json/ctxfeed/v1/category_mapping/?name=wf_feed_google_shopping
|
113 |
-
* @method DELETE
|
114 |
-
* @descripton Delete single attribute
|
115 |
-
*
|
116 |
-
* @param $name String
|
117 |
-
*/
|
118 |
-
[
|
119 |
-
'methods' => WP_REST_Server::DELETABLE,
|
120 |
-
'callback' => [ $this, 'delete_item' ],
|
121 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
122 |
-
'args' => [
|
123 |
-
'name' => [
|
124 |
-
'description' => __( 'feed name', 'woo-feed' ),
|
125 |
-
'type' => 'string',
|
126 |
-
'required' => true,
|
127 |
-
'sanitize_callback' => 'sanitize_text_field',
|
128 |
-
'validate_callback' => 'rest_validate_request_arg',
|
129 |
-
],
|
130 |
-
],
|
131 |
-
],
|
132 |
-
|
133 |
-
]
|
134 |
-
);
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* @param $request
|
139 |
-
*
|
140 |
-
* @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
|
141 |
-
*/
|
142 |
-
public function update_item( $request ) {
|
143 |
-
$body = $request->get_body();
|
144 |
-
$body = (array) json_decode( $body );
|
145 |
-
|
146 |
-
if ( ! $this->is_assoc( $body ) ) {
|
147 |
-
return $this->error( __( 'Option name is missing!', 'woo-feed' ) );
|
148 |
-
}
|
149 |
-
|
150 |
-
return $this->create_item( $request );
|
151 |
-
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* @param $request
|
156 |
-
*
|
157 |
-
* @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
|
158 |
-
*/
|
159 |
-
public function delete_item( $request ) {
|
160 |
-
$name = $request->get_param( 'name' );
|
161 |
-
|
162 |
-
if ( get_option( $name ) ) {
|
163 |
-
delete_option( $name );
|
164 |
-
|
165 |
-
return $this->success( sprintf( __( 'Attribute deleted with name: %s', 'woo-feed' ), $name ) );
|
166 |
-
}
|
167 |
-
|
168 |
-
return $this->error( sprintf( __( 'No attribute found with name: %s', 'woo-feed' ), $name ) );
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* @param $request
|
173 |
-
*
|
174 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
175 |
-
*/
|
176 |
-
public function create_item( $request ) {
|
177 |
-
$option_names = [];
|
178 |
-
$body = $request->get_body();
|
179 |
-
$body = json_decode( $body );
|
180 |
-
// Save option name.
|
181 |
-
foreach ( $body as $option_name => $value ) {
|
182 |
-
if ( ! $this->is_prefix_matched( $option_name, self::$prefix ) ) {
|
183 |
-
return $this->error( __( 'Option name prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ) );
|
184 |
-
}
|
185 |
-
$value = (array) $value;
|
186 |
-
update_option( $option_name, maybe_serialize( $value ) );
|
187 |
-
array_push( $option_names, $option_name );
|
188 |
-
}
|
189 |
-
// Get option name.
|
190 |
-
foreach ( $option_names as $option_name ) {
|
191 |
-
$data[ $option_name ] = maybe_unserialize( get_option( $option_name, false ) );
|
192 |
-
}
|
193 |
-
$this->response['data'] = $data;
|
194 |
-
|
195 |
-
return rest_ensure_response( $this->response );
|
196 |
-
}
|
197 |
-
|
198 |
-
/**
|
199 |
-
* @param $request
|
200 |
-
*
|
201 |
-
* @return \WP_Error|\WP_REST_Response|null
|
202 |
-
*/
|
203 |
-
public function get_item( $request ) {
|
204 |
-
$args = $request->get_params();
|
205 |
-
$feed_name = $args['name'];
|
206 |
-
global $wpdb;
|
207 |
-
$category_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", $feed_name ), 'ARRAY_A' );
|
208 |
-
$this::$category_lists = $category_lists;
|
209 |
-
|
210 |
-
if ( count( $this::$category_lists ) && $this->is_prefix_matched( $this::$category_lists[0]['option_name'], self::$prefix ) ) {
|
211 |
-
$item = $this->prepare_item_for_response( $this::$category_lists[0], $request );
|
212 |
-
|
213 |
-
return $this->success( $item );
|
214 |
-
}
|
215 |
-
|
216 |
-
return $this->error( sprintf( __( 'Not found with: %s or prefix: "'. self::$prefix .'" does\'nt match.', 'woo-feed' ), $feed_name ) );
|
217 |
-
}
|
218 |
-
|
219 |
-
/**
|
220 |
-
*
|
221 |
-
* @param \WP_REST_Request $request Full details about the request.
|
222 |
-
*
|
223 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
224 |
-
*/
|
225 |
-
public function get_items( $request ) {
|
226 |
-
$args = $request->get_params();
|
227 |
-
if ( isset( $args['name'] ) ) {
|
228 |
-
return $this->get_item( $request );
|
229 |
-
}
|
230 |
-
global $wpdb;
|
231 |
-
$category_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", self::$prefix.'%' ), 'ARRAY_A' );
|
232 |
-
$this::$category_lists = $category_lists;
|
233 |
-
|
234 |
-
$data = $this->get_lists( $request );
|
235 |
-
|
236 |
-
$response = rest_ensure_response( $this->response );
|
237 |
-
$response = $this->maybe_add_pagination( $args, $data, $response );
|
238 |
-
|
239 |
-
return $response;
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
-
* @param $request
|
244 |
-
*
|
245 |
-
* @return array
|
246 |
-
*/
|
247 |
-
public function get_lists( $request ) {
|
248 |
-
$lists = [];
|
249 |
-
foreach ( $this::$category_lists as $attr_list ) {
|
250 |
-
$item = $this->prepare_item_for_response( $attr_list, $request );
|
251 |
-
$lists[] = $item;
|
252 |
-
}
|
253 |
-
|
254 |
-
return $lists;
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
* @param $item
|
259 |
-
* @param $request
|
260 |
-
*
|
261 |
-
* @return void|\WP_Error|\WP_REST_Response
|
262 |
-
*/
|
263 |
-
public function prepare_item_for_response( $item, $request ) {
|
264 |
-
$item['option_value'] = maybe_unserialize( get_option( $item['option_name'] ) );
|
265 |
-
|
266 |
-
return $item;
|
267 |
-
}
|
268 |
-
|
269 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
V5/API/V1/{DropDown.php → DropDownOptionsApi.php}
RENAMED
@@ -7,7 +7,7 @@ use WP_REST_Server;
|
|
7 |
use CTXFeed\V5\Common\DropDownOptions;
|
8 |
use \WP_Error;
|
9 |
|
10 |
-
class
|
11 |
|
12 |
/**
|
13 |
* @var $dropdown
|
@@ -16,7 +16,7 @@ class DropDown extends RestController {
|
|
16 |
/**
|
17 |
* The single instance of the class
|
18 |
*
|
19 |
-
* @var
|
20 |
*
|
21 |
*/
|
22 |
protected static $_instance = null;
|
@@ -24,7 +24,7 @@ class DropDown extends RestController {
|
|
24 |
private function __construct() {
|
25 |
parent::__construct();
|
26 |
|
27 |
-
$this->rest_base = '
|
28 |
$this->dropdown = DropDownOptions::instance();
|
29 |
|
30 |
}
|
@@ -34,7 +34,7 @@ class DropDown extends RestController {
|
|
34 |
*
|
35 |
* Ensures only one instance of DropDownOptionsApi is loaded or can be loaded.
|
36 |
*
|
37 |
-
* @return
|
38 |
*/
|
39 |
public static function instance() {
|
40 |
if ( is_null( self::$_instance ) ) {
|
7 |
use CTXFeed\V5\Common\DropDownOptions;
|
8 |
use \WP_Error;
|
9 |
|
10 |
+
class DropDownOptionsApi extends RestController {
|
11 |
|
12 |
/**
|
13 |
* @var $dropdown
|
16 |
/**
|
17 |
* The single instance of the class
|
18 |
*
|
19 |
+
* @var DropDownOptionsApi
|
20 |
*
|
21 |
*/
|
22 |
protected static $_instance = null;
|
24 |
private function __construct() {
|
25 |
parent::__construct();
|
26 |
|
27 |
+
$this->rest_base = 'dropdown';
|
28 |
$this->dropdown = DropDownOptions::instance();
|
29 |
|
30 |
}
|
34 |
*
|
35 |
* Ensures only one instance of DropDownOptionsApi is loaded or can be loaded.
|
36 |
*
|
37 |
+
* @return DropDownOptionsApi Main instance
|
38 |
*/
|
39 |
public static function instance() {
|
40 |
if ( is_null( self::$_instance ) ) {
|
V5/API/V1/DynamicAttributes.php
DELETED
@@ -1,262 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace CTXFeed\V5\API\V1;
|
4 |
-
|
5 |
-
use CTXFeed\V5\API\RestController;
|
6 |
-
use \WP_REST_Server;
|
7 |
-
|
8 |
-
class DynamicAttributes extends RestController {
|
9 |
-
private static $attr_lists = [];
|
10 |
-
private static $prefix = 'wf_dattribute_';
|
11 |
-
/**
|
12 |
-
* The single instance of the class
|
13 |
-
*
|
14 |
-
* @var DynamicAttributes
|
15 |
-
*
|
16 |
-
*/
|
17 |
-
protected static $_instance = null;
|
18 |
-
|
19 |
-
private function __construct() {
|
20 |
-
parent::__construct();
|
21 |
-
$this->rest_base = 'dynamic_attributes';
|
22 |
-
}
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Main DynamicAttributes Instance.
|
26 |
-
*
|
27 |
-
* Ensures only one instance of DynamicAttributes is loaded or can be loaded.
|
28 |
-
*
|
29 |
-
* @return DynamicAttributes Main instance
|
30 |
-
*/
|
31 |
-
public static function instance() {
|
32 |
-
if ( is_null( self::$_instance ) ) {
|
33 |
-
self::$_instance = new self();
|
34 |
-
}
|
35 |
-
|
36 |
-
return self::$_instance;
|
37 |
-
}
|
38 |
-
|
39 |
-
/**
|
40 |
-
* Register routes.
|
41 |
-
* @return void
|
42 |
-
*/
|
43 |
-
public function register_routes() {
|
44 |
-
register_rest_route(
|
45 |
-
$this->namespace,
|
46 |
-
'/' . $this->rest_base,
|
47 |
-
[
|
48 |
-
/**
|
49 |
-
* @endpoint: wp-json/ctxfeed/v1/dynamic_attributes
|
50 |
-
* @description Will get all feed lists
|
51 |
-
*
|
52 |
-
*
|
53 |
-
* @endpoint wp-json/ctxfeed/v1/dynamic_attributes/?page=1&per_page=2
|
54 |
-
* @descripton Get paginated value with previous page and next page link
|
55 |
-
*
|
56 |
-
* @endpoint wp-json/ctxfeed/v1/dynamic_attributes/?name=wf_feed_google_shopping
|
57 |
-
* @method GET
|
58 |
-
* @descripton Get single attribute
|
59 |
-
*
|
60 |
-
* @param $name String
|
61 |
-
*
|
62 |
-
* @param $page Number
|
63 |
-
* @param $per_page Number
|
64 |
-
*/
|
65 |
-
[
|
66 |
-
'methods' => WP_REST_Server::READABLE,
|
67 |
-
'callback' => [ $this, 'get_items' ],
|
68 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
69 |
-
'args' => [
|
70 |
-
'name' => [
|
71 |
-
'description' => __( 'feed name', 'woo-feed' ),
|
72 |
-
'type' => 'string',
|
73 |
-
'required' => false,
|
74 |
-
'sanitize_callback' => 'sanitize_text_field',
|
75 |
-
'validate_callback' => 'rest_validate_request_arg',
|
76 |
-
],
|
77 |
-
'page' => [
|
78 |
-
'description' => __( 'Page number', 'woo-feed' ),
|
79 |
-
'type' => 'number',
|
80 |
-
'required' => false,
|
81 |
-
'sanitize_callback' => 'absint',
|
82 |
-
'validate_callback' => 'rest_validate_request_arg',
|
83 |
-
],
|
84 |
-
'per_page' => [
|
85 |
-
'description' => __( 'Per page', 'woo-feed' ),
|
86 |
-
'type' => 'number',
|
87 |
-
'required' => false,
|
88 |
-
'sanitize_callback' => 'absint',
|
89 |
-
'validate_callback' => 'rest_validate_request_arg',
|
90 |
-
],
|
91 |
-
],
|
92 |
-
],
|
93 |
-
[
|
94 |
-
'methods' => WP_REST_Server::CREATABLE,
|
95 |
-
'callback' => [ $this, 'create_item' ],
|
96 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
97 |
-
'args' => [],
|
98 |
-
],
|
99 |
-
[
|
100 |
-
'methods' => WP_REST_Server::EDITABLE,
|
101 |
-
'callback' => [ $this, 'update_item' ],
|
102 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
103 |
-
'args' => [],
|
104 |
-
],
|
105 |
-
/**
|
106 |
-
* @endpoint wp-json/ctxfeed/v1/dynamic_attributes/?name=wf_feed_google_shopping
|
107 |
-
* @method DELETE
|
108 |
-
* @descripton Delete single attribute
|
109 |
-
*
|
110 |
-
* @param $name String
|
111 |
-
*/
|
112 |
-
[
|
113 |
-
'methods' => WP_REST_Server::DELETABLE,
|
114 |
-
'callback' => [ $this, 'delete_item' ],
|
115 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
116 |
-
'args' => [
|
117 |
-
'name' => [
|
118 |
-
'description' => __( 'feed name', 'woo-feed' ),
|
119 |
-
'type' => 'string',
|
120 |
-
'required' => true,
|
121 |
-
'sanitize_callback' => 'sanitize_text_field',
|
122 |
-
'validate_callback' => 'rest_validate_request_arg',
|
123 |
-
],
|
124 |
-
],
|
125 |
-
],
|
126 |
-
|
127 |
-
]
|
128 |
-
);
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* @param $request
|
133 |
-
*
|
134 |
-
* @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
|
135 |
-
*/
|
136 |
-
public function update_item( $request ) {
|
137 |
-
$body = $request->get_body();
|
138 |
-
$body = (array) json_decode( $body );
|
139 |
-
|
140 |
-
if ( ! $this->is_assoc( $body ) ) {
|
141 |
-
return $this->error( __( 'Option name is missing!', 'woo-feed' ) );
|
142 |
-
}
|
143 |
-
|
144 |
-
return $this->create_item( $request );
|
145 |
-
|
146 |
-
}
|
147 |
-
|
148 |
-
/**
|
149 |
-
* @param $request
|
150 |
-
*
|
151 |
-
* @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
|
152 |
-
*/
|
153 |
-
public function delete_item( $request ) {
|
154 |
-
$name = $request->get_param( 'name' );
|
155 |
-
|
156 |
-
if ( get_option( $name ) ) {
|
157 |
-
delete_option( $name );
|
158 |
-
|
159 |
-
return $this->success( sprintf( __( 'Attribute deleted with name: %s', 'woo-feed' ), $name ) );
|
160 |
-
}
|
161 |
-
|
162 |
-
return $this->error( sprintf( __( 'No attribute found with name: %s', 'woo-feed' ), $name ) );
|
163 |
-
}
|
164 |
-
|
165 |
-
/**
|
166 |
-
* @param $request
|
167 |
-
*
|
168 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
169 |
-
*/
|
170 |
-
public function create_item( $request ) {
|
171 |
-
$option_names = [];
|
172 |
-
$body = $request->get_body();
|
173 |
-
$body = json_decode( $body );
|
174 |
-
// Save option name.
|
175 |
-
foreach ( $body as $option_name => $value ) {
|
176 |
-
if ( ! $this->is_prefix_matched( $option_name, self::$prefix ) ) {
|
177 |
-
return $this->error( __( 'Option name prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ) );
|
178 |
-
}
|
179 |
-
$value = (array) $value;
|
180 |
-
update_option( $option_name, maybe_serialize( $value ) );
|
181 |
-
array_push( $option_names, $option_name );
|
182 |
-
}
|
183 |
-
// Get option name.
|
184 |
-
foreach ( $option_names as $option_name ) {
|
185 |
-
$data[ $option_name ] = maybe_unserialize( get_option( $option_name, false ) );
|
186 |
-
}
|
187 |
-
$this->response['data'] = $data;
|
188 |
-
|
189 |
-
return rest_ensure_response( $this->response );
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
* @param $request
|
194 |
-
*
|
195 |
-
* @return \WP_Error|\WP_REST_Response|null
|
196 |
-
*/
|
197 |
-
public function get_item( $request ) {
|
198 |
-
$args = $request->get_params();
|
199 |
-
$feed_name = $args['name'];
|
200 |
-
global $wpdb;
|
201 |
-
$attr_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", $feed_name ), 'ARRAY_A' );
|
202 |
-
$this::$attr_lists = $attr_lists;
|
203 |
-
if ( count( $this::$attr_lists ) && $this->is_prefix_matched( $this::$attr_lists[0]['option_name'], self::$prefix ) ) {
|
204 |
-
$item = $this->prepare_item_for_response( $this::$attr_lists[0], $request );
|
205 |
-
|
206 |
-
return $this->success( $item );
|
207 |
-
}
|
208 |
-
|
209 |
-
return $this->error( sprintf( __( 'Not found with: %s or prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ), $feed_name ) );
|
210 |
-
}
|
211 |
-
|
212 |
-
/**
|
213 |
-
*
|
214 |
-
* @param \WP_REST_Request $request Full details about the request.
|
215 |
-
*
|
216 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
217 |
-
*/
|
218 |
-
public function get_items( $request ) {
|
219 |
-
$args = $request->get_params();
|
220 |
-
if ( isset( $args['name'] ) ) {
|
221 |
-
return $this->get_item( $request );
|
222 |
-
}
|
223 |
-
global $wpdb;
|
224 |
-
$attr_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", self::$prefix.'%' ), 'ARRAY_A' );
|
225 |
-
$this::$attr_lists = $attr_lists;
|
226 |
-
|
227 |
-
$data = $this->get_lists( $request );
|
228 |
-
|
229 |
-
$response = rest_ensure_response( $this->response );
|
230 |
-
$response = $this->maybe_add_pagination( $args, $data, $response );
|
231 |
-
|
232 |
-
return $response;
|
233 |
-
}
|
234 |
-
|
235 |
-
/**
|
236 |
-
* @param $request
|
237 |
-
*
|
238 |
-
* @return array
|
239 |
-
*/
|
240 |
-
public function get_lists( $request ) {
|
241 |
-
$lists = [];
|
242 |
-
foreach ( $this::$attr_lists as $attr_list ) {
|
243 |
-
$item = $this->prepare_item_for_response( $attr_list, $request );
|
244 |
-
$lists[] = $item;
|
245 |
-
}
|
246 |
-
|
247 |
-
return $lists;
|
248 |
-
}
|
249 |
-
|
250 |
-
/**
|
251 |
-
* @param $item
|
252 |
-
* @param $request
|
253 |
-
*
|
254 |
-
* @return void|\WP_Error|\WP_REST_Response
|
255 |
-
*/
|
256 |
-
public function prepare_item_for_response( $item, $request ) {
|
257 |
-
$item['option_value'] = maybe_unserialize( get_option( $item['option_name'] ) );
|
258 |
-
|
259 |
-
return $item;
|
260 |
-
}
|
261 |
-
|
262 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
V5/API/V1/FeedLists.php
CHANGED
@@ -51,24 +51,15 @@ class FeedLists extends RestController {
|
|
51 |
* @description Will get all feed lists
|
52 |
*
|
53 |
* @endpoint wp-json/ctxfeed/v1/feed_lists/?status=inactive
|
54 |
-
* @method GET
|
55 |
* @description Only inactive feed lists will be returned.
|
56 |
*
|
57 |
*
|
58 |
* @endpoint wp-json/ctxfeed/v1/feed_lists/?status=active
|
59 |
-
* @method GET
|
60 |
* @description Only active feed lists will be returned.
|
61 |
*
|
62 |
* @endpoint wp-json/ctxfeed/v1/feed_lists/?status=active&page=1&per_page=2
|
63 |
-
* @method GET
|
64 |
* @descripton Get paginated value with previous page and next page link
|
65 |
*
|
66 |
-
*
|
67 |
-
* @endpoint wp-json/ctxfeed/v1/feed_lists/?name=wf_feed_google_shopping
|
68 |
-
* @method GET
|
69 |
-
* @descripton Get single feed
|
70 |
-
* @param $name String
|
71 |
-
*
|
72 |
* @param $status String
|
73 |
* @param $page Number
|
74 |
* @param $per_page Number
|
@@ -85,13 +76,6 @@ class FeedLists extends RestController {
|
|
85 |
'sanitize_callback' => 'sanitize_text_field',
|
86 |
'validate_callback' => 'rest_validate_request_arg',
|
87 |
],
|
88 |
-
'name' => [
|
89 |
-
'description' => __( 'feed name', 'woo-feed' ),
|
90 |
-
'type' => 'string',
|
91 |
-
'required' => false,
|
92 |
-
'sanitize_callback' => 'sanitize_text_field',
|
93 |
-
'validate_callback' => 'rest_validate_request_arg',
|
94 |
-
],
|
95 |
'page' => [
|
96 |
'description' => __( 'Page number', 'woo-feed' ),
|
97 |
'type' => 'number',
|
@@ -107,30 +91,11 @@ class FeedLists extends RestController {
|
|
107 |
'validate_callback' => 'rest_validate_request_arg',
|
108 |
],
|
109 |
],
|
110 |
-
]
|
111 |
]
|
112 |
);
|
113 |
}
|
114 |
|
115 |
-
/**
|
116 |
-
* @param $request
|
117 |
-
*
|
118 |
-
* @return \WP_Error|\WP_REST_Response|null
|
119 |
-
*/
|
120 |
-
public function get_item( $request ) {
|
121 |
-
$args = $request->get_params();
|
122 |
-
$feed_name = $args['name'];
|
123 |
-
global $wpdb;
|
124 |
-
$feed_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", $feed_name ), 'ARRAY_A' );
|
125 |
-
$this::$feed_lists = $feed_lists;
|
126 |
-
if( count( $this::$feed_lists ) ) {
|
127 |
-
$item = $this->prepare_item_for_response( $this::$feed_lists[0], $request );
|
128 |
-
return $this->success( $item );
|
129 |
-
}
|
130 |
-
|
131 |
-
return $this->error( sprintf( __( 'Not found with: %s ', 'woo-feed' ), $feed_name ) );
|
132 |
-
}
|
133 |
-
|
134 |
/**
|
135 |
*
|
136 |
* @param \WP_REST_Request $request Full details about the request.
|
@@ -140,9 +105,6 @@ class FeedLists extends RestController {
|
|
140 |
public function get_items( $request ) {
|
141 |
$args = $request->get_params();
|
142 |
$this::$status = isset( $args['status'] ) ? $args['status'] : $this::$status;
|
143 |
-
if ( isset( $args['name'] ) ) {
|
144 |
-
return $this->get_item( $request );
|
145 |
-
}
|
146 |
global $wpdb;
|
147 |
$feed_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", 'wf_feed_%' ), 'ARRAY_A' );
|
148 |
$this::$feed_lists = $feed_lists;
|
@@ -168,7 +130,7 @@ class FeedLists extends RestController {
|
|
168 |
foreach ( $this::$feed_lists as $feed_list ) {
|
169 |
$item = $this->prepare_item_for_response( $feed_list, $request );
|
170 |
if ( $this::$status ) {
|
171 |
-
if
|
172 |
$lists[] = $item;
|
173 |
continue;
|
174 |
}
|
@@ -178,7 +140,7 @@ class FeedLists extends RestController {
|
|
178 |
if ( 'inactive' === $this::$status && 0 === $item['option_value']['status'] ) {
|
179 |
$lists[] = $item;
|
180 |
}
|
181 |
-
}
|
182 |
$lists[] = $item;
|
183 |
}
|
184 |
}
|
51 |
* @description Will get all feed lists
|
52 |
*
|
53 |
* @endpoint wp-json/ctxfeed/v1/feed_lists/?status=inactive
|
|
|
54 |
* @description Only inactive feed lists will be returned.
|
55 |
*
|
56 |
*
|
57 |
* @endpoint wp-json/ctxfeed/v1/feed_lists/?status=active
|
|
|
58 |
* @description Only active feed lists will be returned.
|
59 |
*
|
60 |
* @endpoint wp-json/ctxfeed/v1/feed_lists/?status=active&page=1&per_page=2
|
|
|
61 |
* @descripton Get paginated value with previous page and next page link
|
62 |
*
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
* @param $status String
|
64 |
* @param $page Number
|
65 |
* @param $per_page Number
|
76 |
'sanitize_callback' => 'sanitize_text_field',
|
77 |
'validate_callback' => 'rest_validate_request_arg',
|
78 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
'page' => [
|
80 |
'description' => __( 'Page number', 'woo-feed' ),
|
81 |
'type' => 'number',
|
91 |
'validate_callback' => 'rest_validate_request_arg',
|
92 |
],
|
93 |
],
|
94 |
+
],
|
95 |
]
|
96 |
);
|
97 |
}
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
/**
|
100 |
*
|
101 |
* @param \WP_REST_Request $request Full details about the request.
|
105 |
public function get_items( $request ) {
|
106 |
$args = $request->get_params();
|
107 |
$this::$status = isset( $args['status'] ) ? $args['status'] : $this::$status;
|
|
|
|
|
|
|
108 |
global $wpdb;
|
109 |
$feed_lists = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_id DESC;", 'wf_feed_%' ), 'ARRAY_A' );
|
110 |
$this::$feed_lists = $feed_lists;
|
130 |
foreach ( $this::$feed_lists as $feed_list ) {
|
131 |
$item = $this->prepare_item_for_response( $feed_list, $request );
|
132 |
if ( $this::$status ) {
|
133 |
+
if( is_object( $item['option_value'] ) ) {
|
134 |
$lists[] = $item;
|
135 |
continue;
|
136 |
}
|
140 |
if ( 'inactive' === $this::$status && 0 === $item['option_value']['status'] ) {
|
141 |
$lists[] = $item;
|
142 |
}
|
143 |
+
}else{
|
144 |
$lists[] = $item;
|
145 |
}
|
146 |
}
|
V5/API/V1/MerchantConfig.php
CHANGED
@@ -2,6 +2,8 @@
|
|
2 |
|
3 |
namespace CTXFeed\V5\API\V1;
|
4 |
|
|
|
|
|
5 |
use CTXFeed\V5\API\RestController;
|
6 |
use CTXFeed\V5\Helper\FeedHelper;
|
7 |
use CTXFeed\V5\Merchant\TemplateConfig;
|
@@ -130,26 +132,29 @@ class MerchantConfig extends RestController {
|
|
130 |
$merchant = new Config( $defaultMerchantConfig );
|
131 |
$merchant_config = $merchant->get_config();
|
132 |
|
133 |
-
|
134 |
|
135 |
} elseif ( 'edit' === $type ) {
|
136 |
$feedName = $request->get_param( 'feed' );
|
137 |
// True if feed name is missing
|
138 |
if ( ! $feedName ) {
|
139 |
-
|
|
|
|
|
140 |
}
|
141 |
|
142 |
$feedName = FeedHelper::get_feed_option_name( $feedName );
|
143 |
$feedInfo = get_option( 'wf_config' . $feedName, false );
|
144 |
|
145 |
if ( $feedInfo ) {
|
146 |
-
|
147 |
} else {
|
148 |
-
|
149 |
}
|
150 |
}
|
151 |
|
152 |
-
|
|
|
153 |
}
|
154 |
|
155 |
/**
|
@@ -163,7 +168,6 @@ class MerchantConfig extends RestController {
|
|
163 |
$body = json_decode( $body );
|
164 |
// Save option name.
|
165 |
foreach ( $body as $option_name => $value ) {
|
166 |
-
$value = (array) $value;
|
167 |
update_option( $option_name, $value );
|
168 |
array_push( $option_names, $option_name );
|
169 |
}
|
@@ -171,7 +175,8 @@ class MerchantConfig extends RestController {
|
|
171 |
foreach ( $option_names as $option_name ) {
|
172 |
$data[ $option_name ] = maybe_unserialize( get_option( $option_name, false ) );
|
173 |
}
|
|
|
174 |
|
175 |
-
return $this->
|
176 |
}
|
177 |
}
|
2 |
|
3 |
namespace CTXFeed\V5\API\V1;
|
4 |
|
5 |
+
namespace CTXFeed\V5\API\V1;
|
6 |
+
|
7 |
use CTXFeed\V5\API\RestController;
|
8 |
use CTXFeed\V5\Helper\FeedHelper;
|
9 |
use CTXFeed\V5\Merchant\TemplateConfig;
|
132 |
$merchant = new Config( $defaultMerchantConfig );
|
133 |
$merchant_config = $merchant->get_config();
|
134 |
|
135 |
+
$this->success( $merchant_config );
|
136 |
|
137 |
} elseif ( 'edit' === $type ) {
|
138 |
$feedName = $request->get_param( 'feed' );
|
139 |
// True if feed name is missing
|
140 |
if ( ! $feedName ) {
|
141 |
+
$this->error( __( 'Feed file name missing!', 'woo-feed' ) );
|
142 |
+
|
143 |
+
return rest_ensure_response( $this->response );
|
144 |
}
|
145 |
|
146 |
$feedName = FeedHelper::get_feed_option_name( $feedName );
|
147 |
$feedInfo = get_option( 'wf_config' . $feedName, false );
|
148 |
|
149 |
if ( $feedInfo ) {
|
150 |
+
$this->success( $feedInfo );
|
151 |
} else {
|
152 |
+
$this->error( sprintf( __( 'No configuration found with this feed name: %s', 'woo-feed' ), $feedName ) );
|
153 |
}
|
154 |
}
|
155 |
|
156 |
+
|
157 |
+
return rest_ensure_response( $this->response );
|
158 |
}
|
159 |
|
160 |
/**
|
168 |
$body = json_decode( $body );
|
169 |
// Save option name.
|
170 |
foreach ( $body as $option_name => $value ) {
|
|
|
171 |
update_option( $option_name, $value );
|
172 |
array_push( $option_names, $option_name );
|
173 |
}
|
175 |
foreach ( $option_names as $option_name ) {
|
176 |
$data[ $option_name ] = maybe_unserialize( get_option( $option_name, false ) );
|
177 |
}
|
178 |
+
$this->response['data'] = $data;
|
179 |
|
180 |
+
return rest_ensure_response( $this->response );
|
181 |
}
|
182 |
}
|
V5/API/V1/ProductCategories.php
CHANGED
@@ -17,7 +17,7 @@ class ProductCategories extends RestController {
|
|
17 |
|
18 |
private function __construct() {
|
19 |
parent::__construct();
|
20 |
-
$this->rest_base = '
|
21 |
}
|
22 |
|
23 |
/**
|
@@ -45,7 +45,7 @@ class ProductCategories extends RestController {
|
|
45 |
'/' . $this->rest_base,
|
46 |
[
|
47 |
/**
|
48 |
-
* @endpoint wp-json/ctxfeed/v1/
|
49 |
* @description will return all categories based on search string.
|
50 |
* @param $search String
|
51 |
*
|
17 |
|
18 |
private function __construct() {
|
19 |
parent::__construct();
|
20 |
+
$this->rest_base = 'categories';
|
21 |
}
|
22 |
|
23 |
/**
|
45 |
'/' . $this->rest_base,
|
46 |
[
|
47 |
/**
|
48 |
+
* @endpoint wp-json/ctxfeed/v1/categories/?search=hoo
|
49 |
* @description will return all categories based on search string.
|
50 |
* @param $search String
|
51 |
*
|
V5/API/V1/ProductTaxonomy.php
CHANGED
@@ -9,6 +9,8 @@ use WP_REST_Server;
|
|
9 |
|
10 |
class ProductTaxonomy extends RestController {
|
11 |
|
|
|
|
|
12 |
/**
|
13 |
* Default country code
|
14 |
* @var string
|
@@ -37,7 +39,7 @@ class ProductTaxonomy extends RestController {
|
|
37 |
|
38 |
private function __construct() {
|
39 |
parent::__construct();
|
40 |
-
$this->rest_base = '
|
41 |
}
|
42 |
|
43 |
/**
|
@@ -61,12 +63,12 @@ class ProductTaxonomy extends RestController {
|
|
61 |
'/' . $this->rest_base,
|
62 |
[
|
63 |
/**
|
64 |
-
* @endpoint wp-json/ctxfeed/v1/
|
65 |
* @description will return stored merchant data.
|
66 |
* @param $country_code
|
67 |
* @param $merchant
|
68 |
*
|
69 |
-
* @endpoint wp-json/ctxfeed/v1/
|
70 |
* @description Download merchant taxonomy file.
|
71 |
* @param $country_code String
|
72 |
* @param $merchant Stirng
|
9 |
|
10 |
class ProductTaxonomy extends RestController {
|
11 |
|
12 |
+
protected $rest_base = 'taxonomies';
|
13 |
+
|
14 |
/**
|
15 |
* Default country code
|
16 |
* @var string
|
39 |
|
40 |
private function __construct() {
|
41 |
parent::__construct();
|
42 |
+
$this->rest_base = 'taxonomies';
|
43 |
}
|
44 |
|
45 |
/**
|
63 |
'/' . $this->rest_base,
|
64 |
[
|
65 |
/**
|
66 |
+
* @endpoint wp-json/ctxfeed/v1/taxonomies/?country_code=en-US&merchant=google
|
67 |
* @description will return stored merchant data.
|
68 |
* @param $country_code
|
69 |
* @param $merchant
|
70 |
*
|
71 |
+
* @endpoint wp-json/ctxfeed/v1/taxonomies/?country_code=en-US&merchant=google&update=true
|
72 |
* @description Download merchant taxonomy file.
|
73 |
* @param $country_code String
|
74 |
* @param $merchant Stirng
|
V5/API/V1/ProductTitles.php
CHANGED
@@ -84,8 +84,9 @@ class ProductTitles extends RestController {
|
|
84 |
$handle = wc_get_product( $id );
|
85 |
$search_results[ $id ] = strip_tags( $handle->get_formatted_name() );
|
86 |
}
|
|
|
87 |
|
88 |
-
return $this->
|
89 |
}
|
90 |
|
91 |
}
|
84 |
$handle = wc_get_product( $id );
|
85 |
$search_results[ $id ] = strip_tags( $handle->get_formatted_name() );
|
86 |
}
|
87 |
+
$this->success( [ $search_results ] );
|
88 |
|
89 |
+
return rest_ensure_response( $this->response );
|
90 |
}
|
91 |
|
92 |
}
|
V5/API/V1/Settings.php
DELETED
@@ -1,194 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace CTXFeed\V5\API\V1;
|
4 |
-
|
5 |
-
use CTXFeed\V5\API\RestController;
|
6 |
-
use CTXFeed\V5\Helper\CustomFieldHelper;
|
7 |
-
use \WP_REST_Server;
|
8 |
-
|
9 |
-
class Settings extends RestController {
|
10 |
-
private static $settings_lists = [];
|
11 |
-
/**
|
12 |
-
* @var string
|
13 |
-
*/
|
14 |
-
private static $option_name = 'woo_feed_settings';
|
15 |
-
/**
|
16 |
-
* The single instance of the class
|
17 |
-
*
|
18 |
-
* @var Settings
|
19 |
-
*
|
20 |
-
*/
|
21 |
-
protected static $_instance = null;
|
22 |
-
|
23 |
-
private function __construct() {
|
24 |
-
parent::__construct();
|
25 |
-
$this->rest_base = 'settings';
|
26 |
-
}
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Main Settings Instance.
|
30 |
-
*
|
31 |
-
* Ensures only one instance of Settings is loaded or can be loaded.
|
32 |
-
*
|
33 |
-
* @return Settings Main instance
|
34 |
-
*/
|
35 |
-
public static function instance() {
|
36 |
-
if ( is_null( self::$_instance ) ) {
|
37 |
-
self::$_instance = new self();
|
38 |
-
}
|
39 |
-
|
40 |
-
return self::$_instance;
|
41 |
-
}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Register routes.
|
45 |
-
* @return void
|
46 |
-
*/
|
47 |
-
public function register_routes() {
|
48 |
-
// Default settings
|
49 |
-
register_rest_route(
|
50 |
-
$this->namespace,
|
51 |
-
'/' . $this->rest_base,
|
52 |
-
[
|
53 |
-
/**
|
54 |
-
*
|
55 |
-
* @endpoint wp-json/ctxfeed/v1/settings
|
56 |
-
* @method GET
|
57 |
-
* @descripton Get single attribute
|
58 |
-
*
|
59 |
-
* @param $name String
|
60 |
-
*
|
61 |
-
* @param $page Number
|
62 |
-
* @param $per_page Number
|
63 |
-
*/
|
64 |
-
[
|
65 |
-
'methods' => WP_REST_Server::READABLE,
|
66 |
-
'callback' => [ $this, 'get_item' ],
|
67 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
68 |
-
'args' => [],
|
69 |
-
],
|
70 |
-
[
|
71 |
-
'methods' => WP_REST_Server::EDITABLE,
|
72 |
-
'callback' => [ $this, 'update_item' ],
|
73 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
74 |
-
'args' => [],
|
75 |
-
],
|
76 |
-
'schema' => [ $this, 'get_item_schema' ],
|
77 |
-
],
|
78 |
-
|
79 |
-
);
|
80 |
-
// Custom Fields
|
81 |
-
register_rest_route(
|
82 |
-
$this->namespace, '/' . $this->rest_base . '/custom_settings',
|
83 |
-
/**
|
84 |
-
* @endpoint wp-json/ctxfeed/v1/settings/custom_settings
|
85 |
-
* @method GET
|
86 |
-
* @descripton get custom settings
|
87 |
-
*
|
88 |
-
* @param $name String
|
89 |
-
*/
|
90 |
-
[
|
91 |
-
[
|
92 |
-
'methods' => WP_REST_Server::READABLE,
|
93 |
-
'callback' => [ $this, 'get_custom_fields' ],
|
94 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
95 |
-
'args' => [],
|
96 |
-
]
|
97 |
-
],
|
98 |
-
);
|
99 |
-
}
|
100 |
-
|
101 |
-
/**
|
102 |
-
* @param $request \WP_REST_Request request body will be []
|
103 |
-
*
|
104 |
-
*
|
105 |
-
* @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
|
106 |
-
*/
|
107 |
-
public function get_custom_fields( $request ) {
|
108 |
-
$custom_fields = CustomFieldHelper::get_fields();
|
109 |
-
|
110 |
-
return $this->success( $custom_fields );
|
111 |
-
}
|
112 |
-
|
113 |
-
/**
|
114 |
-
* @param $request
|
115 |
-
*
|
116 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
117 |
-
*/
|
118 |
-
public function update_item( $request ) {
|
119 |
-
$body = $request->get_body();
|
120 |
-
$body = self::json_decode( $body );
|
121 |
-
update_option( self::$option_name, $body );
|
122 |
-
self::$settings_lists = get_option( self::$option_name, [] );
|
123 |
-
|
124 |
-
return $this->success( self::$settings_lists );
|
125 |
-
}
|
126 |
-
|
127 |
-
private static function json_decode( $body ) {
|
128 |
-
$arr = (array) json_decode( $body );
|
129 |
-
foreach ( $arr as &$value ) {
|
130 |
-
if ( is_object( $value ) ) {
|
131 |
-
$value = (array) $value;
|
132 |
-
} elseif ( is_string( $value ) ) {
|
133 |
-
$value = (string) $value;
|
134 |
-
} elseif ( is_array( $value ) ) {
|
135 |
-
$value = (array) $value;
|
136 |
-
} elseif ( is_int( $value ) ) {
|
137 |
-
$value = (int) $value;
|
138 |
-
}
|
139 |
-
}
|
140 |
-
|
141 |
-
return $arr;
|
142 |
-
}
|
143 |
-
|
144 |
-
/**
|
145 |
-
*
|
146 |
-
* @param \WP_REST_Request $request Full details about the request.
|
147 |
-
*
|
148 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
149 |
-
*/
|
150 |
-
public function get_item( $request ) {
|
151 |
-
self::$settings_lists = \CTXFeed\V5\Utility\Settings::get( 'all' );
|
152 |
-
|
153 |
-
return $this->success( self::$settings_lists );
|
154 |
-
}
|
155 |
-
|
156 |
-
|
157 |
-
/**
|
158 |
-
* Get our sample schema for comments.
|
159 |
-
*/
|
160 |
-
public function get_item_schema() {
|
161 |
-
if( $this->schema ) {
|
162 |
-
return $this->add_additional_fields_schema( $this->schema );
|
163 |
-
}
|
164 |
-
$schema = array(
|
165 |
-
// This tells the spec of JSON Schema we are using which is draft 4.
|
166 |
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
167 |
-
// The title property marks the identity of the resource.
|
168 |
-
'title' => 'comment',
|
169 |
-
'type' => 'object',
|
170 |
-
// In JSON Schema you can specify object properties in the properties attribute.
|
171 |
-
'properties' => array(
|
172 |
-
'id' => array(
|
173 |
-
'description' => esc_html__( 'Unique identifier for the object.', 'my-textdomain' ),
|
174 |
-
'type' => 'integer',
|
175 |
-
'context' => array( 'view', 'edit', 'embed' ),
|
176 |
-
'readonly' => true,
|
177 |
-
),
|
178 |
-
'author' => array(
|
179 |
-
'description' => esc_html__( 'The id of the user object, if author was a user.', 'my-textdomain' ),
|
180 |
-
'type' => 'integer',
|
181 |
-
),
|
182 |
-
'content' => array(
|
183 |
-
'description' => esc_html__( 'The content for the object.', 'my-textdomain' ),
|
184 |
-
'type' => 'string',
|
185 |
-
),
|
186 |
-
),
|
187 |
-
);
|
188 |
-
|
189 |
-
$this->schema = $schema;
|
190 |
-
|
191 |
-
return $this->add_additional_fields_schema( $this->schema );
|
192 |
-
}
|
193 |
-
|
194 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
V5/API/V1/WPOptions.php
DELETED
@@ -1,199 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace CTXFeed\V5\API\V1;
|
4 |
-
|
5 |
-
use CTXFeed\V5\API\RestController;
|
6 |
-
use \WP_REST_Server;
|
7 |
-
|
8 |
-
class WPOptions extends RestController {
|
9 |
-
private static $option_lists = [];
|
10 |
-
/**
|
11 |
-
* @var string
|
12 |
-
*/
|
13 |
-
private static $option_name = 'wpfp_option';
|
14 |
-
/**
|
15 |
-
* @var string
|
16 |
-
*/
|
17 |
-
private static $prefix = 'wf_option_';
|
18 |
-
/**
|
19 |
-
* The single instance of the class
|
20 |
-
*
|
21 |
-
* @var WPOptions
|
22 |
-
*
|
23 |
-
*/
|
24 |
-
protected static $_instance = null;
|
25 |
-
|
26 |
-
private function __construct() {
|
27 |
-
parent::__construct();
|
28 |
-
$this->rest_base = 'wp_options';
|
29 |
-
}
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Main WPOptions Instance.
|
33 |
-
*
|
34 |
-
* Ensures only one instance of WPOptions is loaded or can be loaded.
|
35 |
-
*
|
36 |
-
* @return WPOptions Main instance
|
37 |
-
*/
|
38 |
-
public static function instance() {
|
39 |
-
if ( is_null( self::$_instance ) ) {
|
40 |
-
self::$_instance = new self();
|
41 |
-
}
|
42 |
-
|
43 |
-
return self::$_instance;
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Register routes.
|
48 |
-
* @return void
|
49 |
-
*/
|
50 |
-
public function register_routes() {
|
51 |
-
register_rest_route(
|
52 |
-
$this->namespace,
|
53 |
-
'/' . $this->rest_base,
|
54 |
-
[
|
55 |
-
/**
|
56 |
-
* @endpoint: wp-json/ctxfeed/v1/wp_options
|
57 |
-
* @description Will get all feed lists
|
58 |
-
*
|
59 |
-
*
|
60 |
-
* @endpoint wp-json/ctxfeed/v1/wp_options/?page=1&per_page=2
|
61 |
-
* @descripton Get paginated value with previous page and next page link
|
62 |
-
*
|
63 |
-
* @endpoint wp-json/ctxfeed/v1/wp_options/?name=wf_feed_google_shopping
|
64 |
-
* @method GET
|
65 |
-
* @descripton Get single attribute
|
66 |
-
*
|
67 |
-
* @param $name String
|
68 |
-
*
|
69 |
-
* @param $page Number
|
70 |
-
* @param $per_page Number
|
71 |
-
*/
|
72 |
-
[
|
73 |
-
'methods' => WP_REST_Server::READABLE,
|
74 |
-
'callback' => [ $this, 'get_items' ],
|
75 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
76 |
-
'args' => [
|
77 |
-
'page' => [
|
78 |
-
'description' => __( 'Page number', 'woo-feed' ),
|
79 |
-
'type' => 'number',
|
80 |
-
'required' => false,
|
81 |
-
'sanitize_callback' => 'absint',
|
82 |
-
'validate_callback' => 'rest_validate_request_arg',
|
83 |
-
],
|
84 |
-
'per_page' => [
|
85 |
-
'description' => __( 'Per page', 'woo-feed' ),
|
86 |
-
'type' => 'number',
|
87 |
-
'required' => false,
|
88 |
-
'sanitize_callback' => 'absint',
|
89 |
-
'validate_callback' => 'rest_validate_request_arg',
|
90 |
-
],
|
91 |
-
],
|
92 |
-
],
|
93 |
-
[
|
94 |
-
'methods' => WP_REST_Server::CREATABLE,
|
95 |
-
'callback' => [ $this, 'create_item' ],
|
96 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
97 |
-
'args' => [],
|
98 |
-
],
|
99 |
-
/**
|
100 |
-
* @endpoint wp-json/ctxfeed/v1/wp_options/?name=wf_feed_google_shopping
|
101 |
-
* @method DELETE
|
102 |
-
* @descripton Delete single attribute
|
103 |
-
*
|
104 |
-
* @param $name String
|
105 |
-
*/
|
106 |
-
[
|
107 |
-
'methods' => WP_REST_Server::DELETABLE,
|
108 |
-
'callback' => [ $this, 'delete_item' ],
|
109 |
-
'permission_callback' => [ $this, 'get_item_permissions_check' ],
|
110 |
-
'args' => [],
|
111 |
-
],
|
112 |
-
],
|
113 |
-
);
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* @param $request \WP_REST_Request request body will be []
|
118 |
-
*
|
119 |
-
*
|
120 |
-
* @return \WP_Error|\WP_REST_Response|\WP_HTTP_Response
|
121 |
-
*/
|
122 |
-
public function delete_item( $request ) {
|
123 |
-
$body = $request->get_body();
|
124 |
-
$body = json_decode( $body );
|
125 |
-
$this::set_option();
|
126 |
-
|
127 |
-
foreach ( $body as $option ) {
|
128 |
-
if ( isset( self::$option_lists[ $option ] ) ) {
|
129 |
-
unset( self::$option_lists[ $option ] );
|
130 |
-
}
|
131 |
-
}
|
132 |
-
self::update_option( self::$option_lists );
|
133 |
-
|
134 |
-
return $this->success( self::$option_lists );
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* @param $request
|
139 |
-
*
|
140 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
141 |
-
*/
|
142 |
-
public function create_item( $request ) {
|
143 |
-
$body = $request->get_body();
|
144 |
-
$body = json_decode( $body );
|
145 |
-
$this::set_option();
|
146 |
-
// Save option name.
|
147 |
-
foreach ( $body as $index => $name ) {
|
148 |
-
$option_name = self::$prefix . $name;
|
149 |
-
if ( ! $this->is_prefix_matched( $option_name, self::$prefix ) ) {
|
150 |
-
return $this->error( __( 'Option name prefix: "' . self::$prefix . '" does\'nt match.', 'woo-feed' ) );
|
151 |
-
}
|
152 |
-
self::$option_lists[ $name ] = [
|
153 |
-
'option_id' => $name,
|
154 |
-
'option_name' => $option_name,
|
155 |
-
];
|
156 |
-
}
|
157 |
-
// Get option name.
|
158 |
-
$this::update_option( self::$option_lists );
|
159 |
-
|
160 |
-
return $this->success( self::$option_lists );
|
161 |
-
}
|
162 |
-
|
163 |
-
|
164 |
-
/**
|
165 |
-
*
|
166 |
-
* @param \WP_REST_Request $request Full details about the request.
|
167 |
-
*
|
168 |
-
* @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
|
169 |
-
*/
|
170 |
-
public function get_items( $request ) {
|
171 |
-
$args = $request->get_params();
|
172 |
-
if ( isset( $args['name'] ) ) {
|
173 |
-
return $this->get_item( $request );
|
174 |
-
}
|
175 |
-
$this::set_option();
|
176 |
-
|
177 |
-
$response = rest_ensure_response( $this->response );
|
178 |
-
$response = $this->maybe_add_pagination( $args, $this::$option_lists, $response );
|
179 |
-
|
180 |
-
return $response;
|
181 |
-
}
|
182 |
-
|
183 |
-
/**
|
184 |
-
* @return void
|
185 |
-
*/
|
186 |
-
private static function set_option() {
|
187 |
-
self::$option_lists = get_option( self::$option_name, [] );
|
188 |
-
}
|
189 |
-
|
190 |
-
/**
|
191 |
-
* @param $option_lists
|
192 |
-
*
|
193 |
-
* @return void
|
194 |
-
*/
|
195 |
-
private static function update_option( $option_lists = [] ) {
|
196 |
-
update_option( self::$option_name, $option_lists );
|
197 |
-
self::set_option();
|
198 |
-
}
|
199 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/classes/class-woo-feed-constants.php
CHANGED
@@ -23,7 +23,7 @@ if( ! class_exists("Woo_Feed_Constants") ) {
|
|
23 |
* @var string
|
24 |
* @since 3.1.6
|
25 |
*/
|
26 |
-
define( 'WOO_FEED_FREE_VERSION', '4.5.
|
27 |
}
|
28 |
|
29 |
if ( ! defined( 'WOO_FEED_FREE_PATH' ) ) {
|
23 |
* @var string
|
24 |
* @since 3.1.6
|
25 |
*/
|
26 |
+
define( 'WOO_FEED_FREE_VERSION', '4.5.13' );
|
27 |
}
|
28 |
|
29 |
if ( ! defined( 'WOO_FEED_FREE_PATH' ) ) {
|
includes/helper.php
CHANGED
@@ -5337,8 +5337,12 @@ if ( ! function_exists( 'woo_feed_filter_product_title' ) ) {
|
|
5337 |
)
|
5338 |
) ) {
|
5339 |
if ( strlen( $title ) > 150 ) {
|
5340 |
-
$
|
|
|
|
|
|
|
5341 |
|
|
|
5342 |
}
|
5343 |
}
|
5344 |
|
5337 |
)
|
5338 |
) ) {
|
5339 |
if ( strlen( $title ) > 150 ) {
|
5340 |
+
for ( $I = 149; $title[ $I ] != ' '; $I --
|
5341 |
+
) {
|
5342 |
+
;
|
5343 |
+
}
|
5344 |
|
5345 |
+
$title = substr( $title, 0, $I );
|
5346 |
}
|
5347 |
}
|
5348 |
|
woo-feed.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
* Plugin Name: CTX Feed
|
11 |
* Plugin URI: https://webappick.com/
|
12 |
* Description: Easily generate woocommerce product feed for any marketing channel like Google Shopping(Merchant), Facebook Remarketing, Bing, eBay & more. Support 100+ Merchants.
|
13 |
-
* Version: 4.5.
|
14 |
* Author: WebAppick
|
15 |
* Author URI: https://webappick.com/
|
16 |
* License: GPL v2
|
10 |
* Plugin Name: CTX Feed
|
11 |
* Plugin URI: https://webappick.com/
|
12 |
* Description: Easily generate woocommerce product feed for any marketing channel like Google Shopping(Merchant), Facebook Remarketing, Bing, eBay & more. Support 100+ Merchants.
|
13 |
+
* Version: 4.5.13
|
14 |
* Author: WebAppick
|
15 |
* Author URI: https://webappick.com/
|
16 |
* License: GPL v2
|