Completed
Pull Request — master (#1547)
by Naveen
53s
created
src/wordlift/jsonld/class-jsonld-adapter.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -22,39 +22,39 @@
 block discarded – undo
22 22
  */
23 23
 class Jsonld_Adapter {
24 24
 
25
-	/**
26
-	 * @var Wordlift_Jsonld_Service
27
-	 */
28
-	private $jsonld_service;
25
+    /**
26
+     * @var Wordlift_Jsonld_Service
27
+     */
28
+    private $jsonld_service;
29 29
 
30
-	/**
31
-	 * Jsonld_Adapter constructor.
32
-	 *
33
-	 * @param \Wordlift_Jsonld_Service $jsonld_service
34
-	 */
35
-	public function __construct( $jsonld_service ) {
30
+    /**
31
+     * Jsonld_Adapter constructor.
32
+     *
33
+     * @param \Wordlift_Jsonld_Service $jsonld_service
34
+     */
35
+    public function __construct( $jsonld_service ) {
36 36
 
37
-		$this->jsonld_service = $jsonld_service;
37
+        $this->jsonld_service = $jsonld_service;
38 38
 
39
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
40
-		add_action( 'amp_post_template_head', array( $this, 'wp_head' ) );
39
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
40
+        add_action( 'amp_post_template_head', array( $this, 'wp_head' ) );
41 41
 
42
-	}
42
+    }
43 43
 
44
-	public function wp_head() {
44
+    public function wp_head() {
45 45
 
46
-		// Bail out if `wl_jsonld_enabled` isn't enabled.
47
-		if ( ! apply_filters( 'wl_jsonld_enabled', true ) ) {
48
-			return;
49
-		}
46
+        // Bail out if `wl_jsonld_enabled` isn't enabled.
47
+        if ( ! apply_filters( 'wl_jsonld_enabled', true ) ) {
48
+            return;
49
+        }
50 50
 
51
-		$generator = Generator_Factory::get_instance(
52
-			$this->jsonld_service,
53
-			get_the_ID()
54
-		);
51
+        $generator = Generator_Factory::get_instance(
52
+            $this->jsonld_service,
53
+            get_the_ID()
54
+        );
55 55
 
56
-		$generator->generate();
56
+        $generator->generate();
57 57
 
58
-	}
58
+    }
59 59
 
60 60
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,19 +32,19 @@
 block discarded – undo
32 32
 	 *
33 33
 	 * @param \Wordlift_Jsonld_Service $jsonld_service
34 34
 	 */
35
-	public function __construct( $jsonld_service ) {
35
+	public function __construct($jsonld_service) {
36 36
 
37 37
 		$this->jsonld_service = $jsonld_service;
38 38
 
39
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
40
-		add_action( 'amp_post_template_head', array( $this, 'wp_head' ) );
39
+		add_action('wp_head', array($this, 'wp_head'));
40
+		add_action('amp_post_template_head', array($this, 'wp_head'));
41 41
 
42 42
 	}
43 43
 
44 44
 	public function wp_head() {
45 45
 
46 46
 		// Bail out if `wl_jsonld_enabled` isn't enabled.
47
-		if ( ! apply_filters( 'wl_jsonld_enabled', true ) ) {
47
+		if ( ! apply_filters('wl_jsonld_enabled', true)) {
48 48
 			return;
49 49
 		}
50 50
 
Please login to merge, or discard this patch.
src/wordlift/jsonld/generator/class-generator.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,6 +4,6 @@
 block discarded – undo
4 4
 
5 5
 interface Generator {
6 6
 
7
-	function generate();
7
+    function generate();
8 8
 
9 9
 }
10 10
\ No newline at end of file
Please login to merge, or discard this patch.
src/wordlift/jsonld/generator/class-recipe-maker-yoast-generator.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,19 +10,19 @@
 block discarded – undo
10 10
  */
11 11
 class Recipe_Maker_Yoast_Generator implements Generator {
12 12
 
13
-	/**
14
-	 * @var \Wordlift_Jsonld_Service
15
-	 */
16
-	private $jsonld_service;
17
-
18
-	public function __construct( $jsonld_service ) {
19
-		$this->jsonld_service = $jsonld_service;
20
-	}
21
-
22
-	function generate() {
23
-		// we should not print our jsonld when yoast + recipe maker is active
24
-		// and recipe maker integration is turned on.
25
-	}
13
+    /**
14
+     * @var \Wordlift_Jsonld_Service
15
+     */
16
+    private $jsonld_service;
17
+
18
+    public function __construct( $jsonld_service ) {
19
+        $this->jsonld_service = $jsonld_service;
20
+    }
21
+
22
+    function generate() {
23
+        // we should not print our jsonld when yoast + recipe maker is active
24
+        // and recipe maker integration is turned on.
25
+    }
26 26
 
27 27
 
28 28
 }
29 29
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
 	 */
16 16
 	private $jsonld_service;
17 17
 
18
-	public function __construct( $jsonld_service ) {
18
+	public function __construct($jsonld_service) {
19 19
 		$this->jsonld_service = $jsonld_service;
20 20
 	}
21 21
 
Please login to merge, or discard this patch.
src/wordlift/jsonld/generator/class-default-generator.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -6,29 +6,29 @@
 block discarded – undo
6 6
 use Wordlift_Jsonld_Service;
7 7
 
8 8
 class Default_Generator implements Generator {
9
-	/**
10
-	 * @var Wordlift_Jsonld_Service
11
-	 */
12
-	private $jsonld_service;
9
+    /**
10
+     * @var Wordlift_Jsonld_Service
11
+     */
12
+    private $jsonld_service;
13 13
 
14 14
 
15
-	public function __construct( $jsonld_service ) {
16
-		$this->jsonld_service = $jsonld_service;
17
-	}
15
+    public function __construct( $jsonld_service ) {
16
+        $this->jsonld_service = $jsonld_service;
17
+    }
18 18
 
19
-	function generate() {
20
-		// Determine whether this is the home page or whether we're displaying a single post.
21
-		$is_homepage = is_home() || is_front_page();
22
-		$post_id     = is_singular() ? get_the_ID() : null;
19
+    function generate() {
20
+        // Determine whether this is the home page or whether we're displaying a single post.
21
+        $is_homepage = is_home() || is_front_page();
22
+        $post_id     = is_singular() ? get_the_ID() : null;
23 23
 
24
-		// Get the JSON-LD.
25
-		$jsonld = json_encode( $this->jsonld_service->get_jsonld( $is_homepage, $post_id, Jsonld_Context_Enum::PAGE ) );
26
-		// Finally print the JSON-LD out.
27
-		$jsonld_post_html_output = <<<EOF
24
+        // Get the JSON-LD.
25
+        $jsonld = json_encode( $this->jsonld_service->get_jsonld( $is_homepage, $post_id, Jsonld_Context_Enum::PAGE ) );
26
+        // Finally print the JSON-LD out.
27
+        $jsonld_post_html_output = <<<EOF
28 28
         <script type="application/ld+json" id="wl-jsonld">$jsonld</script>
29 29
 EOF;
30
-		$jsonld_post_html_output = apply_filters( 'wl_jsonld_post_html_output', $jsonld_post_html_output, $post_id );
30
+        $jsonld_post_html_output = apply_filters( 'wl_jsonld_post_html_output', $jsonld_post_html_output, $post_id );
31 31
 
32
-		echo $jsonld_post_html_output;
33
-	}
32
+        echo $jsonld_post_html_output;
33
+    }
34 34
 }
35 35
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	private $jsonld_service;
13 13
 
14 14
 
15
-	public function __construct( $jsonld_service ) {
15
+	public function __construct($jsonld_service) {
16 16
 		$this->jsonld_service = $jsonld_service;
17 17
 	}
18 18
 
@@ -22,12 +22,12 @@  discard block
 block discarded – undo
22 22
 		$post_id     = is_singular() ? get_the_ID() : null;
23 23
 
24 24
 		// Get the JSON-LD.
25
-		$jsonld = json_encode( $this->jsonld_service->get_jsonld( $is_homepage, $post_id, Jsonld_Context_Enum::PAGE ) );
25
+		$jsonld = json_encode($this->jsonld_service->get_jsonld($is_homepage, $post_id, Jsonld_Context_Enum::PAGE));
26 26
 		// Finally print the JSON-LD out.
27 27
 		$jsonld_post_html_output = <<<EOF
28 28
         <script type="application/ld+json" id="wl-jsonld">$jsonld</script>
29 29
 EOF;
30
-		$jsonld_post_html_output = apply_filters( 'wl_jsonld_post_html_output', $jsonld_post_html_output, $post_id );
30
+		$jsonld_post_html_output = apply_filters('wl_jsonld_post_html_output', $jsonld_post_html_output, $post_id);
31 31
 
32 32
 		echo $jsonld_post_html_output;
33 33
 	}
Please login to merge, or discard this patch.
src/wordlift/jsonld/generator/class-generator-factory.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -7,26 +7,26 @@
 block discarded – undo
7 7
 class Generator_Factory {
8 8
 
9 9
 
10
-	/**
11
-	 * @param  $jsonld_service \Wordlift_Jsonld_Service
12
-	 *
13
-	 * @return Generator
14
-	 */
15
-	public static function get_instance( $jsonld_service, $post_id ) {
16
-		$recipe_maker_validation_service = Recipe_Maker_Validation_Service::get_instance();
17
-		if ( is_singular()
18
-		     // No Mentions on home page.
19
-		     && ! is_home()
20
-		     && $recipe_maker_validation_service->is_yoast_active()
21
-		     && $recipe_maker_validation_service->is_wp_recipe_maker_available()
22
-		     && $recipe_maker_validation_service->is_recipe_maker_yoast_integration_on()
23
-		     && $recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id )
24
-		) {
25
-			return new Recipe_Maker_Yoast_Generator( $jsonld_service );
26
-		}
27
-
28
-		return new Default_Generator( $jsonld_service );
29
-	}
10
+    /**
11
+     * @param  $jsonld_service \Wordlift_Jsonld_Service
12
+     *
13
+     * @return Generator
14
+     */
15
+    public static function get_instance( $jsonld_service, $post_id ) {
16
+        $recipe_maker_validation_service = Recipe_Maker_Validation_Service::get_instance();
17
+        if ( is_singular()
18
+                // No Mentions on home page.
19
+             && ! is_home()
20
+             && $recipe_maker_validation_service->is_yoast_active()
21
+             && $recipe_maker_validation_service->is_wp_recipe_maker_available()
22
+             && $recipe_maker_validation_service->is_recipe_maker_yoast_integration_on()
23
+             && $recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id )
24
+        ) {
25
+            return new Recipe_Maker_Yoast_Generator( $jsonld_service );
26
+        }
27
+
28
+        return new Default_Generator( $jsonld_service );
29
+    }
30 30
 
31 31
 
32 32
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,20 +12,20 @@
 block discarded – undo
12 12
 	 *
13 13
 	 * @return Generator
14 14
 	 */
15
-	public static function get_instance( $jsonld_service, $post_id ) {
15
+	public static function get_instance($jsonld_service, $post_id) {
16 16
 		$recipe_maker_validation_service = Recipe_Maker_Validation_Service::get_instance();
17
-		if ( is_singular()
17
+		if (is_singular()
18 18
 		     // No Mentions on home page.
19 19
 		     && ! is_home()
20 20
 		     && $recipe_maker_validation_service->is_yoast_active()
21 21
 		     && $recipe_maker_validation_service->is_wp_recipe_maker_available()
22 22
 		     && $recipe_maker_validation_service->is_recipe_maker_yoast_integration_on()
23
-		     && $recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id )
23
+		     && $recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post($post_id)
24 24
 		) {
25
-			return new Recipe_Maker_Yoast_Generator( $jsonld_service );
25
+			return new Recipe_Maker_Yoast_Generator($jsonld_service);
26 26
 		}
27 27
 
28
-		return new Default_Generator( $jsonld_service );
28
+		return new Default_Generator($jsonld_service);
29 29
 	}
30 30
 
31 31
 
Please login to merge, or discard this patch.
src/wordlift/external-plugin-hooks/yoast/class-yoast-jsonld.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -12,27 +12,27 @@
 block discarded – undo
12 12
  */
13 13
 class Yoast_Jsonld {
14 14
 
15
-	/**
16
-	 * @var Recipe_Maker_Validation_Service
17
-	 */
18
-	private $recipe_maker_validation_service;
15
+    /**
16
+     * @var Recipe_Maker_Validation_Service
17
+     */
18
+    private $recipe_maker_validation_service;
19 19
 
20
-	public function __construct( $recipe_maker_validation_service ) {
21
-		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
22
-		add_action( 'wpseo_json_ld', array( $this, 'disable_schema_types' ) );
23
-	}
20
+    public function __construct( $recipe_maker_validation_service ) {
21
+        $this->recipe_maker_validation_service = $recipe_maker_validation_service;
22
+        add_action( 'wpseo_json_ld', array( $this, 'disable_schema_types' ) );
23
+    }
24 24
 
25
-	public function disable_schema_types() {
26
-		if ( ! get_post() instanceof \WP_Post ) {
27
-			return false;
28
-		}
29
-		$post_id = get_the_ID();
30
-		if ( $this->recipe_maker_validation_service
31
-			     ->is_atleast_once_recipe_present_in_the_post( $post_id )
32
-		     && ! $this->recipe_maker_validation_service->is_recipe_maker_yoast_integration_on() ) {
33
-			add_filter( 'wpseo_schema_needs_website', '__return_false' );
34
-			add_filter( 'wpseo_schema_needs_webpage', '__return_false' );
35
-			add_filter( 'wpseo_schema_needs_article', '__return_false' );
36
-		}
37
-	}
25
+    public function disable_schema_types() {
26
+        if ( ! get_post() instanceof \WP_Post ) {
27
+            return false;
28
+        }
29
+        $post_id = get_the_ID();
30
+        if ( $this->recipe_maker_validation_service
31
+                    ->is_atleast_once_recipe_present_in_the_post( $post_id )
32
+             && ! $this->recipe_maker_validation_service->is_recipe_maker_yoast_integration_on() ) {
33
+            add_filter( 'wpseo_schema_needs_website', '__return_false' );
34
+            add_filter( 'wpseo_schema_needs_webpage', '__return_false' );
35
+            add_filter( 'wpseo_schema_needs_article', '__return_false' );
36
+        }
37
+    }
38 38
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,22 +17,22 @@
 block discarded – undo
17 17
 	 */
18 18
 	private $recipe_maker_validation_service;
19 19
 
20
-	public function __construct( $recipe_maker_validation_service ) {
20
+	public function __construct($recipe_maker_validation_service) {
21 21
 		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
22
-		add_action( 'wpseo_json_ld', array( $this, 'disable_schema_types' ) );
22
+		add_action('wpseo_json_ld', array($this, 'disable_schema_types'));
23 23
 	}
24 24
 
25 25
 	public function disable_schema_types() {
26
-		if ( ! get_post() instanceof \WP_Post ) {
26
+		if ( ! get_post() instanceof \WP_Post) {
27 27
 			return false;
28 28
 		}
29 29
 		$post_id = get_the_ID();
30
-		if ( $this->recipe_maker_validation_service
31
-			     ->is_atleast_once_recipe_present_in_the_post( $post_id )
32
-		     && ! $this->recipe_maker_validation_service->is_recipe_maker_yoast_integration_on() ) {
33
-			add_filter( 'wpseo_schema_needs_website', '__return_false' );
34
-			add_filter( 'wpseo_schema_needs_webpage', '__return_false' );
35
-			add_filter( 'wpseo_schema_needs_article', '__return_false' );
30
+		if ($this->recipe_maker_validation_service
31
+			     ->is_atleast_once_recipe_present_in_the_post($post_id)
32
+		     && ! $this->recipe_maker_validation_service->is_recipe_maker_yoast_integration_on()) {
33
+			add_filter('wpseo_schema_needs_website', '__return_false');
34
+			add_filter('wpseo_schema_needs_webpage', '__return_false');
35
+			add_filter('wpseo_schema_needs_article', '__return_false');
36 36
 		}
37 37
 	}
38 38
 }
Please login to merge, or discard this patch.
external-plugin-hooks/recipe-maker/class-recipe-maker-jsonld-swap.php 2 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -11,60 +11,60 @@
 block discarded – undo
11 11
 class Recipe_Maker_Jsonld_Swap {
12 12
 
13 13
 
14
-	/**
15
-	 * @var Recipe_Maker_Validation_Service
16
-	 */
17
-	private $validation_service;
18
-	/**
19
-	 * @var \Wordlift_Jsonld_Service
20
-	 */
21
-	private $jsonld_service;
22
-
23
-	/**
24
-	 * @param $validation_service Recipe_Maker_Validation_Service
25
-	 */
26
-	public function __construct( $validation_service, $jsonld_service ) {
27
-
28
-		$this->validation_service = $validation_service;
29
-		$this->jsonld_service     = $jsonld_service;
30
-
31
-		add_filter( 'wprm_recipe_metadata', array( $this, 'swap_jsonld' ), 10, 2 );
32
-	}
33
-
34
-	/**
35
-	 * Swap the valid jsonld with empty array so that recipe maker
36
-	 * wont output the jsonld.
37
-	 *
38
-	 * @param $metadata
39
-	 * @param $recipe
40
-	 *
41
-	 * @return array
42
-	 */
43
-	public function swap_jsonld( $metadata, $recipe ) {
44
-
45
-		$post_id = get_the_ID();
46
-
47
-		if ( ! $post_id || ! is_singular() || is_home() ) {
48
-			return array();
49
-		}
50
-
51
-		// if yoast + recipe maker integration is on, then we should add mentions to jsonld.
52
-		if ( ! $this->validation_service->is_recipe_maker_yoast_integration_on() ||
53
-		     ! $this->validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) {
54
-			return array();
55
-		}
56
-
57
-		$post_jsonld = $this->jsonld_service->get_jsonld( false, $post_id, Jsonld_Context_Enum::PAGE );
58
-
59
-		if ( 0 === count( $post_jsonld ) || ! array_key_exists( 'mentions', $post_jsonld[0] )
60
-		     || 0 === count( $post_jsonld[0]['mentions'] ) ) {
61
-			return array();
62
-		}
63
-
64
-		$metadata['mentions'] = $post_jsonld[0]['mentions'];
65
-
66
-		return $metadata;
67
-	}
14
+    /**
15
+     * @var Recipe_Maker_Validation_Service
16
+     */
17
+    private $validation_service;
18
+    /**
19
+     * @var \Wordlift_Jsonld_Service
20
+     */
21
+    private $jsonld_service;
22
+
23
+    /**
24
+     * @param $validation_service Recipe_Maker_Validation_Service
25
+     */
26
+    public function __construct( $validation_service, $jsonld_service ) {
27
+
28
+        $this->validation_service = $validation_service;
29
+        $this->jsonld_service     = $jsonld_service;
30
+
31
+        add_filter( 'wprm_recipe_metadata', array( $this, 'swap_jsonld' ), 10, 2 );
32
+    }
33
+
34
+    /**
35
+     * Swap the valid jsonld with empty array so that recipe maker
36
+     * wont output the jsonld.
37
+     *
38
+     * @param $metadata
39
+     * @param $recipe
40
+     *
41
+     * @return array
42
+     */
43
+    public function swap_jsonld( $metadata, $recipe ) {
44
+
45
+        $post_id = get_the_ID();
46
+
47
+        if ( ! $post_id || ! is_singular() || is_home() ) {
48
+            return array();
49
+        }
50
+
51
+        // if yoast + recipe maker integration is on, then we should add mentions to jsonld.
52
+        if ( ! $this->validation_service->is_recipe_maker_yoast_integration_on() ||
53
+             ! $this->validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) {
54
+            return array();
55
+        }
56
+
57
+        $post_jsonld = $this->jsonld_service->get_jsonld( false, $post_id, Jsonld_Context_Enum::PAGE );
58
+
59
+        if ( 0 === count( $post_jsonld ) || ! array_key_exists( 'mentions', $post_jsonld[0] )
60
+             || 0 === count( $post_jsonld[0]['mentions'] ) ) {
61
+            return array();
62
+        }
63
+
64
+        $metadata['mentions'] = $post_jsonld[0]['mentions'];
65
+
66
+        return $metadata;
67
+    }
68 68
 
69 69
 
70 70
 }
71 71
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 	/**
24 24
 	 * @param $validation_service Recipe_Maker_Validation_Service
25 25
 	 */
26
-	public function __construct( $validation_service, $jsonld_service ) {
26
+	public function __construct($validation_service, $jsonld_service) {
27 27
 
28 28
 		$this->validation_service = $validation_service;
29 29
 		$this->jsonld_service     = $jsonld_service;
30 30
 
31
-		add_filter( 'wprm_recipe_metadata', array( $this, 'swap_jsonld' ), 10, 2 );
31
+		add_filter('wprm_recipe_metadata', array($this, 'swap_jsonld'), 10, 2);
32 32
 	}
33 33
 
34 34
 	/**
@@ -40,24 +40,24 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @return array
42 42
 	 */
43
-	public function swap_jsonld( $metadata, $recipe ) {
43
+	public function swap_jsonld($metadata, $recipe) {
44 44
 
45 45
 		$post_id = get_the_ID();
46 46
 
47
-		if ( ! $post_id || ! is_singular() || is_home() ) {
47
+		if ( ! $post_id || ! is_singular() || is_home()) {
48 48
 			return array();
49 49
 		}
50 50
 
51 51
 		// if yoast + recipe maker integration is on, then we should add mentions to jsonld.
52 52
 		if ( ! $this->validation_service->is_recipe_maker_yoast_integration_on() ||
53
-		     ! $this->validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) {
53
+		     ! $this->validation_service->is_atleast_once_recipe_present_in_the_post($post_id)) {
54 54
 			return array();
55 55
 		}
56 56
 
57
-		$post_jsonld = $this->jsonld_service->get_jsonld( false, $post_id, Jsonld_Context_Enum::PAGE );
57
+		$post_jsonld = $this->jsonld_service->get_jsonld(false, $post_id, Jsonld_Context_Enum::PAGE);
58 58
 
59
-		if ( 0 === count( $post_jsonld ) || ! array_key_exists( 'mentions', $post_jsonld[0] )
60
-		     || 0 === count( $post_jsonld[0]['mentions'] ) ) {
59
+		if (0 === count($post_jsonld) || ! array_key_exists('mentions', $post_jsonld[0])
60
+		     || 0 === count($post_jsonld[0]['mentions'])) {
61 61
 			return array();
62 62
 		}
63 63
 
Please login to merge, or discard this patch.
external-plugin-hooks/recipe-maker/class-recipe-maker-jsonld-hook.php 2 patches
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -14,114 +14,114 @@
 block discarded – undo
14 14
  */
15 15
 class Recipe_Maker_Jsonld_Hook {
16 16
 
17
-	/**
18
-	 * @var \Wordlift_Attachment_Service
19
-	 */
20
-	private $attachment_service;
21
-	/**
22
-	 * @var Recipe_Maker_Validation_Service
23
-	 */
24
-	private $recipe_maker_validation_service;
25
-
26
-	/**
27
-	 * Recipe_Maker_Jsonld_Hook constructor.
28
-	 *
29
-	 * @param $attachment_service \Wordlift_Attachment_Service
30
-	 * @param $recipe_maker_validation_service Recipe_Maker_Validation_Service
31
-	 */
32
-	public function __construct( $attachment_service, $recipe_maker_validation_service ) {
33
-
34
-		$this->attachment_service              = $attachment_service;
35
-		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
36
-		$this->merge_recipe_jsonld();
37
-	}
38
-
39
-
40
-	private function merge_recipe_jsonld() {
41
-		// First we push all the linked recipes to references.
42
-		add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
43
-		add_filter( 'wl_post_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
44
-
45
-		// Then we merge the jsonld for every recipe.
46
-		add_filter( 'wl_entity_jsonld', array( $this, 'wl_entity_jsonld' ), 10, 3 );
47
-	}
48
-
49
-	private function is_recipe_maker_yoast_integration_on() {
50
-
51
-		if ( ! class_exists( '\WPRM_Settings' ) ) {
52
-			return false;
53
-		}
54
-
55
-		return \WPRM_Settings::get( 'yoast_seo_integration' ) && interface_exists( 'WPSEO_Graph_Piece' );
56
-	}
57
-
58
-
59
-
60
-	public function wl_entity_jsonld_array( $arr, $post_id ) {
61
-
62
-		$jsonld     = $arr['jsonld'];
63
-		$references = $arr['references'];
64
-
65
-		// check if wp recipe maker installed, if not return early.
66
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
67
-			return $arr;
68
-		}
69
-
70
-		// 1. Get the jsonld from recipe maker for the post id.
71
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
72
-
73
-		// If there are no associated recipes for a post id then return early
74
-		if ( ! $recipe_ids ) {
75
-			return $arr;
76
-		}
77
-
78
-		return array(
79
-			'jsonld'     => $jsonld,
80
-			'references' => array_merge( $recipe_ids, $references )
81
-		);
82
-
83
-	}
84
-
85
-
86
-	public function wl_entity_jsonld( $jsonld, $post_id, $references ) {
87
-		$recipe_data = $this->process_single_recipe_item( $post_id );
88
-		if ( ! $recipe_data ) {
89
-			return $jsonld;
90
-		}
91
-
92
-		// Set image via wordlift.
93
-		\Wordlift_Abstract_Post_To_Jsonld_Converter::set_images(
94
-			$this->attachment_service,
95
-			get_post( $post_id ),
96
-			$recipe_data
97
-		);
98
-
99
-		if ( ! $jsonld ) {
100
-			return $recipe_data;
101
-		}
102
-
103
-		return $recipe_data + $jsonld;
104
-	}
105
-
106
-	/**
107
-	 * @param $linked_recipe_id int post id of that recipe.
108
-	 *
109
-	 * @return array Recipe valid jsonld data.
110
-	 */
111
-	private function process_single_recipe_item( $linked_recipe_id ) {
112
-		// check if recipe maker present.
113
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
114
-			return array();
115
-		}
116
-		$linked_recipe = \WPRM_Recipe_Manager::get_recipe( $linked_recipe_id );
117
-		if ( $linked_recipe ) {
118
-			return \WPRM_Metadata::get_metadata_details( $linked_recipe ) ?: array();
119
-		}
17
+    /**
18
+     * @var \Wordlift_Attachment_Service
19
+     */
20
+    private $attachment_service;
21
+    /**
22
+     * @var Recipe_Maker_Validation_Service
23
+     */
24
+    private $recipe_maker_validation_service;
25
+
26
+    /**
27
+     * Recipe_Maker_Jsonld_Hook constructor.
28
+     *
29
+     * @param $attachment_service \Wordlift_Attachment_Service
30
+     * @param $recipe_maker_validation_service Recipe_Maker_Validation_Service
31
+     */
32
+    public function __construct( $attachment_service, $recipe_maker_validation_service ) {
33
+
34
+        $this->attachment_service              = $attachment_service;
35
+        $this->recipe_maker_validation_service = $recipe_maker_validation_service;
36
+        $this->merge_recipe_jsonld();
37
+    }
38
+
39
+
40
+    private function merge_recipe_jsonld() {
41
+        // First we push all the linked recipes to references.
42
+        add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
43
+        add_filter( 'wl_post_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
44
+
45
+        // Then we merge the jsonld for every recipe.
46
+        add_filter( 'wl_entity_jsonld', array( $this, 'wl_entity_jsonld' ), 10, 3 );
47
+    }
48
+
49
+    private function is_recipe_maker_yoast_integration_on() {
50
+
51
+        if ( ! class_exists( '\WPRM_Settings' ) ) {
52
+            return false;
53
+        }
54
+
55
+        return \WPRM_Settings::get( 'yoast_seo_integration' ) && interface_exists( 'WPSEO_Graph_Piece' );
56
+    }
57
+
58
+
59
+
60
+    public function wl_entity_jsonld_array( $arr, $post_id ) {
61
+
62
+        $jsonld     = $arr['jsonld'];
63
+        $references = $arr['references'];
64
+
65
+        // check if wp recipe maker installed, if not return early.
66
+        if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
67
+            return $arr;
68
+        }
69
+
70
+        // 1. Get the jsonld from recipe maker for the post id.
71
+        $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
72
+
73
+        // If there are no associated recipes for a post id then return early
74
+        if ( ! $recipe_ids ) {
75
+            return $arr;
76
+        }
77
+
78
+        return array(
79
+            'jsonld'     => $jsonld,
80
+            'references' => array_merge( $recipe_ids, $references )
81
+        );
82
+
83
+    }
84
+
85
+
86
+    public function wl_entity_jsonld( $jsonld, $post_id, $references ) {
87
+        $recipe_data = $this->process_single_recipe_item( $post_id );
88
+        if ( ! $recipe_data ) {
89
+            return $jsonld;
90
+        }
91
+
92
+        // Set image via wordlift.
93
+        \Wordlift_Abstract_Post_To_Jsonld_Converter::set_images(
94
+            $this->attachment_service,
95
+            get_post( $post_id ),
96
+            $recipe_data
97
+        );
98
+
99
+        if ( ! $jsonld ) {
100
+            return $recipe_data;
101
+        }
102
+
103
+        return $recipe_data + $jsonld;
104
+    }
105
+
106
+    /**
107
+     * @param $linked_recipe_id int post id of that recipe.
108
+     *
109
+     * @return array Recipe valid jsonld data.
110
+     */
111
+    private function process_single_recipe_item( $linked_recipe_id ) {
112
+        // check if recipe maker present.
113
+        if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
114
+            return array();
115
+        }
116
+        $linked_recipe = \WPRM_Recipe_Manager::get_recipe( $linked_recipe_id );
117
+        if ( $linked_recipe ) {
118
+            return \WPRM_Metadata::get_metadata_details( $linked_recipe ) ?: array();
119
+        }
120 120
 
121
-		return array();
122
-	}
121
+        return array();
122
+    }
123 123
 
124
-	private function get_mentions( $post_id ) {
124
+    private function get_mentions( $post_id ) {
125 125
 
126
-	}
126
+    }
127 127
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @param $attachment_service \Wordlift_Attachment_Service
30 30
 	 * @param $recipe_maker_validation_service Recipe_Maker_Validation_Service
31 31
 	 */
32
-	public function __construct( $attachment_service, $recipe_maker_validation_service ) {
32
+	public function __construct($attachment_service, $recipe_maker_validation_service) {
33 33
 
34 34
 		$this->attachment_service              = $attachment_service;
35 35
 		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
@@ -39,64 +39,64 @@  discard block
 block discarded – undo
39 39
 
40 40
 	private function merge_recipe_jsonld() {
41 41
 		// First we push all the linked recipes to references.
42
-		add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
43
-		add_filter( 'wl_post_jsonld_array', array( $this, 'wl_entity_jsonld_array' ), 10, 2 );
42
+		add_filter('wl_entity_jsonld_array', array($this, 'wl_entity_jsonld_array'), 10, 2);
43
+		add_filter('wl_post_jsonld_array', array($this, 'wl_entity_jsonld_array'), 10, 2);
44 44
 
45 45
 		// Then we merge the jsonld for every recipe.
46
-		add_filter( 'wl_entity_jsonld', array( $this, 'wl_entity_jsonld' ), 10, 3 );
46
+		add_filter('wl_entity_jsonld', array($this, 'wl_entity_jsonld'), 10, 3);
47 47
 	}
48 48
 
49 49
 	private function is_recipe_maker_yoast_integration_on() {
50 50
 
51
-		if ( ! class_exists( '\WPRM_Settings' ) ) {
51
+		if ( ! class_exists('\WPRM_Settings')) {
52 52
 			return false;
53 53
 		}
54 54
 
55
-		return \WPRM_Settings::get( 'yoast_seo_integration' ) && interface_exists( 'WPSEO_Graph_Piece' );
55
+		return \WPRM_Settings::get('yoast_seo_integration') && interface_exists('WPSEO_Graph_Piece');
56 56
 	}
57 57
 
58 58
 
59 59
 
60
-	public function wl_entity_jsonld_array( $arr, $post_id ) {
60
+	public function wl_entity_jsonld_array($arr, $post_id) {
61 61
 
62 62
 		$jsonld     = $arr['jsonld'];
63 63
 		$references = $arr['references'];
64 64
 
65 65
 		// check if wp recipe maker installed, if not return early.
66
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
66
+		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) {
67 67
 			return $arr;
68 68
 		}
69 69
 
70 70
 		// 1. Get the jsonld from recipe maker for the post id.
71
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
71
+		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post($post_id);
72 72
 
73 73
 		// If there are no associated recipes for a post id then return early
74
-		if ( ! $recipe_ids ) {
74
+		if ( ! $recipe_ids) {
75 75
 			return $arr;
76 76
 		}
77 77
 
78 78
 		return array(
79 79
 			'jsonld'     => $jsonld,
80
-			'references' => array_merge( $recipe_ids, $references )
80
+			'references' => array_merge($recipe_ids, $references)
81 81
 		);
82 82
 
83 83
 	}
84 84
 
85 85
 
86
-	public function wl_entity_jsonld( $jsonld, $post_id, $references ) {
87
-		$recipe_data = $this->process_single_recipe_item( $post_id );
88
-		if ( ! $recipe_data ) {
86
+	public function wl_entity_jsonld($jsonld, $post_id, $references) {
87
+		$recipe_data = $this->process_single_recipe_item($post_id);
88
+		if ( ! $recipe_data) {
89 89
 			return $jsonld;
90 90
 		}
91 91
 
92 92
 		// Set image via wordlift.
93 93
 		\Wordlift_Abstract_Post_To_Jsonld_Converter::set_images(
94 94
 			$this->attachment_service,
95
-			get_post( $post_id ),
95
+			get_post($post_id),
96 96
 			$recipe_data
97 97
 		);
98 98
 
99
-		if ( ! $jsonld ) {
99
+		if ( ! $jsonld) {
100 100
 			return $recipe_data;
101 101
 		}
102 102
 
@@ -108,20 +108,20 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @return array Recipe valid jsonld data.
110 110
 	 */
111
-	private function process_single_recipe_item( $linked_recipe_id ) {
111
+	private function process_single_recipe_item($linked_recipe_id) {
112 112
 		// check if recipe maker present.
113
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
113
+		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) {
114 114
 			return array();
115 115
 		}
116
-		$linked_recipe = \WPRM_Recipe_Manager::get_recipe( $linked_recipe_id );
117
-		if ( $linked_recipe ) {
118
-			return \WPRM_Metadata::get_metadata_details( $linked_recipe ) ?: array();
116
+		$linked_recipe = \WPRM_Recipe_Manager::get_recipe($linked_recipe_id);
117
+		if ($linked_recipe) {
118
+			return \WPRM_Metadata::get_metadata_details($linked_recipe) ?: array();
119 119
 		}
120 120
 
121 121
 		return array();
122 122
 	}
123 123
 
124
-	private function get_mentions( $post_id ) {
124
+	private function get_mentions($post_id) {
125 125
 
126 126
 	}
127 127
 }
Please login to merge, or discard this patch.
recipe-maker/class-recipe-maker-validation-service.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -7,65 +7,65 @@
 block discarded – undo
7 7
  */
8 8
 class Recipe_Maker_Validation_Service {
9 9
 
10
-	private function __construct() {
10
+    private function __construct() {
11 11
 
12
-	}
12
+    }
13 13
 
14
-	/**
15
-	 * @var Recipe_Maker_Validation_Service
16
-	 */
17
-	private static $instance;
14
+    /**
15
+     * @var Recipe_Maker_Validation_Service
16
+     */
17
+    private static $instance;
18 18
 
19
-	public static function get_instance() {
19
+    public static function get_instance() {
20 20
 
21
-		if ( ! isset( self::$instance ) ) {
22
-			self::$instance = new self();
23
-		}
21
+        if ( ! isset( self::$instance ) ) {
22
+            self::$instance = new self();
23
+        }
24 24
 
25
-		return self::$instance;
26
-	}
25
+        return self::$instance;
26
+    }
27 27
 
28
-	public function is_atleast_once_recipe_present_in_the_post( $post_id ) {
28
+    public function is_atleast_once_recipe_present_in_the_post( $post_id ) {
29 29
 
30
-		if ( ! $this->is_wp_recipe_maker_available() ) {
31
-			return false;
32
-		}
33
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
30
+        if ( ! $this->is_wp_recipe_maker_available() ) {
31
+            return false;
32
+        }
33
+        $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
34 34
 
35
-		return is_array( $recipe_ids ) ? count( $recipe_ids ) > 0 : false;
36
-	}
35
+        return is_array( $recipe_ids ) ? count( $recipe_ids ) > 0 : false;
36
+    }
37 37
 
38
-	public function is_wp_recipe_maker_available() {
39
-		/**
40
-		 * Dont alter the jsonld if the classes are not present.
41
-		 */
42
-		if ( ! class_exists( '\WPRM_Recipe_Manager' ) || ! class_exists( 'WPRM_Metadata' ) ) {
43
-			return false;
44
-		}
45
-		if ( ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe_ids_from_post' ) ||
46
-		     ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe' ) ||
47
-		     ! method_exists( '\WPRM_Metadata', 'get_metadata_details' )
48
-		) {
49
-			return false;
50
-		}
38
+    public function is_wp_recipe_maker_available() {
39
+        /**
40
+         * Dont alter the jsonld if the classes are not present.
41
+         */
42
+        if ( ! class_exists( '\WPRM_Recipe_Manager' ) || ! class_exists( 'WPRM_Metadata' ) ) {
43
+            return false;
44
+        }
45
+        if ( ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe_ids_from_post' ) ||
46
+             ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe' ) ||
47
+             ! method_exists( '\WPRM_Metadata', 'get_metadata_details' )
48
+        ) {
49
+            return false;
50
+        }
51 51
 
52
-		return true;
53
-	}
52
+        return true;
53
+    }
54 54
 
55 55
 
56
-	public function is_yoast_active() {
57
-		return defined( 'WPSEO_VERSION' );
58
-	}
56
+    public function is_yoast_active() {
57
+        return defined( 'WPSEO_VERSION' );
58
+    }
59 59
 
60 60
 
61
-	public function is_recipe_maker_yoast_integration_on() {
61
+    public function is_recipe_maker_yoast_integration_on() {
62 62
 
63
-		if ( ! class_exists( '\WPRM_Settings' ) ) {
64
-			return false;
65
-		}
63
+        if ( ! class_exists( '\WPRM_Settings' ) ) {
64
+            return false;
65
+        }
66 66
 
67
-		return \WPRM_Settings::get( 'yoast_seo_integration' ) && interface_exists( 'WPSEO_Graph_Piece' );
68
-	}
67
+        return \WPRM_Settings::get( 'yoast_seo_integration' ) && interface_exists( 'WPSEO_Graph_Piece' );
68
+    }
69 69
 
70 70
 
71 71
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -18,33 +18,33 @@  discard block
 block discarded – undo
18 18
 
19 19
 	public static function get_instance() {
20 20
 
21
-		if ( ! isset( self::$instance ) ) {
21
+		if ( ! isset(self::$instance)) {
22 22
 			self::$instance = new self();
23 23
 		}
24 24
 
25 25
 		return self::$instance;
26 26
 	}
27 27
 
28
-	public function is_atleast_once_recipe_present_in_the_post( $post_id ) {
28
+	public function is_atleast_once_recipe_present_in_the_post($post_id) {
29 29
 
30
-		if ( ! $this->is_wp_recipe_maker_available() ) {
30
+		if ( ! $this->is_wp_recipe_maker_available()) {
31 31
 			return false;
32 32
 		}
33
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
33
+		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post($post_id);
34 34
 
35
-		return is_array( $recipe_ids ) ? count( $recipe_ids ) > 0 : false;
35
+		return is_array($recipe_ids) ? count($recipe_ids) > 0 : false;
36 36
 	}
37 37
 
38 38
 	public function is_wp_recipe_maker_available() {
39 39
 		/**
40 40
 		 * Dont alter the jsonld if the classes are not present.
41 41
 		 */
42
-		if ( ! class_exists( '\WPRM_Recipe_Manager' ) || ! class_exists( 'WPRM_Metadata' ) ) {
42
+		if ( ! class_exists('\WPRM_Recipe_Manager') || ! class_exists('WPRM_Metadata')) {
43 43
 			return false;
44 44
 		}
45
-		if ( ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe_ids_from_post' ) ||
46
-		     ! method_exists( '\WPRM_Recipe_Manager', 'get_recipe' ) ||
47
-		     ! method_exists( '\WPRM_Metadata', 'get_metadata_details' )
45
+		if ( ! method_exists('\WPRM_Recipe_Manager', 'get_recipe_ids_from_post') ||
46
+		     ! method_exists('\WPRM_Recipe_Manager', 'get_recipe') ||
47
+		     ! method_exists('\WPRM_Metadata', 'get_metadata_details')
48 48
 		) {
49 49
 			return false;
50 50
 		}
@@ -54,17 +54,17 @@  discard block
 block discarded – undo
54 54
 
55 55
 
56 56
 	public function is_yoast_active() {
57
-		return defined( 'WPSEO_VERSION' );
57
+		return defined('WPSEO_VERSION');
58 58
 	}
59 59
 
60 60
 
61 61
 	public function is_recipe_maker_yoast_integration_on() {
62 62
 
63
-		if ( ! class_exists( '\WPRM_Settings' ) ) {
63
+		if ( ! class_exists('\WPRM_Settings')) {
64 64
 			return false;
65 65
 		}
66 66
 
67
-		return \WPRM_Settings::get( 'yoast_seo_integration' ) && interface_exists( 'WPSEO_Graph_Piece' );
67
+		return \WPRM_Settings::get('yoast_seo_integration') && interface_exists('WPSEO_Graph_Piece');
68 68
 	}
69 69
 
70 70
 
Please login to merge, or discard this patch.