@@ -11,8 +11,8 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | function wl_set_entity_main_type( $post_id, $type_uri ) { |
| 13 | 13 | |
| 14 | - Wordlift_Entity_Type_Service::get_instance() |
|
| 15 | - ->set( $post_id, $type_uri ); |
|
| 14 | + Wordlift_Entity_Type_Service::get_instance() |
|
| 15 | + ->set( $post_id, $type_uri ); |
|
| 16 | 16 | |
| 17 | 17 | } |
| 18 | 18 | |
@@ -21,35 +21,35 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | function wl_print_entity_type_inline_js() { |
| 23 | 23 | |
| 24 | - $terms = get_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'get' => 'all', ) ); |
|
| 24 | + $terms = get_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'get' => 'all', ) ); |
|
| 25 | 25 | |
| 26 | - // Load the type data. |
|
| 27 | - $schema_service = Wordlift_Schema_Service::get_instance(); |
|
| 28 | - $entity_types = array_reduce( $terms, function ( $carry, $term ) use ( $schema_service ) { |
|
| 29 | - $type = $schema_service->get_schema( $term->slug ); |
|
| 26 | + // Load the type data. |
|
| 27 | + $schema_service = Wordlift_Schema_Service::get_instance(); |
|
| 28 | + $entity_types = array_reduce( $terms, function ( $carry, $term ) use ( $schema_service ) { |
|
| 29 | + $type = $schema_service->get_schema( $term->slug ); |
|
| 30 | 30 | |
| 31 | - // Skip if no `uri`. |
|
| 32 | - if ( empty( $type['uri'] ) ) { |
|
| 33 | - return $carry; |
|
| 34 | - } |
|
| 31 | + // Skip if no `uri`. |
|
| 32 | + if ( empty( $type['uri'] ) ) { |
|
| 33 | + return $carry; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - $carry[] = array( |
|
| 37 | - 'label' => $term->name, |
|
| 38 | - 'uri' => $type['uri'], |
|
| 39 | - 'css' => $type['css_class'], |
|
| 40 | - 'sameAs' => isset( $type['same_as'] ) ? $type['same_as'] : array(), |
|
| 41 | - 'slug' => $term->slug, |
|
| 42 | - 'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ), |
|
| 43 | - ); |
|
| 36 | + $carry[] = array( |
|
| 37 | + 'label' => $term->name, |
|
| 38 | + 'uri' => $type['uri'], |
|
| 39 | + 'css' => $type['css_class'], |
|
| 40 | + 'sameAs' => isset( $type['same_as'] ) ? $type['same_as'] : array(), |
|
| 41 | + 'slug' => $term->slug, |
|
| 42 | + 'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ), |
|
| 43 | + ); |
|
| 44 | 44 | |
| 45 | - return $carry; |
|
| 46 | - }, array() ); |
|
| 45 | + return $carry; |
|
| 46 | + }, array() ); |
|
| 47 | 47 | |
| 48 | - // Hook to the Block Editor script. |
|
| 49 | - wp_localize_script( 'wl-block-editor', '_wlEntityTypes', $entity_types ); |
|
| 48 | + // Hook to the Block Editor script. |
|
| 49 | + wp_localize_script( 'wl-block-editor', '_wlEntityTypes', $entity_types ); |
|
| 50 | 50 | |
| 51 | - // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
|
| 52 | - wp_localize_script( 'wl-classic-editor', '_wlEntityTypes', $entity_types ); |
|
| 51 | + // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
|
| 52 | + wp_localize_script( 'wl-classic-editor', '_wlEntityTypes', $entity_types ); |
|
| 53 | 53 | |
| 54 | 54 | } |
| 55 | 55 | |
@@ -9,10 +9,10 @@ discard block |
||
| 9 | 9 | * @deprecated use Wordlift_Entity_Type_Service::get_instance()->set( $post_id, $type_uri ) |
| 10 | 10 | * |
| 11 | 11 | */ |
| 12 | -function wl_set_entity_main_type( $post_id, $type_uri ) { |
|
| 12 | +function wl_set_entity_main_type($post_id, $type_uri) { |
|
| 13 | 13 | |
| 14 | 14 | Wordlift_Entity_Type_Service::get_instance() |
| 15 | - ->set( $post_id, $type_uri ); |
|
| 15 | + ->set($post_id, $type_uri); |
|
| 16 | 16 | |
| 17 | 17 | } |
| 18 | 18 | |
@@ -21,15 +21,15 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | function wl_print_entity_type_inline_js() { |
| 23 | 23 | |
| 24 | - $terms = get_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'get' => 'all', ) ); |
|
| 24 | + $terms = get_terms(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array('get' => 'all',)); |
|
| 25 | 25 | |
| 26 | 26 | // Load the type data. |
| 27 | 27 | $schema_service = Wordlift_Schema_Service::get_instance(); |
| 28 | - $entity_types = array_reduce( $terms, function ( $carry, $term ) use ( $schema_service ) { |
|
| 29 | - $type = $schema_service->get_schema( $term->slug ); |
|
| 28 | + $entity_types = array_reduce($terms, function($carry, $term) use ($schema_service) { |
|
| 29 | + $type = $schema_service->get_schema($term->slug); |
|
| 30 | 30 | |
| 31 | 31 | // Skip if no `uri`. |
| 32 | - if ( empty( $type['uri'] ) ) { |
|
| 32 | + if (empty($type['uri'])) { |
|
| 33 | 33 | return $carry; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -37,22 +37,22 @@ discard block |
||
| 37 | 37 | 'label' => $term->name, |
| 38 | 38 | 'uri' => $type['uri'], |
| 39 | 39 | 'css' => $type['css_class'], |
| 40 | - 'sameAs' => isset( $type['same_as'] ) ? $type['same_as'] : array(), |
|
| 40 | + 'sameAs' => isset($type['same_as']) ? $type['same_as'] : array(), |
|
| 41 | 41 | 'slug' => $term->slug, |
| 42 | - 'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ), |
|
| 42 | + 'templates' => (isset($type['templates']) ? $type['templates'] : array()), |
|
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | 45 | return $carry; |
| 46 | - }, array() ); |
|
| 46 | + }, array()); |
|
| 47 | 47 | |
| 48 | 48 | // Hook to the Block Editor script. |
| 49 | - wp_localize_script( 'wl-block-editor', '_wlEntityTypes', $entity_types ); |
|
| 49 | + wp_localize_script('wl-block-editor', '_wlEntityTypes', $entity_types); |
|
| 50 | 50 | |
| 51 | 51 | // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
| 52 | - wp_localize_script( 'wl-classic-editor', '_wlEntityTypes', $entity_types ); |
|
| 52 | + wp_localize_script('wl-classic-editor', '_wlEntityTypes', $entity_types); |
|
| 53 | 53 | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Allow Classic and Block Editor scripts to register first. |
| 57 | -add_action( 'admin_print_scripts-post.php', 'wl_print_entity_type_inline_js', 11 ); |
|
| 58 | -add_action( 'admin_print_scripts-post-new.php', 'wl_print_entity_type_inline_js', 11 ); |
|
| 57 | +add_action('admin_print_scripts-post.php', 'wl_print_entity_type_inline_js', 11); |
|
| 58 | +add_action('admin_print_scripts-post-new.php', 'wl_print_entity_type_inline_js', 11); |
|
@@ -11,30 +11,30 @@ |
||
| 11 | 11 | |
| 12 | 12 | abstract class Abstract_Autocomplete_Service implements Autocomplete_Service { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Filter out results that are in the excludes list. |
|
| 16 | - * |
|
| 17 | - * @param array $results { |
|
| 18 | - * An array of results. |
|
| 19 | - * |
|
| 20 | - * @type array The result's data. |
|
| 21 | - * } |
|
| 22 | - * |
|
| 23 | - * @param array $excludes An array of URLs. |
|
| 24 | - * |
|
| 25 | - * @return array The filtered array of results. |
|
| 26 | - */ |
|
| 27 | - protected function filter( $results, $excludes ) { |
|
| 14 | + /** |
|
| 15 | + * Filter out results that are in the excludes list. |
|
| 16 | + * |
|
| 17 | + * @param array $results { |
|
| 18 | + * An array of results. |
|
| 19 | + * |
|
| 20 | + * @type array The result's data. |
|
| 21 | + * } |
|
| 22 | + * |
|
| 23 | + * @param array $excludes An array of URLs. |
|
| 24 | + * |
|
| 25 | + * @return array The filtered array of results. |
|
| 26 | + */ |
|
| 27 | + protected function filter( $results, $excludes ) { |
|
| 28 | 28 | |
| 29 | - $excludes_array = (array) $excludes; |
|
| 29 | + $excludes_array = (array) $excludes; |
|
| 30 | 30 | |
| 31 | - return array_filter( $results, function ( $item ) use ( $excludes_array ) { |
|
| 31 | + return array_filter( $results, function ( $item ) use ( $excludes_array ) { |
|
| 32 | 32 | |
| 33 | - return 0 === count( array_intersect( |
|
| 34 | - array_merge( (array) $item['id'], $item['sameAss'] ), |
|
| 35 | - $excludes_array |
|
| 36 | - ) ); |
|
| 37 | - } ); |
|
| 38 | - } |
|
| 33 | + return 0 === count( array_intersect( |
|
| 34 | + array_merge( (array) $item['id'], $item['sameAss'] ), |
|
| 35 | + $excludes_array |
|
| 36 | + ) ); |
|
| 37 | + } ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | } |
@@ -24,16 +24,16 @@ |
||
| 24 | 24 | * |
| 25 | 25 | * @return array The filtered array of results. |
| 26 | 26 | */ |
| 27 | - protected function filter( $results, $excludes ) { |
|
| 27 | + protected function filter($results, $excludes) { |
|
| 28 | 28 | |
| 29 | 29 | $excludes_array = (array) $excludes; |
| 30 | 30 | |
| 31 | - return array_filter( $results, function ( $item ) use ( $excludes_array ) { |
|
| 31 | + return array_filter($results, function($item) use ($excludes_array) { |
|
| 32 | 32 | |
| 33 | - return 0 === count( array_intersect( |
|
| 34 | - array_merge( (array) $item['id'], $item['sameAss'] ), |
|
| 33 | + return 0 === count(array_intersect( |
|
| 34 | + array_merge((array) $item['id'], $item['sameAss']), |
|
| 35 | 35 | $excludes_array |
| 36 | - ) ); |
|
| 36 | + )); |
|
| 37 | 37 | } ); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -11,58 +11,58 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Entity_Helper { |
| 13 | 13 | |
| 14 | - private $entity_uri_service; |
|
| 14 | + private $entity_uri_service; |
|
| 15 | 15 | |
| 16 | - private $entity_service; |
|
| 16 | + private $entity_service; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Entity_Helper constructor. |
|
| 20 | - * |
|
| 21 | - * @param \Wordlift_Entity_Uri_Service $entity_uri_service |
|
| 22 | - * @param \Wordlift_Entity_Service $entity_service |
|
| 23 | - */ |
|
| 24 | - public function __construct( $entity_uri_service, $entity_service ) { |
|
| 18 | + /** |
|
| 19 | + * Entity_Helper constructor. |
|
| 20 | + * |
|
| 21 | + * @param \Wordlift_Entity_Uri_Service $entity_uri_service |
|
| 22 | + * @param \Wordlift_Entity_Service $entity_service |
|
| 23 | + */ |
|
| 24 | + public function __construct( $entity_uri_service, $entity_service ) { |
|
| 25 | 25 | |
| 26 | - $this->entity_uri_service = $entity_uri_service; |
|
| 27 | - $this->entity_service = $entity_service; |
|
| 26 | + $this->entity_uri_service = $entity_uri_service; |
|
| 27 | + $this->entity_service = $entity_service; |
|
| 28 | 28 | |
| 29 | - } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Maps the provided URIs to local URIs. |
|
| 33 | - * |
|
| 34 | - * The input array is filtered out of the local URIs. Then each URI is checked with itemid and sameAs in the local |
|
| 35 | - * database. If found a mapping is added from the external URI to the local URI. |
|
| 36 | - * |
|
| 37 | - * An array of mappings is returned, where the key is the external URI and the value is the local URI. |
|
| 38 | - * |
|
| 39 | - * @param array $uris An array of URIs. |
|
| 40 | - * |
|
| 41 | - * @return array The mappings array. |
|
| 42 | - */ |
|
| 43 | - public function map_many_to_local( $uris ) { |
|
| 31 | + /** |
|
| 32 | + * Maps the provided URIs to local URIs. |
|
| 33 | + * |
|
| 34 | + * The input array is filtered out of the local URIs. Then each URI is checked with itemid and sameAs in the local |
|
| 35 | + * database. If found a mapping is added from the external URI to the local URI. |
|
| 36 | + * |
|
| 37 | + * An array of mappings is returned, where the key is the external URI and the value is the local URI. |
|
| 38 | + * |
|
| 39 | + * @param array $uris An array of URIs. |
|
| 40 | + * |
|
| 41 | + * @return array The mappings array. |
|
| 42 | + */ |
|
| 43 | + public function map_many_to_local( $uris ) { |
|
| 44 | 44 | |
| 45 | - // Filter only the external URIs. |
|
| 46 | - $entity_uri_service = $this->entity_uri_service; |
|
| 47 | - $external_uris = array_filter( $uris, function ( $item ) use ( $entity_uri_service ) { |
|
| 48 | - return ! $entity_uri_service->is_internal( $item ); |
|
| 49 | - } ); |
|
| 45 | + // Filter only the external URIs. |
|
| 46 | + $entity_uri_service = $this->entity_uri_service; |
|
| 47 | + $external_uris = array_filter( $uris, function ( $item ) use ( $entity_uri_service ) { |
|
| 48 | + return ! $entity_uri_service->is_internal( $item ); |
|
| 49 | + } ); |
|
| 50 | 50 | |
| 51 | - // Preload the URIs. |
|
| 52 | - $entity_uri_service->preload_uris( $external_uris ); |
|
| 51 | + // Preload the URIs. |
|
| 52 | + $entity_uri_service->preload_uris( $external_uris ); |
|
| 53 | 53 | |
| 54 | - $mappings = array(); |
|
| 55 | - foreach ( $external_uris as $external_uri ) { |
|
| 56 | - $entity = $entity_uri_service->get_entity( $external_uri ); |
|
| 57 | - if ( null !== $entity ) { |
|
| 54 | + $mappings = array(); |
|
| 55 | + foreach ( $external_uris as $external_uri ) { |
|
| 56 | + $entity = $entity_uri_service->get_entity( $external_uri ); |
|
| 57 | + if ( null !== $entity ) { |
|
| 58 | 58 | |
| 59 | - // Get the internal URI. |
|
| 60 | - $internal_uri = $this->entity_service->get_uri( $entity->ID ); |
|
| 61 | - $mappings[ $external_uri ] = $internal_uri; |
|
| 62 | - } |
|
| 63 | - } |
|
| 59 | + // Get the internal URI. |
|
| 60 | + $internal_uri = $this->entity_service->get_uri( $entity->ID ); |
|
| 61 | + $mappings[ $external_uri ] = $internal_uri; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return $mappings; |
|
| 66 | - } |
|
| 65 | + return $mappings; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param \Wordlift_Entity_Uri_Service $entity_uri_service |
| 22 | 22 | * @param \Wordlift_Entity_Service $entity_service |
| 23 | 23 | */ |
| 24 | - public function __construct( $entity_uri_service, $entity_service ) { |
|
| 24 | + public function __construct($entity_uri_service, $entity_service) { |
|
| 25 | 25 | |
| 26 | 26 | $this->entity_uri_service = $entity_uri_service; |
| 27 | 27 | $this->entity_service = $entity_service; |
@@ -40,25 +40,25 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return array The mappings array. |
| 42 | 42 | */ |
| 43 | - public function map_many_to_local( $uris ) { |
|
| 43 | + public function map_many_to_local($uris) { |
|
| 44 | 44 | |
| 45 | 45 | // Filter only the external URIs. |
| 46 | 46 | $entity_uri_service = $this->entity_uri_service; |
| 47 | - $external_uris = array_filter( $uris, function ( $item ) use ( $entity_uri_service ) { |
|
| 48 | - return ! $entity_uri_service->is_internal( $item ); |
|
| 47 | + $external_uris = array_filter($uris, function($item) use ($entity_uri_service) { |
|
| 48 | + return ! $entity_uri_service->is_internal($item); |
|
| 49 | 49 | } ); |
| 50 | 50 | |
| 51 | 51 | // Preload the URIs. |
| 52 | - $entity_uri_service->preload_uris( $external_uris ); |
|
| 52 | + $entity_uri_service->preload_uris($external_uris); |
|
| 53 | 53 | |
| 54 | 54 | $mappings = array(); |
| 55 | - foreach ( $external_uris as $external_uri ) { |
|
| 56 | - $entity = $entity_uri_service->get_entity( $external_uri ); |
|
| 57 | - if ( null !== $entity ) { |
|
| 55 | + foreach ($external_uris as $external_uri) { |
|
| 56 | + $entity = $entity_uri_service->get_entity($external_uri); |
|
| 57 | + if (null !== $entity) { |
|
| 58 | 58 | |
| 59 | 59 | // Get the internal URI. |
| 60 | - $internal_uri = $this->entity_service->get_uri( $entity->ID ); |
|
| 61 | - $mappings[ $external_uri ] = $internal_uri; |
|
| 60 | + $internal_uri = $this->entity_service->get_uri($entity->ID); |
|
| 61 | + $mappings[$external_uri] = $internal_uri; |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
@@ -43,8 +43,7 @@ |
||
| 43 | 43 | array_push($jsonld['@type'], self::FAQ_JSONLD_TYPE); |
| 44 | 44 | return $jsonld; |
| 45 | 45 | } |
| 46 | - } |
|
| 47 | - else { |
|
| 46 | + } else { |
|
| 48 | 47 | $jsonld['@type'] = array(self::FAQ_JSONLD_TYPE); |
| 49 | 48 | } |
| 50 | 49 | return $jsonld; |
@@ -17,80 +17,80 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Faq_To_Jsonld_Converter { |
| 19 | 19 | |
| 20 | - const FAQ_JSONLD_TYPE = 'FAQPage'; |
|
| 20 | + const FAQ_JSONLD_TYPE = 'FAQPage'; |
|
| 21 | 21 | |
| 22 | - public function __construct() { |
|
| 23 | - add_filter( 'wl_post_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 ); |
|
| 24 | - add_filter( 'wl_entity_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 ); |
|
| 25 | - } |
|
| 22 | + public function __construct() { |
|
| 23 | + add_filter( 'wl_post_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 ); |
|
| 24 | + add_filter( 'wl_entity_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 ); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Set the FAQ type to the json ld array |
|
| 29 | - * |
|
| 30 | - * @param $jsonld array The jsonld array. |
|
| 31 | - * |
|
| 32 | - * @return array Returns the json ld array with the type set. |
|
| 33 | - */ |
|
| 34 | - public function set_faq_type( $jsonld ) { |
|
| 35 | - if ( array_key_exists('@type', $jsonld)) { |
|
| 36 | - if ( is_string($jsonld['@type'])) { |
|
| 37 | - // If a plain string is present, create an array with previous items. |
|
| 38 | - $jsonld['@type'] = array($jsonld['@type'], self::FAQ_JSONLD_TYPE); |
|
| 39 | - return $jsonld; |
|
| 40 | - } |
|
| 41 | - // check if it is a array, then append the type. |
|
| 42 | - if ( is_array($jsonld['@type']) && ! in_array(self::FAQ_JSONLD_TYPE, $jsonld['@type'])) { |
|
| 43 | - array_push($jsonld['@type'], self::FAQ_JSONLD_TYPE); |
|
| 44 | - return $jsonld; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - else { |
|
| 48 | - $jsonld['@type'] = array(self::FAQ_JSONLD_TYPE); |
|
| 49 | - } |
|
| 50 | - return $jsonld; |
|
| 51 | - } |
|
| 52 | - /** |
|
| 53 | - * @param $post_id int The id of the post. |
|
| 54 | - * |
|
| 55 | - * @return array Get the converted jsonld data |
|
| 56 | - */ |
|
| 57 | - public function get_jsonld_for_faq( $jsonld, $post_id ) { |
|
| 27 | + /** |
|
| 28 | + * Set the FAQ type to the json ld array |
|
| 29 | + * |
|
| 30 | + * @param $jsonld array The jsonld array. |
|
| 31 | + * |
|
| 32 | + * @return array Returns the json ld array with the type set. |
|
| 33 | + */ |
|
| 34 | + public function set_faq_type( $jsonld ) { |
|
| 35 | + if ( array_key_exists('@type', $jsonld)) { |
|
| 36 | + if ( is_string($jsonld['@type'])) { |
|
| 37 | + // If a plain string is present, create an array with previous items. |
|
| 38 | + $jsonld['@type'] = array($jsonld['@type'], self::FAQ_JSONLD_TYPE); |
|
| 39 | + return $jsonld; |
|
| 40 | + } |
|
| 41 | + // check if it is a array, then append the type. |
|
| 42 | + if ( is_array($jsonld['@type']) && ! in_array(self::FAQ_JSONLD_TYPE, $jsonld['@type'])) { |
|
| 43 | + array_push($jsonld['@type'], self::FAQ_JSONLD_TYPE); |
|
| 44 | + return $jsonld; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + else { |
|
| 48 | + $jsonld['@type'] = array(self::FAQ_JSONLD_TYPE); |
|
| 49 | + } |
|
| 50 | + return $jsonld; |
|
| 51 | + } |
|
| 52 | + /** |
|
| 53 | + * @param $post_id int The id of the post. |
|
| 54 | + * |
|
| 55 | + * @return array Get the converted jsonld data |
|
| 56 | + */ |
|
| 57 | + public function get_jsonld_for_faq( $jsonld, $post_id ) { |
|
| 58 | 58 | |
| 59 | - $faq_items = get_post_meta( $post_id, Faq_Rest_Controller::FAQ_META_KEY); |
|
| 60 | - /** |
|
| 61 | - * Apply the FAQ mapping only if the FAQ items are present. |
|
| 62 | - */ |
|
| 63 | - if ( count($faq_items) > 0 ) { |
|
| 64 | - $faq_data = $this->get_faq_data( $faq_items ); |
|
| 65 | - // Merge the FAQ data with jsonld. |
|
| 66 | - $jsonld = array_merge( $jsonld, $faq_data); |
|
| 67 | - // check if the @type is set on json ld |
|
| 68 | - $jsonld = $this->set_faq_type($jsonld); |
|
| 69 | - } |
|
| 70 | - return $jsonld; |
|
| 71 | - } |
|
| 59 | + $faq_items = get_post_meta( $post_id, Faq_Rest_Controller::FAQ_META_KEY); |
|
| 60 | + /** |
|
| 61 | + * Apply the FAQ mapping only if the FAQ items are present. |
|
| 62 | + */ |
|
| 63 | + if ( count($faq_items) > 0 ) { |
|
| 64 | + $faq_data = $this->get_faq_data( $faq_items ); |
|
| 65 | + // Merge the FAQ data with jsonld. |
|
| 66 | + $jsonld = array_merge( $jsonld, $faq_data); |
|
| 67 | + // check if the @type is set on json ld |
|
| 68 | + $jsonld = $this->set_faq_type($jsonld); |
|
| 69 | + } |
|
| 70 | + return $jsonld; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param $faq_items array List of FAQ items extracted from the meta. |
|
| 75 | - * |
|
| 76 | - * @return array Associtative array of type, mainEntity. |
|
| 77 | - */ |
|
| 78 | - private function get_faq_data( $faq_items ) { |
|
| 79 | - $jsonld_data['mainEntity'] = array(); |
|
| 80 | - foreach ( $faq_items as $faq_item ) { |
|
| 81 | - if ( 0 === strlen($faq_item['question']) || 0 === strlen($faq_item['answer']) ) { |
|
| 82 | - // Bail out if question or answer is not present |
|
| 83 | - continue; |
|
| 84 | - } |
|
| 85 | - $faq_data = array(); |
|
| 86 | - $faq_data['@type'] = 'Question'; |
|
| 87 | - $faq_data['name'] = $faq_item['question']; |
|
| 88 | - $faq_data['acceptedAnswer'] = array(); |
|
| 89 | - $faq_data['acceptedAnswer']['@type'] = 'Answer'; |
|
| 90 | - $faq_data['acceptedAnswer']['text'] = $faq_item['answer']; |
|
| 91 | - array_push( $jsonld_data['mainEntity'], $faq_data ); |
|
| 92 | - } |
|
| 73 | + /** |
|
| 74 | + * @param $faq_items array List of FAQ items extracted from the meta. |
|
| 75 | + * |
|
| 76 | + * @return array Associtative array of type, mainEntity. |
|
| 77 | + */ |
|
| 78 | + private function get_faq_data( $faq_items ) { |
|
| 79 | + $jsonld_data['mainEntity'] = array(); |
|
| 80 | + foreach ( $faq_items as $faq_item ) { |
|
| 81 | + if ( 0 === strlen($faq_item['question']) || 0 === strlen($faq_item['answer']) ) { |
|
| 82 | + // Bail out if question or answer is not present |
|
| 83 | + continue; |
|
| 84 | + } |
|
| 85 | + $faq_data = array(); |
|
| 86 | + $faq_data['@type'] = 'Question'; |
|
| 87 | + $faq_data['name'] = $faq_item['question']; |
|
| 88 | + $faq_data['acceptedAnswer'] = array(); |
|
| 89 | + $faq_data['acceptedAnswer']['@type'] = 'Answer'; |
|
| 90 | + $faq_data['acceptedAnswer']['text'] = $faq_item['answer']; |
|
| 91 | + array_push( $jsonld_data['mainEntity'], $faq_data ); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $jsonld_data; |
|
| 95 | - } |
|
| 94 | + return $jsonld_data; |
|
| 95 | + } |
|
| 96 | 96 | } |
| 97 | 97 | \ No newline at end of file |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | const FAQ_JSONLD_TYPE = 'FAQPage'; |
| 21 | 21 | |
| 22 | 22 | public function __construct() { |
| 23 | - add_filter( 'wl_post_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 ); |
|
| 24 | - add_filter( 'wl_entity_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 ); |
|
| 23 | + add_filter('wl_post_jsonld', array($this, 'get_jsonld_for_faq'), 11, 2); |
|
| 24 | + add_filter('wl_entity_jsonld', array($this, 'get_jsonld_for_faq'), 11, 2); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -31,15 +31,15 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return array Returns the json ld array with the type set. |
| 33 | 33 | */ |
| 34 | - public function set_faq_type( $jsonld ) { |
|
| 35 | - if ( array_key_exists('@type', $jsonld)) { |
|
| 36 | - if ( is_string($jsonld['@type'])) { |
|
| 34 | + public function set_faq_type($jsonld) { |
|
| 35 | + if (array_key_exists('@type', $jsonld)) { |
|
| 36 | + if (is_string($jsonld['@type'])) { |
|
| 37 | 37 | // If a plain string is present, create an array with previous items. |
| 38 | 38 | $jsonld['@type'] = array($jsonld['@type'], self::FAQ_JSONLD_TYPE); |
| 39 | 39 | return $jsonld; |
| 40 | 40 | } |
| 41 | 41 | // check if it is a array, then append the type. |
| 42 | - if ( is_array($jsonld['@type']) && ! in_array(self::FAQ_JSONLD_TYPE, $jsonld['@type'])) { |
|
| 42 | + if (is_array($jsonld['@type']) && ! in_array(self::FAQ_JSONLD_TYPE, $jsonld['@type'])) { |
|
| 43 | 43 | array_push($jsonld['@type'], self::FAQ_JSONLD_TYPE); |
| 44 | 44 | return $jsonld; |
| 45 | 45 | } |
@@ -54,16 +54,16 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return array Get the converted jsonld data |
| 56 | 56 | */ |
| 57 | - public function get_jsonld_for_faq( $jsonld, $post_id ) { |
|
| 57 | + public function get_jsonld_for_faq($jsonld, $post_id) { |
|
| 58 | 58 | |
| 59 | - $faq_items = get_post_meta( $post_id, Faq_Rest_Controller::FAQ_META_KEY); |
|
| 59 | + $faq_items = get_post_meta($post_id, Faq_Rest_Controller::FAQ_META_KEY); |
|
| 60 | 60 | /** |
| 61 | 61 | * Apply the FAQ mapping only if the FAQ items are present. |
| 62 | 62 | */ |
| 63 | - if ( count($faq_items) > 0 ) { |
|
| 64 | - $faq_data = $this->get_faq_data( $faq_items ); |
|
| 63 | + if (count($faq_items) > 0) { |
|
| 64 | + $faq_data = $this->get_faq_data($faq_items); |
|
| 65 | 65 | // Merge the FAQ data with jsonld. |
| 66 | - $jsonld = array_merge( $jsonld, $faq_data); |
|
| 66 | + $jsonld = array_merge($jsonld, $faq_data); |
|
| 67 | 67 | // check if the @type is set on json ld |
| 68 | 68 | $jsonld = $this->set_faq_type($jsonld); |
| 69 | 69 | } |
@@ -75,10 +75,10 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return array Associtative array of type, mainEntity. |
| 77 | 77 | */ |
| 78 | - private function get_faq_data( $faq_items ) { |
|
| 78 | + private function get_faq_data($faq_items) { |
|
| 79 | 79 | $jsonld_data['mainEntity'] = array(); |
| 80 | - foreach ( $faq_items as $faq_item ) { |
|
| 81 | - if ( 0 === strlen($faq_item['question']) || 0 === strlen($faq_item['answer']) ) { |
|
| 80 | + foreach ($faq_items as $faq_item) { |
|
| 81 | + if (0 === strlen($faq_item['question']) || 0 === strlen($faq_item['answer'])) { |
|
| 82 | 82 | // Bail out if question or answer is not present |
| 83 | 83 | continue; |
| 84 | 84 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $faq_data['acceptedAnswer'] = array(); |
| 89 | 89 | $faq_data['acceptedAnswer']['@type'] = 'Answer'; |
| 90 | 90 | $faq_data['acceptedAnswer']['text'] = $faq_item['answer']; |
| 91 | - array_push( $jsonld_data['mainEntity'], $faq_data ); |
|
| 91 | + array_push($jsonld_data['mainEntity'], $faq_data); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | return $jsonld_data; |
@@ -9,32 +9,32 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | function wordlift_geo_widget_shortcode( $atts, $content = null ) { |
| 11 | 11 | |
| 12 | - // Extract attributes and set default values. |
|
| 13 | - $params = shortcode_atts( array( |
|
| 14 | - 'width' => '100%', |
|
| 15 | - 'height' => '300px', |
|
| 16 | - 'latitude' => 0.0, |
|
| 17 | - 'longitude' => 0.0, |
|
| 18 | - 'zoom' => 5, |
|
| 19 | - |
|
| 20 | - ), $atts ); |
|
| 21 | - |
|
| 22 | - // Add leaflet css and library. |
|
| 23 | - wp_enqueue_style( 'wl-leaflet', 'https://unpkg.com/[email protected]/dist/leaflet.css', array(), '1.6.0' ); |
|
| 24 | - wp_enqueue_script( 'wl-leaflet', 'https://unpkg.com/[email protected]/dist/leaflet.js', array(), '1.6.0', true ); |
|
| 25 | - |
|
| 26 | - ob_start(); // Collect the buffer. |
|
| 27 | - wordlift_geo_widget_html( |
|
| 28 | - $params['width'], |
|
| 29 | - $params['height'], |
|
| 30 | - $params['latitude'], |
|
| 31 | - $params['longitude'], |
|
| 32 | - $params['zoom'], |
|
| 33 | - $content |
|
| 34 | - ); |
|
| 35 | - |
|
| 36 | - // Return the accumulated buffer. |
|
| 37 | - return ob_get_clean(); |
|
| 12 | + // Extract attributes and set default values. |
|
| 13 | + $params = shortcode_atts( array( |
|
| 14 | + 'width' => '100%', |
|
| 15 | + 'height' => '300px', |
|
| 16 | + 'latitude' => 0.0, |
|
| 17 | + 'longitude' => 0.0, |
|
| 18 | + 'zoom' => 5, |
|
| 19 | + |
|
| 20 | + ), $atts ); |
|
| 21 | + |
|
| 22 | + // Add leaflet css and library. |
|
| 23 | + wp_enqueue_style( 'wl-leaflet', 'https://unpkg.com/[email protected]/dist/leaflet.css', array(), '1.6.0' ); |
|
| 24 | + wp_enqueue_script( 'wl-leaflet', 'https://unpkg.com/[email protected]/dist/leaflet.js', array(), '1.6.0', true ); |
|
| 25 | + |
|
| 26 | + ob_start(); // Collect the buffer. |
|
| 27 | + wordlift_geo_widget_html( |
|
| 28 | + $params['width'], |
|
| 29 | + $params['height'], |
|
| 30 | + $params['latitude'], |
|
| 31 | + $params['longitude'], |
|
| 32 | + $params['zoom'], |
|
| 33 | + $content |
|
| 34 | + ); |
|
| 35 | + |
|
| 36 | + // Return the accumulated buffer. |
|
| 37 | + return ob_get_clean(); |
|
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
@@ -42,24 +42,24 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | function wl_geo_widget_layer_shortcode( $atts ) { |
| 44 | 44 | |
| 45 | - // Extract attributes and set default values. |
|
| 46 | - $params = shortcode_atts( array( |
|
| 47 | - 'name' => '', |
|
| 48 | - 'label' => '', |
|
| 49 | - ), $atts ); |
|
| 45 | + // Extract attributes and set default values. |
|
| 46 | + $params = shortcode_atts( array( |
|
| 47 | + 'name' => '', |
|
| 48 | + 'label' => '', |
|
| 49 | + ), $atts ); |
|
| 50 | 50 | |
| 51 | - // Return if a SPARQL Query name hasn't been provided. |
|
| 52 | - if ( empty( $params['name'] ) ) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 51 | + // Return if a SPARQL Query name hasn't been provided. |
|
| 52 | + if ( empty( $params['name'] ) ) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - // Set the layer label. |
|
| 57 | - $label_j = json_encode( empty( $params['label'] ) ? $params['name'] : $params['label'] ); |
|
| 56 | + // Set the layer label. |
|
| 57 | + $label_j = json_encode( empty( $params['label'] ) ? $params['name'] : $params['label'] ); |
|
| 58 | 58 | |
| 59 | - // Define the AJAX Url. |
|
| 60 | - $ajax_url = admin_url( 'admin-ajax.php?action=wl_sparql&format=geojson&slug=' . urlencode( $params['name'] ) ); |
|
| 59 | + // Define the AJAX Url. |
|
| 60 | + $ajax_url = admin_url( 'admin-ajax.php?action=wl_sparql&format=geojson&slug=' . urlencode( $params['name'] ) ); |
|
| 61 | 61 | |
| 62 | - echo <<<EOF |
|
| 62 | + echo <<<EOF |
|
| 63 | 63 | |
| 64 | 64 | $.ajax( '$ajax_url', { |
| 65 | 65 | success: function( data ) { |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | function wl_geo_widget_marker_shortcode( $atts ) { |
| 92 | 92 | |
| 93 | - // Extract attributes and set default values. |
|
| 94 | - $params = shortcode_atts( array( |
|
| 95 | - 'latitude' => null, |
|
| 96 | - 'longitude' => null, |
|
| 97 | - ), $atts ); |
|
| 93 | + // Extract attributes and set default values. |
|
| 94 | + $params = shortcode_atts( array( |
|
| 95 | + 'latitude' => null, |
|
| 96 | + 'longitude' => null, |
|
| 97 | + ), $atts ); |
|
| 98 | 98 | |
| 99 | - // Return if either latitude or longitude haven't been provided. |
|
| 100 | - if ( empty( $params['latitude'] ) || empty( $params['longitude'] ) ) { |
|
| 101 | - return; |
|
| 102 | - } |
|
| 99 | + // Return if either latitude or longitude haven't been provided. |
|
| 100 | + if ( empty( $params['latitude'] ) || empty( $params['longitude'] ) ) { |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $latitude_j = json_encode( $params['latitude'] ); |
|
| 105 | - $longitude_j = json_encode( $params['longitude'] ); |
|
| 104 | + $latitude_j = json_encode( $params['latitude'] ); |
|
| 105 | + $longitude_j = json_encode( $params['longitude'] ); |
|
| 106 | 106 | |
| 107 | - echo <<<EOF |
|
| 107 | + echo <<<EOF |
|
| 108 | 108 | |
| 109 | 109 | L.marker([$latitude_j, $longitude_j]).addTo(map); |
| 110 | 110 | EOF; |
@@ -116,10 +116,10 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | function wordlift_geo_widget_html( $width, $height, $latitude, $longitude, $zoom, $content ) { |
| 118 | 118 | |
| 119 | - // Create a unique Id for this widget. |
|
| 120 | - $div_id = uniqid( 'wl-geo-' ); |
|
| 119 | + // Create a unique Id for this widget. |
|
| 120 | + $div_id = uniqid( 'wl-geo-' ); |
|
| 121 | 121 | |
| 122 | - echo <<<EOF |
|
| 122 | + echo <<<EOF |
|
| 123 | 123 | <div id="$div_id" style="width: $width; height: $height;"></div> |
| 124 | 124 | |
| 125 | 125 | <script type="text/javascript"> |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | EOF; |
| 146 | 146 | |
| 147 | - // Run inner shortcodes. |
|
| 148 | - do_shortcode( $content ); |
|
| 147 | + // Run inner shortcodes. |
|
| 148 | + do_shortcode( $content ); |
|
| 149 | 149 | |
| 150 | - echo <<<EOF |
|
| 150 | + echo <<<EOF |
|
| 151 | 151 | |
| 152 | 152 | } ); |
| 153 | 153 | </script> |
@@ -7,21 +7,21 @@ discard block |
||
| 7 | 7 | * @subpackage Wordlift/modules/geo_widget |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -function wordlift_geo_widget_shortcode( $atts, $content = null ) { |
|
| 10 | +function wordlift_geo_widget_shortcode($atts, $content = null) { |
|
| 11 | 11 | |
| 12 | 12 | // Extract attributes and set default values. |
| 13 | - $params = shortcode_atts( array( |
|
| 13 | + $params = shortcode_atts(array( |
|
| 14 | 14 | 'width' => '100%', |
| 15 | 15 | 'height' => '300px', |
| 16 | 16 | 'latitude' => 0.0, |
| 17 | 17 | 'longitude' => 0.0, |
| 18 | 18 | 'zoom' => 5, |
| 19 | 19 | |
| 20 | - ), $atts ); |
|
| 20 | + ), $atts); |
|
| 21 | 21 | |
| 22 | 22 | // Add leaflet css and library. |
| 23 | - wp_enqueue_style( 'wl-leaflet', 'https://unpkg.com/[email protected]/dist/leaflet.css', array(), '1.6.0' ); |
|
| 24 | - wp_enqueue_script( 'wl-leaflet', 'https://unpkg.com/[email protected]/dist/leaflet.js', array(), '1.6.0', true ); |
|
| 23 | + wp_enqueue_style('wl-leaflet', 'https://unpkg.com/[email protected]/dist/leaflet.css', array(), '1.6.0'); |
|
| 24 | + wp_enqueue_script('wl-leaflet', 'https://unpkg.com/[email protected]/dist/leaflet.js', array(), '1.6.0', true); |
|
| 25 | 25 | |
| 26 | 26 | ob_start(); // Collect the buffer. |
| 27 | 27 | wordlift_geo_widget_html( |
@@ -38,26 +38,26 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | -add_shortcode( 'wl_geo', 'wordlift_geo_widget_shortcode' ); |
|
| 41 | +add_shortcode('wl_geo', 'wordlift_geo_widget_shortcode'); |
|
| 42 | 42 | |
| 43 | -function wl_geo_widget_layer_shortcode( $atts ) { |
|
| 43 | +function wl_geo_widget_layer_shortcode($atts) { |
|
| 44 | 44 | |
| 45 | 45 | // Extract attributes and set default values. |
| 46 | - $params = shortcode_atts( array( |
|
| 46 | + $params = shortcode_atts(array( |
|
| 47 | 47 | 'name' => '', |
| 48 | 48 | 'label' => '', |
| 49 | - ), $atts ); |
|
| 49 | + ), $atts); |
|
| 50 | 50 | |
| 51 | 51 | // Return if a SPARQL Query name hasn't been provided. |
| 52 | - if ( empty( $params['name'] ) ) { |
|
| 52 | + if (empty($params['name'])) { |
|
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Set the layer label. |
| 57 | - $label_j = json_encode( empty( $params['label'] ) ? $params['name'] : $params['label'] ); |
|
| 57 | + $label_j = json_encode(empty($params['label']) ? $params['name'] : $params['label']); |
|
| 58 | 58 | |
| 59 | 59 | // Define the AJAX Url. |
| 60 | - $ajax_url = admin_url( 'admin-ajax.php?action=wl_sparql&format=geojson&slug=' . urlencode( $params['name'] ) ); |
|
| 60 | + $ajax_url = admin_url('admin-ajax.php?action=wl_sparql&format=geojson&slug='.urlencode($params['name'])); |
|
| 61 | 61 | |
| 62 | 62 | echo <<<EOF |
| 63 | 63 | |
@@ -85,24 +85,24 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | -add_shortcode( 'wl_geo_layer', 'wl_geo_widget_layer_shortcode' ); |
|
| 88 | +add_shortcode('wl_geo_layer', 'wl_geo_widget_layer_shortcode'); |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | -function wl_geo_widget_marker_shortcode( $atts ) { |
|
| 91 | +function wl_geo_widget_marker_shortcode($atts) { |
|
| 92 | 92 | |
| 93 | 93 | // Extract attributes and set default values. |
| 94 | - $params = shortcode_atts( array( |
|
| 94 | + $params = shortcode_atts(array( |
|
| 95 | 95 | 'latitude' => null, |
| 96 | 96 | 'longitude' => null, |
| 97 | - ), $atts ); |
|
| 97 | + ), $atts); |
|
| 98 | 98 | |
| 99 | 99 | // Return if either latitude or longitude haven't been provided. |
| 100 | - if ( empty( $params['latitude'] ) || empty( $params['longitude'] ) ) { |
|
| 100 | + if (empty($params['latitude']) || empty($params['longitude'])) { |
|
| 101 | 101 | return; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $latitude_j = json_encode( $params['latitude'] ); |
|
| 105 | - $longitude_j = json_encode( $params['longitude'] ); |
|
| 104 | + $latitude_j = json_encode($params['latitude']); |
|
| 105 | + $longitude_j = json_encode($params['longitude']); |
|
| 106 | 106 | |
| 107 | 107 | echo <<<EOF |
| 108 | 108 | |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | -add_shortcode( 'wl_geo_marker', 'wl_geo_widget_marker_shortcode' ); |
|
| 114 | +add_shortcode('wl_geo_marker', 'wl_geo_widget_marker_shortcode'); |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | -function wordlift_geo_widget_html( $width, $height, $latitude, $longitude, $zoom, $content ) { |
|
| 117 | +function wordlift_geo_widget_html($width, $height, $latitude, $longitude, $zoom, $content) { |
|
| 118 | 118 | |
| 119 | 119 | // Create a unique Id for this widget. |
| 120 | - $div_id = uniqid( 'wl-geo-' ); |
|
| 120 | + $div_id = uniqid('wl-geo-'); |
|
| 121 | 121 | |
| 122 | 122 | echo <<<EOF |
| 123 | 123 | <div id="$div_id" style="width: $width; height: $height;"></div> |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | EOF; |
| 146 | 146 | |
| 147 | 147 | // Run inner shortcodes. |
| 148 | - do_shortcode( $content ); |
|
| 148 | + do_shortcode($content); |
|
| 149 | 149 | |
| 150 | 150 | echo <<<EOF |
| 151 | 151 | |
@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | <h1><?php esc_html_e( 'Tasks', 'wordlift-framework' ); ?></h1> |
| 14 | 14 | |
| 15 | 15 | <?php |
| 16 | - foreach ( $this->task_ajax_adapters_registry->get_task_ajax_adapters() as $task_ajax_adapter ) { |
|
| 17 | - $task = $task_ajax_adapter->get_task(); |
|
| 18 | - ?> |
|
| 16 | + foreach ( $this->task_ajax_adapters_registry->get_task_ajax_adapters() as $task_ajax_adapter ) { |
|
| 17 | + $task = $task_ajax_adapter->get_task(); |
|
| 18 | + ?> |
|
| 19 | 19 | <div class="wl-task"> |
| 20 | 20 | <h2><?php esc_html_e( $task->get_label() ); ?></h2> |
| 21 | 21 | <div class="wl-task__progress" style="border: 1px solid #23282D; height: 20px; margin: 8px 0;"> |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | </div> |
| 34 | 34 | <?php |
| 35 | - } |
|
| 36 | - ?> |
|
| 35 | + } |
|
| 36 | + ?> |
|
| 37 | 37 | |
| 38 | 38 | </div> |
@@ -10,14 +10,14 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | ?> |
| 12 | 12 | <div class="wrap"> |
| 13 | - <h1><?php esc_html_e( 'Tasks', 'wordlift-framework' ); ?></h1> |
|
| 13 | + <h1><?php esc_html_e('Tasks', 'wordlift-framework'); ?></h1> |
|
| 14 | 14 | |
| 15 | 15 | <?php |
| 16 | - foreach ( $this->task_ajax_adapters_registry->get_task_ajax_adapters() as $task_ajax_adapter ) { |
|
| 16 | + foreach ($this->task_ajax_adapters_registry->get_task_ajax_adapters() as $task_ajax_adapter) { |
|
| 17 | 17 | $task = $task_ajax_adapter->get_task(); |
| 18 | 18 | ?> |
| 19 | 19 | <div class="wl-task"> |
| 20 | - <h2><?php esc_html_e( $task->get_label() ); ?></h2> |
|
| 20 | + <h2><?php esc_html_e($task->get_label()); ?></h2> |
|
| 21 | 21 | <div class="wl-task__progress" style="border: 1px solid #23282D; height: 20px; margin: 8px 0;"> |
| 22 | 22 | <div class="wl-task__progress__bar" |
| 23 | 23 | style="width:0;background: #0073AA; text-align: center; height: 100%; color: #fff;"></div> |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | <button |
| 27 | 27 | type="button" |
| 28 | 28 | class="button button-large button-primary" |
| 29 | - data-action="<?php echo esc_attr( $task->get_id() ); ?>" |
|
| 30 | - data-nonce="<?php echo esc_attr( wp_create_nonce( $task->get_id() ) ); ?>" |
|
| 31 | - ><?php esc_html_e( 'Start', 'wordlift-framework' ); ?></button> |
|
| 29 | + data-action="<?php echo esc_attr($task->get_id()); ?>" |
|
| 30 | + data-nonce="<?php echo esc_attr(wp_create_nonce($task->get_id())); ?>" |
|
| 31 | + ><?php esc_html_e('Start', 'wordlift-framework'); ?></button> |
|
| 32 | 32 | |
| 33 | 33 | </div> |
| 34 | 34 | <?php |
@@ -18,66 +18,66 @@ |
||
| 18 | 18 | |
| 19 | 19 | class Tasks_Page extends Submenu_Page_Base { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The ID of this admin page. |
|
| 23 | - * |
|
| 24 | - * @since 1.0.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var string $menu_slug The ID of this page. |
|
| 27 | - */ |
|
| 28 | - private $menu_slug = 'wl_tasks_page'; |
|
| 21 | + /** |
|
| 22 | + * The ID of this admin page. |
|
| 23 | + * |
|
| 24 | + * @since 1.0.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var string $menu_slug The ID of this page. |
|
| 27 | + */ |
|
| 28 | + private $menu_slug = 'wl_tasks_page'; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Used when enqueueing styles or scripts as the version string. |
|
| 32 | - * |
|
| 33 | - * @since 1.0.0 |
|
| 34 | - * @access private |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - private $asset_version = '1.0.0'; |
|
| 30 | + /** |
|
| 31 | + * Used when enqueueing styles or scripts as the version string. |
|
| 32 | + * |
|
| 33 | + * @since 1.0.0 |
|
| 34 | + * @access private |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + private $asset_version = '1.0.0'; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var Task_Ajax_Adapters_Registry |
|
| 41 | - */ |
|
| 42 | - private $task_ajax_adapters_registry; |
|
| 39 | + /** |
|
| 40 | + * @var Task_Ajax_Adapters_Registry |
|
| 41 | + */ |
|
| 42 | + private $task_ajax_adapters_registry; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Define the {@link Wordlift_Admin_Page} constructor. |
|
| 46 | - * |
|
| 47 | - * @param Task_Ajax_Adapters_Registry $task_ajax_adapters_registry |
|
| 48 | - * |
|
| 49 | - * @since 1.0.0 |
|
| 50 | - */ |
|
| 51 | - public function __construct( $task_ajax_adapters_registry ) { |
|
| 52 | - parent::__construct( $this->menu_slug, __( 'Tasks', 'wordlift-framework' ), 'manage_options', 'wl_admin_menu', __( 'Tasks', 'wordlift-framework' ) ); |
|
| 44 | + /** |
|
| 45 | + * Define the {@link Wordlift_Admin_Page} constructor. |
|
| 46 | + * |
|
| 47 | + * @param Task_Ajax_Adapters_Registry $task_ajax_adapters_registry |
|
| 48 | + * |
|
| 49 | + * @since 1.0.0 |
|
| 50 | + */ |
|
| 51 | + public function __construct( $task_ajax_adapters_registry ) { |
|
| 52 | + parent::__construct( $this->menu_slug, __( 'Tasks', 'wordlift-framework' ), 'manage_options', 'wl_admin_menu', __( 'Tasks', 'wordlift-framework' ) ); |
|
| 53 | 53 | |
| 54 | - $this->task_ajax_adapters_registry = $task_ajax_adapters_registry; |
|
| 54 | + $this->task_ajax_adapters_registry = $task_ajax_adapters_registry; |
|
| 55 | 55 | |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Register the stylesheets and scripts for the admin area. |
|
| 60 | - * |
|
| 61 | - * @since 1.0.0 |
|
| 62 | - */ |
|
| 63 | - public function enqueue_scripts() { |
|
| 64 | - wp_enqueue_style( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.css', array(), $this->asset_version, 'all' ); |
|
| 65 | - wp_enqueue_script( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.js', array( |
|
| 66 | - 'jquery', |
|
| 67 | - 'wp-util' |
|
| 68 | - ), $this->asset_version, true ); |
|
| 69 | - } |
|
| 58 | + /** |
|
| 59 | + * Register the stylesheets and scripts for the admin area. |
|
| 60 | + * |
|
| 61 | + * @since 1.0.0 |
|
| 62 | + */ |
|
| 63 | + public function enqueue_scripts() { |
|
| 64 | + wp_enqueue_style( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.css', array(), $this->asset_version, 'all' ); |
|
| 65 | + wp_enqueue_script( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.js', array( |
|
| 66 | + 'jquery', |
|
| 67 | + 'wp-util' |
|
| 68 | + ), $this->asset_version, true ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Render the page. |
|
| 73 | - * |
|
| 74 | - * @since 1.0.0 |
|
| 75 | - */ |
|
| 76 | - public function render() { |
|
| 71 | + /** |
|
| 72 | + * Render the page. |
|
| 73 | + * |
|
| 74 | + * @since 1.0.0 |
|
| 75 | + */ |
|
| 76 | + public function render() { |
|
| 77 | 77 | |
| 78 | - // Include the partial. |
|
| 79 | - include( plugin_dir_path( __FILE__ ) . 'assets/tasks-page.php' ); |
|
| 78 | + // Include the partial. |
|
| 79 | + include( plugin_dir_path( __FILE__ ) . 'assets/tasks-page.php' ); |
|
| 80 | 80 | |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | } |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @since 1.0.0 |
| 50 | 50 | */ |
| 51 | - public function __construct( $task_ajax_adapters_registry ) { |
|
| 52 | - parent::__construct( $this->menu_slug, __( 'Tasks', 'wordlift-framework' ), 'manage_options', 'wl_admin_menu', __( 'Tasks', 'wordlift-framework' ) ); |
|
| 51 | + public function __construct($task_ajax_adapters_registry) { |
|
| 52 | + parent::__construct($this->menu_slug, __('Tasks', 'wordlift-framework'), 'manage_options', 'wl_admin_menu', __('Tasks', 'wordlift-framework')); |
|
| 53 | 53 | |
| 54 | 54 | $this->task_ajax_adapters_registry = $task_ajax_adapters_registry; |
| 55 | 55 | |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | * @since 1.0.0 |
| 62 | 62 | */ |
| 63 | 63 | public function enqueue_scripts() { |
| 64 | - wp_enqueue_style( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.css', array(), $this->asset_version, 'all' ); |
|
| 65 | - wp_enqueue_script( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.js', array( |
|
| 64 | + wp_enqueue_style($this->menu_slug, plugin_dir_url(__FILE__).'assets/tasks-page.css', array(), $this->asset_version, 'all'); |
|
| 65 | + wp_enqueue_script($this->menu_slug, plugin_dir_url(__FILE__).'assets/tasks-page.js', array( |
|
| 66 | 66 | 'jquery', |
| 67 | 67 | 'wp-util' |
| 68 | - ), $this->asset_version, true ); |
|
| 68 | + ), $this->asset_version, true); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | public function render() { |
| 77 | 77 | |
| 78 | 78 | // Include the partial. |
| 79 | - include( plugin_dir_path( __FILE__ ) . 'assets/tasks-page.php' ); |
|
| 79 | + include(plugin_dir_path(__FILE__).'assets/tasks-page.php'); |
|
| 80 | 80 | |
| 81 | 81 | } |
| 82 | 82 | |
@@ -18,71 +18,71 @@ |
||
| 18 | 18 | |
| 19 | 19 | abstract class Tasks_Page_Base extends Submenu_Page_Base { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The ID of this admin page. |
|
| 23 | - * |
|
| 24 | - * @since 1.0.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var string $menu_slug The ID of this page. |
|
| 27 | - */ |
|
| 28 | - private $menu_slug; |
|
| 21 | + /** |
|
| 22 | + * The ID of this admin page. |
|
| 23 | + * |
|
| 24 | + * @since 1.0.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var string $menu_slug The ID of this page. |
|
| 27 | + */ |
|
| 28 | + private $menu_slug; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var Task_Ajax_Adapters_Registry |
|
| 32 | - */ |
|
| 33 | - private $task_ajax_adapters_registry; |
|
| 30 | + /** |
|
| 31 | + * @var Task_Ajax_Adapters_Registry |
|
| 32 | + */ |
|
| 33 | + private $task_ajax_adapters_registry; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private $version; |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private $version; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Define the {@link Wordlift_Admin_Page} constructor. |
|
| 42 | - * |
|
| 43 | - * @param Task_Ajax_Adapters_Registry $task_ajax_adapters_registry |
|
| 44 | - * |
|
| 45 | - * @param string $version |
|
| 46 | - * @param string $menu_slug |
|
| 47 | - * @param string $page_title |
|
| 48 | - * @param string $capability |
|
| 49 | - * @param string|null $parent_slug |
|
| 50 | - * @param string|null $menu_title |
|
| 51 | - * |
|
| 52 | - * @since 1.0.0 |
|
| 53 | - */ |
|
| 54 | - public function __construct( $task_ajax_adapters_registry, $version, $menu_slug, $page_title, $capability = 'manage_options', $parent_slug = null, $menu_title = null ) { |
|
| 55 | - parent::__construct( $menu_slug, $page_title, $capability, $parent_slug, $menu_title ); |
|
| 40 | + /** |
|
| 41 | + * Define the {@link Wordlift_Admin_Page} constructor. |
|
| 42 | + * |
|
| 43 | + * @param Task_Ajax_Adapters_Registry $task_ajax_adapters_registry |
|
| 44 | + * |
|
| 45 | + * @param string $version |
|
| 46 | + * @param string $menu_slug |
|
| 47 | + * @param string $page_title |
|
| 48 | + * @param string $capability |
|
| 49 | + * @param string|null $parent_slug |
|
| 50 | + * @param string|null $menu_title |
|
| 51 | + * |
|
| 52 | + * @since 1.0.0 |
|
| 53 | + */ |
|
| 54 | + public function __construct( $task_ajax_adapters_registry, $version, $menu_slug, $page_title, $capability = 'manage_options', $parent_slug = null, $menu_title = null ) { |
|
| 55 | + parent::__construct( $menu_slug, $page_title, $capability, $parent_slug, $menu_title ); |
|
| 56 | 56 | |
| 57 | - $this->task_ajax_adapters_registry = $task_ajax_adapters_registry; |
|
| 58 | - $this->version = $version; |
|
| 59 | - $this->menu_slug = $menu_slug; |
|
| 57 | + $this->task_ajax_adapters_registry = $task_ajax_adapters_registry; |
|
| 58 | + $this->version = $version; |
|
| 59 | + $this->menu_slug = $menu_slug; |
|
| 60 | 60 | |
| 61 | - } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Register the stylesheets and scripts for the admin area. |
|
| 65 | - * |
|
| 66 | - * @since 1.0.0 |
|
| 67 | - */ |
|
| 68 | - public function enqueue_scripts() { |
|
| 69 | - wp_enqueue_style( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.css', array(), $this->version, 'all' ); |
|
| 70 | - wp_enqueue_script( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.js', array( |
|
| 71 | - 'jquery', |
|
| 72 | - 'wp-util' |
|
| 73 | - ), $this->version, true ); |
|
| 74 | - } |
|
| 63 | + /** |
|
| 64 | + * Register the stylesheets and scripts for the admin area. |
|
| 65 | + * |
|
| 66 | + * @since 1.0.0 |
|
| 67 | + */ |
|
| 68 | + public function enqueue_scripts() { |
|
| 69 | + wp_enqueue_style( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.css', array(), $this->version, 'all' ); |
|
| 70 | + wp_enqueue_script( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.js', array( |
|
| 71 | + 'jquery', |
|
| 72 | + 'wp-util' |
|
| 73 | + ), $this->version, true ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Render the page. |
|
| 78 | - * |
|
| 79 | - * @since 1.0.0 |
|
| 80 | - */ |
|
| 81 | - public function render() { |
|
| 76 | + /** |
|
| 77 | + * Render the page. |
|
| 78 | + * |
|
| 79 | + * @since 1.0.0 |
|
| 80 | + */ |
|
| 81 | + public function render() { |
|
| 82 | 82 | |
| 83 | - // Include the partial. |
|
| 84 | - include( plugin_dir_path( __FILE__ ) . 'assets/tasks-page.php' ); |
|
| 83 | + // Include the partial. |
|
| 84 | + include( plugin_dir_path( __FILE__ ) . 'assets/tasks-page.php' ); |
|
| 85 | 85 | |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | } |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @since 1.0.0 |
| 53 | 53 | */ |
| 54 | - public function __construct( $task_ajax_adapters_registry, $version, $menu_slug, $page_title, $capability = 'manage_options', $parent_slug = null, $menu_title = null ) { |
|
| 55 | - parent::__construct( $menu_slug, $page_title, $capability, $parent_slug, $menu_title ); |
|
| 54 | + public function __construct($task_ajax_adapters_registry, $version, $menu_slug, $page_title, $capability = 'manage_options', $parent_slug = null, $menu_title = null) { |
|
| 55 | + parent::__construct($menu_slug, $page_title, $capability, $parent_slug, $menu_title); |
|
| 56 | 56 | |
| 57 | 57 | $this->task_ajax_adapters_registry = $task_ajax_adapters_registry; |
| 58 | 58 | $this->version = $version; |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | * @since 1.0.0 |
| 67 | 67 | */ |
| 68 | 68 | public function enqueue_scripts() { |
| 69 | - wp_enqueue_style( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.css', array(), $this->version, 'all' ); |
|
| 70 | - wp_enqueue_script( $this->menu_slug, plugin_dir_url( __FILE__ ) . 'assets/tasks-page.js', array( |
|
| 69 | + wp_enqueue_style($this->menu_slug, plugin_dir_url(__FILE__).'assets/tasks-page.css', array(), $this->version, 'all'); |
|
| 70 | + wp_enqueue_script($this->menu_slug, plugin_dir_url(__FILE__).'assets/tasks-page.js', array( |
|
| 71 | 71 | 'jquery', |
| 72 | 72 | 'wp-util' |
| 73 | - ), $this->version, true ); |
|
| 73 | + ), $this->version, true); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | public function render() { |
| 82 | 82 | |
| 83 | 83 | // Include the partial. |
| 84 | - include( plugin_dir_path( __FILE__ ) . 'assets/tasks-page.php' ); |
|
| 84 | + include(plugin_dir_path(__FILE__).'assets/tasks-page.php'); |
|
| 85 | 85 | |
| 86 | 86 | } |
| 87 | 87 | |
@@ -16,30 +16,30 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | interface Task_Progress { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The total number of elements to process. |
|
| 21 | - * |
|
| 22 | - * @param int $value The total number of elements to process. |
|
| 23 | - * |
|
| 24 | - * @since 1.0.0 |
|
| 25 | - */ |
|
| 26 | - function set_count( $value ); |
|
| 19 | + /** |
|
| 20 | + * The total number of elements to process. |
|
| 21 | + * |
|
| 22 | + * @param int $value The total number of elements to process. |
|
| 23 | + * |
|
| 24 | + * @since 1.0.0 |
|
| 25 | + */ |
|
| 26 | + function set_count( $value ); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Set the current processed item. |
|
| 30 | - * |
|
| 31 | - * @param int $counter The current item. |
|
| 32 | - * @param mixed $item The current item. |
|
| 33 | - * |
|
| 34 | - * @since 1.0.0 |
|
| 35 | - */ |
|
| 36 | - function set_progress( $counter, $item ); |
|
| 28 | + /** |
|
| 29 | + * Set the current processed item. |
|
| 30 | + * |
|
| 31 | + * @param int $counter The current item. |
|
| 32 | + * @param mixed $item The current item. |
|
| 33 | + * |
|
| 34 | + * @since 1.0.0 |
|
| 35 | + */ |
|
| 36 | + function set_progress( $counter, $item ); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Set the operation as complete. |
|
| 40 | - * |
|
| 41 | - * @since 1.0.0 |
|
| 42 | - */ |
|
| 43 | - function finish(); |
|
| 38 | + /** |
|
| 39 | + * Set the operation as complete. |
|
| 40 | + * |
|
| 41 | + * @since 1.0.0 |
|
| 42 | + */ |
|
| 43 | + function finish(); |
|
| 44 | 44 | |
| 45 | 45 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @since 1.0.0 |
| 25 | 25 | */ |
| 26 | - function set_count( $value ); |
|
| 26 | + function set_count($value); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Set the current processed item. |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @since 1.0.0 |
| 35 | 35 | */ |
| 36 | - function set_progress( $counter, $item ); |
|
| 36 | + function set_progress($counter, $item); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Set the operation as complete. |