options = $options; } /** * Register meta box * * @param Options $options The Options instance. */ public static function register( Options $options ): void { $page = new MetaBox( $options ); add_action( 'add_meta_boxes', [ $page, 'add_meta_boxes' ] ); add_action( 'save_post', [ $page, 'save_meta_box_options' ] ); } /** * Add "GTM Kit" meta box */ public function add_meta_boxes(): void { if ( current_user_can( 'manage_options' ) ) { $post_types = get_post_types( [ 'public' => true, ], 'objects' ); if ( isset( $post_types['attachment'] ) ) { unset( $post_types['attachment'] ); } foreach ( $post_types as $post_type => $post_type_object ) { $label = $post_type_object->labels->singular_name; add_meta_box( 'gtmkit_options', sprintf( __( 'GTM Kit', 'gtm-kit' ), $label ), [ $this, 'display_meta_boxes', ], $post_type, 'side', 'core' ); } } } /** * Displays some checkbox to de/activate some cache options */ public function display_meta_boxes(): void { if ( current_user_can( 'manage_options' ) ) { wp_nonce_field( 'gtmkit_box_option', '_gtmkitnonce', false ); $page_type = get_post_meta( get_the_ID(), 'gtmkit_page_type', true ); ?>

', '' ); ?>