Skip to content

Instantly share code, notes, and snippets.

<?php
// Adds tiny MCE editor to excerpt
function tinymce_excerpt_js(){
$post_type= get_post_type();
if ($post_type != "shop_order") {?>
<script type="text/javascript">
jQuery(document).ready( tinymce_excerpt );
function tinymce_excerpt() {
jQuery("#excerpt").addClass("mceEditor");
tinyMCE.execCommand("mceAddControl", false, "excerpt");
@brettshumaker
brettshumaker / am_I_doing_it_wrong
Created June 11, 2014 13:46
WordPress - storing array of values in custom post type custom meta field
<?php
// This is essentially what I have adding the post meta field, not doing this from the edit post screen.
$name_meta['first-name'] = "Joe";
$name_meta['middle-name'] = "D.";
$name_meta['last-name'] = "Schmoe";
$name_meta['suffix'] = "Jr.";
update_post_meta($post->ID, '_staff_member_name', $name_meta);
// update_post_meta automatically serializes the array when adding it to the database
@brettshumaker
brettshumaker / add-sortable-column.php
Created April 24, 2012 00:16
WP Custom Sortable Columns
<?php
//-----Add sortable columns
function sortable_column_func(){
return array(
'my_sortable_variable' => 'my_sortable_variable',
);
}
add_filter("manage_edit-POST_TYPE_NAME_sortable_columns", "sortable_column_func");
@brettshumaker
brettshumaker / Facebook-Share.php
Created July 4, 2012 17:56
Facebook Share button for TubePress
<?php $the_url = 'http://www.youtube.com/watch?v='.$video->getId(); ?>
<div class="facebookShare">
<script type="text/javascript">
function fbs_click() {
u=<?php echo $the_url ?>;
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
return false;
}
@brettshumaker
brettshumaker / Image-Carousel.js
Created October 23, 2012 21:46
JS Image Carousel w/Thumb Overlay
@brettshumaker
brettshumaker / vimeo.php
Created January 23, 2013 15:15
Uses the Vimeo Simple API to download all videos from a Vimeo channel and outputs them in 'pages.'
<?php
/**
* Gets and displays paginated Vimeo videos from a Vimeo channel.
* Replace 'YOUR_CHANNEL_NAME' with the channel you want to pull from.
*
* Accepts 4 Values and Returns 1
*
* @param string $channel_name Name of the Vimeo channel
* @param array $excluded_videos Array of video ID's to exclude from the output
@brettshumaker
brettshumaker / show-included-files-widget.php
Created May 12, 2013 13:41
Adds a Dashboard widget that displays all included theme files. Useful for tracking down bugs because you can see every file that's being loaded in the admin.
function add_show_inc_file_widget() {
wp_add_dashboard_widget('included-files', 'Show Included Theme Files', 'show_included_theme_files');
}
add_action('wp_dashboard_setup', 'add_show_inc_file_widget' );
function show_included_theme_files(){
$included_files = get_included_files();
foreach ($included_files as $filename) {
if (strpos($filename, "THEME-FOLDER-NAME")) echo $filename."<br />";
}
@brettshumaker
brettshumaker / Plugin-dev-links
Last active December 21, 2015 20:28
Plugin Dev Links
@brettshumaker
brettshumaker / loop-rows-cols.php
Created April 22, 2016 13:35
This is some boilerplate code to take the content of a WP Query and split the posts into relatively evenly distributed rows and columns.
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
);
$posts_loop = new WP_Query( $args );
if ( $posts_loop->have_posts() ) :
// Initialize Output
$output = '';
@brettshumaker
brettshumaker / edd-remote-license-check-variable-price-name.php
Created July 11, 2016 15:48
Filter to add variable price name to an EDD Software License remote license check
<?php
add_filter( 'edd_remote_license_check_response', 'bsgist_add_data_to_license_check', 10, 3 );
function bsgist_add_data_to_license_check( $json, $args, $license_id ) {
$price_id = get_post_meta( $license_id, '_edd_sl_download_price_id', true );
$download_id = edd_software_licensing()->get_download_id( $license_id );
$download_variable_prices = get_post_meta($download_id, 'edd_variable_prices', true);
$json['account_level'] = $download_variable_prices[$price_id]['name'];