Filter wp_editor args

In the Pro version, you can enable wp_editor on the new topic submission form, allowing users to add formatting. To change the parameters, you can add a filter, e.g.:

function me_filter_editor_args( $args ) {
  $args['teeny'] => true;
  return $args;
}
add_action( 'ctdb_editor_args', 'me_filter_editor_args' );

 

Change permitted file types

In the Pro version, it’s possible to allow users to upload an image as the featured image for the topic. By default, only png and jpg file types are permitted. However, you can change this with a filter, e.g.:

function me_change_mime_types( $existing_mimes ) {
  // Add gif as permitted mime type
  $existing_mimes['gif'] = 'image/gif';
  return $existing_mimes;
}
add_filter( 'ctdb_existing_mimes', 'me_change_mime_types' );

Use with care to avoid users uploading potentially malicious files.

Hooking into the template files

Each template – single-discussion-topics.php and archive-discussion-topics.php – has hooks at the start and end of the file. These hooks can be used to replace the opening and closing HTML tags.

The templates are based on the Twenty Fifteen template files so, using the example of the single-discussion-topics.php file, the tags look like:

<div id="primary" class="content-area">
 <main id="main" class="site-main" role="main">

...

 </main>
</div>

These are inserted into the file through hooks. So to insert your own HTML, you just need to override the plugin, e.g.:

remove_action ( 'ctdb_open_wrapper_single', 'ctdb_open_wrapper_single' );
remove_action ( 'ctdb_close_wrapper_single', 'ctdb_close_wrapper_single' );

add_action ( 'ctdb_close_wrapper_single', 'new_open_wrapper_single' );
add_action ( 'ctdb_close_wrapper_single', 'new_close_wrapper_single' );

// Example only
function new_open_wrapper_single() { ?>
 <div id="primary-id" class="my-content-area">
<?php }

// Example only
function new_close_wrapper_single() { ?>
  </div>
<?php }

You’ll need to replace the markup with suitable markup for your theme.

You can repeat this for the archive-discussion-topics.php template:

remove_action ( 'ctdb_open_wrapper_archive', 'ctdb_open_wrapper_archive' );
remove_action ( 'ctdb_close_wrapper_archive', 'ctdb_close_wrapper_archive' );

add_action ( 'ctdb_close_wrapper_archive', 'new_open_wrapper_archive' );
add_action ( 'ctdb_close_wrapper_archive', 'new_close_wrapper_archive' );

// Example only
function new_open_wrapper_archive() { ?>
 <div id="primary-id" class="my-content-area">
<?php }

// Example only
function new_close_wrapper_archive() { ?>
 </div>
<?php }

Double-check your theme files for the correct markup to use.

Displaying topics

Single Topics
Each topic posted will appear on its own page. By default, this uses the theme’s default single.php template. The advantage of this is that your topic pages will fit perfectly into your theme.

If you wish, you can use an alternative template. To do this, you’ll need to disable the option to use the theme templates by going to Discussion Board > Settings > Design and deselecting Use theme templates.

You can then use alternative templates as follows:

  • Create a new single-discussion-topics.php template in your theme or child theme (note that the post type is plural). The plugin will look for this template in the child theme first, then the parent theme, then the plugin folder itself.
  • Modify the plugin’s template files programmatically. The single-discussion-topics.php file uses the same mark-up as the Twenty Fifteen theme. However, this might not work for your theme. You can hook into the opening and closing wrappers and replace with your own opening and closing tags to ensure compatibility with your theme. See below for further guidance.

Topic Archives
You can override the archive template in the same ways:

  • Create a new archive-discussion-topics.php template in your theme or child theme. The plugin will look for this template in the child theme first, then the parent theme, then the plugin folder itself.
  • Modify the plugin’s template files programmatically.

Shortcode
Instead of using the archive template, the plugin creates a new page called Topics on activation and inserts the [discussion_topics] shortcode. This will display a list of all topics and is preferable to using the archive page.

Change order of profile fields

You can change the order of profile fields using the following filter in your functions.php file:

function prefix_filter_profile_fields( $fields ){
  // Enter your new fields order here
  return $fields;
}
add_filter( 'ctdb_profile_fields', 'prefix_filter_profile_fields' );

The $fields list looks like:

$fields = array( 
 'display_name' => array(
 'id' => 'display_name',
 'label' => __( 'Display name', 'discussion-board-pro' ),
 'callback' => ''
 ),
 'first_name' => array(
 'id' => 'first_name',
 'label' => __( 'First name', 'discussion-board-pro' ),
 'callback' => ''
 ),
 'last_name' => array(
 'id' => 'last_name',
 'label' => __( 'Last name', 'discussion-board-pro' ),
 'callback' => ''
 ),
 'user_url' => array(
 'id' => 'user_url',
 'label' => __( 'Website', 'discussion-board-pro' ),
 'callback' => ''
 ),
 'description' => array(
 'id' => 'description',
 'label' => __( 'Bio', 'discussion-board-pro' ),
 'callback' => ''
 ),
 'user_registered' => array(
 'id' => 'user_registered',
 'label' => __( 'Member since', 'discussion-board-pro' ),
 'callback' => ''
 ),
 'topics_posted' => array(
 'id' => 'topics_posted',
 'label' => __( 'Topics posted', 'discussion-board-pro' ),
 'callback' => ''
 ),
 'replies' => array(
 'id' => 'replies',
 'label' => __( 'Replies', 'discussion-board-pro' ),
 'callback' => ''
 ),
 'last_active' => array(
 'id' => 'last_active',
 'label' => __( 'Last active', 'discussion-board-pro' ),
 'callback' => ''
 ),
 );

Reorder it as you wish.

 

How to change column titles in the discussion_topics shortcode

You can change column titles from the default like this:

function myprefix_change_ctdb_titles( $titles ) {
  $titles['started'] = 'Posted';
  return $titles;
}
add_filter( 'ctdb_topic_titles', 'myprefix_change_ctdb_titles' );

The default titles are:

$titles = array(
 'avatar' => '',
 'topic' => __( 'Topic', 'discussion-board' ),
 'replies' => __( 'Replies', 'discussion-board' ),
 'started' => __( 'Since', 'discussion-board' ),
 'posted-by' => __( 'Posted by: ', 'discussion-board' ),
);

Just replace with new values as required.