Skip to:
Content

bbPress.org

Opened 5 years ago

Last modified 4 years ago

#3365 assigned defect (bug)

variable mismatch on topic split

Reported by: robin-w's profile Robin W Owned by: johnjamesjacoby's profile johnjamesjacoby
Milestone: Under Consideration Priority: normal
Severity: normal Version: trunk
Component: API - Moderation Keywords: needs-patch
Cc:

Description

With the plugin 'theme my login' enabled, splitting a topic causes an error 'A variable mismatch has been detected'

Theme my login support state :

I’d suggest filing a bug report with bbPress. The issue is that TML registers ‘action’ as a public query variable with WP. WP has a check in WP::parse_request(), which ensures that all GET and POST values of public query variables match. If they don’t, it dies with the error message you are seeing. For whatever reason, bbPress uses a different action key depending on GET/POST context. In this specific instance, the GET value of ‘action’ is ‘split’. However, the POST value (set via hidden field in the form) is ‘bbp-split-topic’. This difference is causing the condition described above. In code:

<?php
$_GET['action'] = 'split';
$_POST['action'] = 'bbp-split-topic';

if ( isset( $_GET[ 'action' ] ) && isset( $_POST[ 'action' ] ) && $_GET[ 'action' ] !== $_POST[ 'action ] ) {
        wp_die( __( 'A variable mismatch has been detected.' ),

I have added the following filters to get round this

<?php
function rew_get_topic_split_link( $retval, $r, $args ) {

                // Parse arguments against default values
                $r = bbp_parse_args( $args, array(
                        'id'          => 0,
                        'link_before' => '',
                        'link_after'  => '',
                        'split_text'  => esc_html__( 'Split',                           'bbpress' ),
                        'split_title' => esc_attr__( 'Split the topic from this reply', 'bbpress' )
                ), 'get_topic_split_link' );

                // Get IDs
                $reply_id = bbp_get_reply_id( $r['id'] );
                $topic_id = bbp_get_reply_topic_id( $reply_id );

                // Bail if no reply/topic ID, or user cannot moderate
                if ( empty( $reply_id ) || empty( $topic_id ) || ! current_user_can( 'moderate', $topic_id ) ) {
                        return;
                }

                $uri = add_query_arg( array(
                        'action'   => 'bbp-split-topic',
                        'reply_id' => $reply_id
                ), bbp_get_topic_edit_url( $topic_id ) );

                $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" title="' . $r['split_title'] . '" class="bbp-topic-split-link">' . $r['split_text'] . '</a>' . $r['link_after'];

                // Filter & return
                return apply_filters( 'rew_get_topic_split_link', $retval, $r, $args );
        }

add_filter ('bbp_get_topic_split_link', 'rew_get_topic_split_link' , 10 , 3) ;

function rew_is_topic_split() {

        // Assume false
        $retval = false;

        // Check topic edit and GET params
        if ( bbp_is_topic_edit() && ! empty( $_GET['action'] ) && ( 'bbp-split-topic' === $_GET['action'] ) ) {
                $retval = true;
        }

        // Filter & return
        return (bool) apply_filters( 'rew_is_topic_split', $retval );
}

add_filter ('bbp_is_topic_split' , 'rew_is_topic_split' ) ;

Attachments (1)

0001-use-same-action-variables-for-GET-POST.patch (4.3 KB) - added by konnektiv 4 years ago.
This patch fixes the problem for us for move, split and merge.

Download all attachments as: .zip

Change History (3)

#1 @johnjamesjacoby
5 years ago

  • Component changed from General to API - Moderation
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Under Consideration
  • Owner set to johnjamesjacoby
  • Status changed from new to assigned
  • Version set to trunk

Originally reported in the forums here:

https://wordpress.org/support/topic/error-a-variable-mismatch-has-been-detected-2/
https://bbpress.org/forums/topic/error-a-variable-mismatch-has-been-detected/

The GET and POST requests should be contained to either being admin-side or theme-side.

If this in an issue with split it's probably also an issue with move and other actions, too.

This is going to need a bit more research to decide what the correct fix is.

#2 @konnektiv
4 years ago

We can confirm this bug also affects move action.

@konnektiv
4 years ago

This patch fixes the problem for us for move, split and merge.

Note: See TracTickets for help on using tickets.