我對WordPress插件相當陌生,但是我創建了一個簡單的向我的頁面頁眉添加自定義JavaScript的插件。調用未定義的函數add_action()wp_head
當我在我的本地主機上的WordPress管理頁面上運行插件時,它完美地工作(就像它應該做的那樣),但是我的IDE(phpStorm)插件有錯誤。
我得到的錯誤是:
PHP Fatal error: Uncaught Error: Call to undefined function add_action() in C:\xampp\htdocs\website1\wp-content\plugins\jade-plugin\jade-plugin.php:12 Stack trace: thrown in C:\xampp\htdocs\website1\wp-content\plugins\jade-plugin\jade-plugin.php on line 12
Fatal error: Uncaught Error: Call to undefined function add_action() in C:\xampp\htdocs\website1\wp-content\plugins\jade-plugin\jade-plugin.php:12 Stack trace: thrown in C:\xampp\htdocs\website1\wp-content\plugins\jade-plugin\jade-plugin.php on line 12
Process finished with exit code 255
我不知道是什麼導致這個錯誤,但我認爲這是與我的目錄中的文件。
我也想上傳這個插件與WordPress.org我們的家族企業,但是當我嘗試上傳插件我收到以下錯誤:
The plugin has no name. Add a Plugin Name: line to your main plugin file and upload the plugin again.
這裏是我的插件至今:
<?php
/*
* Plugin Name: InSite
* Plugin URI: http://localhost
* Description: Adds javascript
* Version: 1.0
* Author: Jade
* License: GPL2
*/
/* This function adds two lines of javascript to the page header */
add_action('wp_head', 'addHeader');
function addHeader()
{
?>
<script
src="http://app.insitesoftware.co.za:8080/socket.io/socket.io.js">
</script>
<script src="http://app.insitesoftware.co.za:8080/client.js">
</script>
<?php
}
;
?>
任何幫助會如此感激:)