@@ -8,199 +8,199 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Filters { |
| 10 | 10 | |
| 11 | - const FIELD_NAME = 'wlentity'; |
|
| 12 | - |
|
| 13 | - public function __construct() { |
|
| 14 | - |
|
| 15 | - pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) ); |
|
| 16 | - add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 ); |
|
| 17 | - add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 ); |
|
| 18 | - add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 ); |
|
| 19 | - add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 ); |
|
| 20 | - add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 ); |
|
| 21 | - |
|
| 22 | - add_action( |
|
| 23 | - 'pods_meta_save_taxonomy', |
|
| 24 | - function ( $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ) { |
|
| 25 | - $this->save_field( 'term', $term_id, $groups ); |
|
| 26 | - }, |
|
| 27 | - 10, |
|
| 28 | - 8 |
|
| 29 | - ); |
|
| 30 | - |
|
| 31 | - add_action( |
|
| 32 | - 'pods_meta_save_post', |
|
| 33 | - function ( $data, $pod, $id, $groups ) { |
|
| 34 | - $this->save_field( 'post', $id, $groups ); |
|
| 35 | - }, |
|
| 36 | - 10, |
|
| 37 | - 4 |
|
| 38 | - ); |
|
| 39 | - |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - private function save_field( $type, $identifier, $groups ) { |
|
| 43 | - |
|
| 44 | - $entity_fields = $this->filter_entity_fields( $groups ); |
|
| 45 | - foreach ( $entity_fields as $entity_field ) { |
|
| 46 | - delete_metadata( $type, $identifier, $entity_field ); |
|
| 47 | - $key = sprintf( 'pods_meta_%s', $entity_field ); |
|
| 48 | - |
|
| 49 | - $data = filter_var_array( $_REQUEST, array( $key => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 50 | - |
|
| 51 | - if ( ! $data ) { |
|
| 52 | - continue; |
|
| 53 | - } |
|
| 54 | - $values = $data[ $key ]; |
|
| 55 | - |
|
| 56 | - foreach ( $values as $value ) { |
|
| 57 | - add_metadata( $type, $identifier, $entity_field, $value ); |
|
| 58 | - } |
|
| 59 | - } |
|
| 11 | + const FIELD_NAME = 'wlentity'; |
|
| 12 | + |
|
| 13 | + public function __construct() { |
|
| 14 | + |
|
| 15 | + pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) ); |
|
| 16 | + add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 ); |
|
| 17 | + add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 ); |
|
| 18 | + add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 ); |
|
| 19 | + add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 ); |
|
| 20 | + add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 ); |
|
| 21 | + |
|
| 22 | + add_action( |
|
| 23 | + 'pods_meta_save_taxonomy', |
|
| 24 | + function ( $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ) { |
|
| 25 | + $this->save_field( 'term', $term_id, $groups ); |
|
| 26 | + }, |
|
| 27 | + 10, |
|
| 28 | + 8 |
|
| 29 | + ); |
|
| 30 | + |
|
| 31 | + add_action( |
|
| 32 | + 'pods_meta_save_post', |
|
| 33 | + function ( $data, $pod, $id, $groups ) { |
|
| 34 | + $this->save_field( 'post', $id, $groups ); |
|
| 35 | + }, |
|
| 36 | + 10, |
|
| 37 | + 4 |
|
| 38 | + ); |
|
| 39 | + |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + private function save_field( $type, $identifier, $groups ) { |
|
| 43 | + |
|
| 44 | + $entity_fields = $this->filter_entity_fields( $groups ); |
|
| 45 | + foreach ( $entity_fields as $entity_field ) { |
|
| 46 | + delete_metadata( $type, $identifier, $entity_field ); |
|
| 47 | + $key = sprintf( 'pods_meta_%s', $entity_field ); |
|
| 48 | + |
|
| 49 | + $data = filter_var_array( $_REQUEST, array( $key => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 50 | + |
|
| 51 | + if ( ! $data ) { |
|
| 52 | + continue; |
|
| 53 | + } |
|
| 54 | + $values = $data[ $key ]; |
|
| 55 | + |
|
| 56 | + foreach ( $values as $value ) { |
|
| 57 | + add_metadata( $type, $identifier, $entity_field, $value ); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - } |
|
| 62 | - |
|
| 63 | - private function filter_entity_fields( $groups ) { |
|
| 64 | - |
|
| 65 | - $pods = json_decode( wp_json_encode( $groups ), true ); |
|
| 66 | - |
|
| 67 | - $fields = array_reduce( |
|
| 68 | - $pods, |
|
| 69 | - function ( $carry, $item ) { |
|
| 70 | - return array_merge( $carry, $item['fields'] ); |
|
| 71 | - }, |
|
| 72 | - array() |
|
| 73 | - ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + private function filter_entity_fields( $groups ) { |
|
| 64 | + |
|
| 65 | + $pods = json_decode( wp_json_encode( $groups ), true ); |
|
| 66 | + |
|
| 67 | + $fields = array_reduce( |
|
| 68 | + $pods, |
|
| 69 | + function ( $carry, $item ) { |
|
| 70 | + return array_merge( $carry, $item['fields'] ); |
|
| 71 | + }, |
|
| 72 | + array() |
|
| 73 | + ); |
|
| 74 | 74 | |
| 75 | - return array_map( |
|
| 76 | - function ( $item ) { |
|
| 77 | - return $item['name']; |
|
| 78 | - }, |
|
| 79 | - array_filter( |
|
| 80 | - $fields, |
|
| 81 | - function ( $item ) { |
|
| 82 | - return is_array( $item ) && isset( $item['pick_object'] ) && self::FIELD_NAME === $item['pick_object']; |
|
| 83 | - } |
|
| 84 | - ) |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function wl_pods_transform_data_for_pick_field( $item ) { |
|
| 89 | - |
|
| 90 | - $content = $item->get_content(); |
|
| 91 | - |
|
| 92 | - return array( |
|
| 93 | - 'id' => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ), |
|
| 94 | - 'icon' => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg', |
|
| 95 | - 'name' => $item->get_title() . ' (' . $item->get_schema_type() . ')', |
|
| 96 | - 'edit_link' => $content->get_edit_link(), |
|
| 97 | - 'link' => $content->get_permalink(), |
|
| 98 | - 'selected' => false, |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - public function admin_ajax_filter( $data, $name, $_, $field ) { |
|
| 104 | - |
|
| 105 | - if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) { |
|
| 106 | - return $data; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); |
|
| 110 | - $query_service = Entity_Query_Service::get_instance(); |
|
| 111 | - |
|
| 112 | - return array_map( |
|
| 113 | - array( |
|
| 114 | - $this, |
|
| 115 | - 'wl_pods_transform_data_for_pick_field', |
|
| 116 | - ), |
|
| 117 | - $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) |
|
| 118 | - ); |
|
| 119 | - |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - public function data_filter( $data, $args ) { |
|
| 123 | - |
|
| 124 | - $args_arr = json_decode( wp_json_encode( $args ), true ); |
|
| 125 | - $field_data = $args_arr['options']; |
|
| 126 | - |
|
| 127 | - if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) { |
|
| 128 | - return $data; |
|
| 129 | - } |
|
| 75 | + return array_map( |
|
| 76 | + function ( $item ) { |
|
| 77 | + return $item['name']; |
|
| 78 | + }, |
|
| 79 | + array_filter( |
|
| 80 | + $fields, |
|
| 81 | + function ( $item ) { |
|
| 82 | + return is_array( $item ) && isset( $item['pick_object'] ) && self::FIELD_NAME === $item['pick_object']; |
|
| 83 | + } |
|
| 84 | + ) |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function wl_pods_transform_data_for_pick_field( $item ) { |
|
| 89 | + |
|
| 90 | + $content = $item->get_content(); |
|
| 91 | + |
|
| 92 | + return array( |
|
| 93 | + 'id' => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ), |
|
| 94 | + 'icon' => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg', |
|
| 95 | + 'name' => $item->get_title() . ' (' . $item->get_schema_type() . ')', |
|
| 96 | + 'edit_link' => $content->get_edit_link(), |
|
| 97 | + 'link' => $content->get_permalink(), |
|
| 98 | + 'selected' => false, |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + public function admin_ajax_filter( $data, $name, $_, $field ) { |
|
| 104 | + |
|
| 105 | + if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) { |
|
| 106 | + return $data; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); |
|
| 110 | + $query_service = Entity_Query_Service::get_instance(); |
|
| 111 | + |
|
| 112 | + return array_map( |
|
| 113 | + array( |
|
| 114 | + $this, |
|
| 115 | + 'wl_pods_transform_data_for_pick_field', |
|
| 116 | + ), |
|
| 117 | + $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) |
|
| 118 | + ); |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + public function data_filter( $data, $args ) { |
|
| 123 | + |
|
| 124 | + $args_arr = json_decode( wp_json_encode( $args ), true ); |
|
| 125 | + $field_data = $args_arr['options']; |
|
| 126 | + |
|
| 127 | + if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) { |
|
| 128 | + return $data; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] ) |
|
| 132 | - || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) { |
|
| 133 | - return $data; |
|
| 134 | - } |
|
| 131 | + if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] ) |
|
| 132 | + || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) { |
|
| 133 | + return $data; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - $name = $field_data['name']; |
|
| 137 | - $identifier = $args->id; |
|
| 138 | - $type = $args_arr['pod']['data']['pod_data']['type']; |
|
| 136 | + $name = $field_data['name']; |
|
| 137 | + $identifier = $args->id; |
|
| 138 | + $type = $args_arr['pod']['data']['pod_data']['type']; |
|
| 139 | 139 | |
| 140 | - if ( 'post_type' === $type ) { |
|
| 141 | - $data['fieldValue'] = get_post_meta( $identifier, $name ); |
|
| 142 | - } elseif ( 'taxonomy' === $type ) { |
|
| 143 | - $data['fieldValue'] = get_term_meta( $identifier, $name ); |
|
| 144 | - } |
|
| 140 | + if ( 'post_type' === $type ) { |
|
| 141 | + $data['fieldValue'] = get_post_meta( $identifier, $name ); |
|
| 142 | + } elseif ( 'taxonomy' === $type ) { |
|
| 143 | + $data['fieldValue'] = get_term_meta( $identifier, $name ); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - return $data; |
|
| 147 | - } |
|
| 146 | + return $data; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | |
| 150 | - public function ajax_filter( $result, $name, $value, $field_options ) { |
|
| 151 | - |
|
| 152 | - if ( ! isset( $field_options['pick_object'] ) ) { |
|
| 153 | - return $result; |
|
| 154 | - } |
|
| 150 | + public function ajax_filter( $result, $name, $value, $field_options ) { |
|
| 151 | + |
|
| 152 | + if ( ! isset( $field_options['pick_object'] ) ) { |
|
| 153 | + return $result; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - return self::FIELD_NAME === $field_options['pick_object']; |
|
| 157 | - } |
|
| 156 | + return self::FIELD_NAME === $field_options['pick_object']; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) { |
|
| 159 | + public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) { |
|
| 160 | 160 | |
| 161 | - if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) { |
|
| 162 | - return $info; |
|
| 163 | - } |
|
| 164 | - // We need to return an non empty array here to prevent pods from querying a table. |
|
| 165 | - // This is necessary to prevent errors on ui. |
|
| 166 | - return array( 'foo' => 'bar' ); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) { |
|
| 171 | - |
|
| 172 | - $object_params = json_decode( wp_json_encode( $object_params ), true ); |
|
| 161 | + if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) { |
|
| 162 | + return $info; |
|
| 163 | + } |
|
| 164 | + // We need to return an non empty array here to prevent pods from querying a table. |
|
| 165 | + // This is necessary to prevent errors on ui. |
|
| 166 | + return array( 'foo' => 'bar' ); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) { |
|
| 171 | + |
|
| 172 | + $object_params = json_decode( wp_json_encode( $object_params ), true ); |
|
| 173 | 173 | |
| 174 | - $query_service = Entity_Query_Service::get_instance(); |
|
| 175 | - |
|
| 176 | - if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] ) |
|
| 177 | - && is_string( $object_params['options']['pick_object'] ) |
|
| 178 | - && self::FIELD_NAME === $object_params['options']['pick_object'] |
|
| 179 | - && isset( $object_params['pod']['data']['pod_data']['type'] ) |
|
| 180 | - && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) { |
|
| 174 | + $query_service = Entity_Query_Service::get_instance(); |
|
| 175 | + |
|
| 176 | + if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] ) |
|
| 177 | + && is_string( $object_params['options']['pick_object'] ) |
|
| 178 | + && self::FIELD_NAME === $object_params['options']['pick_object'] |
|
| 179 | + && isset( $object_params['pod']['data']['pod_data']['type'] ) |
|
| 180 | + && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) { |
|
| 181 | 181 | |
| 182 | - $type = $object_params['pod']['data']['pod_data']['type']; |
|
| 183 | - $linked_entities = array(); |
|
| 184 | - if ( 'post_type' === $type ) { |
|
| 185 | - $linked_entities = get_post_meta( $id, $name ); |
|
| 186 | - } elseif ( 'taxonomy' === $type ) { |
|
| 187 | - $linked_entities = get_term_meta( $id, $name ); |
|
| 188 | - } |
|
| 189 | - $data = array(); |
|
| 190 | - $linked_entities = $query_service->get( $linked_entities ); |
|
| 191 | - foreach ( $linked_entities as $linked_entity ) { |
|
| 192 | - $content = $linked_entity->get_content(); |
|
| 193 | - $id = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ); |
|
| 194 | - $text = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')'; |
|
| 195 | - $data[ $id ] = $text; |
|
| 196 | - } |
|
| 182 | + $type = $object_params['pod']['data']['pod_data']['type']; |
|
| 183 | + $linked_entities = array(); |
|
| 184 | + if ( 'post_type' === $type ) { |
|
| 185 | + $linked_entities = get_post_meta( $id, $name ); |
|
| 186 | + } elseif ( 'taxonomy' === $type ) { |
|
| 187 | + $linked_entities = get_term_meta( $id, $name ); |
|
| 188 | + } |
|
| 189 | + $data = array(); |
|
| 190 | + $linked_entities = $query_service->get( $linked_entities ); |
|
| 191 | + foreach ( $linked_entities as $linked_entity ) { |
|
| 192 | + $content = $linked_entity->get_content(); |
|
| 193 | + $id = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ); |
|
| 194 | + $text = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')'; |
|
| 195 | + $data[ $id ] = $text; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - return $data; |
|
| 199 | - } |
|
| 198 | + return $data; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return $_; |
|
| 201 | + return $_; |
|
| 202 | 202 | |
| 203 | - } |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | } |
@@ -12,17 +12,17 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function __construct() { |
| 14 | 14 | |
| 15 | - pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) ); |
|
| 16 | - add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 ); |
|
| 17 | - add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 ); |
|
| 18 | - add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 ); |
|
| 19 | - add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 ); |
|
| 20 | - add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 ); |
|
| 15 | + pods_register_related_object(self::FIELD_NAME, 'WordLift Entity', array('simple' => false)); |
|
| 16 | + add_filter('pods_form_ui_field_pick_ajax', array($this, 'ajax_filter'), 10, 4); |
|
| 17 | + add_filter('pods_api_get_table_info', array($this, 'table_info_filter'), 10, 6); |
|
| 18 | + add_filter('pods_field_pick_object_data', array($this, 'field_options_filter'), 10, 7); |
|
| 19 | + add_filter('pods_field_dfv_data', array($this, 'data_filter'), 10, 2); |
|
| 20 | + add_filter('pods_field_pick_data_ajax', array($this, 'admin_ajax_filter'), 10, 4); |
|
| 21 | 21 | |
| 22 | 22 | add_action( |
| 23 | 23 | 'pods_meta_save_taxonomy', |
| 24 | - function ( $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item ) { |
|
| 25 | - $this->save_field( 'term', $term_id, $groups ); |
|
| 24 | + function($data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item) { |
|
| 25 | + $this->save_field('term', $term_id, $groups); |
|
| 26 | 26 | }, |
| 27 | 27 | 10, |
| 28 | 28 | 8 |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | add_action( |
| 32 | 32 | 'pods_meta_save_post', |
| 33 | - function ( $data, $pod, $id, $groups ) { |
|
| 34 | - $this->save_field( 'post', $id, $groups ); |
|
| 33 | + function($data, $pod, $id, $groups) { |
|
| 34 | + $this->save_field('post', $id, $groups); |
|
| 35 | 35 | }, |
| 36 | 36 | 10, |
| 37 | 37 | 4 |
@@ -39,60 +39,60 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - private function save_field( $type, $identifier, $groups ) { |
|
| 42 | + private function save_field($type, $identifier, $groups) { |
|
| 43 | 43 | |
| 44 | - $entity_fields = $this->filter_entity_fields( $groups ); |
|
| 45 | - foreach ( $entity_fields as $entity_field ) { |
|
| 46 | - delete_metadata( $type, $identifier, $entity_field ); |
|
| 47 | - $key = sprintf( 'pods_meta_%s', $entity_field ); |
|
| 44 | + $entity_fields = $this->filter_entity_fields($groups); |
|
| 45 | + foreach ($entity_fields as $entity_field) { |
|
| 46 | + delete_metadata($type, $identifier, $entity_field); |
|
| 47 | + $key = sprintf('pods_meta_%s', $entity_field); |
|
| 48 | 48 | |
| 49 | - $data = filter_var_array( $_REQUEST, array( $key => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 49 | + $data = filter_var_array($_REQUEST, array($key => array('flags' => FILTER_REQUIRE_ARRAY))); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 50 | 50 | |
| 51 | - if ( ! $data ) { |
|
| 51 | + if ( ! $data) { |
|
| 52 | 52 | continue; |
| 53 | 53 | } |
| 54 | - $values = $data[ $key ]; |
|
| 54 | + $values = $data[$key]; |
|
| 55 | 55 | |
| 56 | - foreach ( $values as $value ) { |
|
| 57 | - add_metadata( $type, $identifier, $entity_field, $value ); |
|
| 56 | + foreach ($values as $value) { |
|
| 57 | + add_metadata($type, $identifier, $entity_field, $value); |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - private function filter_entity_fields( $groups ) { |
|
| 63 | + private function filter_entity_fields($groups) { |
|
| 64 | 64 | |
| 65 | - $pods = json_decode( wp_json_encode( $groups ), true ); |
|
| 65 | + $pods = json_decode(wp_json_encode($groups), true); |
|
| 66 | 66 | |
| 67 | 67 | $fields = array_reduce( |
| 68 | 68 | $pods, |
| 69 | - function ( $carry, $item ) { |
|
| 70 | - return array_merge( $carry, $item['fields'] ); |
|
| 69 | + function($carry, $item) { |
|
| 70 | + return array_merge($carry, $item['fields']); |
|
| 71 | 71 | }, |
| 72 | 72 | array() |
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | 75 | return array_map( |
| 76 | - function ( $item ) { |
|
| 76 | + function($item) { |
|
| 77 | 77 | return $item['name']; |
| 78 | 78 | }, |
| 79 | 79 | array_filter( |
| 80 | 80 | $fields, |
| 81 | - function ( $item ) { |
|
| 82 | - return is_array( $item ) && isset( $item['pick_object'] ) && self::FIELD_NAME === $item['pick_object']; |
|
| 81 | + function($item) { |
|
| 82 | + return is_array($item) && isset($item['pick_object']) && self::FIELD_NAME === $item['pick_object']; |
|
| 83 | 83 | } |
| 84 | 84 | ) |
| 85 | 85 | ); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - public function wl_pods_transform_data_for_pick_field( $item ) { |
|
| 88 | + public function wl_pods_transform_data_for_pick_field($item) { |
|
| 89 | 89 | |
| 90 | 90 | $content = $item->get_content(); |
| 91 | 91 | |
| 92 | 92 | return array( |
| 93 | - 'id' => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ), |
|
| 93 | + 'id' => sprintf('%s_%d', Object_Type_Enum::to_string($content->get_object_type_enum()), $content->get_id()), |
|
| 94 | 94 | 'icon' => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg', |
| 95 | - 'name' => $item->get_title() . ' (' . $item->get_schema_type() . ')', |
|
| 95 | + 'name' => $item->get_title().' ('.$item->get_schema_type().')', |
|
| 96 | 96 | 'edit_link' => $content->get_edit_link(), |
| 97 | 97 | 'link' => $content->get_permalink(), |
| 98 | 98 | 'selected' => false, |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | - public function admin_ajax_filter( $data, $name, $_, $field ) { |
|
| 103 | + public function admin_ajax_filter($data, $name, $_, $field) { |
|
| 104 | 104 | |
| 105 | - if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) { |
|
| 105 | + if (( ! $field instanceof \Pods\Whatsit\Field) || $field->get_arg('pick_object', false) !== self::FIELD_NAME) { |
|
| 106 | 106 | return $data; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); |
|
| 109 | + $query = sanitize_text_field(wp_unslash($_REQUEST['query'])); |
|
| 110 | 110 | $query_service = Entity_Query_Service::get_instance(); |
| 111 | 111 | |
| 112 | 112 | return array_map( |
@@ -114,22 +114,22 @@ discard block |
||
| 114 | 114 | $this, |
| 115 | 115 | 'wl_pods_transform_data_for_pick_field', |
| 116 | 116 | ), |
| 117 | - $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) |
|
| 117 | + $query_service->query($query, $field->get_arg('supported_schema_types', array('Thing'))) |
|
| 118 | 118 | ); |
| 119 | 119 | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public function data_filter( $data, $args ) { |
|
| 122 | + public function data_filter($data, $args) { |
|
| 123 | 123 | |
| 124 | - $args_arr = json_decode( wp_json_encode( $args ), true ); |
|
| 124 | + $args_arr = json_decode(wp_json_encode($args), true); |
|
| 125 | 125 | $field_data = $args_arr['options']; |
| 126 | 126 | |
| 127 | - if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) { |
|
| 127 | + if ( ! isset($field_data['pick_object']) || self::FIELD_NAME !== $field_data['pick_object']) { |
|
| 128 | 128 | return $data; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] ) |
|
| 132 | - || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) { |
|
| 131 | + if ( ! isset($args_arr['pod']['data']['pod_data']['type']) |
|
| 132 | + || ! is_string($args_arr['pod']['data']['pod_data']['type'])) { |
|
| 133 | 133 | return $data; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -137,62 +137,62 @@ discard block |
||
| 137 | 137 | $identifier = $args->id; |
| 138 | 138 | $type = $args_arr['pod']['data']['pod_data']['type']; |
| 139 | 139 | |
| 140 | - if ( 'post_type' === $type ) { |
|
| 141 | - $data['fieldValue'] = get_post_meta( $identifier, $name ); |
|
| 142 | - } elseif ( 'taxonomy' === $type ) { |
|
| 143 | - $data['fieldValue'] = get_term_meta( $identifier, $name ); |
|
| 140 | + if ('post_type' === $type) { |
|
| 141 | + $data['fieldValue'] = get_post_meta($identifier, $name); |
|
| 142 | + } elseif ('taxonomy' === $type) { |
|
| 143 | + $data['fieldValue'] = get_term_meta($identifier, $name); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | return $data; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
| 150 | - public function ajax_filter( $result, $name, $value, $field_options ) { |
|
| 150 | + public function ajax_filter($result, $name, $value, $field_options) { |
|
| 151 | 151 | |
| 152 | - if ( ! isset( $field_options['pick_object'] ) ) { |
|
| 152 | + if ( ! isset($field_options['pick_object'])) { |
|
| 153 | 153 | return $result; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | return self::FIELD_NAME === $field_options['pick_object']; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) { |
|
| 159 | + public function table_info_filter($info, $object_type, $object, $name, $pod, $field) { |
|
| 160 | 160 | |
| 161 | - if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) { |
|
| 161 | + if ($field === null || self::FIELD_NAME !== $field->get_arg('pick_object', false)) { |
|
| 162 | 162 | return $info; |
| 163 | 163 | } |
| 164 | 164 | // We need to return an non empty array here to prevent pods from querying a table. |
| 165 | 165 | // This is necessary to prevent errors on ui. |
| 166 | - return array( 'foo' => 'bar' ); |
|
| 166 | + return array('foo' => 'bar'); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
| 170 | - public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) { |
|
| 170 | + public function field_options_filter($_, $name, $value, $options, $pod, $id, $object_params) { |
|
| 171 | 171 | |
| 172 | - $object_params = json_decode( wp_json_encode( $object_params ), true ); |
|
| 172 | + $object_params = json_decode(wp_json_encode($object_params), true); |
|
| 173 | 173 | |
| 174 | 174 | $query_service = Entity_Query_Service::get_instance(); |
| 175 | 175 | |
| 176 | - if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] ) |
|
| 177 | - && is_string( $object_params['options']['pick_object'] ) |
|
| 176 | + if (is_array($object_params) && isset($object_params['options']['pick_object']) |
|
| 177 | + && is_string($object_params['options']['pick_object']) |
|
| 178 | 178 | && self::FIELD_NAME === $object_params['options']['pick_object'] |
| 179 | - && isset( $object_params['pod']['data']['pod_data']['type'] ) |
|
| 180 | - && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) { |
|
| 179 | + && isset($object_params['pod']['data']['pod_data']['type']) |
|
| 180 | + && is_string($object_params['pod']['data']['pod_data']['type'])) { |
|
| 181 | 181 | |
| 182 | 182 | $type = $object_params['pod']['data']['pod_data']['type']; |
| 183 | 183 | $linked_entities = array(); |
| 184 | - if ( 'post_type' === $type ) { |
|
| 185 | - $linked_entities = get_post_meta( $id, $name ); |
|
| 186 | - } elseif ( 'taxonomy' === $type ) { |
|
| 187 | - $linked_entities = get_term_meta( $id, $name ); |
|
| 184 | + if ('post_type' === $type) { |
|
| 185 | + $linked_entities = get_post_meta($id, $name); |
|
| 186 | + } elseif ('taxonomy' === $type) { |
|
| 187 | + $linked_entities = get_term_meta($id, $name); |
|
| 188 | 188 | } |
| 189 | 189 | $data = array(); |
| 190 | - $linked_entities = $query_service->get( $linked_entities ); |
|
| 191 | - foreach ( $linked_entities as $linked_entity ) { |
|
| 190 | + $linked_entities = $query_service->get($linked_entities); |
|
| 191 | + foreach ($linked_entities as $linked_entity) { |
|
| 192 | 192 | $content = $linked_entity->get_content(); |
| 193 | - $id = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ); |
|
| 194 | - $text = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')'; |
|
| 195 | - $data[ $id ] = $text; |
|
| 193 | + $id = sprintf('%s_%d', Object_Type_Enum::to_string($content->get_object_type_enum()), $content->get_id()); |
|
| 194 | + $text = $linked_entity->get_title().' ('.$linked_entity->get_schema_type().')'; |
|
| 195 | + $data[$id] = $text; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | return $data; |
@@ -19,17 +19,17 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | if ( ! defined( 'ABSPATH' ) ) { |
| 22 | - exit; |
|
| 22 | + exit; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
| 30 | 30 | // Autoloader for plugin itself. |
| 31 | 31 | if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
| 32 | - require __DIR__ . '/vendor/autoload.php'; |
|
| 32 | + require __DIR__ . '/vendor/autoload.php'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -39,31 +39,31 @@ discard block |
||
| 39 | 39 | $container_builder->compile(); |
| 40 | 40 | |
| 41 | 41 | add_action( |
| 42 | - 'plugins_loaded', |
|
| 43 | - function () use ( $container_builder ) { |
|
| 42 | + 'plugins_loaded', |
|
| 43 | + function () use ( $container_builder ) { |
|
| 44 | 44 | |
| 45 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 46 | - $field_definition = $factory->get_field_definition(); |
|
| 47 | - $field_definition->register(); |
|
| 45 | + $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 46 | + $field_definition = $factory->get_field_definition(); |
|
| 47 | + $field_definition->register(); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var $installer \Wordlift\Modules\Pods\Installer |
|
| 51 | - */ |
|
| 52 | - $installer = $container_builder->get( Installer::class ); |
|
| 53 | - $installer->register_hooks(); |
|
| 49 | + /** |
|
| 50 | + * @var $installer \Wordlift\Modules\Pods\Installer |
|
| 51 | + */ |
|
| 52 | + $installer = $container_builder->get( Installer::class ); |
|
| 53 | + $installer->register_hooks(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var $notices \Wordlift\Modules\Pods\Notices |
|
| 57 | - */ |
|
| 58 | - $notices = $container_builder->get( Notices::class ); |
|
| 59 | - $notices->register_hooks(); |
|
| 55 | + /** |
|
| 56 | + * @var $notices \Wordlift\Modules\Pods\Notices |
|
| 57 | + */ |
|
| 58 | + $notices = $container_builder->get( Notices::class ); |
|
| 59 | + $notices->register_hooks(); |
|
| 60 | 60 | |
| 61 | - $filters = $container_builder->get( Filters::class ); |
|
| 61 | + $filters = $container_builder->get( Filters::class ); |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | ); |
| 68 | 68 | |
| 69 | 69 | |
@@ -18,47 +18,47 @@ |
||
| 18 | 18 | use Wordlift\Modules\Pods\Installer; |
| 19 | 19 | |
| 20 | 20 | |
| 21 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 21 | +if ( ! defined('ABSPATH')) { |
|
| 22 | 22 | exit; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { |
|
| 25 | +if ( ! apply_filters('wl_feature__enable__pods-integration', false)) { |
|
| 26 | 26 | return; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
| 30 | 30 | // Autoloader for plugin itself. |
| 31 | -if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
| 32 | - require __DIR__ . '/vendor/autoload.php'; |
|
| 31 | +if (file_exists(__DIR__.'/vendor/autoload.php')) { |
|
| 32 | + require __DIR__.'/vendor/autoload.php'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | $container_builder = new ContainerBuilder(); |
| 37 | -$loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 38 | -$loader->load( 'services.yml' ); |
|
| 37 | +$loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
| 38 | +$loader->load('services.yml'); |
|
| 39 | 39 | $container_builder->compile(); |
| 40 | 40 | |
| 41 | 41 | add_action( |
| 42 | 42 | 'plugins_loaded', |
| 43 | - function () use ( $container_builder ) { |
|
| 43 | + function() use ($container_builder) { |
|
| 44 | 44 | |
| 45 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 45 | + $factory = $container_builder->get(FieldDefinitionFactory::class); |
|
| 46 | 46 | $field_definition = $factory->get_field_definition(); |
| 47 | 47 | $field_definition->register(); |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @var $installer \Wordlift\Modules\Pods\Installer |
| 51 | 51 | */ |
| 52 | - $installer = $container_builder->get( Installer::class ); |
|
| 52 | + $installer = $container_builder->get(Installer::class); |
|
| 53 | 53 | $installer->register_hooks(); |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * @var $notices \Wordlift\Modules\Pods\Notices |
| 57 | 57 | */ |
| 58 | - $notices = $container_builder->get( Notices::class ); |
|
| 58 | + $notices = $container_builder->get(Notices::class); |
|
| 59 | 59 | $notices->register_hooks(); |
| 60 | 60 | |
| 61 | - $filters = $container_builder->get( Filters::class ); |
|
| 61 | + $filters = $container_builder->get(Filters::class); |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | |