Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wordpress插件开发页面表单显示在每篇文章和页面编辑的底部_Php_Html_Wordpress_Plugins - Fatal编程技术网

Php wordpress插件开发页面表单显示在每篇文章和页面编辑的底部

Php wordpress插件开发页面表单显示在每篇文章和页面编辑的底部,php,html,wordpress,plugins,Php,Html,Wordpress,Plugins,我正在为自定义数据表开发一个wordpress CRUD插件,它运行得非常好。然而,插件中用于插入或编辑新记录的页面表单也显示在所有页面的底部,并在管理区域内发布新页面/帖子和编辑页面/帖子 插件中的其他页面不会像预期的那样显示在wordpress中的任何其他地方。我完全没有意识到我做错了什么,希望有人能给我指出解决这个问题的正确方向 如果我停用插件,问题仍然存在 我使用样板模板作为开发以下插件的基础: 这将为其添加菜单选项和回调: $sub2_cb = array(&$th

我正在为自定义数据表开发一个wordpress CRUD插件,它运行得非常好。然而,插件中用于插入或编辑新记录的页面表单也显示在所有页面的底部,并在管理区域内发布新页面/帖子和编辑页面/帖子

插件中的其他页面不会像预期的那样显示在wordpress中的任何其他地方。我完全没有意识到我做错了什么,希望有人能给我指出解决这个问题的正确方向

如果我停用插件,问题仍然存在

我使用样板模板作为开发以下插件的基础:

这将为其添加菜单选项和回调:

    $sub2_cb = array(&$this,'new_award_category_page');     // callback function. name

        add_submenu_page( 
            'Settings', 
            'Award Categories Add New', 
            'Add New', 
            'manage_options',
            'add-category',
            $sub2_cb
         );
以下是包含页面的回调函数:

    public function new_award_category_page() {
    include_once( 'partials/new-award-category-page.php' );     
}
正在从wp_列表_表中的行编辑链接调用同一页,以编辑现有记录:

function column_category($item){

    //Build row actions
    $actions = array(
        'edit' => sprintf('<a href="?page=add-category&id=%s">%s</a>', $item['id'], __('Edit', 'new_award_category_page')),
    );

    //Return the title contents
    return sprintf('%1$s <span style="color:silver"></span>%3$s',
        /*$1%s*/ $item['category'],
        /*$2%s*/ $item['id'],
        /*$3%s*/ $this->row_actions($actions)
    );
}

功能奖励\类别\验证($item){
$messages=array();
如果(空($item['category'))$messages[]=uuuu('category title's required','new_uaward_ucategory_upage');
如果(空($item['paration_1']))$messages[]=\uuuuuu('需要介绍性段落','新的\u奖项\u类别页面');
如果(空($item['img'))$messages[]=uuuu('Representation image is required','new_award_category_page');
if(空($messages))返回true;
返回内爆(“
”,$messages);
}

div class=“wrap”>


HTML是表单页面特定的主题文件吗?或者这是一个基本模板文件?它是插件中某个页面的回调函数的一部分,所以插件的一部分不是我必须在这里将回调函数拆分为不同的代码段以便显示的主题,而是插件中的一个函数-partials/new-award-category-page.php的内容
global $wpdb;
$table_name =  'wp_categories'; // do not forget about tables prefix

$message = '';
$notice = '';

// this is default $item which will be used for new records
$default = array(
    'id' => null,
    'category' => '',
    'paragraph_1' => '',
    'paragraph_2' => '',
    'img' => '',
    'manager' => ''
);

// here we are verifying does this request is post back and have correct nonce
if (wp_verify_nonce($_REQUEST['nonce'], basename(__FILE__))) {
    // combine our default item with request params
    $item = shortcode_atts($default, $_REQUEST);
    // validate data, and if all ok save item to database
    // if id is zero insert otherwise update
    $item_valid = award_category_validate($item);
    if ($item_valid === true) {
        if ($item['id'] == 0) {
            $result = $wpdb->insert($table_name, $item);
            $item['id'] = $wpdb->insert_id;
            if ($result) {
                $message = __('Item was successfully saved', 'new_award_category_page');
            } else {
                $notice = __('There was an error while saving item', 'new_award_category_page');
            }
        } else {
            $result = $wpdb->update($table_name, $item, array('id' => $item['id']));
            if ($result) {
                $message = __('Item was successfully updated', 'new_award_category_page');
            } else {
                $notice = __('There was an error while updating item', 'new_award_category_page');
            }
        }
    } else {
        // if $item_valid not true it contains error message(s)
        $notice = $item_valid;
    }
}
else {
    // if this is not post back we load item to edit or give new one to create
    $item = $default;
    if (isset($_REQUEST['id'])) {
        $item = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE id = %d", $_REQUEST['id']), ARRAY_A);
        if (!$item) {
            $item = $default;
            $notice = __('Item not found', 'new_award_category_page');
        }
    }
}
function award_category_validate($item) {

$messages = array();

if (empty($item['category'])) $messages[] = __('Category title is required ', 'new_award_category_page');
if (empty($item['paragraph_1'])) $messages[] = __('Introductory paragraph is required', 'new_award_category_page');
if (empty($item['img'])) $messages[] = __('Representation image is required', 'new_award_category_page');

if (empty($messages)) return true;
return implode('<br />', $messages);