Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /***
- * Plugin Name: bbPress AutoTagger
- * Plugin URI: http://example.org/
- * Description: --- description here --
- * Version: 1.0
- * Author: Shmoo
- * Author URI: http://example.org/
- * License: Same as WordPress I guess.
- ***/
- add_action( 'bbp_new_topic', 'shmoo_auto_save_tags', 10, 1 );
- add_action( 'bbp_edit_topic', 'shmoo_auto_save_tags', 10, 1 );
- function shmoo_auto_save_tags( $topic_id ) {
- // Get all bbPress topic tags inside an array + strip them to plain text
- $bbp_topic_tags = wp_tag_cloud( array( 'format' => 'array', 'taxonomy' => 'topic-tag' ) );
- function tag_stripper( &$items, $format ) {
- $items = strip_tags( $items );
- }
- array_walk( $bbp_topic_tags, 'tag_stripper' );
- // Topic Content
- // Get the topic content
- $bbp_topic_content = bbp_get_topic_content( $topic_id );
- // Match Topics Tags against Topic Content
- // Check and echo matches
- $matches = array();
- $match_found = preg_match_all( "/\b(" . implode($bbp_topic_tags,"|") . ")\b/i", $bbp_topic_content, $matches );
- if ( $match_found ) {
- $words = array_unique( $matches[0] );
- $words = array_unique( array_merge( $words, wp_get_post_terms( $topic_id, bbp_get_topic_tag_tax_id(), array( 'fields' => 'names' ) ) ) );
- if ( !empty( $words ) )
- wp_set_post_terms( $topic_id, $words, bbp_get_topic_tag_tax_id(), true );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement