My Wordpress plugin is causing the page/post editor to display the update/publishing failed notice when you press publish/update on a page/post with its shortcode embedded, however, the data is being update/published.
I have enable WP_DEBUG and WP_DEBUG_LOG but they are not really that helpful as the only error reported is as follows:
PHP Notice: edit_form_advanced is <strong>deprecated</strong> since version 5.0.0! Use block_editor_meta_box_hidden_fields instead. This action is still supported in the classic editor, but is deprecated in the block editor. in /wp-includes/functions.php on line 4112
I checked the file but it is a WP core file as you can see and the function is simply an error logger.
I know the problem is to do with the Gutenberg editor as the plugin works as expected when in the classic editor.
After reading I noted people suggesting putting the output of the shortcode into a variable and returning that, which I have done to no avail.
The code which I think is relevant is here:
function enu_explorer_shortcode() {
$output = '';
include_once "eurno_include_file.php";
begin_eurno_explorer();
return $output;
}
add_shortcode( 'eurno_explorer', 'enu_explorer_shortcode' );
and the code from the file eurno_include_file.php is here:
function begin_eurno_explorer() {
if (!isset($_GET['action'])) {
if(((!empty(key($_GET))) && (!isset($_GET['preview']))) ){
$chainName = key($_GET);
if(isset($_GET[$chainName])){
$name = $_GET[$chainName];
}
if(isset(get_option('eurno_explorer')['eurno_data']['api'][$chainName][0])){
$api = get_option('eurno_explorer')['eurno_data']['api'][$chainName][0];
}
if(!isset(get_option('eurno_explorer')['eurno_data']['api'][$chainName][0])) {
$api = 'https://enu.qsx.io:443';
}
} else {
$chainName = 'enu';
$api = 'https://enu.qsx.io:443';
}
$output = (include "header.php");
$output .= (include "config/search.php");
if((isset($_GET[$chainName])) && (empty($_GET[$chainName])) || (!isset($_GET[$chainName]))) {
$output .= (include "config/chain-info.php");
$output .= (include "config/block-producers.php");
return;
} elseif(isset($_GET[$chainName]) && (strlen($_GET[$chainName]) === 64) && (ctype_xdigit($_GET[$chainName]))) {
$output .= (include "config/transaction.php");
return;
} elseif((isset($_GET[$chainName])) && (strlen($_GET[$chainName]) <= 12)){
$output .= (include 'config/recent-transactions.php');
return;
}
$term = implode(", ", $_GET);
$chain = key($_GET);
$output .= '<div class="card border border-danger mt-5">';
$output .= '<div class="card-header alert alert-danger">';
$output .= 'Showing results for: '.$term.' on: ' . $chain;
$output .= '</div>';
$output .= '<div class="card-body">';
$output .= '<div class="p-4">';
$output .= '<h4>Well, this is embarassing.</h4>';
$output .= '<p>We can\'t seem to find anything for <b>'.$term.'</b> on the <b>'.$chain.'</b> blockchain. Are you sure you have entered a valid transaction ID or account name?.</p>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
}
If you would like a further look into the plugin's code it can be found at: https://github.com/eurno/eurno-explorer
Thank you in advance it is really appreciated.
It turned out that, although I was assigning my output to a variable which I was returning, I was still ultimately echoing my data in the long run. In order to fix the problem without rewriting the majority of my code I had to use output buffering so now
function enu_explorer_shortcode() {
$output = '';
include_once "eurno_include_file.php";
begin_eurno_explorer();
return $output;
}
add_shortcode( 'eurno_explorer', 'enu_explorer_shortcode' );
to this:
function enu_explorer_shortcode() {
ob_start();
include_once "eurno_include_file.php";
begin_eurno_explorer();
$eurno_explorer_output = ob_get_clean();
return $eurno_explorer_output;
}
add_shortcode( 'eurno_explorer', 'enu_explorer_shortcode' );