@@ -28,6 +28,86 @@ class Audience_Content_Gates extends Wizard {
2828 */
2929 protected $ parent_slug = 'newspack-audience ' ;
3030
31+ /**
32+ * Gate schema properites.
33+ *
34+ * @var array
35+ */
36+ protected $ gate_properties = [
37+ 'title ' => [ 'type ' => 'string ' ],
38+ 'status ' => [ 'type ' => 'string ' ],
39+ 'metering ' => [
40+ 'type ' => 'object ' ,
41+ 'properties ' => [
42+ 'enabled ' => [ 'type ' => 'boolean ' ],
43+ 'anonymous_count ' => [ 'type ' => 'integer ' ],
44+ 'registered_count ' => [ 'type ' => 'integer ' ],
45+ 'period ' => [ 'type ' => 'string ' ],
46+ ],
47+ ],
48+ 'content_rules ' => [
49+ 'type ' => 'array ' ,
50+ 'items ' => [
51+ 'type ' => 'object ' ,
52+ 'properties ' => [
53+ 'slug ' => [ 'type ' => 'string ' ],
54+ 'value ' => [ 'type ' => [ 'string ' , 'array ' ] ],
55+ 'exclusion ' => [ 'type ' => 'boolean ' ],
56+ ],
57+ ],
58+ ],
59+ 'registration ' => [
60+ 'type ' => 'object ' ,
61+ 'properties ' => [
62+ 'active ' => [ 'type ' => 'boolean ' ],
63+ 'require_verification ' => [ 'type ' => 'boolean ' ],
64+ 'gate_layout_id ' => [
65+ 'type ' => 'integer ' ,
66+ 'required ' => false ,
67+ ],
68+ 'metering ' => [
69+ 'type ' => 'object ' ,
70+ 'properties ' => [
71+ 'enabled ' => [ 'type ' => 'boolean ' ],
72+ 'count ' => [ 'type ' => 'integer ' ],
73+ 'period ' => [ 'type ' => 'string ' ],
74+ ],
75+ ],
76+ ],
77+ ],
78+ 'custom_access ' => [
79+ 'type ' => 'object ' ,
80+ 'properties ' => [
81+ 'active ' => [ 'type ' => 'boolean ' ],
82+ 'metering ' => [
83+ 'type ' => 'object ' ,
84+ 'properties ' => [
85+ 'enabled ' => [ 'type ' => 'boolean ' ],
86+ 'count ' => [ 'type ' => 'integer ' ],
87+ 'period ' => [ 'type ' => 'string ' ],
88+ ],
89+ ],
90+ 'gate_layout_id ' => [
91+ 'type ' => 'integer ' ,
92+ 'required ' => false ,
93+ ],
94+ 'access_rules ' => [
95+ 'type ' => 'array ' ,
96+ 'items ' => [
97+ 'type ' => 'array ' ,
98+ 'items ' => [
99+ 'type ' => 'object ' ,
100+ 'properties ' => [
101+ 'slug ' => [ 'type ' => 'string ' ],
102+ 'value ' => [ 'type ' => [ 'string ' , 'array ' ] ],
103+ ],
104+ ],
105+ ],
106+ ],
107+ ],
108+ ],
109+ ];
110+
31111 /**
32112 * Constructor.
33113 */
@@ -249,80 +329,7 @@ public function register_api_endpoints() {
249329 'gate ' => [
250330 'type ' => 'object ' ,
251331 'sanitize_callback ' => [ $ this , 'sanitize_gate ' ],
252- 'properties ' => [
253- 'title ' => [ 'type ' => 'string ' ],
254- 'status ' => [ 'type ' => 'string ' ],
255- 'metering ' => [
256- 'type ' => 'object ' ,
257- 'properties ' => [
258- 'enabled ' => [ 'type ' => 'boolean ' ],
259- 'anonymous_count ' => [ 'type ' => 'integer ' ],
260- 'registered_count ' => [ 'type ' => 'integer ' ],
261- 'period ' => [ 'type ' => 'string ' ],
262- ],
263- ],
264- 'content_rules ' => [
265- 'type ' => 'array ' ,
266- 'items ' => [
267- 'type ' => 'object ' ,
268- 'properties ' => [
269- 'slug ' => [ 'type ' => 'string ' ],
270- 'value ' => [ 'type ' => [ 'string ' , 'array ' ] ],
271- 'exclusion ' => [ 'type ' => 'boolean ' ],
272- ],
273- ],
274- ],
275- 'registration ' => [
276- 'type ' => 'object ' ,
277- 'properties ' => [
278- 'active ' => [ 'type ' => 'boolean ' ],
279- 'require_verification ' => [ 'type ' => 'boolean ' ],
280- 'gate_layout_id ' => [
281- 'type ' => 'integer ' ,
282- 'required ' => false ,
283- ],
284- 'metering ' => [
285- 'type ' => 'object ' ,
286- 'properties ' => [
287- 'enabled ' => [ 'type ' => 'boolean ' ],
288- 'count ' => [ 'type ' => 'integer ' ],
289- 'period ' => [ 'type ' => 'string ' ],
290- ],
291- ],
292- ],
293- ],
294- 'custom_access ' => [
295- 'type ' => 'object ' ,
296- 'properties ' => [
297- 'active ' => [ 'type ' => 'boolean ' ],
298- 'metering ' => [
299- 'type ' => 'object ' ,
300- 'properties ' => [
301- 'enabled ' => [ 'type ' => 'boolean ' ],
302- 'count ' => [ 'type ' => 'integer ' ],
303- 'period ' => [ 'type ' => 'string ' ],
304- ],
305- ],
306- 'gate_layout_id ' => [
307- 'type ' => 'integer ' ,
308- 'required ' => false ,
309- ],
310- 'access_rules ' => [
311- 'type ' => 'array ' ,
312- 'items ' => [
313- 'type ' => 'array ' ,
314- 'items ' => [
315- 'type ' => 'object ' ,
316- 'properties ' => [
317- 'slug ' => [ 'type ' => 'string ' ],
318- 'value ' => [ 'type ' => [ 'string ' , 'array ' ] ],
319- ],
320- ],
321- ],
322- ],
323- ],
324- ],
325- ],
332+ 'properties ' => $ this ->gate_properties ,
326333 ],
327334 ],
328335 'permission_callback ' => [ $ this , 'api_permissions_check ' ],
@@ -378,80 +385,7 @@ public function register_api_endpoints() {
378385 'gate ' => [
379386 'type ' => 'object ' ,
380387 'sanitize_callback ' => [ $ this , 'sanitize_gate ' ],
381- 'properties ' => [
382- 'title ' => [ 'type ' => 'string ' ],
383- 'status ' => [ 'type ' => 'string ' ],
384- 'metering ' => [
385- 'type ' => 'object ' ,
386- 'properties ' => [
387- 'enabled ' => [ 'type ' => 'boolean ' ],
388- 'anonymous_count ' => [ 'type ' => 'integer ' ],
389- 'registered_count ' => [ 'type ' => 'integer ' ],
390- 'period ' => [ 'type ' => 'string ' ],
391- ],
392- ],
393- 'content_rules ' => [
394- 'type ' => 'array ' ,
395- 'items ' => [
396- 'type ' => 'object ' ,
397- 'properties ' => [
398- 'slug ' => [ 'type ' => 'string ' ],
399- 'value ' => [ 'type ' => [ 'string ' , 'array ' ] ],
400- 'exclusion ' => [ 'type ' => 'boolean ' ],
401- ],
402- ],
403- ],
404- 'registration ' => [
405- 'type ' => 'object ' ,
406- 'properties ' => [
407- 'active ' => [ 'type ' => 'boolean ' ],
408- 'require_verification ' => [ 'type ' => 'boolean ' ],
409- 'gate_layout_id ' => [
410- 'type ' => 'integer ' ,
411- 'required ' => false ,
412- ],
413- 'metering ' => [
414- 'type ' => 'object ' ,
415- 'properties ' => [
416- 'enabled ' => [ 'type ' => 'boolean ' ],
417- 'count ' => [ 'type ' => 'integer ' ],
418- 'period ' => [ 'type ' => 'string ' ],
419- ],
420- ],
421- ],
422- ],
423- 'custom_access ' => [
424- 'type ' => 'object ' ,
425- 'properties ' => [
426- 'active ' => [ 'type ' => 'boolean ' ],
427- 'metering ' => [
428- 'type ' => 'object ' ,
429- 'properties ' => [
430- 'enabled ' => [ 'type ' => 'boolean ' ],
431- 'count ' => [ 'type ' => 'integer ' ],
432- 'period ' => [ 'type ' => 'string ' ],
433- ],
434- ],
435- 'gate_layout_id ' => [
436- 'type ' => 'integer ' ,
437- 'required ' => false ,
438- ],
439- 'access_rules ' => [
440- 'type ' => 'array ' ,
441- 'items ' => [
442- 'type ' => 'array ' ,
443- 'items ' => [
444- 'type ' => 'object ' ,
445- 'properties ' => [
446- 'slug ' => [ 'type ' => 'string ' ],
447- 'value ' => [ 'type ' => [ 'string ' , 'array ' ] ],
448- ],
449- ],
450- ],
451- ],
452- ],
453- ],
454- ],
388+ 'properties ' => $ this ->gate_properties ,
455389 ],
456390 ],
457391 ]
0 commit comments