@@ -7,21 +7,21 @@ |
||
| 7 | 7 | |
| 8 | 8 | class FieldDefinitionFactory { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @var $schema Schema |
|
| 12 | - */ |
|
| 13 | - private $schema; |
|
| 10 | + /** |
|
| 11 | + * @var $schema Schema |
|
| 12 | + */ |
|
| 13 | + private $schema; |
|
| 14 | 14 | |
| 15 | - public function __construct( $schema ) { |
|
| 16 | - $this->schema = $schema; |
|
| 17 | - } |
|
| 15 | + public function __construct( $schema ) { |
|
| 16 | + $this->schema = $schema; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - public function get_field_definition() { |
|
| 21 | - $context = $this->schema->get(); |
|
| 22 | - // For now we are registering all the pods. |
|
| 23 | - return new AllPodsDefiniton( $context ); |
|
| 24 | - } |
|
| 20 | + public function get_field_definition() { |
|
| 21 | + $context = $this->schema->get(); |
|
| 22 | + // For now we are registering all the pods. |
|
| 23 | + return new AllPodsDefiniton( $context ); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | } |
@@ -4,11 +4,11 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface FieldDefinition { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * Register the fields for the provided context in constructor. |
|
| 9 | - * @return void |
|
| 10 | - */ |
|
| 11 | - public function register(); |
|
| 7 | + /** |
|
| 8 | + * Register the fields for the provided context in constructor. |
|
| 9 | + * @return void |
|
| 10 | + */ |
|
| 11 | + public function register(); |
|
| 12 | 12 | |
| 13 | 13 | } |
| 14 | 14 | |
@@ -11,27 +11,27 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class AllPodsDefiniton extends AbstractFieldDefiniton { |
| 13 | 13 | |
| 14 | - public function register() { |
|
| 14 | + public function register() { |
|
| 15 | 15 | |
| 16 | - add_action( 'init', array( $this, 'register_on_all_valid_post_types' ) ); |
|
| 17 | - add_action( 'setup_theme', array( $this, 'register_on_all_supported_taxonomies' ) ); |
|
| 18 | - } |
|
| 16 | + add_action( 'init', array( $this, 'register_on_all_valid_post_types' ) ); |
|
| 17 | + add_action( 'setup_theme', array( $this, 'register_on_all_supported_taxonomies' ) ); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | - public function register_on_all_supported_taxonomies() { |
|
| 22 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 23 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 24 | - $this->register_pod( $taxonomy, 'taxonomy', $this->context ); |
|
| 21 | + public function register_on_all_supported_taxonomies() { |
|
| 22 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 23 | + foreach ( $taxonomies as $taxonomy ) { |
|
| 24 | + $this->register_pod( $taxonomy, 'taxonomy', $this->context ); |
|
| 25 | 25 | |
| 26 | - } |
|
| 27 | - } |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function register_on_all_valid_post_types() { |
|
| 30 | - $supported_types = \Wordlift_Entity_Service::valid_entity_post_types(); |
|
| 31 | - foreach ( $supported_types as $supported_type ) { |
|
| 32 | - $this->register_pod( $supported_type, 'post_type', $this->context ); |
|
| 33 | - } |
|
| 34 | - } |
|
| 29 | + public function register_on_all_valid_post_types() { |
|
| 30 | + $supported_types = \Wordlift_Entity_Service::valid_entity_post_types(); |
|
| 31 | + foreach ( $supported_types as $supported_type ) { |
|
| 32 | + $this->register_pod( $supported_type, 'post_type', $this->context ); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -4,82 +4,82 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Schema { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @return Context |
|
| 9 | - */ |
|
| 10 | - public function get() { |
|
| 11 | - // we need to identify the context to filter the results. |
|
| 12 | - |
|
| 13 | - $identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) : ''; |
|
| 14 | - |
|
| 15 | - if ( $identifier ) { |
|
| 16 | - // If post identifier, get schema. |
|
| 17 | - return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) ); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - $identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : ''; |
|
| 21 | - |
|
| 22 | - if ( $identifier ) { |
|
| 23 | - // If post identifier, get schema. |
|
| 24 | - return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) ); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 28 | - return new Context( Context::UNKNOWN, null, null ); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() ); |
|
| 32 | - |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @return Schema_Field_Group[] |
|
| 37 | - */ |
|
| 38 | - private function get_fields_for_post( $identifier ) { |
|
| 39 | - $types = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier ); |
|
| 40 | - $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 41 | - |
|
| 42 | - return array_map( |
|
| 43 | - function ( $schema_type ) use ( $schema_classes ) { |
|
| 44 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 45 | - |
|
| 46 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 47 | - }, |
|
| 48 | - $types |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return Schema_Field_Group[] |
|
| 54 | - */ |
|
| 55 | - private function get_fields_for_term( $identifier ) { |
|
| 56 | - $term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 57 | - $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 58 | - |
|
| 59 | - return array_map( |
|
| 60 | - function ( $schema_type ) use ( $schema_classes ) { |
|
| 61 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 62 | - |
|
| 63 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 64 | - }, |
|
| 65 | - $term_entity_types |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - private function get_all_fields() { |
|
| 70 | - $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 71 | - $all_schema_slugs = $schema_classes->get_all_schema_slugs(); |
|
| 72 | - |
|
| 73 | - return array_filter( |
|
| 74 | - array_map( |
|
| 75 | - function ( $schema_type ) use ( $schema_classes ) { |
|
| 76 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 77 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 78 | - }, |
|
| 79 | - $all_schema_slugs |
|
| 80 | - ) |
|
| 81 | - ); |
|
| 82 | - } |
|
| 7 | + /** |
|
| 8 | + * @return Context |
|
| 9 | + */ |
|
| 10 | + public function get() { |
|
| 11 | + // we need to identify the context to filter the results. |
|
| 12 | + |
|
| 13 | + $identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) : ''; |
|
| 14 | + |
|
| 15 | + if ( $identifier ) { |
|
| 16 | + // If post identifier, get schema. |
|
| 17 | + return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) ); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + $identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : ''; |
|
| 21 | + |
|
| 22 | + if ( $identifier ) { |
|
| 23 | + // If post identifier, get schema. |
|
| 24 | + return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) ); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 28 | + return new Context( Context::UNKNOWN, null, null ); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() ); |
|
| 32 | + |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @return Schema_Field_Group[] |
|
| 37 | + */ |
|
| 38 | + private function get_fields_for_post( $identifier ) { |
|
| 39 | + $types = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier ); |
|
| 40 | + $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 41 | + |
|
| 42 | + return array_map( |
|
| 43 | + function ( $schema_type ) use ( $schema_classes ) { |
|
| 44 | + $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 45 | + |
|
| 46 | + return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 47 | + }, |
|
| 48 | + $types |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return Schema_Field_Group[] |
|
| 54 | + */ |
|
| 55 | + private function get_fields_for_term( $identifier ) { |
|
| 56 | + $term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 57 | + $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 58 | + |
|
| 59 | + return array_map( |
|
| 60 | + function ( $schema_type ) use ( $schema_classes ) { |
|
| 61 | + $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 62 | + |
|
| 63 | + return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 64 | + }, |
|
| 65 | + $term_entity_types |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + private function get_all_fields() { |
|
| 70 | + $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 71 | + $all_schema_slugs = $schema_classes->get_all_schema_slugs(); |
|
| 72 | + |
|
| 73 | + return array_filter( |
|
| 74 | + array_map( |
|
| 75 | + function ( $schema_type ) use ( $schema_classes ) { |
|
| 76 | + $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 77 | + return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 78 | + }, |
|
| 79 | + $all_schema_slugs |
|
| 80 | + ) |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | |
| 85 | 85 | } |
@@ -4,63 +4,63 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Context { |
| 6 | 6 | |
| 7 | - const POST = 0; |
|
| 8 | - const TERM = 1; |
|
| 9 | - const ADMIN_AJAX = 2; |
|
| 10 | - const UNKNOWN = -1; |
|
| 11 | - /** |
|
| 12 | - * @var $object_type int |
|
| 13 | - */ |
|
| 14 | - private $object_type; |
|
| 15 | - /** |
|
| 16 | - * @var $identifier int |
|
| 17 | - */ |
|
| 18 | - private $identifier; |
|
| 19 | - /** |
|
| 20 | - * @var $custom_fields Schema_Field_Group[] |
|
| 21 | - */ |
|
| 22 | - private $custom_fields; |
|
| 7 | + const POST = 0; |
|
| 8 | + const TERM = 1; |
|
| 9 | + const ADMIN_AJAX = 2; |
|
| 10 | + const UNKNOWN = -1; |
|
| 11 | + /** |
|
| 12 | + * @var $object_type int |
|
| 13 | + */ |
|
| 14 | + private $object_type; |
|
| 15 | + /** |
|
| 16 | + * @var $identifier int |
|
| 17 | + */ |
|
| 18 | + private $identifier; |
|
| 19 | + /** |
|
| 20 | + * @var $custom_fields Schema_Field_Group[] |
|
| 21 | + */ |
|
| 22 | + private $custom_fields; |
|
| 23 | 23 | |
| 24 | - private static $pod_types_map = array( |
|
| 25 | - self::POST => 'post_type', |
|
| 26 | - self::TERM => 'taxonomy', |
|
| 27 | - ); |
|
| 24 | + private static $pod_types_map = array( |
|
| 25 | + self::POST => 'post_type', |
|
| 26 | + self::TERM => 'taxonomy', |
|
| 27 | + ); |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param int $object_type |
|
| 32 | - * @param $identifier |
|
| 33 | - * @param $custom_fields |
|
| 34 | - */ |
|
| 35 | - public function __construct( $object_type, $identifier, $custom_fields ) { |
|
| 36 | - $this->object_type = $object_type; |
|
| 37 | - $this->identifier = $identifier; |
|
| 38 | - $this->custom_fields = $custom_fields; |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * @param int $object_type |
|
| 32 | + * @param $identifier |
|
| 33 | + * @param $custom_fields |
|
| 34 | + */ |
|
| 35 | + public function __construct( $object_type, $identifier, $custom_fields ) { |
|
| 36 | + $this->object_type = $object_type; |
|
| 37 | + $this->identifier = $identifier; |
|
| 38 | + $this->custom_fields = $custom_fields; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return int |
|
| 44 | - */ |
|
| 45 | - public function get_object_type() { |
|
| 46 | - return $this->object_type; |
|
| 47 | - } |
|
| 42 | + /** |
|
| 43 | + * @return int |
|
| 44 | + */ |
|
| 45 | + public function get_object_type() { |
|
| 46 | + return $this->object_type; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - public function get_pod_name() { |
|
| 51 | - if ( self::POST === $this->object_type ) { |
|
| 52 | - return get_post_type( $this->identifier ); |
|
| 53 | - } elseif ( self::TERM === $this->object_type ) { |
|
| 54 | - return get_term( $this->identifier )->taxonomy; |
|
| 55 | - } |
|
| 56 | - } |
|
| 50 | + public function get_pod_name() { |
|
| 51 | + if ( self::POST === $this->object_type ) { |
|
| 52 | + return get_post_type( $this->identifier ); |
|
| 53 | + } elseif ( self::TERM === $this->object_type ) { |
|
| 54 | + return get_term( $this->identifier )->taxonomy; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function get_pod_type() { |
|
| 59 | - return self::$pod_types_map[ $this->object_type ]; |
|
| 60 | - } |
|
| 58 | + public function get_pod_type() { |
|
| 59 | + return self::$pod_types_map[ $this->object_type ]; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function get_custom_fields() { |
|
| 63 | - return $this->custom_fields; |
|
| 64 | - } |
|
| 62 | + public function get_custom_fields() { |
|
| 63 | + return $this->custom_fields; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | } |
@@ -7,129 +7,129 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Filters { |
| 9 | 9 | |
| 10 | - const FIELD_NAME = 'wlentity'; |
|
| 10 | + const FIELD_NAME = 'wlentity'; |
|
| 11 | 11 | |
| 12 | - public function __construct() { |
|
| 12 | + public function __construct() { |
|
| 13 | 13 | |
| 14 | - pods_register_related_object( 'wlentity', 'WordLift Entity', array( 'simple' => false ) ); |
|
| 15 | - add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 ); |
|
| 16 | - add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 ); |
|
| 17 | - add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 ); |
|
| 18 | - add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 ); |
|
| 19 | - add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 ); |
|
| 14 | + pods_register_related_object( 'wlentity', 'WordLift Entity', array( 'simple' => false ) ); |
|
| 15 | + add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 ); |
|
| 16 | + add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 ); |
|
| 17 | + add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 ); |
|
| 18 | + add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 ); |
|
| 19 | + add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 ); |
|
| 20 | 20 | |
| 21 | - } |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function wl_pods_transform_data_for_pick_field( $item ) { |
|
| 23 | + public function wl_pods_transform_data_for_pick_field( $item ) { |
|
| 24 | 24 | |
| 25 | - $content = $item->get_content(); |
|
| 25 | + $content = $item->get_content(); |
|
| 26 | 26 | |
| 27 | - return array( |
|
| 28 | - 'id' => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ), |
|
| 29 | - 'icon' => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg', |
|
| 30 | - 'name' => $item->get_title() . ' (' . $item->get_schema_type() . ')', |
|
| 31 | - 'edit_link' => $content->get_edit_link(), |
|
| 32 | - 'link' => $content->get_permalink(), |
|
| 33 | - 'selected' => false, |
|
| 34 | - ); |
|
| 35 | - } |
|
| 27 | + return array( |
|
| 28 | + 'id' => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ), |
|
| 29 | + 'icon' => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg', |
|
| 30 | + 'name' => $item->get_title() . ' (' . $item->get_schema_type() . ')', |
|
| 31 | + 'edit_link' => $content->get_edit_link(), |
|
| 32 | + 'link' => $content->get_permalink(), |
|
| 33 | + 'selected' => false, |
|
| 34 | + ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | - public function admin_ajax_filter( $data, $name, $_, $field ) { |
|
| 38 | + public function admin_ajax_filter( $data, $name, $_, $field ) { |
|
| 39 | 39 | |
| 40 | - if ( ( ! $field instanceof Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== 'wlentity' ) { |
|
| 41 | - return $data; |
|
| 42 | - } |
|
| 40 | + if ( ( ! $field instanceof Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== 'wlentity' ) { |
|
| 41 | + return $data; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); |
|
| 45 | - $query_service = Entity_Query_Service::get_instance(); |
|
| 44 | + $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); |
|
| 45 | + $query_service = Entity_Query_Service::get_instance(); |
|
| 46 | 46 | |
| 47 | - return array_map( array( $this, 'wl_pods_transform_data_for_pick_field' ), $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) ); |
|
| 47 | + return array_map( array( $this, 'wl_pods_transform_data_for_pick_field' ), $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) ); |
|
| 48 | 48 | |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function data_filter( $data, $args ) { |
|
| 51 | + public function data_filter( $data, $args ) { |
|
| 52 | 52 | |
| 53 | - $args_arr = json_decode( wp_json_encode( $args ), true ); |
|
| 54 | - $field_data = $args_arr['options']; |
|
| 53 | + $args_arr = json_decode( wp_json_encode( $args ), true ); |
|
| 54 | + $field_data = $args_arr['options']; |
|
| 55 | 55 | |
| 56 | - if ( ! isset( $field_data['pick_object'] ) || 'wlentity' !== $field_data['pick_object'] ) { |
|
| 57 | - return $data; |
|
| 58 | - } |
|
| 56 | + if ( ! isset( $field_data['pick_object'] ) || 'wlentity' !== $field_data['pick_object'] ) { |
|
| 57 | + return $data; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] ) |
|
| 61 | - || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) { |
|
| 62 | - return $data; |
|
| 63 | - } |
|
| 60 | + if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] ) |
|
| 61 | + || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) { |
|
| 62 | + return $data; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $name = $field_data['name']; |
|
| 66 | - $identifier = $args->id; |
|
| 67 | - $type = $args_arr['pod']['data']['pod_data']['type']; |
|
| 65 | + $name = $field_data['name']; |
|
| 66 | + $identifier = $args->id; |
|
| 67 | + $type = $args_arr['pod']['data']['pod_data']['type']; |
|
| 68 | 68 | |
| 69 | - if ( 'post_type' === $type ) { |
|
| 70 | - $data['fieldValue'] = get_post_meta( $identifier, $name ); |
|
| 71 | - } elseif ( 'taxonomy' === $type ) { |
|
| 72 | - $data['fieldValue'] = get_term_meta( $identifier, $name ); |
|
| 73 | - } |
|
| 69 | + if ( 'post_type' === $type ) { |
|
| 70 | + $data['fieldValue'] = get_post_meta( $identifier, $name ); |
|
| 71 | + } elseif ( 'taxonomy' === $type ) { |
|
| 72 | + $data['fieldValue'] = get_term_meta( $identifier, $name ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return $data; |
|
| 76 | - } |
|
| 75 | + return $data; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - public function ajax_filter( $result, $name, $value, $field_options ) { |
|
| 79 | + public function ajax_filter( $result, $name, $value, $field_options ) { |
|
| 80 | 80 | |
| 81 | - if ( ! isset( $field_options['pick_object'] ) ) { |
|
| 82 | - return $result; |
|
| 83 | - } |
|
| 81 | + if ( ! isset( $field_options['pick_object'] ) ) { |
|
| 82 | + return $result; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return self::FIELD_NAME === $field_options['pick_object']; |
|
| 86 | - } |
|
| 85 | + return self::FIELD_NAME === $field_options['pick_object']; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) { |
|
| 88 | + public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) { |
|
| 89 | 89 | |
| 90 | - if ( $field === null || 'wlentity' !== $field->get_arg( 'pick_object', false ) ) { |
|
| 91 | - return $info; |
|
| 92 | - } |
|
| 93 | - // We need to return an non empty array here to prevent pods from querying a table. |
|
| 94 | - // This is necessary to prevent errors on ui. |
|
| 95 | - return array( 'foo' => 'bar' ); |
|
| 96 | - } |
|
| 90 | + if ( $field === null || 'wlentity' !== $field->get_arg( 'pick_object', false ) ) { |
|
| 91 | + return $info; |
|
| 92 | + } |
|
| 93 | + // We need to return an non empty array here to prevent pods from querying a table. |
|
| 94 | + // This is necessary to prevent errors on ui. |
|
| 95 | + return array( 'foo' => 'bar' ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | |
| 99 | - public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) { |
|
| 99 | + public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) { |
|
| 100 | 100 | |
| 101 | - $object_params = json_decode( wp_json_encode( $object_params ), true ); |
|
| 101 | + $object_params = json_decode( wp_json_encode( $object_params ), true ); |
|
| 102 | 102 | |
| 103 | - $query_service = Entity_Query_Service::get_instance(); |
|
| 103 | + $query_service = Entity_Query_Service::get_instance(); |
|
| 104 | 104 | |
| 105 | - if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] ) |
|
| 106 | - && is_string( $object_params['options']['pick_object'] ) |
|
| 107 | - && 'wlentity' === $object_params['options']['pick_object'] |
|
| 108 | - && isset( $object_params['pod']['data']['pod_data']['type'] ) |
|
| 109 | - && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) { |
|
| 105 | + if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] ) |
|
| 106 | + && is_string( $object_params['options']['pick_object'] ) |
|
| 107 | + && 'wlentity' === $object_params['options']['pick_object'] |
|
| 108 | + && isset( $object_params['pod']['data']['pod_data']['type'] ) |
|
| 109 | + && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) { |
|
| 110 | 110 | |
| 111 | - $type = $object_params['pod']['data']['pod_data']['type']; |
|
| 111 | + $type = $object_params['pod']['data']['pod_data']['type']; |
|
| 112 | 112 | |
| 113 | - if ( 'post_type' === $type ) { |
|
| 114 | - $linked_entities = get_post_meta( $id, $name ); |
|
| 115 | - } elseif ( 'taxonomy' === $type ) { |
|
| 116 | - $linked_entities = get_term_meta( $id, $name ); |
|
| 117 | - } |
|
| 118 | - $data = array(); |
|
| 119 | - $linked_entities = $query_service->get( $linked_entities ); |
|
| 120 | - foreach ( $linked_entities as $linked_entity ) { |
|
| 121 | - $content = $linked_entity->get_content(); |
|
| 122 | - $id = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ); |
|
| 123 | - $text = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')'; |
|
| 124 | - $data[ $id ] = $text; |
|
| 125 | - } |
|
| 113 | + if ( 'post_type' === $type ) { |
|
| 114 | + $linked_entities = get_post_meta( $id, $name ); |
|
| 115 | + } elseif ( 'taxonomy' === $type ) { |
|
| 116 | + $linked_entities = get_term_meta( $id, $name ); |
|
| 117 | + } |
|
| 118 | + $data = array(); |
|
| 119 | + $linked_entities = $query_service->get( $linked_entities ); |
|
| 120 | + foreach ( $linked_entities as $linked_entity ) { |
|
| 121 | + $content = $linked_entity->get_content(); |
|
| 122 | + $id = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ); |
|
| 123 | + $text = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')'; |
|
| 124 | + $data[ $id ] = $text; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - return $data; |
|
| 128 | - } |
|
| 127 | + return $data; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - return $_; |
|
| 130 | + return $_; |
|
| 131 | 131 | |
| 132 | - } |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | |
| 135 | 135 | } |
@@ -4,28 +4,28 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Schema_Field_Group { |
| 6 | 6 | |
| 7 | - private $schema_type; |
|
| 8 | - |
|
| 9 | - private $custom_fields; |
|
| 10 | - |
|
| 11 | - public function __construct( $schema_type, $custom_fields ) { |
|
| 12 | - $this->schema_type = $schema_type; |
|
| 13 | - $this->custom_fields = $custom_fields; |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @return mixed |
|
| 18 | - */ |
|
| 19 | - public function get_schema_type() { |
|
| 20 | - return $this->schema_type; |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @return mixed |
|
| 25 | - */ |
|
| 26 | - public function get_custom_fields() { |
|
| 27 | - return $this->custom_fields; |
|
| 28 | - } |
|
| 7 | + private $schema_type; |
|
| 8 | + |
|
| 9 | + private $custom_fields; |
|
| 10 | + |
|
| 11 | + public function __construct( $schema_type, $custom_fields ) { |
|
| 12 | + $this->schema_type = $schema_type; |
|
| 13 | + $this->custom_fields = $custom_fields; |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @return mixed |
|
| 18 | + */ |
|
| 19 | + public function get_schema_type() { |
|
| 20 | + return $this->schema_type; |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @return mixed |
|
| 25 | + */ |
|
| 26 | + public function get_custom_fields() { |
|
| 27 | + return $this->custom_fields; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | |
@@ -16,16 +16,16 @@ discard block |
||
| 16 | 16 | use Wordlift\Modules\Pods\WlEntityField\Filters; |
| 17 | 17 | |
| 18 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 19 | - exit; |
|
| 19 | + exit; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if ( ! defined( 'PODS_VERSION' ) ) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Autoloader for plugin itself. |
| 27 | 27 | if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
| 28 | - require __DIR__ . '/vendor/autoload.php'; |
|
| 28 | + require __DIR__ . '/vendor/autoload.php'; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | $container_builder->compile(); |
| 36 | 36 | |
| 37 | 37 | add_action( |
| 38 | - 'plugins_loaded', |
|
| 39 | - function () use ($container_builder) { |
|
| 38 | + 'plugins_loaded', |
|
| 39 | + function () use ($container_builder) { |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 45 | - $field_definition = $factory->get_field_definition(); |
|
| 46 | - $field_definition->register(); |
|
| 44 | + $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 45 | + $field_definition = $factory->get_field_definition(); |
|
| 46 | + $field_definition->register(); |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | ); |
| 52 | 52 | |
| 53 | 53 | |
@@ -20,90 +20,90 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | function wl_entity_get_by_title( $title, $autocomplete = false, $include_alias = true, $limit = false, $schema_types = array() ) { |
| 22 | 22 | |
| 23 | - global $wpdb; |
|
| 24 | - |
|
| 25 | - // Search by substring |
|
| 26 | - if ( $autocomplete ) { |
|
| 27 | - $title = '%' . $title . '%'; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - // The title is a LIKE query. |
|
| 31 | - $query = 'SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug' |
|
| 32 | - . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t" |
|
| 33 | - . ' WHERE p.post_title LIKE %s' |
|
| 34 | - . ' AND t.term_id = tt.term_id' |
|
| 35 | - . ' AND tt.taxonomy = %s' |
|
| 36 | - . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
| 37 | - . ' AND tr.object_id = p.ID' |
|
| 38 | - // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
| 39 | - . " AND p.post_status != 'trash'"; |
|
| 40 | - |
|
| 41 | - $params = array( |
|
| 42 | - $title, |
|
| 43 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 44 | - ); |
|
| 45 | - |
|
| 46 | - if ( $schema_types ) { |
|
| 47 | - $query .= ' AND t.name IN (' . join( |
|
| 48 | - ',', |
|
| 49 | - array_map( |
|
| 50 | - function ( $schema_type ) { |
|
| 51 | - return "'" . esc_sql( $schema_type ) . "'"; |
|
| 52 | - }, |
|
| 53 | - $schema_types |
|
| 54 | - ) |
|
| 55 | - ) . ')'; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if ( $include_alias ) { |
|
| 59 | - |
|
| 60 | - $query .= ' UNION' |
|
| 61 | - . " SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug" |
|
| 62 | - . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m" |
|
| 63 | - . ' WHERE m.meta_key = %s AND m.meta_value LIKE %s' |
|
| 64 | - . ' AND m.post_id = p.ID' |
|
| 65 | - . ' AND t.term_id = tt.term_id' |
|
| 66 | - . ' AND tt.taxonomy = %s' |
|
| 67 | - . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
| 68 | - . ' AND tr.object_id = p.ID' |
|
| 69 | - // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
| 70 | - . " AND p.post_status != 'trash'"; |
|
| 71 | - |
|
| 72 | - if ( $schema_types ) { |
|
| 73 | - $query .= ' AND t.name IN (' . join( |
|
| 74 | - ',', |
|
| 75 | - array_map( |
|
| 76 | - function ( $schema_type ) { |
|
| 77 | - return "'" . esc_sql( $schema_type ) . "'"; |
|
| 78 | - }, |
|
| 79 | - $schema_types |
|
| 80 | - ) |
|
| 81 | - ) . ')'; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $params = array_merge( |
|
| 85 | - $params, |
|
| 86 | - array( |
|
| 87 | - Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, |
|
| 88 | - $title, |
|
| 89 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 90 | - ) |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ( $limit ) { |
|
| 97 | - $query .= ' LIMIT %d'; |
|
| 98 | - $params[] = $limit; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $wpdb->get_results( |
|
| 102 | - $wpdb->prepare( |
|
| 103 | - $query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 104 | - $params |
|
| 105 | - ) |
|
| 106 | - ); |
|
| 23 | + global $wpdb; |
|
| 24 | + |
|
| 25 | + // Search by substring |
|
| 26 | + if ( $autocomplete ) { |
|
| 27 | + $title = '%' . $title . '%'; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + // The title is a LIKE query. |
|
| 31 | + $query = 'SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug' |
|
| 32 | + . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t" |
|
| 33 | + . ' WHERE p.post_title LIKE %s' |
|
| 34 | + . ' AND t.term_id = tt.term_id' |
|
| 35 | + . ' AND tt.taxonomy = %s' |
|
| 36 | + . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
| 37 | + . ' AND tr.object_id = p.ID' |
|
| 38 | + // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
| 39 | + . " AND p.post_status != 'trash'"; |
|
| 40 | + |
|
| 41 | + $params = array( |
|
| 42 | + $title, |
|
| 43 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 44 | + ); |
|
| 45 | + |
|
| 46 | + if ( $schema_types ) { |
|
| 47 | + $query .= ' AND t.name IN (' . join( |
|
| 48 | + ',', |
|
| 49 | + array_map( |
|
| 50 | + function ( $schema_type ) { |
|
| 51 | + return "'" . esc_sql( $schema_type ) . "'"; |
|
| 52 | + }, |
|
| 53 | + $schema_types |
|
| 54 | + ) |
|
| 55 | + ) . ')'; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if ( $include_alias ) { |
|
| 59 | + |
|
| 60 | + $query .= ' UNION' |
|
| 61 | + . " SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug" |
|
| 62 | + . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m" |
|
| 63 | + . ' WHERE m.meta_key = %s AND m.meta_value LIKE %s' |
|
| 64 | + . ' AND m.post_id = p.ID' |
|
| 65 | + . ' AND t.term_id = tt.term_id' |
|
| 66 | + . ' AND tt.taxonomy = %s' |
|
| 67 | + . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
| 68 | + . ' AND tr.object_id = p.ID' |
|
| 69 | + // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
| 70 | + . " AND p.post_status != 'trash'"; |
|
| 71 | + |
|
| 72 | + if ( $schema_types ) { |
|
| 73 | + $query .= ' AND t.name IN (' . join( |
|
| 74 | + ',', |
|
| 75 | + array_map( |
|
| 76 | + function ( $schema_type ) { |
|
| 77 | + return "'" . esc_sql( $schema_type ) . "'"; |
|
| 78 | + }, |
|
| 79 | + $schema_types |
|
| 80 | + ) |
|
| 81 | + ) . ')'; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $params = array_merge( |
|
| 85 | + $params, |
|
| 86 | + array( |
|
| 87 | + Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, |
|
| 88 | + $title, |
|
| 89 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 90 | + ) |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ( $limit ) { |
|
| 97 | + $query .= ' LIMIT %d'; |
|
| 98 | + $params[] = $limit; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $wpdb->get_results( |
|
| 102 | + $wpdb->prepare( |
|
| 103 | + $query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 104 | + $params |
|
| 105 | + ) |
|
| 106 | + ); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -113,43 +113,43 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | function wl_entity_ajax_get_by_title() { |
| 115 | 115 | |
| 116 | - // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
| 117 | - // |
|
| 118 | - // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
| 119 | - // Get the title to search. |
|
| 120 | - if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 121 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 122 | - @ob_clean(); |
|
| 123 | - wp_send_json_error( 'The title parameter is required.' ); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
| 127 | - // |
|
| 128 | - // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
| 129 | - $title = sanitize_text_field( wp_unslash( $_POST['title'] ? $_POST['title'] : $_GET['title'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 130 | - |
|
| 131 | - // Are we searching for a specific title or for a containing title? |
|
| 132 | - $autocomplete = isset( $_GET['autocomplete'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 133 | - |
|
| 134 | - // Are we searching also for the aliases? |
|
| 135 | - $include_alias = isset( $_GET['alias'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 136 | - |
|
| 137 | - // Get the edit link. |
|
| 138 | - $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME ); |
|
| 139 | - $edit_link = $post_type_object->_edit_link . '&action=edit'; |
|
| 140 | - |
|
| 141 | - // Prepare the response with the edit link. |
|
| 142 | - $response = array( |
|
| 143 | - 'edit_link' => $edit_link, |
|
| 144 | - 'results' => wl_entity_get_by_title( $title, $autocomplete, $include_alias ), |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - // Clean any buffer. |
|
| 148 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 149 | - @ob_clean(); |
|
| 150 | - |
|
| 151 | - // Send the success response. |
|
| 152 | - wp_send_json_success( $response ); |
|
| 116 | + // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
| 117 | + // |
|
| 118 | + // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
| 119 | + // Get the title to search. |
|
| 120 | + if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 121 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 122 | + @ob_clean(); |
|
| 123 | + wp_send_json_error( 'The title parameter is required.' ); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
| 127 | + // |
|
| 128 | + // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
| 129 | + $title = sanitize_text_field( wp_unslash( $_POST['title'] ? $_POST['title'] : $_GET['title'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 130 | + |
|
| 131 | + // Are we searching for a specific title or for a containing title? |
|
| 132 | + $autocomplete = isset( $_GET['autocomplete'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 133 | + |
|
| 134 | + // Are we searching also for the aliases? |
|
| 135 | + $include_alias = isset( $_GET['alias'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 136 | + |
|
| 137 | + // Get the edit link. |
|
| 138 | + $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME ); |
|
| 139 | + $edit_link = $post_type_object->_edit_link . '&action=edit'; |
|
| 140 | + |
|
| 141 | + // Prepare the response with the edit link. |
|
| 142 | + $response = array( |
|
| 143 | + 'edit_link' => $edit_link, |
|
| 144 | + 'results' => wl_entity_get_by_title( $title, $autocomplete, $include_alias ), |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + // Clean any buffer. |
|
| 148 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 149 | + @ob_clean(); |
|
| 150 | + |
|
| 151 | + // Send the success response. |
|
| 152 | + wp_send_json_success( $response ); |
|
| 153 | 153 | |
| 154 | 154 | } |
| 155 | 155 | |