Skip to content

Instantly share code, notes, and snippets.

View fahdi's full-sized avatar

Fahad Murtaza fahdi

View GitHub Profile
@fahdi
fahdi / wp_filter.php
Created April 20, 2022 11:15
Examples for WP filter
<?php
/*
Plugin Name: Filter the content to remove ADULTKEYWORD. This is an example plugin
*/
add_filter('the_content', 'fm_filter_the_main_loop', 1);
function fm_filter_the_main_loop($content)
{
@fahdi
fahdi / hello-world.php
Created April 16, 2022 16:25
Your next assignment - WP Plugin dev
<?php
/*
Plugin Name: Hello World New
*/
function hello_world_new() {
return '<p>Hello World!</p>';
}
add_shortcode( 'hello_world_new', 'hello_world_new' );
@fahdi
fahdi / wp-list-posts-from-last-month.php
Created November 3, 2021 00:01
WordPress List all posts from last month
<?php
// WordPress List all posts from last month
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
@fahdi
fahdi / calculate-day-between-dates.php
Created November 2, 2021 23:55
Calculate days between dates in php
<?php
function calculateDaysBetweenDates() {
// set time zone to karachi
date_default_timezone_set('Asia/Karachi');
$startDate = new DateTime( 'last thursday' );
$endDate = new DateTime( 'today' );
$interval = $startDate->diff( $endDate );
return $interval->format( '%a' );
@fahdi
fahdi / wp-permissions-script
Created October 10, 2021 10:26 — forked from macbleser/wp-permissions-script
WordPress Permissions Configuration Script
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro
#
WP_OWNER=changeme # &lt;-- wordpress owner
WP_GROUP=changeme # &lt;-- wordpress group
WP_ROOT=/home/changeme # &lt;-- wordpress root directory
@fahdi
fahdi / wp_make_new_site.sh
Created October 9, 2021 14:31 — forked from romanitalian/wp_make_new_site.sh
BASH script to make new WP site: download and WP, configure and restart NGINX; install/make wordpress site by Bash script; wordpress install; wordpress configuration; wordpress initialisation
#!/bin/bash
# -------------------------------------------------
# Make site directory
# Download WP and install WP to site directory
# Set WP configuration
# Configure NGINX for new domain-name
# -------------------------------------------------
# apt-get update
<?php
// add to functions.php
add_filter( 'facetwp_facet_dropdown_show_counts', '__return_false' );
function fwp_wrapper_open() {
echo '<div class="facetwp-template"><!-- start facetwp template -->';
}
<?php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( '' == FWP()->helper->get_uri() && 'dealerships' != $query->get( 'post_type' ) ) {
return false;
}
return $is_main_query;
}, 10, 2 );
@fahdi
fahdi / post-data-curl.php
Created January 12, 2021 01:15
Post data to the API /echo/ at https://github.com/fahdi/echo-slim
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://localhost:8090/echo',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,