Wordpress管理页面插件设置

时间:2017-04-23 00:43:02

标签: php wordpress function plugins admin

我试图制作我的第一个插件管理页面,但我收到错误:

我的插件文件夹层次结构:

  uploadsdir-manager 
    index.html
    test.php
    functions.php
    admin-page.php

在函数I中添加了以下代码:

function awesome_page_create() {
$page_title = 'My Awesome Admin Page';
    $menu_title = 'Awesome Admin Page';
    $capability = 'edit_posts';
    $menu_slug = 'awesome_page';
    $function = 'my_awesome_page_display';
    $icon_url = '';
    $position = 99;

    add_menu_page( $page_title, $menu_title, $capability, $menu_slug, 
$function, $icon_url, $position );
}
add_action('admin_menu', 'awesome_page_create');

然后我收到此错误:

  Fatal error: Uncaught Error: Call to undefined function add_action() 
  in
  C:\xampp\htdocs\wordpress\wp-content\plugins\uploadsdir-
  manager\functions.php:2 
  Stack trace: 
  #0 C:\xampp\htdocs\wordpress\wp-content\plugins\uploadsdir-
  manager\index.html(11): 
  include() #1 {main} 
  thrown in 
  C:\xampp\htdocs\wordpress\wp-
  content\plugins\uploadsdirmanager\functions.php 
  on line 2

我做错了什么?

1 个答案:

答案 0 :(得分:0)

创建插件时,除非您要导入该功能,否则不需要功能页面.php。 Worpress读取与目录同名的文件。在示例中,我的插件目录称为emailblast。 wordpress的真正功能页面是emailblast.php

emailblast.php将启动其代码......

<?php
/**
 * Plugin Name: Email Blasts
 * Plugin URI:  https://yoursite.com
 * Description: These are various email templates that can be sent to an given email using as click of a button.
 * Version:     1.0
 * Author:      your name

 */