Skip to content

Instantly share code, notes, and snippets.

View craigedmonds's full-sized avatar

Craig Edmonds craigedmonds

  • JUCRA Digital SL
  • Marbella, Spain
View GitHub Profile
<?php
/*
This script will allow you to send a custom email from anywhere within wordpress
but using the woocommerce template so that your emails look the same.
Created by craig@123marbella.com on 27th of July 2017
Put the script below into a function or anywhere you want to send a custom email
*/
<?php
/*
Created by: craig@123marbella.com 16/03/2014
Name of script: Create WordPress Admin User
Description: This script will create an admin user in wordpress
Usage: Create a new file in the root of the hosting account and drop this code into it then execute the script through the browser.
@craigedmonds
craigedmonds / gist:02017b329ae5e6b3c5b75e2489aa9fd0
Created July 22, 2022 10:13
get acf gallery using post id outside of loop
<?php
/*
Created by craig@jucra.com on 22/7/2022
The code below will get a list of photos in their
order as they appear in the ACF gallery and provide
you with the thumbnail and large versions.
You can use $gallery to output the gallery code.
@craigedmonds
craigedmonds / gist:e750c6734b8bec47ca04b4d209b5f5f2
Created August 27, 2019 10:56
Get a list of field names and values from an ACF Group
<?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 / woocommerce-conditional-gifts-add-ons.php
Last active November 22, 2021 04:41
WooCommerce conditional fields for gifts options on checkout
<?php
##############################
/*
Conditionally show gift add-ons if user checks a box saying they would like to send the order as a gift.
Created by craig@123marbella.com on 13th of July 2017
As default, WooCommerce simply displays ALL the add ons so makes the checkout form look very long.
This is useful if you want to show a checkbox on your checkout saying "Is this a gift order?"
@craigedmonds
craigedmonds / allow-script-to-run.php
Created August 24, 2019 19:51
Allow a script to run only between two times and email on error
<?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
<?php
/*
Sometimes you need to do some kind of action to a custom post type after its saved.
In the case of this function my scenario is:
1. I have a custom post type registered called: clients
2. I want the url of their details page to be: /client-number-999/ (where 999 is the post_id - or client id)
Created by craig@123marbella.com on 16th of August 2017
@craigedmonds
craigedmonds / jucra-affiliates-to-clients-matching.php
Last active May 5, 2020 11:17
WHMCS custom matching of affiliates to clients (custom hook)
<?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 / wordpress-wp-query-search-cpt-and-two-custom-fields.php
Last active August 24, 2019 19:59
WP_Query - search CPT and two custom fields
<?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 / wordpress-get-first-x-chars-from-post.php
Created August 21, 2019 13:43
Wordpress Get First X Chars From Post
<?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);