Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Created March 9, 2017 21:55
Show Gist options
  • Select an option

  • Save igorbenic/11c1bf2515bab2833bec5777c5692024 to your computer and use it in GitHub Desktop.

Select an option

Save igorbenic/11c1bf2515bab2833bec5777c5692024 to your computer and use it in GitHub Desktop.
Extending the WordPress Media Uploader: Sending HTML to Editor | http://www.ibenic.com/extending-wordpress-media-uploader-sending-html-to-editor
<?php
add_filter( 'media_send_to_editor', 'ibenic_media_send_to_editor', 10, 3 );
/**
* Changing the HTML to the editor
* @param string $html
* @param number $id
* @param array $attachment
* @return string
*/
function ibenic_media_send_to_editor( $html, $id, $attachment ) {
if( isset( $attachment['loggedIn'] ) && $attachment['loggedIn'] == true ) {
$html = '[only-logged-in-image]' . $html . '[/only-logged-in-image]';
}
return $html;
}
<?php
/**
* Shortcode for Only Logged In Images
* @param array $atts
* @param string $content
* @return string
*/
function only_logged_in_image( $atts, $content = null ) {
$user_id = get_current_user_id();
if( $user_id > 0 ) {
return apply_filters( 'only_logged_in_image', $content, $user_id );
}
return false;
}
add_shortcode( 'only-logged-in-image', 'only_logged_in_image' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment