Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@dgoze
dgoze / acf_sync_with_user_profile.php
Created July 24, 2024 18:11 — forked from sabrina-zeidan/acf_sync_with_user_profile.php
When you have ACF User fields like first name and last name and you need to keep that in sync with what is entered in WordPress user profile (works both ways)
//If both changed at the same time - custom field value will be applied as it fires later, set 30 to change it add_action( 'profile_update', array($this, 'update_acf_fields'), 30, 2 );
class Sync_ACF_with_User_Profile_Class {
static public $sync_pair = array(
array( 'acf' => 'member_name', 'profile_field' => 'first_name'), //add acf field name according to your setup
array( 'acf' => 'member_lastname', 'profile_field' => 'last_name')// add more rows to sync any other fields as well
);
public function __construct() {
add_action( 'profile_update', array($this, 'update_acf_fields'), 10, 2 ); //when profile is updated -> update ACF
add_action('updated_user_meta', array($this, 'update_user_profile_fields'),10,4); // when ACF is updated -> update profile
add_action('added_user_meta', array($this, 'update_user_profile_fields'),10,4); // when ACF is added -> update profile
@dgoze
dgoze / functions.php
Created July 24, 2024 18:10 — forked from noahduncan/functions.php
Automatically Sync ACF Fields on dev environments
<?php
/*
Plugin Name: Zing ACF Auto Sync
Plugin URI:
Description: Plugin that automatically syncs the database with local json for .test urls
Version: 20180419
Author: Noah Duncan <[email protected]>
*/
/* Put in /wp-content/mu-plugins/zing-acf-auto-sync/zing-acf-auto-sync.php if you want as a plugin */
@dgoze
dgoze / gist:ebf4d1e340338bf4c576fba39cdf0a77
Created July 24, 2024 18:10 — forked from craigedmonds/gist:e750c6734b8bec47ca04b4d209b5f5f2
Get a list of field names and values from an ACF Group
<?php
########################
// GET FIELD NAMES AND VALUES FROM ACF GROUP
//
// created by [email protected] 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
@dgoze
dgoze / HTMLEntities.php
Created July 24, 2024 18:10 — forked from esamattis/HTMLEntities.php
Automatically decode HTML entities from wp-graphql content fields
<?php
/**
* WordPress does automatic HTML entity encoding but so does React which
* results in double encoding. This reverts the one from WordPress when
* the content is requested using wp-graphql making your life as a React
* dev easier.
*
*/
class HTMLEntities
@dgoze
dgoze / us-states-insert-terms.php
Created July 24, 2024 18:09 — forked from codytooker/us-states-insert-terms.php
US States to insert into a Wordpress Taxonomy
<?php
$states = array(
'Alabama',
'Alaska',
'Arizona',
'Arkansas',
'California',
'Colorado',
'Connecticut',
@dgoze
dgoze / functions.php
Created July 24, 2024 18:09 — forked from ChrisLTD/functions.php
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;
@dgoze
dgoze / acf_get_directions.php
Created July 24, 2024 18:08 — forked from mattradford/acf_get_directions.php
ACF Get Directions map link
<?php
$location = get_field('map_location');
if ( !empty( $location ) ) :
$map_url = 'https://www.google.com/maps/dir/?api=1&destination=' . $location['lat'] . ',' . $location['lng'];
echo '<a href=". esc_url( $map_url ) . '" rel="nooopener">Get directions</a>';
endif;
?>
<p>This should produce a link like this:</p>
<a href="https://www.google.com/maps/dir/?api=1&destination=51.072159,1.088130">Get directions</a>
@dgoze
dgoze / acf-missing.php
Created July 24, 2024 18:07 — forked from thierrypigot/acf-missing.php
WordPress mu plugins to check if "Advanced Custom Fields Pro" is active.
<?php
if( !class_exists('acf') )
{
$tp_acf_notice_msg = __( 'This website needs "Advanced Custom Fields Pro" to run. Please download and activate it', 'tp-notice-acf' );
/*
* Admin notice
*/
add_action( 'admin_notices', 'tp_notice_missing_acf' );
function tp_notice_missing_acf()
@dgoze
dgoze / sync_acf_post_title.php
Created July 24, 2024 18:07 — forked from rveitch/sync_acf_post_title.php
Update WordPress post title from an ACF field value on save. (Advanced Custom Fields)
<?php
/**
* Update Post Title from an ACF field value on post save.
*
* Triggers on save, edit or update of published posts.
* Works in "Quick Edit", but not bulk edit.
*/
function sync_acf_post_title($post_id, $post, $update) {
$acf_title = get_field('my_acf_field_name', $post_id); // NOTE: enter the name of the ACF field here
@dgoze
dgoze / expose_ACF_fields_to_REST.php
Created July 24, 2024 18:07 — forked from MelMacaluso/expose_ACF_fields_to_REST.php
Automatically expose all the ACF fields to the Wordpress REST API in Pages and in your custom post types.
<?php
function create_ACF_meta_in_REST() {
$postypes_to_exclude = ['acf-field-group','acf-field'];
$extra_postypes_to_include = ["page"];
$post_types = array_diff(get_post_types(["_builtin" => false], 'names'),$postypes_to_exclude);
array_push($post_types, $extra_postypes_to_include);
foreach ($post_types as $post_type) {
register_rest_field( $post_type, 'ACF', [