post_type; $disabled_post_types = apply_filters( 'abt_disabled_post_types', [ 'acf', 'um_form' ] ); $is_valid_post_type = ! in_array( $post_type, array_merge( [ 'attachment' ], is_array( $disabled_post_types ) ? $disabled_post_types : [] ), true ); if ( $is_valid_post_type ) { add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_metaboxes' ); add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_scripts' ); add_action( 'save_post', __NAMESPACE__ . '\save_meta' ); add_filter( 'mce_css', function( string $mce_css ): string { return join( ',', array_filter( [ $mce_css, ABT_ROOT_URI . '/bundle/drivers/tinymce.css', ] ) ); } ); add_filter( 'mce_external_plugins', function( array $plugins ): array { $plugins['noneditable'] = '//cdn.jsdelivr.net/npm/tinymce/plugins/noneditable/plugin.min.js'; return $plugins; } ); } } /** * Adds metaboxes to posts and pages. * * @param string $post_type The post type. */ function add_metaboxes( string $post_type ) { add_meta_box( 'abt-reflist', __( 'Reference List', 'academic-bloggers-toolkit' ), function() { wp_nonce_field( Form_Actions::SET_LEGACY_EDITOR_STATE, ABT_NONCE ); ?>
ID, '_abt-reflist-state', true ), true ); $opts = get_option( ABT_OPTIONS_KEY ); if ( empty( $state ) ) { $state = [ 'cache' => [ 'style' => $opts['citation_style'], 'locale' => get_locale(), ], 'citationByIndex' => [], 'CSL' => (object) [], ]; } $state['displayOptions'] = $opts['display_options']; // Legacy checks. if ( array_key_exists( 'processorState', $state ) ) { $state['CSL'] = $state['processorState']; unset( $state['processorState'] ); } if ( array_key_exists( 'citations', $state ) ) { $state['citationByIndex'] = $state['citations']['citationByIndex']; unset( $state['citations'] ); } if ( is_string( $state['cache']['style'] ) ) { $state['cache']['style'] = $opts['citation_style']; } wp_dequeue_script( 'autosave' ); wp_enqueue_style( get_handle( 'editor-legacy', 'style' ) ); wp_enqueue_script( get_handle( 'editor-legacy', 'script' ) ); wp_localize_script( get_handle( 'editor-legacy', 'script' ), 'ABT', [ 'i18n' => $translations, 'options' => $opts, 'state' => $state, 'styles' => get_citation_styles(), 'wp' => [ 'abt_url' => ABT_ROOT_URI, ], ] ); }