diff --git a/code-snippets.php b/code-snippets.php
index 134f111..5aa30ed 100644
--- a/code-snippets.php
+++ b/code-snippets.php
@@ -12,9 +12,11 @@
* Append the term images to content + excerpt.
*/
function mytheme_append_the_term_images( $content ) {
- return $content . apply_filters( 'taxonomy-images-list-the-terms', '', array(
- 'image_size' => 'detail',
- ) );
+ return $content . apply_filters(
+ 'taxonomy_images_list_the_terms', '', array(
+ 'image_size' => 'detail',
+ )
+ );
}
add_filter( 'the_content', 'mytheme_append_the_term_images' );
add_filter( 'the_excerpt', 'mytheme_append_the_term_images' );
@@ -34,47 +36,55 @@ function mytheme_append_the_term_images( $content ) {
/* Default */
-$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN' );
-print '
taxonomy-images-queried-term-image
';
-print '' . htmlentities( $img ) . '
';
+$img = apply_filters( 'taxonomy_images_queried_term_image', 'PLEASE INSTALL PLUGIN' );
+print 'taxonomy_images_queried_term_image
';
+print '' . esc_html( htmlenties( $img ) ) . '
';
/* Inside a yellow box */
-$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
- 'before' => '',
- 'after' => '
',
- ) );
-print 'taxonomy-images-queried-term-image - custom wrapper element.
';
-print '' . htmlentities( $img ) . '
';
+$img = apply_filters(
+ 'taxonomy_images_queried_term_image', 'PLEASE INSTALL PLUGIN', array(
+ 'before' => '',
+ 'after' => '
',
+ )
+);
+print 'taxonomy_images_queried_term_image - custom wrapper element.
';
+print '' . esc_html( htmlenties( $img ) )) . '
';
/* Medium Size */
-$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
- 'image_size' => 'medium',
- ) );
-print 'taxonomy-images-queried-term-image - medium image size
';
-print '' . htmlentities( $img ) . '
';
+$img = apply_filters(
+ 'taxonomy_images_queried_term_image', 'PLEASE INSTALL PLUGIN', array(
+ 'image_size' => 'medium',
+ )
+);
+print 'taxonomy_images_queried_term_image - medium image size
';
+print '' . esc_html( htmlenties( $img ) ) . '
';
/* Unrecognized size */
-$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
- 'image_size' => 'this-is-probably-not-a-real-image-size',
- ) );
-print 'taxonomy-images-queried-term-image - unknown image size
';
-print '' . htmlentities( $img ) . '
';
+$img = apply_filters(
+ 'taxonomy_images_queried_term_image', 'PLEASE INSTALL PLUGIN', array(
+ 'image_size' => 'this-is-probably-not-a-real-image-size',
+ )
+);
+print 'taxonomy_images_queried_term_image - unknown image size
';
+print '' . esc_html( htmlenties( $img ) ) . '
';
/* Custom attributes. */
-$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
- 'attr' => array(
- 'alt' => 'Custom alternative text',
- 'class' => 'my-class-list bunnies turtles',
- 'src' => 'this-is-where-the-image-lives.png',
- 'title' => 'Custom Title',
+$img = apply_filters(
+ 'taxonomy_images_queried_term_image', 'PLEASE INSTALL PLUGIN', array(
+ 'attr' => array(
+ 'alt' => 'Custom alternative text',
+ 'class' => 'my-class-list bunnies turtles',
+ 'src' => 'this-is-where-the-image-lives.png',
+ 'title' => 'Custom Title',
),
- ) );
-print 'taxonomy-images-queried-term-image - custom attributes
';
-print '' . htmlentities( $img ) . '
';
+ )
+);
+print 'taxonomy_images_queried_term_image - custom attributes
';
+print '' . esc_html( htmlenties( $img ) ) . '
';
@@ -88,10 +98,12 @@ function mytheme_append_the_term_images( $content ) {
* In the event that the Taxonomy Images plugin is not installed
* apply_filters() will return it's second parameter.
*/
-$img = apply_filters( 'taxonomy-images-queried-term-image-id', 'PLEASE INSTALL PLUGIN' );
+$img = apply_filters( 'taxonomy_images_queried_term_image_id', 'PLEASE INSTALL PLUGIN' );
-print 'taxonomy-images-queried-term-image-id
';
-print ''; var_dump( $img ); print '
';
+print 'taxonomy_images_queried_term_image_id
';
+print '';
+var_dump( $img );
+print '
';
@@ -106,10 +118,12 @@ function mytheme_append_the_term_images( $content ) {
* In the event that the Taxonomy Images plugin is not installed
* apply_filters() will return it's second parameter.
*/
-$img = apply_filters( 'taxonomy-images-queried-term-image-object', 'PLEASE INSTALL PLUGIN' );
+$img = apply_filters( 'taxonomy_images_queried_term_image_object', 'PLEASE INSTALL PLUGIN' );
-print 'taxonomy-images-queried-term-image-object
';
-print ''; var_dump( $img ); print '
';
+print 'taxonomy_images_queried_term_image_object
';
+print '';
+var_dump( $img );
+print '
';
@@ -127,25 +141,35 @@ function mytheme_append_the_term_images( $content ) {
/* Default */
-$img = apply_filters( 'taxonomy-images-queried-term-image-url', 'PLEASE INSTALL PLUGIN' );
-print 'taxonomy-images-queried-term-image-url - Default
';
-print ''; var_dump( $img ); print '
';
+$img = apply_filters( 'taxonomy_images_queried_term_image_url', 'PLEASE INSTALL PLUGIN' );
+print 'taxonomy_images_queried_term_image_url - Default
';
+print '';
+var_dump( $img );
+print '
';
/* Medium Size */
-$img = apply_filters( 'taxonomy-images-queried-term-image-url', 'PLEASE INSTALL PLUGIN', array(
- 'image_size' => 'medium'
- ) );
-print 'taxonomy-images-queried-term-image-url - Medium
';
-print ''; var_dump( $img ); print '
';
+$img = apply_filters(
+ 'taxonomy_images_queried_term_image_url', 'PLEASE INSTALL PLUGIN', array(
+ 'image_size' => 'medium',
+ )
+);
+print 'taxonomy_images_queried_term_image_url - Medium
';
+print '';
+var_dump( $img );
+print '
';
/* Unregistered Size */
-$img = apply_filters( 'taxonomy-images-queried-term-image-url', 'PLEASE INSTALL PLUGIN', array(
- 'image_size' => 'this-is-not-real-size-probably-I-hope'
- ) );
-print 'taxonomy-images-queried-term-image-url - Unregistered
';
-print ''; var_dump( $img ); print '
';
+$img = apply_filters(
+ 'taxonomy_images_queried_term_image_url', 'PLEASE INSTALL PLUGIN', array(
+ 'image_size' => 'this-is-not-real-size-probably-I-hope',
+ )
+);
+print 'taxonomy_images_queried_term_image_url - Unregistered
';
+print '';
+var_dump( $img );
+print '
';
@@ -163,22 +187,32 @@ function mytheme_append_the_term_images( $content ) {
/* Default */
-$img = apply_filters( 'taxonomy-images-queried-term-image-data', 'PLEASE INSTALL PLUGIN' );
-print 'taxonomy-images-queried-term-image-data - Default
';
-print ''; var_dump( $img ); print '
';
+$img = apply_filters( 'taxonomy_images_queried_term_image_data', 'PLEASE INSTALL PLUGIN' );
+print 'taxonomy_images_queried_term_image_data - Default
';
+print '';
+var_dump( $img );
+print '
';
/* Medium Size */
-$img = apply_filters( 'taxonomy-images-queried-term-image-data', 'PLEASE INSTALL PLUGIN', array(
- 'image_size' => 'medium'
- ) );
-print 'taxonomy-images-queried-term-image-data - Medium
';
-print ''; var_dump( $img ); print '
';
+$img = apply_filters(
+ 'taxonomy_images_queried_term_image_data', 'PLEASE INSTALL PLUGIN', array(
+ 'image_size' => 'medium',
+ )
+);
+print 'taxonomy_images_queried_term_image_data - Medium
';
+print '';
+var_dump( $img );
+print '
';
/* Unregistered Size */
-$img = apply_filters( 'taxonomy-images-queried-term-image-data', 'PLEASE INSTALL PLUGIN', array(
- 'image_size' => 'this-is-not-real-size-probably-I-hope'
- ) );
-print 'taxonomy-images-queried-term-image-data - Unregistered
';
-print ''; var_dump( $img ); print '
';
+$img = apply_filters(
+ 'taxonomy_images_queried_term_image_data', 'PLEASE INSTALL PLUGIN', array(
+ 'image_size' => 'this-is-not-real-size-probably-I-hope',
+ )
+);
+print 'taxonomy_images_queried_term_image_data - Unregistered
';
+print '';
+var_dump( $img );
+print '
';
diff --git a/deprecated.php b/deprecated.php
index 9dce9d0..cf6c153 100644
--- a/deprecated.php
+++ b/deprecated.php
@@ -6,13 +6,14 @@
* @return void
* @access private
*/
-function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) { // DEPRECATED
- $o = '';
+function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) {
+ // DEPRECATED
+ $o = '';
$defaults = array(
'taxonomy' => 'category',
'size' => 'detail',
- 'template' => 'list'
- );
+ 'template' => 'list',
+ );
extract( shortcode_atts( $defaults, $atts ) );
@@ -22,11 +23,12 @@ function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) { // DEP
return '';
}
- $terms = get_terms( $taxonomy );
- $associations = taxonomy_image_plugin_get_associations( $refresh = false );
+ $terms = get_terms( $taxonomy );
+ $refresh = false;
+ $associations = taxonomy_image_plugin_get_associations( $refresh );
if ( ! is_wp_error( $terms ) ) {
- foreach( (array) $terms as $term ) {
+ foreach ( (array) $terms as $term ) {
$url = get_term_link( $term, $term->taxonomy );
$title = apply_filters( 'the_title', $term->name );
$title_attr = esc_attr( $term->name . ' (' . $term->count . ')' );
@@ -34,20 +36,20 @@ function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) { // DEP
$img = '';
if ( array_key_exists( $term->term_taxonomy_id, $associations ) ) {
- $img = wp_get_attachment_image( $associations[$term->term_taxonomy_id], 'detail', false );
+ $img = wp_get_attachment_image( $associations[ $term->term_taxonomy_id ], 'detail', false );
}
- if( $template === 'grid' ) {
- $o.= "\n\t" . '';
- }
- else {
- $o.= "\n\t\t" . '' . $img . '';;
- $o.= "\n\t\t" . '';
- $o.= $description;
- $o.= "\n\t" . '';
- $o.= "\n";
+ if ( 'grid' === $template ) {
+ $o .= "\n\t" . '';
+ } else {
+ $o .= "\n\t\t" . '' . $img . '';
+ ;
+ $o .= "\n\t\t" . '';
+ $o .= $description;
+ $o .= "\n\t" . '';
+ $o .= "\n";
}
}
}
@@ -63,7 +65,7 @@ function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) { // DEP
*
* @access private This class is deprecated. Do not use!!!
*/
-class taxonomy_images_plugin {
+class Taxonomy_Images_Plugin {
public $settings = array();
public function __construct() {
$this->settings = taxonomy_image_plugin_get_associations();
@@ -73,7 +75,7 @@ public function get_thumb( $id ) {
return taxonomy_image_plugin_get_image_src( $id );
}
public function print_image_html( $size = 'medium', $term_tax_id = false, $title = true, $align = 'none' ) {
- print $this->get_image_html( $size, $term_tax_id, $title, $align );
+ print wp_kses_post( $this->get_image_html( $size, $term_tax_id, $title, $align ) );
}
public function get_image_html( $size = 'medium', $term_tax_id = false, $title = true, $align = 'none' ) {
$o = '';
@@ -82,8 +84,7 @@ public function get_image_html( $size = 'medium', $term_tax_id = false, $title =
$obj = $wp_query->get_queried_object();
if ( isset( $obj->term_taxonomy_id ) ) {
$term_tax_id = $obj->term_taxonomy_id;
- }
- else {
+ } else {
return false;
}
}
@@ -93,11 +94,11 @@ public function get_image_html( $size = 'medium', $term_tax_id = false, $title =
$alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
$attachment = get_post( $attachment_id );
/* Just in case an attachment was deleted, but there is still a record for it in this plugins settings. */
- if ( $attachment !== NULL ) {
+ if ( null !== $attachment ) {
$o = get_image_tag( $attachment_id, $alt, '', $align, $size );
}
}
return $o;
}
}
-$taxonomy_images_plugin = new taxonomy_images_plugin();
+$taxonomy_images_plugin = new Taxonomy_Images_Plugin();
diff --git a/public-filters.php b/public-filters.php
index b02d486..b396b03 100644
--- a/public-filters.php
+++ b/public-filters.php
@@ -18,15 +18,15 @@
*/
-add_filter( 'taxonomy-images-get-terms', 'taxonomy_images_plugin_get_terms', 10, 2 );
-add_filter( 'taxonomy-images-get-the-terms', 'taxonomy_images_plugin_get_the_terms', 10, 2 );
-add_filter( 'taxonomy-images-list-the-terms', 'taxonomy_images_plugin_list_the_terms', 10, 2 );
+add_filter( 'taxonomy_images_get_terms', 'taxonomy_images_plugin_get_terms', 10, 2 );
+add_filter( 'taxonomy_images_get_the_terms', 'taxonomy_images_plugin_get_the_terms', 10, 2 );
+add_filter( 'taxonomy_images_list_the_terms', 'taxonomy_images_plugin_list_the_terms', 10, 2 );
-add_filter( 'taxonomy-images-queried-term-image', 'taxonomy_images_plugin_get_queried_term_image', 10, 2 );
-add_filter( 'taxonomy-images-queried-term-image-data', 'taxonomy_images_plugin_get_queried_term_image_data', 10, 2 );
-add_filter( 'taxonomy-images-queried-term-image-id', 'taxonomy_images_plugin_get_queried_term_image_id' );
-add_filter( 'taxonomy-images-queried-term-image-object', 'taxonomy_images_plugin_get_queried_term_image_object' );
-add_filter( 'taxonomy-images-queried-term-image-url', 'taxonomy_images_plugin_get_queried_term_image_url', 10, 2 );
+add_filter( 'taxonomy_images_queried_term_image', 'taxonomy_images_plugin_get_queried_term_image', 10, 2 );
+add_filter( 'taxonomy_images_queried_term_image_data', 'taxonomy_images_plugin_get_queried_term_image_data', 10, 2 );
+add_filter( 'taxonomy_images_queried_term_image_id', 'taxonomy_images_plugin_get_queried_term_image_id' );
+add_filter( 'taxonomy_images_queried_term_image_object', 'taxonomy_images_plugin_get_queried_term_image_object' );
+add_filter( 'taxonomy_images_queried_term_image_url', 'taxonomy_images_plugin_get_queried_term_image_url', 10, 2 );
/**
@@ -63,21 +63,23 @@
* @param array Named arguments. Please see above for explantion.
* @return array List of term objects.
*
- * @access private Use the 'taxonomy-images-get-terms' filter.
+ * @access private Use the 'taxonomy_images_get_terms' filter.
* @since 0.7
*/
function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
- $filter = 'taxonomy-images-get-terms';
- if ( $filter !== current_filter() ) {
+ $filter = 'taxonomy_images_get_terms';
+ if ( current_filter() !== $filter ) {
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
}
- $args = wp_parse_args( $args, array(
- 'cache_images' => true,
- 'having_images' => true,
- 'taxonomy' => 'category',
- 'term_args' => array(),
- ) );
+ $args = wp_parse_args(
+ $args, array(
+ 'cache_images' => true,
+ 'having_images' => true,
+ 'taxonomy' => 'category',
+ 'term_args' => array(),
+ )
+ );
$args['taxonomy'] = explode( ',', $args['taxonomy'] );
$args['taxonomy'] = array_map( 'trim', $args['taxonomy'] );
@@ -98,15 +100,15 @@ function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
return array();
}
- $image_ids = array();
+ $image_ids = array();
$terms_with_images = array();
foreach ( (array) $terms as $key => $term ) {
- $terms[$key]->image_id = 0;
+ $terms[ $key ]->image_id = 0;
if ( array_key_exists( $term->term_taxonomy_id, $assoc ) ) {
- $terms[$key]->image_id = $assoc[$term->term_taxonomy_id];
- $image_ids[] = $assoc[$term->term_taxonomy_id];
+ $terms[ $key ]->image_id = $assoc[ $term->term_taxonomy_id ];
+ $image_ids[] = $assoc[ $term->term_taxonomy_id ];
if ( ! empty( $args['having_images'] ) ) {
- $terms_with_images[] = $terms[$key];
+ $terms_with_images[] = $terms[ $key ];
}
}
}
@@ -155,20 +157,22 @@ function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
* @param array Named arguments. Please see above for explantion.
* @return array List of term objects. Empty array if none were found.
*
- * @access private Use the 'taxonomy-images-get-the-terms' filter.
+ * @access private Use the 'taxonomy_images_get_the_terms' filter.
* @since 0.7
*/
function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
- $filter = 'taxonomy-images-get-the-terms';
- if ( $filter !== current_filter() ) {
+ $filter = 'taxonomy_images_get_the_terms';
+ if ( current_filter() !== $filter ) {
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
}
- $args = wp_parse_args( $args, array(
- 'having_images' => true,
- 'post_id' => 0,
- 'taxonomy' => 'category',
- ) );
+ $args = wp_parse_args(
+ $args, array(
+ 'having_images' => true,
+ 'post_id' => 0,
+ 'taxonomy' => 'category',
+ )
+ );
if ( ! taxonomy_image_plugin_check_taxonomy( $args['taxonomy'], $filter ) ) {
return array();
@@ -192,11 +196,11 @@ function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
$terms_with_images = array();
foreach ( (array) $terms as $key => $term ) {
- $terms[$key]->image_id = 0;
+ $terms[ $key ]->image_id = 0;
if ( array_key_exists( $term->term_taxonomy_id, $assoc ) ) {
- $terms[$key]->image_id = $assoc[$term->term_taxonomy_id];
+ $terms[ $key ]->image_id = $assoc[ $term->term_taxonomy_id ];
if ( ! empty( $args['having_images'] ) ) {
- $terms_with_images[] = $terms[$key];
+ $terms_with_images[] = $terms[ $key ];
}
}
}
@@ -245,24 +249,26 @@ function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
* @param array Named arguments. Please see above for explantion.
* @return string HTML markup.
*
- * @access private Use the 'taxonomy-images-list-the-terms' filter.
+ * @access private Use the 'taxonomy_images_list_the_terms' filter.
* @since 0.7
*/
function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
- $filter = 'taxonomy-images-list-the-terms';
- if ( $filter !== current_filter() ) {
+ $filter = 'taxonomy_images_list_the_terms';
+ if ( current_filter() !== $filter ) {
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
}
- $args = wp_parse_args( $args, array(
- 'after' => '',
- 'after_image' => '',
- 'before' => '',
- 'before_image' => '- ',
- 'image_size' => 'thumbnail',
- 'post_id' => 0,
- 'taxonomy' => 'category',
- ) );
+ $args = wp_parse_args(
+ $args, array(
+ 'after' => '
',
+ 'after_image' => '',
+ 'before' => '',
+ 'before_image' => '- ',
+ 'image_size' => 'thumbnail',
+ 'post_id' => 0,
+ 'taxonomy' => 'category',
+ )
+ );
$args['having_images'] = true;
@@ -270,20 +276,20 @@ function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
return '';
}
- $terms = apply_filters( 'taxonomy-images-get-the-terms', '', $args );
+ $terms = apply_filters( 'taxonomy_images_get_the_terms', '', $args );
if ( empty( $terms ) ) {
return '';
}
$output = '';
- foreach( $terms as $term ) {
+ foreach ( $terms as $term ) {
if ( ! isset( $term->image_id ) ) {
continue;
}
$image = wp_get_attachment_image( $term->image_id, $args['image_size'] );
if ( ! empty( $image ) ) {
- $output .= $args['before_image'] . '' . $image .'' . $args['after_image'];
+ $output .= $args['before_image'] . '' . $image . '' . $args['after_image'];
}
}
@@ -319,29 +325,31 @@ function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
* @param array Named array of arguments.
* @return string HTML markup for the associated image.
*
- * @access private Use the 'taxonomy-images-queried-term-image' filter.
+ * @access private Use the 'taxonomy_images_queried_term_image' filter.
* @since 0.7
*/
function taxonomy_images_plugin_get_queried_term_image( $default, $args = array() ) {
- $filter = 'taxonomy-images-queried-term-image';
- if ( $filter !== current_filter() ) {
+ $filter = 'taxonomy_images_queried_term_image';
+ if ( current_filter() !== $filter ) {
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
}
- $args = wp_parse_args( $args, array(
- 'after' => '',
- 'attr' => array(),
- 'before' => '',
- 'image_size' => 'thumbnail',
- ) );
+ $args = wp_parse_args(
+ $args, array(
+ 'after' => '',
+ 'attr' => array(),
+ 'before' => '',
+ 'image_size' => 'thumbnail',
+ )
+ );
- $ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
+ $id = apply_filters( 'taxonomy_images_queried_term_image_id', 0 );
- if ( empty( $ID ) ) {
+ if ( empty( $id ) ) {
return '';
}
- $html = wp_get_attachment_image( $ID, $args['image_size'], false, $args['attr'] );
+ $html = wp_get_attachment_image( $id, $args['image_size'], false, $args['attr'] );
if ( empty( $html ) ) {
return '';
@@ -364,17 +372,17 @@ function taxonomy_images_plugin_get_queried_term_image( $default, $args = array(
*
* This function should never be called directly in any file
* however it may be access in any template file via the
- * 'taxonomy-images-queried-term-image-id' filter.
+ * 'taxonomy_images_queried_term_image_id' filter.
*
* @param mixed Default value for apply_filters() to return. Unused.
* @return int Image attachment's ID.
*
- * @access private Use the 'taxonomy-images-queried-term-image-id' filter.
+ * @access private Use the 'taxonomy_images_queried_term_image_id' filter.
* @since 0.7
*/
function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
- $filter = 'taxonomy-images-queried-term-image-id';
- if ( $filter !== current_filter() ) {
+ $filter = 'taxonomy_images_queried_term_image_id';
+ if ( current_filter() !== $filter ) {
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
}
@@ -382,11 +390,14 @@ function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
/* Return early is we are not in a term archive. */
if ( ! isset( $obj->term_taxonomy_id ) ) {
- trigger_error( sprintf( esc_html__( '%1$s is not a property of the current queried object. This usually happens when the %2$s filter is used in an unsupported template file. This filter has been designed to work in taxonomy archives which are traditionally served by one of the following template files: category.php, tag.php or taxonomy.php. Learn more about %3$s.', 'taxonomy-images' ),
- '
' . esc_html__( 'term_taxonomy_id', 'taxonomy-images' ) . '',
- '' . esc_html( $filter ) . '',
- '' . esc_html( 'template hierarchy', 'taxonomy-images' ) . ''
- ) );
+ trigger_error(
+ sprintf(
+ esc_html__( '%1$s is not a property of the current queried object. This usually happens when the %2$s filter is used in an unsupported template file. This filter has been designed to work in taxonomy archives which are traditionally served by one of the following template files: category.php, tag.php or taxonomy.php. Learn more about %3$s.', 'taxonomy-images' ),
+ '' . esc_html__( 'term_taxonomy_id', 'taxonomy-images' ) . '',
+ '' . esc_html( $filter ) . '',
+ '' . esc_html( 'template hierarchy', 'taxonomy-images' ) . ''
+ )
+ );
return 0;
}
@@ -395,14 +406,14 @@ function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
}
$associations = taxonomy_image_plugin_get_associations();
- $tt_id = absint( $obj->term_taxonomy_id );
+ $tt_id = absint( $obj->term_taxonomy_id );
- $ID = 0;
+ $id = 0;
if ( array_key_exists( $tt_id, $associations ) ) {
- $ID = absint( $associations[$tt_id] );
+ $id = absint( $associations[ $tt_id ] );
}
- return $ID;
+ return $id;
}
@@ -419,25 +430,25 @@ function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
*
* This function should never be called directly in any file
* however it may be access in any template file via the
- * 'taxonomy-images-queried-term-image' filter.
+ * 'taxonomy_images_queried_term_image' filter.
*
* @param mixed Default value for apply_filters() to return. Unused.
* @return stdClass WordPress Post object.
*
- * @access private Use the 'taxonomy-images-queried-term-image-object' filter.
+ * @access private Use the 'taxonomy_images_queried_term_image_object' filter.
* @since 0.7
*/
function taxonomy_images_plugin_get_queried_term_image_object( $default ) {
- $filter = 'taxonomy-images-queried-term-image-object';
- if ( $filter !== current_filter() ) {
+ $filter = 'taxonomy_images_queried_term_image_object';
+ if ( current_filter() !== $filter ) {
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
}
- $ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
+ $id = apply_filters( 'taxonomy_images_queried_term_image_id', 0 );
$image = new stdClass;
- if ( ! empty( $ID ) ) {
- $image = get_post( $ID );
+ if ( ! empty( $id ) ) {
+ $image = get_post( $id );
}
return $image;
}
@@ -464,20 +475,22 @@ function taxonomy_images_plugin_get_queried_term_image_object( $default ) {
* @param array Named Arguments.
* @return string Image URL.
*
- * @access private Use the 'taxonomy-images-queried-term-image-url' filter.
+ * @access private Use the 'taxonomy_images_queried_term_image_url' filter.
* @since 0.7
*/
function taxonomy_images_plugin_get_queried_term_image_url( $default, $args = array() ) {
- $filter = 'taxonomy-images-queried-term-image-url';
- if ( $filter !== current_filter() ) {
+ $filter = 'taxonomy_images_queried_term_image_url';
+ if ( current_filter() !== $filter ) {
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
}
- $args = wp_parse_args( $args, array(
- 'image_size' => 'thumbnail',
- ) );
+ $args = wp_parse_args(
+ $args, array(
+ 'image_size' => 'thumbnail',
+ )
+ );
- $data = apply_filters( 'taxonomy-images-queried-term-image-data', array(), $args );
+ $data = apply_filters( 'taxonomy_images_queried_term_image_data', array(), $args );
$url = '';
if ( isset( $data['url'] ) ) {
@@ -509,30 +522,32 @@ function taxonomy_images_plugin_get_queried_term_image_url( $default, $args = ar
* @param array Named Arguments.
* @return array Image data: url, width and height.
*
- * @access private Use the 'taxonomy-images-queried-term-image-data' filter.
+ * @access private Use the 'taxonomy_images_queried_term_image_data' filter.
* @since 0.7
* @alter 0.7.2
*/
function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = array() ) {
- $filter = 'taxonomy-images-queried-term-image-data';
- if ( $filter !== current_filter() ) {
+ $filter = 'taxonomy_images_queried_term_image_data';
+ if ( current_filter() !== $filter ) {
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
}
- $args = wp_parse_args( $args, array(
- 'image_size' => 'thumbnail',
- ) );
+ $args = wp_parse_args(
+ $args, array(
+ 'image_size' => 'thumbnail',
+ )
+ );
- $ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
+ $id = apply_filters( 'taxonomy_images_queried_term_image_id', 0 );
- if ( empty( $ID ) ) {
+ if ( empty( $id ) ) {
return array();
}
$data = array();
- if ( in_array( $args['image_size'], array( 'full', 'fullsize' ) ) ) {
- $src = wp_get_attachment_image_src( $ID, 'full' );
+ if ( in_array( $args['image_size'], array( 'full', 'fullsize' ), true ) ) {
+ $src = wp_get_attachment_image_src( $id, 'full' );
if ( isset( $src[0] ) ) {
$data['url'] = $src[0];
@@ -543,9 +558,8 @@ function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = a
if ( isset( $src[2] ) ) {
$data['height'] = $src[2];
}
- }
- else {
- $data = image_get_intermediate_size( $ID, $args['image_size'] );
+ } else {
+ $data = image_get_intermediate_size( $id, $args['image_size'] );
}
if ( ! empty( $data ) ) {
diff --git a/taxonomy-images.php b/taxonomy-images.php
index ff5312c..8df59b8 100644
--- a/taxonomy-images.php
+++ b/taxonomy-images.php
@@ -69,7 +69,7 @@ function taxonomy_image_plugin_url( $file = '' ) {
function taxonomy_image_plugin_detail_image_size() {
return array(
'name' => 'detail',
- 'size' => array( 75, 75, true )
+ 'size' => array( 75, 75, true ),
);
}
@@ -123,17 +123,17 @@ function taxonomy_image_plugin_modal_button( $fields, $post ) {
$o = '';
- $o.= '' . sprintf( esc_html__( 'Associate with %1$s', 'taxonomy-images' ), '' . esc_html__( 'this term', 'taxonomy-images' ) . '' ) . '';
+ $o .= '' . sprintf( esc_html__( 'Associate with %1$s', 'taxonomy-images' ), '' . esc_html__( 'this term', 'taxonomy-images' ) . '' ) . '';
- $o.= '' . sprintf( esc_html__( 'Remove association with %1$s', 'taxonomy-images' ), '' . esc_html__( 'this term', 'taxonomy-images' ) . '' ) . '';
+ $o .= '' . sprintf( esc_html__( 'Remove association with %1$s', 'taxonomy-images' ), '' . esc_html__( 'this term', 'taxonomy-images' ) . '' ) . '';
- $o.= '';
+ $o .= '';
- $o.= '';
+ $o .= '';
- $o.= '';
+ $o .= '';
- $o.= '
';
+ $o .= '';
$fields['image-size']['extra_rows']['taxonomy-image-plugin-button']['html'] = $o;
}
@@ -161,8 +161,9 @@ function taxonomy_image_plugin_get_image_src( $id ) {
/* Return url to custom intermediate size if it exists. */
$img = image_get_intermediate_size( $id, $detail['name'] );
- if ( isset( $img['url'] ) )
+ if ( isset( $img['url'] ) ) {
return $img['url'];
+ }
/* Detail image does not exist, attempt to create it. */
$wp_upload_dir = wp_upload_dir();
@@ -173,11 +174,12 @@ function taxonomy_image_plugin_get_image_src( $id ) {
if ( is_file( $path ) ) {
/* Attempt to create a new downsized version of the original image. */
- $new = image_resize( $path,
+ $new = image_resize(
+ $path,
$detail['size'][0],
$detail['size'][1],
$detail['size'][2]
- );
+ );
/* Image creation successful. Generate and cache image metadata. Return url. */
if ( ! is_wp_error( $new ) ) {
@@ -193,13 +195,15 @@ function taxonomy_image_plugin_get_image_src( $id ) {
/* Custom intermediate size cannot be created, try for thumbnail. */
$img = image_get_intermediate_size( $id, 'thumbnail' );
- if ( isset( $img['url'] ) )
+ if ( isset( $img['url'] ) ) {
return $img['url'];
+ }
/* Thumbnail cannot be found, try fullsize. */
$url = wp_get_attachment_url( $id );
- if ( ! empty( $url ) )
+ if ( ! empty( $url ) ) {
return $url;
+ }
/*
* No image can be found.
@@ -212,7 +216,7 @@ function taxonomy_image_plugin_get_image_src( $id ) {
$assoc = taxonomy_image_plugin_get_associations();
foreach ( $assoc as $term => $img ) {
if ( $img === $id ) {
- unset( $assoc[$term] );
+ unset( $assoc[ $term ] );
}
}
update_option( 'taxonomy_image_plugin', $assoc );
@@ -243,8 +247,9 @@ function taxonomy_image_plugin_sanitize_associations( $associations ) {
foreach ( (array) $associations as $tt_id => $im_id ) {
$tt_id = absint( $tt_id );
$im_id = absint( $im_id );
- if ( 0 < $tt_id && 0 < $im_id )
- $o[$tt_id] = $im_id;
+ if ( 0 < $tt_id && 0 < $im_id ) {
+ $o[ $tt_id ] = $im_id;
+ }
}
return $o;
}
@@ -268,8 +273,9 @@ function taxonomy_image_plugin_settings_sanitize( $dirty ) {
if ( isset( $dirty['taxonomies'] ) ) {
$taxonomies = get_taxonomies();
foreach ( (array) $dirty['taxonomies'] as $taxonomy ) {
- if ( in_array( $taxonomy, $taxonomies ) )
+ if ( in_array( $taxonomy, $taxonomies, true ) ) {
$clean['taxonomies'][] = $taxonomy;
+ }
}
}
@@ -389,26 +395,34 @@ function taxonomy_image_plugin_settings_page() {
* @access private
*/
function taxonomy_image_plugin_control_taxonomies() {
- $settings = get_option( 'taxonomy_image_plugin_settings' );
+ $settings = get_option( 'taxonomy_image_plugin_settings' );
$taxonomies = get_taxonomies( array(), 'objects' );
foreach ( (array) $taxonomies as $taxonomy ) {
- if ( ! isset( $taxonomy->name ) )
+ if ( ! isset( $taxonomy->name ) ) {
continue;
+ }
- if ( ! isset( $taxonomy->label ) )
+ if ( ! isset( $taxonomy->label ) ) {
continue;
+ }
- if ( ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) )
+ if ( ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) ) {
continue;
+ }
$id = 'taxonomy-images-' . $taxonomy->name;
- $checked = '';
- if ( isset( $settings['taxonomies'] ) && in_array( $taxonomy->name, (array) $settings['taxonomies'] ) )
- $checked = ' checked="checked"';
+ $checked = false;
+ if ( isset( $settings['taxonomies'] ) && in_array( $taxonomy->name, (array) $settings['taxonomies'], true ) ) {
+ $checked = true;
+ }
print "\n" . '';
}
}
@@ -424,12 +438,14 @@ function taxonomy_image_plugin_control_taxonomies() {
*/
function taxonomy_image_plugin_json_response( $args ) {
/* translators: An ajax request has failed for an unknown reason. */
- $response = wp_parse_args( $args, array(
- 'status' => 'bad',
- 'why' => esc_html__( 'Unknown error encountered', 'taxonomy-images' )
- ) );
+ $response = wp_parse_args(
+ $args, array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'Unknown error encountered', 'taxonomy-images' ),
+ )
+ );
header( 'Content-type: application/jsonrequest' );
- print json_encode( $response );
+ print wp_json_encode( $response );
exit;
}
@@ -446,21 +462,24 @@ function taxonomy_image_plugin_json_response( $args ) {
*/
function taxonomy_image_plugin_get_term_info( $tt_id ) {
static $cache = array();
- if ( isset( $cache[$tt_id] ) ) {
- return $cache[$tt_id];
+ if ( isset( $cache[ $tt_id ] ) ) {
+ return $cache[ $tt_id ];
}
global $wpdb;
$data = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d LIMIT 1", $tt_id ) );
- if ( isset( $data[0]->term_id ) )
- $cache[$tt_id]['term_id'] = absint( $data[0]->term_id );
+ if ( isset( $data[0]->term_id ) ) {
+ $cache[ $tt_id ]['term_id'] = absint( $data[0]->term_id );
+ }
- if ( isset( $data[0]->taxonomy ) )
- $cache[$tt_id]['taxonomy'] = sanitize_title_with_dashes( $data[0]->taxonomy );
+ if ( isset( $data[0]->taxonomy ) ) {
+ $cache[ $tt_id ]['taxonomy'] = sanitize_title_with_dashes( $data[0]->taxonomy );
+ }
- if ( isset( $cache[$tt_id] ) )
- return $cache[$tt_id];
+ if ( isset( $cache[ $tt_id ] ) ) {
+ return $cache[ $tt_id ];
+ }
return array();
}
@@ -479,12 +498,14 @@ function taxonomy_image_plugin_get_term_info( $tt_id ) {
*/
function taxonomy_image_plugin_check_permissions( $tt_id ) {
$data = taxonomy_image_plugin_get_term_info( $tt_id );
- if ( ! isset( $data['taxonomy'] ) )
+ if ( ! isset( $data['taxonomy'] ) ) {
return false;
+ }
$taxonomy = get_taxonomy( $data['taxonomy'] );
- if ( ! isset( $taxonomy->cap->edit_terms ) )
+ if ( ! isset( $taxonomy->cap->edit_terms ) ) {
return false;
+ }
return current_user_can( $taxonomy->cap->edit_terms );
}
@@ -498,71 +519,88 @@ function taxonomy_image_plugin_check_permissions( $tt_id ) {
* @access private
*/
function taxonomy_image_plugin_create_association() {
- if ( ! isset( $_POST['tt_id'] ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
- ) );
+ if ( ! isset( $_POST['tt_id'] ) ) { // input var ok
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
+ )
+ );
}
- $tt_id = absint( $_POST['tt_id'] );
+ $tt_id = absint( $_POST['tt_id'] ); // input var ok
if ( empty( $tt_id ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
- ) );
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
+ )
+ );
}
if ( ! taxonomy_image_plugin_check_permissions( $tt_id ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
- ) );
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
+ )
+ );
}
- if ( ! isset( $_POST['wp_nonce'] ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'No nonce included.', 'taxonomy-images' ),
- ) );
+ if ( ! isset( $_POST['wp_nonce'] ) ) { // input var ok
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'No nonce included.', 'taxonomy-images' ),
+ )
+ );
}
- if ( ! wp_verify_nonce( $_POST['wp_nonce'], 'taxonomy-image-plugin-create-association' ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
- ) );
+ if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wp_nonce'] ) ), 'taxonomy-image-plugin-create-association' ) ) { // input var ok
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
+ )
+ );
}
- if ( ! isset( $_POST['attachment_id'] ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'Image id not sent', 'taxonomy-images' )
- ) );
+ if ( ! isset( $_POST['attachment_id'] ) ) { // input var ok
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'Image id not sent', 'taxonomy-images' ),
+ )
+ );
}
- $image_id = absint( $_POST['attachment_id'] );
+ $image_id = absint( $_POST['attachment_id'] ); // input var ok
if ( empty( $image_id ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'Image id is not a positive integer', 'taxonomy-images' )
- ) );
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'Image id is not a positive integer', 'taxonomy-images' ),
+ )
+ );
}
- $assoc = taxonomy_image_plugin_get_associations();
- $assoc[$tt_id] = $image_id;
+ $assoc = taxonomy_image_plugin_get_associations();
+ $assoc[ $tt_id ] = $image_id;
if ( update_option( 'taxonomy_image_plugin', taxonomy_image_plugin_sanitize_associations( $assoc ) ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'good',
- 'why' => esc_html__( 'Image successfully associated', 'taxonomy-images' ),
- 'attachment_thumb_src' => taxonomy_image_plugin_get_image_src( $image_id )
- ) );
- }
- else {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'Association could not be created', 'taxonomy-images' )
- ) );
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'good',
+ 'why' => esc_html__( 'Image successfully associated', 'taxonomy-images' ),
+ 'attachment_thumb_src' => taxonomy_image_plugin_get_image_src( $image_id ),
+ )
+ );
+ } else {
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'Association could not be created', 'taxonomy-images' ),
+ )
+ );
}
/* Don't know why, but something didn't work. */
@@ -580,63 +618,78 @@ function taxonomy_image_plugin_create_association() {
* @access private
*/
function taxonomy_image_plugin_remove_association() {
- if ( ! isset( $_POST['tt_id'] ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
- ) );
+ if ( ! isset( $_POST['tt_id'] ) ) { // input var ok
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
+ )
+ );
}
- $tt_id = absint( $_POST['tt_id'] );
+ $tt_id = absint( $_POST['tt_id'] ); // input var ok
if ( empty( $tt_id ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
- ) );
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
+ )
+ );
}
if ( ! taxonomy_image_plugin_check_permissions( $tt_id ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
- ) );
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
+ )
+ );
}
- if ( ! isset( $_POST['wp_nonce'] ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'No nonce included', 'taxonomy-images' ),
- ) );
+ if ( ! isset( $_POST['wp_nonce'] ) ) { // input var ok
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'No nonce included', 'taxonomy-images' ),
+ )
+ );
}
- if ( ! wp_verify_nonce( $_POST['wp_nonce'], 'taxonomy-image-plugin-remove-association') ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
- ) );
+ if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wp_nonce'] ) ), 'taxonomy-image-plugin-remove-association' ) ) { // input var ok
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
+ )
+ );
}
$assoc = taxonomy_image_plugin_get_associations();
- if ( ! isset( $assoc[$tt_id] ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'good',
- 'why' => esc_html__( 'Nothing to remove', 'taxonomy-images' )
- ) );
+ if ( ! isset( $assoc[ $tt_id ] ) ) {
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'good',
+ 'why' => esc_html__( 'Nothing to remove', 'taxonomy-images' ),
+ )
+ );
}
- unset( $assoc[$tt_id] );
+ unset( $assoc[ $tt_id ] );
if ( update_option( 'taxonomy_image_plugin', $assoc ) ) {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'good',
- 'why' => esc_html__( 'Association successfully removed', 'taxonomy-images' )
- ) );
- }
- else {
- taxonomy_image_plugin_json_response( array(
- 'status' => 'bad',
- 'why' => esc_html__( 'Association could not be removed', 'taxonomy-images' )
- ) );
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'good',
+ 'why' => esc_html__( 'Association successfully removed', 'taxonomy-images' ),
+ )
+ );
+ } else {
+ taxonomy_image_plugin_json_response(
+ array(
+ 'status' => 'bad',
+ 'why' => esc_html__( 'Association could not be removed', 'taxonomy-images' ),
+ )
+ );
}
/* Don't know why, but something didn't work. */
@@ -656,8 +709,9 @@ function taxonomy_image_plugin_remove_association() {
*/
function taxonomy_image_plugin_get_associations( $refresh = false ) {
static $associations = array();
- if ( empty( $associations ) || $refresh )
+ if ( empty( $associations ) || $refresh ) {
$associations = taxonomy_image_plugin_sanitize_associations( get_option( 'taxonomy_image_plugin' ) );
+ }
return $associations;
}
@@ -677,13 +731,14 @@ function taxonomy_image_plugin_get_associations( $refresh = false ) {
*/
function taxonomy_image_plugin_add_dynamic_hooks() {
$settings = get_option( 'taxonomy_image_plugin_settings' );
- if ( ! isset( $settings['taxonomies'] ) )
+ if ( ! isset( $settings['taxonomies'] ) ) {
return;
+ }
foreach ( $settings['taxonomies'] as $taxonomy ) {
add_filter( 'manage_' . $taxonomy . '_custom_column', 'taxonomy_image_plugin_taxonomy_rows', 15, 3 );
- add_filter( 'manage_edit-' . $taxonomy . '_columns', 'taxonomy_image_plugin_taxonomy_columns' );
- add_action( $taxonomy . '_edit_form_fields', 'taxonomy_image_plugin_edit_tag_form', 10, 2 );
+ add_filter( 'manage_edit-' . $taxonomy . '_columns', 'taxonomy_image_plugin_taxonomy_columns' );
+ add_action( $taxonomy . '_edit_form_fields', 'taxonomy_image_plugin_edit_tag_form', 10, 2 );
}
}
add_action( 'admin_init', 'taxonomy_image_plugin_add_dynamic_hooks' );
@@ -748,14 +803,15 @@ function taxonomy_image_plugin_taxonomy_rows( $row, $column_name, $term_id ) {
*/
function taxonomy_image_plugin_edit_tag_form( $term, $taxonomy ) {
$taxonomy = get_taxonomy( $taxonomy );
- $name = __( 'term', 'taxonomy-images' );
- if ( isset( $taxonomy->labels->singular_name ) )
+ $name = __( 'term', 'taxonomy-images' );
+ if ( isset( $taxonomy->labels->singular_name ) ) {
$name = strtolower( $taxonomy->labels->singular_name );
+ }
?>
- |
+ |
- term_id, $taxonomy->name ); ?>
+ term_id, $taxonomy->name ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
|
@@ -777,39 +833,42 @@ function taxonomy_image_plugin_control_image( $term_id, $taxonomy ) {
$term = get_term( $term_id, $taxonomy );
$tt_id = 0;
- if ( isset( $term->term_taxonomy_id ) )
+ if ( isset( $term->term_taxonomy_id ) ) {
$tt_id = (int) $term->term_taxonomy_id;
+ }
$taxonomy = get_taxonomy( $taxonomy );
$name = esc_html__( 'term', 'taxonomy-images' );
- if ( isset( $taxonomy->labels->singular_name ) )
+ if ( isset( $taxonomy->labels->singular_name ) ) {
$name = strtolower( $taxonomy->labels->singular_name );
+ }
- $hide = ' hide';
+ $hide = ' hide';
$attachment_id = 0;
- $associations = taxonomy_image_plugin_get_associations();
+ $associations = taxonomy_image_plugin_get_associations();
if ( isset( $associations[ $tt_id ] ) ) {
$attachment_id = (int) $associations[ $tt_id ];
- $hide = '';
+ $hide = '';
}
$img = taxonomy_image_plugin_get_image_src( $attachment_id );
$term = get_term( $term_id, $taxonomy->name );
- $o = "\n" . '';
return $o;
}
@@ -828,14 +887,16 @@ function taxonomy_image_plugin_media_upload_popup_js() {
array( 'jquery' ),
taxonomy_image_plugin_version()
);
- wp_localize_script( 'taxonomy-images-media-upload-popup', 'TaxonomyImagesModal', array (
- 'termBefore' => esc_html__( '“', 'taxonomy-images' ),
- 'termAfter' => esc_html__( '”', 'taxonomy-images' ),
- 'associating' => esc_html__( 'Associating …', 'taxonomy-images' ),
- 'success' => esc_html__( 'Successfully Associated', 'taxonomy-images' ),
- 'removing' => esc_html__( 'Removing …', 'taxonomy-images' ),
- 'removed' => esc_html__( 'Successfully Removed', 'taxonomy-images' )
- ) );
+ wp_localize_script(
+ 'taxonomy-images-media-upload-popup', 'TaxonomyImagesModal', array(
+ 'termBefore' => esc_html__( '“', 'taxonomy-images' ),
+ 'termAfter' => esc_html__( '”', 'taxonomy-images' ),
+ 'associating' => esc_html__( 'Associating …', 'taxonomy-images' ),
+ 'success' => esc_html__( 'Successfully Associated', 'taxonomy-images' ),
+ 'removing' => esc_html__( 'Removing …', 'taxonomy-images' ),
+ 'removed' => esc_html__( 'Successfully Removed', 'taxonomy-images' ),
+ )
+ );
}
add_action( 'admin_print_scripts-media-upload-popup', 'taxonomy_image_plugin_media_upload_popup_js' );
@@ -846,8 +907,9 @@ function taxonomy_image_plugin_media_upload_popup_js() {
* @access private
*/
function taxonomy_image_plugin_edit_tags_js() {
- if ( false == taxonomy_image_plugin_is_screen_active() )
+ if ( false === taxonomy_image_plugin_is_screen_active() ) {
return;
+ }
wp_enqueue_script(
'taxonomy-image-plugin-edit-tags',
@@ -855,12 +917,14 @@ function taxonomy_image_plugin_edit_tags_js() {
array( 'jquery', 'thickbox' ),
taxonomy_image_plugin_version()
);
- wp_localize_script( 'taxonomy-image-plugin-edit-tags', 'taxonomyImagesPlugin', array (
- 'nonce' => wp_create_nonce( 'taxonomy-image-plugin-remove-association' ),
- 'img_src' => taxonomy_image_plugin_url( 'default.png' ),
- 'tt_id' => 0,
- 'image_id' => 0,
- ) );
+ wp_localize_script(
+ 'taxonomy-image-plugin-edit-tags', 'taxonomyImagesPlugin', array(
+ 'nonce' => wp_create_nonce( 'taxonomy-image-plugin-remove-association' ),
+ 'img_src' => taxonomy_image_plugin_url( 'default.png' ),
+ 'tt_id' => 0,
+ 'image_id' => 0,
+ )
+ );
}
add_action( 'admin_print_scripts-edit-tags.php', 'taxonomy_image_plugin_edit_tags_js' );
@@ -872,8 +936,9 @@ function taxonomy_image_plugin_edit_tags_js() {
* @access private
*/
function taxonomy_image_plugin_css_admin() {
- if ( false == taxonomy_image_plugin_is_screen_active() && 'admin_print_styles-media-upload-popup' != current_filter() )
+ if ( false === taxonomy_image_plugin_is_screen_active() && 'admin_print_styles-media-upload-popup' !== current_filter() ) {
return;
+ }
wp_enqueue_style(
'taxonomy-image-plugin-edit-tags',
@@ -894,8 +959,9 @@ function taxonomy_image_plugin_css_admin() {
* @access private
*/
function taxonomy_image_plugin_css_thickbox() {
- if ( false == taxonomy_image_plugin_is_screen_active() )
+ if ( false === taxonomy_image_plugin_is_screen_active() ) {
return;
+ }
wp_enqueue_style( 'thickbox' );
}
@@ -910,14 +976,15 @@ function taxonomy_image_plugin_css_thickbox() {
* insert the following code into your theme's functions.php
* file:
*
- * add_filter( 'taxonomy-images-disable-public-css', '__return_true' );
+ * add_filter( 'taxonomy_images_disable_public_css', '__return_true' );
*
* @since 0.7
* @access private
*/
function taxonomy_image_plugin_css_public() {
- if ( apply_filters( 'taxonomy-images-disable-public-css', false ) )
+ if ( apply_filters( 'taxonomy_images_disable_public_css', false ) ) {
return;
+ }
wp_enqueue_style(
'taxonomy-image-plugin-public',
@@ -951,14 +1018,17 @@ function taxonomy_image_plugin_css_public() {
*/
function taxonomy_image_plugin_activate() {
$associations = get_option( 'taxonomy_image_plugin' );
- if ( false === $associations )
+ if ( false === $associations ) {
add_option( 'taxonomy_image_plugin', array() );
+ }
$settings = get_option( 'taxonomy_image_plugin_settings' );
if ( false === $settings ) {
- add_option( 'taxonomy_image_plugin_settings', array(
- 'taxonomies' => array()
- ) );
+ add_option(
+ 'taxonomy_image_plugin_settings', array(
+ 'taxonomies' => array(),
+ )
+ );
}
}
register_activation_hook( __FILE__, 'taxonomy_image_plugin_activate' );
@@ -974,15 +1044,18 @@ function taxonomy_image_plugin_activate() {
*/
function taxonomy_image_plugin_is_screen_active() {
$screen = get_current_screen();
- if ( ! isset( $screen->taxonomy ) )
+ if ( ! isset( $screen->taxonomy ) ) {
return false;
+ }
$settings = get_option( 'taxonomy_image_plugin_settings' );
- if ( ! isset( $settings['taxonomies'] ) )
+ if ( ! isset( $settings['taxonomies'] ) ) {
return false;
+ }
- if ( in_array( $screen->taxonomy, $settings['taxonomies'] ) )
+ if ( in_array( $screen->taxonomy, $settings['taxonomies'], true ) ) {
return true;
+ }
return false;
}
@@ -1003,17 +1076,20 @@ function taxonomy_image_plugin_is_screen_active() {
*/
function taxonomy_image_plugin_cache_images( $posts ) {
$assoc = taxonomy_image_plugin_get_associations();
- if ( empty( $assoc ) )
+ if ( empty( $assoc ) ) {
return;
+ }
$tt_ids = array();
foreach ( (array) $posts as $post ) {
- if ( ! isset( $post->ID ) || ! isset( $post->post_type ) )
+ if ( ! isset( $post->ID ) || ! isset( $post->post_type ) ) {
continue;
+ }
$taxonomies = get_object_taxonomies( $post->post_type );
- if ( empty( $taxonomies ) )
+ if ( empty( $taxonomies ) ) {
continue;
+ }
foreach ( $taxonomies as $taxonomy ) {
$the_terms = get_the_terms( $post->ID, $taxonomy );
@@ -1029,22 +1105,27 @@ function taxonomy_image_plugin_cache_images( $posts ) {
$image_ids = array();
foreach ( $tt_ids as $tt_id ) {
- if ( ! isset( $assoc[$tt_id] ) )
+ if ( ! isset( $assoc[ $tt_id ] ) ) {
continue;
+ }
- if ( in_array( $assoc[$tt_id], $image_ids ) )
+ if ( in_array( $assoc[ $tt_id ], $image_ids, true ) ) {
continue;
+ }
- $image_ids[] = $assoc[$tt_id];
+ $image_ids[] = $assoc[ $tt_id ];
}
- if ( empty( $image_ids ) )
+ if ( empty( $image_ids ) ) {
return;
+ }
- $images = get_posts( array(
- 'include' => $image_ids,
- 'post_type' => 'attachment'
- ) );
+ $images = get_posts(
+ array(
+ 'include' => $image_ids,
+ 'post_type' => 'attachment',
+ )
+ );
}
@@ -1082,26 +1163,41 @@ function taxonomy_image_plugin_cache_queried_images() {
*/
function taxonomy_image_plugin_check_taxonomy( $taxonomy, $filter ) {
if ( ! taxonomy_exists( $taxonomy ) ) {
- trigger_error( sprintf( esc_html__( 'The %1$s argument for %2$s is set to %3$s which is not a registered taxonomy. Please check the spelling and update the argument.', 'taxonomy-images' ),
- '' . esc_html__( 'taxonomy', 'taxonomy-images' ) . '',
- '' . esc_html( $filter ) . '',
- '' . esc_html( $taxonomy ) . ''
- ) );
+ trigger_error(
+ sprintf(
+ esc_html__( 'The %1$s argument for %2$s is set to %3$s which is not a registered taxonomy. Please check the spelling and update the argument.', 'taxonomy-images' ),
+ '' . esc_html__( 'taxonomy', 'taxonomy-images' ) . '',
+ '' . esc_html( $filter ) . '',
+ '' . esc_html( $taxonomy ) . ''
+ )
+ );
return false;
}
$settings = get_option( 'taxonomy_image_plugin_settings' );
if ( ! isset( $settings['taxonomies'] ) ) {
- trigger_error( sprintf( esc_html__( 'No taxonomies have image support. %1$s', 'taxonomy-images' ), taxonomy_images_plugin_settings_page_link() ) );
+ trigger_error(
+ esc_html(
+ sprintf(
+ __( 'No taxonomies have image support. %1$s', 'taxonomy-images' )
+ taxonomy_images_plugin_settings_page_link()
+ )
+ )
+ );
return false;
}
- if ( ! in_array( $taxonomy, (array) $settings['taxonomies'] ) ) {
- trigger_error( sprintf( esc_html__( 'The %1$s taxonomy does not have image support. %2$s', 'taxonomy-images' ),
- '' . esc_html( $taxonomy ) . '',
- taxonomy_images_plugin_settings_page_link()
- ) );
+ if ( ! in_array( $taxonomy, (array) $settings['taxonomies'], true ) ) {
+ trigger_error(
+ esc_html(
+ sprintf(
+ __( 'The %1$s taxonomy does not have image support. %2$s', 'taxonomy-images' ),
+ '' . esc_html( $taxonomy ) . '',
+ taxonomy_images_plugin_settings_page_link()
+ )
+ )
+ );
return false;
}
@@ -1123,10 +1219,13 @@ function taxonomy_image_plugin_check_taxonomy( $taxonomy, $filter ) {
* @since 0.7
*/
function taxonomy_image_plugin_please_use_filter( $function, $filter ) {
- trigger_error( sprintf( esc_html__( 'The %1$s has been called directly. Please use the %2$s filter instead.', 'taxonomy-images' ),
- '' . esc_html( $function . '()' ) . '',
- '' . esc_html( $filter ) . ''
- ) );
+ trigger_error(
+ sprintf(
+ esc_html__( 'The %1$s has been called directly. Please use the %2$s filter instead.', 'taxonomy-images' ),
+ '' . esc_html( $function . '()' ) . '',
+ '' . esc_html( $filter ) . ''
+ )
+ );
}
@@ -1146,15 +1245,18 @@ function taxonomy_image_plugin_please_use_filter( $function, $filter ) {
function taxonomy_images_plugin_row_meta( $links, $file ) {
static $plugin_name = '';
- if ( empty( $plugin_name ) )
+ if ( empty( $plugin_name ) ) {
$plugin_name = plugin_basename( __FILE__ );
+ }
- if ( $plugin_name != $file )
+ if ( $plugin_name !== $file ) {
return $links;
+ }
$link = taxonomy_images_plugin_settings_page_link( __( 'Settings', 'taxonomy-images' ) );
- if ( ! empty( $link ) )
+ if ( ! empty( $link ) ) {
$links[] = $link;
+ }
$links[] = '' . __( 'Donate', 'taxonomy-images' ) . '';
@@ -1173,12 +1275,14 @@ function taxonomy_images_plugin_row_meta( $links, $file ) {
* @since 0.7
*/
function taxonomy_images_plugin_settings_page_link( $link_text = '' ) {
- if ( empty( $link_text ) )
+ if ( empty( $link_text ) ) {
$link_text = __( 'Manage Settings', 'taxonomy-images' );
+ }
$link = '';
- if ( current_user_can( 'manage_options' ) )
+ if ( current_user_can( 'manage_options' ) ) {
$link = '' . esc_html( $link_text ) . '';
+ }
return $link;
}