Discussion Board – WordPress Forum Shortcodes

Below, you’ll find a detailed guide on how to add the Discussion Board – WordPress Forum Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Discussion Board – WordPress Forum Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Discussion Board – WordPress Forum Plugin and the shortcodes it provides:

Plugin Icon
Discussion Board – WordPress Forum Plugin

"Discussion Board – WordPress Forum Plugin is a powerful tool for enhancing user interaction on your website. This plugin transforms your platform into a fully functional forum, fostering active discussions and community engagement."

★★★★☆ (36) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: 5.2.4
Included Shortcodes:
  • [discussion_board_form]
  • [discussion_topics]
  • [recent_discussion_topics]
  • [discussion_board_log_in_out]
  • [is_logged_in]
  • [not_logged_in]
  • [new_topic_button]
  • [discussion_board_login_form]
  • [discussion_board_login_only]
  • [discussion_board_registration_only]

Discussion Board – WordPress Forum [discussion_board_form] Shortcode

The wp-discussion-board plugin shortcode ‘discussion_board_form’ is used to display a new topic form. It checks if the form is submitted, verifies the nonce, and prevents duplication. It validates the form fields, displays error messages if any, and creates a new topic if no errors are found. It also checks for a time limit to prevent multiple quick posts.

Shortcode: [discussion_board_form]

Examples and Usage

Basic example – Display a new topic form on your page or post using the shortcode.

[discussion_board_form]

Advanced examples

Display a new topic form with a specific title and content. This can be useful when you want to pre-fill the form fields for your users, making it easier for them to create a new topic.

[discussion_board_form topic_title="Your Topic Title Here" topic_content="Your Topic Content Here"]

Display a new topic form with a specific status. By default, the status is set to ‘draft’, but you can change it to ‘publish’ if you want the new topics to be published immediately after submission.

[discussion_board_form status="publish"]

Control the comment status of the new topics. By default, the comment status is set to ‘open’, but you can change it to ‘closed’ if you don’t want to allow replies to the new topics.

[discussion_board_form comment_status="closed"]

Please note that the above examples assume that you have registered the corresponding shortcode attributes in your ‘display_new_topic_form’ function.

PHP Function Code

