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-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', [
@dgoze
dgoze / remove-custom-taxonomy-metabox.php
Created July 24, 2024 18:06
Remove Custom Taxonomy Metabox from WP Sidebar #wordpress #cptui
<?php
// example custom post type is "event"
// example custom taxonomy is "events-category"
function remove_default_event_category_metabox() {
remove_meta_box( 'tagsdiv-events-category', 'event', 'side' );
}
add_action( 'admin_menu' , 'remove_default_event_category_metabox' );
@dgoze
dgoze / Move Old Event to Past Event Taxonomy.php
Created July 24, 2024 18:06
Move Old Events to 'Past Event' Taxonomy #wordpress #cron
<?php //for formatting - ignore this line
// Move Old Events to 'Past Event' Taxonomy
add_action( 'hide_old_events', 'run_hide_old_events' );
add_action('admin_init', function() { // check on admin load, could be on init, but seems overkill
if (! wp_next_scheduled ( 'hide_old_events' )) { //see if the event is set
wp_schedule_event( strtotime('tomorrow 12:01am'), 'daily', 'hide_old_events' ); //Schedule it to run at 12:01 am - adjust to your liking
}
@dgoze
dgoze / remove-custom-taxonomy-metaboxes.php
Created July 24, 2024 18:06
Remove All Custom Taxonomy Sidebar Metaboxes #cptui #wordpress
<?php // ignore - for formatting only
// Useful if you are creating custom taxonomines and controlling them with ACF. This will remove all the metaboxes for your custom taxonomies
function edit_taxonomy_args( $args, $tax_slug, $cptui_tax_args ) {
// Set to false for all taxonomies created with CPTUI.
$args['meta_box_cb'] = false;
return $args;
}
add_filter( 'cptui_pre_register_taxonomy', 'edit_taxonomy_args', 10, 3 );
@dgoze
dgoze / URL-Param-Shortcode.php
Created July 24, 2024 18:05
Use the [URLParam param='paramName'] shortcode to display GET parameters from the current URL
<?php // ignore this line - only for formatting
// Use the [URLParam param='paramName'] shortcode to display GET parameters from the current URL
function displayURLparam( $atts ) {
extract( shortcode_atts( array(
'param' => 'param',
), $atts ) );
return esc_attr(esc_html($_GET[$param]));
}

Three options to format US phone numbers

PHP
Using PHP to extract (substr) the phone number into separate parts, inject the separator and reassemble. Output with a shortcode

Loops and Logic
Use Loops and Logic's regex feature using capture groups to extract the parts, then insert separator when reassembling the capture groups before outputting the phone number.

Javascript
If you don't have control over the HTML, you can use JS to extract (slice) the phone number into separate parts, inject the separator and reassemble.

@dgoze
dgoze / custom_taxonomy_term_list.php
Created July 24, 2024 18:04 — forked from JiveDig/custom_taxonomy_term_list.php
Show list of terms from a custom taxonomy linked to their archive pages
<?php
add_action( 'genesis_before_loop', 'spears_do_resource_term_links' );
function spears_do_resource_term_links() {
// Show Custom Taxonomy
$args = array( 'taxonomy' => 'resource_type' );
$terms = get_terms('resource_type', $args);
@dgoze
dgoze / show_post_terms.php
Created July 24, 2024 18:03 — forked from JiveDig/show_post_terms.php
Show post terms with links - get_the_term_list
<?php
$language = wp_get_post_terms($post->ID, 'ft_language');
if( $language ) {
echo get_the_term_list( $post->ID, 'ft_language', '<li><span class="detail">Languages:</span>', ', ', '</li>' );
}