@@ -11,100 +11,100 @@ |
||
11 | 11 | */ |
12 | 12 | class Recipe_Maker_Warning { |
13 | 13 | |
14 | - /** |
|
15 | - * @var Recipe_Maker_Validation_Service |
|
16 | - */ |
|
17 | - private $recipe_maker_validation_service; |
|
18 | - |
|
19 | - public function __construct( $recipe_maker_validation_service ) { |
|
20 | - $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
|
21 | - |
|
22 | - add_action( 'wordlift_admin_notices', array( $this, 'display_image_size_warning' ) ); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Show the warning after applying the conditions. |
|
27 | - */ |
|
28 | - public function display_image_size_warning() { |
|
29 | - |
|
30 | - // Check if we are on the post. |
|
31 | - if ( ! get_post() instanceof \WP_Post ) { |
|
32 | - return false; |
|
33 | - } |
|
34 | - if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
35 | - return false; |
|
36 | - } |
|
37 | - $post_id = get_the_ID(); |
|
38 | - |
|
39 | - // Dont show notification if there is no recipes referred by the post. |
|
40 | - if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) { |
|
41 | - return false; |
|
42 | - } |
|
43 | - |
|
44 | - $warnings = $this->get_warnings( $post_id ); |
|
45 | - |
|
46 | - if ( count( $warnings ) > 0 ) { |
|
47 | - // Show notification. |
|
48 | - ?> |
|
14 | + /** |
|
15 | + * @var Recipe_Maker_Validation_Service |
|
16 | + */ |
|
17 | + private $recipe_maker_validation_service; |
|
18 | + |
|
19 | + public function __construct( $recipe_maker_validation_service ) { |
|
20 | + $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
|
21 | + |
|
22 | + add_action( 'wordlift_admin_notices', array( $this, 'display_image_size_warning' ) ); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Show the warning after applying the conditions. |
|
27 | + */ |
|
28 | + public function display_image_size_warning() { |
|
29 | + |
|
30 | + // Check if we are on the post. |
|
31 | + if ( ! get_post() instanceof \WP_Post ) { |
|
32 | + return false; |
|
33 | + } |
|
34 | + if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
35 | + return false; |
|
36 | + } |
|
37 | + $post_id = get_the_ID(); |
|
38 | + |
|
39 | + // Dont show notification if there is no recipes referred by the post. |
|
40 | + if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) { |
|
41 | + return false; |
|
42 | + } |
|
43 | + |
|
44 | + $warnings = $this->get_warnings( $post_id ); |
|
45 | + |
|
46 | + if ( count( $warnings ) > 0 ) { |
|
47 | + // Show notification. |
|
48 | + ?> |
|
49 | 49 | <div class="notice notice-warning is-dismissible"> |
50 | 50 | <h3><?php esc_html_e( 'WordLift', 'wordlift' ); ?></h3> |
51 | 51 | <p><?php esc_html_e( 'The following recipes didn\'t have minimum image size of 1200 x 1200 px', 'wordlift' ); ?></p> |
52 | 52 | <ol> |
53 | 53 | <?php |
54 | - foreach ( $warnings as $warning ) { |
|
55 | - $image_link = get_edit_post_link( $warning['image_id'] ); |
|
56 | - ?> |
|
54 | + foreach ( $warnings as $warning ) { |
|
55 | + $image_link = get_edit_post_link( $warning['image_id'] ); |
|
56 | + ?> |
|
57 | 57 | <li><a href="<?php echo esc_attr( $image_link ); ?>"><?php echo esc_html( get_the_title( $warning['recipe_id'] ) ); ?></a></li> |
58 | 58 | <?php |
59 | - } |
|
60 | - ?> |
|
59 | + } |
|
60 | + ?> |
|
61 | 61 | </ol> |
62 | 62 | </div> |
63 | 63 | <?php |
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param $post_id |
|
70 | - * |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - private function get_warnings( $post_id ) { |
|
74 | - |
|
75 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
76 | - |
|
77 | - // Dont show duplicate warnings. |
|
78 | - $recipe_ids = array_unique( $recipe_ids ); |
|
79 | - |
|
80 | - $recipe_with_image_warnings = array(); |
|
81 | - |
|
82 | - foreach ( $recipe_ids as $recipe_id ) { |
|
83 | - $recipe = \WPRM_Recipe_Manager::get_recipe( $recipe_id ); |
|
84 | - if ( ! $recipe ) { |
|
85 | - continue; |
|
86 | - } |
|
87 | - $image_id = $recipe->image_id(); |
|
88 | - $image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) ); |
|
89 | - if ( ! is_array( $image_data ) ) { |
|
90 | - continue; |
|
91 | - } |
|
92 | - $image_width = array_key_exists( 1, $image_data ) ? $image_data [1] : false; |
|
93 | - $image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false; |
|
94 | - if ( ! ( $image_height && $image_width ) ) { |
|
95 | - continue; |
|
96 | - } |
|
97 | - |
|
98 | - if ( $image_height < 1200 || $image_width < 1200 ) { |
|
99 | - // Image size not present in 1200 * 1200, show a warning. |
|
100 | - $recipe_with_image_warnings[] = array( |
|
101 | - 'recipe_id' => $recipe_id, |
|
102 | - 'image_id' => $image_id, |
|
103 | - ); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - return $recipe_with_image_warnings; |
|
108 | - } |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param $post_id |
|
70 | + * |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + private function get_warnings( $post_id ) { |
|
74 | + |
|
75 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
76 | + |
|
77 | + // Dont show duplicate warnings. |
|
78 | + $recipe_ids = array_unique( $recipe_ids ); |
|
79 | + |
|
80 | + $recipe_with_image_warnings = array(); |
|
81 | + |
|
82 | + foreach ( $recipe_ids as $recipe_id ) { |
|
83 | + $recipe = \WPRM_Recipe_Manager::get_recipe( $recipe_id ); |
|
84 | + if ( ! $recipe ) { |
|
85 | + continue; |
|
86 | + } |
|
87 | + $image_id = $recipe->image_id(); |
|
88 | + $image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) ); |
|
89 | + if ( ! is_array( $image_data ) ) { |
|
90 | + continue; |
|
91 | + } |
|
92 | + $image_width = array_key_exists( 1, $image_data ) ? $image_data [1] : false; |
|
93 | + $image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false; |
|
94 | + if ( ! ( $image_height && $image_width ) ) { |
|
95 | + continue; |
|
96 | + } |
|
97 | + |
|
98 | + if ( $image_height < 1200 || $image_width < 1200 ) { |
|
99 | + // Image size not present in 1200 * 1200, show a warning. |
|
100 | + $recipe_with_image_warnings[] = array( |
|
101 | + 'recipe_id' => $recipe_id, |
|
102 | + 'image_id' => $image_id, |
|
103 | + ); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + return $recipe_with_image_warnings; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | } |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | */ |
17 | 17 | private $recipe_maker_validation_service; |
18 | 18 | |
19 | - public function __construct( $recipe_maker_validation_service ) { |
|
19 | + public function __construct($recipe_maker_validation_service) { |
|
20 | 20 | $this->recipe_maker_validation_service = $recipe_maker_validation_service; |
21 | 21 | |
22 | - add_action( 'wordlift_admin_notices', array( $this, 'display_image_size_warning' ) ); |
|
22 | + add_action('wordlift_admin_notices', array($this, 'display_image_size_warning')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -28,33 +28,33 @@ discard block |
||
28 | 28 | public function display_image_size_warning() { |
29 | 29 | |
30 | 30 | // Check if we are on the post. |
31 | - if ( ! get_post() instanceof \WP_Post ) { |
|
31 | + if ( ! get_post() instanceof \WP_Post) { |
|
32 | 32 | return false; |
33 | 33 | } |
34 | - if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) { |
|
34 | + if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) { |
|
35 | 35 | return false; |
36 | 36 | } |
37 | 37 | $post_id = get_the_ID(); |
38 | 38 | |
39 | 39 | // Dont show notification if there is no recipes referred by the post. |
40 | - if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) { |
|
40 | + if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post($post_id)) { |
|
41 | 41 | return false; |
42 | 42 | } |
43 | 43 | |
44 | - $warnings = $this->get_warnings( $post_id ); |
|
44 | + $warnings = $this->get_warnings($post_id); |
|
45 | 45 | |
46 | - if ( count( $warnings ) > 0 ) { |
|
46 | + if (count($warnings) > 0) { |
|
47 | 47 | // Show notification. |
48 | 48 | ?> |
49 | 49 | <div class="notice notice-warning is-dismissible"> |
50 | - <h3><?php esc_html_e( 'WordLift', 'wordlift' ); ?></h3> |
|
51 | - <p><?php esc_html_e( 'The following recipes didn\'t have minimum image size of 1200 x 1200 px', 'wordlift' ); ?></p> |
|
50 | + <h3><?php esc_html_e('WordLift', 'wordlift'); ?></h3> |
|
51 | + <p><?php esc_html_e('The following recipes didn\'t have minimum image size of 1200 x 1200 px', 'wordlift'); ?></p> |
|
52 | 52 | <ol> |
53 | 53 | <?php |
54 | - foreach ( $warnings as $warning ) { |
|
55 | - $image_link = get_edit_post_link( $warning['image_id'] ); |
|
54 | + foreach ($warnings as $warning) { |
|
55 | + $image_link = get_edit_post_link($warning['image_id']); |
|
56 | 56 | ?> |
57 | - <li><a href="<?php echo esc_attr( $image_link ); ?>"><?php echo esc_html( get_the_title( $warning['recipe_id'] ) ); ?></a></li> |
|
57 | + <li><a href="<?php echo esc_attr($image_link); ?>"><?php echo esc_html(get_the_title($warning['recipe_id'])); ?></a></li> |
|
58 | 58 | <?php |
59 | 59 | } |
60 | 60 | ?> |
@@ -70,32 +70,32 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return array |
72 | 72 | */ |
73 | - private function get_warnings( $post_id ) { |
|
73 | + private function get_warnings($post_id) { |
|
74 | 74 | |
75 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id ); |
|
75 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post($post_id); |
|
76 | 76 | |
77 | 77 | // Dont show duplicate warnings. |
78 | - $recipe_ids = array_unique( $recipe_ids ); |
|
78 | + $recipe_ids = array_unique($recipe_ids); |
|
79 | 79 | |
80 | 80 | $recipe_with_image_warnings = array(); |
81 | 81 | |
82 | - foreach ( $recipe_ids as $recipe_id ) { |
|
83 | - $recipe = \WPRM_Recipe_Manager::get_recipe( $recipe_id ); |
|
84 | - if ( ! $recipe ) { |
|
82 | + foreach ($recipe_ids as $recipe_id) { |
|
83 | + $recipe = \WPRM_Recipe_Manager::get_recipe($recipe_id); |
|
84 | + if ( ! $recipe) { |
|
85 | 85 | continue; |
86 | 86 | } |
87 | 87 | $image_id = $recipe->image_id(); |
88 | - $image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) ); |
|
89 | - if ( ! is_array( $image_data ) ) { |
|
88 | + $image_data = wp_get_attachment_image_src($image_id, array(1200, 1200)); |
|
89 | + if ( ! is_array($image_data)) { |
|
90 | 90 | continue; |
91 | 91 | } |
92 | - $image_width = array_key_exists( 1, $image_data ) ? $image_data [1] : false; |
|
93 | - $image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false; |
|
94 | - if ( ! ( $image_height && $image_width ) ) { |
|
92 | + $image_width = array_key_exists(1, $image_data) ? $image_data [1] : false; |
|
93 | + $image_height = array_key_exists(2, $image_data) ? $image_data [2] : false; |
|
94 | + if ( ! ($image_height && $image_width)) { |
|
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - if ( $image_height < 1200 || $image_width < 1200 ) { |
|
98 | + if ($image_height < 1200 || $image_width < 1200) { |
|
99 | 99 | // Image size not present in 1200 * 1200, show a warning. |
100 | 100 | $recipe_with_image_warnings[] = array( |
101 | 101 | 'recipe_id' => $recipe_id, |