2012-02-06 10 views
1

私は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.phpという名前のファイルを作成します

/*****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');} 

を始める必要があります。そのファイルに「Hello World」と表示されていることを確認してください。

このコードは、WordPressコーデックスhttp://codex.wordpress.org/Adding_Administration_Menusで詳細に説明されています。これは、標準的な方法でページを正しく構築する方法の例を示します。

関連する問題