Skip to content

Instantly share code, notes, and snippets.

View garvs's full-sized avatar

Vladimir Garagulia garvs

View GitHub Profile
@garvs
garvs / remove-comments-actions.php
Created April 4, 2016 16:05
Remove comments actions for the role
<?php
add_action('bulk_actions-edit-comments', 'ure_remove_comments_actions');
add_action('comment_row_actions', 'ure_remove_comments_actions');
function ure_remove_comments_actions($actions) {
if (current_user_can('editor')) {
if (isset($actions['delete'])) {
unset($actions['delete']);
@garvs
garvs / wc-product-remove-main-editor.php
Created April 14, 2016 17:04
Remove main editor field from WooCommerce product edit page
<?php
function remove_product_editor() {
remove_post_type_support( 'product', 'editor' );
}
add_action( 'init', 'remove_product_editor' );
@garvs
garvs / wc-assign-other-role-instead-customer.php
Created May 5, 2016 01:15
Assign to new WooCommerce registered user another role instead of customer
/**
* Replace 'customer' role (WooCommerce use by default) with your own one.
**/
add_filter('woocommerce_new_customer_data', 'wc_assign_custom_role', 10, 1);
function wc_assign_custom_role($args) {
$args['role'] = 'subscriber';
return $args;
}
@garvs
garvs / exclude-posts-from-edit-restrictions.php
Last active October 17, 2019 03:27
User Role Editor Pro: Exclude posts from edit restrictions
<?php
add_filter( 'ure_restrict_edit_post_type', 'exclude_posts_from_edit_restrictions' );
function exclude_posts_from_edit_restrictions( $post_type ) {
$restrict_it = $post_type;
$user = wp_get_current_user();
if ( empty( $user) || !is_array( $user->roles ) ) {
return $restrict_it;
}
@garvs
garvs / not-edit-pending-for-review.php
Created December 30, 2016 03:21
Prohibit contributors editing pending posts
<?php
add_filter('map_meta_cap', 'not_edit_pending_for_review', 10, 4);
function not_edit_pending_for_review($caps, $cap, $user_id, $args) {
if ($cap!=='edit_post' && $cap!=='delete_post') {
return $caps;
}
@garvs
garvs / ure-edit-posts-access-id-list.php
Created January 7, 2017 03:58
ure_edit_posts_access_id_list filter
add_filter('ure_edit_posts_access_id_list', 'ure_edit_posts_access_set_id_list');
function ure_edit_posts_access_set_id_list($list) {
$list .= ',1584';
return $list;
}
@garvs
garvs / change-avada-admin-menu-permissions.php
Created January 18, 2017 07:58
Change Avada admin menu permissions
<?php
class Change_Avada_Admin_Menu_Permissions {
public function __construct() {
add_action('admin_menu', array($this, 'admin_menu'), 9);
}
// end of __construct()
@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;
}
@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 / 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;