2012-02-06 43 views
1

我对编写WordPress插件非常新颖。如何在wordpress中创建一个管理面板

我正在着手编写一个插件,用户可以上传图片,并且将特定样式(在后端编码)应用于图片。然后,我会允许用户使用短代码来输入图像。

(以上只是我需要做的......它有点复杂得多,这一点,但我确定一个例子,我可以,一旦编写了我得到一个开始)

所以我的简码我可以。

一是如何将我去创造一个管理面板,可以上传图片,并将该图像存储在数据库中。

当有用户上传图片时,上一张图片将被覆盖。

如果有人有一个很好的教程创建管理面板的链接。那些在那里的人只是没有为我工作。

回答

11

这又是一个良好的开端:http://codex.wordpress.org/Writing_a_Plugin

此代码应该让你去:

yourPlugin.php 

<?php 
/* 
Plugin Name: Name Of The Plugin 
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates 
Description: A brief description of the Plugin. 
Version: The Plugin's Version Number, e.g.: 1.0 
Author: Name Of The Plugin Author 
Author URI: http://URI_Of_The_Plugin_Author 
License: A "Slug" license name e.g. GPL2 
*/ 

/* Copyright YEAR PLUGIN_AUTHOR_NAME (email : PLUGIN AUTHOR EMAIL) 

    This program is free software; you can redistribute it and/or modify 
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation. 

    This program is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    GNU General Public License for more details. 

    You should have received a copy of the GNU General Public License 
    along with this program; if not, write to the Free Software 
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 
*/ 

$object = new YourPlugin(); 

//add a hook into the admin header to check if the user has agreed to the terms and conditions. 
add_action('admin_head', array($object, 'adminHeader')); 

//add footer code 
add_action('admin_footer', array($object, 'adminFooter')); 

// Hook for adding admin menus 
add_action('admin_menu', array($object, 'addMenu')); 

//This will create [yourshortcode] shortcode 
add_shortcode('yourshortcode', array($object, 'shortcode')); 

class YourPlugin{ 

    /** 
    * This will create a menu item under the option menu 
    * @see http://codex.wordpress.org/Function_Reference/add_options_page 
    */ 
    public function addMenu(){ 
     add_options_page('Your Plugin Options', 'Your Plugin', 'manage_options', 'my-unique-identifier', array($this, 'optionPage')); 
    } 

    /** 
    * This is where you add all the html and php for your option page 
    * @see http://codex.wordpress.org/Function_Reference/add_options_page 
    */ 
    public function optionPage(){ 
     echo "add your option page html here or include another php file"; 
    } 

    /** 
    * this is where you add the code that will be returned wherever you put your shortcode 
    * @see http://codex.wordpress.org/Shortcode_API 
    */ 
    public function shortcode(){ 
     return "add your image and html here..."; 
    } 
} 
?> 

添加这段代码放到一个yourPlugin.php文件中,并放在你的插件目录中。 E.g plugins/yourPlugin/yourPlugin.php

1

添加类似以下内容到你的插件应该让你开始

/*****Options Page Initialization*****/ 
// if an admin is loading the admin menu then call the admin actions function 
if(is_admin()) add_action('admin_menu', 'my_options'); 
// actions to perform when the admin menu is loaded 
function my_options(){add_options_page("My Options", "My Options", "edit_pages", "my-options", "my_admin");} 
// function called when "My Options" is selected from the admin menu 
function my_admin(){include('admin-options.php');} 

然后,你将创建一个名为admin,options.php与后台管理页面演示和功能性文件。在该文件中尝试一个“Hello World”,看看它是否出现。

这段代码在WordPress Codex http://codex.wordpress.org/Adding_Administration_Menus中有详细解释,它也会给你一些如何以标准方式正确构建页面的例子。

相关问题