Skip to content

Instantly share code, notes, and snippets.

@ridinghoodmedia
ridinghoodmedia / functions.php
Last active July 5, 2020 21:03
Populate Envira Gallery with ACF gallery field
/*
* Populate Envira Gallery with ACF gallery field
*
* Filters the gallery $data and replaces with the image data for our images in the ACF gallery field.
*
* @uses ACF Pro
* @uses Envira Gallery
* @param $data
* @param $gallery_id
*/
<?php
function my_acf_save_post_searchwp( $post_id ) {
// re-index the post
SWP()->purge_post( absint( $post_id ) );
SWP()->trigger_index();
// For some reason the above doesn't work unless there is some sort of output below it??
// The js can be any arbitrary even an alert, which causes an error with acf's redirect function
// but still updates the searchwp index
// Without the code below, the post is purged - i.e. the old meta is not found, but the new meta
@ridinghoodmedia
ridinghoodmedia / wp_kses_boilerplate.php
Last active April 25, 2016 21:58
wp_kses boilerplate
// Escape and echo search output and pagination
echo wp_kses( $content, array(
'div' => array(
'class' => array(),
'id' => array()),
'ul' => array('class' => array()),
'li' => array(
'class' => array(),
'p' => array()),
'a' => array(
//Useful js snippets
//Redirect to refferer url
if (document.referrer != "") {
location.href = document.referrer;
}
@ridinghoodmedia
ridinghoodmedia / envira-escape.php
Last active May 10, 2016 03:45
Escape envira gallery output
// Essentially this, but need to escape the output, as images are taken from ACF pro fields
function rl_gallery() {
envira_gallery( 'gallery', 'slug' );
}
// Escape and echo gallery
echo wp_kses( rl_gallery(), array(
'div' => array(
'class' => array(),
'class' => array(),
@ridinghoodmedia
ridinghoodmedia / array-tools.php
Last active June 15, 2016 17:42
PHP array functions
<?php
// Use array_search to get the key and remove it with unset if found:
if (($key = array_search('strawberry', $array)) !== false) {
unset($array[$key]);
}
// array_search returns false (null until PHP 4.2.0) if no item has been found.
// And if there can be multiple items with the same value, you can use array_keys to get the keys to all items:
foreach (array_keys($array, 'strawberry') as $key) {
@ridinghoodmedia
ridinghoodmedia / ajax-tools.js
Last active June 15, 2016 00:59
Useful ajax snippets
// Since the settings object is tied to that ajax call, you can simply add in the indexer
// as a custom setting, which you can then access using this in the success callback:
// http://stackoverflow.com/questions/18413969/pass-variable-to-function-in-jquery-ajax-success-callback
//preloader for images on gallery pages
window.onload = function() {
var urls = ["./img/party/","./img/wedding/","./img/wedding/tree/"];
setTimeout(function() {
for ( var i = 0; i < urls.length; i++ ) {
$.ajax({
@ridinghoodmedia
ridinghoodmedia / jquery.snippets.js
Created February 24, 2017 15:39
Helpful code snippets
// If variable exists
if ( typeof pagetype !== 'undefined' && pagetype == 'textpage' ) {
...
}
@ridinghoodmedia
ridinghoodmedia / postgres-cheatsheet.md
Last active December 7, 2017 05:51 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@ridinghoodmedia
ridinghoodmedia / wp_snippets.php
Last active February 3, 2018 02:33
Wordpress snippets
// Hide error display
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);
add_filter( 'auto_update_plugin', '__return_true' );
This filter tells WordPress automatic updater to automatically install plugin updates when they’re available.
If you also want to automatically update your themes, then you can add another code like this:
1 add_filter( 'auto_update_theme', '__return_true' );