Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPCS code standards cleanup #36

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
160 changes: 97 additions & 63 deletions code-snippets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -34,47 +36,55 @@ function mytheme_append_the_term_images( $content ) {


/* Default */
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN' );
print '<h2>taxonomy-images-queried-term-image</h2>';
print '<pre>' . htmlentities( $img ) . '</pre>';
$img = apply_filters( 'taxonomy_images_queried_term_image', 'PLEASE INSTALL PLUGIN' );
print '<h2>taxonomy_images_queried_term_image</h2>';
print '<pre>' . esc_html( htmlenties( $img ) ) . '</pre>';


/* Inside a yellow box */
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
'before' => '<div style="padding:20px;background-color:yellow;">',
'after' => '</div>',
) );
print '<h2>taxonomy-images-queried-term-image - custom wrapper element.</h2>';
print '<pre>' . htmlentities( $img ) . '</pre>';
$img = apply_filters(
'taxonomy_images_queried_term_image', 'PLEASE INSTALL PLUGIN', array(
'before' => '<div style="padding:20px;background-color:yellow;">',
'after' => '</div>',
)
);
print '<h2>taxonomy_images_queried_term_image - custom wrapper element.</h2>';
print '<pre>' . esc_html( htmlenties( $img ) )) . '</pre>';


/* Medium Size */
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
'image_size' => 'medium',
) );
print '<h2>taxonomy-images-queried-term-image - medium image size</h2>';
print '<pre>' . htmlentities( $img ) . '</pre>';
$img = apply_filters(
'taxonomy_images_queried_term_image', 'PLEASE INSTALL PLUGIN', array(
'image_size' => 'medium',
)
);
print '<h2>taxonomy_images_queried_term_image - medium image size</h2>';
print '<pre>' . esc_html( htmlenties( $img ) ) . '</pre>';


/* 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 '<h2>taxonomy-images-queried-term-image - unknown image size</h2>';
print '<pre>' . htmlentities( $img ) . '</pre>';
$img = apply_filters(
'taxonomy_images_queried_term_image', 'PLEASE INSTALL PLUGIN', array(
'image_size' => 'this-is-probably-not-a-real-image-size',
)
);
print '<h2>taxonomy_images_queried_term_image - unknown image size</h2>';
print '<pre>' . esc_html( htmlenties( $img ) ) . '</pre>';


/* 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 '<h2>taxonomy-images-queried-term-image - custom attributes</h2>';
print '<pre>' . htmlentities( $img ) . '</pre>';
)
);
print '<h2>taxonomy_images_queried_term_image - custom attributes</h2>';
print '<pre>' . esc_html( htmlenties( $img ) ) . '</pre>';



Expand All @@ -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 '<h2>taxonomy-images-queried-term-image-id</h2>';
print '<pre>'; var_dump( $img ); print '</pre>';
print '<h2>taxonomy_images_queried_term_image_id</h2>';
print '<pre>';
var_dump( $img );
print '</pre>';



Expand All @@ -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 '<h2>taxonomy-images-queried-term-image-object</h2>';
print '<pre>'; var_dump( $img ); print '</pre>';
print '<h2>taxonomy_images_queried_term_image_object</h2>';
print '<pre>';
var_dump( $img );
print '</pre>';



Expand All @@ -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 '<h2>taxonomy-images-queried-term-image-url - Default</h2>';
print '<pre>'; var_dump( $img ); print '</pre>';
$img = apply_filters( 'taxonomy_images_queried_term_image_url', 'PLEASE INSTALL PLUGIN' );
print '<h2>taxonomy_images_queried_term_image_url - Default</h2>';
print '<pre>';
var_dump( $img );
print '</pre>';


/* Medium Size */
$img = apply_filters( 'taxonomy-images-queried-term-image-url', 'PLEASE INSTALL PLUGIN', array(
'image_size' => 'medium'
) );
print '<h2>taxonomy-images-queried-term-image-url - Medium</h2>';
print '<pre>'; var_dump( $img ); print '</pre>';
$img = apply_filters(
'taxonomy_images_queried_term_image_url', 'PLEASE INSTALL PLUGIN', array(
'image_size' => 'medium',
)
);
print '<h2>taxonomy_images_queried_term_image_url - Medium</h2>';
print '<pre>';
var_dump( $img );
print '</pre>';