In case you have difficulties debugging what causing issues with [discussion_board_form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('discussion_board_form', array($this, 'display_new_topic_form'));

Shortcode PHP function:

function display_new_topic_form()
		{
			$has_duplicate = false;
			// Check if the form was submitted
			if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['insert_post'])) {
				// Verify the nonce
				if (!wp_verify_nonce($_POST['new_topic'], 'display_new_topic_form')) {
					return;
				}
				// Prevent duplication
				$args = array(
					'post_type'				=> 'discussion-topics',
					'posts_per_page'	=> 9999,
					'meta_key'				=> 'ctdb_uniqid',
					'meta_value'			=> sanitize_text_field($_POST['ctdb_uniqid']),
					'fields'					=> 'ids'
				);
				$duplicates = new WP_Query($args);
				if ($duplicates->posts) {
					// Duplicate found
					$has_duplicate = true;
					$dupes = $duplicates->posts;
					$my_post_id = $dupes[0];
				}

				// Just in case there are any errors
				$errors = array();

				$error_params = array(
					'topic_title'	=> array(
						'id'			=> 'topic_title', // The form element we're evaluating
						'check'			=> '', // The value that will throw the error
						'response'		=> __('Please add a title.', 'wp-discussion-board'), // The error message if the element is empty
						'topic_element'	=> 'title' // The element of the $post_args to be populated with this element's value
					),
					'topic_content'	=> array(
						'id'			=> 'topic_content', // The form element we're evaluating
						'check'			=> '', // The value that will throw the error
						'response'		=> __('Please add some content to the topic.', 'wp-discussion-board'), // The error message if the element is empty
						'topic_element'	=> 'content' // The element of the $post_args to be populated with this element's value
					)
				);

				$error_params = apply_filters('ctdb_new_topic_form_validation', $error_params);

				// Add new content into this array once it's passed validation
				$new_content = array();

				foreach ($error_params as $error_param) {
					if (isset($_POST[$error_param['id']]) && $_POST[$error_param['id']] == $error_param['check']) {
						$errors[] = $error_param['response'];
					}
				}
				if (count($errors) != 0) {
					// If we've found errors, let the user know
					$intro = __('We found', 'wp-discussion-board');
					$problems = _n('an item missing:', 'some items missing:', count($errors), 'wp-discussion-board');
					$output = '<div class="ctdb-errors">' . $intro . ' ' . $problems;
					$output .= '<ul>';
					// We found an error so display the form
					foreach ($errors as $error) {
						$output .= '<li>' . $error . '</li>';
					}
					$output .= '</ul></div>';
					$output .= $this->new_topic_form_content();
				} else {
					$output = '';
					// No errors so create the new topic
					$options = get_option('ctdb_options_settings');
					if (isset($options['new_topic_status'])) {
						$status = 'publish';
					} else {
						$status = 'draft';
					}

					$allowed_tags = wp_kses_allowed_html('post');
					unset($allowed_tags['a']);

					$post_args = array(
						'post_title'		=> wp_strip_all_tags($_POST['topic_title']),
						'post_content'		=> strip_shortcodes(wp_kses($_POST['topic_content'], $allowed_tags)), //strip_shortcodes(sanitize_textarea_field(strip_tags($_POST['topic_content'], $allowed_tags))),
						'post_status'		=> $status,
						'post_type' 		=> 'discussion-topics',
						'comment_status'	=> 'open', // Forces the comment status to open - otherwise no one can reply
					);

					// Check for taxonomy
					$post_args = apply_filters('ctdb_post_args', $post_args);

					if (!$has_duplicate) {
						// Create the new topic
						$my_post_id = wp_insert_post($post_args);

						// Filter the new topic ID. Not sure we need this.
						$my_post_id = apply_filters('ctdb_post_id', $my_post_id);

						// Save the uniqid value to prevent duplicate topics
						update_post_meta($my_post_id, 'ctdb_uniqid', sanitize_text_field($_POST['ctdb_uniqid']));

						// Do stuff with the topic ID
						// @hooked CT_DB_Pro_Categories::create_new_term
						do_action('ctdb_new_topic_id', $my_post_id);
					}


					if ($my_post_id !== false) {
						// Display success message
						if ($status == 'publish') {
							$output .= '<p>' . stripslashes(wp_strip_all_tags($_POST['topic_title'])) . __(' successfully added. View it at:', 'wp-discussion-board') . '<br>';
							$url = get_permalink($my_post_id);
							$output .= '<a href="' . esc_url($url) . '">' . $url . '</a></p>';
						} else {
							$output .= '<p>' . wp_strip_all_tags($_POST['topic_title']) . __(' is awaiting moderation', 'wp-discussion-board') . '</p>';
						}
					}
				}
			} else {
				// Check for time limit to prevent multiple quick posts
				$options = get_option('ctdb_options_settings');
				$delay = $options['new_post_delay'];
				$user = wp_get_current_user();
				// Get the time of the user's last topic
				$last_post = get_posts(
					array(
						'author'		=> $user->ID,
						'orderby'		=> 'date',
						'post_type'		=> 'discussion-topics',
						'numberposts'	=> 1
					)
				);
				if ($last_post) {
					$last_post = $last_post[0];
					$last_post_time = get_post_time('U', true, $last_post->ID);
				} else {
					$last_post_time = 0;
				}
				$time_now = date('U');
				// We can set delay to 0 to allow quick reposting
				// Gets round time-based errors with dodgy plugins
				if (absint($time_now) - absint($last_post_time) < $delay && $delay != 0) {
					// User isn't permitted to post another topic yet
					if ($delay > 60) {
						$minutes = $delay / 60 . __(' minutes', 'wp-discussion-board');
					} else {
						$minutes = __('a minute', 'wp-discussion-board');;
					}
					$output = '<p>' . __('You can\'t post a new topic just yet. Please come back in ') . $minutes . '.</p>';
				} else if ($this->user_can_post) {
					// User is permitted to post another topic
					$output = $this->new_topic_form_content();
				} else {
					// User can't view
					$output = $this->access_restricted_message;
				}
			}

			$output = apply_filters('ctdb_topic_form', $output);

			return $output;
		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-front-end.php

Discussion Board – WordPress Forum [discussion_topics] Shortcode

The wp-discussion-board plugin shortcode ‘discussion_topics’ displays all discussion topics in a chosen layout. It allows customization of the order, columns, and number of topics displayed per page. The shortcode also includes navigation and handles user permissions, only displaying topics to permitted users. If no topics are found, a message is displayed.

