Skip to content

Instantly share code, notes, and snippets.

View nfsarmento's full-sized avatar

NS nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / ns-create-vh-db-wp-ssl.sh
Last active February 23, 2023 00:10
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 July 9, 2021 11:17
Hide a WordPress plugin from plugin list
function ns_hide_plugin() {
global $wp_list_table;
$hidearr = array('wordfence/wordfence.php', 'updraftplus/updraftplus.php', 'wp-security-audit-log/wp-security-audit-log.php', 'simple-history/index.php', 'user-switching/user-switching.php');
$myplugins = $wp_list_table->items;
foreach ($myplugins as $key => $val) {
if (in_array($key,$hidearr)) {
unset($wp_list_table->items[$key]);
}
}
}
@nfsarmento
nfsarmento / feature-post-query.php
Last active April 29, 2021 12:03
Feature post metabox and query
<div class="posts-listings">
<?php
$args = array(
'posts_per_page' => '1',
'orderby' => 'featured-checkbox',
'order' => 'ASC',
'meta_query' => array(
array(
@nfsarmento
nfsarmento / yz-send-bp-welcome-msg.php
Created March 31, 2021 10:27 — forked from KaineLabs/yz-send-bp-welcome-msg.php
Send Buddypress Welcome Message !
<?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 June 15, 2022 16:55
Wordpress Fail2Ban Filter (Debian/Ubuntu Apache2)

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 December 15, 2020 19:02
WordPress Allows contributors to see and manage only their custom post types and drafts from the manage posts screen.
/*
*
* 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 December 15, 2020 10:59
WordPress Menu add class to submenu.
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 December 15, 2020 10:58
WordPress Menu add class to <a>
/*
* 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;
}
@nfsarmento
nfsarmento / wg_install.sh
Created July 16, 2020 18:07 — forked from Anachron/wg_install.sh
A script to spin up a Wireguard VPN server with Unbound recursive DNS in a hurry
#!/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