Skip to content

Instantly share code, notes, and snippets.

@ofernandolopes
ofernandolopes / functions.php
Created June 19, 2023 16:48
Remove the 'all', 'publish', 'future', 'sticky', 'draft', 'pending', 'trash' views for non-admins
//Remove the 'all', 'publish', 'future', 'sticky', 'draft', 'pending', 'trash' views for non-admins
//https://wordpress.stackexchange.com/questions/224159/how-to-disable-or-remove-all-posts-published-and-trash-in-dashboard-posts
add_filter( 'views_edit-post', function( $views )
{
if( current_user_can( 'manage_options' ) )
return $views;
$remove_views = [ 'all','publish','future','sticky','draft','pending','trash' ];
foreach( (array) $remove_views as $view )
@ofernandolopes
ofernandolopes / functions.php
Created December 26, 2022 17:34
WordPress - Hide all admin notices for everyone except admin users
//Hide all admin notices for everyone except admin users
//https://wordpress.stackexchange.com/questions/396302/how-can-i-programattically-hide-all-admin-notices-for-everyone-except-admin-user
add_action(
'admin_notices',
function() {
if ( ! current_user_can( 'manage_options' ) ) {
remove_all_actions( 'admin_notices' );
}
},
0
@ofernandolopes
ofernandolopes / functions.php
Created June 21, 2022 08:55
Customizing WooCommerce
//
//Tips on Customizing WooCommerce - https://plugintests.com/plugins/wporg/woocommerce/tips
//
//How to Hide WooCommerce Admin Menus
function plt_hide_woocommerce_menus() {
//Hide "Tools → Scheduled Actions".
remove_submenu_page('tools.php', 'action-scheduler');
//Hide "WooCommerce".
@ofernandolopes
ofernandolopes / functions.php
Created May 30, 2021 09:17
Disable showing of WordPress post counts
//Disable showing of WordPress post counts
//https://www.collectiveray.com/show-only-posts-media-owned-logged-in-wordpress-user
function fix_post_counts($views) {
global $current_user, $wp_query;
unset($views['mine']);
$types = array(
array( 'status' => NULL ),
array( 'status' => 'publish' ),
array( 'status' => 'draft' ),
array( 'status' => 'pending' ),
@ofernandolopes
ofernandolopes / functions.php
Created May 30, 2021 09:11
Restricting Authors to View Only Posts They Created
//Restricting Authors to View Only Posts They Created
//https://www.isitwp.com/restricting-authors-to-view-only-posts-they-created/
function posts_for_current_author($query) {
global $pagenow;
if( 'edit.php' != $pagenow || !$query->is_admin )
return $query;
if( !current_user_can( 'manage_options' ) ) {
global $user_ID;
@ofernandolopes
ofernandolopes / functions.php
Last active June 14, 2022 17:33
Removing links from the WordPress Toolbar
//Removing links from the WordPress Toolbar
function webriti_remove_admin_bar_links() {
global $wp_admin_bar;
//Remove WordPress Logo Menu Items
$wp_admin_bar->remove_menu('wp-logo'); // Removes WP Logo and submenus completely, to remove individual items, use the below mentioned codes
$wp_admin_bar->remove_menu('about'); // 'About WordPress'
$wp_admin_bar->remove_menu('wporg'); // 'WordPress.org'
$wp_admin_bar->remove_menu('documentation'); // 'Documentation'
$wp_admin_bar->remove_menu('support-forums'); // 'Support Forums'
@ofernandolopes
ofernandolopes / function.php
Created May 30, 2021 02:46
Removing wp admin bar nodes for non admin
// Removing wp admin bar nodes for non admin
function wpdocs_remove_nodes($wp_admin_bar)
{
// Remove items from the menu bar.
if ( ! current_user_can('administrator')) {
$wp_admin_bar->remove_node('wp-logo');
$wp_admin_bar->remove_node('comments');
$wp_admin_bar->remove_node('new-content');
$wp_admin_bar->remove_node('edit');
$wp_admin_bar->remove_node('litespeed-menu');
@ofernandolopes
ofernandolopes / functions.php
Created August 29, 2020 08:50
Remove fields from WooCommerce checkout page.
//Remove fields from WooCommerce checkout page.
add_filter( 'woocommerce_checkout_fields' , 'custom_remove_woo_checkout_fields' );
function custom_remove_woo_checkout_fields( $fields ) {
// remove billing fields
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
@ofernandolopes
ofernandolopes / functions.php
Created May 12, 2020 22:53
WooCommerce set default city on checkout
/**
* @snippet WooCommerce Set Default City @ Checkout
* @how-to Get CustomizeWoo.com FREE
* @sourcecode https://businessbloomer.com/?p=21223
* @author Rodolfo Melogli
* @testedwith WooCommerce 3.4.6
*/
add_filter( 'woocommerce_checkout_fields', 'bbloomer_set_checkout_field_input_value_default' );
@ofernandolopes
ofernandolopes / functions.php
Created May 6, 2020 15:41
WooCommerce - Change add to cart text
// To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' );
function woocommerce_custom_single_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
}
// To change add to cart text on product archives(Collection) page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
function woocommerce_custom_product_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );