@@ -15,64 +15,64 @@ |
||
15 | 15 | */ |
16 | 16 | class Taxonomy_Option { |
17 | 17 | |
18 | - /** |
|
19 | - * This value is used in rule field one and rule field two |
|
20 | - * options are linked to one by this value |
|
21 | - */ |
|
22 | - const PARENT_VALUE = 'taxonomy'; |
|
18 | + /** |
|
19 | + * This value is used in rule field one and rule field two |
|
20 | + * options are linked to one by this value |
|
21 | + */ |
|
22 | + const PARENT_VALUE = 'taxonomy'; |
|
23 | 23 | |
24 | - public function add_taxonomy_option() { |
|
25 | - $this->add_rule_field_one_options(); |
|
26 | - $this->add_rule_field_two_options(); |
|
27 | - } |
|
24 | + public function add_taxonomy_option() { |
|
25 | + $this->add_rule_field_one_options(); |
|
26 | + $this->add_rule_field_two_options(); |
|
27 | + } |
|
28 | 28 | |
29 | - private function add_rule_field_one_options() { |
|
29 | + private function add_rule_field_one_options() { |
|
30 | 30 | |
31 | - add_filter( |
|
32 | - 'wl_mappings_rule_field_one_options', |
|
33 | - function ( $rule_field_one_options ) { |
|
31 | + add_filter( |
|
32 | + 'wl_mappings_rule_field_one_options', |
|
33 | + function ( $rule_field_one_options ) { |
|
34 | 34 | |
35 | - $rule_field_one_options[] = array( |
|
36 | - 'label' => __( 'Taxonomy', 'wordlift' ), |
|
37 | - 'value' => Taxonomy_Option::PARENT_VALUE, |
|
38 | - // Left empty since these values are provided locally, not needed to be fetched from |
|
39 | - // api. |
|
40 | - 'api_source' => '', |
|
41 | - ); |
|
35 | + $rule_field_one_options[] = array( |
|
36 | + 'label' => __( 'Taxonomy', 'wordlift' ), |
|
37 | + 'value' => Taxonomy_Option::PARENT_VALUE, |
|
38 | + // Left empty since these values are provided locally, not needed to be fetched from |
|
39 | + // api. |
|
40 | + 'api_source' => '', |
|
41 | + ); |
|
42 | 42 | |
43 | - return $rule_field_one_options; |
|
43 | + return $rule_field_one_options; |
|
44 | 44 | |
45 | - } |
|
46 | - ); |
|
47 | - } |
|
45 | + } |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | - private function add_rule_field_two_options() { |
|
49 | + private function add_rule_field_two_options() { |
|
50 | 50 | |
51 | - add_filter( |
|
52 | - 'wl_mappings_rule_field_two_options', |
|
53 | - function ( $rule_field_two_options ) { |
|
51 | + add_filter( |
|
52 | + 'wl_mappings_rule_field_two_options', |
|
53 | + function ( $rule_field_two_options ) { |
|
54 | 54 | |
55 | - $taxonomies = get_object_taxonomies( 'post', 'objects' ); |
|
55 | + $taxonomies = get_object_taxonomies( 'post', 'objects' ); |
|
56 | 56 | |
57 | - $taxonomy_options = array(); |
|
57 | + $taxonomy_options = array(); |
|
58 | 58 | |
59 | - foreach ( $taxonomies as $item ) { |
|
60 | - /** |
|
61 | - * $item Taxonomy |
|
62 | - */ |
|
63 | - $taxonomy_options[] = array( |
|
64 | - 'label' => $item->label, |
|
65 | - 'value' => $item->name, |
|
66 | - // The value of parent option on rule field one. |
|
67 | - 'parent_value' => Taxonomy_Option::PARENT_VALUE, |
|
68 | - ); |
|
69 | - } |
|
59 | + foreach ( $taxonomies as $item ) { |
|
60 | + /** |
|
61 | + * $item Taxonomy |
|
62 | + */ |
|
63 | + $taxonomy_options[] = array( |
|
64 | + 'label' => $item->label, |
|
65 | + 'value' => $item->name, |
|
66 | + // The value of parent option on rule field one. |
|
67 | + 'parent_value' => Taxonomy_Option::PARENT_VALUE, |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | - return array_merge( $rule_field_two_options, $taxonomy_options ); |
|
71 | + return array_merge( $rule_field_two_options, $taxonomy_options ); |
|
72 | 72 | |
73 | - } |
|
74 | - ); |
|
73 | + } |
|
74 | + ); |
|
75 | 75 | |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | 78 | } |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | |
31 | 31 | add_filter( |
32 | 32 | 'wl_mappings_rule_field_one_options', |
33 | - function ( $rule_field_one_options ) { |
|
33 | + function($rule_field_one_options) { |
|
34 | 34 | |
35 | 35 | $rule_field_one_options[] = array( |
36 | - 'label' => __( 'Taxonomy', 'wordlift' ), |
|
36 | + 'label' => __('Taxonomy', 'wordlift'), |
|
37 | 37 | 'value' => Taxonomy_Option::PARENT_VALUE, |
38 | 38 | // Left empty since these values are provided locally, not needed to be fetched from |
39 | 39 | // api. |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | |
51 | 51 | add_filter( |
52 | 52 | 'wl_mappings_rule_field_two_options', |
53 | - function ( $rule_field_two_options ) { |
|
53 | + function($rule_field_two_options) { |
|
54 | 54 | |
55 | - $taxonomies = get_object_taxonomies( 'post', 'objects' ); |
|
55 | + $taxonomies = get_object_taxonomies('post', 'objects'); |
|
56 | 56 | |
57 | 57 | $taxonomy_options = array(); |
58 | 58 | |
59 | - foreach ( $taxonomies as $item ) { |
|
59 | + foreach ($taxonomies as $item) { |
|
60 | 60 | /** |
61 | 61 | * $item Taxonomy |
62 | 62 | */ |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | ); |
69 | 69 | } |
70 | 70 | |
71 | - return array_merge( $rule_field_two_options, $taxonomy_options ); |
|
71 | + return array_merge($rule_field_two_options, $taxonomy_options); |
|
72 | 72 | |
73 | 73 | } |
74 | 74 | ); |
@@ -11,44 +11,44 @@ |
||
11 | 11 | |
12 | 12 | class Data_Source_Factory { |
13 | 13 | |
14 | - private static $instance = null; |
|
15 | - |
|
16 | - private $data_sources = array(); |
|
17 | - |
|
18 | - public function __construct() { |
|
19 | - $this->data_sources = array( |
|
20 | - 'acf' => new Acf_Data_Source(), |
|
21 | - 'meta' => new Meta_Data_Source(), |
|
22 | - ); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @param $identifier int post id or term id based on type. |
|
27 | - * @param $property_data array |
|
28 | - * @param $type string post or term. |
|
29 | - * |
|
30 | - * @return mixed |
|
31 | - */ |
|
32 | - public function get_data( $identifier, $property_data, $type ) { |
|
33 | - switch ( $property_data['field_type'] ) { |
|
34 | - case Jsonld_Converter::FIELD_TYPE_ACF: |
|
35 | - return $this->data_sources['acf']->get_data( $identifier, $property_data, $type ); |
|
36 | - case Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD: |
|
37 | - return $this->data_sources['meta']->get_data( $identifier, $property_data, $type ); |
|
38 | - default: |
|
39 | - return $property_data['field_name']; |
|
40 | - } |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @return Data_Source_Factory |
|
45 | - */ |
|
46 | - public static function get_instance() { |
|
47 | - if ( null === self::$instance ) { |
|
48 | - self::$instance = new Data_Source_Factory(); |
|
49 | - } |
|
50 | - |
|
51 | - return self::$instance; |
|
52 | - } |
|
14 | + private static $instance = null; |
|
15 | + |
|
16 | + private $data_sources = array(); |
|
17 | + |
|
18 | + public function __construct() { |
|
19 | + $this->data_sources = array( |
|
20 | + 'acf' => new Acf_Data_Source(), |
|
21 | + 'meta' => new Meta_Data_Source(), |
|
22 | + ); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @param $identifier int post id or term id based on type. |
|
27 | + * @param $property_data array |
|
28 | + * @param $type string post or term. |
|
29 | + * |
|
30 | + * @return mixed |
|
31 | + */ |
|
32 | + public function get_data( $identifier, $property_data, $type ) { |
|
33 | + switch ( $property_data['field_type'] ) { |
|
34 | + case Jsonld_Converter::FIELD_TYPE_ACF: |
|
35 | + return $this->data_sources['acf']->get_data( $identifier, $property_data, $type ); |
|
36 | + case Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD: |
|
37 | + return $this->data_sources['meta']->get_data( $identifier, $property_data, $type ); |
|
38 | + default: |
|
39 | + return $property_data['field_name']; |
|
40 | + } |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @return Data_Source_Factory |
|
45 | + */ |
|
46 | + public static function get_instance() { |
|
47 | + if ( null === self::$instance ) { |
|
48 | + self::$instance = new Data_Source_Factory(); |
|
49 | + } |
|
50 | + |
|
51 | + return self::$instance; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | } |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return mixed |
31 | 31 | */ |
32 | - public function get_data( $identifier, $property_data, $type ) { |
|
33 | - switch ( $property_data['field_type'] ) { |
|
32 | + public function get_data($identifier, $property_data, $type) { |
|
33 | + switch ($property_data['field_type']) { |
|
34 | 34 | case Jsonld_Converter::FIELD_TYPE_ACF: |
35 | - return $this->data_sources['acf']->get_data( $identifier, $property_data, $type ); |
|
35 | + return $this->data_sources['acf']->get_data($identifier, $property_data, $type); |
|
36 | 36 | case Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD: |
37 | - return $this->data_sources['meta']->get_data( $identifier, $property_data, $type ); |
|
37 | + return $this->data_sources['meta']->get_data($identifier, $property_data, $type); |
|
38 | 38 | default: |
39 | 39 | return $property_data['field_name']; |
40 | 40 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @return Data_Source_Factory |
45 | 45 | */ |
46 | 46 | public static function get_instance() { |
47 | - if ( null === self::$instance ) { |
|
47 | + if (null === self::$instance) { |
|
48 | 48 | self::$instance = new Data_Source_Factory(); |
49 | 49 | } |
50 | 50 |
@@ -11,63 +11,63 @@ |
||
11 | 11 | |
12 | 12 | class Acf_Data_Source implements Abstract_Data_Source { |
13 | 13 | |
14 | - public function get_data( $identifier, $property_data, $type ) { |
|
14 | + public function get_data( $identifier, $property_data, $type ) { |
|
15 | 15 | |
16 | - if ( ! function_exists( 'get_field' ) || ! function_exists( 'get_field_object' ) ) { |
|
17 | - return array(); |
|
18 | - } |
|
16 | + if ( ! function_exists( 'get_field' ) || ! function_exists( 'get_field_object' ) ) { |
|
17 | + return array(); |
|
18 | + } |
|
19 | 19 | |
20 | - return $this->get_data_for_acf_field( $property_data['field_name'], $identifier, $type ); |
|
21 | - } |
|
20 | + return $this->get_data_for_acf_field( $property_data['field_name'], $identifier, $type ); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Gets data from acf, format the data if it is a repeater field. |
|
25 | - * |
|
26 | - * @param $field_name string |
|
27 | - * @param $identifier int Identifier ( post id or term id ) |
|
28 | - * |
|
29 | - * @return array|mixed |
|
30 | - */ |
|
31 | - private function get_data_for_acf_field( $field_name, $identifier, $type ) { |
|
32 | - if ( Jsonld_Converter::TERM === $type ) { |
|
33 | - $term = get_term( $identifier ); |
|
34 | - // Data fetching method for term is different. |
|
35 | - $field_data = get_field_object( $field_name, $term ); |
|
36 | - $data = get_field( $field_name, $term ); |
|
37 | - } else { |
|
38 | - $field_data = get_field_object( $field_name, $identifier ); |
|
39 | - $data = get_field( $field_name, $identifier ); |
|
40 | - } |
|
41 | - // only process if it is a repeater field, else return the data. |
|
42 | - if ( is_array( $field_data ) && array_key_exists( 'type', $field_data ) |
|
43 | - && 'repeater' === $field_data['type'] ) { |
|
44 | - /** |
|
45 | - * check if we have only one sub field, currently we only support one subfield, |
|
46 | - * so each repeater item should be checked if there is a single sub field. |
|
47 | - */ |
|
48 | - if ( is_array( $data ) && |
|
49 | - count( $data ) > 0 && |
|
50 | - count( array_keys( $data[0] ) ) === 1 ) { |
|
51 | - $repeater_formatted_data = array(); |
|
52 | - foreach ( $data as $item ) { |
|
53 | - $repeater_formatted_data = array_merge( $repeater_formatted_data, array_values( $item ) ); |
|
54 | - } |
|
55 | - // Remove non unique values. |
|
56 | - $repeater_formatted_data = array_unique( $repeater_formatted_data ); |
|
57 | - // Remove empty values |
|
58 | - $repeater_formatted_data = array_filter( |
|
59 | - $repeater_formatted_data, |
|
60 | - function ( $item ) { |
|
61 | - return is_array( $item ) || strlen( $item ); |
|
62 | - } |
|
63 | - ); |
|
23 | + /** |
|
24 | + * Gets data from acf, format the data if it is a repeater field. |
|
25 | + * |
|
26 | + * @param $field_name string |
|
27 | + * @param $identifier int Identifier ( post id or term id ) |
|
28 | + * |
|
29 | + * @return array|mixed |
|
30 | + */ |
|
31 | + private function get_data_for_acf_field( $field_name, $identifier, $type ) { |
|
32 | + if ( Jsonld_Converter::TERM === $type ) { |
|
33 | + $term = get_term( $identifier ); |
|
34 | + // Data fetching method for term is different. |
|
35 | + $field_data = get_field_object( $field_name, $term ); |
|
36 | + $data = get_field( $field_name, $term ); |
|
37 | + } else { |
|
38 | + $field_data = get_field_object( $field_name, $identifier ); |
|
39 | + $data = get_field( $field_name, $identifier ); |
|
40 | + } |
|
41 | + // only process if it is a repeater field, else return the data. |
|
42 | + if ( is_array( $field_data ) && array_key_exists( 'type', $field_data ) |
|
43 | + && 'repeater' === $field_data['type'] ) { |
|
44 | + /** |
|
45 | + * check if we have only one sub field, currently we only support one subfield, |
|
46 | + * so each repeater item should be checked if there is a single sub field. |
|
47 | + */ |
|
48 | + if ( is_array( $data ) && |
|
49 | + count( $data ) > 0 && |
|
50 | + count( array_keys( $data[0] ) ) === 1 ) { |
|
51 | + $repeater_formatted_data = array(); |
|
52 | + foreach ( $data as $item ) { |
|
53 | + $repeater_formatted_data = array_merge( $repeater_formatted_data, array_values( $item ) ); |
|
54 | + } |
|
55 | + // Remove non unique values. |
|
56 | + $repeater_formatted_data = array_unique( $repeater_formatted_data ); |
|
57 | + // Remove empty values |
|
58 | + $repeater_formatted_data = array_filter( |
|
59 | + $repeater_formatted_data, |
|
60 | + function ( $item ) { |
|
61 | + return is_array( $item ) || strlen( $item ); |
|
62 | + } |
|
63 | + ); |
|
64 | 64 | |
65 | - // re-index all the values. |
|
66 | - return array_values( $repeater_formatted_data ); |
|
67 | - } |
|
68 | - } |
|
65 | + // re-index all the values. |
|
66 | + return array_values( $repeater_formatted_data ); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - // Return normal acf data if it is not a repeater field. |
|
71 | - return $data; |
|
72 | - } |
|
70 | + // Return normal acf data if it is not a repeater field. |
|
71 | + return $data; |
|
72 | + } |
|
73 | 73 | } |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | |
12 | 12 | class Acf_Data_Source implements Abstract_Data_Source { |
13 | 13 | |
14 | - public function get_data( $identifier, $property_data, $type ) { |
|
14 | + public function get_data($identifier, $property_data, $type) { |
|
15 | 15 | |
16 | - if ( ! function_exists( 'get_field' ) || ! function_exists( 'get_field_object' ) ) { |
|
16 | + if ( ! function_exists('get_field') || ! function_exists('get_field_object')) { |
|
17 | 17 | return array(); |
18 | 18 | } |
19 | 19 | |
20 | - return $this->get_data_for_acf_field( $property_data['field_name'], $identifier, $type ); |
|
20 | + return $this->get_data_for_acf_field($property_data['field_name'], $identifier, $type); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -28,42 +28,42 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return array|mixed |
30 | 30 | */ |
31 | - private function get_data_for_acf_field( $field_name, $identifier, $type ) { |
|
32 | - if ( Jsonld_Converter::TERM === $type ) { |
|
33 | - $term = get_term( $identifier ); |
|
31 | + private function get_data_for_acf_field($field_name, $identifier, $type) { |
|
32 | + if (Jsonld_Converter::TERM === $type) { |
|
33 | + $term = get_term($identifier); |
|
34 | 34 | // Data fetching method for term is different. |
35 | - $field_data = get_field_object( $field_name, $term ); |
|
36 | - $data = get_field( $field_name, $term ); |
|
35 | + $field_data = get_field_object($field_name, $term); |
|
36 | + $data = get_field($field_name, $term); |
|
37 | 37 | } else { |
38 | - $field_data = get_field_object( $field_name, $identifier ); |
|
39 | - $data = get_field( $field_name, $identifier ); |
|
38 | + $field_data = get_field_object($field_name, $identifier); |
|
39 | + $data = get_field($field_name, $identifier); |
|
40 | 40 | } |
41 | 41 | // only process if it is a repeater field, else return the data. |
42 | - if ( is_array( $field_data ) && array_key_exists( 'type', $field_data ) |
|
43 | - && 'repeater' === $field_data['type'] ) { |
|
42 | + if (is_array($field_data) && array_key_exists('type', $field_data) |
|
43 | + && 'repeater' === $field_data['type']) { |
|
44 | 44 | /** |
45 | 45 | * check if we have only one sub field, currently we only support one subfield, |
46 | 46 | * so each repeater item should be checked if there is a single sub field. |
47 | 47 | */ |
48 | - if ( is_array( $data ) && |
|
49 | - count( $data ) > 0 && |
|
50 | - count( array_keys( $data[0] ) ) === 1 ) { |
|
48 | + if (is_array($data) && |
|
49 | + count($data) > 0 && |
|
50 | + count(array_keys($data[0])) === 1) { |
|
51 | 51 | $repeater_formatted_data = array(); |
52 | - foreach ( $data as $item ) { |
|
53 | - $repeater_formatted_data = array_merge( $repeater_formatted_data, array_values( $item ) ); |
|
52 | + foreach ($data as $item) { |
|
53 | + $repeater_formatted_data = array_merge($repeater_formatted_data, array_values($item)); |
|
54 | 54 | } |
55 | 55 | // Remove non unique values. |
56 | - $repeater_formatted_data = array_unique( $repeater_formatted_data ); |
|
56 | + $repeater_formatted_data = array_unique($repeater_formatted_data); |
|
57 | 57 | // Remove empty values |
58 | 58 | $repeater_formatted_data = array_filter( |
59 | 59 | $repeater_formatted_data, |
60 | - function ( $item ) { |
|
61 | - return is_array( $item ) || strlen( $item ); |
|
60 | + function($item) { |
|
61 | + return is_array($item) || strlen($item); |
|
62 | 62 | } |
63 | 63 | ); |
64 | 64 | |
65 | 65 | // re-index all the values. |
66 | - return array_values( $repeater_formatted_data ); |
|
66 | + return array_values($repeater_formatted_data); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 |
@@ -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 |