Completed
Pull Request — master (#1549)
by Naveen
53s
created
wordlift/external-plugin-hooks/recipe-maker/class-recipe-maker-warning.php 2 patches
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -10,102 +10,102 @@
 block discarded – undo
10 10
  */
11 11
 class Recipe_Maker_Warning {
12 12
 
13
-	/**
14
-	 * @var Recipe_Maker_Validation_Service
15
-	 */
16
-	private $recipe_maker_validation_service;
17
-
18
-	public function __construct( $recipe_maker_validation_service ) {
19
-		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
20
-		/**
21
-		 * Filter: wl_feature__enable__notices.
22
-		 *
23
-		 * @param bool whether the notices needs to be enabled or not.
24
-		 *
25
-		 * @return bool
26
-		 * @since 3.27.6
27
-		 */
28
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
29
-			add_action( 'admin_notices', array( $this, 'display_image_size_warning' ) );
30
-		}
31
-	}
32
-
33
-	/**
34
-	 * Show the warning after applying the conditions.
35
-	 */
36
-	public function display_image_size_warning() {
37
-
38
-		// Check if we are on the post.
39
-		if ( ! get_post() instanceof \WP_Post ) {
40
-			return false;
41
-		}
42
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
43
-			return false;
44
-		}
45
-		$post_id = get_the_ID();
46
-
47
-		// Dont show notification if there is no recipes referred by the post.
48
-		if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) {
49
-			return false;
50
-		}
51
-
52
-		$recipe_with_image_warnings = $this->get_warnings( $post_id );
53
-
54
-		if ( count( $recipe_with_image_warnings ) > 0 ) {
55
-			// Show notification.
56
-			?>
13
+    /**
14
+     * @var Recipe_Maker_Validation_Service
15
+     */
16
+    private $recipe_maker_validation_service;
17
+
18
+    public function __construct( $recipe_maker_validation_service ) {
19
+        $this->recipe_maker_validation_service = $recipe_maker_validation_service;
20
+        /**
21
+         * Filter: wl_feature__enable__notices.
22
+         *
23
+         * @param bool whether the notices needs to be enabled or not.
24
+         *
25
+         * @return bool
26
+         * @since 3.27.6
27
+         */
28
+        if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
29
+            add_action( 'admin_notices', array( $this, 'display_image_size_warning' ) );
30
+        }
31
+    }
32
+
33
+    /**
34
+     * Show the warning after applying the conditions.
35
+     */
36
+    public function display_image_size_warning() {
37
+
38
+        // Check if we are on the post.
39
+        if ( ! get_post() instanceof \WP_Post ) {
40
+            return false;
41
+        }
42
+        if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
43
+            return false;
44
+        }
45
+        $post_id = get_the_ID();
46
+
47
+        // Dont show notification if there is no recipes referred by the post.
48
+        if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) {
49
+            return false;
50
+        }
51
+
52
+        $recipe_with_image_warnings = $this->get_warnings( $post_id );
53
+
54
+        if ( count( $recipe_with_image_warnings ) > 0 ) {
55
+            // Show notification.
56
+            ?>
57 57
             <div class="notice notice-warning is-dismissible">
58 58
                 <p><?php echo __( 'The following recipes didnt have minimum image size of 1200 x 1200 px', 'wordlift' ); ?></p>
59 59
                 <ol>
60 60
 					<?php
61
-					foreach ( $recipe_with_image_warnings as $post_id ) {
62
-						echo "<li>" . get_the_title( $post_id ) . "</li>";
63
-					}
64
-					?>
61
+                    foreach ( $recipe_with_image_warnings as $post_id ) {
62
+                        echo "<li>" . get_the_title( $post_id ) . "</li>";
63
+                    }
64
+                    ?>
65 65
                 </ol>
66 66
             </div>
67 67
 			<?php
68
-		}
68
+        }
69 69
 
70
-	}
70
+    }
71 71
 
72
-	/**
73
-	 * @param $post_id
74
-	 *
75
-	 * @return array
76
-	 */
77
-	private function get_warnings( $post_id ) {
72
+    /**
73
+     * @param $post_id
74
+     *
75
+     * @return array
76
+     */
77
+    private function get_warnings( $post_id ) {
78 78
 
79
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
79
+        $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
80 80
 
81
-		// Dont show duplicate warnings.
82
-		$recipe_ids = array_unique( $recipe_ids );
81
+        // Dont show duplicate warnings.
82
+        $recipe_ids = array_unique( $recipe_ids );
83 83
 
84
-		$recipe_with_image_warnings = array();
84
+        $recipe_with_image_warnings = array();
85 85
 
86
-		foreach ( $recipe_ids as $recipe_id ) {
87
-			$recipe     = \WPRM_Recipe_Manager::get_recipe( $recipe_id );
86
+        foreach ( $recipe_ids as $recipe_id ) {
87
+            $recipe     = \WPRM_Recipe_Manager::get_recipe( $recipe_id );
88 88
             if (  ! $recipe ) {
89 89
                 continue;
90 90
             }
91
-			$image_id   = $recipe->image_id();
92
-			$image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) );
93
-			if ( ! is_array( $image_data ) ) {
94
-				continue;
95
-			}
96
-			$image_width  = array_key_exists( 1, $image_data ) ? $image_data [1] : false;
97
-			$image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false;
98
-			if ( ! ( $image_height && $image_width ) ) {
99
-				continue;
100
-			}
101
-
102
-			if ( $image_height < 1200 || $image_width < 1200 ) {
103
-				// Image size not present in 1200 * 1200, show a warning.
104
-				$recipe_with_image_warnings[] = $recipe_id;
105
-			}
106
-		}
107
-
108
-		return $recipe_with_image_warnings;
109
-	}
91
+            $image_id   = $recipe->image_id();
92
+            $image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) );
93
+            if ( ! is_array( $image_data ) ) {
94
+                continue;
95
+            }
96
+            $image_width  = array_key_exists( 1, $image_data ) ? $image_data [1] : false;
97
+            $image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false;
98
+            if ( ! ( $image_height && $image_width ) ) {
99
+                continue;
100
+            }
101
+
102
+            if ( $image_height < 1200 || $image_width < 1200 ) {
103
+                // Image size not present in 1200 * 1200, show a warning.
104
+                $recipe_with_image_warnings[] = $recipe_id;
105
+            }
106
+        }
107
+
108
+        return $recipe_with_image_warnings;
109
+    }
110 110
 
