Skip to content

Instantly share code, notes, and snippets.

View ajskelton's full-sized avatar

Anthony ajskelton

View GitHub Profile
@ajskelton
ajskelton / Meta_Box.php
Last active January 31, 2024 23:30
Add 'searchwp_related_sample_engines' filter to the get_samples function
/**
* Get associative array of sample results for keywords
*
* @param string $existing_keywords
*
* @param int $post_id
*
* @return array
*/
public function get_samples( $existing_keywords = '', $post_id = 0 ) {
@ajskelton
ajskelton / gist:915675de94d914bbadd9bcef965c3cbc
Created July 26, 2021 22:23
WordPress SQL Query for finding posts that have a specific acf value
SELECT * FROM wp_posts
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_posts.post_status = 'publish'
AND wp_postmeta.meta_value = '%ACF_FIELD_VALUE%'
ORDER BY wp_posts.ID
@ajskelton
ajskelton / gist:b358fa7e58c303314f7b2fe962a651f8
Created April 6, 2020 15:36
Test for pages using a specific Page Template
function test_for_page_template() {
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'PAGETEMPLATE.php'
)
)
);
@ajskelton
ajskelton / wp-external-image-handler.php
Last active March 15, 2022 04:47
WordPress External Image Handler - Add External URL image as featured image for a post
/**
* Uploads an image from remote url and sets as featured image of the new post
*
* @param int $post_id The id of the new post
* @param string $thumbnail_url Url of the preview image hosted by BrightTalk
*/
private function image_handler( $post_id, $thumbnail_url ) {
$image_url = $thumbnail_url; // Define the image URL here
$image_name = basename( $thumbnail_url );
alias gtree='git log --graph --abbrev-commit --decorate --date=relative --format=format:'\''%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'\'' --all'
add_filter( 'acf/load_value/name=content_blocks', 'default_fields', 10, 3 );
function default_fields( $value, $post_id, $field ) {
// Only add default content for new posts
if ( $value !== null ) {
return $value;
}
// Only add default content for certain post types
if ( ! in_array(
@ajskelton
ajskelton / gist:6eca1d026301a1690213a671c5e564bc
Last active January 30, 2019 18:50
Laravel Valet Local then Remote Images
location ~* .(png|jpe?g|gif|ico|svg)$ {
expires 24h;
log_not_found off;
root '/Users/USERNAME/.valet/Sites/mixpanel/’;
if (-f $request_filename) {
break;
}
try_files $uri $uri/ @production;
}
@ajskelton
ajskelton / gravity-forms-email-blacklist.php
Created April 5, 2018 15:49
Gravity Forms email blacklist
add_filter( 'gform_field_validation', 'PREFIX_gravity_forms_blacklist', 10, 4 );
/**
* Added Validation check for email vs blacklist of free email accounts.
*
* @param $result array The validation result to be filtered
* @param $value string|array The field value to be validated
* @param $form object Current Form object
* @param $field object Current Field object
*
* @return mixed
$regex = "/([0-9]{1,2}:[0-9]{2}:[0-9]{2})\s(AM|PM|XM)\s{0,1}\*{3}\s{0,3}\ *{1,2}LOCAL.*?([0-9]{1,2}:[0-9]{2})/";
@ajskelton
ajskelton / removeHash
Created June 26, 2017 16:34
Remove the hash from a url and keep the browser in the same scroll position
function removeHash () {
var scrollV, scrollH, loc = window.location;
if ("pushState" in history)
history.pushState("", document.title, loc.pathname + loc.search);
else {
// Prevent scrolling by storing the page's current scroll offset
scrollV = document.body.scrollTop;
scrollH = document.body.scrollLeft;
loc.hash = "";