Version Description
Fixes media modal not opening on newly created terms.
Download this release
Release Info
| Developer | husobj |
| Plugin | |
| Version | 0.9.1 |
| Comparing to | |
| See all releases | |
Code changes from version 0.9 to 0.9.1
- code-snippets.php +12 -14
- deprecated.php +27 -20
- js/media-modal.js +2 -2
- public-filters.php +23 -23
- readme.md +8 -1
- readme.txt +12 -4
- taxonomy-images.php +112 -84
code-snippets.php
CHANGED
|
@@ -15,20 +15,20 @@ exit;
|
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
-
|
| 19 |
* Append the term images to content + excerpt.
|
| 20 |
*/
|
| 21 |
function taxonomy_images_test_theme_append_the_term_images( $content ) {
|
| 22 |
return $content . apply_filters( 'taxonomy-images-list-the-terms', '', array(
|
| 23 |
'image_size' => 'detail',
|
| 24 |
-
|
| 25 |
}
|
| 26 |
add_filter( 'the_content', 'taxonomy_images_test_theme_append_the_term_images' );
|
| 27 |
add_filter( 'the_excerpt', 'taxonomy_images_test_theme_append_the_term_images' );
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
-
|
| 32 |
* Queried Term Image.
|
| 33 |
*
|
| 34 |
* Return html markup representing the image associated with the
|
|
@@ -48,7 +48,7 @@ print '<pre>' . htmlentities( $img ) . '</pre>';
|
|
| 48 |
|
| 49 |
/* Inside a yellow box */
|
| 50 |
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
| 51 |
-
'before' => '<div style="padding:20px;background-color:yellow;">',
|
| 52 |
'after' => '</div>',
|
| 53 |
) );
|
| 54 |
print '<h2>taxonomy-images-queried-term-image - custom wrapper element.</h2>';
|
|
@@ -58,7 +58,7 @@ print '<pre>' . htmlentities( $img ) . '</pre>';
|
|
| 58 |
/* Medium Size */
|
| 59 |
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
| 60 |
'image_size' => 'medium',
|
| 61 |
-
|
| 62 |
print '<h2>taxonomy-images-queried-term-image - medium image size</h2>';
|
| 63 |
print '<pre>' . htmlentities( $img ) . '</pre>';
|
| 64 |
|
|
@@ -66,7 +66,7 @@ print '<pre>' . htmlentities( $img ) . '</pre>';
|
|
| 66 |
/* Unrecognized size */
|
| 67 |
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
| 68 |
'image_size' => 'this-is-probably-not-a-real-image-size',
|
| 69 |
-
|
| 70 |
print '<h2>taxonomy-images-queried-term-image - unknown image size</h2>';
|
| 71 |
print '<pre>' . htmlentities( $img ) . '</pre>';
|
| 72 |
|
|
@@ -78,14 +78,14 @@ $img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUG
|
|
| 78 |
'class' => 'my-class-list bunnies turtles',
|
| 79 |
'src' => 'this-is-where-the-image-lives.png',
|
| 80 |
'title' => 'Custom Title',
|
| 81 |
-
|
| 82 |
-
|
| 83 |
print '<h2>taxonomy-images-queried-term-image - custom attributes</h2>';
|
| 84 |
print '<pre>' . htmlentities( $img ) . '</pre>';
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
-
|
| 89 |
* Queried Term Image ID.
|
| 90 |
*
|
| 91 |
* Return the id of the image associated with the currently
|
|
@@ -96,14 +96,13 @@ print '<pre>' . htmlentities( $img ) . '</pre>';
|
|
| 96 |
* apply_filters() will return it's second parameter.
|
| 97 |
*/
|
| 98 |
$img = apply_filters( 'taxonomy-images-queried-term-image-id', 'PLEASE INSTALL PLUGIN' );
|
| 99 |
-
|
| 100 |
print '<h2>taxonomy-images-queried-term-image-id</h2>';
|
| 101 |
print '<pre>'; var_dump( $img ); print '</pre>';
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
-
|
| 107 |
* Queried Term Image Object.
|
| 108 |
*
|
| 109 |
* Return an object representing the image associated with the
|
|
@@ -114,14 +113,13 @@ print '<pre>'; var_dump( $img ); print '</pre>';
|
|
| 114 |
* apply_filters() will return it's second parameter.
|
| 115 |
*/
|
| 116 |
$img = apply_filters( 'taxonomy-images-queried-term-image-object', 'PLEASE INSTALL PLUGIN' );
|
| 117 |
-
|
| 118 |
print '<h2>taxonomy-images-queried-term-image-object</h2>';
|
| 119 |
print '<pre>'; var_dump( $img ); print '</pre>';
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
-
|
| 125 |
* Queried Term Image URL.
|
| 126 |
*
|
| 127 |
* Return a url to the image associated with the current queried
|
|
@@ -157,7 +155,7 @@ print '<pre>'; var_dump( $img ); print '</pre>';
|
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
-
|
| 161 |
* Queried Term Image Data.
|
| 162 |
*
|
| 163 |
* Return an array of data about the image associated with the current
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
+
/**
|
| 19 |
* Append the term images to content + excerpt.
|
| 20 |
*/
|
| 21 |
function taxonomy_images_test_theme_append_the_term_images( $content ) {
|
| 22 |
return $content . apply_filters( 'taxonomy-images-list-the-terms', '', array(
|
| 23 |
'image_size' => 'detail',
|
| 24 |
+
) );
|
| 25 |
}
|
| 26 |
add_filter( 'the_content', 'taxonomy_images_test_theme_append_the_term_images' );
|
| 27 |
add_filter( 'the_excerpt', 'taxonomy_images_test_theme_append_the_term_images' );
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
+
/**
|
| 32 |
* Queried Term Image.
|
| 33 |
*
|
| 34 |
* Return html markup representing the image associated with the
|
| 48 |
|
| 49 |
/* Inside a yellow box */
|
| 50 |
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
| 51 |
+
'before' => '<div style="padding: 20px; background-color: yellow;">',
|
| 52 |
'after' => '</div>',
|
| 53 |
) );
|
| 54 |
print '<h2>taxonomy-images-queried-term-image - custom wrapper element.</h2>';
|
| 58 |
/* Medium Size */
|
| 59 |
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
| 60 |
'image_size' => 'medium',
|
| 61 |
+
) );
|
| 62 |
print '<h2>taxonomy-images-queried-term-image - medium image size</h2>';
|
| 63 |
print '<pre>' . htmlentities( $img ) . '</pre>';
|
| 64 |
|
| 66 |
/* Unrecognized size */
|
| 67 |
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
| 68 |
'image_size' => 'this-is-probably-not-a-real-image-size',
|
| 69 |
+
) );
|
| 70 |
print '<h2>taxonomy-images-queried-term-image - unknown image size</h2>';
|
| 71 |
print '<pre>' . htmlentities( $img ) . '</pre>';
|
| 72 |
|
| 78 |
'class' => 'my-class-list bunnies turtles',
|
| 79 |
'src' => 'this-is-where-the-image-lives.png',
|
| 80 |
'title' => 'Custom Title',
|
| 81 |
+
),
|
| 82 |
+
) );
|
| 83 |
print '<h2>taxonomy-images-queried-term-image - custom attributes</h2>';
|
| 84 |
print '<pre>' . htmlentities( $img ) . '</pre>';
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
+
/**
|
| 89 |
* Queried Term Image ID.
|
| 90 |
*
|
| 91 |
* Return the id of the image associated with the currently
|
| 96 |
* apply_filters() will return it's second parameter.
|
| 97 |
*/
|
| 98 |
$img = apply_filters( 'taxonomy-images-queried-term-image-id', 'PLEASE INSTALL PLUGIN' );
|
|
|
|
| 99 |
print '<h2>taxonomy-images-queried-term-image-id</h2>';
|
| 100 |
print '<pre>'; var_dump( $img ); print '</pre>';
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
+
/**
|
| 106 |
* Queried Term Image Object.
|
| 107 |
*
|
| 108 |
* Return an object representing the image associated with the
|
| 113 |
* apply_filters() will return it's second parameter.
|
| 114 |
*/
|
| 115 |
$img = apply_filters( 'taxonomy-images-queried-term-image-object', 'PLEASE INSTALL PLUGIN' );
|
|
|
|
| 116 |
print '<h2>taxonomy-images-queried-term-image-object</h2>';
|
| 117 |
print '<pre>'; var_dump( $img ); print '</pre>';
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
+
/**
|
| 123 |
* Queried Term Image URL.
|
| 124 |
*
|
| 125 |
* Return a url to the image associated with the current queried
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
+
/**
|
| 159 |
* Queried Term Image Data.
|
| 160 |
*
|
| 161 |
* Return an array of data about the image associated with the current
|
deprecated.php
CHANGED
|
@@ -3,23 +3,25 @@
|
|
| 3 |
/**
|
| 4 |
* Deprecated Shortcode.
|
| 5 |
*
|
| 6 |
-
* @
|
| 7 |
-
*
|
|
|
|
|
|
|
| 8 |
*/
|
| 9 |
-
function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) {
|
| 10 |
$o = '';
|
| 11 |
$defaults = array(
|
| 12 |
'taxonomy' => 'category',
|
| 13 |
'size' => 'detail',
|
| 14 |
'template' => 'list'
|
| 15 |
-
|
| 16 |
|
| 17 |
extract( shortcode_atts( $defaults, $atts ) );
|
| 18 |
|
| 19 |
/* No taxonomy defined return an html comment. */
|
| 20 |
if ( ! taxonomy_exists( $taxonomy ) ) {
|
| 21 |
$tax = strip_tags( trim( $taxonomy ) );
|
| 22 |
-
return '<!-- taxonomy_image_plugin error: Taxonomy "' . $taxonomy . '" is not defined.-->';
|
| 23 |
}
|
| 24 |
|
| 25 |
$terms = get_terms( $taxonomy );
|
|
@@ -34,20 +36,19 @@ function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) { // DEP
|
|
| 34 |
|
| 35 |
$img = '';
|
| 36 |
if ( array_key_exists( $term->term_taxonomy_id, $associations ) ) {
|
| 37 |
-
$img = wp_get_attachment_image( $associations[$term->term_taxonomy_id], 'detail', false );
|
| 38 |
}
|
| 39 |
|
| 40 |
-
if(
|
| 41 |
-
$o.= "\n\t" . '<div class="taxonomy_image_plugin-' . $template . '">';
|
| 42 |
-
$o.= "\n\t\t" . '<a style="float: left;" title="' . $title_attr . '" href="' . $url . '">' . $img . '</a>';
|
| 43 |
-
$o.= "\n\t" . '</div>';
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
$o.= "\n\t\t" . '<
|
| 47 |
-
$o.=
|
| 48 |
-
$o.=
|
| 49 |
-
$o.= "\n
|
| 50 |
-
$o.= "\n";
|
| 51 |
}
|
| 52 |
}
|
| 53 |
}
|
|
@@ -61,20 +62,26 @@ add_shortcode( 'taxonomy_image_plugin', 'taxonomy_images_plugin_shortcode_deprec
|
|
| 61 |
* of this plugin 0.5 and under. Please do not use any methods or
|
| 62 |
* properties directly in your theme.
|
| 63 |
*
|
| 64 |
-
* @
|
|
|
|
| 65 |
*/
|
| 66 |
class taxonomy_images_plugin {
|
|
|
|
| 67 |
public $settings = array();
|
|
|
|
| 68 |
public function __construct() {
|
| 69 |
$this->settings = taxonomy_image_plugin_get_associations();
|
| 70 |
add_action( 'taxonomy_image_plugin_print_image_html', array( &$this, 'print_image_html' ), 1, 3 );
|
| 71 |
}
|
|
|
|
| 72 |
public function get_thumb( $id ) {
|
| 73 |
return taxonomy_image_plugin_get_image_src( $id );
|
| 74 |
}
|
|
|
|
| 75 |
public function print_image_html( $size = 'medium', $term_tax_id = false, $title = true, $align = 'none' ) {
|
| 76 |
print $this->get_image_html( $size, $term_tax_id, $title, $align );
|
| 77 |
}
|
|
|
|
| 78 |
public function get_image_html( $size = 'medium', $term_tax_id = false, $title = true, $align = 'none' ) {
|
| 79 |
$o = '';
|
| 80 |
if ( false === $term_tax_id ) {
|
|
@@ -82,8 +89,7 @@ class taxonomy_images_plugin {
|
|
| 82 |
$obj = $wp_query->get_queried_object();
|
| 83 |
if ( isset( $obj->term_taxonomy_id ) ) {
|
| 84 |
$term_tax_id = $obj->term_taxonomy_id;
|
| 85 |
-
}
|
| 86 |
-
else {
|
| 87 |
return false;
|
| 88 |
}
|
| 89 |
}
|
|
@@ -99,5 +105,6 @@ class taxonomy_images_plugin {
|
|
| 99 |
}
|
| 100 |
return $o;
|
| 101 |
}
|
|
|
|
| 102 |
}
|
| 103 |
$taxonomy_images_plugin = new taxonomy_images_plugin();
|
| 3 |
/**
|
| 4 |
* Deprecated Shortcode.
|
| 5 |
*
|
| 6 |
+
* @deprecated Deprecated since version 0.7
|
| 7 |
+
*
|
| 8 |
+
* @return void
|
| 9 |
+
* @access private
|
| 10 |
*/
|
| 11 |
+
function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) {
|
| 12 |
$o = '';
|
| 13 |
$defaults = array(
|
| 14 |
'taxonomy' => 'category',
|
| 15 |
'size' => 'detail',
|
| 16 |
'template' => 'list'
|
| 17 |
+
);
|
| 18 |
|
| 19 |
extract( shortcode_atts( $defaults, $atts ) );
|
| 20 |
|
| 21 |
/* No taxonomy defined return an html comment. */
|
| 22 |
if ( ! taxonomy_exists( $taxonomy ) ) {
|
| 23 |
$tax = strip_tags( trim( $taxonomy ) );
|
| 24 |
+
return '<!-- taxonomy_image_plugin error: Taxonomy "' . esc_html( $taxonomy ) . '" is not defined.-->';
|
| 25 |
}
|
| 26 |
|
| 27 |
$terms = get_terms( $taxonomy );
|
| 36 |
|
| 37 |
$img = '';
|
| 38 |
if ( array_key_exists( $term->term_taxonomy_id, $associations ) ) {
|
| 39 |
+
$img = wp_get_attachment_image( $associations[ $term->term_taxonomy_id ], 'detail', false );
|
| 40 |
}
|
| 41 |
|
| 42 |
+
if ( 'grid' == $template ) {
|
| 43 |
+
$o .= "\n\t" . '<div class="taxonomy_image_plugin-' . $template . '">';
|
| 44 |
+
$o .= "\n\t\t" . '<a style="float: left;" title="' . $title_attr . '" href="' . $url . '">' . $img . '</a>';
|
| 45 |
+
$o .= "\n\t" . '</div>';
|
| 46 |
+
} else {
|
| 47 |
+
$o .= "\n\t\t" . '<a title="' . $title_attr . '" href="' . $url . '">' . $img . '</a>';;
|
| 48 |
+
$o .= "\n\t\t" . '<h2 style="clear: none; margin-top: 0; padding-top: 0; line-height: 1em;"><a href="' . $url . '">' . $title . '</a></h2>';
|
| 49 |
+
$o .= $description;
|
| 50 |
+
$o .= "\n\t" . '<div style="clear: both; height: 1.5em;"></div>';
|
| 51 |
+
$o .= "\n";
|
|
|
|
| 52 |
}
|
| 53 |
}
|
| 54 |
}
|
| 62 |
* of this plugin 0.5 and under. Please do not use any methods or
|
| 63 |
* properties directly in your theme.
|
| 64 |
*
|
| 65 |
+
* @deprecated Deprecated since version 0.5
|
| 66 |
+
* @access private
|
| 67 |
*/
|
| 68 |
class taxonomy_images_plugin {
|
| 69 |
+
|
| 70 |
public $settings = array();
|
| 71 |
+
|
| 72 |
public function __construct() {
|
| 73 |
$this->settings = taxonomy_image_plugin_get_associations();
|
| 74 |
add_action( 'taxonomy_image_plugin_print_image_html', array( &$this, 'print_image_html' ), 1, 3 );
|
| 75 |
}
|
| 76 |
+
|
| 77 |
public function get_thumb( $id ) {
|
| 78 |
return taxonomy_image_plugin_get_image_src( $id );
|
| 79 |
}
|
| 80 |
+
|
| 81 |
public function print_image_html( $size = 'medium', $term_tax_id = false, $title = true, $align = 'none' ) {
|
| 82 |
print $this->get_image_html( $size, $term_tax_id, $title, $align );
|
| 83 |
}
|
| 84 |
+
|
| 85 |
public function get_image_html( $size = 'medium', $term_tax_id = false, $title = true, $align = 'none' ) {
|
| 86 |
$o = '';
|
| 87 |
if ( false === $term_tax_id ) {
|
| 89 |
$obj = $wp_query->get_queried_object();
|
| 90 |
if ( isset( $obj->term_taxonomy_id ) ) {
|
| 91 |
$term_tax_id = $obj->term_taxonomy_id;
|
| 92 |
+
} else {
|
|
|
|
| 93 |
return false;
|
| 94 |
}
|
| 95 |
}
|
| 105 |
}
|
| 106 |
return $o;
|
| 107 |
}
|
| 108 |
+
|
| 109 |
}
|
| 110 |
$taxonomy_images_plugin = new taxonomy_images_plugin();
|
js/media-modal.js
CHANGED
|
@@ -10,7 +10,7 @@ var taxonomy_images_file_frame;
|
|
| 10 |
TaxonomyImagesMediaModal.wp_media_post_id = wp.media.model.settings.post.id;
|
| 11 |
|
| 12 |
// When the remove icon is clicked...
|
| 13 |
-
$( '.
|
| 14 |
|
| 15 |
event.preventDefault();
|
| 16 |
|
|
@@ -50,7 +50,7 @@ var taxonomy_images_file_frame;
|
|
| 50 |
} );
|
| 51 |
|
| 52 |
// When image or upload icon clicked...
|
| 53 |
-
$( '.taxonomy-image-control a.upload, .taxonomy-image-control a.taxonomy-image-thumbnail'
|
| 54 |
|
| 55 |
event.preventDefault();
|
| 56 |
|
| 10 |
TaxonomyImagesMediaModal.wp_media_post_id = wp.media.model.settings.post.id;
|
| 11 |
|
| 12 |
// When the remove icon is clicked...
|
| 13 |
+
$( '.wp-list-table, .form-table' ).on( 'click', '.taxonomy-image-control a.remove', function( event ) {
|
| 14 |
|
| 15 |
event.preventDefault();
|
| 16 |
|
| 50 |
} );
|
| 51 |
|
| 52 |
// When image or upload icon clicked...
|
| 53 |
+
$( '.wp-list-table, .form-table' ).on( 'click', '.taxonomy-image-control a.upload, .taxonomy-image-control a.taxonomy-image-thumbnail', function( event ) {
|
| 54 |
|
| 55 |
event.preventDefault();
|
| 56 |
|
public-filters.php
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
| 3 |
* Interface.
|
| 4 |
*
|
|
@@ -68,7 +69,7 @@ add_filter( 'taxonomy-images-queried-term-image-url', 'taxonomy_images_plugin
|
|
| 68 |
*/
|
| 69 |
function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
|
| 70 |
$filter = 'taxonomy-images-get-terms';
|
| 71 |
-
if (
|
| 72 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 73 |
}
|
| 74 |
|
|
@@ -77,7 +78,7 @@ function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
|
|
| 77 |
'having_images' => true,
|
| 78 |
'taxonomy' => 'category',
|
| 79 |
'term_args' => array(),
|
| 80 |
-
|
| 81 |
|
| 82 |
$args['taxonomy'] = explode( ',', $args['taxonomy'] );
|
| 83 |
$args['taxonomy'] = array_map( 'trim', $args['taxonomy'] );
|
|
@@ -101,12 +102,12 @@ function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
|
|
| 101 |
$image_ids = array();
|
| 102 |
$terms_with_images = array();
|
| 103 |
foreach ( (array) $terms as $key => $term ) {
|
| 104 |
-
$terms[$key]->image_id = 0;
|
| 105 |
if ( array_key_exists( $term->term_taxonomy_id, $assoc ) ) {
|
| 106 |
-
$terms[$key]->image_id = $assoc[$term->term_taxonomy_id];
|
| 107 |
-
$image_ids[] = $assoc[$term->term_taxonomy_id];
|
| 108 |
if ( ! empty( $args['having_images'] ) ) {
|
| 109 |
-
$terms_with_images[] = $terms[$key];
|
| 110 |
}
|
| 111 |
}
|
| 112 |
}
|
|
@@ -168,7 +169,7 @@ function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
|
|
| 168 |
'having_images' => true,
|
| 169 |
'post_id' => 0,
|
| 170 |
'taxonomy' => 'category',
|
| 171 |
-
|
| 172 |
|
| 173 |
if ( ! taxonomy_image_plugin_check_taxonomy( $args['taxonomy'], $filter ) ) {
|
| 174 |
return array();
|
|
@@ -192,11 +193,11 @@ function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
|
|
| 192 |
|
| 193 |
$terms_with_images = array();
|
| 194 |
foreach ( (array) $terms as $key => $term ) {
|
| 195 |
-
$terms[$key]->image_id = 0;
|
| 196 |
if ( array_key_exists( $term->term_taxonomy_id, $assoc ) ) {
|
| 197 |
-
$terms[$key]->image_id = $assoc[$term->term_taxonomy_id];
|
| 198 |
if ( ! empty( $args['having_images'] ) ) {
|
| 199 |
-
$terms_with_images[] = $terms[$key];
|
| 200 |
}
|
| 201 |
}
|
| 202 |
}
|
|
@@ -250,7 +251,7 @@ function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
|
|
| 250 |
*/
|
| 251 |
function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
|
| 252 |
$filter = 'taxonomy-images-list-the-terms';
|
| 253 |
-
if (
|
| 254 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 255 |
}
|
| 256 |
|
|
@@ -262,7 +263,7 @@ function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
|
|
| 262 |
'image_size' => 'thumbnail',
|
| 263 |
'post_id' => 0,
|
| 264 |
'taxonomy' => 'category',
|
| 265 |
-
|
| 266 |
|
| 267 |
$args['having_images'] = true;
|
| 268 |
|
|
@@ -324,7 +325,7 @@ function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
|
|
| 324 |
*/
|
| 325 |
function taxonomy_images_plugin_get_queried_term_image( $default, $args = array() ) {
|
| 326 |
$filter = 'taxonomy-images-queried-term-image';
|
| 327 |
-
if (
|
| 328 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 329 |
}
|
| 330 |
|
|
@@ -333,7 +334,7 @@ function taxonomy_images_plugin_get_queried_term_image( $default, $args = array(
|
|
| 333 |
'attr' => array(),
|
| 334 |
'before' => '',
|
| 335 |
'image_size' => 'thumbnail',
|
| 336 |
-
|
| 337 |
|
| 338 |
$ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
|
| 339 |
|
|
@@ -374,7 +375,7 @@ function taxonomy_images_plugin_get_queried_term_image( $default, $args = array(
|
|
| 374 |
*/
|
| 375 |
function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
|
| 376 |
$filter = 'taxonomy-images-queried-term-image-id';
|
| 377 |
-
if (
|
| 378 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 379 |
}
|
| 380 |
|
|
@@ -386,7 +387,7 @@ function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
|
|
| 386 |
'<code>' . esc_html__( 'term_taxonomy_id', 'taxonomy-images' ) . '</code>',
|
| 387 |
'<code>' . esc_html( $filter ) . '</code>',
|
| 388 |
'<a href="http://codex.wordpress.org/Template_Hierarchy">' . esc_html( 'template hierarchy', 'taxonomy-images' ) . '</a>'
|
| 389 |
-
|
| 390 |
return 0;
|
| 391 |
}
|
| 392 |
|
|
@@ -429,7 +430,7 @@ function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
|
|
| 429 |
*/
|
| 430 |
function taxonomy_images_plugin_get_queried_term_image_object( $default ) {
|
| 431 |
$filter = 'taxonomy-images-queried-term-image-object';
|
| 432 |
-
if (
|
| 433 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 434 |
}
|
| 435 |
|
|
@@ -469,13 +470,13 @@ function taxonomy_images_plugin_get_queried_term_image_object( $default ) {
|
|
| 469 |
*/
|
| 470 |
function taxonomy_images_plugin_get_queried_term_image_url( $default, $args = array() ) {
|
| 471 |
$filter = 'taxonomy-images-queried-term-image-url';
|
| 472 |
-
if (
|
| 473 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 474 |
}
|
| 475 |
|
| 476 |
$args = wp_parse_args( $args, array(
|
| 477 |
'image_size' => 'thumbnail',
|
| 478 |
-
|
| 479 |
|
| 480 |
$data = apply_filters( 'taxonomy-images-queried-term-image-data', array(), $args );
|
| 481 |
|
|
@@ -515,13 +516,13 @@ function taxonomy_images_plugin_get_queried_term_image_url( $default, $args = ar
|
|
| 515 |
*/
|
| 516 |
function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = array() ) {
|
| 517 |
$filter = 'taxonomy-images-queried-term-image-data';
|
| 518 |
-
if (
|
| 519 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 520 |
}
|
| 521 |
|
| 522 |
$args = wp_parse_args( $args, array(
|
| 523 |
'image_size' => 'thumbnail',
|
| 524 |
-
|
| 525 |
|
| 526 |
$ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
|
| 527 |
|
|
@@ -543,8 +544,7 @@ function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = a
|
|
| 543 |
if ( isset( $src[2] ) ) {
|
| 544 |
$data['height'] = $src[2];
|
| 545 |
}
|
| 546 |
-
}
|
| 547 |
-
else {
|
| 548 |
$data = image_get_intermediate_size( $ID, $args['image_size'] );
|
| 549 |
}
|
| 550 |
|
| 1 |
<?php
|
| 2 |
+
|
| 3 |
/**
|
| 4 |
* Interface.
|
| 5 |
*
|
| 69 |
*/
|
| 70 |
function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
|
| 71 |
$filter = 'taxonomy-images-get-terms';
|
| 72 |
+
if ( current_filter() !== $filter ) {
|
| 73 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 74 |
}
|
| 75 |
|
| 78 |
'having_images' => true,
|
| 79 |
'taxonomy' => 'category',
|
| 80 |
'term_args' => array(),
|
| 81 |
+
) );
|
| 82 |
|
| 83 |
$args['taxonomy'] = explode( ',', $args['taxonomy'] );
|
| 84 |
$args['taxonomy'] = array_map( 'trim', $args['taxonomy'] );
|
| 102 |
$image_ids = array();
|
| 103 |
$terms_with_images = array();
|
| 104 |
foreach ( (array) $terms as $key => $term ) {
|
| 105 |
+
$terms[ $key ]->image_id = 0;
|
| 106 |
if ( array_key_exists( $term->term_taxonomy_id, $assoc ) ) {
|
| 107 |
+
$terms[ $key ]->image_id = $assoc[ $term->term_taxonomy_id ];
|
| 108 |
+
$image_ids[] = $assoc[ $term->term_taxonomy_id ];
|
| 109 |
if ( ! empty( $args['having_images'] ) ) {
|
| 110 |
+
$terms_with_images[] = $terms[ $key ];
|
| 111 |
}
|
| 112 |
}
|
| 113 |
}
|
| 169 |
'having_images' => true,
|
| 170 |
'post_id' => 0,
|
| 171 |
'taxonomy' => 'category',
|
| 172 |
+
) );
|
| 173 |
|
| 174 |
if ( ! taxonomy_image_plugin_check_taxonomy( $args['taxonomy'], $filter ) ) {
|
| 175 |
return array();
|
| 193 |
|
| 194 |
$terms_with_images = array();
|
| 195 |
foreach ( (array) $terms as $key => $term ) {
|
| 196 |
+
$terms[ $key ]->image_id = 0;
|
| 197 |
if ( array_key_exists( $term->term_taxonomy_id, $assoc ) ) {
|
| 198 |
+
$terms[ $key ]->image_id = $assoc[ $term->term_taxonomy_id ];
|
| 199 |
if ( ! empty( $args['having_images'] ) ) {
|
| 200 |
+
$terms_with_images[] = $terms[ $key ];
|
| 201 |
}
|
| 202 |
}
|
| 203 |
}
|
| 251 |
*/
|
| 252 |
function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
|
| 253 |
$filter = 'taxonomy-images-list-the-terms';
|
| 254 |
+
if ( current_filter() !== $filter ) {
|
| 255 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 256 |
}
|
| 257 |
|
| 263 |
'image_size' => 'thumbnail',
|
| 264 |
'post_id' => 0,
|
| 265 |
'taxonomy' => 'category',
|
| 266 |
+
) );
|
| 267 |
|
| 268 |
$args['having_images'] = true;
|
| 269 |
|
| 325 |
*/
|
| 326 |
function taxonomy_images_plugin_get_queried_term_image( $default, $args = array() ) {
|
| 327 |
$filter = 'taxonomy-images-queried-term-image';
|
| 328 |
+
if ( current_filter() !== $filter ) {
|
| 329 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 330 |
}
|
| 331 |
|
| 334 |
'attr' => array(),
|
| 335 |
'before' => '',
|
| 336 |
'image_size' => 'thumbnail',
|
| 337 |
+
) );
|
| 338 |
|
| 339 |
$ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
|
| 340 |
|
| 375 |
*/
|
| 376 |
function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
|
| 377 |
$filter = 'taxonomy-images-queried-term-image-id';
|
| 378 |
+
if ( current_filter() !== $filter ) {
|
| 379 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 380 |
}
|
| 381 |
|
| 387 |
'<code>' . esc_html__( 'term_taxonomy_id', 'taxonomy-images' ) . '</code>',
|
| 388 |
'<code>' . esc_html( $filter ) . '</code>',
|
| 389 |
'<a href="http://codex.wordpress.org/Template_Hierarchy">' . esc_html( 'template hierarchy', 'taxonomy-images' ) . '</a>'
|
| 390 |
+
) );
|
| 391 |
return 0;
|
| 392 |
}
|
| 393 |
|
| 430 |
*/
|
| 431 |
function taxonomy_images_plugin_get_queried_term_image_object( $default ) {
|
| 432 |
$filter = 'taxonomy-images-queried-term-image-object';
|
| 433 |
+
if ( current_filter() !== $filter ) {
|
| 434 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 435 |
}
|
| 436 |
|
| 470 |
*/
|
| 471 |
function taxonomy_images_plugin_get_queried_term_image_url( $default, $args = array() ) {
|
| 472 |
$filter = 'taxonomy-images-queried-term-image-url';
|
| 473 |
+
if ( current_filter() !== $filter ) {
|
| 474 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 475 |
}
|
| 476 |
|
| 477 |
$args = wp_parse_args( $args, array(
|
| 478 |
'image_size' => 'thumbnail',
|
| 479 |
+
) );
|
| 480 |
|
| 481 |
$data = apply_filters( 'taxonomy-images-queried-term-image-data', array(), $args );
|
| 482 |
|
| 516 |
*/
|
| 517 |
function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = array() ) {
|
| 518 |
$filter = 'taxonomy-images-queried-term-image-data';
|
| 519 |
+
if ( current_filter() !== $filter ) {
|
| 520 |
taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
|
| 521 |
}
|
| 522 |
|
| 523 |
$args = wp_parse_args( $args, array(
|
| 524 |
'image_size' => 'thumbnail',
|
| 525 |
+
) );
|
| 526 |
|
| 527 |
$ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
|
| 528 |
|
| 544 |
if ( isset( $src[2] ) ) {
|
| 545 |
$data['height'] = $src[2];
|
| 546 |
}
|
| 547 |
+
} else {
|
|
|
|
| 548 |
$data = image_get_intermediate_size( $ID, $args['image_size'] );
|
| 549 |
}
|
| 550 |
|
readme.md
CHANGED
|
@@ -207,7 +207,7 @@ If you have fallen in love with this plugin and would not be able to sleep witho
|
|
| 207 |
Need More Taxonomy Plugins?
|
| 208 |
---------------------------
|
| 209 |
|
| 210 |
-
The original author of this plugin, Michael Fields, released a handful of plugins dealing with taxonomies. Please see his [
|
| 211 |
|
| 212 |
Installation
|
| 213 |
------------
|
|
@@ -221,6 +221,9 @@ Installation
|
|
| 221 |
Upgrade Notice
|
| 222 |
--------------
|
| 223 |
|
|
|
|
|
|
|
|
|
|
| 224 |
### 0.9
|
| 225 |
Fixes media modal for newer versions of WordPress. Tested up to WordPress 4.3.1 (requires 3.4+).
|
| 226 |
|
|
@@ -233,6 +236,10 @@ Complete rewrite. Better everything. Many bug fixes.
|
|
| 233 |
Changelog
|
| 234 |
---------
|
| 235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
### 0.9
|
| 237 |
* __COMPAT:__ Add support for WordPress 3.5+ media modal.
|
| 238 |
* __COMPAT:__ Confirmed minimum WordPress 3.4 required.
|
| 207 |
Need More Taxonomy Plugins?
|
| 208 |
---------------------------
|
| 209 |
|
| 210 |
+
The original author of this plugin, Michael Fields, released a handful of plugins dealing with taxonomies. Please see his [WordPress.org profile](https://profiles.wordpress.org/mfields/) for more information.
|
| 211 |
|
| 212 |
Installation
|
| 213 |
------------
|
| 221 |
Upgrade Notice
|
| 222 |
--------------
|
| 223 |
|
| 224 |
+
### 0.9.1
|
| 225 |
+
Fixes media modal not opening on newly created terms.
|
| 226 |
+
|
| 227 |
### 0.9
|
| 228 |
Fixes media modal for newer versions of WordPress. Tested up to WordPress 4.3.1 (requires 3.4+).
|
| 229 |
|
| 236 |
Changelog
|
| 237 |
---------
|
| 238 |
|
| 239 |
+
### 0.9.1
|
| 240 |
+
* __BUGFIX:__ Fixes media modal not opening on newly created terms.
|
| 241 |
+
* __UPDATE:__ Adhere to WordPress PHP coding standards.
|
| 242 |
+
|
| 243 |
### 0.9
|
| 244 |
* __COMPAT:__ Add support for WordPress 3.5+ media modal.
|
| 245 |
* __COMPAT:__ Confirmed minimum WordPress 3.4 required.
|
readme.txt
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
=== Taxonomy Images ===
|
| 2 |
-
|
| 3 |
Contributors: mfields, husobj, jamiemchale
|
| 4 |
-
|
|
|
|
| 5 |
Requires at least: 3.4
|
| 6 |
Tested up to: 4.3.1
|
| 7 |
-
Stable tag: 0.9
|
| 8 |
License: GPLv2 or later
|
|
|
|
| 9 |
|
| 10 |
Associate images from your media library to categories, tags and custom taxonomies.
|
| 11 |
|
|
@@ -190,7 +191,7 @@ If you have fallen in love with this plugin and would not be able to sleep witho
|
|
| 190 |
|
| 191 |
= Need More Taxonomy Plugins? =
|
| 192 |
|
| 193 |
-
The original author of this plugin, Michael Fields, released a handful of plugins dealing with taxonomies. Please see his [
|
| 194 |
|
| 195 |
== Installation ==
|
| 196 |
|
|
@@ -208,6 +209,9 @@ The original author of this plugin, Michael Fields, released a handful of plugin
|
|
| 208 |
|
| 209 |
== Upgrade Notice ==
|
| 210 |
|
|
|
|
|
|
|
|
|
|
| 211 |
= 0.9 =
|
| 212 |
Fixes media modal for newer versions of WordPress. Tested up to WordPress 4.3.1 (requires 3.4+).
|
| 213 |
|
|
@@ -219,6 +223,10 @@ Complete rewrite. Better everything. Many bug fixes.
|
|
| 219 |
|
| 220 |
== Changelog ==
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
= 0.9 =
|
| 223 |
* __COMPAT:__ Add support for WordPress 3.5+ media modal.
|
| 224 |
* __COMPAT:__ Confirmed minimum WordPress 3.4 required.
|
| 1 |
=== Taxonomy Images ===
|
|
|
|
| 2 |
Contributors: mfields, husobj, jamiemchale
|
| 3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QSYTTQZBRKQVE
|
| 4 |
+
Tags: taxonomy, tag, category, term, image, upload, media
|
| 5 |
Requires at least: 3.4
|
| 6 |
Tested up to: 4.3.1
|
| 7 |
+
Stable tag: 0.9.1
|
| 8 |
License: GPLv2 or later
|
| 9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
| 11 |
Associate images from your media library to categories, tags and custom taxonomies.
|
| 12 |
|
| 191 |
|
| 192 |
= Need More Taxonomy Plugins? =
|
| 193 |
|
| 194 |
+
The original author of this plugin, Michael Fields, released a handful of plugins dealing with taxonomies. Please see his [WordPress.org profile](https://profiles.wordpress.org/mfields/) for more information.
|
| 195 |
|
| 196 |
== Installation ==
|
| 197 |
|
| 209 |
|
| 210 |
== Upgrade Notice ==
|
| 211 |
|
| 212 |
+
= 0.9.1 =
|
| 213 |
+
Fixes media modal not opening on newly created terms.
|
| 214 |
+
|
| 215 |
= 0.9 =
|
| 216 |
Fixes media modal for newer versions of WordPress. Tested up to WordPress 4.3.1 (requires 3.4+).
|
| 217 |
|
| 223 |
|
| 224 |
== Changelog ==
|
| 225 |
|
| 226 |
+
= 0.9.1 =
|
| 227 |
+
* __BUGFIX:__ Fixes media modal not opening on newly created terms.
|
| 228 |
+
* __UPDATE:__ Adhere to WordPress PHP coding standards.
|
| 229 |
+
|
| 230 |
= 0.9 =
|
| 231 |
* __COMPAT:__ Add support for WordPress 3.5+ media modal.
|
| 232 |
* __COMPAT:__ Confirmed minimum WordPress 3.4 required.
|
taxonomy-images.php
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
/*
|
| 3 |
Plugin Name: Taxonomy Images
|
| 4 |
Plugin URI: https://github.com/benhuson/Taxonomy-Images
|
| 5 |
Description: Associate images from your media library to categories, tags and custom taxonomies.
|
| 6 |
-
Version: 0.9
|
| 7 |
Author: Michael Fields, Ben Huson
|
| 8 |
Author URI: http://wordpress.mfields.org/
|
| 9 |
License: GNU General Public License v2 or later
|
|
@@ -39,7 +40,7 @@ require_once( trailingslashit( dirname( __FILE__ ) ) . 'public-filters.php' );
|
|
| 39 |
* @alter 0.7.4
|
| 40 |
*/
|
| 41 |
function taxonomy_image_plugin_version() {
|
| 42 |
-
return '0.9';
|
| 43 |
}
|
| 44 |
|
| 45 |
|
|
@@ -121,19 +122,13 @@ function taxonomy_image_plugin_modal_button( $fields, $post ) {
|
|
| 121 |
if ( isset( $fields['image-size'] ) && isset( $post->ID ) ) {
|
| 122 |
$image_id = (int) $post->ID;
|
| 123 |
|
| 124 |
-
$o
|
| 125 |
-
|
| 126 |
-
$o.= '<span class="
|
| 127 |
-
|
| 128 |
-
$o.= '<
|
| 129 |
-
|
| 130 |
-
$o.= '
|
| 131 |
-
|
| 132 |
-
$o.= '<input class="taxonomy-image-button-nonce-create" name="' . esc_attr( 'taxonomy-image-button-nonce-create-' . $image_id ) . '" type="hidden" value="' . esc_attr( wp_create_nonce( 'taxonomy-image-plugin-create-association' ) ) . '" />';
|
| 133 |
-
|
| 134 |
-
$o.= '<input class="taxonomy-image-button-nonce-remove" name="' . esc_attr( 'taxonomy-image-button-nonce-remove-' . $image_id ) . '" type="hidden" value="' . esc_attr( wp_create_nonce( 'taxonomy-image-plugin-remove-association' ) ) . '" />';
|
| 135 |
-
|
| 136 |
-
$o.= '</div>';
|
| 137 |
|
| 138 |
$fields['image-size']['extra_rows']['taxonomy-image-plugin-button']['html'] = $o;
|
| 139 |
}
|
|
@@ -161,8 +156,9 @@ function taxonomy_image_plugin_get_image_src( $id ) {
|
|
| 161 |
|
| 162 |
/* Return url to custom intermediate size if it exists. */
|
| 163 |
$img = image_get_intermediate_size( $id, $detail['name'] );
|
| 164 |
-
if ( isset( $img['url'] ) )
|
| 165 |
return $img['url'];
|
|
|
|
| 166 |
|
| 167 |
/* Detail image does not exist, attempt to create it. */
|
| 168 |
$wp_upload_dir = wp_upload_dir();
|
|
@@ -177,7 +173,7 @@ function taxonomy_image_plugin_get_image_src( $id ) {
|
|
| 177 |
$detail['size'][0],
|
| 178 |
$detail['size'][1],
|
| 179 |
$detail['size'][2]
|
| 180 |
-
|
| 181 |
|
| 182 |
/* Image creation successful. Generate and cache image metadata. Return url. */
|
| 183 |
if ( ! is_wp_error( $new ) ) {
|
|
@@ -193,15 +189,17 @@ function taxonomy_image_plugin_get_image_src( $id ) {
|
|
| 193 |
|
| 194 |
/* Custom intermediate size cannot be created, try for thumbnail. */
|
| 195 |
$img = image_get_intermediate_size( $id, 'thumbnail' );
|
| 196 |
-
if ( isset( $img['url'] ) )
|
| 197 |
return $img['url'];
|
|
|
|
| 198 |
|
| 199 |
/* Thumbnail cannot be found, try fullsize. */
|
| 200 |
$url = wp_get_attachment_url( $id );
|
| 201 |
-
if ( ! empty( $url ) )
|
| 202 |
return $url;
|
|
|
|
| 203 |
|
| 204 |
-
|
| 205 |
* No image can be found.
|
| 206 |
* This is most likely caused by a user deleting an attachment before deleting it's association with a taxonomy.
|
| 207 |
* If we are in the administration panels:
|
|
@@ -212,7 +210,7 @@ function taxonomy_image_plugin_get_image_src( $id ) {
|
|
| 212 |
$assoc = taxonomy_image_plugin_get_associations();
|
| 213 |
foreach ( $assoc as $term => $img ) {
|
| 214 |
if ( $img === $id ) {
|
| 215 |
-
unset( $assoc[$term] );
|
| 216 |
}
|
| 217 |
}
|
| 218 |
update_option( 'taxonomy_image_plugin', $assoc );
|
|
@@ -244,7 +242,7 @@ function taxonomy_image_plugin_sanitize_associations( $associations ) {
|
|
| 244 |
$tt_id = absint( $tt_id );
|
| 245 |
$im_id = absint( $im_id );
|
| 246 |
if ( 0 < $tt_id && 0 < $im_id )
|
| 247 |
-
$o[$tt_id] = $im_id;
|
| 248 |
}
|
| 249 |
return $o;
|
| 250 |
}
|
|
@@ -342,8 +340,8 @@ add_action( 'admin_init', 'taxonomy_image_plugin_register_settings' );
|
|
| 342 |
*/
|
| 343 |
function taxonomy_images_settings_menu() {
|
| 344 |
add_options_page(
|
| 345 |
-
esc_html__( 'Taxonomy Images', 'taxonomy-images' ),
|
| 346 |
-
esc_html__( 'Taxonomy Images', 'taxonomy-images' ),
|
| 347 |
'manage_options',
|
| 348 |
'taxonomy_image_plugin_settings',
|
| 349 |
'taxonomy_image_plugin_settings_page'
|
|
@@ -391,20 +389,24 @@ function taxonomy_image_plugin_control_taxonomies() {
|
|
| 391 |
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
| 392 |
$taxonomies = get_taxonomies( array(), 'objects' );
|
| 393 |
foreach ( (array) $taxonomies as $taxonomy ) {
|
| 394 |
-
if ( ! isset( $taxonomy->name ) )
|
| 395 |
continue;
|
|
|
|
| 396 |
|
| 397 |
-
if ( ! isset( $taxonomy->label ) )
|
| 398 |
continue;
|
|
|
|
| 399 |
|
| 400 |
-
if ( ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) )
|
| 401 |
continue;
|
|
|
|
| 402 |
|
| 403 |
$id = 'taxonomy-images-' . $taxonomy->name;
|
| 404 |
|
| 405 |
$checked = '';
|
| 406 |
-
if ( isset( $settings['taxonomies'] ) && in_array( $taxonomy->name, (array) $settings['taxonomies'] ) )
|
| 407 |
$checked = ' checked="checked"';
|
|
|
|
| 408 |
|
| 409 |
print "\n" . '<p><label for="' . esc_attr( $id ) . '">';
|
| 410 |
print '<input' . $checked . ' id="' . esc_attr( $id ) . '" type="checkbox" name="taxonomy_image_plugin_settings[taxonomies][]" value="' . esc_attr( $taxonomy->name ) . '" />';
|
|
@@ -445,21 +447,24 @@ function taxonomy_image_plugin_json_response( $args ) {
|
|
| 445 |
*/
|
| 446 |
function taxonomy_image_plugin_get_term_info( $tt_id ) {
|
| 447 |
static $cache = array();
|
| 448 |
-
if ( isset( $cache[$tt_id] ) ) {
|
| 449 |
-
return $cache[$tt_id];
|
| 450 |
}
|
| 451 |
|
| 452 |
global $wpdb;
|
| 453 |
|
| 454 |
$data = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d LIMIT 1", $tt_id ) );
|
| 455 |
-
if ( isset( $data[0]->term_id ) )
|
| 456 |
-
$cache[$tt_id]['term_id'] = absint( $data[0]->term_id );
|
|
|
|
| 457 |
|
| 458 |
-
if ( isset( $data[0]->taxonomy ) )
|
| 459 |
-
$cache[$tt_id]['taxonomy'] = sanitize_title_with_dashes( $data[0]->taxonomy );
|
|
|
|
| 460 |
|
| 461 |
-
if ( isset( $cache[$tt_id] ) )
|
| 462 |
-
return $cache[$tt_id];
|
|
|
|
| 463 |
|
| 464 |
return array();
|
| 465 |
}
|
|
@@ -478,12 +483,14 @@ function taxonomy_image_plugin_get_term_info( $tt_id ) {
|
|
| 478 |
*/
|
| 479 |
function taxonomy_image_plugin_check_permissions( $tt_id ) {
|
| 480 |
$data = taxonomy_image_plugin_get_term_info( $tt_id );
|
| 481 |
-
if ( ! isset( $data['taxonomy'] ) )
|
| 482 |
return false;
|
|
|
|
| 483 |
|
| 484 |
$taxonomy = get_taxonomy( $data['taxonomy'] );
|
| 485 |
-
if ( ! isset( $taxonomy->cap->edit_terms ) )
|
| 486 |
return false;
|
|
|
|
| 487 |
|
| 488 |
return current_user_can( $taxonomy->cap->edit_terms );
|
| 489 |
}
|
|
@@ -549,15 +556,14 @@ function taxonomy_image_plugin_create_association() {
|
|
| 549 |
}
|
| 550 |
|
| 551 |
$assoc = taxonomy_image_plugin_get_associations();
|
| 552 |
-
$assoc[$tt_id] = $image_id;
|
| 553 |
if ( update_option( 'taxonomy_image_plugin', taxonomy_image_plugin_sanitize_associations( $assoc ) ) ) {
|
| 554 |
taxonomy_image_plugin_json_response( array(
|
| 555 |
'status' => 'good',
|
| 556 |
'why' => esc_html__( 'Image successfully associated', 'taxonomy-images' ),
|
| 557 |
'attachment_thumb_src' => taxonomy_image_plugin_get_image_src( $image_id )
|
| 558 |
) );
|
| 559 |
-
}
|
| 560 |
-
else {
|
| 561 |
taxonomy_image_plugin_json_response( array(
|
| 562 |
'status' => 'bad',
|
| 563 |
'why' => esc_html__( 'Association could not be created', 'taxonomy-images' )
|
|
@@ -616,22 +622,21 @@ function taxonomy_image_plugin_remove_association() {
|
|
| 616 |
}
|
| 617 |
|
| 618 |
$assoc = taxonomy_image_plugin_get_associations();
|
| 619 |
-
if ( ! isset( $assoc[$tt_id] ) ) {
|
| 620 |
taxonomy_image_plugin_json_response( array(
|
| 621 |
'status' => 'good',
|
| 622 |
'why' => esc_html__( 'Nothing to remove', 'taxonomy-images' )
|
| 623 |
) );
|
| 624 |
}
|
| 625 |
|
| 626 |
-
unset( $assoc[$tt_id] );
|
| 627 |
|
| 628 |
if ( update_option( 'taxonomy_image_plugin', $assoc ) ) {
|
| 629 |
taxonomy_image_plugin_json_response( array(
|
| 630 |
'status' => 'good',
|
| 631 |
'why' => esc_html__( 'Association successfully removed', 'taxonomy-images' )
|
| 632 |
) );
|
| 633 |
-
}
|
| 634 |
-
else {
|
| 635 |
taxonomy_image_plugin_json_response( array(
|
| 636 |
'status' => 'bad',
|
| 637 |
'why' => esc_html__( 'Association could not be removed', 'taxonomy-images' )
|
|
@@ -655,8 +660,9 @@ add_action( 'wp_ajax_taxonomy_image_plugin_remove_association', 'taxonomy_image_
|
|
| 655 |
*/
|
| 656 |
function taxonomy_image_plugin_get_associations( $refresh = false ) {
|
| 657 |
static $associations = array();
|
| 658 |
-
if ( empty( $associations ) || $refresh )
|
| 659 |
$associations = taxonomy_image_plugin_sanitize_associations( get_option( 'taxonomy_image_plugin' ) );
|
|
|
|
| 660 |
|
| 661 |
return $associations;
|
| 662 |
}
|
|
@@ -676,8 +682,9 @@ add_action( 'init', 'taxonomy_image_plugin_get_associations' );
|
|
| 676 |
*/
|
| 677 |
function taxonomy_image_plugin_add_dynamic_hooks() {
|
| 678 |
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
| 679 |
-
if ( ! isset( $settings['taxonomies'] ) )
|
| 680 |
return;
|
|
|
|
| 681 |
|
| 682 |
foreach ( $settings['taxonomies'] as $taxonomy ) {
|
| 683 |
add_filter( 'manage_' . $taxonomy . '_custom_column', 'taxonomy_image_plugin_taxonomy_rows', 15, 3 );
|
|
@@ -776,14 +783,16 @@ function taxonomy_image_plugin_control_image( $term_id, $taxonomy ) {
|
|
| 776 |
$term = get_term( $term_id, $taxonomy );
|
| 777 |
|
| 778 |
$tt_id = 0;
|
| 779 |
-
if ( isset( $term->term_taxonomy_id ) )
|
| 780 |
$tt_id = (int) $term->term_taxonomy_id;
|
|
|
|
| 781 |
|
| 782 |
$taxonomy = get_taxonomy( $taxonomy );
|
| 783 |
|
| 784 |
$name = esc_html__( 'term', 'taxonomy-images' );
|
| 785 |
-
if ( isset( $taxonomy->labels->singular_name ) )
|
| 786 |
$name = strtolower( $taxonomy->labels->singular_name );
|
|
|
|
| 787 |
|
| 788 |
$hide = ' hide';
|
| 789 |
$attachment_id = 0;
|
|
@@ -800,18 +809,18 @@ function taxonomy_image_plugin_control_image( $term_id, $taxonomy ) {
|
|
| 800 |
$nonce = wp_create_nonce( 'taxonomy-image-plugin-create-association' );
|
| 801 |
$nonce_remove = wp_create_nonce( 'taxonomy-image-plugin-remove-association' );
|
| 802 |
|
| 803 |
-
$o
|
| 804 |
-
$o.= "\n" . '<a class="thickbox taxonomy-image-thumbnail" data-tt-id="' . $tt_id . '" data-attachment-id="' . $attachment_id . '" data-nonce="' . $nonce . '" href="' . esc_url( admin_url( 'media-upload.php' ) . '?type=image&tab=library&post_id=0&TB_iframe=true' ) . '" title="' . esc_attr( sprintf( __( 'Associate an image with the %1$s named “%2$s”.', 'taxonomy-images' ), $name, $term->name ) ) . '"><img id="' . esc_attr( 'taxonomy_image_plugin_' . $tt_id ) . '" src="' . esc_url( $img ) . '" alt="" /></a>';
|
| 805 |
-
$o.= "\n" . '<a class="control upload thickbox" data-tt-id="' . $tt_id . '" data-attachment-id="' . $attachment_id . '" data-nonce="' . $nonce . '" href="' . esc_url( admin_url( 'media-upload.php' ) . '?type=image&tab=type&post_id=0&TB_iframe=true' ) . '" title="' . esc_attr( sprintf( __( 'Upload a new image for this %s.', 'taxonomy-images' ), $name ) ) . '">' . esc_html__( 'Upload.', 'taxonomy-images' ) . '</a>';
|
| 806 |
-
$o.= "\n" . '<a class="control remove' . $hide . '" data-tt-id="' . $tt_id . '" data-nonce="' . $nonce_remove . '" href="#" id="' . esc_attr( 'remove-' . $tt_id ) . '" rel="' . esc_attr( $tt_id ) . '" title="' . esc_attr( sprintf( __( 'Remove image from this %s.', 'taxonomy-images' ), $name ) ) . '">' . esc_html__( 'Delete', 'taxonomy-images' ) . '</a>';
|
| 807 |
-
$o.= "\n" . '<input type="hidden" class="tt_id" name="' . esc_attr( 'tt_id-' . $tt_id ) . '" value="' . esc_attr( $tt_id ) . '" />';
|
|
|
|
| 808 |
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
$o.= "\n" . '<input type="hidden" class="term_name" name="' . esc_attr( 'term_name-' . $term->slug ) . '" value="' . esc_attr( $term->name ) . '" />';
|
| 813 |
|
| 814 |
-
$o.= "\n" . '</div>';
|
| 815 |
return $o;
|
| 816 |
}
|
| 817 |
|
|
@@ -835,7 +844,7 @@ function taxonomy_image_plugin_media_upload_popup_js() {
|
|
| 835 |
array( 'jquery' ),
|
| 836 |
taxonomy_image_plugin_version()
|
| 837 |
);
|
| 838 |
-
wp_localize_script( 'taxonomy-images-media-upload-popup', 'TaxonomyImagesModal', array
|
| 839 |
'termBefore' => esc_html__( '“', 'taxonomy-images' ),
|
| 840 |
'termAfter' => esc_html__( '”', 'taxonomy-images' ),
|
| 841 |
'associating' => esc_html__( 'Associating …', 'taxonomy-images' ),
|
|
@@ -853,8 +862,9 @@ add_action( 'admin_print_scripts-media-upload-popup', 'taxonomy_image_plugin_med
|
|
| 853 |
* @access private
|
| 854 |
*/
|
| 855 |
function taxonomy_image_plugin_edit_tags_js() {
|
| 856 |
-
if ( false == taxonomy_image_plugin_is_screen_active() )
|
| 857 |
return;
|
|
|
|
| 858 |
|
| 859 |
if ( version_compare( get_bloginfo( 'version' ), 3.5 ) >= 0 ) {
|
| 860 |
return;
|
|
@@ -866,7 +876,7 @@ function taxonomy_image_plugin_edit_tags_js() {
|
|
| 866 |
array( 'jquery', 'thickbox' ),
|
| 867 |
taxonomy_image_plugin_version()
|
| 868 |
);
|
| 869 |
-
wp_localize_script( 'taxonomy-image-plugin-edit-tags', 'taxonomyImagesPlugin', array
|
| 870 |
'nonce' => wp_create_nonce( 'taxonomy-image-plugin-remove-association' ),
|
| 871 |
'img_src' => taxonomy_image_plugin_url( 'default.png' ),
|
| 872 |
'tt_id' => 0,
|
|
@@ -883,8 +893,9 @@ add_action( 'admin_print_scripts-edit-tags.php', 'taxonomy_image_plugin_edit_tag
|
|
| 883 |
* @access private
|
| 884 |
*/
|
| 885 |
function taxonomy_image_plugin_css_admin() {
|
| 886 |
-
if ( false == taxonomy_image_plugin_is_screen_active() && 'admin_print_styles-media-upload-popup'
|
| 887 |
return;
|
|
|
|
| 888 |
|
| 889 |
wp_enqueue_style(
|
| 890 |
'taxonomy-image-plugin-edit-tags',
|
|
@@ -905,8 +916,9 @@ add_action( 'admin_print_styles-media-upload-popup', 'taxonomy_image_plugin_css_
|
|
| 905 |
* @access private
|
| 906 |
*/
|
| 907 |
function taxonomy_image_plugin_css_thickbox() {
|
| 908 |
-
if ( false == taxonomy_image_plugin_is_screen_active() )
|
| 909 |
return;
|
|
|
|
| 910 |
|
| 911 |
wp_enqueue_style( 'thickbox' );
|
| 912 |
}
|
|
@@ -927,8 +939,9 @@ add_action( 'admin_print_styles-edit-tags.php', 'taxonomy_image_plugin_css_thick
|
|
| 927 |
* @access private
|
| 928 |
*/
|
| 929 |
function taxonomy_image_plugin_css_public() {
|
| 930 |
-
if ( apply_filters( 'taxonomy-images-disable-public-css', false ) )
|
| 931 |
return;
|
|
|
|
| 932 |
|
| 933 |
wp_enqueue_style(
|
| 934 |
'taxonomy-image-plugin-public',
|
|
@@ -962,8 +975,9 @@ add_action( 'wp_enqueue_scripts', 'taxonomy_image_plugin_css_public' );
|
|
| 962 |
*/
|
| 963 |
function taxonomy_image_plugin_activate() {
|
| 964 |
$associations = get_option( 'taxonomy_image_plugin' );
|
| 965 |
-
if ( false === $associations )
|
| 966 |
add_option( 'taxonomy_image_plugin', array() );
|
|
|
|
| 967 |
|
| 968 |
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
| 969 |
if ( false === $settings ) {
|
|
@@ -985,15 +999,18 @@ register_activation_hook( __FILE__, 'taxonomy_image_plugin_activate' );
|
|
| 985 |
*/
|
| 986 |
function taxonomy_image_plugin_is_screen_active() {
|
| 987 |
$screen = get_current_screen();
|
| 988 |
-
if ( ! isset( $screen->taxonomy ) )
|
| 989 |
return false;
|
|
|
|
| 990 |
|
| 991 |
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
| 992 |
-
if ( ! isset( $settings['taxonomies'] ) )
|
| 993 |
return false;
|
|
|
|
| 994 |
|
| 995 |
-
if ( in_array( $screen->taxonomy, $settings['taxonomies'] ) )
|
| 996 |
return true;
|
|
|
|
| 997 |
|
| 998 |
return false;
|
| 999 |
}
|
|
@@ -1014,17 +1031,20 @@ function taxonomy_image_plugin_is_screen_active() {
|
|
| 1014 |
*/
|
| 1015 |
function taxonomy_image_plugin_cache_images( $posts ) {
|
| 1016 |
$assoc = taxonomy_image_plugin_get_associations();
|
| 1017 |
-
if ( empty( $assoc ) )
|
| 1018 |
return;
|
|
|
|
| 1019 |
|
| 1020 |
$tt_ids = array();
|
| 1021 |
foreach ( (array) $posts as $post ) {
|
| 1022 |
-
if ( ! isset( $post->ID ) || ! isset( $post->post_type ) )
|
| 1023 |
continue;
|
|
|
|
| 1024 |
|
| 1025 |
$taxonomies = get_object_taxonomies( $post->post_type );
|
| 1026 |
-
if ( empty( $taxonomies ) )
|
| 1027 |
continue;
|
|
|
|
| 1028 |
|
| 1029 |
foreach ( $taxonomies as $taxonomy ) {
|
| 1030 |
$the_terms = get_the_terms( $post->ID, $taxonomy );
|
|
@@ -1040,17 +1060,20 @@ function taxonomy_image_plugin_cache_images( $posts ) {
|
|
| 1040 |
|
| 1041 |
$image_ids = array();
|
| 1042 |
foreach ( $tt_ids as $tt_id ) {
|
| 1043 |
-
if ( ! isset( $assoc[$tt_id] ) )
|
| 1044 |
continue;
|
|
|
|
| 1045 |
|
| 1046 |
-
if ( in_array( $assoc[$tt_id], $image_ids ) )
|
| 1047 |
continue;
|
|
|
|
| 1048 |
|
| 1049 |
-
$image_ids[] = $assoc[$tt_id];
|
| 1050 |
}
|
| 1051 |
|
| 1052 |
-
if ( empty( $image_ids ) )
|
| 1053 |
return;
|
|
|
|
| 1054 |
|
| 1055 |
$images = get_posts( array(
|
| 1056 |
'include' => $image_ids,
|
|
@@ -1094,9 +1117,9 @@ add_action( 'template_redirect', 'taxonomy_image_plugin_cache_queried_images' );
|
|
| 1094 |
function taxonomy_image_plugin_check_taxonomy( $taxonomy, $filter ) {
|
| 1095 |
if ( ! taxonomy_exists( $taxonomy ) ) {
|
| 1096 |
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' ),
|
| 1097 |
-
|
| 1098 |
-
|
| 1099 |
-
|
| 1100 |
) );
|
| 1101 |
return false;
|
| 1102 |
}
|
|
@@ -1157,15 +1180,18 @@ function taxonomy_image_plugin_please_use_filter( $function, $filter ) {
|
|
| 1157 |
function taxonomy_images_plugin_row_meta( $links, $file ) {
|
| 1158 |
static $plugin_name = '';
|
| 1159 |
|
| 1160 |
-
if ( empty( $plugin_name ) )
|
| 1161 |
$plugin_name = plugin_basename( __FILE__ );
|
|
|
|
| 1162 |
|
| 1163 |
-
if ( $plugin_name != $file )
|
| 1164 |
return $links;
|
|
|
|
| 1165 |
|
| 1166 |
$link = taxonomy_images_plugin_settings_page_link( esc_html__( 'Settings', 'taxonomy-images' ) );
|
| 1167 |
-
if ( ! empty( $link ) )
|
| 1168 |
$links[] = $link;
|
|
|
|
| 1169 |
|
| 1170 |
$links[] = '<a href="http://wordpress.mfields.org/donate/">' . esc_html__( 'Donate', 'taxonomy-images' ) . '</a>';
|
| 1171 |
|
|
@@ -1184,12 +1210,14 @@ add_filter( 'plugin_row_meta', 'taxonomy_images_plugin_row_meta', 10, 2 );
|
|
| 1184 |
* @since 0.7
|
| 1185 |
*/
|
| 1186 |
function taxonomy_images_plugin_settings_page_link( $link_text = '' ) {
|
| 1187 |
-
if ( empty( $link_text ) )
|
| 1188 |
$link_text = __( 'Manage Settings', 'taxonomy-images' );
|
|
|
|
| 1189 |
|
| 1190 |
$link = '';
|
| 1191 |
-
if ( current_user_can( 'manage_options' ) )
|
| 1192 |
$link = '<a href="' . esc_url( add_query_arg( array( 'page' => 'taxonomy_image_plugin_settings' ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html( $link_text ) . '</a>';
|
|
|
|
| 1193 |
|
| 1194 |
return $link;
|
| 1195 |
}
|
| 1 |
<?php
|
| 2 |
+
|
| 3 |
/*
|
| 4 |
Plugin Name: Taxonomy Images
|
| 5 |
Plugin URI: https://github.com/benhuson/Taxonomy-Images
|
| 6 |
Description: Associate images from your media library to categories, tags and custom taxonomies.
|
| 7 |
+
Version: 0.9.1
|
| 8 |
Author: Michael Fields, Ben Huson
|
| 9 |
Author URI: http://wordpress.mfields.org/
|
| 10 |
License: GNU General Public License v2 or later
|
| 40 |
* @alter 0.7.4
|
| 41 |
*/
|
| 42 |
function taxonomy_image_plugin_version() {
|
| 43 |
+
return '0.9.1';
|
| 44 |
}
|
| 45 |
|
| 46 |
|
| 122 |
if ( isset( $fields['image-size'] ) && isset( $post->ID ) ) {
|
| 123 |
$image_id = (int) $post->ID;
|
| 124 |
|
| 125 |
+
$o = '<div class="taxonomy-image-modal-control" id="' . esc_attr( 'taxonomy-image-modal-control-' . $image_id ) . '">';
|
| 126 |
+
$o .= '<span class="button create-association">' . sprintf( esc_html__( 'Associate with %1$s', 'taxonomy-images' ), '<span class="term-name">' . esc_html__( 'this term', 'taxonomy-images' ) . '</span>' ) . '</span>';
|
| 127 |
+
$o .= '<span class="remove-association">' . sprintf( esc_html__( 'Remove association with %1$s', 'taxonomy-images' ), '<span class="term-name">' . esc_html__( 'this term', 'taxonomy-images' ) . '</span>' ) . '</span>';
|
| 128 |
+
$o .= '<input class="taxonomy-image-button-image-id" name="' . esc_attr( 'taxonomy-image-button-image-id-' . $image_id ) . '" type="hidden" value="' . esc_attr( $image_id ) . '" />';
|
| 129 |
+
$o .= '<input class="taxonomy-image-button-nonce-create" name="' . esc_attr( 'taxonomy-image-button-nonce-create-' . $image_id ) . '" type="hidden" value="' . esc_attr( wp_create_nonce( 'taxonomy-image-plugin-create-association' ) ) . '" />';
|
| 130 |
+
$o .= '<input class="taxonomy-image-button-nonce-remove" name="' . esc_attr( 'taxonomy-image-button-nonce-remove-' . $image_id ) . '" type="hidden" value="' . esc_attr( wp_create_nonce( 'taxonomy-image-plugin-remove-association' ) ) . '" />';
|
| 131 |
+
$o .= '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
$fields['image-size']['extra_rows']['taxonomy-image-plugin-button']['html'] = $o;
|
| 134 |
}
|
| 156 |
|
| 157 |
/* Return url to custom intermediate size if it exists. */
|
| 158 |
$img = image_get_intermediate_size( $id, $detail['name'] );
|
| 159 |
+
if ( isset( $img['url'] ) ) {
|
| 160 |
return $img['url'];
|
| 161 |
+
}
|
| 162 |
|
| 163 |
/* Detail image does not exist, attempt to create it. */
|
| 164 |
$wp_upload_dir = wp_upload_dir();
|
| 173 |
$detail['size'][0],
|
| 174 |
$detail['size'][1],
|
| 175 |
$detail['size'][2]
|
| 176 |
+
);
|
| 177 |
|
| 178 |
/* Image creation successful. Generate and cache image metadata. Return url. */
|
| 179 |
if ( ! is_wp_error( $new ) ) {
|
| 189 |
|
| 190 |
/* Custom intermediate size cannot be created, try for thumbnail. */
|
| 191 |
$img = image_get_intermediate_size( $id, 'thumbnail' );
|
| 192 |
+
if ( isset( $img['url'] ) ) {
|
| 193 |
return $img['url'];
|
| 194 |
+
}
|
| 195 |
|
| 196 |
/* Thumbnail cannot be found, try fullsize. */
|
| 197 |
$url = wp_get_attachment_url( $id );
|
| 198 |
+
if ( ! empty( $url ) ) {
|
| 199 |
return $url;
|
| 200 |
+
}
|
| 201 |
|
| 202 |
+
/**
|
| 203 |
* No image can be found.
|
| 204 |
* This is most likely caused by a user deleting an attachment before deleting it's association with a taxonomy.
|
| 205 |
* If we are in the administration panels:
|
| 210 |
$assoc = taxonomy_image_plugin_get_associations();
|
| 211 |
foreach ( $assoc as $term => $img ) {
|
| 212 |
if ( $img === $id ) {
|
| 213 |
+
unset( $assoc[ $term ] );
|
| 214 |
}
|
| 215 |
}
|
| 216 |
update_option( 'taxonomy_image_plugin', $assoc );
|
| 242 |
$tt_id = absint( $tt_id );
|
| 243 |
$im_id = absint( $im_id );
|
| 244 |
if ( 0 < $tt_id && 0 < $im_id )
|
| 245 |
+
$o[ $tt_id ] = $im_id;
|
| 246 |
}
|
| 247 |
return $o;
|
| 248 |
}
|
| 340 |
*/
|
| 341 |
function taxonomy_images_settings_menu() {
|
| 342 |
add_options_page(
|
| 343 |
+
esc_html__( 'Taxonomy Images', 'taxonomy-images' ), // HTML <title> tag.
|
| 344 |
+
esc_html__( 'Taxonomy Images', 'taxonomy-images' ), // Link text in admin menu.
|
| 345 |
'manage_options',
|
| 346 |
'taxonomy_image_plugin_settings',
|
| 347 |
'taxonomy_image_plugin_settings_page'
|
| 389 |
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
| 390 |
$taxonomies = get_taxonomies( array(), 'objects' );
|
| 391 |
foreach ( (array) $taxonomies as $taxonomy ) {
|
| 392 |
+
if ( ! isset( $taxonomy->name ) ) {
|
| 393 |
continue;
|
| 394 |
+
}
|
| 395 |
|
| 396 |
+
if ( ! isset( $taxonomy->label ) ) {
|
| 397 |
continue;
|
| 398 |
+
}
|
| 399 |
|
| 400 |
+
if ( ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) ) {
|
| 401 |
continue;
|
| 402 |
+
}
|
| 403 |
|
| 404 |
$id = 'taxonomy-images-' . $taxonomy->name;
|
| 405 |
|
| 406 |
$checked = '';
|
| 407 |
+
if ( isset( $settings['taxonomies'] ) && in_array( $taxonomy->name, (array) $settings['taxonomies'] ) ) {
|
| 408 |
$checked = ' checked="checked"';
|
| 409 |
+
}
|
| 410 |
|
| 411 |
print "\n" . '<p><label for="' . esc_attr( $id ) . '">';
|
| 412 |
print '<input' . $checked . ' id="' . esc_attr( $id ) . '" type="checkbox" name="taxonomy_image_plugin_settings[taxonomies][]" value="' . esc_attr( $taxonomy->name ) . '" />';
|
| 447 |
*/
|
| 448 |
function taxonomy_image_plugin_get_term_info( $tt_id ) {
|
| 449 |
static $cache = array();
|
| 450 |
+
if ( isset( $cache[ $tt_id ] ) ) {
|
| 451 |
+
return $cache[ $tt_id ];
|
| 452 |
}
|
| 453 |
|
| 454 |
global $wpdb;
|
| 455 |
|
| 456 |
$data = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d LIMIT 1", $tt_id ) );
|
| 457 |
+
if ( isset( $data[0]->term_id ) ) {
|
| 458 |
+
$cache[ $tt_id ]['term_id'] = absint( $data[0]->term_id );
|
| 459 |
+
}
|
| 460 |
|
| 461 |
+
if ( isset( $data[0]->taxonomy ) ) {
|
| 462 |
+
$cache[ $tt_id ]['taxonomy'] = sanitize_title_with_dashes( $data[0]->taxonomy );
|
| 463 |
+
}
|
| 464 |
|
| 465 |
+
if ( isset( $cache[ $tt_id ] ) ) {
|
| 466 |
+
return $cache[ $tt_id ];
|
| 467 |
+
}
|
| 468 |
|
| 469 |
return array();
|
| 470 |
}
|
| 483 |
*/
|
| 484 |
function taxonomy_image_plugin_check_permissions( $tt_id ) {
|
| 485 |
$data = taxonomy_image_plugin_get_term_info( $tt_id );
|
| 486 |
+
if ( ! isset( $data['taxonomy'] ) ) {
|
| 487 |
return false;
|
| 488 |
+
}
|
| 489 |
|
| 490 |
$taxonomy = get_taxonomy( $data['taxonomy'] );
|
| 491 |
+
if ( ! isset( $taxonomy->cap->edit_terms ) ) {
|
| 492 |
return false;
|
| 493 |
+
}
|
| 494 |
|
| 495 |
return current_user_can( $taxonomy->cap->edit_terms );
|
| 496 |
}
|
| 556 |
}
|
| 557 |
|
| 558 |
$assoc = taxonomy_image_plugin_get_associations();
|
| 559 |
+
$assoc[ $tt_id ] = $image_id;
|
| 560 |
if ( update_option( 'taxonomy_image_plugin', taxonomy_image_plugin_sanitize_associations( $assoc ) ) ) {
|
| 561 |
taxonomy_image_plugin_json_response( array(
|
| 562 |
'status' => 'good',
|
| 563 |
'why' => esc_html__( 'Image successfully associated', 'taxonomy-images' ),
|
| 564 |
'attachment_thumb_src' => taxonomy_image_plugin_get_image_src( $image_id )
|
| 565 |
) );
|
| 566 |
+
} else {
|
|
|
|
| 567 |
taxonomy_image_plugin_json_response( array(
|
| 568 |
'status' => 'bad',
|
| 569 |
'why' => esc_html__( 'Association could not be created', 'taxonomy-images' )
|
| 622 |
}
|
| 623 |
|
| 624 |
$assoc = taxonomy_image_plugin_get_associations();
|
| 625 |
+
if ( ! isset( $assoc[ $tt_id ] ) ) {
|
| 626 |
taxonomy_image_plugin_json_response( array(
|
| 627 |
'status' => 'good',
|
| 628 |
'why' => esc_html__( 'Nothing to remove', 'taxonomy-images' )
|
| 629 |
) );
|
| 630 |
}
|
| 631 |
|
| 632 |
+
unset( $assoc[ $tt_id ] );
|
| 633 |
|
| 634 |
if ( update_option( 'taxonomy_image_plugin', $assoc ) ) {
|
| 635 |
taxonomy_image_plugin_json_response( array(
|
| 636 |
'status' => 'good',
|
| 637 |
'why' => esc_html__( 'Association successfully removed', 'taxonomy-images' )
|
| 638 |
) );
|
| 639 |
+
} else {
|
|
|
|
| 640 |
taxonomy_image_plugin_json_response( array(
|
| 641 |
'status' => 'bad',
|
| 642 |
'why' => esc_html__( 'Association could not be removed', 'taxonomy-images' )
|
| 660 |
*/
|
| 661 |
function taxonomy_image_plugin_get_associations( $refresh = false ) {
|
| 662 |
static $associations = array();
|
| 663 |
+
if ( empty( $associations ) || $refresh ) {
|
| 664 |
$associations = taxonomy_image_plugin_sanitize_associations( get_option( 'taxonomy_image_plugin' ) );
|
| 665 |
+
}
|
| 666 |
|
| 667 |
return $associations;
|
| 668 |
}
|
| 682 |
*/
|
| 683 |
function taxonomy_image_plugin_add_dynamic_hooks() {
|
| 684 |
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
| 685 |
+
if ( ! isset( $settings['taxonomies'] ) ) {
|
| 686 |
return;
|
| 687 |
+
}
|
| 688 |
|
| 689 |
foreach ( $settings['taxonomies'] as $taxonomy ) {
|
| 690 |
add_filter( 'manage_' . $taxonomy . '_custom_column', 'taxonomy_image_plugin_taxonomy_rows', 15, 3 );
|
| 783 |
$term = get_term( $term_id, $taxonomy );
|
| 784 |
|
| 785 |
$tt_id = 0;
|
| 786 |
+
if ( isset( $term->term_taxonomy_id ) ) {
|
| 787 |
$tt_id = (int) $term->term_taxonomy_id;
|
| 788 |
+
}
|
| 789 |
|
| 790 |
$taxonomy = get_taxonomy( $taxonomy );
|
| 791 |
|
| 792 |
$name = esc_html__( 'term', 'taxonomy-images' );
|
| 793 |
+
if ( isset( $taxonomy->labels->singular_name ) ) {
|
| 794 |
$name = strtolower( $taxonomy->labels->singular_name );
|
| 795 |
+
}
|
| 796 |
|
| 797 |
$hide = ' hide';
|
| 798 |
$attachment_id = 0;
|
| 809 |
$nonce = wp_create_nonce( 'taxonomy-image-plugin-create-association' );
|
| 810 |
$nonce_remove = wp_create_nonce( 'taxonomy-image-plugin-remove-association' );
|
| 811 |
|
| 812 |
+
$o = "\n" . '<div id="' . esc_attr( 'taxonomy-image-control-' . $tt_id ) . '" class="taxonomy-image-control hide-if-no-js">';
|
| 813 |
+
$o .= "\n" . '<a class="thickbox taxonomy-image-thumbnail" data-tt-id="' . $tt_id . '" data-attachment-id="' . $attachment_id . '" data-nonce="' . $nonce . '" href="' . esc_url( admin_url( 'media-upload.php' ) . '?type=image&tab=library&post_id=0&TB_iframe=true' ) . '" title="' . esc_attr( sprintf( __( 'Associate an image with the %1$s named “%2$s”.', 'taxonomy-images' ), $name, $term->name ) ) . '"><img id="' . esc_attr( 'taxonomy_image_plugin_' . $tt_id ) . '" src="' . esc_url( $img ) . '" alt="" /></a>';
|
| 814 |
+
$o .= "\n" . '<a class="control upload thickbox" data-tt-id="' . $tt_id . '" data-attachment-id="' . $attachment_id . '" data-nonce="' . $nonce . '" href="' . esc_url( admin_url( 'media-upload.php' ) . '?type=image&tab=type&post_id=0&TB_iframe=true' ) . '" title="' . esc_attr( sprintf( __( 'Upload a new image for this %s.', 'taxonomy-images' ), $name ) ) . '">' . esc_html__( 'Upload.', 'taxonomy-images' ) . '</a>';
|
| 815 |
+
$o .= "\n" . '<a class="control remove' . $hide . '" data-tt-id="' . $tt_id . '" data-nonce="' . $nonce_remove . '" href="#" id="' . esc_attr( 'remove-' . $tt_id ) . '" rel="' . esc_attr( $tt_id ) . '" title="' . esc_attr( sprintf( __( 'Remove image from this %s.', 'taxonomy-images' ), $name ) ) . '">' . esc_html__( 'Delete', 'taxonomy-images' ) . '</a>';
|
| 816 |
+
$o .= "\n" . '<input type="hidden" class="tt_id" name="' . esc_attr( 'tt_id-' . $tt_id ) . '" value="' . esc_attr( $tt_id ) . '" />';
|
| 817 |
+
$o .= "\n" . '<input type="hidden" class="image_id" name="' . esc_attr( 'image_id-' . $tt_id ) . '" value="' . esc_attr( $attachment_id ) . '" />';
|
| 818 |
|
| 819 |
+
if ( isset( $term->name ) && isset( $term->slug ) ) {
|
| 820 |
+
$o .= "\n" . '<input type="hidden" class="term_name" name="' . esc_attr( 'term_name-' . $term->slug ) . '" value="' . esc_attr( $term->name ) . '" />';
|
| 821 |
+
}
|
|
|
|
| 822 |
|
| 823 |
+
$o .= "\n" . '</div>';
|
| 824 |
return $o;
|
| 825 |
}
|
| 826 |
|
| 844 |
array( 'jquery' ),
|
| 845 |
taxonomy_image_plugin_version()
|
| 846 |
);
|
| 847 |
+
wp_localize_script( 'taxonomy-images-media-upload-popup', 'TaxonomyImagesModal', array(
|
| 848 |
'termBefore' => esc_html__( '“', 'taxonomy-images' ),
|
| 849 |
'termAfter' => esc_html__( '”', 'taxonomy-images' ),
|
| 850 |
'associating' => esc_html__( 'Associating …', 'taxonomy-images' ),
|
| 862 |
* @access private
|
| 863 |
*/
|
| 864 |
function taxonomy_image_plugin_edit_tags_js() {
|
| 865 |
+
if ( false == taxonomy_image_plugin_is_screen_active() ) {
|
| 866 |
return;
|
| 867 |
+
}
|
| 868 |
|
| 869 |
if ( version_compare( get_bloginfo( 'version' ), 3.5 ) >= 0 ) {
|
| 870 |
return;
|
| 876 |
array( 'jquery', 'thickbox' ),
|
| 877 |
taxonomy_image_plugin_version()
|
| 878 |
);
|
| 879 |
+
wp_localize_script( 'taxonomy-image-plugin-edit-tags', 'taxonomyImagesPlugin', array(
|
| 880 |
'nonce' => wp_create_nonce( 'taxonomy-image-plugin-remove-association' ),
|
| 881 |
'img_src' => taxonomy_image_plugin_url( 'default.png' ),
|
| 882 |
'tt_id' => 0,
|
| 893 |
* @access private
|
| 894 |
*/
|
| 895 |
function taxonomy_image_plugin_css_admin() {
|
| 896 |
+
if ( false == taxonomy_image_plugin_is_screen_active() && current_filter() != 'admin_print_styles-media-upload-popup' ) {
|
| 897 |
return;
|
| 898 |
+
}
|
| 899 |
|
| 900 |
wp_enqueue_style(
|
| 901 |
'taxonomy-image-plugin-edit-tags',
|
| 916 |
* @access private
|
| 917 |
*/
|
| 918 |
function taxonomy_image_plugin_css_thickbox() {
|
| 919 |
+
if ( false == taxonomy_image_plugin_is_screen_active() ) {
|
| 920 |
return;
|
| 921 |
+
}
|
| 922 |
|
| 923 |
wp_enqueue_style( 'thickbox' );
|
| 924 |
}
|
| 939 |
* @access private
|
| 940 |
*/
|
| 941 |
function taxonomy_image_plugin_css_public() {
|
| 942 |
+
if ( apply_filters( 'taxonomy-images-disable-public-css', false ) ) {
|
| 943 |
return;
|
| 944 |
+
}
|
| 945 |
|
| 946 |
wp_enqueue_style(
|
| 947 |
'taxonomy-image-plugin-public',
|
| 975 |
*/
|
| 976 |
function taxonomy_image_plugin_activate() {
|
| 977 |
$associations = get_option( 'taxonomy_image_plugin' );
|
| 978 |
+
if ( false === $associations ) {
|
| 979 |
add_option( 'taxonomy_image_plugin', array() );
|
| 980 |
+
}
|
| 981 |
|
| 982 |
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
| 983 |
if ( false === $settings ) {
|
| 999 |
*/
|
| 1000 |
function taxonomy_image_plugin_is_screen_active() {
|
| 1001 |
$screen = get_current_screen();
|
| 1002 |
+
if ( ! isset( $screen->taxonomy ) ) {
|
| 1003 |
return false;
|
| 1004 |
+
}
|
| 1005 |
|
| 1006 |
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
| 1007 |
+
if ( ! isset( $settings['taxonomies'] ) ) {
|
| 1008 |
return false;
|
| 1009 |
+
}
|
| 1010 |
|
| 1011 |
+
if ( in_array( $screen->taxonomy, $settings['taxonomies'] ) ) {
|
| 1012 |
return true;
|
| 1013 |
+
}
|
| 1014 |
|
| 1015 |
return false;
|
| 1016 |
}
|
| 1031 |
*/
|
| 1032 |
function taxonomy_image_plugin_cache_images( $posts ) {
|
| 1033 |
$assoc = taxonomy_image_plugin_get_associations();
|
| 1034 |
+
if ( empty( $assoc ) ) {
|
| 1035 |
return;
|
| 1036 |
+
}
|
| 1037 |
|
| 1038 |
$tt_ids = array();
|
| 1039 |
foreach ( (array) $posts as $post ) {
|
| 1040 |
+
if ( ! isset( $post->ID ) || ! isset( $post->post_type ) ) {
|
| 1041 |
continue;
|
| 1042 |
+
}
|
| 1043 |
|
| 1044 |
$taxonomies = get_object_taxonomies( $post->post_type );
|
| 1045 |
+
if ( empty( $taxonomies ) ) {
|
| 1046 |
continue;
|
| 1047 |
+
}
|
| 1048 |
|
| 1049 |
foreach ( $taxonomies as $taxonomy ) {
|
| 1050 |
$the_terms = get_the_terms( $post->ID, $taxonomy );
|
| 1060 |
|
| 1061 |
$image_ids = array();
|
| 1062 |
foreach ( $tt_ids as $tt_id ) {
|
| 1063 |
+
if ( ! isset( $assoc[ $tt_id ] ) ) {
|
| 1064 |
continue;
|
| 1065 |
+
}
|
| 1066 |
|
| 1067 |
+
if ( in_array( $assoc[ $tt_id ], $image_ids ) ) {
|
| 1068 |
continue;
|
| 1069 |
+
}
|
| 1070 |
|
| 1071 |
+
$image_ids[] = $assoc[ $tt_id ];
|
| 1072 |
}
|
| 1073 |
|
| 1074 |
+
if ( empty( $image_ids ) ) {
|
| 1075 |
return;
|
| 1076 |
+
}
|
| 1077 |
|
| 1078 |
$images = get_posts( array(
|
| 1079 |
'include' => $image_ids,
|
| 1117 |
function taxonomy_image_plugin_check_taxonomy( $taxonomy, $filter ) {
|
| 1118 |
if ( ! taxonomy_exists( $taxonomy ) ) {
|
| 1119 |
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' ),
|
| 1120 |
+
'<var>' . esc_html__( 'taxonomy', 'taxonomy-images' ) . '</var>',
|
| 1121 |
+
'<code>' . esc_html( $filter ) . '</code>',
|
| 1122 |
+
'<strong>' . esc_html( $taxonomy ) . '</strong>'
|
| 1123 |
) );
|
| 1124 |
return false;
|
| 1125 |
}
|
| 1180 |
function taxonomy_images_plugin_row_meta( $links, $file ) {
|
| 1181 |
static $plugin_name = '';
|
| 1182 |
|
| 1183 |
+
if ( empty( $plugin_name ) ) {
|
| 1184 |
$plugin_name = plugin_basename( __FILE__ );
|
| 1185 |
+
}
|
| 1186 |
|
| 1187 |
+
if ( $plugin_name != $file ) {
|
| 1188 |
return $links;
|
| 1189 |
+
}
|
| 1190 |
|
| 1191 |
$link = taxonomy_images_plugin_settings_page_link( esc_html__( 'Settings', 'taxonomy-images' ) );
|
| 1192 |
+
if ( ! empty( $link ) ) {
|
| 1193 |
$links[] = $link;
|
| 1194 |
+
}
|
| 1195 |
|
| 1196 |
$links[] = '<a href="http://wordpress.mfields.org/donate/">' . esc_html__( 'Donate', 'taxonomy-images' ) . '</a>';
|
| 1197 |
|
| 1210 |
* @since 0.7
|
| 1211 |
*/
|
| 1212 |
function taxonomy_images_plugin_settings_page_link( $link_text = '' ) {
|
| 1213 |
+
if ( empty( $link_text ) ) {
|
| 1214 |
$link_text = __( 'Manage Settings', 'taxonomy-images' );
|
| 1215 |
+
}
|
| 1216 |
|
| 1217 |
$link = '';
|
| 1218 |
+
if ( current_user_can( 'manage_options' ) ) {
|
| 1219 |
$link = '<a href="' . esc_url( add_query_arg( array( 'page' => 'taxonomy_image_plugin_settings' ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html( $link_text ) . '</a>';
|
| 1220 |
+
}
|
| 1221 |
|
| 1222 |
return $link;
|
| 1223 |
}
|
