2012-02-06 7 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 и поместите его в свой каталог плагинов. Например 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');} 

Затем вы можете создать файл с именем администратора-options.php с презентацией и функциональность администратора страницы. Попробуйте «Hello World» в этом файле, чтобы увидеть его.

Этот код объясняется в деталях в WordPress Codex http://codex.wordpress.org/Adding_Administration_Menus, который также даст вам несколько примеров правильного построения вашей страницы стандартным способом.