Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Navarro, Jr. dnavarrojr

View GitHub Profile
@dnavarrojr
dnavarrojr / ffprobe.sh
Last active Apr 3, 2020
Using FFPROBE to Create JSON files
View ffprobe.sh
#!/bin/bash
folder="/var/www/{website}/wp-content/uploads/video"
for filename in $folder/*.mov; do
if [ -f $filename ]; then
ffprobe -hide_banner -v quiet -print_format json -show_format -show_streams $filename > $folder/$(basename -s .mov $filename).json
fi
done
for filename in $folder/*.mp4; do
if [ -f $filename ]; then
ffprobe -hide_banner -v quiet -print_format json -show_format -show_streams $filename > $folder/$(basename -s .mp4 $filename).json
@dnavarrojr
dnavarrojr / wp-body_class.php
Last active Dec 18, 2019
Attempt to add a CLASS to the BODY tag in WordPress, not working.
View wp-body_class.php
<?php
add_filter( 'body_class', function( $classes ) {
$restrict_page = ( get_field( 'msp_registration_required' ) ? true : false );
error_log( "before count = " . count( $classes ) );
if ( $restrict_page ) {
$classes[] = 'msp-restrict-page';
}
error_log( "after count = " . count( $classes ) );
return $classes;
} );
@dnavarrojr
dnavarrojr / .bashrc
Created Sep 25, 2019
My BASH Aliases
View .bashrc
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
@dnavarrojr
dnavarrojr / wp-cpt-ui-mods.php
Created Jan 17, 2019
Custom Post Type modify the UI
View wp-cpt-ui-mods.php
<?php
function tscpl_pb_edit_titles( $title ) {
$screen = get_current_screen();
switch ( $screen->post_type ) {
case 'event':
case 'eventsregistration':
case 'eventsapi':
@dnavarrojr
dnavarrojr / monthly.php
Created Dec 11, 2018
Generate recurring monthly dates
View monthly.php
// 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 / submenu.php
Created Dec 4, 2018
Trouble Loading datepicker in WordPress
View submenu.php
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 / array-sorting.php
Created Dec 3, 2018
PHP Sort an Array of Arrays by Key
View array-sorting.php
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 / acf_href.php
Created Aug 7, 2018
Create an HREF link with a shortcode using ACF fields
View acf_href.php
<?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 / sort_cpt.php
Created Jul 30, 2018
WordPress Sort CPT by Date and Time
View sort_cpt.php
$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 / recurring.php
Last active Dec 17, 2018
Recurring Weekly Array
View recurring.php
function tscpl_recurring_weekly( $start_date, $dow, $count ) {
$days = array(
'sunday' => 0,
'monday' => 1,
'tuesday' => 2,
'wednesday' => 3,
'thursday' => 4,
'friday' => 5,
'saturday' => 6