Skip to content

Instantly share code, notes, and snippets.

@mangesh
Last active December 12, 2016 12:42
Show Gist options
  • Select an option

  • Save mangesh/66116130398b8a136458cbf7cc3d736b to your computer and use it in GitHub Desktop.

Select an option

Save mangesh/66116130398b8a136458cbf7cc3d736b to your computer and use it in GitHub Desktop.
Add custom field in activity page and display the value submitted in the custom field in lightbox
<?php
function rtmedia_uploader_before_start_upload_button_callback() {
global $rtmedia_media;
?> <div> city :<input class="rtmedia_city" id="rtmedia_city" type="text" name="city" value="" /> </div>
<?php
}
add_action('rtmedia_uploader_before_start_upload_button', 'rtmedia_uploader_before_start_upload_button_callback');
function wp_ajax_rtmedia_add_city_to_media_callback(){
if( ! function_exists( 'update_rtmedia_meta' ) ) {
die();
}
$media_id = ( !empty( $_POST['media_id'] ) ) ? wp_strip_all_tags( $_POST['media_id'] , true ) : false;
$media_id = filter_var( $media_id , FILTER_SANITIZE_NUMBER_INT);
$city = ( !empty( $_POST['city'] ) ) ? wp_strip_all_tags( $_POST['city'], true ) : false;
if( $media_id && $city ){
update_rtmedia_meta( $media_id, 'city', $city );
}else{
die( "error" );
}
}
add_action( 'wp_ajax_rtmedia_add_city_to_media', 'wp_ajax_rtmedia_add_city_to_media_callback' );
add_action( 'wp_ajax_nopriv_rtmedia_add_city_to_media', 'wp_ajax_rtmedia_add_city_to_media_callback' );
function rtmedia_actions_before_description_callback( $media_id ) {
if( ! function_exists( 'get_rtmedia_meta' ) ) {
return;
}
if( $media_id ){
$city = get_rtmedia_meta( $media_id, 'city' );
if( !empty( $city ) ){ ?>
<div class="rtmedia-media-city">
<span>City: <?php echo $city; ?></span>
</div>
<?php
}
}
}
add_action('rtmedia_actions_before_description', 'rtmedia_actions_before_description_callback', 100, 1);
function rtmedia_uploader_before_start_upload_button_script() {
?>
<script type="text/javascript">
if ( undefined !== window.jQuery ) {
jQuery( 'document' ).ready( function( $ ) {
rtMediaHook.register( 'rtmedia_js_after_file_upload', function( $args ) {
var rtmedia_city = jQuery( "#rtmedia_city" ).val();
if( $args[2] && rtmedia_city ){
jQuery.ajax({
type: "POST",
url: rtmedia_ajax_url,
data: {
action: 'rtmedia_add_city_to_media',
media_id: $args[2],
city: rtmedia_city,
},
success : function(data){
}
});
}
});
});
}
</script>
<?php
}
add_action( 'wp_footer', 'rtmedia_uploader_before_start_upload_button_script' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment