Home / Admin / unitap.io
Duplicate Snippet

Embed Snippet on Your Site

unitap.io

function myfirsttheme_setup() {
/*
* Load additional block styles.
*/
$styled_blocks = ['latest-comments'];
foreach ( $styled_blocks as $block_name ) {
$args = array(
'handle' => "myfirsttheme-$block_name",
'src' => get_theme_file_uri( "assets/css/blocks/$block_name.css" ),
$args['path'] = get_theme_file_path( "assets/css/blocks/$block_name.css" ),
);
wp_enqueue_block_style( "core/$block_name", $args );
}
}
add_action( 'after_setup_theme', 'myfirsttheme_setup' );

Code Preview
php
<?php
add_action( 'admin_bar_menu', function ( $admin_bar ) {
	// Only show this when editing a post.
	$screen = get_current_screen();
	if ( ! $screen || 'post' !== $screen->base ) {
		return;
	}
	$post             = get_post();
	$post_type_object = get_post_type_object( $post->post_type );
	if ( null === $post_type_object || ! current_user_can( $post_type_object->cap->create_posts ) ) {
		return;
	}
	$url = wp_nonce_url(
		add_query_arg(
			array(
				'action'  => 'wpcode_snippet_duplicate_post',
				'post_id' => $post->ID,
			),
			'admin.php'
		),
		'wpcode_duplicate_post_' . $post->ID,
		'wpcode_duplicate_nonce'
	);
	$admin_bar->add_menu(
		array(
			'id'    => 'wpcode_duplicate',
			'title' => 'Duplicate',
			'href'  => $url,
		)
	);
}, 1100 );

Comments

Add a Comment