"; $hide_form_menu = get_option( 'button_block_option', 'false' ); $show_ui = ( $hide_form_menu === 'true' ) ? false : true; register_post_type( $this->post_type, [ 'labels' => [ 'name' => __( 'Button Block', 'button-block' ), 'singular_name' => __( 'Button Block', 'button-block' ), 'add_new' => __( 'Add New', 'button-block' ), 'add_new_item' => __( 'Add New Button', 'button-block' ), 'edit_item' => __( 'Edit Button', 'button-block' ), 'new_item' => __( 'New Button', 'button-block' ), 'view_item' => __( 'View Button', 'button-block' ), 'search_items' => __( 'Search Button', 'button-block' ), 'not_found' => __( 'Sorry, we couldn\'t find any item you are looking for.', 'button-block' ) ], 'public' => false, 'show_ui' => $show_ui, 'publicly_queryable' => false, 'exclude_from_search' => false, 'show_in_rest' => true, 'menu_position' => 14, 'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode($menuIcon), 'has_archive' => false, 'hierarchical' => false, 'capability_type' => 'page', 'rewrite' => [ 'slug' => 'button-block' ], 'supports' => [ 'title', 'editor' ], 'template' => [ ['btn/button'] ], 'template_lock' => 'all' ] ); // Register Post Type } function postRowActions( $actions, $post ){ if ( $post->post_type == $this->post_type ) { $actions['duplicate'] = 'ID}" ) . '">Duplicate'; } return $actions; } function duplicatePost(){ if ( !isset( $_GET['post'] ) || !current_user_can( 'edit_posts') ) { wp_die( 'Permission denied' ); } $postId = $_GET['post']; $post = get_post( $postId ); if ( !$post ) { wp_die( 'Invalid post ID' ); } if ( $post && !current_user_can( 'edit_post', $postId ) ) { wp_die( 'You do not have permission to duplicate this post.' ); } $newPost = [ 'post_title' => $post->post_title . '(copy)', 'post_content' => $post->post_content, 'post_status' => $post->post_status, 'post_type' => $post->post_type, ]; $newPostId = wp_insert_post( $newPost ); wp_redirect( admin_url( "post.php?action=edit&post={$newPostId}" ) ); exit; } function manageBTNBlockPostsColumns( $defaults ) { unset( $defaults['date'] ); $defaults['shortcode'] = 'ShortCode'; $defaults['date'] = 'Date'; return $defaults; } function manageBTNBlockPostsCustomColumns( $column_name, $post_ID ) { if ( $column_name == 'shortcode' ) { echo "
Copy To Clipboard
"; } } function onAddShortcode( $atts ) { $post_id = $atts['id']; $post = get_post( $post_id ); if ( !$post ) { return ''; } if ( post_password_required( $post ) ) { return get_the_password_form( $post ); } switch ( $post->post_status ) { case 'publish': return $this->displayContent( $post ); case 'private': if (current_user_can('read_private_posts')) { return $this->displayContent( $post ); } return ''; case 'draft': case 'pending': case 'future': if ( current_user_can( 'edit_post', $post_id ) ) { return $this->displayContent( $post ); } return ''; default: return ''; } } function displayContent( $post ){ $blocks = parse_blocks( $post->post_content ); return render_block( $blocks[0] ); } function useBlockEditorForPost( $use, $post ){ if ( $this->post_type === $post->post_type ) { return true; } return $use; } } new BTNCustomPost(); }