Waste Licence

Waste carriers affiliation badge

Use Snippet
php
<?php
<iframe style="border: 1px solid #dddddd; overflow: hidden" width="330" height="165" src="https://environment.data.gov.uk/public-register/waste-carriers-brokers/widget/CBDL457468" title="Widget for CBDL457468"></iframe>
Anthony Burnett
<10

Lowercase Filenames for Uploads

Make all the filenames of new uploads to lowercase after you enable this snippet.

Use Snippet
php
<?php
add_filter( 'sanitize_file_name', 'mb_strtolower' );
WPCode Team
<10

Disable Gutenberg Code Editing for Non-Admin Users

Prevent non-admin users from using "Edit as HTML" or "Code editor" in the Gutenberg Editor.

Use Snippet
php
<?php
add_filter( 'block_editor_settings_all', function ( $settings ) {
	
	$settings['codeEditingEnabled'] = current_user_can( 'manage_options' );
	return $settings;
} );
WPCode Team
<10

Replace WordPress Logo on Login Page

Use your custom logo on the default login page, don't forget to edit the snippet...

Use Snippet
php
<?php
add_filter( 'login_head', function () {
	// Update the line below with the URL to your own logo.
	// Adjust the Width & Height accordingly.
	$custom_logo = 'https://wpcode.com/wp-admin/images/wordpress-logo.svg';
	$logo_width  = 84;
	$logo_height = 84;
	printf(
		'<style>.login h1 a {background-image:url(%1$s) !important; margin:0 auto; width: %2$spx; height: %3$spx; background-size: 100%%;}</style>',
		$custom_logo,
		$logo_width,
		$logo_height
	);
}, 990 );
WPCode Team
<10

Duplicate Post/Page Link

Duplicate posts, pages or any post type with 1-click by adding a duplicate link in...

Use Snippet
php
<?php
// Add duplicate button to post/page list of actions.
add_filter( 'post_row_actions', 'wpcode_snippet_duplicate_post_link', 10, 2 );
add_filter( 'page_row_actions', 'wpcode_snippet_duplicate_post_link', 10, 2 );
// Let's make sure the function doesn't already exist.
if ( ! function_exists( 'wpcode_snippet_duplicate_post_link' ) ) {
	/**
	 * @param array   $actions The actions added as links to the admin.
	 * @param WP_Post $post The post object.
	 *
	 * @return array
	 */
	function wpcode_snippet_duplicate_post_link( $actions, $post ) {
		// Don't add action if the current user can't create posts of this post type.
		$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 $actions;
		}
		$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'
		);
		$actions['wpcode_duplicate'] = '<a href="' . $url . '" title="Duplicate item" rel="permalink">Duplicate</a>';
		return $actions;
	}
}
/**
 * Handle the custom action when clicking the button we added above.
 */
add_action( 'admin_action_wpcode_snippet_duplicate_post', function () {
	if ( empty( $_GET['post_id'] ) ) {
		wp_die( 'No post id set for the duplicate action.' );
	}
	$post_id = absint( $_GET['post_id'] );
	// Check the nonce specific to the post we are duplicating.
	if ( ! isset( $_GET['wpcode_duplicate_nonce'] ) || ! wp_verify_nonce( $_GET['wpcode_duplicate_nonce'], 'wpcode_duplicate_post_' . $post_id ) ) {
		// Display a message if the nonce is invalid, may it expired.
		wp_die( 'The link you followed has expired, please try again.' );
	}
	// Load the post we want to duplicate.
	$post = get_post( $post_id );
	// Create a new post data array from the post loaded.
	if ( $post ) {
		$current_user = wp_get_current_user();
		$new_post     = array(
			'comment_status' => $post->comment_status,
			'menu_order'     => $post->menu_order,
			'ping_status'    => $post->ping_status,
			'post_author'    => $current_user->ID,
			'post_content'   => $post->post_content,
			'post_excerpt'   => $post->post_excerpt,
			'post_name'      => $post->post_name,
			'post_parent'    => $post->post_parent,
			'post_password'  => $post->post_password,
			'post_status'    => 'draft',
			'post_title'     => $post->post_title . ' (copy)',// Add "(copy)" to the title.
			'post_type'      => $post->post_type,
			'to_ping'        => $post->to_ping,
		);
		// Create the new post
		$duplicate_id = wp_insert_post( $new_post );
		// Copy the taxonomy terms.
		$taxonomies = get_object_taxonomies( get_post_type( $post ) );
		if ( $taxonomies ) {
			foreach ( $taxonomies as $taxonomy ) {
				$post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
				wp_set_object_terms( $duplicate_id, $post_terms, $taxonomy );
			}
		}
		// Copy all the custom fields.
		$post_meta = get_post_meta( $post_id );
		if ( $post_meta ) {
			foreach ( $post_meta as $meta_key => $meta_values ) {
				if ( '_wp_old_slug' === $meta_key ) { // skip old slug.
					continue;
				}
				foreach ( $meta_values as $meta_value ) {
					add_post_meta( $duplicate_id, $meta_key, $meta_value );
				}
			}
		}
		// Redirect to edit the new post.
		wp_safe_redirect(
			add_query_arg(
				array(
					'action' => 'edit',
					'post'   => $duplicate_id
				),
				admin_url( 'post.php' )
			)
		);
		exit;
	} else {
		wp_die( 'Error loading post for duplication, please try again.' );
	}
} );
WPCode Team
<10

Disable New User Notifications

Prevent the admin user from getting new user notification emails.

Use Snippet
php
<?php
function wpcode_send_new_user_notifications( $user_id, $notify = 'user' ) {
	if ( empty( $notify ) || 'admin' === $notify ) {
		return;
	} elseif ( 'both' === $notify ) {
		// Send new users the email but not the admin.
		$notify = 'user';
	}
	wp_send_new_user_notifications( $user_id, $notify );
}
add_action(
	'init',
	function () {
		// Disable default email notifications.
		remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
		remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications' );
		// Replace with custom function that only sends to user.
		add_action( 'register_new_user', 'wpcode_send_new_user_notifications' );
		add_action( 'edit_user_created_user', 'wpcode_send_new_user_notifications', 10, 2 );
	}
);
WPCode Team
<10

rexing

fishing camera

Use Snippet
html
<a href="https://www.kqzyfj.com/click-100700341-15218440" target="_top" rel="noopener">
<img src="https://www.awltovhc.com/image-100700341-15218440" width="728" height="90" alt="" border="0"/></a>
Chet fishingfortrout
<10

Change Outgoing Email Sender

Change the outgoing sender name and email address. Don't forget to edit the snippet with...

Use Snippet
php
<?php
// Please edit the address and name below before activating this snippet.
// Change the From address.
add_filter( 'wp_mail_from', function ( $original_email_address ) {
	return '[email protected]';
} );
// Change the From name.
add_filter( 'wp_mail_from_name', function ( $original_email_from ) {
	return 'Tim Smith';
} );
WPCode Team
<10
1 2 3 4