PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 1.0.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v1.0.3
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Settings / RegisterSetting.php
RegisterSetting.php
96 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace SureCart\Settings;
3
4 /**
5 * Class to extend settings registration.
6 */
7 abstract class RegisterSetting {
8 /**
9 * Slug for the setting
10 *
11 * @since 1.0
12 * @var string $slug
13 */
14 protected $name;
15
16 /**
17 * Setting REST API Schema
18 *
19 * @var array
20 */
21 protected $schema;
22
23 /**
24 * Register the setting.
25 *
26 * @return void
27 */
28 public function register() {
29 add_filter( 'surecart/rest/settings/schema', [ $this, 'registerSchema' ] );
30 add_filter( 'surecart/rest/settings/index', [ $this, 'index' ], 10, 2 );
31 add_filter( 'surecart/rest/settings/update', [ $this, 'handleUpdate' ] );
32 }
33
34 /**
35 * Get the attribute
36 *
37 * @param string $key Attribute name.
38 *
39 * @return mixed
40 */
41 public function __get( $key ) {
42 return $this->$key;
43 }
44
45 /**
46 * Register the settings schema for REST API requests.
47 *
48 * @param array $schema Schema for requests.
49 *
50 * @return array
51 */
52 public function registerSchema( $schema ) {
53 $schema[ $this->name ] = $this->schema;
54 return $schema;
55 }
56
57 /**
58 * Add our data to the index.
59 *
60 * @param array $settings Array of settings data.
61 *
62 * @return array
63 */
64 public function addToIndex( $settings, $params ) {
65 $settings[ $this->name ] = $this->index( $settings, $params );
66 return $settings;
67 }
68
69 /**
70 * Handle the setting update.
71 *
72 * @param array $settings Array of settings.
73 * @param array $params Array of params.
74 *
75 * @return array
76 */
77 protected function handleUpdate( $settings, $params ) {
78 $settings[ $this->name ] = $this->update( $params );
79 return $settings;
80 }
81
82 /**
83 * What to return when settings are indexed.
84 */
85 public function index( $settings, $params ) {
86 return [];
87 }
88
89 /**
90 * What to return when settings are updated.
91 */
92 public function update() {
93 return [];
94 }
95 }
96