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