/* 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 '<h2>taxonomy-images-queried-term-image-url - Unregistered</h2>';
print '<pre>'; var_dump( $img ); print '</pre>';
$img = apply_filters(
'taxonomy_images_queried_term_image_url', 'PLEASE INSTALL PLUGIN', array(
'image_size' => 'this-is-not-real-size-probably-I-hope',
)
);
print '<h2>taxonomy_images_queried_term_image_url - Unregistered</h2>';
print '<pre>';
var_dump( $img );
print '</pre>';



Expand All @@ -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 '<h2>taxonomy-images-queried-term-image-data - Default</h2>';
print '<pre>'; var_dump( $img ); print '</pre>';
$img = apply_filters( 'taxonomy_images_queried_term_image_data', 'PLEASE INSTALL PLUGIN' );
print '<h2>taxonomy_images_queried_term_image_data - Default</h2>';
print '<pre>';
var_dump( $img );
print '</pre>';


/* Medium Size */
$img = apply_filters( 'taxonomy-images-queried-term-image-data', 'PLEASE INSTALL PLUGIN', array(
'image_size' => 'medium'
) );
print '<h2>taxonomy-images-queried-term-image-data - Medium</h2>';
print '<pre>'; var_dump( $img ); print '</pre>';
$img = apply_filters(
'taxonomy_images_queried_term_image_data', 'PLEASE INSTALL PLUGIN', array(
'image_size' => 'medium',
)
);
print '<h2>taxonomy_images_queried_term_image_data - Medium</h2>';
print '<pre>';
var_dump( $img );
print '</pre>';


/* 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 '<h2>taxonomy-images-queried-term-image-data - Unregistered</h2>';
print '<pre>'; var_dump( $img ); print '</pre>';
$img = apply_filters(
'taxonomy_images_queried_term_image_data', 'PLEASE INSTALL PLUGIN', array(
'image_size' => 'this-is-not-real-size-probably-I-hope',
)
);
print '<h2>taxonomy_images_queried_term_image_data - Unregistered</h2>';
print '<pre>';
var_dump( $img );
print '</pre>';
51 changes: 26 additions & 25 deletions deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );

Expand All @@ -22,32 +23,33 @@ function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) { // DEP
return '<!-- taxonomy_image_plugin error: Taxonomy "' . $taxonomy . '" is not defined.-->';
}

$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 . ')' );
$description = apply_filters( 'the_content', $term->description );

$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" . '<div class="taxonomy_image_plugin-' . $template . '">';
$o.= "\n\t\t" . '<a style="float:left;" title="' . $title_attr . '" href="' . $url . '">' . $img . '</a>';
$o.= "\n\t" . '</div>';
}
else {
$o.= "\n\t\t" . '<a title="' . $title_attr . '" href="' . $url . '">' . $img . '</a>';;
$o.= "\n\t\t" . '<h2 style="clear:none;margin-top:0;padding-top:0;line-height:1em;"><a href="' . $url . '">' . $title . '</a></h2>';
$o.= $description;
$o.= "\n\t" . '<div style="clear:both;height:1.5em"></div>';
$o.= "\n";
if ( 'grid' === $template ) {
$o .= "\n\t" . '<div class="taxonomy_image_plugin-' . $template . '">';
$o .= "\n\t\t" . '<a style="float:left;" title="' . $title_attr . '" href="' . $url . '">' . $img . '</a>';
$o .= "\n\t" . '</div>';
} else {
$o .= "\n\t\t" . '<a title="' . $title_attr . '" href="' . $url . '">' . $img . '</a>';
;
$o .= "\n\t\t" . '<h2 style="clear:none;margin-top:0;padding-top:0;line-height:1em;"><a href="' . $url . '">' . $title . '</a></h2>';
$o .= $description;
$o .= "\n\t" . '<div style="clear:both;height:1.5em"></div>';
$o .= "\n";
}
}
}
Expand All @@ -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();
Expand All @@ -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 = '';
Expand All @@ -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;
}
}
Expand All @@ -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();
Loading