Skip to content

Instantly share code, notes, and snippets.

View EvanHerman's full-sized avatar
🐈
Cats, Code, WordPress

Evan Herman EvanHerman

🐈
Cats, Code, WordPress
View GitHub Profile
@EvanHerman
EvanHerman / custom-function.php
Last active February 9, 2018 16:36
Timeline Express - Enable Announcement Date & Time Pickers
<?php
/**
* Add date/time picker field to Timeline Express announcements
*
* @param array $custom_field Array of custom fields to append to our announcements.
*/
function add_custom_fields_to_announcements( $custom_fields ) {
$custom_fields[] = array(
'name' => esc_html__( 'Announcement Date & Time', 'text-domain' ),
@EvanHerman
EvanHerman / custom-interior-image-timeline-express.php
Created May 18, 2016 21:54
Use a different image on the single announcement page, than what is used on the timeline.
/**
* Timeline Express Add Custom Metabox
* @param array $options Array of options for Timeline Express.
*/
function define_custom_excerpt_metabox( $options ) {
$announcement_custom_metabox = new_cmb2_box( array(
'id' => 'custom_meta',
'title' => __( 'Additional Announcement Meta', 'text-domain' ),
'object_types' => array( 'te_announcements' ), // Post type
'context' => 'advanced',
@EvanHerman
EvanHerman / enqueue_parent_styles_and_animate_css.php
Last active March 2, 2016 21:47
Enqueue Parent Theme Style + Animate.css from child theme root
<?php
add_action( 'wp_enqueue_scripts', 'my_enqueue_assets' );
function my_enqueue_assets() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'animate-css', get_stylesheet_directory_uri() . '/animate.min.css' );
}
@EvanHerman
EvanHerman / export-database-table-to-csv.php
Last active February 19, 2016 19:51
Export a database table to .CSV. Usage example found at the bottom of this file.
<?php
/**
* Export Class to help export a given database table to CSV.
*/
class TOOL_EXPORT_CLASS {
/*
* Export our forms
* @parameters
* @table_name the name of the table to export
@EvanHerman
EvanHerman / wp-admin-table-markup.html
Last active August 8, 2020 07:32
WordPress Dashboard Admin Table Markup
<table class="widefat fixed" cellspacing="0">
<thead>
<tr>
<th id="cb" class="manage-column column-cb check-column" scope="col"></th> <!-- this column contains checkboxes -->
<th id="columnname" class="manage-column column-columnname" scope="col"></th>
<th id="columnname" class="manage-column column-columnname num" scope="col"></th> <!-- "num" added because the column contains numbers -->
</tr>
</thead>
@EvanHerman
EvanHerman / functions.php
Created January 24, 2016 16:56
Localize the jquery datepicker in WordPress using the WP_Locale object
<?php
add_action( 'admin_enqueue_scripts', 'admin_print_js' );
public function admin_print_js() {
global $wp_locale;
//add the jQuery UI elements shipped with WP
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-datepicker' );
@EvanHerman
EvanHerman / create-admin-user.php
Created December 23, 2015 14:44
Programatically create an admin user (WordPress)
<?php
add_action('init', 'prefix_add_user');
function prefix_add_user() {
$username = 'username123';
$password = 'azerty321';
$email = 'example@example.com';
@EvanHerman
EvanHerman / enable-sorting-default-wp-taxonomies.php
Created December 11, 2015 19:39
Enable taxonomy sorting (tax_position) for default WordPress taxonomies (post - categories etc.)
<?php
/*
* Enable drag & drop sorting on default WordPress taxonomies (ie: categories) - (page/post)
*/
add_filter( 'register_taxonomy_args' , 'add_tax_position_support', 9999, 3 );
function add_tax_position_support( $args, $taxonomy, $object_type ) {
if( 'category' == $taxonomy ) {
$args['tax_position'] = true;
}
@EvanHerman
EvanHerman / enable-sorting-custom-taxonomies.php
Last active April 2, 2017 12:13
Enable taxonomy sorting (tax_position) for custom taxonomies
<?php
/*
* If you've registered a custom taxonomy to assign to one of your custom post types,
* you'll want to add an additional paprameter to the $args array
*
*/
// Register Custom Taxonomy
function custom_taxonomy() {
@EvanHerman
EvanHerman / Remove-stats-admin-widget.php
Last active December 1, 2015 14:11
Remove Easy Forms for MailChimp dashboard widgets for everyone but admins.
<?php
// when copying, do not include lines 1 & 2
// Create the function to use in the action hook
function yikes_remove_stats_dashboard_widget() {
// Check user capabilities
if( ! current_user_can( 'manage_options' ) ) {
// Remove the stats metabox
remove_meta_box( 'yikes_easy_mc_list_stats_widget', 'dashboard', 'normal' );
// Remove the list activity metabox