Remove plugin deactivation

// Remove plugin deactivation for all users except ‘rubberduckers’ function rubberduckers_disable_plugin_deactivation($actions, $plugin_file, $plugin_data, $context) { // Get the current user $current_user = wp_get_current_user(); // Check if the current user’s username is NOT ‘rubberduckers’ if ($current_user->user_login !== ‘rubberduckers’) { // List…Continue reading

Show featured image in post list

// Show featured image in post list /* * * Add Featured Image Column to Admin Area and Quick Edit menu * Source: https://rudrastyh.com/wordpress/quick-edit-featured-image.html * */ /* * This action hook allows to add a new empty column */ add_filter(‘manage_resource_posts_columns’,…Continue reading

Enable Menu Management for Non-Administrators

function modify_appearance_menu() { if (!current_user_can(‘administrator’)) { // Remove access to themes and customize for all users except administrators remove_submenu_page(‘themes.php’, ‘themes.php’); remove_submenu_page(‘themes.php’, ‘customize.php’); // Block access to /wp-admin/themes.php and /wp-admin/customize.php global $pagenow; $restricted_pages = array(‘themes.php’, ‘customize.php’); if (in_array($pagenow, $restricted_pages)) { wp_redirect(admin_url());…Continue reading

Custom drag and drop

function enqueue_admin_reorder_scripts() { global $pagenow; // Ensure the script is not loaded on the plugins page if ($pagenow !== ‘plugins.php’) { wp_enqueue_script(‘jquery-ui-sortable’); wp_add_inline_script(‘jquery-ui-sortable’, ‘ jQuery(document).ready(function($) { var $sortableList = $(“#the-list”); var postType = $(“body”).attr(“class”).match(/post-type-([^\s]+)/)[1]; $sortableList.sortable({ update: function(event, ui) { var…Continue reading

Duplicate posts

// 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’ ) ) { /** *…Continue reading

Disable Attachment Filters to Fix Envira Gallery

add_action( ‘plugins_loaded’, function(){ remove_filter(‘attachment_fields_to_edit’, array(‘Fusion_Images’, ‘add_image_meta_fields’), 10); remove_filter(‘attachment_fields_to_edit’, array(‘Avada_Images’, ‘add_image_meta_fields’), 10); }, 99); function remove_masonry($fields) { unset($fields[‘fusion_masonry_element_layout’]); return $fields; } add_filter(‘attachment_fields_to_edit’, ‘remove_caption’, 99);Continue reading

Disable Name Editing With Checkbox

// Add checkbox to user profile for administrators function add_custom_user_profile_field_3784163($user) { if (current_user_can(‘administrator’)) { // Display checkbox only for administrators $restrict_name_change = get_user_meta($user->ID, ‘restrict_name_change’, true); $checked = $restrict_name_change === ‘yes’ ? ‘checked’ : ”; ?>Continue reading

[Admin] – Manage clinic locations

// Register menus add_action(‘admin_menu’, ‘register_vtc_form_menus’); function register_vtc_form_menus() { add_menu_page(‘VTC Form’, ‘VTC Form’, ‘manage_options’, ‘vtc_form’, ‘display_vtc_form_admin_page’, ‘dashicons-forms’, 6); add_submenu_page(‘vtc_form’, ‘Manage Clinics’, ‘Manage Clinics’, ‘manage_options’, ‘vtc_form_clinics’, ‘display_vtc_form_clinics_page’); } // Display the main admin page content function display_vtc_form_admin_page() { if (!current_user_can(‘manage_options’)) return; echo…Continue reading

Disable administrator role checkbox

function disable_administrator_role_checkbox() { $current_user = wp_get_current_user(); $current_user_roles = (array) $current_user->roles; // Check if the current user is an administrator if (in_array(‘administrator’, $current_user_roles)) { ?>Continue reading