Skip to content

Instantly share code, notes, and snippets.

View garvs's full-sized avatar

Vladimir Garagulia garvs

View GitHub Profile
@garvs
garvs / functions.php
Created November 28, 2019 03:02
Add JavaScript code to front-end page for a role
<?php
// Additional options for URE
// Hide parts of front-end page for selected role
add_filter( 'ure_role_additional_options', 'ure_add_front_end_js_option', 10, 1 );
function ure_add_front_end_js_option( $items ) {
$item = URE_Role_Additional_Options::create_item( 'change_front_end_css', esc_html__('Change Front-end CSS', 'user-role-editor'), 'init', 'ure_add_front_end_js_init' );
$items[$item->id] = $item;
@garvs
garvs / restrict-woocommerce-reports-tabs.php
Created November 3, 2019 02:48
Restrict Woocommerce reports tab
<?php
add_filter( 'woocommerce_admin_reports', 'restricts_wc_reports_tabs', 10, 1 );
function restricts_wc_reports_tabs( $reports ) {
if ( current_user_can( 'manage_woocommerce' ) ) {
// do not restrict WooCommerce admin
return $reports;
}
@garvs
garvs / ure-hide-screen-options.php
Created April 10, 2019 14:40
This code adds additional option to the Users->User Role Editor, which allows to hide "Screen Options" link from the top of WordPress admin pages for the selected role
<?php
// Add additional option "Hide Screen Options" for every role at Users->User Role Editor
add_filter('ure_role_additional_options', 'add_hide_screen_options', 10, 1);
function add_hide_screen_options( $items ) {
$item = URE_Role_Additional_Options::create_item(
'hide_screen_options',
esc_html__('Hide Screen Options', 'user-role-editor'),
'screen_options_show_screen',
@garvs
garvs / export-roles-csv.php
Created February 1, 2019 04:06
Export all WordPress user roles to CSV file
<?php
/* Project: User Role Editor WordPress plugin
* Adds admin menu item "Tools->Export roles (CSV)" and allows to export all user roles to CSV file with one click
* Setup: Install as a Must Use plugin: https://codex.wordpress.org/Must_Use_Plugins
* Author: Vladimir Garagulia
* Email: [email protected]
* Site: https://role-editor.com
* License: GPL v.3
*/
@garvs
garvs / ure-widgets-edit-access-user.php
Created September 18, 2018 08:28
User Role Editor Pro ure_widgets_edit_access_user filter example
<?php
add_filter('ure_widgets_edit_access_user', 'ure_restrict_widgets_edit_access_for_user', 10, 2);
/*
* $blocked - array of widgets and sidebars which should be unavailable for editing to the current user.
* $blocked['widgets'] - array with list of widgets
* $blocked['sidebars'] - array with list of sidebars
* $user - WP_User object with data about the current user
*
@garvs
garvs / restrict-wc-orders-statuses.php
Last active March 5, 2023 16:21
User Role Editor: Show for the role WooCommerce orders with selected status only
<?php
add_filter('ure_role_additional_options', 'add_show_processing_orders_only_to_admin_option', 10, 1);
function add_show_processing_orders_only_to_admin_option($items) {
$item = URE_Role_Additional_Options::create_item('show_processing_orders_only', esc_html__('Show orders with =Processing= status only', 'user-role-editor'), 'init', 'show_processing_orders_only');
$items[$item->id] = $item;
return $items;
}
@garvs
garvs / ure-supress-admin-protect.php
Created July 12, 2018 10:08
User Role Editor WordPress plugin - suppress admin protection
<?php
add_filter('ure_supress_administrators_protection', 'switch_off_ure_administrators_protection', 10, 1);
function switch_off_ure_administrators_protection($supress_protection) {
$supress_protection = true;
return $supress_protection;
}
@garvs
garvs / ure_addons_to_copy_for_new_blog.php
Created May 5, 2018 05:02
ure_addons_to_copy_for_new_blog filter filter
<?php
add_filter('ure_addons_to_copy_for_new_blog', 'ure_addons_to_copy_for_new_blog', 10, 1);
function ure_addons_to_copy_for_new_blog($addons) {
$addons['admin_menu']->copy = true;
$addons['widgets_admin']->copy = true;
$addons['widgets_show']->copy = true;
$addons['meta_boxes']->copy = true;
@garvs
garvs / hide-wp-logo-admin-bar-menu.php
Created March 5, 2018 02:18
Hide WP Logo from admin bar menu additional role option
/**
* This code adds additonal option to the Users->User Role Editor,
* which allows to hide WordPress Logo menu from admin bar menu for the selected role
**/
add_filter('ure_role_additional_options', 'ure_hide_wp_logo_role_option', 10, 1);
function ure_hide_wp_logo_role_option($items) {
$item = URE_Role_Additional_Options::create_item('hide_wp_logo', esc_html__('Hide WP Logo from admin menu bar', 'user-role-editor'), 'admin_bar_menu', 'hide_wp_logo_admin_bar_menu');
$items[$item->id] = $item;
@garvs
garvs / block-woocommerce-refunds-for-role.php
Last active August 14, 2017 04:51
Block WooCommerce refunds for role
<?php
add_action('admin_head', 'hide_wc_refund_button');
function hide_wc_refund_button() {
global $post;
if (!current_user_can('sales')) {
return;
}