Shortcode: [discussion_topics]

Parameters

Here is a list of all possible discussion_topics shortcode parameters and attributes:

  • orderby – sets the sorting criteria for the topics
  • order – defines the sorting order, either ascending (ASC) or descending (DESC)
  • cols – determines which columns to display: avatar, topic, replies, started
  • number – sets the number of topics to display per page
  • show_nav – indicates whether to show navigation or not

Examples and Usage

Basic Example – Displaying the discussion topics with the default settings

[discussion_topics]

Advanced Examples

Displaying the discussion topics in ascending order by title

[discussion_topics orderby="title" order="ASC"]

Displaying the discussion topics with specific columns (avatar, topic, replies, and started), in descending order by date, and showing 5 topics per page

[discussion_topics cols="avatar,topic,replies,started" orderby="date" order="DESC" number="5"]

Displaying the discussion topics without navigation

[discussion_topics show_nav="false"]

Remember that the ‘cols’ attribute accepts a comma-separated list of column names, and the ‘orderby’ attribute accepts the name of the column to sort by. The ‘order’ attribute accepts either ‘ASC’ for ascending order or ‘DESC’ for descending order. The ‘number’ attribute is used to set the number of topics per page, and the ‘show_nav’ attribute can be set to ‘false’ if you don’t want to display navigation.

PHP Function Code

In case you have difficulties debugging what causing issues with [discussion_topics] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('discussion_topics', array($this, 'display_all_topics'), 10, 2);

Shortcode PHP function:

