我需要getdata()
函數class-GetData.php
在此shortcode_function()
內部調用。來自另一個文件的呼叫功能
require_once plugin_dir_path(__FILE__) . '/class-GetData.php';
add_shortcode('registration-plugin','shortcode_function');
function shortcode_function()
{
ob_start();
insert_data();
getdata(); //from GetData.php
return ob_get_clean();
}
?>
類訪問getdata.php
<?php
class GetData
{
public function getdata()
{
//something here
}
}
$getData = new GetData();
但我正在逐漸未定義功能錯誤:
Call to undefined function getdata()
'的getData()'是在'GetData'類*方法*。你需要使用'$ getData-> getData()',調用對象的方法。通常,您不會通過 – Qirel
'$ getData-> getdata()' – Und3rTow
來初始化類文件中的對象。請參閱http://php.net/manual/en/language.types.object.php和http:/ /php.net/manual/en/language.oop5.basic.php – Qirel