WordPress file upload only from computer
This code snippet can be useful for developing your WordPress plugins.. For the code snippet to work, add it to the function.php file.
Code Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
add_filter('media_upload_tabs','wpse13567_media_upload_tabs', 99); function wpse13567_media_upload_tabs( $tabs ) { if ( wpse13567_post_has_attachments() ) { unset( $tabs['type'] ); } unset( $tabs['type_url'] ); unset( $tabs['library'] ); return $tabs; } add_filter( 'media_upload_default_tab', 'wpse13567_media_upload_default_tab' ); function wpse13567_media_upload_default_tab( $tab ){ if ( wpse13567_post_has_attachments() ) { return 'gallery'; } return $tab; } function wpse13567_post_has_attachments(){ static $post_has_attachments = null; if ( null === $post_has_attachments && $post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : false) ) { $post_has_attachments = count(get_posts("post_type=attachment&post_parent={$post_id}"))>0; } return $post_has_attachments; } |
Code checked, works great.
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.