function display_all_topics($atts, $class = '')
		{

			$options = get_option('ctdb_design_settings');
			$topics_per_page = 10;
			if (isset($options['number_topics'])) {
				$topics_per_page = $options['number_topics'];
			}

			// We can filter our attributes here
			$atts = apply_filters('ctdb_discussion_topics_shortcode_atts', $atts);

			extract(shortcode_atts(array(
				'orderby'		=> 'date',
				'order'			=> 'DESC',
				'cols'			=> 'avatar,topic,replies,started',
				'number'		=> $topics_per_page,
				'show_nav'		=> true
			), $atts));

			$output = '';

			if (empty($cols)) {
				$cols = array('avatar', 'topic', 'replies', 'started');
			} else {
				$cols = explode(',', str_replace(' ', '', $cols));
			}

			global $CT_DB_Public;

			if (ctdb_is_user_permitted() == true) {

				// Only display topics if number of topics is greater than 0
				if ($number > 0) {
					// Get the layout style
					// Return standard layout
					// @updated 1.7.0 for new Style setting
					if (isset($options['layout'])) {
						$layout = $options['layout'];
					} else if (!isset($options['archive_layout']) || $options['archive_layout'] == 'standard') {
						$layout = 'standard';
					} else {
						$layout = $options['archive_layout'];
					}

					/*
					 * Updated @1.5.1
					 * Fixed pagination on static home page
					 */
					global $paged;

					if (get_query_var('paged')) {
						$paged = get_query_var('paged');
					} else if (get_query_var('page')) {
						$paged = get_query_var('page');
					} else {
						$paged = 1;
					}
					//	$page = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
					$offset = ($paged - 1) * $topics_per_page;

					$args = array(
						'post_type'			=>	'discussion-topics',
						'paged'				=>	$paged,
						'posts_per_page'	=>	$number,
						'offset'			=>	$offset
					);

					if (isset($orderby)) {
						$permitted_params = array('date', 'title', 'author', 'modified', 'rand', 'comment_count');
						$permitted_params = apply_filters('ctdb_discussion_topics_shortcode_orderby', $permitted_params);
						if (in_array($orderby, $permitted_params)) {
							// Only specify this param if it's in our list of permitted params
							$args['orderby'] = esc_attr($orderby);
						}
					}

					if (isset($order)) {
						$args['order'] = esc_attr($order);
					}

					// We can filter our arguments here
					$args = apply_filters('ctdb_discussion_topics_shortcode_args', $args, $atts);

					$topics = new WP_Query($args);

					if ($topics->have_posts()) {

						if ($layout == 'standard') {
							$output = $this->return_standard_layout($topics);
						} else {
							$output = $this->return_table_layout($topics, $cols);
						}

						if (isset($show_nav) && $show_nav == true) {
							$output .= '<ul class="ctdb-pagination"><li class="prev">' . get_previous_posts_link('<< Previous', $topics->max_num_pages) . '</li><li class="next">' . get_next_posts_link('Next >>', $topics->max_num_pages) . '</li></ul>';
						}
					} else {

						// No topics found
						$output .= '<div class="ctdb-no-topics-message ' . $class . '">';
						$output .= __('There are no topics posted yet.', 'wp-discussion-board');
						$output .= '</div>';
					}

					wp_reset_query();
				}
			} else {

				// User can't view
				$output .= $this->access_restricted_message;
			}

			$output = apply_filters('ctdb_discussion_topics_end', $output);

			return $output;
		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-front-end.php

Discussion Board – WordPress Forum [recent_discussion_topics] Shortcode

The WP-Discussion-Board shortcode ‘recent_discussion_topics’ displays the most recent discussion topics on your WordPress site. It fetches the latest topics based on the set number, and can optionally show excerpts and additional information.

Shortcode: [recent_discussion_topics]

Parameters

Here is a list of all possible recent_discussion_topics shortcode parameters and attributes:

  • number – defines how many recent discussion topics to display
  • show_excerpt – decides if a short summary of the topic should be shown
  • show_info – determines if additional information bar should be displayed

Examples and Usage

Basic example – Displaying the most recent 5 discussion topics.

[recent_discussion_topics number=5]

Advanced examples

Displaying the most recent 10 discussion topics with their excerpts.

[recent_discussion_topics number=10 show_excerpt=true]

Displaying the most recent 3 discussion topics with additional information bar.

[recent_discussion_topics number=3 show_info=true]

Displaying the most recent 7 discussion topics with their excerpts and additional information bar.

[recent_discussion_topics number=7 show_excerpt=true show_info=true]

PHP Function Code

In case you have difficulties debugging what causing issues with [recent_discussion_topics] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('recent_discussion_topics', array($this, 'display_recent_topics'));

Shortcode PHP function:

function display_recent_topics($atts)
		{

			extract(shortcode_atts(array(
				'number'		=>	5,
				'show_excerpt'	=>	false,
				'show_info'		=>	false,
			), $atts));

			$output = '';

			if ($this->user_can_view == true) {

				$options = get_option('ctdb_options_settings');

				// Create the query of topics
				$args = array(
					'post_type'			=>	'discussion-topics',
					'posts_per_page'	=>	$number
				);
				$topics = new WP_Query($args);

				if ($topics->have_posts()) {

					$output .= '<ul class="ctdb-recent-topics">';

					while ($topics->have_posts()) : $topics->the_post();

						$url = get_permalink();

						$output .= '<li>';

						$output .= sprintf(
							'<a href="%1$s">%2$s</a>',
							esc_url($url),
							get_the_title()
						);

						if ($show_excerpt) {
							// Excerpt
							$output .= '<div class="ctdb-excerpt">';
							$output .= '<p>' . get_the_excerpt() . '</p>';
							$output .= '</div><!-- .ctdb-excerpt -->';
						}

						if ($show_info) {
							$output .= $this->display_information_bar();
						}

						$output .= '</li>';

					endwhile;

					$output .= '</ul><!-- .ctdb-recent-topics -->';

					wp_reset_query();
				}
			} else {

				// User can't view
				// Don't display anything

			}

			return $output;
		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-front-end.php

Discussion Board – WordPress Forum [discussion_board_log_in_out] Shortcode

The WP-Discussion-Board plugin shortcode ‘discussion_board_log_in_out’ is designed to manage user login and logout functionality. It checks if a user is logged in, and if so, provides a logout URL. If the user is not logged in, it checks for a front-end login page option and provides a login URL. If no front-end login page is set, it returns nothing.

Shortcode: [discussion_board_log_in_out]

Examples and Usage

Basic example – A simple way to use the ‘discussion_board_log_in_out’ shortcode is by directly inserting it into your post or page. This will return a logout link if the user is logged in, or a login link if the user is not logged in, provided a front-end login page is set in the plugin’s options.

[discussion_board_log_in_out /]

Advanced examples

Although the ‘discussion_board_log_in_out’ shortcode does not accept any parameters, you can use it in conjunction with other shortcodes or blocks for more advanced use cases. For instance, you can use it with the ‘if’ shortcode from the ‘Shortcoder’ plugin to display different content based on whether the user is logged in or not.

[sc_if is_user_logged_in="yes"] Welcome, user! [discussion_board_log_in_out /] [/sc_if]

In the above example, if the user is logged in, they will see a welcome message along with the logout link. If they are not logged in, they won’t see anything.

Another example could be using it with the ‘else’ shortcode from the ‘Shortcoder’ plugin.

[sc_if is_user_logged_in="yes"] Welcome, user! [discussion_board_log_in_out /] [sc_else] Please log in to view the content. [discussion_board_log_in_out /] [/sc_if]

In this example, logged-in users will see a welcome message and a logout link, while non-logged-in users will be encouraged to log in to view the content.

PHP Function Code

In case you have difficulties debugging what causing issues with [discussion_board_log_in_out] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('discussion_board_log_in_out', array($this, 'return_logout_url'), 10, 2);

Shortcode PHP function:

function return_logout_url()
		{

			if (is_user_logged_in()) {

				$url = wp_logout_url(get_permalink());

				$logout = sprintf(
					'<p><a href="%1$s" title="%2$s">%3$s</a></p>',
					esc_url($url),
					__('Log out', 'wp-discussion-board'),
					__('Log out', 'wp-discussion-board')
				);

				return $logout;
			} else {

				// See if there's a front-end log-in page to display
				$options = get_option('ctdb_options_settings');

				if ($options['frontend_login_page']) {

					$login = sprintf(
						'<p><a href="%1$s" title="%2$s">%3$s</a></p>',
						esc_url(get_permalink($options['frontend_login_page'])),
						__('Log in', 'wp-discussion-board'),
						__('Log in', 'wp-discussion-board')
					);

					return $login;
				} else {

					// Return nothing
					return;
				}
			}
		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-front-end.php

Discussion Board – WordPress Forum [is_logged_in] Shortcode

The WP-Discussion-Board plugin’s shortcode, ‘is_logged_in’, is designed to check if a user is logged in. This shortcode, when implemented, returns the enclosed content only if the user is logged in. If not, it returns an empty string. This allows for user-specific content customization.

Shortcode: [is_logged_in]

Examples and Usage

Basic example – A simple usage of the ‘is_logged_in’ shortcode that only displays content to logged-in users.

[is_logged_in]Welcome, registered user![/is_logged_in]

Advanced examples

Combining the ‘is_logged_in’ shortcode with other shortcodes, to display specific content to logged-in users. In this example, a logged-in user will see a contact form (assuming a contact form plugin is installed and a form with ID 123 exists).

[is_logged_in][contact-form-7 id="123"][/is_logged_in]

Using nested ‘is_logged_in’ shortcodes to display different content to logged-in users. In this example, a logged-in user will see a welcome message, while a non-logged-in user will see a login prompt.

[is_logged_in]Welcome, registered user![/is_logged_in][is_logged_out]Please login to view more content[/is_logged_out]

Please note that these examples assume that the ‘is_logged_out’ shortcode functions similarly to ‘is_logged_in’, but in reverse (i.e., it only displays content to non-logged-in users).

PHP Function Code

In case you have difficulties debugging what causing issues with [is_logged_in] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('is_logged_in', array($this, 'is_logged_in_shortcode'), 10, 2);

Shortcode PHP function:

function is_logged_in_shortcode($atts, $content = null)
		{

			$output = '';

			if (is_user_logged_in()) {

				$output = do_shortcode($content);
			}

			return $output;
		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-front-end.php

Discussion Board – WordPress Forum [not_logged_in] Shortcode

The wp-discussion-board plugin’s ‘not_logged_in’ shortcode checks if a user is logged in or not. When the shortcode is used, it probes the user’s login status. If the user is not logged in, it executes the enclosed content. If the user is logged in, it returns an empty string. This shortcode is useful for displaying content exclusively to guests.

Shortcode: [not_logged_in]

Examples and Usage

Basic example – A simple usage of the shortcode to display content only for guests (not logged in users).

[not_logged_in]Welcome, please log in to access more content.[/not_logged_in]

Advanced examples

Embedding another shortcode within the ‘not_logged_in’ shortcode. In this case, a login form shortcode is displayed for guests. This is useful if you want to prompt guests to log in directly from the page they are viewing.

[not_logged_in][login_form][/not_logged_in]

Combining the ‘not_logged_in’ shortcode with conditional shortcodes. In this example, a specific message is shown to guests, while a different message is shown to logged in users.

[not_logged_in]Welcome, please log in to access more content.[/not_logged_in][is_logged_in]Welcome back, enjoy your visit.[/is_logged_in]

Please note that the ‘login_form’ and ‘is_logged_in’ shortcodes are just placeholders for actual shortcodes that you would use in your WordPress site.

PHP Function Code

In case you have difficulties debugging what causing issues with [not_logged_in] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('not_logged_in', array($this, 'not_logged_in_shortcode'), 10, 2);

Shortcode PHP function:

function not_logged_in_shortcode($atts, $content = null)
		{

			$output = '';

			if (!is_user_logged_in()) {

				$output = do_shortcode($content);
			}

			return $output;
		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-front-end.php

Discussion Board – WordPress Forum [new_topic_button] Shortcode

The WP-Discussion-Board plugin’s shortcode, ‘new_topic_button’, generates a button for users to start a new topic. The shortcode accepts ‘class’ and ‘text’ attributes to customize the button’s styling and label. If the new topic page is set in the plugin settings, the button redirects to that page. If not, a message is displayed to the admin to set the page.

Shortcode: [new_topic_button]

Parameters

Here is a list of all possible new_topic_button shortcode parameters and attributes:

  • class – CSS class to style the new topic button.
  • text – Defines the text displayed on the new topic button.

Examples and Usage

Basic example – A simple usage of the new_topic_button shortcode with no additional attributes.

[new_topic_button /]

Advanced examples

Customizing the new_topic_button shortcode by adding a specific class to the button. This can be useful for applying custom CSS styles to the button.

[new_topic_button class="my-custom-class" /]

Changing the text displayed on the new_topic_button. This can be helpful for non-English sites or to better suit the context of your site.

[new_topic_button text="Start a Discussion" /]

Combining both class and text attributes for more advanced customization of the new_topic_button shortcode.

[new_topic_button class="my-custom-class" text="Start a Discussion" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [new_topic_button] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('new_topic_button', array($this, 'new_topic_button_shortcode'));

Shortcode PHP function:

function new_topic_button_shortcode($atts)
		{

			extract(shortcode_atts(array(
				'class' => '',
				'text' 	=> __('Add new topic', 'wp-discussion-board')
			), $atts));

			$atts = apply_filters('ctdb_new_topic_button_atts', $atts);

			$output = '';

			// Get the page with the new topic form
			$options = get_option('ctdb_options_settings');
			if (isset($options['new_topic_page']) && $options['new_topic_page'] != '') {
				$new_topic_page = intval($options['new_topic_page']);
				// URL for the button
				$url = get_permalink($new_topic_page);
				$url = apply_filters('ctdb_new_topic_button_url', $url, $atts, $new_topic_page);
				$output .= sprintf(
					'<a class="ctdb-new-topic-button %s" href="%s">%s</a>',
					esc_attr($class),
					esc_url($url),
					esc_html($text)
				);
			} else {
				// Display a message to admins that there's no topic page set
				// Show admin a message to let them know
				if (current_user_can('update_plugins')) {
					return '<p class="ctdb-admin-message">' . __('Site Admin: please set the "New topic form page" field in Settings > Discussion Board > Options for the new_topic_button shortcode to work. This message will not be displayed to non-admins.', 'wp-discussion-board') . '</p>';
				} else {
					return;
				}
			}

			$output = apply_filters('ctdb_new_topic_button_filter', $output, $atts);

			return $output;
		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-front-end.php

Discussion Board – WordPress Forum [discussion_board_login_form] Shortcode

The wp-discussion-board plugin shortcode enables a login/registration form. It checks if a user is logged in or if registration is successful. If not, it displays a login and registration form. It also allows the use of icons and the ability to hide the registration tab.

Shortcode: [discussion_board_login_form]

Examples and Usage

Basic example – Display a login form using the ‘discussion_board_login_form’ shortcode without any parameters:

[discussion_board_login_form]

Advanced examples

Display a login form with custom attributes. In this example, we are passing two attributes, ‘id’ and ‘title’. The form will first try to load by ‘id’, but if not found, it will try to load by ‘title’.

[discussion_board_login_form id=1 title="User Login"]

Using the shortcode to display a login form with a custom class name. This can be useful for applying custom CSS styles to the form.

[discussion_board_login_form class="custom-login-form"]

Using the shortcode to display a login form with a custom redirect URL. This can be useful for directing users to a specific page after they log in.

[discussion_board_login_form redirect_url="https://yourwebsite.com/welcome-page"]

Please note that the shortcode attributes ‘id’, ‘title’, ‘class’, and ‘redirect_url’ may not work if they are not defined in the ‘return_login_registration_form’ function in your plugin’s code. Always refer to the plugin’s documentation or code to confirm the available attributes.

PHP Function Code

In case you have difficulties debugging what causing issues with [discussion_board_login_form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'discussion_board_login_form', array( $this, 'return_login_registration_form' ), 10, 2 );

Shortcode PHP function:

function return_login_registration_form( $atts, $content = '' ) {

			$successful_registration = false;
			if ( ! empty( $_POST['ctdb_user_email'] ) ) {
				$user_email = sanitize_email( wp_unslash( $_POST['ctdb_user_email'] ) );
				$user       = get_user_by( 'email', $user_email );
				if ( $user ) {
					$successful_registration = true;
				}
			}

			if ( ! is_user_logged_in() && ! $successful_registration ) {

				$message = '';
				$class   = '';

				// Check if styles are enqueued
				$options           = get_option( 'ctdb_design_settings' );
				$general_options   = get_option( 'ctdb_options_settings' );
				$hide_registration = ! empty( $general_options['hide_registration_tab'] ) ? true : false;

				// Use icons?
				$show_icons = ctdb_use_icons();

				// Log in tab
				$message .= '<div class="ctdb-login-form-wrapper">';
				if ( isset( $_POST['ctdb_page'] ) && $_POST['ctdb_page'] != 'register' ) {
					$class = 'active-header';
				}
				$message .= '<div class="ctdb-header ' . $class . '" data-form-id="ctdb-login-wrap"><h3 class="ctdb-h3">';
				if ( $show_icons ) {
					$message .= '<span class="dashicons dashicons-unlock"></span>';
				}
				$message .= __( 'Log in', 'wp-discussion-board' ) . '</h3></div>';

				// If styles are not enqueued we will display the log-in form fields directly after the heading
				if ( empty( $options['enqueue_styles'] ) ) {
					$message .= $this->display_login_form();
				}

				// Registration tab
				if ( ! $hide_registration ) {
					$class = '';
					if ( isset( $_POST['ctdb_page'] ) && $_POST['ctdb_page'] == 'register' ) {
						$class = 'active-header';
					}
					$message .= '<div class="ctdb-header ' . $class . '" data-form-id="ctdb-registration-wrap"><h3 class="ctdb-h3">';
					if ( $show_icons ) {
						$message .= '<span class="dashicons dashicons-edit"></span>';
					}
					$message .= __( 'Register', 'wp-discussion-board' ) . '</h3></div>';
				}

				// Get the forms HTML

				// If styles are enqueued we will display the log-in form fields after both headings
				if ( ! empty( $options['enqueue_styles'] ) ) {
					$message .= $this->display_login_form();
				}

				if ( ! $hide_registration ) {
					$message .= $this->display_registration_form();
				}

				$message .= '</div><!-- .ctdb-login-form-wrapper -->';

				$message .= '<script>
					jQuery(document).ready(function($){
						$(".ctdb-header").on("click",function(){
							id = $(this).data("form-id");
							$(".ctdb-header").removeClass("active-header");
							$(this).addClass("active-header");
							$(".ctdb-form-section").removeClass("active-section");
							$("#"+id).addClass("active-section");
						});
					});
				</script>';

			} else {

				$message = do_shortcode( $content );

			}

			return $message;

		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-registration.php

Discussion Board – WordPress Forum [discussion_board_login_only] Shortcode

The WP-Discussion-Board shortcode is designed to display a login form for users who are not logged in. It checks user status, enqueues styles, and presents an icon-based login tab. When a user is logged in, the shortcode executes the content within its enclosing tags, making it versatile for content display.

Shortcode: [discussion_board_login_only]

Examples and Usage

Basic example – The shortcode will display the login form only if the user is not logged in.

[discussion_board_login_only /]

Advanced examples

Using the shortcode to display a custom message after the login form. This will be shown only if the user is not logged in. The content within the shortcode will be processed and displayed if the user is logged in.

[discussion_board_login_only]Welcome to the discussion board![/discussion_board_login_only]

Specifying the attributes in the shortcode. Please note that the attributes are not processed in the basic shortcode implementation. They are included here for illustration purposes and will require modification of the shortcode function to work.

[discussion_board_login_only attr1="value1" attr2="value2"]Welcome to the discussion board![/discussion_board_login_only]

PHP Function Code

In case you have difficulties debugging what causing issues with [discussion_board_login_only] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'discussion_board_login_only', array( $this, 'return_login_form_only' ), 10, 2 );

Shortcode PHP function:

function return_login_form_only( $atts, $content = '' ) {

			if ( ! is_user_logged_in() ) {

				$message = '';
				$class   = '';

				// Check if styles are enqueued
				$options = get_option( 'ctdb_design_settings' );

				// Use icons?
				$show_icons = ctdb_use_icons();

				// Log in tab
				$message .= '<div class="ctdb-header active-header" data-form-id="ctdb-login-wrap"><h3 class="ctdb-h3">';
				if ( $show_icons ) {
					$message .= '<span class="dashicons dashicons-unlock"></span>';
				}
				$message .= __( 'Log in', 'wp-discussion-board' ) . '</h3></div>';

				// Fake page to show form
				$_POST['ctdb_page'] = 'login';

				// Get the forms HTML
				$message .= $this->display_login_form();

			} else {

				$message = do_shortcode( $content );

			}

			return $message;

		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-registration.php

Discussion Board – WordPress Forum [discussion_board_registration_only] Shortcode

The wp-discussion-board plugin shortcode ‘discussion_board_registration_only’ handles the registration process. It checks if a user is registered by validating the email address. If the user is not registered, it displays the registration form.

Shortcode: [discussion_board_registration_only]

Examples and Usage

Basic example – A simple implementation of the ‘discussion_board_registration_only’ shortcode. This will return a registration form for discussion boards.

[discussion_board_registration_only /]

Advanced examples

Using the shortcode with additional parameters to customize the display. For example, you can pass in user email as a parameter to check if a user is already registered. If the user is found, a successful registration message will be displayed. If the user is not found, the registration form will be displayed.

[discussion_board_registration_only ctdb_user_email="user@example.com" /]

Another advanced example is to use the shortcode within the content of a page or post. This will display the registration form within the content where the shortcode is placed. If the user is logged in, the content of the page or post will be displayed instead.

[discussion_board_registration_only]Welcome to our discussion board. Please register to participate in the discussions.[/discussion_board_registration_only]

PHP Function Code

In case you have difficulties debugging what causing issues with [discussion_board_registration_only] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'discussion_board_registration_only', array( $this, 'return_registration_form_only' ), 10, 2 );

Shortcode PHP function:

function return_registration_form_only( $atts, $content = '' ) {

			$successful_registration = false;
			if ( ! empty( $_POST['ctdb_user_email'] ) ) {
				$user_email = sanitize_email( wp_unslash( $_POST['ctdb_user_email'] ) );
				$user       = get_user_by( 'email', $user_email );
				if ( $user ) {
					$successful_registration = true;
				}
			}

			if ( ! is_user_logged_in() ) {

				$message = '';
				$class   = '';

				// Check if styles are enqueued
				$options = get_option( 'ctdb_design_settings' );

				// Use icons?
				$show_icons = ctdb_use_icons();

				// Registration tab
				$message .= '<div class="ctdb-header active-header" data-form-id="ctdb-registration-wrap"><h3 class="ctdb-h3">';
				if ( $show_icons ) {
					$message .= '<span class="dashicons dashicons-edit"></span>';
				}
				$message .= __( 'Register', 'wp-discussion-board' ) . '</h3></div>';

				// Fake page to show form
				$_POST['ctdb_page'] = 'register';

				// Get the forms HTML
				$message .= $this->display_registration_form();

			} else {

				$message = do_shortcode( $content );

			}

			return $message;

		}

Code file location:

wp-discussion-board/wp-discussion-board/includes/classes/class-ct-db-registration.php

Conclusion

Now that you’ve learned how to embed the Discussion Board – WordPress Forum Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *