Plugin Directory

Changeset 773032


Ignore:
Timestamp:
09/16/2013 02:27:59 AM (13 years ago)
Author:
codebykat
Message:

add shortcode to support custom taxonomy terms

File:
1 edited

Legend:

Unmodified
Added
Removed
  • post-by-email/trunk/class-post-by-email.php

    r773031 r773032  
    336336
    337337
    338             /* categories */
     338            /* shortcode: categories. [category cat1 cat2...] */
    339339
    340340            $shortcode_categories = $this->find_shortcode( 'category', $post_content );
     
    357357            }
    358358
    359             /* get tags from shortcode */
     359            /* shortcode: tags. [tag tag1 tag2...] */
     360
    360361            $tags_input = $this->find_shortcode( 'tag', $post_content );
    361362
    362 
     363            $original_post_content = $post_content;
    363364            $post_content = $this->filter_valid_shortcodes( $post_content );
    364365
     
    380381            // save original message sender as post_meta, in case we want it later
    381382            add_post_meta( $post_ID, 'original_author', $from_email );
     383
     384
     385            /* shortcode: custom taxonomies.  [taxname term1 term2 ...] */
     386            $tax_input = array();
     387
     388            // get all registered custom taxonomies
     389            $args = array(
     390                'public'   => true,
     391                '_builtin' => false
     392            );
     393            $registered_taxonomies = get_taxonomies( $args, 'names', 'and' );
     394
     395            if ( $registered_taxonomies ) {
     396                foreach ( $registered_taxonomies as $taxonomy_name ) {
     397                    $tax_shortcodes = $this->find_shortcode( $taxonomy_name, $original_post_content );
     398                    if ( count( $tax_shortcodes ) > 0 ) {
     399                        // pending bug fix: http://core.trac.wordpress.org/ticket/19373
     400                        //$tax_input[] = array( $taxonomy_name => $tax_shortcodes );
     401                        wp_set_post_terms( $post_ID, $tax_shortcodes, $taxonomy_name );
     402                    }
     403                }
     404            }
    382405
    383406            /* attachments */
     
    768791     */
    769792    protected function filter_valid_shortcodes( $text ) {
    770         foreach ( array( 'tag', 'category', 'pin' ) as $shortcode ) {
     793        $valid_shortcodes = array( 'tag', 'category', 'pin' );
     794
     795        // get all registered custom taxonomies
     796        $args = array(
     797            'public'   => true,
     798            '_builtin' => false
     799        );
     800        $registered_taxonomies = get_taxonomies( $args, 'names', 'and' );
     801
     802        if ( $registered_taxonomies ) {
     803            foreach ( $registered_taxonomies as $taxonomy ) {
     804                $valid_shortcodes[] = $taxonomy;
     805            }
     806        }
     807
     808        foreach ( $valid_shortcodes as $shortcode ) {
    771809            $text = preg_replace( "/\[$shortcode\s(.*?)\]/i", '', $text ); 
    772810        }
Note: See TracChangeset for help on using the changeset viewer.