@@ -4,100 +4,100 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Schema { |
| 6 | 6 | |
| 7 | - public function get_context_type() { |
|
| 8 | - |
|
| 9 | - if ( isset( $_REQUEST['post'] ) ) { |
|
| 10 | - return Context::POST; |
|
| 11 | - } |
|
| 12 | - if ( isset( $_REQUEST['tag_ID'] ) ) { |
|
| 13 | - return Context::TERM; |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 17 | - return Context::ADMIN_AJAX; |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - return Context::UNKNOWN; |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @return Context |
|
| 26 | - */ |
|
| 27 | - public function get() { |
|
| 28 | - // we need to identify the context to filter the results. |
|
| 29 | - |
|
| 30 | - $identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) : ''; |
|
| 31 | - |
|
| 32 | - if ( $identifier ) { |
|
| 33 | - // If post identifier, get schema. |
|
| 34 | - return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - $identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : ''; |
|
| 38 | - |
|
| 39 | - if ( $identifier ) { |
|
| 40 | - // If post identifier, get schema. |
|
| 41 | - return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - if ( is_admin() && defined( 'DOING_AJAX' ) ) { |
|
| 45 | - return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() ); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - return new Context( Context::UNKNOWN, null, null ); |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return Schema_Field_Group[] |
|
| 54 | - */ |
|
| 55 | - private function get_fields_for_post( $identifier ) { |
|
| 56 | - $types = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier ); |
|
| 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 | - $types |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return Schema_Field_Group[] |
|
| 71 | - */ |
|
| 72 | - private function get_fields_for_term( $identifier ) { |
|
| 73 | - $term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 74 | - $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 75 | - |
|
| 76 | - return array_map( |
|
| 77 | - function ( $schema_type ) use ( $schema_classes ) { |
|
| 78 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 79 | - |
|
| 80 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 81 | - }, |
|
| 82 | - $term_entity_types |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - private function get_all_fields() { |
|
| 87 | - $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 88 | - $all_schema_slugs = $schema_classes->get_all_schema_slugs(); |
|
| 89 | - |
|
| 90 | - return array_filter( |
|
| 91 | - array_map( |
|
| 92 | - function ( $schema_type ) use ( $schema_classes ) { |
|
| 93 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 94 | - |
|
| 95 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 96 | - }, |
|
| 97 | - $all_schema_slugs |
|
| 98 | - ) |
|
| 99 | - ); |
|
| 100 | - } |
|
| 7 | + public function get_context_type() { |
|
| 8 | + |
|
| 9 | + if ( isset( $_REQUEST['post'] ) ) { |
|
| 10 | + return Context::POST; |
|
| 11 | + } |
|
| 12 | + if ( isset( $_REQUEST['tag_ID'] ) ) { |
|
| 13 | + return Context::TERM; |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 17 | + return Context::ADMIN_AJAX; |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + return Context::UNKNOWN; |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @return Context |
|
| 26 | + */ |
|
| 27 | + public function get() { |
|
| 28 | + // we need to identify the context to filter the results. |
|
| 29 | + |
|
| 30 | + $identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) : ''; |
|
| 31 | + |
|
| 32 | + if ( $identifier ) { |
|
| 33 | + // If post identifier, get schema. |
|
| 34 | + return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + $identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : ''; |
|
| 38 | + |
|
| 39 | + if ( $identifier ) { |
|
| 40 | + // If post identifier, get schema. |
|
| 41 | + return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + if ( is_admin() && defined( 'DOING_AJAX' ) ) { |
|
| 45 | + return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() ); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + return new Context( Context::UNKNOWN, null, null ); |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return Schema_Field_Group[] |
|
| 54 | + */ |
|
| 55 | + private function get_fields_for_post( $identifier ) { |
|
| 56 | + $types = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier ); |
|
| 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 | + $types |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return Schema_Field_Group[] |
|
| 71 | + */ |
|
| 72 | + private function get_fields_for_term( $identifier ) { |
|
| 73 | + $term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 74 | + $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 75 | + |
|
| 76 | + return array_map( |
|
| 77 | + function ( $schema_type ) use ( $schema_classes ) { |
|
| 78 | + $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 79 | + |
|
| 80 | + return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 81 | + }, |
|
| 82 | + $term_entity_types |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + private function get_all_fields() { |
|
| 87 | + $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
| 88 | + $all_schema_slugs = $schema_classes->get_all_schema_slugs(); |
|
| 89 | + |
|
| 90 | + return array_filter( |
|
| 91 | + array_map( |
|
| 92 | + function ( $schema_type ) use ( $schema_classes ) { |
|
| 93 | + $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 94 | + |
|
| 95 | + return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 96 | + }, |
|
| 97 | + $all_schema_slugs |
|
| 98 | + ) |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | } |
@@ -6,14 +6,14 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | public function get_context_type() { |
| 8 | 8 | |
| 9 | - if ( isset( $_REQUEST['post'] ) ) { |
|
| 9 | + if (isset($_REQUEST['post'])) { |
|
| 10 | 10 | return Context::POST; |
| 11 | 11 | } |
| 12 | - if ( isset( $_REQUEST['tag_ID'] ) ) { |
|
| 12 | + if (isset($_REQUEST['tag_ID'])) { |
|
| 13 | 13 | return Context::TERM; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 16 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
| 17 | 17 | return Context::ADMIN_AJAX; |
| 18 | 18 | } |
| 19 | 19 | |
@@ -27,40 +27,40 @@ discard block |
||
| 27 | 27 | public function get() { |
| 28 | 28 | // we need to identify the context to filter the results. |
| 29 | 29 | |
| 30 | - $identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) : ''; |
|
| 30 | + $identifier = isset($_REQUEST['post']) ? sanitize_text_field(wp_unslash($_REQUEST['post'])) : ''; |
|
| 31 | 31 | |
| 32 | - if ( $identifier ) { |
|
| 32 | + if ($identifier) { |
|
| 33 | 33 | // If post identifier, get schema. |
| 34 | - return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) ); |
|
| 34 | + return new Context(Context::POST, $identifier, $this->get_fields_for_post($identifier)); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - $identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : ''; |
|
| 37 | + $identifier = isset($_REQUEST['tag_ID']) ? sanitize_text_field(wp_unslash($_REQUEST['tag_ID'])) : ''; |
|
| 38 | 38 | |
| 39 | - if ( $identifier ) { |
|
| 39 | + if ($identifier) { |
|
| 40 | 40 | // If post identifier, get schema. |
| 41 | - return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) ); |
|
| 41 | + return new Context(Context::TERM, $identifier, $this->get_fields_for_term($identifier)); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ( is_admin() && defined( 'DOING_AJAX' ) ) { |
|
| 45 | - return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() ); |
|
| 44 | + if (is_admin() && defined('DOING_AJAX')) { |
|
| 45 | + return new Context(Context::ADMIN_AJAX, null, $this->get_all_fields()); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - return new Context( Context::UNKNOWN, null, null ); |
|
| 48 | + return new Context(Context::UNKNOWN, null, null); |
|
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @return Schema_Field_Group[] |
| 54 | 54 | */ |
| 55 | - private function get_fields_for_post( $identifier ) { |
|
| 56 | - $types = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier ); |
|
| 55 | + private function get_fields_for_post($identifier) { |
|
| 56 | + $types = \Wordlift_Entity_Type_Service::get_instance()->get_names($identifier); |
|
| 57 | 57 | $schema_classes = \Wordlift_Schema_Service::get_instance(); |
| 58 | 58 | |
| 59 | 59 | return array_map( |
| 60 | - function ( $schema_type ) use ( $schema_classes ) { |
|
| 61 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 60 | + function($schema_type) use ($schema_classes) { |
|
| 61 | + $data = $schema_classes->get_schema(strtolower($schema_type)); |
|
| 62 | 62 | |
| 63 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 63 | + return new Schema_Field_Group($schema_type, $data['custom_fields']); |
|
| 64 | 64 | }, |
| 65 | 65 | $types |
| 66 | 66 | ); |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | /** |
| 70 | 70 | * @return Schema_Field_Group[] |
| 71 | 71 | */ |
| 72 | - private function get_fields_for_term( $identifier ) { |
|
| 73 | - $term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 72 | + private function get_fields_for_term($identifier) { |
|
| 73 | + $term_entity_types = get_term_meta((int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 74 | 74 | $schema_classes = \Wordlift_Schema_Service::get_instance(); |
| 75 | 75 | |
| 76 | 76 | return array_map( |
| 77 | - function ( $schema_type ) use ( $schema_classes ) { |
|
| 78 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 77 | + function($schema_type) use ($schema_classes) { |
|
| 78 | + $data = $schema_classes->get_schema(strtolower($schema_type)); |
|
| 79 | 79 | |
| 80 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 80 | + return new Schema_Field_Group($schema_type, $data['custom_fields']); |
|
| 81 | 81 | }, |
| 82 | 82 | $term_entity_types |
| 83 | 83 | ); |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | return array_filter( |
| 91 | 91 | array_map( |
| 92 | - function ( $schema_type ) use ( $schema_classes ) { |
|
| 93 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
| 92 | + function($schema_type) use ($schema_classes) { |
|
| 93 | + $data = $schema_classes->get_schema(strtolower($schema_type)); |
|
| 94 | 94 | |
| 95 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
| 95 | + return new Schema_Field_Group($schema_type, $data['custom_fields']); |
|
| 96 | 96 | }, |
| 97 | 97 | $all_schema_slugs |
| 98 | 98 | ) |