bpbbpst_change_topic_title

Change the title of the topic to add support mention.

Description

(string) bpbbpst_change_topic_title( (string) $title = '', (int) $id = 0 ); 

Returns (string)

$title the title with the eventual support mention

Parameters (2)

0. $title — Optional. (string) => ''
The title of the topic
1. $id — Optional. (int)
The id of the topic

Usage

  1. if ( !function_exists( 'bpbbpst_change_topic_title' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddy-bbpress-support-topic/includes/functions.php'; 
  3.  
  4. // the title of the topic 
  5. $title = ''; 
  6.  
  7. // the id of the topic 
  8. $id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bpbbpst_change_topic_title($title, $id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/functions.php  
  1. function bpbbpst_change_topic_title( $title = '', $id = 0 ) { 
  2. /** 
  3. * get_the_title() is where is located the filter 'the_title', the one the plugin is 
  4. * using to prefix topic title. The problem is that there's no context to this filter 
  5. * so that we are sure get_the_title() is called to actually display the topic title just 
  6. * before the topic content. 
  7. * get_the_title() or the_title() can be used in header, widgets, breadcrumbs, meta tags... So there will 
  8. * allways be a place where the plugin shouldn't filter the title. If you're a plugin/theme developer 
  9. * and you want to get rid of this prefix, you simply need to add these lines before and after your use of 
  10. * get_the_title() : 
  11. * add_filter( 'bpbbpst_donot_change_topic_title', '__return_true' ); 
  12. * get_the_title() 
  13. * remove_filter( 'bpbbpst_donot_change_topic_title', '__return_true' ); 
  14. * If you want to completely get rid of it, just use the first line in the above example 
  15. * The prefix is only appended when on the topic single and edit bbPress templates. If on this template,  
  16. * a sidebar widget displaying the recent topics for instance could have the prefix appended, but not on 
  17. * all other pages of the site. So to be consistent, i chose to disable the prefix filter in dynamic 
  18. * sidebars. 
  19. * @param bool true to avoid the prefix to be appended to the_title, false otherwise 
  20. */ 
  21. $do_not_prefix = apply_filters( 'bpbbpst_donot_change_topic_title', bpbbpst_is_sidebar() ); 
  22.  
  23. if ( ! empty( $do_not_prefix ) ) { 
  24. return $title; 
  25.  
  26. if ( ! bbp_is_topic( $id ) ) { 
  27. return $title; 
  28.  
  29. if ( bbp_is_topic_edit() || bbp_is_single_topic() ) { 
  30. return bpbbpst_add_support_mention( $id, false ) . $title; 
  31. } else { 
  32. return $title;