Skip to content

Instantly share code, notes, and snippets.

Nuno Morais Sarmento nfsarmento

Block or report user

Report or block nfsarmento

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View PHP Detect All Versions of IE.php
$ua = htmlentities($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, 'UTF-8');
if (preg_match('~MSIE|Internet Explorer~i', $ua) || (strpos($ua, 'Trident/7.0') !== false && strpos($ua, 'rv:11.0') !== false)) {
// do stuff for IE
}
@nfsarmento
nfsarmento / Prevent mixture of a specific category and other products in same cart.php
Created Jan 9, 2020
Prevent mixture of a specific category and other products in same cart
View Prevent mixture of a specific category and other products in same cart.php
/*
* Prevent mixture of a specific category and other products in same cart
*/
function ns_dont_add_booklet_to_cart_containing_other($validation, $product_id) {
// Set flag false until we find a product in cat booklet
$cart_has_booklets = false;
// Set $cat_check true if a cart item is in booklet cat
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
@nfsarmento
nfsarmento / Custom Post Type Counts WordPress Admin Column on User List Page.php
Created Jan 8, 2020
Custom Post(s) Type Counts WordPress Admin Column on User List Page
View Custom Post Type Counts WordPress Admin Column on User List Page.php
add_action('manage_users_columns','ns_manage_users_columns');
function ns_manage_users_columns($column_headers) {
unset($column_headers['posts']);
$column_headers['custom_posts'] = 'Posts';
return $column_headers;
}
add_action('manage_users_custom_column','ns_manage_users_custom_column',10,3);
function ns_manage_users_custom_column($custom_column,$column_name,$user_id) {
View log-in-and-log-out-menu-links.php
@nfsarmento
nfsarmento / remove-menu-items-for-admin-bar.php
Created Dec 30, 2019
Removing Items From the Admin Bar
View remove-menu-items-for-admin-bar.php
/**
*
* Removing Items From the Admin Bar
*
*/
if ( ! function_exists( 'nwljds_remove_from_admin_bar' ) ) :
function nwljds_remove_from_admin_bar($wp_admin_bar) {
/*
* Placing items in here will only remove them from admin bar
* when viewing the fronte end of the site
@nfsarmento
nfsarmento / show-content-based-on-multiple-user-roles.php
Last active Jan 7, 2020
Show content based on multiple user roles in WordPress
View show-content-based-on-multiple-user-roles.php
<?php
global $user_login, $current_user;
wp_get_current_user();
$user_info = get_userdata($current_user->ID);
$roles = array (
'administrator',
'subscriber',
);
if (is_user_logged_in() && array_intersect( $roles, $user_info->roles)) {
View nginx-block-tor-ip.sh
wget -qO- https://check.torproject.org/exit-addresses | grep ExitAddress | cut -d ' ' -f 2 | sed "s/^/deny /g; s/$/;/g" > /etc/nginx/conf.d/tor-block.conf; systemctl reload nginx
#next add the following to your nginx site conf
#In nginx you then just include the blacklist.
include /etc/nginx/conf.d/tor-block.conf;
#The file contains statements like this:
@nfsarmento
nfsarmento / functions.php
Created Dec 4, 2019
Share post - Social Icons
View functions.php
<?php
/**
*
* Custom social icons on single post
*
*/
if ( ! function_exists( 'nstaxjustice_social_sharing_buttons' ) ) :
function nstaxjustice_social_sharing_buttons() {
global $post;
@nfsarmento
nfsarmento / apachevhost.sh
Last active Nov 14, 2019
Create apache2 virtual hosts on Ubuntu.
View apachevhost.sh
#! /bin/bash
# This script is used for creating apache2 virtual hosts on Ubuntu.
# Created by Nuno Sarmento from http://www.nuno-sarmento.com.
#
# DN = domainname -- used in apache config file
# DocRt is /var/www-vhosts/$DN
# Logs go in /var/log/apache2/$DN
#
echo -n "Enter full domain name without wwww (e.g. example.com): "
read -e DN
@nfsarmento
nfsarmento / functions.php
Last active Nov 4, 2019
Add a custom image to WordPress User Profile
View functions.php
/**
*
* Add custom user profile information
*
*/
add_action( 'show_user_profile', 'ns_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'ns_show_extra_profile_fields' );
function ns_show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
You can’t perform that action at this time.