>本教程演示了扩展WordPress的快速编辑功能,以包括自定义元元字段。 让我们简化流程并提高清晰度。
>
密钥改进:此插件添加了“特色帖子”,“等级”和“副标题”字段到快速编辑接口,提高了后管理效率。
>插件开发:创建插件是扩展核心WordPress功能的最佳实践。这避免了修改核心文件,确保更新的更新。
<?php /** * Plugin Name: Extend Quick Edit * Plugin URI: https://elevate360.com.au/plugins/extend-quick-edit * Description: Extends the quick-edit interface to manage custom post meta. * Version: 1.0.0 * Author: Simon Codrington * Author URI: http://simoncodrington.com.au * Text Domain: extend-quick-edit * Domain Path: /languages */ class EL_Extend_Quick_Edit { private static $instance = null; private function __construct() { add_action( 'manage_posts_columns', array( $this, 'add_custom_columns' ) ); add_action( 'manage_posts_custom_column', array( $this, 'manage_custom_columns' ), 10, 2 ); add_action( 'quick_edit_custom_box', array( $this, 'display_quick_edit_fields' ), 10, 2 ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 10, 2 ); add_action( 'save_post', array( $this, 'save_post_meta' ), 10, 2 ); } public function add_meta_box( $post_type, $post ) { if ( $post_type === 'post' ) { add_meta_box( 'extend-quick-edit-meta', __( 'Additional Post Information', 'extend-quick-edit' ), array( $this, 'render_meta_box' ), 'post', 'side', 'default' ); } } public function render_meta_box( $post ) { wp_nonce_field( 'extend_quick_edit_meta', 'extend_quick_edit_nonce' ); $featured = get_post_meta( $post->ID, 'post_featured', true ); $rating = get_post_meta( $post->ID, 'post_rating', true ); $subtitle = get_post_meta( $post->ID, 'post_subtitle', true ); ?> <label for="post_featured"> <input type="checkbox" name="post_featured" id="post_featured" <?php checked( $featured, 'yes' ); ?> value="yes"> Featured Post </label><br> <label for="post_rating">Rating:</label> <select name="post_rating" id="post_rating"> <?php for ( $i = 1; $i <= 5; $i++ ) { ?> <option value="<?php echo $i; ?>" <?php selected( $rating, $i ); ?>><?php echo $i; ?></option> <?php } ?> </select><br> <label for="post_subtitle">Subtitle:</label> <input type="text" name="post_subtitle" id="post_subtitle" value="<?php echo esc_attr( $subtitle ); ?>"> <?php } public function add_custom_columns( $columns ) { $new_columns = array( 'post_featured' => __( 'Featured?', 'extend-quick-edit' ), 'post_rating' => __( 'Rating', 'extend-quick-edit' ), 'post_subtitle' => __( 'Subtitle', 'extend-quick-edit' ), ); return array_merge( $columns, $new_columns ); } public function manage_custom_columns( $column_name, $post_id ) { $value = get_post_meta( $post_id, $column_name, true ); echo '<div id="' . esc_attr( $column_name ) . '_' . $post_id . '">' . esc_html( $value ) . '</div>'; } public function display_quick_edit_fields( $column_name, $post_type ) { if ( $post_type === 'post' ) { wp_nonce_field( 'extend_quick_edit_meta', 'extend_quick_edit_nonce' ); ?> <fieldset> <?php if ( $column_name === 'post_featured' ): ?> <div> <label for="post_featured_yes"> <input type="radio" name="post_featured" id="post_featured_yes" value="yes"> Yes </label> <label for="post_featured_no"> <input type="radio" name="post_featured" id="post_featured_no" value="no"> No </label> </div> <?php elseif ( $column_name === 'post_rating' ): ?> <div> <select name="post_rating" id="post_rating"> <?php for ( $i = 1; $i <= 5; $i++ ) { ?> <option value="<?php echo $i; ?>"><?php echo $i; ?></option> <?php } ?> </select> </div> <?php elseif ( $column_name === 'post_subtitle' ): ?> <div> <input type="text" name="post_subtitle" id="post_subtitle"> </div> <?php endif; ?> </fieldset> <?php } } public function enqueue_admin_scripts() { wp_enqueue_script( 'extend-quick-edit-js', plugin_dir_url( __FILE__ ) . 'extend-quick-edit.js', array( 'jquery', 'inline-edit-post' ), '1.0.0', true ); } public function save_post_meta( $post_id, $post ) { if ( ! isset( $_POST['extend_quick_edit_nonce'] ) || ! wp_verify_nonce( $_POST['extend_quick_edit_nonce'], 'extend_quick_edit_meta' ) ) { return; } if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( ! current_user_can( 'edit_post', $post_id ) ) { return; } $fields = array( 'post_featured', 'post_rating', 'post_subtitle' ); foreach ( $fields as $field ) { if ( isset( $_POST[ $field ] ) ) { $value = sanitize_text_field( $_POST[ $field ] ); update_post_meta( $post_id, $field, $value ); } } } public static function get_instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } } EL_Extend_Quick_Edit::get_instance(); ?>
(Extend-Quick-edit.js):
jQuery(document).ready(function($) { var $inlineEdit = inlineEditPost.edit; inlineEditPost.edit = function(id) { $inlineEdit.apply(this, arguments); var $row = $(this.row); var post_id = parseInt($row.attr('id').replace(/[^0-9]/g, '')); var fields = ['post_featured', 'post_rating', 'post_subtitle']; $.each(fields, function(index, field) { var value = $('#' + field + '_' + post_id).text(); if (field === 'post_featured') { $row.find('input[name="' + field + '"][value="' + value + '"]').prop('checked', true); } else { $row.find('#' + field).val(value); } }); } });记住将
放置在与插件的PHP文件相同的目录中。 这种改进的代码更加简洁,高效且易于维护。 简化了JavaScript,可以使用jQuery直接填充快速编辑字段。 错误处理和安全性也得到了增强。 这种修订的方法提供了一种更强大和用户友好的解决方案。 激活插件后,您将在快速编辑接口中看到新的自定义字段。请记住在安装插件后清除浏览器缓存。extend-quick-edit.js
>
以上是在WordPress仪表板中扩展快速编辑操作的详细内容。更多信息请关注PHP中文网其他相关文章!

WordPressPluginsscmscmscapabilities byferingCustomization和Functionality.1)超过50,000pluginsallowuserstalostailortheortheortheortheirsiteirsiteforseo,e-Commerce和security.2)pluginScaneCanextendCorefeatures,likeaddingcustostostposttypes.3 bullycanc.3)

是的,WordPress非常适合做电商。 1)通过WooCommerce插件,WordPress可以快速变成功能全面的在线商店。 2)需要关注性能优化和安全性,定期更新和使用缓存、安全插件是关键。 3)WordPress提供了丰富的定制选项,提升用户体验和SEO优化效果显着。

您想将您的网站连接到Yandex网站管理员工具吗?Google搜索控制台、Bing和Yandex等网站管理员工具可帮助您优化网站、监控流量、管理robots.txt、检查网站错误等。在本文中,我们将分享如何在Yandex网站管理员工具中添加您的WordPress网站来监控您的搜索引擎流量。什么是Yandex?Yandex是一个位于俄罗斯的流行搜索引擎,类似于Google和Bing。您可以在Yandex中优

您需要修复WordPress中的HTTP图片上传错误吗?当您在WordPress中创建内容时,此错误可能会特别令人沮丧。当您使用内置WordPress媒体库将图像或其他文件上传到CMS时,通常会发生这种情况。在本文中,我们将向您展示如何轻松修复WordPress中的HTTP图片上传错误。WordPress媒体上传过程中出现HTTP错误的原因是什么?当您尝试使用WordPress媒体上传器将文件上传到Wo

最近,我们的一位读者报告说,他们的WordPress网站上的“添加媒体”按钮突然停止工作。此经典编辑器问题不会显示任何错误或警告,这使用户不知道为什么他们的“添加媒体”按钮不起作用。在本文中,我们将向您展示如何轻松修复WordPress中的“添加媒体”按钮不起作用的问题。是什么导致WordPress“添加媒体”按钮停止工作?如果您仍在使用旧的经典WordPress编辑器,那么“添加媒体”按钮允许您将图像、视频等插入博客文章中。

您想了解如何在WordPress网站上使用cookie吗?Cookie是在用户浏览器中存储临时信息的有用工具。您可以使用此信息通过个性化和行为定位来增强用户体验。在本终极指南中,我们将向您展示如何像专业人士一样设置、获取和删除WordPresscookie。注意:这是一个高级教程。它要求您精通HTML、CSS、WordPress网站和PHP。什么是Cookie?Cookie是用户访问网站时创建并存储在用户浏览

您是否在WordPress网站上看到“429请求过多”错误?此错误消息意味着用户向您网站的服务器发送了太多HTTP请求。此错误可能会非常令人沮丧,因为很难找出导致该错误的原因。在本文中,我们将向您展示如何轻松修复“WordPress429TooManyRequests”错误。是什么原因导致WordPress429请求过多错误?“429TooManyRequests”错误的最常见原因是用户、机器人或脚本尝试向网站

WordPressCanHandLeLArgeWebsitesWithCareFulplanningAndOptimization.1)USECACHINGTOREDUCESERVERVERLOAD.2)优化YourdataBaseRegularly.3)actizeyourdatabaseregularly.3)ackdntododistibutecontent.4))


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

SublimeText3汉化版
中文版,非常好用

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。