@@ -4,39 +4,39 @@ |
||
4 | 4 | |
5 | 5 | class Preconditions { |
6 | 6 | |
7 | - /** |
|
8 | - * @var Notices |
|
9 | - */ |
|
10 | - private $notices; |
|
11 | - |
|
12 | - public function __construct( Notices $notices ) { |
|
13 | - $this->notices = $notices; |
|
14 | - } |
|
15 | - |
|
16 | - public function pass() { |
|
17 | - return $this->has_prerequisites() && $this->check_version(); |
|
18 | - } |
|
19 | - |
|
20 | - private function has_prerequisites() { |
|
21 | - return defined( 'WPRM_VERSION' ) |
|
22 | - && class_exists( 'WP_Recipe_Maker' ) |
|
23 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
24 | - && apply_filters( 'wl_feature__enable__food-kg', false ); |
|
25 | - } |
|
26 | - |
|
27 | - private function check_version() { |
|
28 | - $check = version_compare( WPRM_VERSION, '8.1.0', '>=' ) |
|
29 | - && version_compare( WPRM_VERSION, '8.9.3', '<' ); |
|
30 | - |
|
31 | - if ( ! $check ) { |
|
32 | - $this->notices->queue( |
|
33 | - 'warning', |
|
34 | - /* translators: 1: minimum supported WPRM version, 2: maximum supported WPRM version, 3: Detected WP Recipe Maker version. */ |
|
35 | - sprintf( __( 'WordLift Food KG support requires WP Recipe Maker %1$s-%2$s, %3$s found.', 'wordlift' ), '8.1', '8.7', WPRM_VERSION ) |
|
36 | - ); |
|
37 | - } |
|
38 | - |
|
39 | - return $check; |
|
40 | - } |
|
7 | + /** |
|
8 | + * @var Notices |
|
9 | + */ |
|
10 | + private $notices; |
|
11 | + |
|
12 | + public function __construct( Notices $notices ) { |
|
13 | + $this->notices = $notices; |
|
14 | + } |
|
15 | + |
|
16 | + public function pass() { |
|
17 | + return $this->has_prerequisites() && $this->check_version(); |
|
18 | + } |
|
19 | + |
|
20 | + private function has_prerequisites() { |
|
21 | + return defined( 'WPRM_VERSION' ) |
|
22 | + && class_exists( 'WP_Recipe_Maker' ) |
|
23 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
24 | + && apply_filters( 'wl_feature__enable__food-kg', false ); |
|
25 | + } |
|
26 | + |
|
27 | + private function check_version() { |
|
28 | + $check = version_compare( WPRM_VERSION, '8.1.0', '>=' ) |
|
29 | + && version_compare( WPRM_VERSION, '8.9.3', '<' ); |
|
30 | + |
|
31 | + if ( ! $check ) { |
|
32 | + $this->notices->queue( |
|
33 | + 'warning', |
|
34 | + /* translators: 1: minimum supported WPRM version, 2: maximum supported WPRM version, 3: Detected WP Recipe Maker version. */ |
|
35 | + sprintf( __( 'WordLift Food KG support requires WP Recipe Maker %1$s-%2$s, %3$s found.', 'wordlift' ), '8.1', '8.7', WPRM_VERSION ) |
|
36 | + ); |
|
37 | + } |
|
38 | + |
|
39 | + return $check; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
@@ -20,86 +20,86 @@ |
||
20 | 20 | */ |
21 | 21 | class Post_Id_To_Entity_Transform_Function implements Mappings_Transform_Function { |
22 | 22 | |
23 | - public function __construct() { |
|
23 | + public function __construct() { |
|
24 | 24 | |
25 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
25 | + add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
26 | 26 | |
27 | - } |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Hook to add ourselves to the list of available transform functions. |
|
31 | - * |
|
32 | - * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
33 | - * |
|
34 | - * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
35 | - */ |
|
36 | - public function wl_mappings_transformation_functions( $value ) { |
|
29 | + /** |
|
30 | + * Hook to add ourselves to the list of available transform functions. |
|
31 | + * |
|
32 | + * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
33 | + * |
|
34 | + * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
35 | + */ |
|
36 | + public function wl_mappings_transformation_functions( $value ) { |
|
37 | 37 | |
38 | - $value[] = $this; |
|
38 | + $value[] = $this; |
|
39 | 39 | |
40 | - return $value; |
|
41 | - } |
|
40 | + return $value; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @inheritDoc |
|
45 | - */ |
|
46 | - public function get_name() { |
|
43 | + /** |
|
44 | + * @inheritDoc |
|
45 | + */ |
|
46 | + public function get_name() { |
|
47 | 47 | |
48 | - return 'post_id_to_entity'; |
|
49 | - } |
|
48 | + return 'post_id_to_entity'; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @inheritDoc |
|
53 | - */ |
|
54 | - public function get_label() { |
|
51 | + /** |
|
52 | + * @inheritDoc |
|
53 | + */ |
|
54 | + public function get_label() { |
|
55 | 55 | |
56 | - return __( 'Post ID to Entity', 'wordlift' ); |
|
57 | - } |
|
56 | + return __( 'Post ID to Entity', 'wordlift' ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @inheritDoc |
|
61 | - */ |
|
62 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
63 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
59 | + /** |
|
60 | + * @inheritDoc |
|
61 | + */ |
|
62 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
63 | + public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
64 | 64 | |
65 | - $ret_val = array(); |
|
66 | - foreach ( (array) $data as $target_post_id ) { |
|
65 | + $ret_val = array(); |
|
66 | + foreach ( (array) $data as $target_post_id ) { |
|
67 | 67 | |
68 | - // We may receive a `WP_Post` here, in which case we want the ID. |
|
69 | - if ( is_a( $target_post_id, '\WP_Post' ) ) { |
|
70 | - $target_post_id = $target_post_id->ID; |
|
71 | - } |
|
68 | + // We may receive a `WP_Post` here, in which case we want the ID. |
|
69 | + if ( is_a( $target_post_id, '\WP_Post' ) ) { |
|
70 | + $target_post_id = $target_post_id->ID; |
|
71 | + } |
|
72 | 72 | |
73 | - // We need a numeric post ID. |
|
74 | - if ( ! is_numeric( $target_post_id ) ) { |
|
73 | + // We need a numeric post ID. |
|
74 | + if ( ! is_numeric( $target_post_id ) ) { |
|
75 | 75 | |
76 | - $class_name = is_object( $target_post_id ) ? get_class( $target_post_id ) : 'unknown, maybe a string'; |
|
76 | + $class_name = is_object( $target_post_id ) ? get_class( $target_post_id ) : 'unknown, maybe a string'; |
|
77 | 77 | |
78 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
79 | - @header( "X-Post-Id-To-Entity-Transform-Function: $class_name is not numeric." ); |
|
78 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
79 | + @header( "X-Post-Id-To-Entity-Transform-Function: $class_name is not numeric." ); |
|
80 | 80 | |
81 | - continue; |
|
82 | - } |
|
81 | + continue; |
|
82 | + } |
|
83 | 83 | |
84 | - // Get the entity by URI. |
|
85 | - $entity_url = Wordpress_Content_Service::get_instance() |
|
86 | - ->get_entity_id( Wordpress_Content_Id::create_post( $target_post_id ) ); |
|
84 | + // Get the entity by URI. |
|
85 | + $entity_url = Wordpress_Content_Service::get_instance() |
|
86 | + ->get_entity_id( Wordpress_Content_Id::create_post( $target_post_id ) ); |
|
87 | 87 | |
88 | - // No entity URL. |
|
89 | - if ( empty( $entity_url ) ) { |
|
90 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
91 | - @header( "X-Post-Id-To-Entity-Transform-Function: entity url for $data not found." ); |
|
88 | + // No entity URL. |
|
89 | + if ( empty( $entity_url ) ) { |
|
90 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
91 | + @header( "X-Post-Id-To-Entity-Transform-Function: entity url for $data not found." ); |
|
92 | 92 | |
93 | - continue; |
|
94 | - } |
|
93 | + continue; |
|
94 | + } |
|
95 | 95 | |
96 | - // Add the entity among the references using the post ID. |
|
97 | - $references[] = (int) $target_post_id; |
|
96 | + // Add the entity among the references using the post ID. |
|
97 | + $references[] = (int) $target_post_id; |
|
98 | 98 | |
99 | - $ret_val[] = array( '@id' => $entity_url ); |
|
100 | - } |
|
99 | + $ret_val[] = array( '@id' => $entity_url ); |
|
100 | + } |
|
101 | 101 | |
102 | - return $ret_val; |
|
103 | - } |
|
102 | + return $ret_val; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | } |