Skip to content

Instantly share code, notes, and snippets.

@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21
WordPress - Custom quantity of columns on the dashboard
//Custom quantity of columns on the dashboard
function restore_dashboard_columns() {
add_screen_option(
'layout_columns',
array(
'max' => 4, // Maximum number of columns
'default' => 2 // Value set as the default
)
);
}
@ofernandolopes
ofernandolopes / config.php
Created May 23, 2015 11:09
WordPress - Disable Automatic Updates
define( 'WP_AUTO_UPDATE_CORE', false );
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21
WordPress - Sender Email Custom
//Sender Email Custom
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');
function new_mail_from($old) {
return 'email@yourwebsite.com';
}
function new_mail_from_name($old) {
return 'Site Name';
@ofernandolopes
ofernandolopes / functions.php
Created May 23, 2015 11:18
WooCommerce - Remove Settings and Status submenus for non-administrator users
//Remove Settings and Status submenus for non-administrator users
if ( ! current_user_can('manage_options') ) {
add_action( 'admin_menu', 'my_remove_menu_pages', 999 );
function my_remove_menu_pages() {
remove_submenu_page('woocommerce', 'woocommerce_settings');
remove_submenu_page('woocommerce', 'woocommerce_status');
}}
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21
WordPress - User has access only to your posts
//User has access only to your posts
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;
$query->set('author', $user_ID );
}
return $query;
@ofernandolopes
ofernandolopes / functions.php
Created May 23, 2015 11:28
WordPress - User only has access to your uploaded media
//User only has access to your uploaded media
function my_files_only( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
if ( !current_user_can( 'level_5' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'my_files_only' );
@ofernandolopes
ofernandolopes / functions.php
Created May 23, 2015 11:33
WordPress - Remove menus for non-administrator users
//Remove menus for non-administrator users
add_action('admin_menu', 'remove_menus');
function remove_menus () {
global $menu;
if( (current_user_can('install_themes')) ) { // Hides the menus for users who have the lowest role that
$restricted = array();
}else{
$restricted = array(
__('Dashboard'),
__('Posts'),
@ofernandolopes
ofernandolopes / functions.php
Created May 23, 2015 11:39
WordPress - Add fields in the user profile
//Add fields in the user profile
function my_new_contactmethods( $contactmethods ) {
//Add Twitter
$contactmethods['twitter'] = 'Twitter';
//Add Facebook
$contactmethods['facebook'] = 'Facebook';
return $contactmethods;
}
add_filter('user_contactmethods','my_new_contactmethods',10,1);
@ofernandolopes
ofernandolopes / functions.php
Created May 23, 2015 11:43
WordPress - Remove fields in the user profile
//Remove fields in the user profile
add_filter('user_contactmethods','hide_profile_fields',10,1);
function hide_profile_fields( $contactmethods ) {
unset($contactmethods['website']);
unset($contactmethods['aim']);
unset($contactmethods['jabber']);
unset($contactmethods['yim']);
return $contactmethods;
}
@ofernandolopes
ofernandolopes / functions.php
Created May 23, 2015 11:49
WordPress - Remove comments, tags, categories, and author of the posts listing, pages and media
//Remove comments, tags, categories, and author of the posts listing, pages and media
//Remove of the posts listing
function custom_post_columns($defaults) {
unset($defaults['comments']);
unset($defaults['tags']);
unset($defaults['author']);
unset($defaults['categories']);
return $defaults;
}