• Resolved Manzoor Wani (a11n)

    (@manzoorwanijk)


    I am a plugin developer. My plugin uses ajax requests which return anything from 200 to 500 status headers. But when the error returned is not 200, the JSON is corrupted by WordFence. How to tackle the issue?

    Console Error

    View post on imgur.com

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • wfdave

    (@wfdave)

    Hi @manzoorwanijk,

    I just did some testing and it seems to work fine for me:

    <?php
    
    $rtn = [
        'ok' => false,
        'error_code' => 400,
        'description' => 'Bad Request: chat not found'
    ];
    
    http_response_code(400);
    
    echo json_encode($rtn);

    Can I see the code you’re running to generate the JSON and the code you’re using to parse the JSON. (Show me both the PHP and JavaScript)

    Dave

    Thread Starter Manzoor Wani (a11n)

    (@manzoorwanijk)

    OK, will test that and let you know…
    Thanks

    tutabook

    (@tutabook)

    <?php
    /**
    * Plugin Name: ShareThis Share Buttons
    * Plugin URI: https://sharethis.com/
    * Description: Integrates the ShareThis Sharing Buttons directly into your website.
    * Version: 1.1.8
    * Author: ShareThis
    * Author URI: https://sharethis.com/
    * Text Domain: sharethis-share-buttons
    * Domain Path: /languages
    * License: GPL v2 or later

    Copyright 2017 ShareThis

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    * @package ShareThisShareButtons
    */

    if ( version_compare( phpversion(), ‘5.3’, ‘>=’ ) ) {
    require_once __DIR__ . ‘/instance.php’;
    } else {
    if ( defined( ‘WP_CLI’ ) ) {
    WP_CLI::warning( _sharethis_share_buttons_php_version_text() );
    } else {
    add_action( ‘admin_notices’, ‘_sharethis_share_buttons_php_version_error’ );
    }
    }

    /**
    * Admin notice for incompatible versions of PHP.
    */
    function _sharethis_share_buttons_php_version_error() {
    printf( ‘<div class=”error”><p>%s</p></div>’, esc_html( _sharethis_share_buttons_php_version_text() ) );
    }

    /**
    * String describing the minimum PHP version.
    *
    * @return string
    */
    function _sharethis_share_buttons_php_version_text() {
    return __( ‘ShareThis Share Buttons plugin error: Your version of PHP is too old to run this plugin. You must be running PHP 5.3 or higher.’, ‘sharethis-share-buttons’ );
    }

    /**
    * The helper function to insert the proper inline button container.
    *
    * @return string
    */
    function sharethis_inline_buttons() {
    return ‘<div class=”sharethis-inline-share-buttons”></div>’;
    }

    add_filter( ‘plugin_action_links_’ . plugin_basename( __FILE__ ), ‘_sharethis_share_buttons_add_action_links’ );

    /**
    * Add a link to the settings page.
    *
    * @param string $links The links shown in the plugin page.
    *
    * @return array
    */
    function _sharethis_share_buttons_add_action_links( $links ) {
    $mylinks = array(
    Settings‘,
    );
    return array_merge( $links, $mylinks );
    }

    tutabook

    (@tutabook)

    <div class=”sharethis-inline-follow-buttons”></div>

    Hi @manzoorwanijk,

    We haven’t heard back from you in a while, so I’ve gone ahead and marked this thread as resolved.

    Please feel free to open another thread, if you’re still having issues with Wordfence.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WordFence corrupts JSON response from ajax if not 200’ is closed to new replies.