Skip to content

Instantly share code, notes, and snippets.

Avatar

Nuno Morais Sarmento nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / NPM installation requirements
Created Jun 6, 2022 — forked from kompuser/NPM installation requirements
Roots Sage Gulpfile Including Critical CSS and CombineMQ
View NPM installation requirements
npm install --save asset-builder browser-sync del gulp gulp-autoprefixer gulp-changed gulp-concat gulp-cssnano gulp-flatten gulp-if gulp-imagemin gulp-jshint gulp-less gulp-plumber gulp-rename gulp-rev gulp-sass gulp-sourcemaps gulp-uglify imagemin-pngcrush jshint jshint-stylish lazypipe merge-stream minimist run-sequence traverse wiredep gulp-util gulp-combine-mq critical gulp-rename gulp-penthouse
View 01-gulpfile.js
/*!
* gulp
* $ npm install gulp-ruby-sass gulp-autoprefixer gulp-cssnano gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev
*/
// Load plugins
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
@nfsarmento
nfsarmento / functions.php
Created May 17, 2022
Disable admin notices In WordPress for all users apart from the the ID define on the Array
View functions.php
<?php
/**
* How To Disable Admin Notices In WordPress
*
*/
add_action('admin_enqueue_scripts', 'os_admin_theme_style');
add_action('login_enqueue_scripts', 'os_admin_theme_style');
function os_admin_theme_style() {
$super_admins = array( 5 );
if( ! in_array( get_current_user_id(), $super_admins ) ){
@nfsarmento
nfsarmento / functions.php
Created Oct 1, 2021
Custom contact form shortcode - used for custom product enquiry on WooCommerce
View functions.php
/**
*
* Shortcode contact form
*/
// @codingStandardsIgnoreStart
function decorativefair_shortcode_product_form($item) {
ob_start();
global $post, $product;
$author_name = get_the_author_meta( 'user_email', $product->post->post_author );
@nfsarmento
nfsarmento / functions.php
Created Sep 13, 2021
WordPress Countdown Timer Shortcode
View functions.php
<?php
/*
*
* Countdown Timer Shortcode
* [cdt month="9" day="28" year="2021"] This is content that will only be shown after a set number of days.[/cdt]
*
*/
// @codingStandardsIgnoreStart
function aet_content_countdown($atts, $content = null){
extract(shortcode_atts(array(
@nfsarmento
nfsarmento / ns-create-vh-db-wp-ssl.sh
Last active Sep 8, 2021
bash script to create mariadb database, create nginx virtual host, setup WordPress and install SSL.
View ns-create-vh-db-wp-ssl.sh
#!/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 Jul 9, 2021
Hide a WordPress plugin from plugin list
View functions.php
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 Apr 29, 2021
Feature post metabox and query
View feature-post-query.php
<div class="posts-listings">
<?php
$args = array(
'posts_per_page' => '1',
'orderby' => 'featured-checkbox',
'order' => 'ASC',
'meta_query' => array(
array(
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 Jun 15, 2022
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