Skip to content

Instantly share code, notes, and snippets.

View nfsarmento's full-sized avatar

Nuno Sarmento nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / export-active-woo-subscripitions.sql
Last active January 3, 2026 01:04
Export all ACTIVE subscriptions from WooCommerce Subscriptions using a MySQL query
SELECT
p.ID as 'Subscription ID',
p.post_status as 'Subscription Status',
pm1.meta_value as 'Billing First Name',
pm2.meta_value as 'Billing Last Name',
pm3.meta_value as 'Billing Email',
oitems.order_item_name as 'Product',
pm4.meta_value as 'Order Total',
pm5.meta_value as 'Order Tax'
FROM wp_posts p
@nfsarmento
nfsarmento / nginx-wordpress.conf
Last active December 18, 2025 05:54
Harden wordpress security nginx
############ WordPress ####################
# Disable logging for favicon and robots.txt
location = /favicon.ico {
try_files /favicon.ico @empty;
access_log off;
log_not_found off;
expires max;
}
@nfsarmento
nfsarmento / simple-map-defer.php
Created December 12, 2017 12:46 — forked from glueckpress/simple-map-defer.php
[WordPress][Simple Map] Load Google Maps API script from Simple Map deferred.
<?php
defined( 'ABSPATH' ) or die( 'No direct access here.' );
/**
* Plugin Name: Simple Map | Defer
* Description: Makes sure Google Maps API script from <a href="https://wordpress.org/plugins/simple-map/">Simple Map</a> gets loaded deferred.
* Author: Caspar Hübinger
* Author URI: https://profiles.wordpress.org/glueckpress
* Plugin URI: https://gist.github.com/glueckpress/56c88900aad391b95b5d44f4e752a1a4
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
@nfsarmento
nfsarmento / nginx-block-tor-ip.sh
Created December 27, 2019 13:58
nginx block tor
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 / ns-create-vh-db-wp-ssl.sh
Last active August 22, 2024 14:25
bash script to create mariadb database, create nginx virtual host, setup WordPress and install SSL.
#!/bin/bash
# -------------------------------------------------
# Make site directory
# Download WP and install WP to site directory
# Set WP configuration
# Configure NGINX for new domain-name
# -------------------------------------------------
#
# Requirments:
#
@nfsarmento
nfsarmento / functions.php
Created June 6, 2024 13:32
Create shortcode for WooCommerce basket Item and WooCommerce account Item
<?php
/**
*
* Create Shortcode for WooCommerce Basket Item and WooCommerce Account Item
* @link https://wpbeaches.com/add-woocommerce-cart-icon-to-menu-with-cart-item-count/#just-icon
*/
function mic_woo_cart_but() {
ob_start();
$cart_count = WC()->cart->cart_contents_count; // Set variable for cart item count
@nfsarmento
nfsarmento / ajax-filter-posts.js
Created March 11, 2018 12:42
Ajax filters for CPT with custom taxonomy
(function($) {
'use strict';
jQuery(document).ready(function() {
//Load all posts
asr_ajax_get_postdata(-1);
$('.asr_texonomy').on('click',function(){
var term_id = $(this).attr('data_id');
@nfsarmento
nfsarmento / funtions.php
Created April 17, 2024 19:13
WordPress - Disable a specific plugin update check
<?php
/**
*
* Prevent update notification for plugin
*
*/
function ns_disable_plugin_updates( $value ) {
$pluginsToDisable = [
'plugin-folder/plugin.php',
@nfsarmento
nfsarmento / functions.php
Last active April 17, 2024 19:08
Redirect all users that are not in the users array to the wp-admin dashboard page if trying to access the pages below declared
/**
*
* Redirect all users that are not in the users array to the wp-admin dashboard page if trying to access the pages below declared
*
*/
if ( ! function_exists( 'ns_redirect_users_by_role' ) ) :
function ns_redirect_users_by_role() {
global $pagenow;
@nfsarmento
nfsarmento / functions.php
Created March 20, 2024 16:30
Default/fallback post thumbnail image.
<?php
/**
*
* Default/fallback post thumbnail image.
*
*/
function aoa_filter_thumbnail_id( $thumbnail_id, $post = null ) {
if ( ! $thumbnail_id ) {