Skip to content

Instantly share code, notes, and snippets.

View dnavarrojr's full-sized avatar

Dave Navarro, Jr. dnavarrojr

View GitHub Profile
@dnavarrojr
dnavarrojr / acf-dave.php
Created April 12, 2018 23:55
ACF action "acf/input/admin_footer" not working with get_field_objects()
<?php
function dave_acf_code_master_footer() {
$id = get_the_ID();
$field = get_field_object( 'code_type', $id );
$field_label = esc_attr( 'acf-' . $field['key'] );
?>
<script type="text/javascript">
jQuery( document ).ready( function() {
function setEditorCodeType() {
var editor = ace.edit( jQuery(".editor")[0] );
@dnavarrojr
dnavarrojr / tscpl-cpt.php
Created April 30, 2018 21:52
WordPress Registered Post Type Capabilities
<?php
/*
Plugin Name: TSCPL CPT Test
*/
function tscpl_register_teamrooms_cpt() {
/**
* Post Type: Team Rooms.
*/
@dnavarrojr
dnavarrojr / sort_cpt.php
Created July 30, 2018 13:31
WordPress Sort CPT by Date and Time
$args = array(
'post_type' => 'eventsapi',
'numberposts' => -1,
'meta_query' => array(
'event_date' => array( 'key' => 'event_date', 'value' => $date, 'compare' => '=' ),
'event_time' => array(
'relation' => 'OR',
array( 'key' => 'event_start', 'compare' => 'EXISTS' ),
array( 'key' => 'event_start', 'compare' => 'NOT EXISTS' ),
),
@dnavarrojr
dnavarrojr / acf_href.php
Created August 7, 2018 22:41
Create an HREF link with a shortcode using ACF fields
<?php
/*****************************************************************************************************************************************************
*
* Usage: [acf_href href_before="mailto:" href="acf:field_name" text="acf:field_name"]
*
* acf:fieldname will retrieve the value of the specified "fieldname" and use that.
* get:url_variable will grab a variable from the URL and use that.
*
* [acf_href href="acf:my_link" text="Link to web site"]
@dnavarrojr
dnavarrojr / array-sorting.php
Created December 3, 2018 18:49
PHP Sort an Array of Arrays by Key
function array_sort_by_key( $array, $key ) {
$compare = make_key_cmp( $key );
usort( $array, $compare );
return $array;
}
function make_key_cmp( $key ) {
$code = "if (\$a['$key'] == \$b['$key']) return 0;";
$code .= "return (\$a['$key'] < \$b['$key']) ? -1 : 1;";
return create_function( '$a,$b', $code );
@dnavarrojr
dnavarrojr / submenu.php
Created December 4, 2018 11:44
Trouble Loading datepicker in WordPress
function export_menu_scripts( $hook ) {
if ( $hook == 'admin_page_export-submenu' ) {
// load our scripts
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_style('jquery-ui', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
}
}
add_action( 'admin_enqueue_scripts', 'export_menu_scripts' );
@dnavarrojr
dnavarrojr / monthly.php
Created December 11, 2018 14:21
Generate recurring monthly dates
// returns an array with the dates for a recurring monthly rule
$dates = tscpl_recurring_monthly( $start_date, $end_date, 'fourth', 'tuesday );
function tscpl_recurring_weekly( $start_date, $end_date = null, $dow ) {
$days = array(
'sunday' => 0,
'monday' => 1,
'tuesday' => 2,
@dnavarrojr
dnavarrojr / recurring.php
Last active December 17, 2018 21:04
Recurring Weekly Array
function tscpl_recurring_weekly( $start_date, $dow, $count ) {
$days = array(
'sunday' => 0,
'monday' => 1,
'tuesday' => 2,
'wednesday' => 3,
'thursday' => 4,
'friday' => 5,
'saturday' => 6
@dnavarrojr
dnavarrojr / wp-cpt-ui-mods.php
Created January 17, 2019 18:38
Custom Post Type modify the UI
<?php
function tscpl_pb_edit_titles( $title ) {
$screen = get_current_screen();
switch ( $screen->post_type ) {
case 'event':
case 'eventsregistration':
case 'eventsapi':
@dnavarrojr
dnavarrojr / .bashrc
Created September 25, 2019 22:59
My BASH Aliases
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias aliases='nano ~/.bashrc'
alias realias='. ~/.bashrc'
alias ls="ls -ahl --color=never --group-directories-first"
alias del=rm
alias cls=clear