Skip to content

Instantly share code, notes, and snippets.

Avatar

Nuno Morais Sarmento nfsarmento

View GitHub Profile
View Related posts
@nfsarmento
nfsarmento / wg_install.sh
Created Jul 16, 2020 — forked from Anachron/wg_install.sh
A script to spin up a Wireguard VPN server with Unbound recursive DNS in a hurry
View wg_install.sh
#!/bin/bash
# This file is designed to spin up a Wireguard VPN quickly and easily,
# including configuring a recursive local DNS server using Unbound
#
# Make sure to change the public/private keys before running the script
# Also change the IPs, IP ranges, and listening port if desired
# iptables-persistent currently requires user input
# add wireguard repo
sudo add-apt-repository ppa:wireguard/wireguard -y
@nfsarmento
nfsarmento / functions.php
Created Jul 2, 2020
Display categories in single-cpt.php
View functions.php
<?php
if ( is_singular('YOUR_CUSTOM_POST_TYPE') ) {
$terms = get_the_terms($post->ID, 'custom_categories');
foreach ($terms as $term) {
$term_link = get_term_link($term, 'custom_categories');
if (is_wp_error($term_link))
continue;
echo '<a href="' . $term_link . '">' . $term->name . '</a>, ';
}
@nfsarmento
nfsarmento / .htaccess
Last active May 29, 2020
WordPress Apache .htaccess
View .htaccess
## Use the code below only if you had enable .htaccess - "AllowOverride All"
## You may need to enable mod_headers on apache - "a2enmod headers"
## The code below goes under the rules that you should have if you are using WordPress
#BEGIN https code
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#BEGIN Block bad hackers
@nfsarmento
nfsarmento / WordPress shortoce to show Custom Post Type .php
Created May 19, 2020
WordPress shortoce to show Custom Post Type
View WordPress shortoce to show Custom Post Type .php
<?php
/**
*
* Usage [workcpt posts_per_page="4" term="4"] .
* I'm using MultiPostThumbnails plugin (line 63) to fetch a second fetaure image - if you are not using the plugin please replace that with get get_the_post_thumbnail_url(get_the_ID(),'full');
* Change post_type to your CPT name
* Change taxonomy to your taxonomy name
*
*/
// @codingStandardsIgnoreStart
@nfsarmento
nfsarmento / shortcode-button.php
Created May 19, 2020
WordPress shortcode to show button
View shortcode-button.php
<?php
/**
*
* Add a new custom button.
* Usage [custombutton url="https://www.nuno-sarmento.com/" target="self" text="Go To NS"].
*/
// @codingStandardsIgnoreStart
function ns_custom_button_shortcode( $atts, $content = null ) {
// shortcode attributes
@nfsarmento
nfsarmento / single.php
Created May 18, 2020
Get Related Posts For Custom Post Type by Custom Taxonomy
View single.php
<?php
// Show related posts.
// Fetch taxonomy terms for current product.
$productterms = get_the_terms( get_the_ID(), 'work_categories' );
if( $productterms ) {
$producttermnames[] = 0;
foreach( $productterms as $productterm ) {
$producttermnames[] = $productterm->name;
}
// Set up the query arguments.
@nfsarmento
nfsarmento / .htaccess
Last active May 16, 2020
WordPress Security Harden Apache .htaccess
View .htaccess
# Prevents directory listing
Options -Indexes
# Deny backup extensions & log files
<Files ~ "(^#.*#|~|\.save|\.sw[op])$">
Order allow,deny
Deny from all
</Files>
#Protect .htaccess From Unauthorized Access
@nfsarmento
nfsarmento / WordPress admin column to print user websites visits.php
Created May 6, 2020
WordPress admin column to print user websites visits
View WordPress admin column to print user websites visits.php
/*
* Admin user page custom column - Print User Web Visits Column Value
*/
class NSLogin_Counter {
public function init() {
add_action( 'wp_login', array( $this, 'count_user_login' ), 10, 2 );
add_filter( 'manage_users_columns', array( $this, 'add_stats_columns' ) );
add_filter( 'manage_users_custom_column', array( $this, 'fill_stats_columns' ), 10, 3 );
View Add SVG support on WordPress .php
/**
* Add svg support
*
*/
add_filter( 'wp_check_filetype_and_ext', function( $data, $file, $filename, $mimes) {
global $wp_version;
if( $wp_version == '4.7' || ( (float) $wp_version < 4.7 ) ) {
return $data;
}
$filetype = wp_check_filetype( $filename, $mimes );
You can’t perform that action at this time.