gpt4 book ai didi

php - 如何在 wordpress 中创建管理面板

转载 作者:行者123 更新时间:2023-12-02 05:38:28 24 4
gpt4 key购买 nike

我对为 wordpress 编写插件非常陌生。

我正在考虑编写一个插件,用户可以在其中上传图像,并将某种样式(在后端编码)应用于图像。然后我会允许用户使用短代码输入图像。

(以上只是我需要做的一个例子……它比这复杂一点,但我确定一旦开始我就可以编写代码)

所以我可以做简码。

首先,我将如何创建一个可以上传图像并将该图像存储在数据库中的管理面板。

当用户上传图片时,之前的图片将被覆盖。

如果有人有一个关于创建管理面板的好教程的链接,那就太好了。外面的那些对我不起作用。

最佳答案

这是另一个不错的起点: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

关于php - 如何在 wordpress 中创建管理面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9164265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com