Advertisement
Guest User

Untitled

a guest
Feb 5th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /***
  3.     * Plugin Name: bbPress AutoTagger
  4.     * Plugin URI:  http://example.org/
  5.     * Description: --- description here --
  6.     * Version:     1.0
  7.     * Author:      Shmoo
  8.     * Author URI:  http://example.org/
  9.     * License:     Same as WordPress I guess.
  10. ***/
  11.  
  12. add_action( 'bbp_new_topic',  'shmoo_auto_save_tags', 10, 1 );
  13. add_action( 'bbp_edit_topic', 'shmoo_auto_save_tags', 10, 1 );
  14.  
  15.  
  16. function shmoo_auto_save_tags( $topic_id ) {
  17.  
  18.     // Get all bbPress topic tags inside an array + strip them to plain text
  19.         $bbp_topic_tags = wp_tag_cloud( array( 'format' => 'array', 'taxonomy' => 'topic-tag' ) );
  20.  
  21.                 function tag_stripper( &$items, $format ) {
  22.  
  23.                         $items = strip_tags( $items );
  24.  
  25.                 }
  26.                 array_walk( $bbp_topic_tags, 'tag_stripper' );
  27.  
  28.  
  29. // Topic Content
  30.  
  31.  
  32.         // Get the topic content
  33.         $bbp_topic_content = bbp_get_topic_content( $topic_id );
  34.  
  35.  
  36. // Match Topics Tags against Topic Content
  37.  
  38.  
  39.         // Check and echo matches
  40.         $matches = array();
  41.  
  42.         $match_found = preg_match_all( "/\b(" . implode($bbp_topic_tags,"|") . ")\b/i", $bbp_topic_content, $matches );
  43.  
  44.         if ( $match_found ) {
  45.  
  46.             $words = array_unique( $matches[0] );
  47.  
  48.                     $words = array_unique( array_merge( $words, wp_get_post_terms( $topic_id, bbp_get_topic_tag_tax_id(), array( 'fields' => 'names' ) ) ) );
  49.                         if ( !empty( $words ) )
  50.                             wp_set_post_terms( $topic_id, $words, bbp_get_topic_tag_tax_id(), true );
  51.  
  52.         }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement