Skip to content

Instantly share code, notes, and snippets.

Craig Edmonds craigedmonds

Block or report user

Report or block craigedmonds

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@craigedmonds
craigedmonds / gist:e750c6734b8bec47ca04b4d209b5f5f2
Created Aug 27, 2019
Get a list of field names and values from an ACF Group
View gist:e750c6734b8bec47ca04b4d209b5f5f2
<?php
########################
// GET FIELD NAMES AND VALUES FROM ACF GROUP
//
// created by craig@jucra.com on 27/8/2019
//
// This script will do the following:
// 1. Loop through the fields in a specific ACF Group
// 2. Create an array called $array_of_field_names
// so you can easily print out a list of the field names
@craigedmonds
craigedmonds / wordpress-wp-query-search-cpt-and-two-custom-fields.php
Last active Aug 24, 2019
WP_Query - search CPT and two custom fields
View wordpress-wp-query-search-cpt-and-two-custom-fields.php
<?php
########################
// Here you can search a post type or post and find posts
// with two different custom field data (keys).
// This is useful if you have setup two custom fields and storing
// data in the fields and need to find posts that match.
// In the case below I have two custom fields: content_client_id and content_status
// content_client_id = the id of a client
// content_status = the status of a post (EG: Awaiting Approval by Client)
// I want to find all posts that match a client id and Awaiting Approval by Client
@craigedmonds
craigedmonds / allow-script-to-run.php
Created Aug 24, 2019
Allow a script to run only between two times and email on error
View allow-script-to-run.php
<?php
########################
// allow a script to only be run between two times
// EG: you can use this for a cron job and if someone tries to access it outside the times
// then you can block the request.
########################
header('Content-type: application/json; charset=utf-8'); //set the page to text only (optional)
$start_time = "09:00";
$end_time = "09:30";
$server_time_zone = date_default_timezone_get(); //this is the current server timezone
View wordpress-get-first-x-chars-from-post.php
<?php
#########################################################
// Get the first X chars from the content post (strips out any html)
// USAGE: get_intro_text($max_char = 75, $content, $more_link_text = '(more...)')
#########################################################
function get_intro_text($max_char, $content, $more_link_text = '(more...)') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
$content = strip_tags($content);
@craigedmonds
craigedmonds / footer.php
Last active Apr 29, 2019
Add 21 days to the date picker on a gravity form. This is useful for only allowing people to select a date in the future.
View footer.php
@craigedmonds
craigedmonds / sync_arctis-dealers.php
Created Oct 25, 2018
This is a special function whcih pulls in the remote data from the dealer core and stores a local json file with the dealers data. The dealers details pages will actually be populated from the local json file so we do not need to do any major database processed which will save database overhead.
View sync_arctis-dealers.php
<?php
############################
//sync the dealer store pages
############################
/*
This is a special function whcih pulls in the remote data from the dealer core
and stores a local json file with the dealers data. The dealers details pages will actually
be populated from the local json file so we do not need to do any major database processed
which will save database overhead.
*/
@craigedmonds
craigedmonds / functions.php
Created Oct 19, 2018
This checks to see if the post being loaded is 1. a special offer 2. if the dealer is authorised to load the special offer on their dealer site and if not we force a 301 redirect back to the dealers home page
View functions.php
<?php
######################################################
//Here we will check to see if the special offer being presented
//is in the list of the dealers posts and if not do a 301 redirect
//back to the home page
//added on 19/10/2018 by craig@jucra.com
######################################################
function white_label_special_offer_301_redirect_check($array_of_dealer) {
###################################################
@craigedmonds
craigedmonds / functions.php
Created Oct 19, 2018
Get a list of special offers for a dealer based on whether the dealer has special offers turned off, whether they are in a certain region or whether they have their own special offers.
View functions.php
<?php
######################################################
//get a list of specials assigned to a dealer so that we can display a list
//of post id's in the array_of_dealer
//added on 19/10/2018 by craig@jucra.com
######################################################
function white_label_get_array_of_special_offer_posts_for_dealer($dealer_id) {
###################################################
//STEP 1
@craigedmonds
craigedmonds / jucra-affiliates-to-clients-matching.php
Last active Feb 8, 2019
WHMCS custom matching of affiliates to clients (custom hook)
View jucra-affiliates-to-clients-matching.php
<?php
/*
Custom WHMCS Affiliate hook by craig@jucra.com
Date: 14th October 2018
Stored in WHCMS: /includes/hooks/
The WHMCS affiliate system is basic, very basic in terms of: affiliates can only
earn comissions based on orders they generate.
@craigedmonds
craigedmonds / get-files-and-folders-array.php
Last active Oct 11, 2017
Iterate through directories and sub directories and get list of files and folders in an array
View get-files-and-folders-array.php
<?php
###########################
/*
This script is useful if you wanted to get a list of the files and folders within a directory on your web site.
EG: Lets say you wanted to monitor your theme folder in wordpress. With this script you can generate a list of
all the files and folders and check for any changes.
You could extend this script to exclude certain folders or file names or file types.
You can’t perform that action at this time.