Wordpress 插件未出现在管理屏幕中
Wordpress Plugin does not appear in Admin Screen
我创建了一个 wordpress 插件。它没有反映在管理模块中。
下面给出了代码和屏幕截图。
Code in structure in Visual Studio Code
<?php
/**
* EndpointHelper File Doc Comment.
*
* PHP version 7.4.1
*
* @category EndpointHelper
* @package Helper
* @author Bonson Mampilli <bonson.mampilli@company.com>
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://test site.com
* @return empty string
*/
add_action('admin_init', 'do_something');
/**
* EndpointHelper File Doc Comment.
*
* PHP version 7.4.1
*
* @category EndpointHelper
* @package Helper
* @author Bonson Mampilli <bonson.mampilli@company.com>
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://test site.com
* @return empty string
*/
function Do_something()
{
wp_die('Hello World');
}
这是来自 wordpress 文档
do_action( 'admin_init' )
Note, this does not just run on user-facing admin screens. It runs on admin-ajax.php and admin-post.php as well.
This is roughly analogous to the more general ‘init’ hook, which fires earlier.
这里是您可以用来在管理端显示内容的示例(用于调试目的)
add_filter('admin_footer_text', 'left_admin_footer_text_output'); //left side
function left_admin_footer_text_output($text) {
$text = 'How much wood would a woodchuck chuck?';
return $text;
}
与前端不同,这里的大部分代码是由管理模板通过 ajax 加载的,die()
和 wp_die()
可以工作,因为这意味着发生了致命错误,echo
会起作用,但你不会看到它。检查你的控制台和如何使用 JS 和 PHP 将东西加载到管理屏幕的文档,你可以从这里开始。
I had to add the following lines in the beginning and it starting
showing up as a control in the admin screens:
Few additional changes:
- ?> was missing at the end
- Added certain items at the beginning. I understand now that they are mandatory for the plugin to be visible.
<?php
/**
* PHP version 7.4.1
* Plugin Name: My New Plugin
* Plugin URI: http://yourdomain.com/
* Description: My new wordpress plugin
* Version: 1.0
* Author: Bonson Mampilli
* Author URI: http://yourdomain.com
* License: GPL
*
* @category EndpointHelper
* @package Helper
* @author Bonson Mampilli <bonson.mampilli@company.com>
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://test site.com
* @return empty string
*/
add_action('admin_init', 'Do_something');
/**
* PHP version 7.4.1
* Plugin Name: My New Plugin
* Plugin URI: http://yourdomain.com/
* Description: My new wordpress plugin
* Version: 1.0
* Author: Bonson Mampilli
* Author URI: http://yourdomain.com
* License: GPL
*
* @category EndpointHelper
* @package Helper
* @author Bonson Mampilli <bonson.mampilli@company.com>
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://test site.com
* @return empty string
*/
function Do_something()
{
wp_die('Hello World');
}
?>
我创建了一个 wordpress 插件。它没有反映在管理模块中。
下面给出了代码和屏幕截图。
Code in structure in Visual Studio Code
<?php
/**
* EndpointHelper File Doc Comment.
*
* PHP version 7.4.1
*
* @category EndpointHelper
* @package Helper
* @author Bonson Mampilli <bonson.mampilli@company.com>
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://test site.com
* @return empty string
*/
add_action('admin_init', 'do_something');
/**
* EndpointHelper File Doc Comment.
*
* PHP version 7.4.1
*
* @category EndpointHelper
* @package Helper
* @author Bonson Mampilli <bonson.mampilli@company.com>
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://test site.com
* @return empty string
*/
function Do_something()
{
wp_die('Hello World');
}
这是来自 wordpress 文档
do_action( 'admin_init' )
Note, this does not just run on user-facing admin screens. It runs on admin-ajax.php and admin-post.php as well. This is roughly analogous to the more general ‘init’ hook, which fires earlier.
这里是您可以用来在管理端显示内容的示例(用于调试目的)
add_filter('admin_footer_text', 'left_admin_footer_text_output'); //left side
function left_admin_footer_text_output($text) {
$text = 'How much wood would a woodchuck chuck?';
return $text;
}
与前端不同,这里的大部分代码是由管理模板通过 ajax 加载的,die()
和 wp_die()
可以工作,因为这意味着发生了致命错误,echo
会起作用,但你不会看到它。检查你的控制台和如何使用 JS 和 PHP 将东西加载到管理屏幕的文档,你可以从这里开始。
I had to add the following lines in the beginning and it starting showing up as a control in the admin screens:
Few additional changes:
- ?> was missing at the end
- Added certain items at the beginning. I understand now that they are mandatory for the plugin to be visible.
<?php
/**
* PHP version 7.4.1
* Plugin Name: My New Plugin
* Plugin URI: http://yourdomain.com/
* Description: My new wordpress plugin
* Version: 1.0
* Author: Bonson Mampilli
* Author URI: http://yourdomain.com
* License: GPL
*
* @category EndpointHelper
* @package Helper
* @author Bonson Mampilli <bonson.mampilli@company.com>
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://test site.com
* @return empty string
*/
add_action('admin_init', 'Do_something');
/**
* PHP version 7.4.1
* Plugin Name: My New Plugin
* Plugin URI: http://yourdomain.com/
* Description: My new wordpress plugin
* Version: 1.0
* Author: Bonson Mampilli
* Author URI: http://yourdomain.com
* License: GPL
*
* @category EndpointHelper
* @package Helper
* @author Bonson Mampilli <bonson.mampilli@company.com>
* @license GNU General Public License version 2 or later; see LICENSE
* @link http://test site.com
* @return empty string
*/
function Do_something()
{
wp_die('Hello World');
}
?>