Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Restorff paperrobots

View GitHub Profile
@heyfletch
heyfletch / migrate-db-pro-preserve-options.php
Last active Feb 28, 2020 — forked from daltonrooney/acf-migrate-db-pro.php
Prevent ACF Pro license key from being overwritten during WP Migrate DB Pro migration
View migrate-db-pro-preserve-options.php
<?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 Dec 20, 2016
Wordpress srcset snippet for ACF image field
View srcset.php
<?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 Aug 26, 2016
WPForms preselect dropdown field based on URL parameter
View functions.php
<?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
Fix so you can preview ACF field changes in Wordpress admin
View functions.php
<?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 Nov 7, 2013
[WordPress] Add file to media library programmatically
View gist:7352933
<?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 Dec 26, 2018
Shell script to create MAMP PRO virtual host
View vhost.sh
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 Sep 16, 2020
WordPress: check if a current page has children, if so display them, if not display all pages on the same level as current page
View gist:1247306
<?php
// Your functions.php content
function has_children() {
global $post;
$pages = get_pages('child_of=' . $post->ID);
return count($pages);