true ), 'objects' ); $filtered_post_types = array_filter( $all_post_types, static function ( $post_type ) { return ! in_array( $post_type->name, array( 'page', 'attachment' ), true ); } ); // Determine active tab — default to post-types. $active_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'post-types'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $allowed_tabs = array( 'post-types', 'custom-fields', 'email-notifications' ); if ( ! in_array( $active_tab, $allowed_tabs, true ) ) { $active_tab = 'post-types'; } ?>

/>

/>

' . esc_html__( 'Security check failed. Please try again.', 'ait-easy-post-customization' ) . ''; return; } $custom_fields = get_option( 'aitepc_custom_fields', array() ); $action = sanitize_text_field( wp_unslash( $_POST['aitepc_custom_fields_action'] ) ); if ( 'add' === $action || 'edit' === $action ) { $key = sanitize_key( wp_unslash( $_POST['field_key'] ?? '' ) ); $label = sanitize_text_field( wp_unslash( $_POST['field_label'] ?? '' ) ); $type = sanitize_text_field( wp_unslash( $_POST['field_type'] ?? '' ) ); $post_types = isset( $_POST['field_post_types'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['field_post_types'] ) ) : array(); if ( empty( $key ) || empty( $label ) || empty( $type ) ) { echo ''; return; } if ( 'add' === $action && array_key_exists( $key, $custom_fields ) ) { echo ''; return; } $custom_fields[ $key ] = array( 'label' => $label, 'type' => $type, 'post_types' => $post_types, ); update_option( 'aitepc_custom_fields', $custom_fields ); $verb = ( 'add' === $action ) ? __( 'added', 'ait-easy-post-customization' ) : __( 'updated', 'ait-easy-post-customization' ); echo ''; } elseif ( 'delete' === $action ) { $key = sanitize_key( wp_unslash( $_POST['field_key'] ?? '' ) ); if ( array_key_exists( $key, $custom_fields ) ) { unset( $custom_fields[ $key ] ); update_option( 'aitepc_custom_fields', $custom_fields ); echo ''; } } } // --------------------------------------------------------------------------- // Custom Fields display // --------------------------------------------------------------------------- /** * Render the custom fields add/edit form and the existing fields table. * * @param array $filtered_post_types Post type objects (excluding page/attachment). */ function aitepc_display_custom_fields_form( $filtered_post_types ) { $custom_fields = get_option( 'aitepc_custom_fields', array() ); $edit_key = isset( $_GET['edit'] ) ? sanitize_key( $_GET['edit'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $edit_field = ( $edit_key && isset( $custom_fields[ $edit_key ] ) ) ? $custom_fields[ $edit_key ] : null; ?>

pattern="[a-z0-9_]+" >
name, $edit_field['post_types'], true ) ) ? 'checked="checked"' : ''; ?>
id="field_name ); ?>" >

$field ) : ?>