Created
March 9, 2017 21:55
-
-
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
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_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; | |
| } |
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 | |
| /** | |
| * 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