Advertisement
Guest User

bbPress auto tags

a guest
Feb 3rd, 2014
74
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, 5 );
  13. //add_action( 'bbp_edit_topic', 'shmoo_auto_save_tags', 10, 5 );
  14.  
  15.  
  16. function shmoo_auto_save_tags() {
  17.  
  18. // Topic Tags
  19.  
  20.  
  21.     // Get all bbPress topic tags inside an array + strip them to plain text
  22.     $bbp_topic_tags = wp_tag_cloud( array( 'format' => 'array', 'taxonomy' => 'topic-tag' ) );
  23.  
  24.         function tag_stripper( &$items, $format ) {
  25.  
  26.             $items = strip_tags( $items );
  27.  
  28.         }
  29.         array_walk( $bbp_topic_tags, 'tag_stripper' );
  30.  
  31.  
  32. // Topic Content
  33.  
  34.  
  35.     // Get the topic content
  36.     $bbp_topic_content = bbp_get_topic_content();
  37.  
  38.  
  39. // Match Topics Tags against Topic Content
  40.  
  41.  
  42.     // Check and echo matches
  43.     $matches = array();
  44.  
  45.     $match_found = preg_match_all( "/\b(" . implode($bbp_topic_tags,"|") . ")\b/i", $bbp_topic_content, $matches );
  46.  
  47.     if ( $match_found ) {
  48.         $words = array_unique( $matches[0] );
  49.             foreach( $words as $word ) {
  50.                 echo $word . ", ";
  51.             }
  52.     }
  53.  
  54.  
  55. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement