定制 arraypress/cpt-inline-list-table 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arraypress/cpt-inline-list-table

Composer 安装命令:

composer require arraypress/cpt-inline-list-table

包简介

A WordPress plugin library providing an easy way to enhance admin interfaces with sortable, duplicable custom post type list tables for conditional rules, notices and more.

README 文档

README

By leveraging the Custom Post Type Inline List Table library, developers can easily register, display, and manage custom post types with enhanced functionalities such as custom columns, script and style enqueues, admin menu highlighting, and more. Designed for seamless integration with WordPress core functionalities, this tool streamlines the administrative tasks associated with custom post types, offering a developer-friendly approach to customization and management.

Key Features:

  • Custom Column Management: Define and manage custom columns for your post type's list table, providing a tailored view of your data.
  • Script and Style Enqueues: Specify admin screens where custom scripts and styles should be loaded, enhancing the admin UI and UX.
  • Admin Menu Highlighting: Maintain menu and submenu highlighting within the admin sidebar, improving navigation and usability.
  • Flexible Pagination: Control the number of items displayed per page in the list table, supporting efficient data handling and presentation.
  • Streamlined Integration: Utilize hooks and WordPress core functions for a smooth integration, adhering to WordPress standards and best practices.

This library facilitates the creation of a refined administrative interface for custom post types, ensuring a coherent and efficient management experience within the WordPress admin.

Installation

Ensure you have the package installed in your project. If not, you can typically include it using Composer:

composer require arraypress/cpt-inline-list-table

Example Usage

The register_inline_table function allows for easy setup and configuration of your custom post type's inline list table. Here's how to use it:

// Example usage of register_inline_table_post_type to create a 'Conditional Fee' custom post type.
register_inline_post_type(
    'conditional_fee',                                  // The key for the custom post type.
    __( 'Conditional Fee', 'edd-conditional-fees' ),    // The singular name of the custom post type for labels.
    __( 'Conditional Fees', 'edd-conditional-fees' ),   // The plural name of the custom post type for labels.
    'conditional_fee',                                  // The slug for the custom post type.
    [ 'excerpt', 'custom-fields', 'editor' ],           // (Optional) Additional features the post type supports.
    false                                               // (Optional) Whether to expose this post type in the WordPress REST API. Enables use of the Gutenberg editor and REST API queries.
);

/**
 * Defines columns for the list table of a custom post type, showcasing conditional discounts.
 * This configuration automatically includes default columns such as title, date, and author.
 * Additional custom columns can specify callbacks for rendering their content or use formatters
 * for specific data presentation. If only a key and label are provided (without a callback),
 * the system will first look for a matching property in the post object, then check post meta.
 *
 * When defining columns, it's crucial to understand the built-in logic for data retrieval:
 *
 * 1. If a 'callback' is provided, it will be used to fetch and render the column's data.
 * 2. Without a 'callback', the system searches for a matching property within the post object.
 * 3. If not found in the post object, the system then searches the post meta.
 * 4. A 'formatter' function can be used to format the value obtained from the callback or automatic data retrieval.
 *
 * This approach provides flexibility in displaying both standard and custom data within your list table.
 */

$columns = [
	// Example of a custom column with a callback and formatter.
	'amount'          => [
		'label'     => __( 'Amount', 'edd-conditional-fees' ),
		'callback'  => function ( $post ) {
			return get_post_meta( $post->ID, 'amount', true );
		},
		'formatter' => function ( $value, $post ) {
			return edd_currency_filter( edd_format_amount( $value ) );
		},
	],
	// Example of a simple column that relies on automatic data sourcing.
	'expiration_date' => [
		'label' => __( 'Expiration Date', 'edd-conditional-fees' ),
		// No callback needed; the system will automatically search for 'expiration_date' in post object or meta.
	]
];

// Registers an inline list table for a specified custom post type, configuring it with
// custom columns, administrative URLs, and settings for menu highlighting.
register_inline_table(
	'conditional_fee', // The custom post type identifier.
	$columns, // Associative array of columns with render callbacks and formatters.
	'edd_conditional_fees_table', // Hook name to attach the list table initialization.
	10, // Priority for the hook to control when the list table is initialized.
	'edit.php?post_type=download&page=edd-settings&tab=extensions', // URL for admin redirects.
	[ 'download_page_edd-settings' ], // Admin screens where scripts/styles should be enqueued.
	'edit.php?post_type=download', // Parent file slug for menu highlighting.
	'edd-settings' // Submenu file slug for submenu highlighting.
);

// Registers a settings section for managing conditional fees within the extension settings.
function register_section( array $sections ): array {
	$sections['conditional_fees'] = __( 'Conditional Fees', 'edd-conditional-fees' );

	return $sections;
}

add_filter( 'edd_settings_sections_extensions', __NAMESPACE__ . '\\register_section' );

// Adds settings for the 'Conditional Fees' section within the extension settings, enabling the configuration of rules.
function register_settings( array $existing_settings ): array {
	return array_merge( $existing_settings, [
		'conditional_fees' => [
			[
				'id'   => 'conditional_fees_table',
				'name' => __( 'Conditional Fees', 'edd-conditional-fees' ),
				'type' => 'hook',
			],
		]
	] );
}

add_filter( 'edd_settings_extensions', __NAMESPACE__ . '\\register_settings' );

Contributions

We welcome contributions to enhance the library's functionality and compatibility. Feel free to submit pull requests or report issues on our GitHub repository.

License

The Custom Post Type Inline List Table library is open-sourced software licensed under the GPL-2.0-or-later license. It is free for personal and commercial use, adhering to the terms of the GNU General Public License.

arraypress/cpt-inline-list-table 适用场景与选型建议

arraypress/cpt-inline-list-table 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 arraypress/cpt-inline-list-table 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 arraypress/cpt-inline-list-table 我们能提供哪些服务?
定制开发 / 二次开发

基于 arraypress/cpt-inline-list-table 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2024-03-18