PDA

View Full Version : Vb Api Extension returns data and shows always after <body>


talhatc
07-18-2016, 10:23 PM
I am creating a Api Extension with the help of Wordpress Header & Footer Integation (https://vborg.vbsupport.ru/showthread.php?t=302307)

I am almost done and everything seems to be in order except, whenever I return a data, it always goes on the top of the browser, after the <body> tag, example given below:

class wpHeaderFooter_Api_Options extends vB_Api_Extensions
{
public $product = 'wpheaderfooter';
public $version = '1.0.0';
public $developer = 'me';
public $title = 'WordPress Integration Extension';
public $minver = '5.2.2';
public $maxver = '5.9.99';
public $infourl = '';
public $checkurl = '';
public $AutoInstall = 1;
public $extensionOrder = 10;

public function wpHeader($x){
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/wpfolder/wp-content/themes/mytheme/header-forums.php";
include_once($path);
return;
}

header-forums.php file simply contains an echo statement. VB displays it, but shows it on the top, even above the main-navbar-wrapper. However, the weird part is, if I do the following, it shows where the hook is supposed to show it

class wpHeaderFooter_Api_Options extends vB_Api_Extensions
{
public $product = 'wpheaderfooter';
public $version = '1.0.0';
public $developer = 'me';
public $title = 'WordPress Integration Extension';
public $minver = '5.2.2';
public $maxver = '5.9.99';
public $infourl = '';
public $checkurl = '';
public $AutoInstall = 1;
public $extensionOrder = 10;

public function wpHeader($x){
//$path = $_SERVER['DOCUMENT_ROOT'];
//$path .= "/wpfolder/wp-content/themes/mytheme/header-forums.php";
//include_once($path);
return "<h1>My Custom Footer</h1>";
}

Any help would be highly appreciated.

Replicant
07-18-2016, 11:11 PM
The echo statement is the problem. VB wants to display the returned data. Assign your data to a variable and return the variable.

$data = '<h1>My Custom Footer</h1>';
return $data;

talhatc
07-19-2016, 08:12 AM
The echo statement is the problem. VB wants to display the returned data. Assign your data to a variable and return the variable.

$data = '<h1>My Custom Footer</h1>';
return $data;

Well the issue isn't with the second piece of code from my post, outputting the following is causing the issue

public function wpHeader($x){
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/wpfolder/wp-content/themes/mytheme/header-forums.php";
include_once($path);
return;
}

Replicant
07-19-2016, 11:03 AM
Using an echo will show at the top of the page like a debug marker. You need to remove the echo.

in your snippet, you're doing "return;"

You need to put the data in a variable and "return $data;"