PHP code example of arraypress / cpt-inline-list-table
1. Go to this page and download the library: Download arraypress/cpt-inline-list-table library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
arraypress / cpt-inline-list-table example snippets
composer
// 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 [
'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' );