Permalink
Browse files

only show imagehelper error messages if WP_DEBUG is set to true

  • Loading branch information...
Ville Pietarinen
Ville Pietarinen committed Dec 14, 2018
1 parent 88f24de commit 68362753acfbabf62689e6af56f8595d5f443132
Showing with 59 additions and 36 deletions.
  1. +5 −0 CHANGELOG.md
  2. +54 −36 helpers/image.php
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed
- Only show image helper error messages if WP_DEBUG is set to true

## [1.18.0] - 2018-10-23

### Added
@@ -28,19 +28,23 @@ public function output() {
// SRC also given.
if ( null !== $image_data['src'] ) {
return '<p><strong>Dustpress image helper error:</strong>
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Image id and custom src both given.
Only one of these parameters can be used.</em></p>';
}
return;
} else { // Only the ID given as the original image source.
if ( null === $image_data['size'] ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>No image size attribute given. When
using the ID, you have to give a registered size name to
the helper. </em></p>';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>No image size attribute given. When
using the ID, you have to give a registered size name to
the helper. </em></p>';
}
return;
} else { // ID and size given.
@@ -61,18 +65,21 @@ public function output() {
return $the_image_markup;
} else {
return '<p><strong>Dustpress image helper error:</strong>
<em>No image found from the database with the given id.</em></p>';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>No image found from the database with the given id.</em></p>';
}
return;
}
} else { // Custom responsive parameters are given.
// SRCSET exists but no SIZES attribute is given.
if ( null === $image_data['sizes'] ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Srcset exists but no sizes attribute is given.</em></p>';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Srcset exists but no sizes attribute is given.</em></p>';
}
return;
} else { // Both custom responsive parameters and the id is given.
@@ -86,27 +93,33 @@ public function output() {
// No SRC given either.
if ( null === $image_data['src'] ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Image id or custom src not given.
The helper needs at least one of these parameters.</em></p>';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Image id or custom src not given.
The helper needs at least one of these parameters.</em></p>';
}
return;
} else { // Only the SRC given as the original image source.
// When using the custom SRC, both SRCSET and SIZES need to be given.
if ( null === $image_data['srcset'] ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Srcset not given. Both the srcset and the sizes are
needed when using a custom src.</em></p>';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Srcset not given. Both the srcset and the sizes are
needed when using a custom src.</em></p>';
}
return;
}
// When using the custom SRC, both SRCSET and SIZES need to be given.
if ( null === $image_data['sizes'] ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Sizes not given. Both the srcset and the sizes are
needed when using a custom src.</em></p>';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Sizes not given. Both the srcset and the sizes are
needed when using a custom src.</em></p>';
}
return;
}
@@ -204,10 +217,11 @@ private function get_image_markup( $image_data ) {
'" src="' . $image_src . '"';
} else { // Else return an error.
return '<p><strong>Dustpress image helper error:</strong>
<em>No image found from the database with the given id.</em></p>';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>No image found from the database with the given id.</em></p>';
}
return;
}
}
@@ -228,9 +242,11 @@ private function get_image_markup( $image_data ) {
// Check that the srcset is given as an array.
if ( ! is_array( $sizes ) ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Given sizes attribute is not an array.</em></p>';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Given sizes attribute is not an array.</em></p>';
}
return;
}
@@ -247,9 +263,11 @@ private function get_image_markup( $image_data ) {
// Check that the srcset is given as an array.
if ( ! is_array( $srcset_array ) ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Given srcset attribute is not an array.</em></p>';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
return '<p><strong>Dustpress image helper error:</strong>
<em>Given srcset attribute is not an array.</em></p>';
}
return;
}

0 comments on commit 6836275

Please sign in to comment.