Skip to content

Instantly share code, notes, and snippets.

View paperrobots's full-sized avatar

Matthew Restorff paperrobots

View GitHub Profile
@heyfletch
heyfletch / migrate-db-pro-preserve-options.php
Last active February 9, 2023 00:20 — forked from daltonrooney/acf-migrate-db-pro.php
Prevent ACF Pro license key from being overwritten during WP Migrate DB Pro migration
<?php
/*
Based on https://gist.github.com/daltonrooney/470619cca87a6c29cb84f92d856b9ec1
and http://github.com/deliciousbrains/wp-migrate-db-pro-tweaks
*/
class ACF_WP_Migrate_DB_Pro_Tweaks {
function __construct() {
add_filter( 'wpmdb_preserved_options', array( $this, 'preserved_options' ) );
}
@verticalgrain
verticalgrain / srcset.php
Created December 20, 2016 18:46
Wordpress srcset snippet for ACF image field
<?php
// Use an ACF image field
// Set the 'return value' option to "array" (this is the default)
// This example uses three image sizes, called medium, medium_large, thumbnail
$imageobject = get_field('image');
if( !empty($imageobject) ):
echo '<img alt="' . $imageobject['title'] . '" src="' . $imageobject['sizes']['medium'] . '" srcset="' . $imageobject['sizes']['medium_large'] .' '. $imageobject['sizes']['medium_large-width'] .'w, '. $imageobject['sizes']['medium'] .' '. $imageobject['sizes']['medium-width'] .'w, '. $imageobject['sizes']['thumbnail'] .' '. $imageobject['sizes']['thumbnail-width'] .'w">';
endif;
?>
@jaredatch
jaredatch / functions.php
Created August 26, 2016 19:34
WPForms preselect dropdown field based on URL parameter
<?php
/**
* Preselect dropdown field based on URL parameter.
*
* @param array $field
* @param array $field_atts
* @param array $form_data
* @return array
*/
function wpf_preselect_dropdown( $field, $field_atts, $form_data ) {
@ChrisLTD
ChrisLTD / functions.php
Created May 8, 2014 16:22
Fix so you can preview ACF field changes in Wordpress admin
<?php
/*
Debug preview with custom fields
Taken from: http://support.advancedcustomfields.com/forums/topic/preview-solution/
See also: http://support.advancedcustomfields.com/forums/topic/2nd-every-other-post-preview-throws-notice/
*/
add_filter('_wp_post_revision_fields', 'add_field_debug_preview');
function add_field_debug_preview($fields){
$fields["debug_preview"] = "debug_preview";
return $fields;
@hissy
hissy / gist:7352933
Created November 7, 2013 11:07
[WordPress] Add file to media library programmatically
<?php
$file = '/path/to/file.png';
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $parent_post_id,
@rsanchez
rsanchez / vhost.sh
Last active December 26, 2018 03:57
Shell script to create MAMP PRO virtual host
vhost( ) {
if [[ -z $1 ]]; then
echo 'usage: vhost [hostname]'
return
fi
HOST=$1
HOSTNAME="$HOST.dev"
ADDRESS="127.0.0.1"
SITEPATH="$HOME/Sites/$HOST"
@lukaszklis
lukaszklis / gist:1247306
Last active July 29, 2022 11:25
WordPress: check if a current page has children, if so display them, if not display all pages on the same level as current page
<?php
// Your functions.php content
function has_children() {
global $post;
$pages = get_pages('child_of=' . $post->ID);
return count($pages);