This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove specified keys from an array. | |
* | |
* @param array &$array The reference to the array to be modified | |
* @param array $keys An array of keys to be removed | |
* @return void | |
*/ | |
function remove_array_keys( &$array, $keys ) { | |
foreach( $array as $key => &$value ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Check if an array is a multidimensional array. | |
* | |
* @param array $arr The array to check | |
* @return boolean Whether the the array is a multidimensional array or not | |
*/ | |
function is_multi_array( $x ) { | |
if( count( array_filter( $x,'is_array' ) ) > 0 ) return true; | |
return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Create an associative array from a csv file. | |
* | |
* @param file $file The csv file that is going to be parsed | |
* @return array $data An associative array with the csv headings as keys | |
*/ | |
function csv_to_array( $file ) { | |
$data = array(); | |
$header = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Create an array of an attachment image's data. | |
* | |
* @param int $id The id of the attachment image | |
* @return array $image An array of all the image data | |
*/ | |
function wp_get_attachment_image_data( $id=null ) { | |
$image = array(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Create a custom length excerpt. | |
* | |
* @param integer $limit How many words you want returned | |
* @return string $content The content string | |
*/ | |
function wp_excerpt_length( $limit=50 ) { | |
$content = get_the_content(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ACF Load Field Choices. | |
* | |
* @param array $field The field that we are going to add options to | |
* @return array $field The field we modified | |
*/ | |
function acf_load_field_choices( $field ) { | |
// Reset choices | |
$field['choices'] = array(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add a blank option to a Gravity Forms dropdown | |
* | |
* @param object $form The Gravity Form | |
* @return object $form The modified Gravity Form | |
*/ | |
function wp_gravity_forms_add_empty_dropdown_option( $form ) { | |
// Select the correct form, then set the id of the field(s) we need to change | |
if( $form['id'] == 1 ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function saveFile(url) { | |
var filename = url.substring(url.lastIndexOf("/") + 1).split("?")[0]; | |
var xhr = new XMLHttpRequest(); | |
xhr.responseType = 'blob'; | |
xhr.onload = function() { | |
var a = document.createElement('a'); | |
a.href = window.URL.createObjectURL(xhr.response); | |
a.download = filename; | |
a.style.display = 'none'; | |
document.body.appendChild(a); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* For Themes */ | |
wp_enqueue_style('slug', get_template_directory_uri().'/css/slug.css', array(), filemtime(get_template_directory().'/css/slug.css')); | |
wp_enqueue_script('slug', get_template_directory_uri().'/js/slug.js', array(), filemtime(get_template_directory().'/js/slug.js')); | |
/* For Plugins */ | |
wp_enqueue_style('slug', plugin_dir_url(__FILE__).'css/slug.css', array(), filemtime(plugin_dir_path(__FILE__).'css/slug.css')); | |
wp_enqueue_script('slug', plugin_dir_url(__FILE__).'js/slug.js', array(), filemtime(plugin_dir_path(__FILE__).'js/slug.js')); |