@@ -14,114 +14,114 @@ |
||
| 14 | 14 | |
| 15 | 15 | class Entity_Query_Service { |
| 16 | 16 | |
| 17 | - private static $instance = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The singleton instance. |
|
| 21 | - * |
|
| 22 | - * @return Entity_Query_Service |
|
| 23 | - */ |
|
| 24 | - public static function get_instance() { |
|
| 25 | - if ( ! isset( self::$instance ) ) { |
|
| 26 | - self::$instance = new self(); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return self::$instance; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - private function query_posts( $query, $schema_types, $limit ) { |
|
| 33 | - return wl_entity_get_by_title( $query, true, true, $limit, $schema_types ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - private function query_terms( $query, $schema_types, $limit ) { |
|
| 37 | - global $wpdb; |
|
| 38 | - $schema_types = join( |
|
| 39 | - ',', |
|
| 40 | - array_map( |
|
| 41 | - function ( $schema_type ) { |
|
| 42 | - return "'" . esc_sql( strtolower( $schema_type ) ) . "'"; |
|
| 43 | - }, |
|
| 44 | - $schema_types |
|
| 45 | - ) |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - return $wpdb->get_results( |
|
| 49 | - $wpdb->prepare( |
|
| 50 | - "SELECT DISTINCT t.term_id as id, t.name as title, tm.meta_value as schema_type_name FROM $wpdb->terms t INNER JOIN $wpdb->termmeta tm |
|
| 17 | + private static $instance = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The singleton instance. |
|
| 21 | + * |
|
| 22 | + * @return Entity_Query_Service |
|
| 23 | + */ |
|
| 24 | + public static function get_instance() { |
|
| 25 | + if ( ! isset( self::$instance ) ) { |
|
| 26 | + self::$instance = new self(); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return self::$instance; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + private function query_posts( $query, $schema_types, $limit ) { |
|
| 33 | + return wl_entity_get_by_title( $query, true, true, $limit, $schema_types ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + private function query_terms( $query, $schema_types, $limit ) { |
|
| 37 | + global $wpdb; |
|
| 38 | + $schema_types = join( |
|
| 39 | + ',', |
|
| 40 | + array_map( |
|
| 41 | + function ( $schema_type ) { |
|
| 42 | + return "'" . esc_sql( strtolower( $schema_type ) ) . "'"; |
|
| 43 | + }, |
|
| 44 | + $schema_types |
|
| 45 | + ) |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + return $wpdb->get_results( |
|
| 49 | + $wpdb->prepare( |
|
| 50 | + "SELECT DISTINCT t.term_id as id, t.name as title, tm.meta_value as schema_type_name FROM $wpdb->terms t INNER JOIN $wpdb->termmeta tm |
|
| 51 | 51 | ON t.term_id=tm.term_id WHERE t.name LIKE %s AND (tm.meta_key = %s AND tm.meta_value IN ($schema_types)) LIMIT %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 52 | - '%' . $wpdb->esc_like( $query ) . '%', |
|
| 53 | - \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 54 | - $limit |
|
| 55 | - ) |
|
| 56 | - ); |
|
| 57 | - |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param $results |
|
| 62 | - * @param $object_type |
|
| 63 | - * |
|
| 64 | - * @return Entity[] |
|
| 65 | - */ |
|
| 66 | - private function transform_posts( $results ) { |
|
| 67 | - return array_map( |
|
| 68 | - function ( $item ) { |
|
| 69 | - return new Entity( $item->schema_type_name, new Wordpress_Content( get_post( $item->id ) ) ); |
|
| 70 | - }, |
|
| 71 | - $results |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - private function transform_terms( $results ) { |
|
| 76 | - return array_map( |
|
| 77 | - function ( $item ) { |
|
| 78 | - return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
|
| 79 | - }, |
|
| 80 | - $results |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param $query |
|
| 86 | - * @param $schema_types |
|
| 87 | - * @param $limit |
|
| 88 | - * |
|
| 89 | - * @return Entity[] |
|
| 90 | - */ |
|
| 91 | - public function query( $query, $schema_types = array(), $limit = 10 ) { |
|
| 92 | - |
|
| 93 | - $results = $this->transform_posts( $this->query_posts( $query, $schema_types, $limit ) ); |
|
| 94 | - |
|
| 95 | - if ( count( $results ) >= $limit ) { |
|
| 96 | - return $results; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $results = array_merge( $results, $this->transform_terms( $this->query_terms( $query, $schema_types, $limit ) ) ); |
|
| 100 | - |
|
| 101 | - return $results; |
|
| 102 | - |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function get( $linked_entities ) { |
|
| 106 | - return array_filter( |
|
| 107 | - array_map( |
|
| 108 | - function ( $item ) { |
|
| 109 | - $parts = explode( '_', $item ); |
|
| 110 | - $type = Object_Type_Enum::from_string( $parts[0] ); |
|
| 111 | - $identifier = $parts[1]; |
|
| 112 | - |
|
| 113 | - if ( $type === Object_Type_Enum::POST ) { |
|
| 114 | - return new Entity( 'Thing', new Wordpress_Content( get_post( $identifier ) ) ); |
|
| 115 | - } elseif ( $type === Object_Type_Enum::TERM ) { |
|
| 116 | - return new Entity( 'Thing', new Wordpress_Content( get_term( $identifier ) ) ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
|
| 120 | - }, |
|
| 121 | - $linked_entities |
|
| 122 | - ) |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - } |
|
| 52 | + '%' . $wpdb->esc_like( $query ) . '%', |
|
| 53 | + \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 54 | + $limit |
|
| 55 | + ) |
|
| 56 | + ); |
|
| 57 | + |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param $results |
|
| 62 | + * @param $object_type |
|
| 63 | + * |
|
| 64 | + * @return Entity[] |
|
| 65 | + */ |
|
| 66 | + private function transform_posts( $results ) { |
|
| 67 | + return array_map( |
|
| 68 | + function ( $item ) { |
|
| 69 | + return new Entity( $item->schema_type_name, new Wordpress_Content( get_post( $item->id ) ) ); |
|
| 70 | + }, |
|
| 71 | + $results |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + private function transform_terms( $results ) { |
|
| 76 | + return array_map( |
|
| 77 | + function ( $item ) { |
|
| 78 | + return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
|
| 79 | + }, |
|
| 80 | + $results |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param $query |
|
| 86 | + * @param $schema_types |
|
| 87 | + * @param $limit |
|
| 88 | + * |
|
| 89 | + * @return Entity[] |
|
| 90 | + */ |
|
| 91 | + public function query( $query, $schema_types = array(), $limit = 10 ) { |
|
| 92 | + |
|
| 93 | + $results = $this->transform_posts( $this->query_posts( $query, $schema_types, $limit ) ); |
|
| 94 | + |
|
| 95 | + if ( count( $results ) >= $limit ) { |
|
| 96 | + return $results; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $results = array_merge( $results, $this->transform_terms( $this->query_terms( $query, $schema_types, $limit ) ) ); |
|
| 100 | + |
|
| 101 | + return $results; |
|
| 102 | + |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function get( $linked_entities ) { |
|
| 106 | + return array_filter( |
|
| 107 | + array_map( |
|
| 108 | + function ( $item ) { |
|
| 109 | + $parts = explode( '_', $item ); |
|
| 110 | + $type = Object_Type_Enum::from_string( $parts[0] ); |
|
| 111 | + $identifier = $parts[1]; |
|
| 112 | + |
|
| 113 | + if ( $type === Object_Type_Enum::POST ) { |
|
| 114 | + return new Entity( 'Thing', new Wordpress_Content( get_post( $identifier ) ) ); |
|
| 115 | + } elseif ( $type === Object_Type_Enum::TERM ) { |
|
| 116 | + return new Entity( 'Thing', new Wordpress_Content( get_term( $identifier ) ) ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
|
| 120 | + }, |
|
| 121 | + $linked_entities |
|
| 122 | + ) |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |
@@ -22,24 +22,24 @@ discard block |
||
| 22 | 22 | * @return Entity_Query_Service |
| 23 | 23 | */ |
| 24 | 24 | public static function get_instance() { |
| 25 | - if ( ! isset( self::$instance ) ) { |
|
| 25 | + if ( ! isset(self::$instance)) { |
|
| 26 | 26 | self::$instance = new self(); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | return self::$instance; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - private function query_posts( $query, $schema_types, $limit ) { |
|
| 33 | - return wl_entity_get_by_title( $query, true, true, $limit, $schema_types ); |
|
| 32 | + private function query_posts($query, $schema_types, $limit) { |
|
| 33 | + return wl_entity_get_by_title($query, true, true, $limit, $schema_types); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - private function query_terms( $query, $schema_types, $limit ) { |
|
| 36 | + private function query_terms($query, $schema_types, $limit) { |
|
| 37 | 37 | global $wpdb; |
| 38 | 38 | $schema_types = join( |
| 39 | 39 | ',', |
| 40 | 40 | array_map( |
| 41 | - function ( $schema_type ) { |
|
| 42 | - return "'" . esc_sql( strtolower( $schema_type ) ) . "'"; |
|
| 41 | + function($schema_type) { |
|
| 42 | + return "'".esc_sql(strtolower($schema_type))."'"; |
|
| 43 | 43 | }, |
| 44 | 44 | $schema_types |
| 45 | 45 | ) |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $wpdb->prepare( |
| 50 | 50 | "SELECT DISTINCT t.term_id as id, t.name as title, tm.meta_value as schema_type_name FROM $wpdb->terms t INNER JOIN $wpdb->termmeta tm |
| 51 | 51 | ON t.term_id=tm.term_id WHERE t.name LIKE %s AND (tm.meta_key = %s AND tm.meta_value IN ($schema_types)) LIMIT %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 52 | - '%' . $wpdb->esc_like( $query ) . '%', |
|
| 52 | + '%'.$wpdb->esc_like($query).'%', |
|
| 53 | 53 | \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
| 54 | 54 | $limit |
| 55 | 55 | ) |
@@ -63,19 +63,19 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return Entity[] |
| 65 | 65 | */ |
| 66 | - private function transform_posts( $results ) { |
|
| 66 | + private function transform_posts($results) { |
|
| 67 | 67 | return array_map( |
| 68 | - function ( $item ) { |
|
| 69 | - return new Entity( $item->schema_type_name, new Wordpress_Content( get_post( $item->id ) ) ); |
|
| 68 | + function($item) { |
|
| 69 | + return new Entity($item->schema_type_name, new Wordpress_Content(get_post($item->id))); |
|
| 70 | 70 | }, |
| 71 | 71 | $results |
| 72 | 72 | ); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - private function transform_terms( $results ) { |
|
| 75 | + private function transform_terms($results) { |
|
| 76 | 76 | return array_map( |
| 77 | - function ( $item ) { |
|
| 78 | - return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
|
| 77 | + function($item) { |
|
| 78 | + return new Entity($item->schema_type_name, new Wordpress_Content(get_term($item->id))); |
|
| 79 | 79 | }, |
| 80 | 80 | $results |
| 81 | 81 | ); |
@@ -88,32 +88,32 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return Entity[] |
| 90 | 90 | */ |
| 91 | - public function query( $query, $schema_types = array(), $limit = 10 ) { |
|
| 91 | + public function query($query, $schema_types = array(), $limit = 10) { |
|
| 92 | 92 | |
| 93 | - $results = $this->transform_posts( $this->query_posts( $query, $schema_types, $limit ) ); |
|
| 93 | + $results = $this->transform_posts($this->query_posts($query, $schema_types, $limit)); |
|
| 94 | 94 | |
| 95 | - if ( count( $results ) >= $limit ) { |
|
| 95 | + if (count($results) >= $limit) { |
|
| 96 | 96 | return $results; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $results = array_merge( $results, $this->transform_terms( $this->query_terms( $query, $schema_types, $limit ) ) ); |
|
| 99 | + $results = array_merge($results, $this->transform_terms($this->query_terms($query, $schema_types, $limit))); |
|
| 100 | 100 | |
| 101 | 101 | return $results; |
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - public function get( $linked_entities ) { |
|
| 105 | + public function get($linked_entities) { |
|
| 106 | 106 | return array_filter( |
| 107 | 107 | array_map( |
| 108 | - function ( $item ) { |
|
| 109 | - $parts = explode( '_', $item ); |
|
| 110 | - $type = Object_Type_Enum::from_string( $parts[0] ); |
|
| 108 | + function($item) { |
|
| 109 | + $parts = explode('_', $item); |
|
| 110 | + $type = Object_Type_Enum::from_string($parts[0]); |
|
| 111 | 111 | $identifier = $parts[1]; |
| 112 | 112 | |
| 113 | - if ( $type === Object_Type_Enum::POST ) { |
|
| 114 | - return new Entity( 'Thing', new Wordpress_Content( get_post( $identifier ) ) ); |
|
| 115 | - } elseif ( $type === Object_Type_Enum::TERM ) { |
|
| 116 | - return new Entity( 'Thing', new Wordpress_Content( get_term( $identifier ) ) ); |
|
| 113 | + if ($type === Object_Type_Enum::POST) { |
|
| 114 | + return new Entity('Thing', new Wordpress_Content(get_post($identifier))); |
|
| 115 | + } elseif ($type === Object_Type_Enum::TERM) { |
|
| 116 | + return new Entity('Thing', new Wordpress_Content(get_term($identifier))); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Entity { |
| 9 | 9 | |
| 10 | - private $schema_type; |
|
| 11 | - /** |
|
| 12 | - * @var Wordpress_Content |
|
| 13 | - */ |
|
| 14 | - private $content; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @param $schema_type |
|
| 18 | - * @param $content Wordpress_Content |
|
| 19 | - */ |
|
| 20 | - public function __construct( $schema_type, $content ) { |
|
| 21 | - $this->schema_type = $schema_type; |
|
| 22 | - $this->content = $content; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @return Wordpress_Content |
|
| 27 | - */ |
|
| 28 | - public function get_content() { |
|
| 29 | - return $this->content; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function get_schema_type() { |
|
| 33 | - return $this->schema_type; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function get_title() { |
|
| 37 | - if ( Object_Type_Enum::POST === $this->content->get_object_type_enum() ) { |
|
| 38 | - return $this->content->get_bag()->post_title; |
|
| 39 | - } |
|
| 40 | - if ( Object_Type_Enum::TERM === $this->content->get_object_type_enum() ) { |
|
| 41 | - return $this->content->get_bag()->name; |
|
| 42 | - } |
|
| 43 | - return ''; |
|
| 44 | - } |
|
| 10 | + private $schema_type; |
|
| 11 | + /** |
|
| 12 | + * @var Wordpress_Content |
|
| 13 | + */ |
|
| 14 | + private $content; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @param $schema_type |
|
| 18 | + * @param $content Wordpress_Content |
|
| 19 | + */ |
|
| 20 | + public function __construct( $schema_type, $content ) { |
|
| 21 | + $this->schema_type = $schema_type; |
|
| 22 | + $this->content = $content; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @return Wordpress_Content |
|
| 27 | + */ |
|
| 28 | + public function get_content() { |
|
| 29 | + return $this->content; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function get_schema_type() { |
|
| 33 | + return $this->schema_type; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function get_title() { |
|
| 37 | + if ( Object_Type_Enum::POST === $this->content->get_object_type_enum() ) { |
|
| 38 | + return $this->content->get_bag()->post_title; |
|
| 39 | + } |
|
| 40 | + if ( Object_Type_Enum::TERM === $this->content->get_object_type_enum() ) { |
|
| 41 | + return $this->content->get_bag()->name; |
|
| 42 | + } |
|
| 43 | + return ''; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | } |
@@ -21,36 +21,36 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Wl_Metabox extends Wl_Abstract_Metabox { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * WL_Metabox constructor. |
|
| 26 | - * |
|
| 27 | - * @since 3.1.0 |
|
| 28 | - */ |
|
| 29 | - public function __construct() { |
|
| 30 | - parent::__construct(); |
|
| 31 | - /** |
|
| 32 | - * Filter: wl_feature__enable__metabox. |
|
| 33 | - * |
|
| 34 | - * @param bool whether the metabox should be shown, defaults to true. |
|
| 35 | - * |
|
| 36 | - * @return bool |
|
| 37 | - * @since 3.28.1 |
|
| 38 | - */ |
|
| 39 | - if ( apply_filters( 'wl_feature__enable__metabox', true ) && ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 40 | - |
|
| 41 | - // Add hooks to print metaboxes and save submitted data. |
|
| 42 | - add_action( 'add_meta_boxes', array( $this, 'add_main_metabox' ) ); |
|
| 43 | - add_action( 'wl_linked_data_save_post', array( $this, 'save_form' ) ); |
|
| 44 | - |
|
| 45 | - // Enqueue js and css. |
|
| 46 | - $this->enqueue_scripts_and_styles(); |
|
| 47 | - |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function save_form( $post_id ) { |
|
| 53 | - $this->save_form_data( $post_id, Object_Type_Enum::POST ); |
|
| 54 | - } |
|
| 24 | + /** |
|
| 25 | + * WL_Metabox constructor. |
|
| 26 | + * |
|
| 27 | + * @since 3.1.0 |
|
| 28 | + */ |
|
| 29 | + public function __construct() { |
|
| 30 | + parent::__construct(); |
|
| 31 | + /** |
|
| 32 | + * Filter: wl_feature__enable__metabox. |
|
| 33 | + * |
|
| 34 | + * @param bool whether the metabox should be shown, defaults to true. |
|
| 35 | + * |
|
| 36 | + * @return bool |
|
| 37 | + * @since 3.28.1 |
|
| 38 | + */ |
|
| 39 | + if ( apply_filters( 'wl_feature__enable__metabox', true ) && ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 40 | + |
|
| 41 | + // Add hooks to print metaboxes and save submitted data. |
|
| 42 | + add_action( 'add_meta_boxes', array( $this, 'add_main_metabox' ) ); |
|
| 43 | + add_action( 'wl_linked_data_save_post', array( $this, 'save_form' ) ); |
|
| 44 | + |
|
| 45 | + // Enqueue js and css. |
|
| 46 | + $this->enqueue_scripts_and_styles(); |
|
| 47 | + |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function save_form( $post_id ) { |
|
| 53 | + $this->save_form_data( $post_id, Object_Type_Enum::POST ); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | } |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | * @return bool |
| 37 | 37 | * @since 3.28.1 |
| 38 | 38 | */ |
| 39 | - if ( apply_filters( 'wl_feature__enable__metabox', true ) && ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 39 | + if (apply_filters('wl_feature__enable__metabox', true) && ! apply_filters('wl_feature__enable__pods-integration', false)) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 40 | 40 | |
| 41 | 41 | // Add hooks to print metaboxes and save submitted data. |
| 42 | - add_action( 'add_meta_boxes', array( $this, 'add_main_metabox' ) ); |
|
| 43 | - add_action( 'wl_linked_data_save_post', array( $this, 'save_form' ) ); |
|
| 42 | + add_action('add_meta_boxes', array($this, 'add_main_metabox')); |
|
| 43 | + add_action('wl_linked_data_save_post', array($this, 'save_form')); |
|
| 44 | 44 | |
| 45 | 45 | // Enqueue js and css. |
| 46 | 46 | $this->enqueue_scripts_and_styles(); |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function save_form( $post_id ) { |
|
| 53 | - $this->save_form_data( $post_id, Object_Type_Enum::POST ); |
|
| 52 | + public function save_form($post_id) { |
|
| 53 | + $this->save_form_data($post_id, Object_Type_Enum::POST); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | } |
@@ -12,51 +12,51 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Term_Metabox extends Wl_Abstract_Metabox { |
| 14 | 14 | |
| 15 | - public function __construct() { |
|
| 16 | - parent::__construct(); |
|
| 17 | - if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 18 | - add_action( 'init', array( $this, 'init_all_custom_fields' ) ); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @param $term \WP_Term |
|
| 25 | - */ |
|
| 26 | - public function render_ui( $term ) { |
|
| 27 | - |
|
| 28 | - $this->instantiate_fields( $term->term_id, Object_Type_Enum::TERM ); |
|
| 29 | - $this->html(); |
|
| 30 | - $this->enqueue_scripts_and_styles(); |
|
| 31 | - $plugin = \Wordlift::get_instance(); |
|
| 32 | - |
|
| 33 | - // Enqueue this scripts for sameas fields. |
|
| 34 | - wp_enqueue_script( |
|
| 35 | - 'wl-autocomplete-select', |
|
| 36 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.js', |
|
| 37 | - array(), |
|
| 38 | - $plugin->get_version(), |
|
| 39 | - true |
|
| 40 | - ); |
|
| 41 | - |
|
| 42 | - wp_enqueue_style( |
|
| 43 | - 'wl-autocomplete-select', |
|
| 44 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.css', |
|
| 45 | - array(), |
|
| 46 | - $plugin->get_version() |
|
| 47 | - ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function save_field( $term_id ) { |
|
| 51 | - $this->save_form_data( $term_id, Object_Type_Enum::TERM ); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function init_all_custom_fields() { |
|
| 55 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 56 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 57 | - add_action( "${taxonomy}_edit_form", array( $this, 'render_ui' ), 1 ); |
|
| 58 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 59 | - } |
|
| 60 | - } |
|
| 15 | + public function __construct() { |
|
| 16 | + parent::__construct(); |
|
| 17 | + if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 18 | + add_action( 'init', array( $this, 'init_all_custom_fields' ) ); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @param $term \WP_Term |
|
| 25 | + */ |
|
| 26 | + public function render_ui( $term ) { |
|
| 27 | + |
|
| 28 | + $this->instantiate_fields( $term->term_id, Object_Type_Enum::TERM ); |
|
| 29 | + $this->html(); |
|
| 30 | + $this->enqueue_scripts_and_styles(); |
|
| 31 | + $plugin = \Wordlift::get_instance(); |
|
| 32 | + |
|
| 33 | + // Enqueue this scripts for sameas fields. |
|
| 34 | + wp_enqueue_script( |
|
| 35 | + 'wl-autocomplete-select', |
|
| 36 | + plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.js', |
|
| 37 | + array(), |
|
| 38 | + $plugin->get_version(), |
|
| 39 | + true |
|
| 40 | + ); |
|
| 41 | + |
|
| 42 | + wp_enqueue_style( |
|
| 43 | + 'wl-autocomplete-select', |
|
| 44 | + plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.css', |
|
| 45 | + array(), |
|
| 46 | + $plugin->get_version() |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function save_field( $term_id ) { |
|
| 51 | + $this->save_form_data( $term_id, Object_Type_Enum::TERM ); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function init_all_custom_fields() { |
|
| 55 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 56 | + foreach ( $taxonomies as $taxonomy ) { |
|
| 57 | + add_action( "${taxonomy}_edit_form", array( $this, 'render_ui' ), 1 ); |
|
| 58 | + add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | } |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | - if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 18 | - add_action( 'init', array( $this, 'init_all_custom_fields' ) ); |
|
| 17 | + if ( ! apply_filters('wl_feature__enable__pods-integration', false)) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 18 | + add_action('init', array($this, 'init_all_custom_fields')); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | } |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | /** |
| 24 | 24 | * @param $term \WP_Term |
| 25 | 25 | */ |
| 26 | - public function render_ui( $term ) { |
|
| 26 | + public function render_ui($term) { |
|
| 27 | 27 | |
| 28 | - $this->instantiate_fields( $term->term_id, Object_Type_Enum::TERM ); |
|
| 28 | + $this->instantiate_fields($term->term_id, Object_Type_Enum::TERM); |
|
| 29 | 29 | $this->html(); |
| 30 | 30 | $this->enqueue_scripts_and_styles(); |
| 31 | 31 | $plugin = \Wordlift::get_instance(); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | // Enqueue this scripts for sameas fields. |
| 34 | 34 | wp_enqueue_script( |
| 35 | 35 | 'wl-autocomplete-select', |
| 36 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.js', |
|
| 36 | + plugin_dir_url(dirname(__DIR__)).'js/dist/autocomplete-select.js', |
|
| 37 | 37 | array(), |
| 38 | 38 | $plugin->get_version(), |
| 39 | 39 | true |
@@ -41,21 +41,21 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | wp_enqueue_style( |
| 43 | 43 | 'wl-autocomplete-select', |
| 44 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.css', |
|
| 44 | + plugin_dir_url(dirname(__DIR__)).'js/dist/autocomplete-select.css', |
|
| 45 | 45 | array(), |
| 46 | 46 | $plugin->get_version() |
| 47 | 47 | ); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public function save_field( $term_id ) { |
|
| 51 | - $this->save_form_data( $term_id, Object_Type_Enum::TERM ); |
|
| 50 | + public function save_field($term_id) { |
|
| 51 | + $this->save_form_data($term_id, Object_Type_Enum::TERM); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public function init_all_custom_fields() { |
| 55 | 55 | $taxonomies = Terms_Compat::get_public_taxonomies(); |
| 56 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 57 | - add_action( "${taxonomy}_edit_form", array( $this, 'render_ui' ), 1 ); |
|
| 58 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 56 | + foreach ($taxonomies as $taxonomy) { |
|
| 57 | + add_action("${taxonomy}_edit_form", array($this, 'render_ui'), 1); |
|
| 58 | + add_action("edited_${taxonomy}", array($this, 'save_field')); |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
@@ -11,151 +11,151 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Jsonld_Generator { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var \Wordlift_Entity_Type_Service |
|
| 16 | - */ |
|
| 17 | - private $entity_type_service; |
|
| 18 | - /** |
|
| 19 | - * @var \Wordlift_Property_Getter |
|
| 20 | - */ |
|
| 21 | - private $property_getter; |
|
| 22 | - /** |
|
| 23 | - * @var Type_Service |
|
| 24 | - */ |
|
| 25 | - private $term_entity_type_service; |
|
| 26 | - /** |
|
| 27 | - * @var \Wordlift_Entity_Service |
|
| 28 | - */ |
|
| 29 | - private $entity_service; |
|
| 30 | - |
|
| 31 | - public function __construct( $entity_type_service, $property_getter ) { |
|
| 32 | - $this->entity_type_service = $entity_type_service; |
|
| 33 | - $this->property_getter = $property_getter; |
|
| 34 | - $this->term_entity_type_service = Type_Service::get_instance(); |
|
| 35 | - $this->entity_service = \Wordlift_Entity_Service::get_instance(); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function init() { |
|
| 39 | - add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 ); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function wl_term_jsonld_array( $data, $term_id ) { |
|
| 43 | - $jsonld = $data['jsonld']; |
|
| 44 | - $references = $data['references']; |
|
| 45 | - |
|
| 46 | - $term_jsonld_data = $this->get_jsonld_data_for_term( $term_id ); |
|
| 47 | - |
|
| 48 | - // Return early if we dont have the entity data |
|
| 49 | - // for the term. |
|
| 50 | - if ( ! $term_jsonld_data ) { |
|
| 51 | - return $data; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $term_jsonld = $term_jsonld_data['jsonld']; |
|
| 55 | - |
|
| 56 | - $references = array_merge( $references, $term_jsonld_data['references'] ); |
|
| 57 | - |
|
| 58 | - array_unshift( $jsonld, $term_jsonld ); |
|
| 59 | - |
|
| 60 | - return array( |
|
| 61 | - 'jsonld' => $jsonld, |
|
| 62 | - 'references' => $references, |
|
| 63 | - ); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - private function get_jsonld_data_for_term( $term_id ) { |
|
| 67 | - |
|
| 68 | - $id = $this->entity_service->get_uri( $term_id, Object_Type_Enum::TERM ); |
|
| 69 | - |
|
| 70 | - // If we don't have a dataset URI, then don't publish the term data |
|
| 71 | - // on this page. |
|
| 72 | - if ( ! $id ) { |
|
| 73 | - return false; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $references = array(); |
|
| 77 | - $term = get_term( $term_id ); |
|
| 78 | - $permalink = get_term_link( $term ); |
|
| 79 | - |
|
| 80 | - $custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id ); |
|
| 81 | - $term = get_term( $term_id ); |
|
| 82 | - $jsonld = array( |
|
| 83 | - '@context' => 'http://schema.org', |
|
| 84 | - 'name' => $term->name, |
|
| 85 | - '@type' => $this->term_entity_type_service->get_entity_types_labels( $term_id ), |
|
| 86 | - '@id' => $id, |
|
| 87 | - 'description' => $term->description, |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - if ( ! $custom_fields || ! is_array( $custom_fields ) ) { |
|
| 91 | - return $jsonld; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - foreach ( $custom_fields as $key => $value ) { |
|
| 95 | - $name = $this->relative_to_schema_context( $value['predicate'] ); |
|
| 96 | - $value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM ); |
|
| 97 | - $value = $this->process_value( $value, $references ); |
|
| 98 | - if ( ! isset( $value ) || |
|
| 99 | - is_array( $value ) && empty( $value ) || |
|
| 100 | - is_string( $value ) && empty( $value ) ) { |
|
| 101 | - continue; |
|
| 102 | - } |
|
| 103 | - $jsonld[ $name ] = $value; |
|
| 104 | - |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ( $permalink ) { |
|
| 108 | - $jsonld['mainEntityOfPage'] = $permalink; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return apply_filters( |
|
| 112 | - 'wl_no_vocabulary_term_jsonld_array', |
|
| 113 | - array( |
|
| 114 | - 'jsonld' => $jsonld, |
|
| 115 | - 'references' => $references, |
|
| 116 | - ), |
|
| 117 | - $term_id |
|
| 118 | - ); |
|
| 119 | - |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - private function relative_to_schema_context( $predicate ) { |
|
| 123 | - return str_replace( 'http://schema.org/', '', $predicate ); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - private function process_value( $value, &$references ) { |
|
| 127 | - |
|
| 128 | - if ( is_array( $value ) |
|
| 129 | - && count( $value ) > 0 |
|
| 130 | - && $value[0] instanceof \Wordlift_Property_Entity_Reference ) { |
|
| 131 | - |
|
| 132 | - // All of the references from the custom fields are post references. |
|
| 133 | - $references = array_merge( |
|
| 134 | - $references, |
|
| 135 | - array_map( |
|
| 136 | - function ( $property_entity_reference ) { |
|
| 137 | - /** |
|
| 138 | - * @var $property_entity_reference \Wordlift_Property_Entity_Reference |
|
| 139 | - */ |
|
| 140 | - return $property_entity_reference->to_reference(); |
|
| 141 | - }, |
|
| 142 | - $value |
|
| 143 | - ) |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - return array_map( |
|
| 147 | - function ( $reference ) { |
|
| 148 | - /** |
|
| 149 | - * @var $reference \Wordlift_Property_Entity_Reference |
|
| 150 | - */ |
|
| 151 | - return array( '@id' => $reference->get_url() ); |
|
| 152 | - }, |
|
| 153 | - $value |
|
| 154 | - ); |
|
| 155 | - |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - return $value; |
|
| 159 | - } |
|
| 14 | + /** |
|
| 15 | + * @var \Wordlift_Entity_Type_Service |
|
| 16 | + */ |
|
| 17 | + private $entity_type_service; |
|
| 18 | + /** |
|
| 19 | + * @var \Wordlift_Property_Getter |
|
| 20 | + */ |
|
| 21 | + private $property_getter; |
|
| 22 | + /** |
|
| 23 | + * @var Type_Service |
|
| 24 | + */ |
|
| 25 | + private $term_entity_type_service; |
|
| 26 | + /** |
|
| 27 | + * @var \Wordlift_Entity_Service |
|
| 28 | + */ |
|
| 29 | + private $entity_service; |
|
| 30 | + |
|
| 31 | + public function __construct( $entity_type_service, $property_getter ) { |
|
| 32 | + $this->entity_type_service = $entity_type_service; |
|
| 33 | + $this->property_getter = $property_getter; |
|
| 34 | + $this->term_entity_type_service = Type_Service::get_instance(); |
|
| 35 | + $this->entity_service = \Wordlift_Entity_Service::get_instance(); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function init() { |
|
| 39 | + add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 ); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function wl_term_jsonld_array( $data, $term_id ) { |
|
| 43 | + $jsonld = $data['jsonld']; |
|
| 44 | + $references = $data['references']; |
|
| 45 | + |
|
| 46 | + $term_jsonld_data = $this->get_jsonld_data_for_term( $term_id ); |
|
| 47 | + |
|
| 48 | + // Return early if we dont have the entity data |
|
| 49 | + // for the term. |
|
| 50 | + if ( ! $term_jsonld_data ) { |
|
| 51 | + return $data; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + $term_jsonld = $term_jsonld_data['jsonld']; |
|
| 55 | + |
|
| 56 | + $references = array_merge( $references, $term_jsonld_data['references'] ); |
|
| 57 | + |
|
| 58 | + array_unshift( $jsonld, $term_jsonld ); |
|
| 59 | + |
|
| 60 | + return array( |
|
| 61 | + 'jsonld' => $jsonld, |
|
| 62 | + 'references' => $references, |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + private function get_jsonld_data_for_term( $term_id ) { |
|
| 67 | + |
|
| 68 | + $id = $this->entity_service->get_uri( $term_id, Object_Type_Enum::TERM ); |
|
| 69 | + |
|
| 70 | + // If we don't have a dataset URI, then don't publish the term data |
|
| 71 | + // on this page. |
|
| 72 | + if ( ! $id ) { |
|
| 73 | + return false; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $references = array(); |
|
| 77 | + $term = get_term( $term_id ); |
|
| 78 | + $permalink = get_term_link( $term ); |
|
| 79 | + |
|
| 80 | + $custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id ); |
|
| 81 | + $term = get_term( $term_id ); |
|
| 82 | + $jsonld = array( |
|
| 83 | + '@context' => 'http://schema.org', |
|
| 84 | + 'name' => $term->name, |
|
| 85 | + '@type' => $this->term_entity_type_service->get_entity_types_labels( $term_id ), |
|
| 86 | + '@id' => $id, |
|
| 87 | + 'description' => $term->description, |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + if ( ! $custom_fields || ! is_array( $custom_fields ) ) { |
|
| 91 | + return $jsonld; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + foreach ( $custom_fields as $key => $value ) { |
|
| 95 | + $name = $this->relative_to_schema_context( $value['predicate'] ); |
|
| 96 | + $value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM ); |
|
| 97 | + $value = $this->process_value( $value, $references ); |
|
| 98 | + if ( ! isset( $value ) || |
|
| 99 | + is_array( $value ) && empty( $value ) || |
|
| 100 | + is_string( $value ) && empty( $value ) ) { |
|
| 101 | + continue; |
|
| 102 | + } |
|
| 103 | + $jsonld[ $name ] = $value; |
|
| 104 | + |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ( $permalink ) { |
|
| 108 | + $jsonld['mainEntityOfPage'] = $permalink; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return apply_filters( |
|
| 112 | + 'wl_no_vocabulary_term_jsonld_array', |
|
| 113 | + array( |
|
| 114 | + 'jsonld' => $jsonld, |
|
| 115 | + 'references' => $references, |
|
| 116 | + ), |
|
| 117 | + $term_id |
|
| 118 | + ); |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + private function relative_to_schema_context( $predicate ) { |
|
| 123 | + return str_replace( 'http://schema.org/', '', $predicate ); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + private function process_value( $value, &$references ) { |
|
| 127 | + |
|
| 128 | + if ( is_array( $value ) |
|
| 129 | + && count( $value ) > 0 |
|
| 130 | + && $value[0] instanceof \Wordlift_Property_Entity_Reference ) { |
|
| 131 | + |
|
| 132 | + // All of the references from the custom fields are post references. |
|
| 133 | + $references = array_merge( |
|
| 134 | + $references, |
|
| 135 | + array_map( |
|
| 136 | + function ( $property_entity_reference ) { |
|
| 137 | + /** |
|
| 138 | + * @var $property_entity_reference \Wordlift_Property_Entity_Reference |
|
| 139 | + */ |
|
| 140 | + return $property_entity_reference->to_reference(); |
|
| 141 | + }, |
|
| 142 | + $value |
|
| 143 | + ) |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + return array_map( |
|
| 147 | + function ( $reference ) { |
|
| 148 | + /** |
|
| 149 | + * @var $reference \Wordlift_Property_Entity_Reference |
|
| 150 | + */ |
|
| 151 | + return array( '@id' => $reference->get_url() ); |
|
| 152 | + }, |
|
| 153 | + $value |
|
| 154 | + ); |
|
| 155 | + |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + return $value; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | 161 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | private $entity_service; |
| 30 | 30 | |
| 31 | - public function __construct( $entity_type_service, $property_getter ) { |
|
| 31 | + public function __construct($entity_type_service, $property_getter) { |
|
| 32 | 32 | $this->entity_type_service = $entity_type_service; |
| 33 | 33 | $this->property_getter = $property_getter; |
| 34 | 34 | $this->term_entity_type_service = Type_Service::get_instance(); |
@@ -36,26 +36,26 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function init() { |
| 39 | - add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 ); |
|
| 39 | + add_filter('wl_term_jsonld_array', array($this, 'wl_term_jsonld_array'), 10, 2); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function wl_term_jsonld_array( $data, $term_id ) { |
|
| 42 | + public function wl_term_jsonld_array($data, $term_id) { |
|
| 43 | 43 | $jsonld = $data['jsonld']; |
| 44 | 44 | $references = $data['references']; |
| 45 | 45 | |
| 46 | - $term_jsonld_data = $this->get_jsonld_data_for_term( $term_id ); |
|
| 46 | + $term_jsonld_data = $this->get_jsonld_data_for_term($term_id); |
|
| 47 | 47 | |
| 48 | 48 | // Return early if we dont have the entity data |
| 49 | 49 | // for the term. |
| 50 | - if ( ! $term_jsonld_data ) { |
|
| 50 | + if ( ! $term_jsonld_data) { |
|
| 51 | 51 | return $data; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $term_jsonld = $term_jsonld_data['jsonld']; |
| 55 | 55 | |
| 56 | - $references = array_merge( $references, $term_jsonld_data['references'] ); |
|
| 56 | + $references = array_merge($references, $term_jsonld_data['references']); |
|
| 57 | 57 | |
| 58 | - array_unshift( $jsonld, $term_jsonld ); |
|
| 58 | + array_unshift($jsonld, $term_jsonld); |
|
| 59 | 59 | |
| 60 | 60 | return array( |
| 61 | 61 | 'jsonld' => $jsonld, |
@@ -63,48 +63,48 @@ discard block |
||
| 63 | 63 | ); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - private function get_jsonld_data_for_term( $term_id ) { |
|
| 66 | + private function get_jsonld_data_for_term($term_id) { |
|
| 67 | 67 | |
| 68 | - $id = $this->entity_service->get_uri( $term_id, Object_Type_Enum::TERM ); |
|
| 68 | + $id = $this->entity_service->get_uri($term_id, Object_Type_Enum::TERM); |
|
| 69 | 69 | |
| 70 | 70 | // If we don't have a dataset URI, then don't publish the term data |
| 71 | 71 | // on this page. |
| 72 | - if ( ! $id ) { |
|
| 72 | + if ( ! $id) { |
|
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $references = array(); |
| 77 | - $term = get_term( $term_id ); |
|
| 78 | - $permalink = get_term_link( $term ); |
|
| 77 | + $term = get_term($term_id); |
|
| 78 | + $permalink = get_term_link($term); |
|
| 79 | 79 | |
| 80 | - $custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id ); |
|
| 81 | - $term = get_term( $term_id ); |
|
| 80 | + $custom_fields = $this->entity_type_service->get_custom_fields_for_term($term_id); |
|
| 81 | + $term = get_term($term_id); |
|
| 82 | 82 | $jsonld = array( |
| 83 | 83 | '@context' => 'http://schema.org', |
| 84 | 84 | 'name' => $term->name, |
| 85 | - '@type' => $this->term_entity_type_service->get_entity_types_labels( $term_id ), |
|
| 85 | + '@type' => $this->term_entity_type_service->get_entity_types_labels($term_id), |
|
| 86 | 86 | '@id' => $id, |
| 87 | 87 | 'description' => $term->description, |
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | - if ( ! $custom_fields || ! is_array( $custom_fields ) ) { |
|
| 90 | + if ( ! $custom_fields || ! is_array($custom_fields)) { |
|
| 91 | 91 | return $jsonld; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - foreach ( $custom_fields as $key => $value ) { |
|
| 95 | - $name = $this->relative_to_schema_context( $value['predicate'] ); |
|
| 96 | - $value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM ); |
|
| 97 | - $value = $this->process_value( $value, $references ); |
|
| 98 | - if ( ! isset( $value ) || |
|
| 99 | - is_array( $value ) && empty( $value ) || |
|
| 100 | - is_string( $value ) && empty( $value ) ) { |
|
| 94 | + foreach ($custom_fields as $key => $value) { |
|
| 95 | + $name = $this->relative_to_schema_context($value['predicate']); |
|
| 96 | + $value = $this->property_getter->get($term_id, $key, Object_Type_Enum::TERM); |
|
| 97 | + $value = $this->process_value($value, $references); |
|
| 98 | + if ( ! isset($value) || |
|
| 99 | + is_array($value) && empty($value) || |
|
| 100 | + is_string($value) && empty($value)) { |
|
| 101 | 101 | continue; |
| 102 | 102 | } |
| 103 | - $jsonld[ $name ] = $value; |
|
| 103 | + $jsonld[$name] = $value; |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - if ( $permalink ) { |
|
| 107 | + if ($permalink) { |
|
| 108 | 108 | $jsonld['mainEntityOfPage'] = $permalink; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -119,21 +119,21 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - private function relative_to_schema_context( $predicate ) { |
|
| 123 | - return str_replace( 'http://schema.org/', '', $predicate ); |
|
| 122 | + private function relative_to_schema_context($predicate) { |
|
| 123 | + return str_replace('http://schema.org/', '', $predicate); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - private function process_value( $value, &$references ) { |
|
| 126 | + private function process_value($value, &$references) { |
|
| 127 | 127 | |
| 128 | - if ( is_array( $value ) |
|
| 129 | - && count( $value ) > 0 |
|
| 130 | - && $value[0] instanceof \Wordlift_Property_Entity_Reference ) { |
|
| 128 | + if (is_array($value) |
|
| 129 | + && count($value) > 0 |
|
| 130 | + && $value[0] instanceof \Wordlift_Property_Entity_Reference) { |
|
| 131 | 131 | |
| 132 | 132 | // All of the references from the custom fields are post references. |
| 133 | 133 | $references = array_merge( |
| 134 | 134 | $references, |
| 135 | 135 | array_map( |
| 136 | - function ( $property_entity_reference ) { |
|
| 136 | + function($property_entity_reference) { |
|
| 137 | 137 | /** |
| 138 | 138 | * @var $property_entity_reference \Wordlift_Property_Entity_Reference |
| 139 | 139 | */ |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | 146 | return array_map( |
| 147 | - function ( $reference ) { |
|
| 147 | + function($reference) { |
|
| 148 | 148 | /** |
| 149 | 149 | * @var $reference \Wordlift_Property_Entity_Reference |
| 150 | 150 | */ |
| 151 | - return array( '@id' => $reference->get_url() ); |
|
| 151 | + return array('@id' => $reference->get_url()); |
|
| 152 | 152 | }, |
| 153 | 153 | $value |
| 154 | 154 | ); |
@@ -19,81 +19,81 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | function wl_entity_get_by_title( $title, $autocomplete = false, $include_alias = true, $limit = false, $schema_types = array() ) { |
| 21 | 21 | |
| 22 | - global $wpdb; |
|
| 23 | - |
|
| 24 | - $schema_type_query = ''; |
|
| 25 | - |
|
| 26 | - if ( $schema_types ) { |
|
| 27 | - $schema_type_query = ' AND t.name IN (' . join( |
|
| 28 | - ',', |
|
| 29 | - array_map( |
|
| 30 | - function ( $schema_type ) { |
|
| 31 | - return "'" . esc_sql( $schema_type ) . "'"; |
|
| 32 | - }, |
|
| 33 | - $schema_types |
|
| 34 | - ) |
|
| 35 | - ) . ')'; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // Search by substring |
|
| 39 | - if ( $autocomplete ) { |
|
| 40 | - $title = '%' . $title . '%'; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - // The title is a LIKE query. |
|
| 44 | - $query = 'SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug' |
|
| 45 | - . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t" |
|
| 46 | - . ' WHERE p.post_title LIKE %s' |
|
| 47 | - . ' AND t.term_id = tt.term_id' |
|
| 48 | - . ' AND tt.taxonomy = %s' |
|
| 49 | - . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
| 50 | - . ' AND tr.object_id = p.ID' |
|
| 51 | - // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
| 52 | - . " AND p.post_status != 'trash'" |
|
| 53 | - . $schema_type_query; |
|
| 54 | - |
|
| 55 | - $params = array( |
|
| 56 | - $title, |
|
| 57 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - if ( $include_alias ) { |
|
| 61 | - |
|
| 62 | - $query .= ' UNION' |
|
| 63 | - . " 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" |
|
| 64 | - . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m" |
|
| 65 | - . ' WHERE m.meta_key = %s AND m.meta_value LIKE %s' |
|
| 66 | - . ' AND m.post_id = p.ID' |
|
| 67 | - . ' AND t.term_id = tt.term_id' |
|
| 68 | - . ' AND tt.taxonomy = %s' |
|
| 69 | - . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
| 70 | - . ' AND tr.object_id = p.ID' |
|
| 71 | - // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
| 72 | - . " AND p.post_status != 'trash'" |
|
| 73 | - . $schema_type_query; |
|
| 74 | - |
|
| 75 | - $params = array_merge( |
|
| 76 | - $params, |
|
| 77 | - array( |
|
| 78 | - Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, |
|
| 79 | - $title, |
|
| 80 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ( $limit ) { |
|
| 87 | - $query .= ' LIMIT %d'; |
|
| 88 | - $params[] = $limit; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $wpdb->get_results( |
|
| 92 | - $wpdb->prepare( |
|
| 93 | - $query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 94 | - $params |
|
| 95 | - ) |
|
| 96 | - ); |
|
| 22 | + global $wpdb; |
|
| 23 | + |
|
| 24 | + $schema_type_query = ''; |
|
| 25 | + |
|
| 26 | + if ( $schema_types ) { |
|
| 27 | + $schema_type_query = ' AND t.name IN (' . join( |
|
| 28 | + ',', |
|
| 29 | + array_map( |
|
| 30 | + function ( $schema_type ) { |
|
| 31 | + return "'" . esc_sql( $schema_type ) . "'"; |
|
| 32 | + }, |
|
| 33 | + $schema_types |
|
| 34 | + ) |
|
| 35 | + ) . ')'; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // Search by substring |
|
| 39 | + if ( $autocomplete ) { |
|
| 40 | + $title = '%' . $title . '%'; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // The title is a LIKE query. |
|
| 44 | + $query = 'SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug' |
|
| 45 | + . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t" |
|
| 46 | + . ' WHERE p.post_title LIKE %s' |
|
| 47 | + . ' AND t.term_id = tt.term_id' |
|
| 48 | + . ' AND tt.taxonomy = %s' |
|
| 49 | + . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
| 50 | + . ' AND tr.object_id = p.ID' |
|
| 51 | + // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
| 52 | + . " AND p.post_status != 'trash'" |
|
| 53 | + . $schema_type_query; |
|
| 54 | + |
|
| 55 | + $params = array( |
|
| 56 | + $title, |
|
| 57 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + if ( $include_alias ) { |
|
| 61 | + |
|
| 62 | + $query .= ' UNION' |
|
| 63 | + . " 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" |
|
| 64 | + . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m" |
|
| 65 | + . ' WHERE m.meta_key = %s AND m.meta_value LIKE %s' |
|
| 66 | + . ' AND m.post_id = p.ID' |
|
| 67 | + . ' AND t.term_id = tt.term_id' |
|
| 68 | + . ' AND tt.taxonomy = %s' |
|
| 69 | + . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
| 70 | + . ' AND tr.object_id = p.ID' |
|
| 71 | + // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
| 72 | + . " AND p.post_status != 'trash'" |
|
| 73 | + . $schema_type_query; |
|
| 74 | + |
|
| 75 | + $params = array_merge( |
|
| 76 | + $params, |
|
| 77 | + array( |
|
| 78 | + Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, |
|
| 79 | + $title, |
|
| 80 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ( $limit ) { |
|
| 87 | + $query .= ' LIMIT %d'; |
|
| 88 | + $params[] = $limit; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $wpdb->get_results( |
|
| 92 | + $wpdb->prepare( |
|
| 93 | + $query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 94 | + $params |
|
| 95 | + ) |
|
| 96 | + ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -103,43 +103,43 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | function wl_entity_ajax_get_by_title() { |
| 105 | 105 | |
| 106 | - // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
| 107 | - // |
|
| 108 | - // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
| 109 | - // Get the title to search. |
|
| 110 | - if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 111 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 112 | - @ob_clean(); |
|
| 113 | - wp_send_json_error( 'The title parameter is required.' ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
| 117 | - // |
|
| 118 | - // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
| 119 | - $title = sanitize_text_field( wp_unslash( $_POST['title'] ? $_POST['title'] : $_GET['title'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 120 | - |
|
| 121 | - // Are we searching for a specific title or for a containing title? |
|
| 122 | - $autocomplete = isset( $_GET['autocomplete'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 123 | - |
|
| 124 | - // Are we searching also for the aliases? |
|
| 125 | - $include_alias = isset( $_GET['alias'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 126 | - |
|
| 127 | - // Get the edit link. |
|
| 128 | - $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME ); |
|
| 129 | - $edit_link = $post_type_object->_edit_link . '&action=edit'; |
|
| 130 | - |
|
| 131 | - // Prepare the response with the edit link. |
|
| 132 | - $response = array( |
|
| 133 | - 'edit_link' => $edit_link, |
|
| 134 | - 'results' => wl_entity_get_by_title( $title, $autocomplete, $include_alias ), |
|
| 135 | - ); |
|
| 136 | - |
|
| 137 | - // Clean any buffer. |
|
| 138 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 139 | - @ob_clean(); |
|
| 140 | - |
|
| 141 | - // Send the success response. |
|
| 142 | - wp_send_json_success( $response ); |
|
| 106 | + // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
| 107 | + // |
|
| 108 | + // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
| 109 | + // Get the title to search. |
|
| 110 | + if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 111 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 112 | + @ob_clean(); |
|
| 113 | + wp_send_json_error( 'The title parameter is required.' ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
| 117 | + // |
|
| 118 | + // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
| 119 | + $title = sanitize_text_field( wp_unslash( $_POST['title'] ? $_POST['title'] : $_GET['title'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 120 | + |
|
| 121 | + // Are we searching for a specific title or for a containing title? |
|
| 122 | + $autocomplete = isset( $_GET['autocomplete'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 123 | + |
|
| 124 | + // Are we searching also for the aliases? |
|
| 125 | + $include_alias = isset( $_GET['alias'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 126 | + |
|
| 127 | + // Get the edit link. |
|
| 128 | + $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME ); |
|
| 129 | + $edit_link = $post_type_object->_edit_link . '&action=edit'; |
|
| 130 | + |
|
| 131 | + // Prepare the response with the edit link. |
|
| 132 | + $response = array( |
|
| 133 | + 'edit_link' => $edit_link, |
|
| 134 | + 'results' => wl_entity_get_by_title( $title, $autocomplete, $include_alias ), |
|
| 135 | + ); |
|
| 136 | + |
|
| 137 | + // Clean any buffer. |
|
| 138 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 139 | + @ob_clean(); |
|
| 140 | + |
|
| 141 | + // Send the success response. |
|
| 142 | + wp_send_json_success( $response ); |
|
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
@@ -17,27 +17,27 @@ discard block |
||
| 17 | 17 | * @return array An array of WP_Post instances. |
| 18 | 18 | * @since 3.0.0 |
| 19 | 19 | */ |
| 20 | -function wl_entity_get_by_title( $title, $autocomplete = false, $include_alias = true, $limit = false, $schema_types = array() ) { |
|
| 20 | +function wl_entity_get_by_title($title, $autocomplete = false, $include_alias = true, $limit = false, $schema_types = array()) { |
|
| 21 | 21 | |
| 22 | 22 | global $wpdb; |
| 23 | 23 | |
| 24 | 24 | $schema_type_query = ''; |
| 25 | 25 | |
| 26 | - if ( $schema_types ) { |
|
| 27 | - $schema_type_query = ' AND t.name IN (' . join( |
|
| 26 | + if ($schema_types) { |
|
| 27 | + $schema_type_query = ' AND t.name IN ('.join( |
|
| 28 | 28 | ',', |
| 29 | 29 | array_map( |
| 30 | - function ( $schema_type ) { |
|
| 31 | - return "'" . esc_sql( $schema_type ) . "'"; |
|
| 30 | + function($schema_type) { |
|
| 31 | + return "'".esc_sql($schema_type)."'"; |
|
| 32 | 32 | }, |
| 33 | 33 | $schema_types |
| 34 | 34 | ) |
| 35 | - ) . ')'; |
|
| 35 | + ).')'; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Search by substring |
| 39 | - if ( $autocomplete ) { |
|
| 40 | - $title = '%' . $title . '%'; |
|
| 39 | + if ($autocomplete) { |
|
| 40 | + $title = '%'.$title.'%'; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // The title is a LIKE query. |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | - if ( $include_alias ) { |
|
| 60 | + if ($include_alias) { |
|
| 61 | 61 | |
| 62 | 62 | $query .= ' UNION' |
| 63 | 63 | . " 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" |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ( $limit ) { |
|
| 86 | + if ($limit) { |
|
| 87 | 87 | $query .= ' LIMIT %d'; |
| 88 | 88 | $params[] = $limit; |
| 89 | 89 | } |
@@ -107,31 +107,31 @@ discard block |
||
| 107 | 107 | // |
| 108 | 108 | // See https://github.com/insideout10/wordlift-plugin/issues/438. |
| 109 | 109 | // Get the title to search. |
| 110 | - if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 110 | + if (empty($_POST['title']) && empty($_GET['title'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 111 | 111 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 112 | 112 | @ob_clean(); |
| 113 | - wp_send_json_error( 'The title parameter is required.' ); |
|
| 113 | + wp_send_json_error('The title parameter is required.'); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
| 117 | 117 | // |
| 118 | 118 | // See https://github.com/insideout10/wordlift-plugin/issues/438. |
| 119 | - $title = sanitize_text_field( wp_unslash( $_POST['title'] ? $_POST['title'] : $_GET['title'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 119 | + $title = sanitize_text_field(wp_unslash($_POST['title'] ? $_POST['title'] : $_GET['title'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
| 120 | 120 | |
| 121 | 121 | // Are we searching for a specific title or for a containing title? |
| 122 | - $autocomplete = isset( $_GET['autocomplete'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 122 | + $autocomplete = isset($_GET['autocomplete']); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 123 | 123 | |
| 124 | 124 | // Are we searching also for the aliases? |
| 125 | - $include_alias = isset( $_GET['alias'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 125 | + $include_alias = isset($_GET['alias']); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 126 | 126 | |
| 127 | 127 | // Get the edit link. |
| 128 | - $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME ); |
|
| 129 | - $edit_link = $post_type_object->_edit_link . '&action=edit'; |
|
| 128 | + $post_type_object = get_post_type_object(Wordlift_Entity_Service::TYPE_NAME); |
|
| 129 | + $edit_link = $post_type_object->_edit_link.'&action=edit'; |
|
| 130 | 130 | |
| 131 | 131 | // Prepare the response with the edit link. |
| 132 | 132 | $response = array( |
| 133 | 133 | 'edit_link' => $edit_link, |
| 134 | - 'results' => wl_entity_get_by_title( $title, $autocomplete, $include_alias ), |
|
| 134 | + 'results' => wl_entity_get_by_title($title, $autocomplete, $include_alias), |
|
| 135 | 135 | ); |
| 136 | 136 | |
| 137 | 137 | // Clean any buffer. |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | @ob_clean(); |
| 140 | 140 | |
| 141 | 141 | // Send the success response. |
| 142 | - wp_send_json_success( $response ); |
|
| 142 | + wp_send_json_success($response); |
|
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | -add_action( 'wp_ajax_entity_by_title', 'wl_entity_ajax_get_by_title' ); |
|
| 146 | +add_action('wp_ajax_entity_by_title', 'wl_entity_ajax_get_by_title'); |
|
@@ -5,9 +5,9 @@ |
||
| 5 | 5 | |
| 6 | 6 | // Autoloader for dependencies. |
| 7 | 7 | if ( file_exists( __DIR__ . '/third-party/vendor/scoper-autoload.php' ) ) { |
| 8 | - require __DIR__ . '/third-party/vendor/scoper-autoload.php'; |
|
| 8 | + require __DIR__ . '/third-party/vendor/scoper-autoload.php'; |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
| 12 | - require __DIR__ . '/vendor/autoload.php'; |
|
| 12 | + require __DIR__ . '/vendor/autoload.php'; |
|
| 13 | 13 | } |
@@ -4,10 +4,10 @@ |
||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | // Autoloader for dependencies. |
| 7 | -if ( file_exists( __DIR__ . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 8 | - require __DIR__ . '/third-party/vendor/scoper-autoload.php'; |
|
| 7 | +if (file_exists(__DIR__.'/third-party/vendor/scoper-autoload.php')) { |
|
| 8 | + require __DIR__.'/third-party/vendor/scoper-autoload.php'; |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | -if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
| 12 | - require __DIR__ . '/vendor/autoload.php'; |
|
| 11 | +if (file_exists(__DIR__.'/vendor/autoload.php')) { |
|
| 12 | + require __DIR__.'/vendor/autoload.php'; |
|
| 13 | 13 | } |
@@ -17,16 +17,16 @@ discard block |
||
| 17 | 17 | use Wordlift\Modules\Pods\WlEntityField\Filters; |
| 18 | 18 | |
| 19 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | - exit; |
|
| 20 | + exit; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) || ! defined( 'PODS_VERSION' ) ) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // Autoloader for plugin itself. |
| 28 | 28 | if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
| 29 | - require __DIR__ . '/vendor/autoload.php'; |
|
| 29 | + require __DIR__ . '/vendor/autoload.php'; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $container_builder = new ContainerBuilder(); |
@@ -35,28 +35,28 @@ 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 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 42 | - $field_definition = $factory->get_field_definition(); |
|
| 43 | - $field_definition->register(); |
|
| 41 | + $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 42 | + $field_definition = $factory->get_field_definition(); |
|
| 43 | + $field_definition->register(); |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var $installer \Wordlift\Modules\Pods\Installer |
|
| 47 | - */ |
|
| 48 | - $installer = $container_builder->get( Installer::class ); |
|
| 49 | - $installer->register_hooks(); |
|
| 45 | + /** |
|
| 46 | + * @var $installer \Wordlift\Modules\Pods\Installer |
|
| 47 | + */ |
|
| 48 | + $installer = $container_builder->get( Installer::class ); |
|
| 49 | + $installer->register_hooks(); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var $notices \Wordlift\Modules\Pods\Notices |
|
| 53 | - */ |
|
| 54 | - $notices = $container_builder->get( Notices::class ); |
|
| 55 | - $notices->register_hooks(); |
|
| 51 | + /** |
|
| 52 | + * @var $notices \Wordlift\Modules\Pods\Notices |
|
| 53 | + */ |
|
| 54 | + $notices = $container_builder->get( Notices::class ); |
|
| 55 | + $notices->register_hooks(); |
|
| 56 | 56 | |
| 57 | - $filters = $container_builder->get( Filters::class ); |
|
| 57 | + $filters = $container_builder->get( Filters::class ); |
|
| 58 | 58 | |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | ); |
| 61 | 61 | |
| 62 | 62 | |
@@ -16,45 +16,45 @@ |
||
| 16 | 16 | use Wordlift\Modules\Pods\Notices; |
| 17 | 17 | use Wordlift\Modules\Pods\WlEntityField\Filters; |
| 18 | 18 | |
| 19 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 19 | +if ( ! defined('ABSPATH')) { |
|
| 20 | 20 | exit; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) || ! defined( 'PODS_VERSION' ) ) { |
|
| 23 | +if ( ! apply_filters('wl_feature__enable__pods-integration', false) || ! defined('PODS_VERSION')) { |
|
| 24 | 24 | return; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // Autoloader for plugin itself. |
| 28 | -if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
| 29 | - require __DIR__ . '/vendor/autoload.php'; |
|
| 28 | +if (file_exists(__DIR__.'/vendor/autoload.php')) { |
|
| 29 | + require __DIR__.'/vendor/autoload.php'; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $container_builder = new ContainerBuilder(); |
| 33 | -$loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 34 | -$loader->load( 'services.yml' ); |
|
| 33 | +$loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
| 34 | +$loader->load('services.yml'); |
|
| 35 | 35 | $container_builder->compile(); |
| 36 | 36 | |
| 37 | 37 | add_action( |
| 38 | 38 | 'plugins_loaded', |
| 39 | - function () use ( $container_builder ) { |
|
| 39 | + function() use ($container_builder) { |
|
| 40 | 40 | |
| 41 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 41 | + $factory = $container_builder->get(FieldDefinitionFactory::class); |
|
| 42 | 42 | $field_definition = $factory->get_field_definition(); |
| 43 | 43 | $field_definition->register(); |
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * @var $installer \Wordlift\Modules\Pods\Installer |
| 47 | 47 | */ |
| 48 | - $installer = $container_builder->get( Installer::class ); |
|
| 48 | + $installer = $container_builder->get(Installer::class); |
|
| 49 | 49 | $installer->register_hooks(); |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * @var $notices \Wordlift\Modules\Pods\Notices |
| 53 | 53 | */ |
| 54 | - $notices = $container_builder->get( Notices::class ); |
|
| 54 | + $notices = $container_builder->get(Notices::class); |
|
| 55 | 55 | $notices->register_hooks(); |
| 56 | 56 | |
| 57 | - $filters = $container_builder->get( Filters::class ); |
|
| 57 | + $filters = $container_builder->get(Filters::class); |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | ); |
@@ -4,60 +4,60 @@ |
||
| 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; |
|
| 23 | - |
|
| 24 | - private static $pod_types_map = array( |
|
| 25 | - self::POST => 'post_type', |
|
| 26 | - self::TERM => 'taxonomy', |
|
| 27 | - ); |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param int $object_type |
|
| 31 | - * @param $identifier |
|
| 32 | - * @param $custom_fields |
|
| 33 | - */ |
|
| 34 | - public function __construct( $object_type, $identifier, $custom_fields ) { |
|
| 35 | - $this->object_type = $object_type; |
|
| 36 | - $this->identifier = $identifier; |
|
| 37 | - $this->custom_fields = $custom_fields; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @return int |
|
| 42 | - */ |
|
| 43 | - public function get_object_type() { |
|
| 44 | - return $this->object_type; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function get_pod_name() { |
|
| 48 | - if ( self::POST === $this->object_type ) { |
|
| 49 | - return get_post_type( $this->identifier ); |
|
| 50 | - } elseif ( self::TERM === $this->object_type ) { |
|
| 51 | - return get_term( $this->identifier )->taxonomy; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function get_pod_type() { |
|
| 56 | - return self::$pod_types_map[ $this->object_type ]; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function get_custom_fields() { |
|
| 60 | - return $this->custom_fields; |
|
| 61 | - } |
|
| 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 | + |
|
| 24 | + private static $pod_types_map = array( |
|
| 25 | + self::POST => 'post_type', |
|
| 26 | + self::TERM => 'taxonomy', |
|
| 27 | + ); |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param int $object_type |
|
| 31 | + * @param $identifier |
|
| 32 | + * @param $custom_fields |
|
| 33 | + */ |
|
| 34 | + public function __construct( $object_type, $identifier, $custom_fields ) { |
|
| 35 | + $this->object_type = $object_type; |
|
| 36 | + $this->identifier = $identifier; |
|
| 37 | + $this->custom_fields = $custom_fields; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @return int |
|
| 42 | + */ |
|
| 43 | + public function get_object_type() { |
|
| 44 | + return $this->object_type; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function get_pod_name() { |
|
| 48 | + if ( self::POST === $this->object_type ) { |
|
| 49 | + return get_post_type( $this->identifier ); |
|
| 50 | + } elseif ( self::TERM === $this->object_type ) { |
|
| 51 | + return get_term( $this->identifier )->taxonomy; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function get_pod_type() { |
|
| 56 | + return self::$pod_types_map[ $this->object_type ]; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function get_custom_fields() { |
|
| 60 | + return $this->custom_fields; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param $identifier |
| 32 | 32 | * @param $custom_fields |
| 33 | 33 | */ |
| 34 | - public function __construct( $object_type, $identifier, $custom_fields ) { |
|
| 34 | + public function __construct($object_type, $identifier, $custom_fields) { |
|
| 35 | 35 | $this->object_type = $object_type; |
| 36 | 36 | $this->identifier = $identifier; |
| 37 | 37 | $this->custom_fields = $custom_fields; |
@@ -45,15 +45,15 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function get_pod_name() { |
| 48 | - if ( self::POST === $this->object_type ) { |
|
| 49 | - return get_post_type( $this->identifier ); |
|
| 50 | - } elseif ( self::TERM === $this->object_type ) { |
|
| 51 | - return get_term( $this->identifier )->taxonomy; |
|
| 48 | + if (self::POST === $this->object_type) { |
|
| 49 | + return get_post_type($this->identifier); |
|
| 50 | + } elseif (self::TERM === $this->object_type) { |
|
| 51 | + return get_term($this->identifier)->taxonomy; |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public function get_pod_type() { |
| 56 | - return self::$pod_types_map[ $this->object_type ]; |
|
| 56 | + return self::$pod_types_map[$this->object_type]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public function get_custom_fields() { |