Why this global php does not echo in the Wordpress plugin
source link: https://www.codesd.com/item/why-this-global-php-does-not-echo-in-the-wordpress-plugin.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Why this global php does not echo in the Wordpress plugin
I'm new to PHP and I'm not sure why this doesn't work. I have done everything this page said http://php.net/manual/en/language.variables.scope.php (example #1 Using global)... Why is it not working? it's frustrating.
This is a first attempt on wordpress plugins. First file contains:
function pp_sa_menu(){
add_menu_page('Shadow Accounts Search', 'Shadow Accounts', 'manage_options', 'shadow_accounts', 'pp_sa_search');
}
add_action('admin_menu','pp_sa_menu');
function pp_sa_search(){
include('shadow-accounts/admin/sa-admin.php');
}
then the sa-admin.php
file is where the problem happens
<?php
$sandbox = true;
$phost = 'localhost';
$pus = 'user';
$ppas = 'pass';
$pus = 'Hello World';
function testFunc(){
global $phost;
return $phost;
}
echo testFunc(); //empty
function getForumAccounts(){
global $pus;
echo $pus; // empty
echo 'test'; // shows 'test'
echo $ppas; // empty
}
getForumAccounts();
?>
Not sure if this will work any different but:
$phost = 'localhost';
function getForumAccounts(){
global $phost;
return $phost;
}
echo getForumAccounts();
Function should be returning something. In this case its the variable and then you can echo that out or use the function in another way.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK