Skip to content

Instantly share code, notes, and snippets.

Avatar

Nuno Morais Sarmento nfsarmento

View GitHub Profile
View yz-send-bp-welcome-msg.php
<?php
//send a welcome email when a user account is activated
add_action( 'bp_core_activated_user', 'yz_welcome_user_notification', 10, 3 );
function yz_welcome_user_notification( $user_id, $key = false, $user = false ) {
if ( is_multisite() ) {
return ;// we don't need it for multisite
}
//send the welcome mail to user
@nfsarmento
nfsarmento / fail2ban-wordpress.md
Last active Dec 29, 2020
Wordpress Fail2Ban Filter (Debian/Ubuntu Apache2)
View fail2ban-wordpress.md

Blocking wp-login.php brute forcing

This guide will tell you how to setup a custom fail2ban filter and jail to watch the Apache access log and ban malicious attackers who brute for wp-login.php.

Install fail2ban using apt

# apt install fail2ban

Create wordpress filter

@nfsarmento
nfsarmento / functions.php
Created Dec 15, 2020
WordPress Allows contributors to see and manage only their custom post types and drafts from the manage posts screen.
View functions.php
/*
*
* Allows contributors to see and manage only their custom post types and drafts from the manage posts screen.
* src: https://wordpress.stackexchange.com/questions/89233/restrict-contributors-to-view-only-their-own-custom-post-types
*
*/
add_action( 'pre_get_posts', 'aet_filter_cpt_listing_by_author' );
function aet_filter_cpt_listing_by_author( $wp_query_obj ){
// Front end, do nothing
if( !is_admin() )
@nfsarmento
nfsarmento / functions.php
Created Dec 15, 2020
WordPress Menu add class to submenu.
View functions.php
add_filter( 'wp_nav_menu_objects', 'ns_add_menu_parent_class' );
function ns_add_menu_parent_class( $items ) {
$parents = array();
foreach ( $items as $item ) {
//Check if the item is a parent item
if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
$parents[] = $item->menu_item_parent;
}
}
@nfsarmento
nfsarmento / functions.php
Created Dec 15, 2020
WordPress Menu add class to <a>
View functions.php
/*
* Menu
* add class to <a> on WP menu
*/
function ns_menu_add_class( $atts, $item, $args ) {
if($args->theme_location == 'topics') {
$class = 'term--single with-image'; // or something based on $item
$atts['class'] = $class;
}
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