Changeset 1866666
- Timestamp:
- 04/30/2018 10:05:42 PM (8 years ago)
- Location:
- wp-random-post-thumbnails/trunk/classes
- Files:
-
- 2 edited
-
class-wprpt-options.php (modified) (5 diffs)
-
class-wprpt.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-random-post-thumbnails/trunk/classes/class-wprpt-options.php
r1742817 r1866666 51 51 */ 52 52 public function __construct() { 53 53 54 54 // Set our title 55 55 $this->title = __( 'Random Post Thumbnails', $this->prefix ); … … 57 57 // Set our menu link title 58 58 $this->menu_title = __( 'Random Thumbnails', $this->prefix ); 59 60 } 61 62 59 60 } 61 62 63 63 /** 64 64 * Initiate our hooks … … 70 70 */ 71 71 public function hooks() { 72 72 73 73 add_action( 'admin_init', array( $this, 'init' ) ); 74 74 add_action( 'cmb2_admin_init', array( $this, 'add_options_page_tabs' ) ); … … 310 310 ) ); 311 311 312 313 // Group field that houses our repeatable fields 314 $taxonomy_options->add_field( array( 315 'name' => 'Excluded Term', 316 'description' => 'Select any categories in which the posts should be <strong>excluded</strong> from having random thumbnails.', 317 'id' => "taxonomy_{$taxonomy_object->name}_excluded_terms", 318 'taxonomy' => $taxonomy_slug, //Enter Taxonomy Slug 319 'type' => 'taxonomy_multicheck', 320 // Optional : 321 'text' => array( 322 'no_terms_text' => 'Sorry, no terms could be found.' // Change default text. Default: "No terms" 323 ), 324 'remove_default' => 'true' // Removes the default metabox provided by WP core. Pending release as of Aug-10-16 325 ) ); 326 312 327 // Set the object type and add the metabox to our array of boxes 313 328 $taxonomy_options->object_type( 'options-page' ); … … 416 431 * 417 432 * @since 1.0.0 418 * 433 * 419 434 * @param string $field Field to retrieve 420 435 * @return mixed Field value or exception is thrown -
wp-random-post-thumbnails/trunk/classes/class-wprpt.php
r1858153 r1866666 28 28 add_filter( 'wprpt_all_images', array($this, 'add_images_based_on_post_type') ); 29 29 add_filter( 'wprpt_all_images', array($this, 'add_images_based_on_taxonomy') ); 30 add_filter( 'wprpt_all_images', array($this, 'exclude_taxonomy_terms') ); 30 31 } 31 32 … … 232 233 233 234 /** 235 * Filters the array of all possible random images and adds any that are 236 * specific to the current taxonomy term. 237 * 238 * @since 2.0.0 239 * 240 * @param $all_images array 241 * @return array 242 */ 243 function exclude_taxonomy_terms( $all_images ) { 244 245 $post_id = get_the_ID(); 246 $taxonomies = get_the_taxonomies( $post_id ); 247 248 if ( !empty($taxonomies) ) { 249 250 // Loop through each taxonomy for the current post 251 foreach( $taxonomies as $slug => $taxonomy ) { 252 $terms = wp_get_post_terms( $post_id, $slug ); 253 $excluded_terms = wprpt_get_option( "taxonomy_{$slug}_excluded_terms" ); 254 255 // If the term is in the list of excluded terms, remove all of 256 // the random images to 'disable' the random image functionality 257 // for these terms. 258 foreach( $terms as $term ) { 259 if ( !empty($excluded_terms) && in_array($term->slug, $excluded_terms ) ) { 260 $all_images = array(); 261 } 262 } 263 264 } 265 } 266 267 return $all_images; 268 269 } 270 271 272 /** 234 273 * Adds custom links to the plugin action links on the Plugins page (Edit, 235 274 * Delete, Deactivate, etc).
Note: See TracChangeset
for help on using the changeset viewer.