is_block_editor() ) { return; } // Only fire for post types that have the expiry metabox enabled. $enabled_post_types = get_option( 'aitepc_expiry_date_post_types', array( 'post' ) ); if ( ! is_array( $enabled_post_types ) || ! in_array( $screen->post_type, $enabled_post_types, true ) ) { return; } // Register and enqueue the sidebar script. wp_enqueue_script( 'aitepc-gutenberg-sidebar', plugins_url( 'assets/js/aitepc-gutenberg-sidebar.js', __FILE__ ), array( 'wp-plugins', // registerPlugin 'wp-edit-post', // PluginSidebar, PluginSidebarMoreMenuItem 'wp-element', // createElement, Fragment 'wp-components', // PanelBody, TextControl, SelectControl, Notice 'wp-data', // withSelect, withDispatch 'wp-compose', // compose ), '2.1.0', true // Load in footer. ); // Build the actions list for the SelectControl. $actions_map = function_exists( 'aitepc_get_expiry_actions' ) ? aitepc_get_expiry_actions() : array(); $action_options = array( array( 'value' => '', /* translators: %s: site-default action label */ 'label' => sprintf( __( '— Site Default (%s) —', 'ait-easy-post-customization' ), isset( $actions_map[ get_option( 'aitepc_default_expiry_action', 'draft' ) ] ) ? $actions_map[ get_option( 'aitepc_default_expiry_action', 'draft' ) ] : __( 'Set to Draft', 'ait-easy-post-customization' ) ), ), ); foreach ( $actions_map as $value => $label ) { $action_options[] = array( 'value' => $value, 'label' => $label, ); } // Pass PHP data to JS via wp_localize_script (sanitized strings only). wp_localize_script( 'aitepc-gutenberg-sidebar', 'aitepcSidebarData', array( 'actions' => $action_options, 'i18n' => array( 'sidebarTitle' => __( 'Post Expiry', 'ait-easy-post-customization' ), 'expirySettings' => __( 'Expiry Settings', 'ait-easy-post-customization' ), 'expiryDate' => __( 'Expiry Date', 'ait-easy-post-customization' ), 'expiryDateHelp' => __( 'Leave blank to never expire.', 'ait-easy-post-customization' ), 'expiryAction' => __( 'On Expiry', 'ait-easy-post-customization' ), 'redirectUrl' => __( 'Redirect URL', 'ait-easy-post-customization' ), 'redirectHelp' => __( 'Visitors will be 301-redirected here after the post expires.', 'ait-easy-post-customization' ), 'deleteWarning' => __( 'Warning: the post will be permanently deleted and cannot be recovered.', 'ait-easy-post-customization' ), ), ) ); // Scoped sidebar styles. wp_enqueue_style( 'aitepc-gutenberg-sidebar', plugins_url( 'assets/css/aitepc-gutenberg-sidebar.css', __FILE__ ), array(), '2.1.0' ); } add_action( 'admin_enqueue_scripts', 'aitepc_enqueue_gutenberg_sidebar' );