Skip to content

Instantly share code, notes, and snippets.

View garvs's full-sized avatar

Vladimir Garagulia garvs

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / block-admin-notices.php
Last active December 16, 2022 05:41
Block admin notices option for User Role Editor
<?php
add_filter('ure_role_additional_options', 'ure_add_block_admin_notices_option', 10, 1);
function ure_add_block_admin_notices_option($items) {
$item = URE_Role_Additional_Options::create_item('block_admin_notices', esc_html__('Block admin notices', 'user-role-editor'), 'admin_init', 'ure_block_admin_notices');
$items[$item->id] = $item;
return $items;
}
@garvs
garvs / functions.php
Created March 25, 2016 01:09
Block permalink edit button
<?php
/*
* Hide permalink 'Edit' button for 'author' role
*/
add_action('edit_form_before_permalink', 'ure_block_edit_slug');
function ure_block_edit_slug() {
if (!current_user_can('author')) {
return;
@garvs
garvs / functions.php
Created March 5, 2016 03:05
Custom user capability to duplicate WooCommerce products
<?php
add_filter('woocommerce_duplicate_product_capability', 'my_woocommerce_duplicate_product_capability');
function my_woocommerce_duplicate_product_capability($cap) {
return 'duplicate_products';
}