Skip to content

Instantly share code, notes, and snippets.

@imjjss
imjjss / gist:2834553
Created May 30, 2012 08:34
add media edit field
/**
* Add Photographer Name and URL fields to media uploader
*
* @param $form_fields array, fields to include in attachment form
* @param $post object, attachment record in database
* @return $form_fields, modified form fields
*/
function be_attachment_field_credit( $form_fields, $post ) {
$form_fields['be-photographer-name'] = array(
@imjjss
imjjss / gist:2828780
Created May 29, 2012 14:36
gallery fix
// Registers our function to filter default gallery shortcode
remove_shortcode('gallery');
add_shortcode('gallery', 'sandbox_gallery');
// Function to filter the default gallery shortcode
function sandbox_gallery($attr) {
global $post;
static $instance = 0;
$instance++;
@imjjss
imjjss / gist:2807890
Created May 27, 2012 11:30
attachment icons by minetype
function get_attachment_icons($echo = false){
$sAttachmentString = "<div class='documentIconsWrapper'> \n";
if ( $files = get_children(array( //do only if there are attachments of these qualifications
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'application/pdf', //MIME Type condition
))){
foreach( $files as $file ){ //setup array for more than one file attachment
$file_link = wp_get_attachment_url($file->ID); //get the url for linkage
@imjjss
imjjss / gist:2761835
Created May 21, 2012 11:07
modified file_gallery_content for find_post_div, may not use it
<?php
function media_gallery_content() {
global $post;
echo '<div id="fg_container">
<noscript>
<div class="error" style="margin: 0;">
<p>' . __ ( 'File Gallery requires Javascript to function. Please enable it in your browser.', 'file-gallery' ) . '</p>
</div>
</noscript>
@imjjss
imjjss / gist:2761828
Created May 21, 2012 11:02
modified file_gallery_check_attachment_originality for single post_id
<?php
add_action( 'admin_footer', 'file_gallery_check_attachment_originality' ));
function press_gallery_check_attachment_originality() {
$find_screen = - 1;
if (is_admin ()) {
$find_screen = ('upload' == get_current_screen ()->base) ? 1 : 0;
} else {
$find_screen = ('create' == xxx_view () || 'edit' == xxx_view ()) ? 1 : 0;
}
@imjjss
imjjss / gist:2758279
Created May 20, 2012 14:19
Find Posts Dialog Box
http://shibashake.com/wordpress-theme/find-posts-dialog-box
<?php
?>
<form name="plugin_form" id="plugin_form" method="post" action="">
<?php wp_nonce_field('plugin_nonce'); ?>
// Other form elements and code ...
<?php find_posts_div(); ?>
</form>
<?php
@imjjss
imjjss / gist:2758270
Created May 20, 2012 14:14
Media Library Menu Check
<?php
//http://shibashake.com/wordpress-theme/expand-the-wordpress-media-library-admin-panel
add_action('admin_init', 'init_media_plus');
function init_media_plus() {
// Only activate plugin for the Media Library page
if (strpos($_SERVER["REQUEST_URI"], "upload.php") === FALSE)
return;
@imjjss
imjjss / gist:2723589
Created May 18, 2012 06:39
Media Library Tabs
<?php
// add a tab
function modify_post_mime_types($post_mime_types) {
$post_mime_types['application/x-shockwave-flash'] = array('Flash', 'Manage Flash', 'Flash (%s)');
return $post_mime_types;
}
add_filter('post_mime_types', 'modify_post_mime_types');
//remove a tab by its type
@imjjss
imjjss / gist:2717067
Created May 17, 2012 06:49
change banner img using media gallery
<a href="media-upload.php?type=image&TB_iframe=true" class="thickbox" title="Select A Banner Image From Gallery" onclick="return false;" class="thickbox">
<img id="banner_image" src="<?php echo(htmlentities($banner_image)); ?>" width="450" height="25" />
</a>
<input type="hidden" id="banner_image_input" name="banner_image" value="<?php echo(htmlentities($banner_image)); ?>" />
<?php
/*
strip out everything but the image source and updates the form. First, the function eliminates all of the text returned except the image source. It then updates the banner image and the hidden input value that I am using in my form:
*/
function send_to_editor(html) {
@imjjss
imjjss / gist:2716576
Created May 17, 2012 05:09
add media form fields to a specific mime type
<? php
$post_mime_type = ( 'audio/mpeg' == get_post_mime_type( $post ) ) ? 1 : 0;
if( 1 == $post_mime_type ) {
$form_fields[...] = array(...);
}
?>