111 111
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	private $recipe_maker_validation_service;
17 17
 
18
-	public function __construct( $recipe_maker_validation_service ) {
18
+	public function __construct($recipe_maker_validation_service) {
19 19
 		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
20 20
 		/**
21 21
 		 * Filter: wl_feature__enable__notices.
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 		 * @return bool
26 26
 		 * @since 3.27.6
27 27
 		 */
28
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
29
-			add_action( 'admin_notices', array( $this, 'display_image_size_warning' ) );
28
+		if (apply_filters('wl_feature__enable__notices', true)) {
29
+			add_action('admin_notices', array($this, 'display_image_size_warning'));
30 30
 		}
31 31
 	}
32 32
 
@@ -36,30 +36,30 @@  discard block
 block discarded – undo
36 36
 	public function display_image_size_warning() {
37 37
 
38 38
 		// Check if we are on the post.
39
-		if ( ! get_post() instanceof \WP_Post ) {
39
+		if ( ! get_post() instanceof \WP_Post) {
40 40
 			return false;
41 41
 		}
42
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
42
+		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) {
43 43
 			return false;
44 44
 		}
45 45
 		$post_id = get_the_ID();
46 46
 
47 47
 		// Dont show notification if there is no recipes referred by the post.
48
-		if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) {
48
+		if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post($post_id)) {
49 49
 			return false;
50 50
 		}
51 51
 
52
-		$recipe_with_image_warnings = $this->get_warnings( $post_id );
52
+		$recipe_with_image_warnings = $this->get_warnings($post_id);
53 53
 
54
-		if ( count( $recipe_with_image_warnings ) > 0 ) {
54
+		if (count($recipe_with_image_warnings) > 0) {
55 55
 			// Show notification.
56 56
 			?>
57 57
             <div class="notice notice-warning is-dismissible">
58
-                <p><?php echo __( 'The following recipes didnt have minimum image size of 1200 x 1200 px', 'wordlift' ); ?></p>
58
+                <p><?php echo __('The following recipes didnt have minimum image size of 1200 x 1200 px', 'wordlift'); ?></p>
59 59
                 <ol>
60 60
 					<?php
61
-					foreach ( $recipe_with_image_warnings as $post_id ) {
62
-						echo "<li>" . get_the_title( $post_id ) . "</li>";
61
+					foreach ($recipe_with_image_warnings as $post_id) {
62
+						echo "<li>".get_the_title($post_id)."</li>";
63 63
 					}
64 64
 					?>
65 65
                 </ol>
@@ -74,32 +74,32 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return array
76 76
 	 */
77
-	private function get_warnings( $post_id ) {
77
+	private function get_warnings($post_id) {
78 78
 
79
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
79
+		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post($post_id);
80 80
 
81 81
 		// Dont show duplicate warnings.
82
-		$recipe_ids = array_unique( $recipe_ids );
82
+		$recipe_ids = array_unique($recipe_ids);
83 83
 
84 84
 		$recipe_with_image_warnings = array();
85 85
 
86
-		foreach ( $recipe_ids as $recipe_id ) {
87
-			$recipe     = \WPRM_Recipe_Manager::get_recipe( $recipe_id );
88
-            if (  ! $recipe ) {
86
+		foreach ($recipe_ids as $recipe_id) {
87
+			$recipe = \WPRM_Recipe_Manager::get_recipe($recipe_id);
88
+            if ( ! $recipe) {
89 89
                 continue;
90 90
             }
91 91
 			$image_id   = $recipe->image_id();
92
-			$image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) );
93
-			if ( ! is_array( $image_data ) ) {
92
+			$image_data = wp_get_attachment_image_src($image_id, array(1200, 1200));
93
+			if ( ! is_array($image_data)) {
94 94
 				continue;
95 95
 			}
96
-			$image_width  = array_key_exists( 1, $image_data ) ? $image_data [1] : false;
97
-			$image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false;
98
-			if ( ! ( $image_height && $image_width ) ) {
96
+			$image_width  = array_key_exists(1, $image_data) ? $image_data [1] : false;
97
+			$image_height = array_key_exists(2, $image_data) ? $image_data [2] : false;
98
+			if ( ! ($image_height && $image_width)) {
99 99
 				continue;
100 100
 			}
101 101
 
102
-			if ( $image_height < 1200 || $image_width < 1200 ) {
102
+			if ($image_height < 1200 || $image_width < 1200) {
103 103
 				// Image size not present in 1200 * 1200, show a warning.
104 104
 				$recipe_with_image_warnings[] = $recipe_id;
105 105
 			}
Please login to merge, or discard this patch.