• Resolved peesus

    (@peesus)


    I have been making a plugin and it uses a shortcode to display content on the users front end. The plugin works fully as expected apart from with the Gutenberg editor.

    When I press “save” or “update” WP displays the “publishing failed” or “update failed” error message. The strange thing is that it actually does save the content/changes.

    I have enable WP_DEBUG but it does not provide any further insight, I enable WP_DEBUG_LOG and I can see the following error:

    PHP Notice: edit_form_advanced is deprecated 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 have been digging around trying to find the cause and I am stumped. I have seen people quoting you need to return your content, which I am, my actual shortcode is as follows:

    function enu_explorer_shortcode() {
      return begin_eurno_explorer();
    }
    add_shortcode( 'eurno_explorer', 'enu_explorer_shortcode' );

    The function which it calls is as follows:

    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';
    }
    include_once "header.php";
    include_once "config/search.php";
    if((isset($_GET[$chainName])) && (empty($_GET[$chainName])) || (!isset($_GET[$chainName]))) {
      include_once "config/chain-info.php";
      include_once "config/block-producers.php";
      return;
    } elseif(isset($_GET[$chainName]) && (strlen($_GET[$chainName]) === 64) && (ctype_xdigit($_GET[$chainName]))) {
      include_once "config/transaction.php";
      return;
    } elseif((isset($_GET[$chainName])) && (strlen($_GET[$chainName]) <= 12)){
      include_once 'config/recent-transactions.php';
      return;
    }
    $term = implode(", ", $_GET);
    $chain = key($_GET);
    echo '<div class="card border border-danger mt-5">';
      echo '<div class="card-header alert alert-danger">';
        echo 'Showing results for: '.$term.' on: ' . $chain;
      echo '</div>';
      echo '<div class="card-body">';
        echo '<div class="p-4">';
          echo '<h4>Well, this is embarassing.</h4>';
          echo '<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>';
        echo '</div>';
      echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    }
    }

    Any insight is really appreciated.

    Thank you.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    You don’t have it *returning* your content. You have it *echoing* your content.

    Shortcode functions should return a string with the content in it. They should never “echo” that content, they should build a string and return it. WordPress takes care of putting the string into the output for you.

    Get rid of all those echo’s, build a string, return that string.

    If you don’t control how begin_eurno_explorer() behaves, then wrap that function call using PHP output buffering, get the echo’d data as a string, then flush it to prevent it from being echo’d and return the output as a string instead.

    Thread Starter peesus

    (@peesus)

    Thank you for responding and helping mate. Would you advise declaring a variable in each section or use one universal variable which I add the elements to with =.

    Moderator bcworkz

    (@bcworkz)

    It all has to boil down to one return value, whichever way you get there. Considering the code you posted includes external files which surely generate output, I think your best solution is to use output buffering.

    Thread Starter peesus

    (@peesus)

    You are an absolute diamond! Thank you so much mate I used

      ob_start();
      include_once "eurno_include_file.php";
      begin_eurno_explorer();
      $object = ob_get_clean();
      return $object;

    which seems to have done the trick! Thanks again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘“Update Failed” message but data is actually saved, Gutenberg’ is closed to new replies.