• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

Implemented XF Forums Drop Down

dethfire

Baby Penguin
XenWord Professional
WordPress version: current
XenForo version: current
XenWord version: current


Categories are listed along with forums. So potentially a category can be selected as where to post the thread. I don't think that is intended and can cause some confusion.
 

dethfire

Baby Penguin
XenWord Professional
Also it appears the drop down selection doesn't stick. I it always resets to the last forum. Nothing I select sticks after saving.
 

LPH

Flight Director
Flight Instructor
Correct on both of these --

Categories are listed -- and nested if you use a different browser than Chrome
The code does not show the selected forum but it is written to the database

I've considered changing the behavior but am watching to see reactions to the changes made in 2.5.
 

LPH

Flight Director
Flight Instructor
In looking at the code in class-xenword-metabox-forumid.php. You can add a conditional to only show the forums. Here is the code.

PHP:
/**
* Prints the box content.
*
* @since 2.2.0.1
*
* @param $forums
*/
function show_forum_id_meta_box( $post ) {

    // Add an nonce field so we can check for it later.
    wp_nonce_field( 'xenword_meta_forum_id_box', 'xenword_meta_box_forum_id_nonce' );

    $forums = XenForo_Model_Node::create( 'XenForo_Model_Node' )->getModelFromCache( 'XenForo_Model_Node' )->getViewableNodeList( null, true );

    echo '<select id="xenword_forum_id" name="xenword_forum_id" class="textCtrl" ><optgroup label="Choose Forum">';

    foreach ( $forums as $forum ) {

        if ($forum['node_type_id'] == 'Forum') {

            echo '<option value="' . $forum['node_id'] . '"';

            echo ' selected="selected"' . 'class="_depth' . $forum['depth'] . '"';

            echo '>' . $forum['title'] . '</option>';
        }

    }

    echo '</optgroup></select>';
}

The key is the conditional
Code:
if ($forum['node_type_id'] == 'Forum') {
 

dethfire

Baby Penguin
XenWord Professional
Not having the forum selection stick is a real problem because if you forget to set every time you update, it will move the thread to a different forum. Other authors are definitely going to forget.
 
Last edited:

LPH

Flight Director
Flight Instructor
It's been this way since the first coding of the forum pull down. It'll take time to figure out how to get the select. If you look at the code you'll see why this is not an easy fix.
 

LPH

Flight Director
Flight Instructor
OK. I tackled this code so that the forum selected is shown. It will be released in 2.5.1. This is the code if anyone would like to make a change.

Open class-xenword-metabox-forumid.php and find the function show_forum_id_meta_box( $post ).

PHP:
/**
 * Prints the box content.
 *
 * @since 2.2.0.1
 *
 * @param $post
 *
 * @throws XenForo_Exception
 */
function show_forum_id_meta_box( $post ) {

	// Add an nonce field so we can check for it later.
	wp_nonce_field( 'xenword_meta_forum_id_box', 'xenword_meta_box_forum_id_nonce' );

	$forumId = $post->forum_id;

	/** @var  $forumModel XenForo_Model_Node */
	$forumModel = XenForo_Model_Node::create( 'XenForo_Model_Node' );
	$forums = $forumModel->getViewableNodeList( null, true );

	echo '<select id="xenword_forum_id" name="xenword_forum_id" class="textCtrl" >';

	foreach ( $forums as $forum ) {

		if ( $forum['node_type_id'] == 'Forum' ) {

			echo '<option value="' . $forum['node_id'] . '"';

			if ( $forum['node_id'] == $forumId ) {
				echo 'selected="selected"';
			}

			echo ' class="_depth' . $forum['depth'] . '">' . $forum['title'] . '</option>';

		}
	}

	echo '</select>';
}
 
Top