@@ -17,26 +17,26 @@ |
||
17 | 17 | */ |
18 | 18 | class Meta_Data_Source implements Abstract_Data_Source { |
19 | 19 | |
20 | - /** |
|
21 | - * @param int $identifier Post id or term id |
|
22 | - * @param $property |
|
23 | - * @param $type |
|
24 | - * |
|
25 | - * @return array |
|
26 | - */ |
|
27 | - public function get_data( $identifier, $property, $type ) { |
|
28 | - |
|
29 | - $value = $property['field_name']; |
|
30 | - |
|
31 | - if ( Jsonld_Converter::TERM === $type ) { |
|
32 | - $meta = get_term_meta( $identifier, $value ); |
|
33 | - } else { |
|
34 | - $meta = get_post_meta( $identifier, $value ); |
|
35 | - } |
|
36 | - $values = ( 1 === count( $meta ) && is_array( $meta[0] ) ) |
|
37 | - ? $meta[0] : $meta; |
|
38 | - |
|
39 | - return array_map( 'wp_strip_all_tags', $values ); |
|
40 | - |
|
41 | - } |
|
20 | + /** |
|
21 | + * @param int $identifier Post id or term id |
|
22 | + * @param $property |
|
23 | + * @param $type |
|
24 | + * |
|
25 | + * @return array |
|
26 | + */ |
|
27 | + public function get_data( $identifier, $property, $type ) { |
|
28 | + |
|
29 | + $value = $property['field_name']; |
|
30 | + |
|
31 | + if ( Jsonld_Converter::TERM === $type ) { |
|
32 | + $meta = get_term_meta( $identifier, $value ); |
|
33 | + } else { |
|
34 | + $meta = get_post_meta( $identifier, $value ); |
|
35 | + } |
|
36 | + $values = ( 1 === count( $meta ) && is_array( $meta[0] ) ) |
|
37 | + ? $meta[0] : $meta; |
|
38 | + |
|
39 | + return array_map( 'wp_strip_all_tags', $values ); |
|
40 | + |
|
41 | + } |
|
42 | 42 | } |
@@ -24,19 +24,19 @@ |
||
24 | 24 | * |
25 | 25 | * @return array |
26 | 26 | */ |
27 | - public function get_data( $identifier, $property, $type ) { |
|
27 | + public function get_data($identifier, $property, $type) { |
|
28 | 28 | |
29 | 29 | $value = $property['field_name']; |
30 | 30 | |
31 | - if ( Jsonld_Converter::TERM === $type ) { |
|
32 | - $meta = get_term_meta( $identifier, $value ); |
|
31 | + if (Jsonld_Converter::TERM === $type) { |
|
32 | + $meta = get_term_meta($identifier, $value); |
|
33 | 33 | } else { |
34 | - $meta = get_post_meta( $identifier, $value ); |
|
34 | + $meta = get_post_meta($identifier, $value); |
|
35 | 35 | } |
36 | - $values = ( 1 === count( $meta ) && is_array( $meta[0] ) ) |
|
36 | + $values = (1 === count($meta) && is_array($meta[0])) |
|
37 | 37 | ? $meta[0] : $meta; |
38 | 38 | |
39 | - return array_map( 'wp_strip_all_tags', $values ); |
|
39 | + return array_map('wp_strip_all_tags', $values); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | } |
@@ -15,85 +15,85 @@ |
||
15 | 15 | */ |
16 | 16 | class Acf_Mappings { |
17 | 17 | |
18 | - /** |
|
19 | - * Acf_Mappings constructor. |
|
20 | - * |
|
21 | - * Hooks `wl_mappings_field_types` to our own function to declare support for ACF fields. |
|
22 | - */ |
|
23 | - public function __construct() { |
|
24 | - |
|
25 | - $that = $this; |
|
26 | - add_action( |
|
27 | - 'plugins_loaded', |
|
28 | - function () use ( $that ) { |
|
29 | - $that->add_acf_option_to_mappings_ui(); |
|
30 | - } |
|
31 | - ); |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - private function add_acf_option_to_mappings_ui() { |
|
36 | - // Bail out if ACF is not available. |
|
37 | - if ( ! function_exists( 'acf_get_field_groups' ) ) { |
|
38 | - return array(); |
|
39 | - } |
|
40 | - |
|
41 | - add_filter( 'wl_mappings_field_types', array( $this, 'wl_mappings_field_types' ) ); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Hook to `wl_mappings_field_types` to declare support for ACF fields. |
|
46 | - * |
|
47 | - * @param array $field_types An array of field types. |
|
48 | - * |
|
49 | - * @return array The array with our ACF declaration. |
|
50 | - */ |
|
51 | - public function wl_mappings_field_types( $field_types ) { |
|
52 | - |
|
53 | - $field_types[] = array( |
|
54 | - 'field_type' => 'acf', |
|
55 | - 'label' => __( 'ACF', 'wordlift' ), |
|
56 | - 'value' => self::get_acf_options(), |
|
57 | - ); |
|
58 | - |
|
59 | - return $field_types; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Returns array of acf options. |
|
64 | - * |
|
65 | - * The array is composed by all the ACF groups and their fields hierarchy. |
|
66 | - * |
|
67 | - * @return array ACF options array. |
|
68 | - */ |
|
69 | - private static function get_acf_options() { |
|
70 | - |
|
71 | - $acf_options = array(); |
|
72 | - |
|
73 | - // Get all the ACF field groups. |
|
74 | - $field_groups = acf_get_field_groups(); |
|
75 | - |
|
76 | - foreach ( $field_groups as $field_group ) { |
|
77 | - $group_name = $field_group['title']; |
|
78 | - $group_key = $field_group['key']; |
|
79 | - |
|
80 | - $group_fields = acf_get_fields( $group_key ); |
|
81 | - |
|
82 | - $group_options = array(); |
|
83 | - foreach ( $group_fields as $group_field ) { |
|
84 | - $group_options[] = array( |
|
85 | - 'label' => $group_field['label'], |
|
86 | - 'value' => $group_field['key'], |
|
87 | - ); |
|
88 | - } |
|
89 | - |
|
90 | - $acf_options[] = array( |
|
91 | - 'group_name' => $group_name, |
|
92 | - 'group_options' => $group_options, |
|
93 | - ); |
|
94 | - } |
|
95 | - |
|
96 | - return $acf_options; |
|
97 | - } |
|
18 | + /** |
|
19 | + * Acf_Mappings constructor. |
|
20 | + * |
|
21 | + * Hooks `wl_mappings_field_types` to our own function to declare support for ACF fields. |
|
22 | + */ |
|
23 | + public function __construct() { |
|
24 | + |
|
25 | + $that = $this; |
|
26 | + add_action( |
|
27 | + 'plugins_loaded', |
|
28 | + function () use ( $that ) { |
|
29 | + $that->add_acf_option_to_mappings_ui(); |
|
30 | + } |
|
31 | + ); |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + private function add_acf_option_to_mappings_ui() { |
|
36 | + // Bail out if ACF is not available. |
|
37 | + if ( ! function_exists( 'acf_get_field_groups' ) ) { |
|
38 | + return array(); |
|
39 | + } |
|
40 | + |
|
41 | + add_filter( 'wl_mappings_field_types', array( $this, 'wl_mappings_field_types' ) ); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Hook to `wl_mappings_field_types` to declare support for ACF fields. |
|
46 | + * |
|
47 | + * @param array $field_types An array of field types. |
|
48 | + * |
|
49 | + * @return array The array with our ACF declaration. |
|
50 | + */ |
|
51 | + public function wl_mappings_field_types( $field_types ) { |
|
52 | + |
|
53 | + $field_types[] = array( |
|
54 | + 'field_type' => 'acf', |
|
55 | + 'label' => __( 'ACF', 'wordlift' ), |
|
56 | + 'value' => self::get_acf_options(), |
|
57 | + ); |
|
58 | + |
|
59 | + return $field_types; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Returns array of acf options. |
|
64 | + * |
|
65 | + * The array is composed by all the ACF groups and their fields hierarchy. |
|
66 | + * |
|
67 | + * @return array ACF options array. |
|
68 | + */ |
|
69 | + private static function get_acf_options() { |
|
70 | + |
|
71 | + $acf_options = array(); |
|
72 | + |
|
73 | + // Get all the ACF field groups. |
|
74 | + $field_groups = acf_get_field_groups(); |
|
75 | + |
|
76 | + foreach ( $field_groups as $field_group ) { |
|
77 | + $group_name = $field_group['title']; |
|
78 | + $group_key = $field_group['key']; |
|
79 | + |
|
80 | + $group_fields = acf_get_fields( $group_key ); |
|
81 | + |
|
82 | + $group_options = array(); |
|
83 | + foreach ( $group_fields as $group_field ) { |
|
84 | + $group_options[] = array( |
|
85 | + 'label' => $group_field['label'], |
|
86 | + 'value' => $group_field['key'], |
|
87 | + ); |
|
88 | + } |
|
89 | + |
|
90 | + $acf_options[] = array( |
|
91 | + 'group_name' => $group_name, |
|
92 | + 'group_options' => $group_options, |
|
93 | + ); |
|
94 | + } |
|
95 | + |
|
96 | + return $acf_options; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | $that = $this; |
26 | 26 | add_action( |
27 | 27 | 'plugins_loaded', |
28 | - function () use ( $that ) { |
|
28 | + function() use ($that) { |
|
29 | 29 | $that->add_acf_option_to_mappings_ui(); |
30 | 30 | } |
31 | 31 | ); |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | |
35 | 35 | private function add_acf_option_to_mappings_ui() { |
36 | 36 | // Bail out if ACF is not available. |
37 | - if ( ! function_exists( 'acf_get_field_groups' ) ) { |
|
37 | + if ( ! function_exists('acf_get_field_groups')) { |
|
38 | 38 | return array(); |
39 | 39 | } |
40 | 40 | |
41 | - add_filter( 'wl_mappings_field_types', array( $this, 'wl_mappings_field_types' ) ); |
|
41 | + add_filter('wl_mappings_field_types', array($this, 'wl_mappings_field_types')); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return array The array with our ACF declaration. |
50 | 50 | */ |
51 | - public function wl_mappings_field_types( $field_types ) { |
|
51 | + public function wl_mappings_field_types($field_types) { |
|
52 | 52 | |
53 | 53 | $field_types[] = array( |
54 | 54 | 'field_type' => 'acf', |
55 | - 'label' => __( 'ACF', 'wordlift' ), |
|
55 | + 'label' => __('ACF', 'wordlift'), |
|
56 | 56 | 'value' => self::get_acf_options(), |
57 | 57 | ); |
58 | 58 | |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | // Get all the ACF field groups. |
74 | 74 | $field_groups = acf_get_field_groups(); |
75 | 75 | |
76 | - foreach ( $field_groups as $field_group ) { |
|
76 | + foreach ($field_groups as $field_group) { |
|
77 | 77 | $group_name = $field_group['title']; |
78 | 78 | $group_key = $field_group['key']; |
79 | 79 | |
80 | - $group_fields = acf_get_fields( $group_key ); |
|
80 | + $group_fields = acf_get_fields($group_key); |
|
81 | 81 | |
82 | 82 | $group_options = array(); |
83 | - foreach ( $group_fields as $group_field ) { |
|
83 | + foreach ($group_fields as $group_field) { |
|
84 | 84 | $group_options[] = array( |
85 | 85 | 'label' => $group_field['label'], |
86 | 86 | 'value' => $group_field['key'], |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return array List of property items belong to $mapping_id. |
68 | 68 | */ |
69 | - public function get_properties( $mapping_id ) { |
|
69 | + public function get_properties($mapping_id) { |
|
70 | 70 | global $wpdb; |
71 | 71 | $property_rows = $wpdb->get_results( |
72 | - $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wl_mapping_property WHERE mapping_id=%d", $mapping_id ), |
|
72 | + $wpdb->prepare("SELECT * FROM {$wpdb->prefix}wl_mapping_property WHERE mapping_id=%d", $mapping_id), |
|
73 | 73 | ARRAY_A |
74 | 74 | ); |
75 | 75 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return bool Returns true if the row exists, false if it does not |
87 | 87 | */ |
88 | - private function check_if_row_exists( $table_name, $primary_key_name, $primary_key_value ) { |
|
88 | + private function check_if_row_exists($table_name, $primary_key_name, $primary_key_value) { |
|
89 | 89 | global $wpdb; |
90 | 90 | $primary_key_value = (int) $primary_key_value; |
91 | 91 | $count = (int) $this->wpdb->get_var( |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return int Id of the inserted mapping item. |
110 | 110 | */ |
111 | - public function insert_mapping_item( $title ) { |
|
112 | - $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME; |
|
111 | + public function insert_mapping_item($title) { |
|
112 | + $mapping_table_name = $this->wpdb->prefix.WL_MAPPING_TABLE_NAME; |
|
113 | 113 | $this->wpdb->insert( |
114 | 114 | $mapping_table_name, |
115 | - array( 'mapping_title' => $title ) |
|
115 | + array('mapping_title' => $title) |
|
116 | 116 | ); |
117 | 117 | |
118 | 118 | return $this->wpdb->insert_id; |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return int Id of the inserted mapping item |
127 | 127 | */ |
128 | - public function insert_or_update_mapping_item( $mapping_data ) { |
|
129 | - $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME; |
|
130 | - $mapping_id = array_key_exists( 'mapping_id', $mapping_data ) ? (int) $mapping_data['mapping_id'] : null; |
|
131 | - if ( $this->check_if_row_exists( $mapping_table_name, 'mapping_id', $mapping_data['mapping_id'] ) ) { |
|
128 | + public function insert_or_update_mapping_item($mapping_data) { |
|
129 | + $mapping_table_name = $this->wpdb->prefix.WL_MAPPING_TABLE_NAME; |
|
130 | + $mapping_id = array_key_exists('mapping_id', $mapping_data) ? (int) $mapping_data['mapping_id'] : null; |
|
131 | + if ($this->check_if_row_exists($mapping_table_name, 'mapping_id', $mapping_data['mapping_id'])) { |
|
132 | 132 | $this->wpdb->update( |
133 | 133 | $mapping_table_name, |
134 | 134 | $mapping_data, |
135 | - array( 'mapping_id' => $mapping_id ) |
|
135 | + array('mapping_id' => $mapping_id) |
|
136 | 136 | ); |
137 | 137 | } else { |
138 | 138 | $this->wpdb->insert( |
@@ -152,13 +152,13 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return int $rule_id The inserted rule id. |
154 | 154 | */ |
155 | - public function insert_or_update_rule_item( $rule_item_data ) { |
|
156 | - $rule_table_name = $this->wpdb->prefix . WL_RULE_TABLE_NAME; |
|
157 | - $rule_id = array_key_exists( 'rule_id', $rule_item_data ) ? $rule_item_data['rule_id'] : null; |
|
158 | - if ( $this->check_if_row_exists( $rule_table_name, 'rule_id', $rule_id ) ) { |
|
159 | - $this->wpdb->update( $rule_table_name, $rule_item_data, array( 'rule_id' => $rule_id ) ); |
|
155 | + public function insert_or_update_rule_item($rule_item_data) { |
|
156 | + $rule_table_name = $this->wpdb->prefix.WL_RULE_TABLE_NAME; |
|
157 | + $rule_id = array_key_exists('rule_id', $rule_item_data) ? $rule_item_data['rule_id'] : null; |
|
158 | + if ($this->check_if_row_exists($rule_table_name, 'rule_id', $rule_id)) { |
|
159 | + $this->wpdb->update($rule_table_name, $rule_item_data, array('rule_id' => $rule_id)); |
|
160 | 160 | } else { |
161 | - $this->wpdb->insert( $rule_table_name, $rule_item_data ); |
|
161 | + $this->wpdb->insert($rule_table_name, $rule_item_data); |
|
162 | 162 | $rule_id = $this->wpdb->insert_id; |
163 | 163 | } |
164 | 164 | |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return int The inserted rule group id. |
175 | 175 | */ |
176 | - public function insert_rule_group( $mapping_id ) { |
|
177 | - $rule_group_table_name = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME; |
|
176 | + public function insert_rule_group($mapping_id) { |
|
177 | + $rule_group_table_name = $this->wpdb->prefix.WL_RULE_GROUP_TABLE_NAME; |
|
178 | 178 | $this->wpdb->insert( |
179 | 179 | $rule_group_table_name, |
180 | 180 | array( |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | * |
193 | 193 | * @return void |
194 | 194 | */ |
195 | - public function delete_rule_item( $rule_id ) { |
|
196 | - $rule_table_name = $this->wpdb->prefix . WL_RULE_TABLE_NAME; |
|
197 | - $this->wpdb->delete( $rule_table_name, array( 'rule_id' => $rule_id ) ); |
|
195 | + public function delete_rule_item($rule_id) { |
|
196 | + $rule_table_name = $this->wpdb->prefix.WL_RULE_TABLE_NAME; |
|
197 | + $this->wpdb->delete($rule_table_name, array('rule_id' => $rule_id)); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @return void |
206 | 206 | */ |
207 | - public function delete_rule_group_item( $rule_group_id ) { |
|
208 | - $rule_group_table_name = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME; |
|
209 | - $this->wpdb->delete( $rule_group_table_name, array( 'rule_group_id' => $rule_group_id ) ); |
|
207 | + public function delete_rule_group_item($rule_group_id) { |
|
208 | + $rule_group_table_name = $this->wpdb->prefix.WL_RULE_GROUP_TABLE_NAME; |
|
209 | + $this->wpdb->delete($rule_group_table_name, array('rule_group_id' => $rule_group_id)); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @return void |
218 | 218 | */ |
219 | - public function delete_mapping_item( $mapping_id ) { |
|
220 | - $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME; |
|
221 | - $this->wpdb->delete( $mapping_table_name, array( 'mapping_id' => $mapping_id ) ); |
|
219 | + public function delete_mapping_item($mapping_id) { |
|
220 | + $mapping_table_name = $this->wpdb->prefix.WL_MAPPING_TABLE_NAME; |
|
221 | + $this->wpdb->delete($mapping_table_name, array('mapping_id' => $mapping_id)); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @return array Get list of rule group items. |
230 | 230 | */ |
231 | - public function get_rule_group_list( $mapping_id ) { |
|
231 | + public function get_rule_group_list($mapping_id) { |
|
232 | 232 | global $wpdb; |
233 | 233 | return $wpdb->get_results( |
234 | 234 | $wpdb->prepare( |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * |
247 | 247 | * @return array Get list of rule group items. |
248 | 248 | */ |
249 | - public function get_rule_groups_by_mapping( $mapping_id ) { |
|
249 | + public function get_rule_groups_by_mapping($mapping_id) { |
|
250 | 250 | global $wpdb; |
251 | 251 | $rule_group_rows = $wpdb->get_results( |
252 | 252 | $wpdb->prepare( |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | |
259 | 259 | // List of all rule group items. |
260 | 260 | $rule_groups = array(); |
261 | - foreach ( $rule_group_rows as $rule_group_row ) { |
|
261 | + foreach ($rule_group_rows as $rule_group_row) { |
|
262 | 262 | $rule_groups[] = array( |
263 | 263 | 'rule_group_id' => $rule_group_row['rule_group_id'], |
264 | - 'rules' => $this->get_rules_by_rule_group( $rule_group_row['rule_group_id'] ), |
|
264 | + 'rules' => $this->get_rules_by_rule_group($rule_group_row['rule_group_id']), |
|
265 | 265 | ); |
266 | 266 | } |
267 | 267 | |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * |
276 | 276 | * @return array Get list of rule items. |
277 | 277 | */ |
278 | - public function get_rules_by_rule_group( $rule_group_id ) { |
|
278 | + public function get_rules_by_rule_group($rule_group_id) { |
|
279 | 279 | global $wpdb; |
280 | 280 | return $wpdb->get_results( |
281 | 281 | $wpdb->prepare( |
@@ -293,18 +293,18 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @return int Inserted Property Id. |
295 | 295 | */ |
296 | - public function insert_or_update_property( $property_data ) { |
|
297 | - $property_table_name = $this->wpdb->prefix . WL_PROPERTY_TABLE_NAME; |
|
298 | - $property_id = array_key_exists( 'property_id', $property_data ) ? $property_data['property_id'] : null; |
|
296 | + public function insert_or_update_property($property_data) { |
|
297 | + $property_table_name = $this->wpdb->prefix.WL_PROPERTY_TABLE_NAME; |
|
298 | + $property_id = array_key_exists('property_id', $property_data) ? $property_data['property_id'] : null; |
|
299 | 299 | |
300 | - if ( $this->check_if_row_exists( $property_table_name, 'property_id', $property_id ) ) { |
|
300 | + if ($this->check_if_row_exists($property_table_name, 'property_id', $property_id)) { |
|
301 | 301 | $this->wpdb->update( |
302 | 302 | $property_table_name, |
303 | 303 | $property_data, |
304 | - array( 'property_id' => $property_id ) |
|
304 | + array('property_id' => $property_id) |
|
305 | 305 | ); |
306 | 306 | } else { |
307 | - $this->wpdb->insert( $property_table_name, $property_data ); |
|
307 | + $this->wpdb->insert($property_table_name, $property_data); |
|
308 | 308 | $property_id = $this->wpdb->insert_id; |
309 | 309 | } |
310 | 310 | |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | * |
319 | 319 | * @return array Returns single mapping table row.. |
320 | 320 | */ |
321 | - public function get_mapping_item_data( $mapping_id ) { |
|
321 | + public function get_mapping_item_data($mapping_id) { |
|
322 | 322 | global $wpdb; |
323 | 323 | return $wpdb->get_row( |
324 | 324 | $wpdb->prepare( |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @return int|false The number of rows updated, or false on error. |
338 | 338 | */ |
339 | - public function delete_property( $property_id ) { |
|
340 | - $property_table_name = $this->wpdb->prefix . WL_PROPERTY_TABLE_NAME; |
|
339 | + public function delete_property($property_id) { |
|
340 | + $property_table_name = $this->wpdb->prefix.WL_PROPERTY_TABLE_NAME; |
|
341 | 341 | |
342 | - return $this->wpdb->delete( $property_table_name, array( 'property_id' => $property_id ) ); |
|
342 | + return $this->wpdb->delete($property_table_name, array('property_id' => $property_id)); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | } |
@@ -12,334 +12,334 @@ |
||
12 | 12 | */ |
13 | 13 | final class Mappings_DBO { |
14 | 14 | |
15 | - /** |
|
16 | - * The {@link wpdb} instance. |
|
17 | - * |
|
18 | - * @since 3.25.0 |
|
19 | - * @access private |
|
20 | - * @var \wpdb $wpdb The {@link wpdb} instance. |
|
21 | - */ |
|
22 | - private $wpdb = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * Construct DBO object. |
|
26 | - */ |
|
27 | - public function __construct() { |
|
28 | - global $wpdb; |
|
29 | - $this->wpdb = $wpdb; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Returns an array of mappings. |
|
34 | - * |
|
35 | - * Each mapping contains one or more rule groups which in turn contain one or more rules. |
|
36 | - * |
|
37 | - * @return array An array of mappings. |
|
38 | - */ |
|
39 | - public function get_mappings() { |
|
40 | - global $wpdb; |
|
41 | - return $this->wpdb->get_results( |
|
42 | - "SELECT * FROM {$wpdb->prefix}wl_mapping", |
|
43 | - ARRAY_A |
|
44 | - ); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Returns an array of active mappings. |
|
49 | - * |
|
50 | - * Each mapping contains one or more rule groups which in turn contain one or more rules. |
|
51 | - * |
|
52 | - * @return array An array of mappings. |
|
53 | - */ |
|
54 | - public function get_active_mappings() { |
|
55 | - global $wpdb; |
|
56 | - return $this->wpdb->get_results( |
|
57 | - "SELECT * FROM {$wpdb->prefix}wl_mapping WHERE mapping_status = 'active'", |
|
58 | - ARRAY_A |
|
59 | - ); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Returns a list of property rows |
|
64 | - * |
|
65 | - * @param int $mapping_id Primary key of mapping table. |
|
66 | - * |
|
67 | - * @return array List of property items belong to $mapping_id. |
|
68 | - */ |
|
69 | - public function get_properties( $mapping_id ) { |
|
70 | - global $wpdb; |
|
71 | - $property_rows = $wpdb->get_results( |
|
72 | - $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wl_mapping_property WHERE mapping_id=%d", $mapping_id ), |
|
73 | - ARRAY_A |
|
74 | - ); |
|
75 | - |
|
76 | - return $property_rows; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Check if the row exists in the table |
|
81 | - * |
|
82 | - * @param string $table_name The table name you want to query, completely escaped value. |
|
83 | - * @param string $primary_key_name The primary key you want to query, should be escaped before passing. |
|
84 | - * @param int $primary_key_value The primary key value, no need to escape. |
|
85 | - * |
|
86 | - * @return bool Returns true if the row exists, false if it does not |
|
87 | - */ |
|
88 | - private function check_if_row_exists( $table_name, $primary_key_name, $primary_key_value ) { |
|
89 | - global $wpdb; |
|
90 | - $primary_key_value = (int) $primary_key_value; |
|
91 | - $count = (int) $this->wpdb->get_var( |
|
92 | - $wpdb->prepare( |
|
93 | - 'SELECT COUNT(%1s) from %2s where %3s = %4d', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder |
|
94 | - $primary_key_name, |
|
95 | - $table_name, |
|
96 | - $primary_key_name, |
|
97 | - $primary_key_value |
|
98 | - ) |
|
99 | - ); |
|
100 | - |
|
101 | - return $count > 0; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Insert new mapping item with title |
|
106 | - * |
|
107 | - * @param string $title Title of the mapping item. |
|
108 | - * |
|
109 | - * @return int Id of the inserted mapping item. |
|
110 | - */ |
|
111 | - public function insert_mapping_item( $title ) { |
|
112 | - $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME; |
|
113 | - $this->wpdb->insert( |
|
114 | - $mapping_table_name, |
|
115 | - array( 'mapping_title' => $title ) |
|
116 | - ); |
|
117 | - |
|
118 | - return $this->wpdb->insert_id; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Update mapping item with new title |
|
123 | - * |
|
124 | - * @param array $mapping_data Array of the mapping data. |
|
125 | - * |
|
126 | - * @return int Id of the inserted mapping item |
|
127 | - */ |
|
128 | - public function insert_or_update_mapping_item( $mapping_data ) { |
|
129 | - $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME; |
|
130 | - $mapping_id = array_key_exists( 'mapping_id', $mapping_data ) ? (int) $mapping_data['mapping_id'] : null; |
|
131 | - if ( $this->check_if_row_exists( $mapping_table_name, 'mapping_id', $mapping_data['mapping_id'] ) ) { |
|
132 | - $this->wpdb->update( |
|
133 | - $mapping_table_name, |
|
134 | - $mapping_data, |
|
135 | - array( 'mapping_id' => $mapping_id ) |
|
136 | - ); |
|
137 | - } else { |
|
138 | - $this->wpdb->insert( |
|
139 | - $mapping_table_name, |
|
140 | - $mapping_data |
|
141 | - ); |
|
142 | - $mapping_id = (int) $this->wpdb->insert_id; |
|
143 | - } |
|
144 | - |
|
145 | - return $mapping_id; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Updates rule item. |
|
150 | - * |
|
151 | - * @param array $rule_item_data The rule_item_data, should contain rule_id. |
|
152 | - * |
|
153 | - * @return int $rule_id The inserted rule id. |
|
154 | - */ |
|
155 | - public function insert_or_update_rule_item( $rule_item_data ) { |
|
156 | - $rule_table_name = $this->wpdb->prefix . WL_RULE_TABLE_NAME; |
|
157 | - $rule_id = array_key_exists( 'rule_id', $rule_item_data ) ? $rule_item_data['rule_id'] : null; |
|
158 | - if ( $this->check_if_row_exists( $rule_table_name, 'rule_id', $rule_id ) ) { |
|
159 | - $this->wpdb->update( $rule_table_name, $rule_item_data, array( 'rule_id' => $rule_id ) ); |
|
160 | - } else { |
|
161 | - $this->wpdb->insert( $rule_table_name, $rule_item_data ); |
|
162 | - $rule_id = $this->wpdb->insert_id; |
|
163 | - } |
|
164 | - |
|
165 | - return $rule_id; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * If a rule group exists doesn't do anything, but if rule group |
|
170 | - * didn't exist then it inserts a new entry. |
|
171 | - * |
|
172 | - * @param int $mapping_id Primary key for mapping table. |
|
173 | - * |
|
174 | - * @return int The inserted rule group id. |
|
175 | - */ |
|
176 | - public function insert_rule_group( $mapping_id ) { |
|
177 | - $rule_group_table_name = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME; |
|
178 | - $this->wpdb->insert( |
|
179 | - $rule_group_table_name, |
|
180 | - array( |
|
181 | - 'mapping_id' => $mapping_id, |
|
182 | - ) |
|
183 | - ); |
|
184 | - |
|
185 | - return $this->wpdb->insert_id; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Deletes a rule item by rule_id from rule and rule group table. |
|
190 | - * |
|
191 | - * @param int $rule_id Primary key for rule table. |
|
192 | - * |
|
193 | - * @return void |
|
194 | - */ |
|
195 | - public function delete_rule_item( $rule_id ) { |
|
196 | - $rule_table_name = $this->wpdb->prefix . WL_RULE_TABLE_NAME; |
|
197 | - $this->wpdb->delete( $rule_table_name, array( 'rule_id' => $rule_id ) ); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Deletes a rule group item by rule_group_id from rule group table. |
|
202 | - * |
|
203 | - * @param int $rule_group_id Primary key for rule table. |
|
204 | - * |
|
205 | - * @return void |
|
206 | - */ |
|
207 | - public function delete_rule_group_item( $rule_group_id ) { |
|
208 | - $rule_group_table_name = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME; |
|
209 | - $this->wpdb->delete( $rule_group_table_name, array( 'rule_group_id' => $rule_group_id ) ); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Deletes a mapping item by mapping_id |
|
214 | - * |
|
215 | - * @param int $mapping_id Primary key for mapping table. |
|
216 | - * |
|
217 | - * @return void |
|
218 | - */ |
|
219 | - public function delete_mapping_item( $mapping_id ) { |
|
220 | - $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME; |
|
221 | - $this->wpdb->delete( $mapping_table_name, array( 'mapping_id' => $mapping_id ) ); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Gets a list of rule group items. |
|
226 | - * |
|
227 | - * @param int $mapping_id Primary key for mapping table. |
|
228 | - * |
|
229 | - * @return array Get list of rule group items. |
|
230 | - */ |
|
231 | - public function get_rule_group_list( $mapping_id ) { |
|
232 | - global $wpdb; |
|
233 | - return $wpdb->get_results( |
|
234 | - $wpdb->prepare( |
|
235 | - "SELECT rule_group_id FROM {$wpdb->prefix}wl_mapping_rule_group WHERE mapping_id=%d", |
|
236 | - $mapping_id |
|
237 | - ), |
|
238 | - ARRAY_A |
|
239 | - ); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Gets a list of rule group items. |
|
244 | - * |
|
245 | - * @param int $mapping_id Primary key for mapping table. |
|
246 | - * |
|
247 | - * @return array Get list of rule group items. |
|
248 | - */ |
|
249 | - public function get_rule_groups_by_mapping( $mapping_id ) { |
|
250 | - global $wpdb; |
|
251 | - $rule_group_rows = $wpdb->get_results( |
|
252 | - $wpdb->prepare( |
|
253 | - "SELECT rule_group_id FROM {$wpdb->prefix}wl_mapping_rule_group WHERE mapping_id=%d", |
|
254 | - $mapping_id |
|
255 | - ), |
|
256 | - ARRAY_A |
|
257 | - ); |
|
258 | - |
|
259 | - // List of all rule group items. |
|
260 | - $rule_groups = array(); |
|
261 | - foreach ( $rule_group_rows as $rule_group_row ) { |
|
262 | - $rule_groups[] = array( |
|
263 | - 'rule_group_id' => $rule_group_row['rule_group_id'], |
|
264 | - 'rules' => $this->get_rules_by_rule_group( $rule_group_row['rule_group_id'] ), |
|
265 | - ); |
|
266 | - } |
|
267 | - |
|
268 | - return $rule_groups; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Gets a list of rule items belong to rule_group_id. |
|
273 | - * |
|
274 | - * @param int $rule_group_id Indicates which group the item belongs to. |
|
275 | - * |
|
276 | - * @return array Get list of rule items. |
|
277 | - */ |
|
278 | - public function get_rules_by_rule_group( $rule_group_id ) { |
|
279 | - global $wpdb; |
|
280 | - return $wpdb->get_results( |
|
281 | - $wpdb->prepare( |
|
282 | - "SELECT * FROM {$wpdb->prefix}wl_mapping_rule WHERE rule_group_id=%d", |
|
283 | - $rule_group_id |
|
284 | - ), |
|
285 | - ARRAY_A |
|
286 | - ); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Insert/Update property item. |
|
291 | - * |
|
292 | - * @param array $property_data Property row from table/ui. |
|
293 | - * |
|
294 | - * @return int Inserted Property Id. |
|
295 | - */ |
|
296 | - public function insert_or_update_property( $property_data ) { |
|
297 | - $property_table_name = $this->wpdb->prefix . WL_PROPERTY_TABLE_NAME; |
|
298 | - $property_id = array_key_exists( 'property_id', $property_data ) ? $property_data['property_id'] : null; |
|
299 | - |
|
300 | - if ( $this->check_if_row_exists( $property_table_name, 'property_id', $property_id ) ) { |
|
301 | - $this->wpdb->update( |
|
302 | - $property_table_name, |
|
303 | - $property_data, |
|
304 | - array( 'property_id' => $property_id ) |
|
305 | - ); |
|
306 | - } else { |
|
307 | - $this->wpdb->insert( $property_table_name, $property_data ); |
|
308 | - $property_id = $this->wpdb->insert_id; |
|
309 | - } |
|
310 | - |
|
311 | - return $property_id; |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Gets a single mapping item row. |
|
316 | - * |
|
317 | - * @param int $mapping_id Primary key of mapping table. |
|
318 | - * |
|
319 | - * @return array Returns single mapping table row.. |
|
320 | - */ |
|
321 | - public function get_mapping_item_data( $mapping_id ) { |
|
322 | - global $wpdb; |
|
323 | - return $wpdb->get_row( |
|
324 | - $wpdb->prepare( |
|
325 | - "SELECT * FROM {$wpdb->prefix}wl_mapping WHERE mapping_id=%d", |
|
326 | - $mapping_id |
|
327 | - ), |
|
328 | - ARRAY_A |
|
329 | - ); |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Delete property item. |
|
334 | - * |
|
335 | - * @param int $property_id Primary key for property table. |
|
336 | - * |
|
337 | - * @return int|false The number of rows updated, or false on error. |
|
338 | - */ |
|
339 | - public function delete_property( $property_id ) { |
|
340 | - $property_table_name = $this->wpdb->prefix . WL_PROPERTY_TABLE_NAME; |
|
341 | - |
|
342 | - return $this->wpdb->delete( $property_table_name, array( 'property_id' => $property_id ) ); |
|
343 | - } |
|
15 | + /** |
|
16 | + * The {@link wpdb} instance. |
|
17 | + * |
|
18 | + * @since 3.25.0 |
|
19 | + * @access private |
|
20 | + * @var \wpdb $wpdb The {@link wpdb} instance. |
|
21 | + */ |
|
22 | + private $wpdb = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * Construct DBO object. |
|
26 | + */ |
|
27 | + public function __construct() { |
|
28 | + global $wpdb; |
|
29 | + $this->wpdb = $wpdb; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Returns an array of mappings. |
|
34 | + * |
|
35 | + * Each mapping contains one or more rule groups which in turn contain one or more rules. |
|
36 | + * |
|
37 | + * @return array An array of mappings. |
|
38 | + */ |
|
39 | + public function get_mappings() { |
|
40 | + global $wpdb; |
|
41 | + return $this->wpdb->get_results( |
|
42 | + "SELECT * FROM {$wpdb->prefix}wl_mapping", |
|
43 | + ARRAY_A |
|
44 | + ); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Returns an array of active mappings. |
|
49 | + * |
|
50 | + * Each mapping contains one or more rule groups which in turn contain one or more rules. |
|
51 | + * |
|
52 | + * @return array An array of mappings. |
|
53 | + */ |
|
54 | + public function get_active_mappings() { |
|
55 | + global $wpdb; |
|
56 | + return $this->wpdb->get_results( |
|
57 | + "SELECT * FROM {$wpdb->prefix}wl_mapping WHERE mapping_status = 'active'", |
|
58 | + ARRAY_A |
|
59 | + ); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Returns a list of property rows |
|
64 | + * |
|
65 | + * @param int $mapping_id Primary key of mapping table. |
|
66 | + * |
|
67 | + * @return array List of property items belong to $mapping_id. |
|
68 | + */ |
|
69 | + public function get_properties( $mapping_id ) { |
|
70 | + global $wpdb; |
|
71 | + $property_rows = $wpdb->get_results( |
|
72 | + $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wl_mapping_property WHERE mapping_id=%d", $mapping_id ), |
|
73 | + ARRAY_A |
|
74 | + ); |
|
75 | + |
|
76 | + return $property_rows; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Check if the row exists in the table |
|
81 | + * |
|
82 | + * @param string $table_name The table name you want to query, completely escaped value. |
|
83 | + * @param string $primary_key_name The primary key you want to query, should be escaped before passing. |
|
84 | + * @param int $primary_key_value The primary key value, no need to escape. |
|
85 | + * |
|
86 | + * @return bool Returns true if the row exists, false if it does not |
|
87 | + */ |
|
88 | + private function check_if_row_exists( $table_name, $primary_key_name, $primary_key_value ) { |
|
89 | + global $wpdb; |
|
90 | + $primary_key_value = (int) $primary_key_value; |
|
91 | + $count = (int) $this->wpdb->get_var( |
|
92 | + $wpdb->prepare( |
|
93 | + 'SELECT COUNT(%1s) from %2s where %3s = %4d', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder |
|
94 | + $primary_key_name, |
|
95 | + $table_name, |
|
96 | + $primary_key_name, |
|
97 | + $primary_key_value |
|
98 | + ) |
|
99 | + ); |
|
100 | + |
|
101 | + return $count > 0; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Insert new mapping item with title |
|
106 | + * |
|
107 | + * @param string $title Title of the mapping item. |
|
108 | + * |
|
109 | + * @return int Id of the inserted mapping item. |
|
110 | + */ |
|
111 | + public function insert_mapping_item( $title ) { |
|
112 | + $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME; |
|
113 | + $this->wpdb->insert( |
|
114 | + $mapping_table_name, |
|
115 | + array( 'mapping_title' => $title ) |
|
116 | + ); |
|
117 | + |
|
118 | + return $this->wpdb->insert_id; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Update mapping item with new title |
|
123 | + * |
|
124 | + * @param array $mapping_data Array of the mapping data. |
|
125 | + * |
|
126 | + * @return int Id of the inserted mapping item |
|
127 | + */ |
|
128 | + public function insert_or_update_mapping_item( $mapping_data ) { |
|
129 | + $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME; |
|
130 | + $mapping_id = array_key_exists( 'mapping_id', $mapping_data ) ? (int) $mapping_data['mapping_id'] : null; |
|
131 | + if ( $this->check_if_row_exists( $mapping_table_name, 'mapping_id', $mapping_data['mapping_id'] ) ) { |
|
132 | + $this->wpdb->update( |
|
133 | + $mapping_table_name, |
|
134 | + $mapping_data, |
|
135 | + array( 'mapping_id' => $mapping_id ) |
|
136 | + ); |
|
137 | + } else { |
|
138 | + $this->wpdb->insert( |
|
139 | + $mapping_table_name, |
|
140 | + $mapping_data |
|
141 | + ); |
|
142 | + $mapping_id = (int) $this->wpdb->insert_id; |
|
143 | + } |
|
144 | + |
|
145 | + return $mapping_id; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Updates rule item. |
|
150 | + * |
|
151 | + * @param array $rule_item_data The rule_item_data, should contain rule_id. |
|
152 | + * |
|
153 | + * @return int $rule_id The inserted rule id. |
|
154 | + */ |
|
155 | + public function insert_or_update_rule_item( $rule_item_data ) { |
|
156 | + $rule_table_name = $this->wpdb->prefix . WL_RULE_TABLE_NAME; |
|
157 | + $rule_id = array_key_exists( 'rule_id', $rule_item_data ) ? $rule_item_data['rule_id'] : null; |
|
158 | + if ( $this->check_if_row_exists( $rule_table_name, 'rule_id', $rule_id ) ) { |
|
159 | + $this->wpdb->update( $rule_table_name, $rule_item_data, array( 'rule_id' => $rule_id ) ); |
|
160 | + } else { |
|
161 | + $this->wpdb->insert( $rule_table_name, $rule_item_data ); |
|
162 | + $rule_id = $this->wpdb->insert_id; |
|
163 | + } |
|
164 | + |
|
165 | + return $rule_id; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * If a rule group exists doesn't do anything, but if rule group |
|
170 | + * didn't exist then it inserts a new entry. |
|
171 | + * |
|
172 | + * @param int $mapping_id Primary key for mapping table. |
|
173 | + * |
|
174 | + * @return int The inserted rule group id. |
|
175 | + */ |
|
176 | + public function insert_rule_group( $mapping_id ) { |
|
177 | + $rule_group_table_name = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME; |
|
178 | + $this->wpdb->insert( |
|
179 | + $rule_group_table_name, |
|
180 | + array( |
|
181 | + 'mapping_id' => $mapping_id, |
|
182 | + ) |
|
183 | + ); |
|
184 | + |
|
185 | + return $this->wpdb->insert_id; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Deletes a rule item by rule_id from rule and rule group table. |
|
190 | + * |
|
191 | + * @param int $rule_id Primary key for rule table. |
|
192 | + * |
|
193 | + * @return void |
|
194 | + */ |
|
195 | + public function delete_rule_item( $rule_id ) { |
|
196 | + $rule_table_name = $this->wpdb->prefix . WL_RULE_TABLE_NAME; |
|
197 | + $this->wpdb->delete( $rule_table_name, array( 'rule_id' => $rule_id ) ); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Deletes a rule group item by rule_group_id from rule group table. |
|
202 | + * |
|
203 | + * @param int $rule_group_id Primary key for rule table. |
|
204 | + * |
|
205 | + * @return void |
|
206 | + */ |
|
207 | + public function delete_rule_group_item( $rule_group_id ) { |
|
208 | + $rule_group_table_name = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME; |
|
209 | + $this->wpdb->delete( $rule_group_table_name, array( 'rule_group_id' => $rule_group_id ) ); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Deletes a mapping item by mapping_id |
|
214 | + * |
|
215 | + * @param int $mapping_id Primary key for mapping table. |
|
216 | + * |
|
217 | + * @return void |
|
218 | + */ |
|
219 | + public function delete_mapping_item( $mapping_id ) { |
|
220 | + $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME; |
|
221 | + $this->wpdb->delete( $mapping_table_name, array( 'mapping_id' => $mapping_id ) ); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Gets a list of rule group items. |
|
226 | + * |
|
227 | + * @param int $mapping_id Primary key for mapping table. |
|
228 | + * |
|
229 | + * @return array Get list of rule group items. |
|
230 | + */ |
|
231 | + public function get_rule_group_list( $mapping_id ) { |
|
232 | + global $wpdb; |
|
233 | + return $wpdb->get_results( |
|
234 | + $wpdb->prepare( |
|
235 | + "SELECT rule_group_id FROM {$wpdb->prefix}wl_mapping_rule_group WHERE mapping_id=%d", |
|
236 | + $mapping_id |
|
237 | + ), |
|
238 | + ARRAY_A |
|
239 | + ); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Gets a list of rule group items. |
|
244 | + * |
|
245 | + * @param int $mapping_id Primary key for mapping table. |
|
246 | + * |
|
247 | + * @return array Get list of rule group items. |
|
248 | + */ |
|
249 | + public function get_rule_groups_by_mapping( $mapping_id ) { |
|
250 | + global $wpdb; |
|
251 | + $rule_group_rows = $wpdb->get_results( |
|
252 | + $wpdb->prepare( |
|
253 | + "SELECT rule_group_id FROM {$wpdb->prefix}wl_mapping_rule_group WHERE mapping_id=%d", |
|
254 | + $mapping_id |
|
255 | + ), |
|
256 | + ARRAY_A |
|
257 | + ); |
|
258 | + |
|
259 | + // List of all rule group items. |
|
260 | + $rule_groups = array(); |
|
261 | + foreach ( $rule_group_rows as $rule_group_row ) { |
|
262 | + $rule_groups[] = array( |
|
263 | + 'rule_group_id' => $rule_group_row['rule_group_id'], |
|
264 | + 'rules' => $this->get_rules_by_rule_group( $rule_group_row['rule_group_id'] ), |
|
265 | + ); |
|
266 | + } |
|
267 | + |
|
268 | + return $rule_groups; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Gets a list of rule items belong to rule_group_id. |
|
273 | + * |
|
274 | + * @param int $rule_group_id Indicates which group the item belongs to. |
|
275 | + * |
|
276 | + * @return array Get list of rule items. |
|
277 | + */ |
|
278 | + public function get_rules_by_rule_group( $rule_group_id ) { |
|
279 | + global $wpdb; |
|
280 | + return $wpdb->get_results( |
|
281 | + $wpdb->prepare( |
|
282 | + "SELECT * FROM {$wpdb->prefix}wl_mapping_rule WHERE rule_group_id=%d", |
|
283 | + $rule_group_id |
|
284 | + ), |
|
285 | + ARRAY_A |
|
286 | + ); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Insert/Update property item. |
|
291 | + * |
|
292 | + * @param array $property_data Property row from table/ui. |
|
293 | + * |
|
294 | + * @return int Inserted Property Id. |
|
295 | + */ |
|
296 | + public function insert_or_update_property( $property_data ) { |
|
297 | + $property_table_name = $this->wpdb->prefix . WL_PROPERTY_TABLE_NAME; |
|
298 | + $property_id = array_key_exists( 'property_id', $property_data ) ? $property_data['property_id'] : null; |
|
299 | + |
|
300 | + if ( $this->check_if_row_exists( $property_table_name, 'property_id', $property_id ) ) { |
|
301 | + $this->wpdb->update( |
|
302 | + $property_table_name, |
|
303 | + $property_data, |
|
304 | + array( 'property_id' => $property_id ) |
|
305 | + ); |
|
306 | + } else { |
|
307 | + $this->wpdb->insert( $property_table_name, $property_data ); |
|
308 | + $property_id = $this->wpdb->insert_id; |
|
309 | + } |
|
310 | + |
|
311 | + return $property_id; |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Gets a single mapping item row. |
|
316 | + * |
|
317 | + * @param int $mapping_id Primary key of mapping table. |
|
318 | + * |
|
319 | + * @return array Returns single mapping table row.. |
|
320 | + */ |
|
321 | + public function get_mapping_item_data( $mapping_id ) { |
|
322 | + global $wpdb; |
|
323 | + return $wpdb->get_row( |
|
324 | + $wpdb->prepare( |
|
325 | + "SELECT * FROM {$wpdb->prefix}wl_mapping WHERE mapping_id=%d", |
|
326 | + $mapping_id |
|
327 | + ), |
|
328 | + ARRAY_A |
|
329 | + ); |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Delete property item. |
|
334 | + * |
|
335 | + * @param int $property_id Primary key for property table. |
|
336 | + * |
|
337 | + * @return int|false The number of rows updated, or false on error. |
|
338 | + */ |
|
339 | + public function delete_property( $property_id ) { |
|
340 | + $property_table_name = $this->wpdb->prefix . WL_PROPERTY_TABLE_NAME; |
|
341 | + |
|
342 | + return $this->wpdb->delete( $property_table_name, array( 'property_id' => $property_id ) ); |
|
343 | + } |
|
344 | 344 | |
345 | 345 | } |
@@ -20,79 +20,79 @@ |
||
20 | 20 | */ |
21 | 21 | class Post_Id_To_Entity_Transform_Function implements Mappings_Transform_Function { |
22 | 22 | |
23 | - public function __construct() { |
|
23 | + public function __construct() { |
|
24 | 24 | |
25 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
25 | + add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
26 | 26 | |
27 | - } |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Hook to add ourselves to the list of available transform functions. |
|
31 | - * |
|
32 | - * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
33 | - * |
|
34 | - * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
35 | - */ |
|
36 | - public function wl_mappings_transformation_functions( $value ) { |
|
29 | + /** |
|
30 | + * Hook to add ourselves to the list of available transform functions. |
|
31 | + * |
|
32 | + * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
33 | + * |
|
34 | + * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
35 | + */ |
|
36 | + public function wl_mappings_transformation_functions( $value ) { |
|
37 | 37 | |
38 | - $value[] = $this; |
|
38 | + $value[] = $this; |
|
39 | 39 | |
40 | - return $value; |
|
41 | - } |
|
40 | + return $value; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @inheritDoc |
|
45 | - */ |
|
46 | - public function get_name() { |
|
43 | + /** |
|
44 | + * @inheritDoc |
|
45 | + */ |
|
46 | + public function get_name() { |
|
47 | 47 | |
48 | - return 'post_id_to_entity'; |
|
49 | - } |
|
48 | + return 'post_id_to_entity'; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @inheritDoc |
|
53 | - */ |
|
54 | - public function get_label() { |
|
51 | + /** |
|
52 | + * @inheritDoc |
|
53 | + */ |
|
54 | + public function get_label() { |
|
55 | 55 | |
56 | - return __( 'Post ID to Entity', 'wordlift' ); |
|
57 | - } |
|
56 | + return __( 'Post ID to Entity', 'wordlift' ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @inheritDoc |
|
61 | - */ |
|
62 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
63 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
59 | + /** |
|
60 | + * @inheritDoc |
|
61 | + */ |
|
62 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
63 | + public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
64 | 64 | |
65 | - $ret_val = array(); |
|
66 | - foreach ( (array) $data as $target_post_id ) { |
|
65 | + $ret_val = array(); |
|
66 | + foreach ( (array) $data as $target_post_id ) { |
|
67 | 67 | |
68 | - // We need a numeric post ID. |
|
69 | - if ( ! is_numeric( $target_post_id ) ) { |
|
68 | + // We need a numeric post ID. |
|
69 | + if ( ! is_numeric( $target_post_id ) ) { |
|
70 | 70 | |
71 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
72 | - @header( "X-Post-Id-To-Entity-Transform-Function: $target_post_id not numeric." ); |
|
71 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
72 | + @header( "X-Post-Id-To-Entity-Transform-Function: $target_post_id not numeric." ); |
|
73 | 73 | |
74 | - continue; |
|
75 | - } |
|
74 | + continue; |
|
75 | + } |
|
76 | 76 | |
77 | - // Get the entity by URI. |
|
78 | - $entity_url = Wordpress_Content_Service::get_instance() |
|
79 | - ->get_entity_id( Wordpress_Content_Id::create_post( $target_post_id ) ); |
|
77 | + // Get the entity by URI. |
|
78 | + $entity_url = Wordpress_Content_Service::get_instance() |
|
79 | + ->get_entity_id( Wordpress_Content_Id::create_post( $target_post_id ) ); |
|
80 | 80 | |
81 | - // No entity URL. |
|
82 | - if ( empty( $entity_url ) ) { |
|
83 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
84 | - @header( "X-Post-Id-To-Entity-Transform-Function: entity url for $data not found." ); |
|
81 | + // No entity URL. |
|
82 | + if ( empty( $entity_url ) ) { |
|
83 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
84 | + @header( "X-Post-Id-To-Entity-Transform-Function: entity url for $data not found." ); |
|
85 | 85 | |
86 | - continue; |
|
87 | - } |
|
86 | + continue; |
|
87 | + } |
|
88 | 88 | |
89 | - // Add the entity among the references using the post ID. |
|
90 | - $references[] = (int) $target_post_id; |
|
89 | + // Add the entity among the references using the post ID. |
|
90 | + $references[] = (int) $target_post_id; |
|
91 | 91 | |
92 | - $ret_val[] = array( '@id' => $entity_url ); |
|
93 | - } |
|
92 | + $ret_val[] = array( '@id' => $entity_url ); |
|
93 | + } |
|
94 | 94 | |
95 | - return $ret_val; |
|
96 | - } |
|
95 | + return $ret_val; |
|
96 | + } |
|
97 | 97 | |
98 | 98 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | public function __construct() { |
24 | 24 | |
25 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
25 | + add_filter('wl_mappings_transformation_functions', array($this, 'wl_mappings_transformation_functions')); |
|
26 | 26 | |
27 | 27 | } |
28 | 28 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return Mappings_Transform_Function[] An updated array with ourselves too. |
35 | 35 | */ |
36 | - public function wl_mappings_transformation_functions( $value ) { |
|
36 | + public function wl_mappings_transformation_functions($value) { |
|
37 | 37 | |
38 | 38 | $value[] = $this; |
39 | 39 | |
@@ -53,35 +53,35 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function get_label() { |
55 | 55 | |
56 | - return __( 'Post ID to Entity', 'wordlift' ); |
|
56 | + return __('Post ID to Entity', 'wordlift'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @inheritDoc |
61 | 61 | */ |
62 | 62 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
63 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
63 | + public function transform_data($data, $jsonld, &$references, $post_id) { |
|
64 | 64 | |
65 | 65 | $ret_val = array(); |
66 | - foreach ( (array) $data as $target_post_id ) { |
|
66 | + foreach ((array) $data as $target_post_id) { |
|
67 | 67 | |
68 | 68 | // We need a numeric post ID. |
69 | - if ( ! is_numeric( $target_post_id ) ) { |
|
69 | + if ( ! is_numeric($target_post_id)) { |
|
70 | 70 | |
71 | 71 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
72 | - @header( "X-Post-Id-To-Entity-Transform-Function: $target_post_id not numeric." ); |
|
72 | + @header("X-Post-Id-To-Entity-Transform-Function: $target_post_id not numeric."); |
|
73 | 73 | |
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | 77 | // Get the entity by URI. |
78 | 78 | $entity_url = Wordpress_Content_Service::get_instance() |
79 | - ->get_entity_id( Wordpress_Content_Id::create_post( $target_post_id ) ); |
|
79 | + ->get_entity_id(Wordpress_Content_Id::create_post($target_post_id)); |
|
80 | 80 | |
81 | 81 | // No entity URL. |
82 | - if ( empty( $entity_url ) ) { |
|
82 | + if (empty($entity_url)) { |
|
83 | 83 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
84 | - @header( "X-Post-Id-To-Entity-Transform-Function: entity url for $data not found." ); |
|
84 | + @header("X-Post-Id-To-Entity-Transform-Function: entity url for $data not found."); |
|
85 | 85 | |
86 | 86 | continue; |
87 | 87 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | // Add the entity among the references using the post ID. |
90 | 90 | $references[] = (int) $target_post_id; |
91 | 91 | |
92 | - $ret_val[] = array( '@id' => $entity_url ); |
|
92 | + $ret_val[] = array('@id' => $entity_url); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | return $ret_val; |
@@ -19,72 +19,72 @@ |
||
19 | 19 | */ |
20 | 20 | class Url_To_Entity_Transform_Function implements Mappings_Transform_Function { |
21 | 21 | |
22 | - /** |
|
23 | - * The {@link Wordlift_Entity_Uri_Service} instance. |
|
24 | - * |
|
25 | - * @var Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
26 | - */ |
|
27 | - private $entity_uri_service; |
|
28 | - |
|
29 | - /** |
|
30 | - * Url_To_Entity_Transform_Function constructor. |
|
31 | - * |
|
32 | - * @param Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
33 | - */ |
|
34 | - public function __construct( $entity_uri_service ) { |
|
35 | - |
|
36 | - $this->entity_uri_service = $entity_uri_service; |
|
37 | - |
|
38 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
39 | - |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Hook to add ourselves to the list of available transform functions. |
|
44 | - * |
|
45 | - * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
46 | - * |
|
47 | - * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
48 | - */ |
|
49 | - public function wl_mappings_transformation_functions( $value ) { |
|
50 | - |
|
51 | - $value[] = $this; |
|
52 | - |
|
53 | - return $value; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @inheritDoc |
|
58 | - */ |
|
59 | - public function get_name() { |
|
60 | - |
|
61 | - return 'url_to_entity'; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @inheritDoc |
|
66 | - */ |
|
67 | - public function get_label() { |
|
68 | - |
|
69 | - return __( 'URL to Entity', 'wordlift' ); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @inheritDoc |
|
74 | - */ |
|
75 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
76 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
77 | - |
|
78 | - // Get the entity by URI. |
|
79 | - $post = $this->entity_uri_service->get_entity( $data ); |
|
80 | - |
|
81 | - // If found, add the reference. |
|
82 | - if ( is_a( $post, 'WP_Post' ) ) { |
|
83 | - // Add the entity among the references using the post ID. |
|
84 | - $references[] = $post->ID; |
|
85 | - } |
|
86 | - |
|
87 | - return array( '@id' => $data ); |
|
88 | - } |
|
22 | + /** |
|
23 | + * The {@link Wordlift_Entity_Uri_Service} instance. |
|
24 | + * |
|
25 | + * @var Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
26 | + */ |
|
27 | + private $entity_uri_service; |
|
28 | + |
|
29 | + /** |
|
30 | + * Url_To_Entity_Transform_Function constructor. |
|
31 | + * |
|
32 | + * @param Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
33 | + */ |
|
34 | + public function __construct( $entity_uri_service ) { |
|
35 | + |
|
36 | + $this->entity_uri_service = $entity_uri_service; |
|
37 | + |
|
38 | + add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
39 | + |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Hook to add ourselves to the list of available transform functions. |
|
44 | + * |
|
45 | + * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
46 | + * |
|
47 | + * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
48 | + */ |
|
49 | + public function wl_mappings_transformation_functions( $value ) { |
|
50 | + |
|
51 | + $value[] = $this; |
|
52 | + |
|
53 | + return $value; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @inheritDoc |
|
58 | + */ |
|
59 | + public function get_name() { |
|
60 | + |
|
61 | + return 'url_to_entity'; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @inheritDoc |
|
66 | + */ |
|
67 | + public function get_label() { |
|
68 | + |
|
69 | + return __( 'URL to Entity', 'wordlift' ); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @inheritDoc |
|
74 | + */ |
|
75 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
76 | + public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
77 | + |
|
78 | + // Get the entity by URI. |
|
79 | + $post = $this->entity_uri_service->get_entity( $data ); |
|
80 | + |
|
81 | + // If found, add the reference. |
|
82 | + if ( is_a( $post, 'WP_Post' ) ) { |
|
83 | + // Add the entity among the references using the post ID. |
|
84 | + $references[] = $post->ID; |
|
85 | + } |
|
86 | + |
|
87 | + return array( '@id' => $data ); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | } |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
33 | 33 | */ |
34 | - public function __construct( $entity_uri_service ) { |
|
34 | + public function __construct($entity_uri_service) { |
|
35 | 35 | |
36 | 36 | $this->entity_uri_service = $entity_uri_service; |
37 | 37 | |
38 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
38 | + add_filter('wl_mappings_transformation_functions', array($this, 'wl_mappings_transformation_functions')); |
|
39 | 39 | |
40 | 40 | } |
41 | 41 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return Mappings_Transform_Function[] An updated array with ourselves too. |
48 | 48 | */ |
49 | - public function wl_mappings_transformation_functions( $value ) { |
|
49 | + public function wl_mappings_transformation_functions($value) { |
|
50 | 50 | |
51 | 51 | $value[] = $this; |
52 | 52 | |
@@ -66,25 +66,25 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function get_label() { |
68 | 68 | |
69 | - return __( 'URL to Entity', 'wordlift' ); |
|
69 | + return __('URL to Entity', 'wordlift'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @inheritDoc |
74 | 74 | */ |
75 | 75 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
76 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
76 | + public function transform_data($data, $jsonld, &$references, $post_id) { |
|
77 | 77 | |
78 | 78 | // Get the entity by URI. |
79 | - $post = $this->entity_uri_service->get_entity( $data ); |
|
79 | + $post = $this->entity_uri_service->get_entity($data); |
|
80 | 80 | |
81 | 81 | // If found, add the reference. |
82 | - if ( is_a( $post, 'WP_Post' ) ) { |
|
82 | + if (is_a($post, 'WP_Post')) { |
|
83 | 83 | // Add the entity among the references using the post ID. |
84 | 84 | $references[] = $post->ID; |
85 | 85 | } |
86 | 86 | |
87 | - return array( '@id' => $data ); |
|
87 | + return array('@id' => $data); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | } |
@@ -18,57 +18,57 @@ |
||
18 | 18 | */ |
19 | 19 | class Taxonomy_To_Terms_Transform_Function implements Mappings_Transform_Function { |
20 | 20 | |
21 | - /** |
|
22 | - * Taxonomy_To_Terms_Transform_Function constructor. |
|
23 | - */ |
|
24 | - public function __construct() { |
|
21 | + /** |
|
22 | + * Taxonomy_To_Terms_Transform_Function constructor. |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | 25 | |
26 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
26 | + add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
27 | 27 | |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Hook to add ourselves to the list of available transform functions. |
|
32 | - * |
|
33 | - * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
34 | - * |
|
35 | - * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
36 | - */ |
|
37 | - public function wl_mappings_transformation_functions( $value ) { |
|
30 | + /** |
|
31 | + * Hook to add ourselves to the list of available transform functions. |
|
32 | + * |
|
33 | + * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
34 | + * |
|
35 | + * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
36 | + */ |
|
37 | + public function wl_mappings_transformation_functions( $value ) { |
|
38 | 38 | |
39 | - $value[] = $this; |
|
39 | + $value[] = $this; |
|
40 | 40 | |
41 | - return $value; |
|
42 | - } |
|
41 | + return $value; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @inheritDoc |
|
46 | - */ |
|
47 | - public function get_name() { |
|
44 | + /** |
|
45 | + * @inheritDoc |
|
46 | + */ |
|
47 | + public function get_name() { |
|
48 | 48 | |
49 | - return 'taxonomy_to_terms'; |
|
50 | - } |
|
49 | + return 'taxonomy_to_terms'; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @inheritDoc |
|
54 | - */ |
|
55 | - public function get_label() { |
|
52 | + /** |
|
53 | + * @inheritDoc |
|
54 | + */ |
|
55 | + public function get_label() { |
|
56 | 56 | |
57 | - return __( 'Taxonomy to Terms', 'wordlift' ); |
|
58 | - } |
|
57 | + return __( 'Taxonomy to Terms', 'wordlift' ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @inheritDoc |
|
62 | - */ |
|
63 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
60 | + /** |
|
61 | + * @inheritDoc |
|
62 | + */ |
|
63 | + public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
64 | 64 | |
65 | - $terms = wp_get_object_terms( $post_id, $data, array( 'fields' => 'names' ) ); |
|
65 | + $terms = wp_get_object_terms( $post_id, $data, array( 'fields' => 'names' ) ); |
|
66 | 66 | |
67 | - if ( ! is_array( $terms ) || empty( $terms ) ) { |
|
68 | - return null; |
|
69 | - } |
|
67 | + if ( ! is_array( $terms ) || empty( $terms ) ) { |
|
68 | + return null; |
|
69 | + } |
|
70 | 70 | |
71 | - return $terms; |
|
72 | - } |
|
71 | + return $terms; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct() { |
25 | 25 | |
26 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
26 | + add_filter('wl_mappings_transformation_functions', array($this, 'wl_mappings_transformation_functions')); |
|
27 | 27 | |
28 | 28 | } |
29 | 29 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return Mappings_Transform_Function[] An updated array with ourselves too. |
36 | 36 | */ |
37 | - public function wl_mappings_transformation_functions( $value ) { |
|
37 | + public function wl_mappings_transformation_functions($value) { |
|
38 | 38 | |
39 | 39 | $value[] = $this; |
40 | 40 | |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function get_label() { |
56 | 56 | |
57 | - return __( 'Taxonomy to Terms', 'wordlift' ); |
|
57 | + return __('Taxonomy to Terms', 'wordlift'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @inheritDoc |
62 | 62 | */ |
63 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
63 | + public function transform_data($data, $jsonld, &$references, $post_id) { |
|
64 | 64 | |
65 | - $terms = wp_get_object_terms( $post_id, $data, array( 'fields' => 'names' ) ); |
|
65 | + $terms = wp_get_object_terms($post_id, $data, array('fields' => 'names')); |
|
66 | 66 | |
67 | - if ( ! is_array( $terms ) || empty( $terms ) ) { |
|
67 | + if ( ! is_array($terms) || empty($terms)) { |
|
68 | 68 | return null; |
69 | 69 | } |
70 | 70 |
@@ -5,71 +5,71 @@ |
||
5 | 5 | use Wordlift\Object_Type_Enum; |
6 | 6 | |
7 | 7 | class Sync_Post_Adapter extends Abstract_Sync_Object_Adapter { |
8 | - /** |
|
9 | - * @var int |
|
10 | - */ |
|
11 | - private $post_id; |
|
8 | + /** |
|
9 | + * @var int |
|
10 | + */ |
|
11 | + private $post_id; |
|
12 | 12 | |
13 | - /** |
|
14 | - * Sync_Term_Adapter constructor. |
|
15 | - * |
|
16 | - * @param int $post_id |
|
17 | - * |
|
18 | - * @throws \Exception when an error occurs. |
|
19 | - */ |
|
20 | - public function __construct( $post_id ) { |
|
21 | - parent::__construct( Object_Type_Enum::POST, $post_id ); |
|
13 | + /** |
|
14 | + * Sync_Term_Adapter constructor. |
|
15 | + * |
|
16 | + * @param int $post_id |
|
17 | + * |
|
18 | + * @throws \Exception when an error occurs. |
|
19 | + */ |
|
20 | + public function __construct( $post_id ) { |
|
21 | + parent::__construct( Object_Type_Enum::POST, $post_id ); |
|
22 | 22 | |
23 | - $this->post_id = $post_id; |
|
24 | - } |
|
23 | + $this->post_id = $post_id; |
|
24 | + } |
|
25 | 25 | |
26 | - public function is_published() { |
|
27 | - return ( 'publish' === get_post_status( $this->post_id ) ); |
|
28 | - } |
|
26 | + public function is_published() { |
|
27 | + return ( 'publish' === get_post_status( $this->post_id ) ); |
|
28 | + } |
|
29 | 29 | |
30 | - public function is_public() { |
|
31 | - // Check if the post type is public. |
|
32 | - $post_type = get_post_type( $this->post_id ); |
|
33 | - $post_type_obj = get_post_type_object( $post_type ); |
|
30 | + public function is_public() { |
|
31 | + // Check if the post type is public. |
|
32 | + $post_type = get_post_type( $this->post_id ); |
|
33 | + $post_type_obj = get_post_type_object( $post_type ); |
|
34 | 34 | |
35 | - return $post_type_obj->public; |
|
36 | - } |
|
35 | + return $post_type_obj->public; |
|
36 | + } |
|
37 | 37 | |
38 | - public function set_values( $arr ) { |
|
39 | - global $wpdb; |
|
38 | + public function set_values( $arr ) { |
|
39 | + global $wpdb; |
|
40 | 40 | |
41 | - $field_names = implode( ', ', array_map( 'esc_sql', array_keys( $arr ) ) ); |
|
42 | - $field_values = "'" . implode( "', '", array_map( 'esc_sql', array_values( $arr ) ) ) . "'"; |
|
41 | + $field_names = implode( ', ', array_map( 'esc_sql', array_keys( $arr ) ) ); |
|
42 | + $field_values = "'" . implode( "', '", array_map( 'esc_sql', array_values( $arr ) ) ) . "'"; |
|
43 | 43 | |
44 | - $update_stmt = implode( |
|
45 | - ', ', |
|
46 | - array_map( |
|
47 | - function ( $key ) use ( $arr ) { |
|
48 | - return "$key = '" . esc_sql( $arr[ $key ] ) . "'"; |
|
49 | - }, |
|
50 | - array_keys( $arr ) |
|
51 | - ) |
|
52 | - ); |
|
44 | + $update_stmt = implode( |
|
45 | + ', ', |
|
46 | + array_map( |
|
47 | + function ( $key ) use ( $arr ) { |
|
48 | + return "$key = '" . esc_sql( $arr[ $key ] ) . "'"; |
|
49 | + }, |
|
50 | + array_keys( $arr ) |
|
51 | + ) |
|
52 | + ); |
|
53 | 53 | |
54 | - $wpdb->query( |
|
55 | - $wpdb->prepare( |
|
56 | - "INSERT INTO {$wpdb->prefix}wl_entities( content_id, content_type, $field_names ) VALUES ( %d, %d, $field_values ) ON DUPLICATE KEY UPDATE $update_stmt;", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
57 | - $this->post_id, |
|
58 | - Object_Type_Enum::POST |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
54 | + $wpdb->query( |
|
55 | + $wpdb->prepare( |
|
56 | + "INSERT INTO {$wpdb->prefix}wl_entities( content_id, content_type, $field_names ) VALUES ( %d, %d, $field_values ) ON DUPLICATE KEY UPDATE $update_stmt;", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
57 | + $this->post_id, |
|
58 | + Object_Type_Enum::POST |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - public function get_value( $key ) { |
|
64 | - global $wpdb; |
|
63 | + public function get_value( $key ) { |
|
64 | + global $wpdb; |
|
65 | 65 | |
66 | - return $wpdb->get_var( |
|
67 | - $wpdb->prepare( |
|
68 | - "SELECT $key FROM {$wpdb->prefix}wl_entities WHERE content_id = %d AND content_type = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
69 | - $this->post_id, |
|
70 | - Object_Type_Enum::POST |
|
71 | - ) |
|
72 | - ); |
|
73 | - } |
|
66 | + return $wpdb->get_var( |
|
67 | + $wpdb->prepare( |
|
68 | + "SELECT $key FROM {$wpdb->prefix}wl_entities WHERE content_id = %d AND content_type = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
69 | + $this->post_id, |
|
70 | + Object_Type_Enum::POST |
|
71 | + ) |
|
72 | + ); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | } |
@@ -17,37 +17,37 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @throws \Exception when an error occurs. |
19 | 19 | */ |
20 | - public function __construct( $post_id ) { |
|
21 | - parent::__construct( Object_Type_Enum::POST, $post_id ); |
|
20 | + public function __construct($post_id) { |
|
21 | + parent::__construct(Object_Type_Enum::POST, $post_id); |
|
22 | 22 | |
23 | 23 | $this->post_id = $post_id; |
24 | 24 | } |
25 | 25 | |
26 | 26 | public function is_published() { |
27 | - return ( 'publish' === get_post_status( $this->post_id ) ); |
|
27 | + return ('publish' === get_post_status($this->post_id)); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function is_public() { |
31 | 31 | // Check if the post type is public. |
32 | - $post_type = get_post_type( $this->post_id ); |
|
33 | - $post_type_obj = get_post_type_object( $post_type ); |
|
32 | + $post_type = get_post_type($this->post_id); |
|
33 | + $post_type_obj = get_post_type_object($post_type); |
|
34 | 34 | |
35 | 35 | return $post_type_obj->public; |
36 | 36 | } |
37 | 37 | |
38 | - public function set_values( $arr ) { |
|
38 | + public function set_values($arr) { |
|
39 | 39 | global $wpdb; |
40 | 40 | |
41 | - $field_names = implode( ', ', array_map( 'esc_sql', array_keys( $arr ) ) ); |
|
42 | - $field_values = "'" . implode( "', '", array_map( 'esc_sql', array_values( $arr ) ) ) . "'"; |
|
41 | + $field_names = implode(', ', array_map('esc_sql', array_keys($arr))); |
|
42 | + $field_values = "'".implode("', '", array_map('esc_sql', array_values($arr)))."'"; |
|
43 | 43 | |
44 | 44 | $update_stmt = implode( |
45 | 45 | ', ', |
46 | 46 | array_map( |
47 | - function ( $key ) use ( $arr ) { |
|
48 | - return "$key = '" . esc_sql( $arr[ $key ] ) . "'"; |
|
47 | + function($key) use ($arr) { |
|
48 | + return "$key = '".esc_sql($arr[$key])."'"; |
|
49 | 49 | }, |
50 | - array_keys( $arr ) |
|
50 | + array_keys($arr) |
|
51 | 51 | ) |
52 | 52 | ); |
53 | 53 | |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | ); |
61 | 61 | } |
62 | 62 | |
63 | - public function get_value( $key ) { |
|
63 | + public function get_value($key) { |
|
64 | 64 | global $wpdb; |
65 | 65 | |
66 | 66 | return $wpdb->get_var( |
67 | 67 | $wpdb->prepare( |
68 | - "SELECT $key FROM {$wpdb->prefix}wl_entities WHERE content_id = %d AND content_type = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
68 | + "SELECT $key FROM {$wpdb->prefix}wl_entities WHERE content_id = %d AND content_type = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
69 | 69 | $this->post_id, |
70 | 70 | Object_Type_Enum::POST |
71 | 71 | ) |
@@ -15,62 +15,62 @@ |
||
15 | 15 | */ |
16 | 16 | class Sync_Hooks_Entity_Relation { |
17 | 17 | |
18 | - /** |
|
19 | - * @var \Wordlift_Entity_Service |
|
20 | - */ |
|
21 | - private $entity_service; |
|
22 | - |
|
23 | - /** |
|
24 | - * Entity_Dct_Relation constructor. |
|
25 | - * |
|
26 | - * @param $entity_service \Wordlift_Entity_Service |
|
27 | - */ |
|
28 | - public function __construct( $entity_service ) { |
|
29 | - $this->entity_service = $entity_service; |
|
30 | - |
|
31 | - add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 ); |
|
32 | - } |
|
33 | - |
|
34 | - public function jsonld( $jsonld, $type, $post_id ) { |
|
35 | - |
|
36 | - // @@todo add support anything that isn't a POST. |
|
37 | - if ( Object_Type_Enum::POST !== $type ) { |
|
38 | - return $jsonld; |
|
39 | - } |
|
40 | - |
|
41 | - // Choose the dcterm property according to the post type. |
|
42 | - $property = $this->entity_service->is_entity( $post_id ) |
|
43 | - ? 'http://purl.org/dc/terms/relation' |
|
44 | - : 'http://purl.org/dc/terms/references'; |
|
45 | - |
|
46 | - $references = array_unique( $this->entity_service->get_related_entities( $post_id ) ); |
|
47 | - |
|
48 | - // Bail out if there are no references. |
|
49 | - if ( empty( $references ) ) { |
|
50 | - return $jsonld; |
|
51 | - } |
|
52 | - |
|
53 | - if ( ! isset( $jsonld[0][ $property ] ) ) { |
|
54 | - $jsonld[0][ $property ] = array(); |
|
55 | - } |
|
56 | - |
|
57 | - if ( ! is_array( $jsonld[0][ $property ] ) ) { |
|
58 | - $jsonld[0][ $property ] = array( $jsonld[0][ $property ] ); |
|
59 | - } |
|
60 | - |
|
61 | - $that = $this; |
|
62 | - $references_array = array_values( |
|
63 | - array_map( |
|
64 | - function ( $item ) use ( $that ) { |
|
65 | - return array( '@id' => $that->entity_service->get_uri( $item ) ); |
|
66 | - }, |
|
67 | - $references |
|
68 | - ) |
|
69 | - ); |
|
70 | - |
|
71 | - $jsonld[0][ $property ] = array_merge( $jsonld[0][ $property ], $references_array ); |
|
72 | - |
|
73 | - return $jsonld; |
|
74 | - } |
|
18 | + /** |
|
19 | + * @var \Wordlift_Entity_Service |
|
20 | + */ |
|
21 | + private $entity_service; |
|
22 | + |
|
23 | + /** |
|
24 | + * Entity_Dct_Relation constructor. |
|
25 | + * |
|
26 | + * @param $entity_service \Wordlift_Entity_Service |
|
27 | + */ |
|
28 | + public function __construct( $entity_service ) { |
|
29 | + $this->entity_service = $entity_service; |
|
30 | + |
|
31 | + add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 ); |
|
32 | + } |
|
33 | + |
|
34 | + public function jsonld( $jsonld, $type, $post_id ) { |
|
35 | + |
|
36 | + // @@todo add support anything that isn't a POST. |
|
37 | + if ( Object_Type_Enum::POST !== $type ) { |
|
38 | + return $jsonld; |
|
39 | + } |
|
40 | + |
|
41 | + // Choose the dcterm property according to the post type. |
|
42 | + $property = $this->entity_service->is_entity( $post_id ) |
|
43 | + ? 'http://purl.org/dc/terms/relation' |
|
44 | + : 'http://purl.org/dc/terms/references'; |
|
45 | + |
|
46 | + $references = array_unique( $this->entity_service->get_related_entities( $post_id ) ); |
|
47 | + |
|
48 | + // Bail out if there are no references. |
|
49 | + if ( empty( $references ) ) { |
|
50 | + return $jsonld; |
|
51 | + } |
|
52 | + |
|
53 | + if ( ! isset( $jsonld[0][ $property ] ) ) { |
|
54 | + $jsonld[0][ $property ] = array(); |
|
55 | + } |
|
56 | + |
|
57 | + if ( ! is_array( $jsonld[0][ $property ] ) ) { |
|
58 | + $jsonld[0][ $property ] = array( $jsonld[0][ $property ] ); |
|
59 | + } |
|
60 | + |
|
61 | + $that = $this; |
|
62 | + $references_array = array_values( |
|
63 | + array_map( |
|
64 | + function ( $item ) use ( $that ) { |
|
65 | + return array( '@id' => $that->entity_service->get_uri( $item ) ); |
|
66 | + }, |
|
67 | + $references |
|
68 | + ) |
|
69 | + ); |
|
70 | + |
|
71 | + $jsonld[0][ $property ] = array_merge( $jsonld[0][ $property ], $references_array ); |
|
72 | + |
|
73 | + return $jsonld; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
@@ -25,50 +25,50 @@ |
||
25 | 25 | * |
26 | 26 | * @param $entity_service \Wordlift_Entity_Service |
27 | 27 | */ |
28 | - public function __construct( $entity_service ) { |
|
28 | + public function __construct($entity_service) { |
|
29 | 29 | $this->entity_service = $entity_service; |
30 | 30 | |
31 | - add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 ); |
|
31 | + add_filter('wl_dataset__sync_service__sync_item__jsonld', array($this, 'jsonld'), 10, 3); |
|
32 | 32 | } |
33 | 33 | |
34 | - public function jsonld( $jsonld, $type, $post_id ) { |
|
34 | + public function jsonld($jsonld, $type, $post_id) { |
|
35 | 35 | |
36 | 36 | // @@todo add support anything that isn't a POST. |
37 | - if ( Object_Type_Enum::POST !== $type ) { |
|
37 | + if (Object_Type_Enum::POST !== $type) { |
|
38 | 38 | return $jsonld; |
39 | 39 | } |
40 | 40 | |
41 | 41 | // Choose the dcterm property according to the post type. |
42 | - $property = $this->entity_service->is_entity( $post_id ) |
|
42 | + $property = $this->entity_service->is_entity($post_id) |
|
43 | 43 | ? 'http://purl.org/dc/terms/relation' |
44 | 44 | : 'http://purl.org/dc/terms/references'; |
45 | 45 | |
46 | - $references = array_unique( $this->entity_service->get_related_entities( $post_id ) ); |
|
46 | + $references = array_unique($this->entity_service->get_related_entities($post_id)); |
|
47 | 47 | |
48 | 48 | // Bail out if there are no references. |
49 | - if ( empty( $references ) ) { |
|
49 | + if (empty($references)) { |
|
50 | 50 | return $jsonld; |
51 | 51 | } |
52 | 52 | |
53 | - if ( ! isset( $jsonld[0][ $property ] ) ) { |
|
54 | - $jsonld[0][ $property ] = array(); |
|
53 | + if ( ! isset($jsonld[0][$property])) { |
|
54 | + $jsonld[0][$property] = array(); |
|
55 | 55 | } |
56 | 56 | |
57 | - if ( ! is_array( $jsonld[0][ $property ] ) ) { |
|
58 | - $jsonld[0][ $property ] = array( $jsonld[0][ $property ] ); |
|
57 | + if ( ! is_array($jsonld[0][$property])) { |
|
58 | + $jsonld[0][$property] = array($jsonld[0][$property]); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $that = $this; |
62 | 62 | $references_array = array_values( |
63 | 63 | array_map( |
64 | - function ( $item ) use ( $that ) { |
|
65 | - return array( '@id' => $that->entity_service->get_uri( $item ) ); |
|
64 | + function($item) use ($that) { |
|
65 | + return array('@id' => $that->entity_service->get_uri($item)); |
|
66 | 66 | }, |
67 | 67 | $references |
68 | 68 | ) |
69 | 69 | ); |
70 | 70 | |
71 | - $jsonld[0][ $property ] = array_merge( $jsonld[0][ $property ], $references_array ); |
|
71 | + $jsonld[0][$property] = array_merge($jsonld[0][$property], $references_array); |
|
72 | 72 | |
73 | 73 | return $jsonld; |
74 | 74 | } |
@@ -4,27 +4,27 @@ |
||
4 | 4 | |
5 | 5 | abstract class Abstract_Sync_Hooks { |
6 | 6 | |
7 | - private $queue = array(); |
|
7 | + private $queue = array(); |
|
8 | 8 | |
9 | - public function __construct() { |
|
9 | + public function __construct() { |
|
10 | 10 | |
11 | - // To sync at the end of the usual WordPress lifecycle |
|
12 | - add_action( 'shutdown', array( $this, 'shutdown' ) ); |
|
11 | + // To sync at the end of the usual WordPress lifecycle |
|
12 | + add_action( 'shutdown', array( $this, 'shutdown' ) ); |
|
13 | 13 | |
14 | - } |
|
14 | + } |
|
15 | 15 | |
16 | - protected function enqueue( $item ) { |
|
16 | + protected function enqueue( $item ) { |
|
17 | 17 | |
18 | - if ( empty( $this->queue ) || $item !== $this->queue[ count( $this->queue ) - 1 ] ) { |
|
19 | - $this->queue[] = $item; |
|
20 | - } |
|
18 | + if ( empty( $this->queue ) || $item !== $this->queue[ count( $this->queue ) - 1 ] ) { |
|
19 | + $this->queue[] = $item; |
|
20 | + } |
|
21 | 21 | |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - public function shutdown() { |
|
25 | - foreach ( $this->queue as $callback ) { |
|
26 | - call_user_func( array( $this, $callback[0] ), $callback[1] ); |
|
27 | - } |
|
28 | - } |
|
24 | + public function shutdown() { |
|
25 | + foreach ( $this->queue as $callback ) { |
|
26 | + call_user_func( array( $this, $callback[0] ), $callback[1] ); |
|
27 | + } |
|
28 | + } |
|
29 | 29 | |
30 | 30 | } |
@@ -9,21 +9,21 @@ |
||
9 | 9 | public function __construct() { |
10 | 10 | |
11 | 11 | // To sync at the end of the usual WordPress lifecycle |
12 | - add_action( 'shutdown', array( $this, 'shutdown' ) ); |
|
12 | + add_action('shutdown', array($this, 'shutdown')); |
|
13 | 13 | |
14 | 14 | } |
15 | 15 | |
16 | - protected function enqueue( $item ) { |
|
16 | + protected function enqueue($item) { |
|
17 | 17 | |
18 | - if ( empty( $this->queue ) || $item !== $this->queue[ count( $this->queue ) - 1 ] ) { |
|
18 | + if (empty($this->queue) || $item !== $this->queue[count($this->queue) - 1]) { |
|
19 | 19 | $this->queue[] = $item; |
20 | 20 | } |
21 | 21 | |
22 | 22 | } |
23 | 23 | |
24 | 24 | public function shutdown() { |
25 | - foreach ( $this->queue as $callback ) { |
|
26 | - call_user_func( array( $this, $callback[0] ), $callback[1] ); |
|
25 | + foreach ($this->queue as $callback) { |
|
26 | + call_user_func(array($this, $callback[0]), $callback[1]); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 |