Programmatically adding images to media library

$image_url=”adress img”; $upload_dir = wp_upload_dir(); $image_data = file_get_contents( $image_url ); $filename = basename( $image_url ); if ( wp_mkdir_p( $upload_dir[‘path’] ) ) { $file = $upload_dir[‘path’] . “https://wordpress.stackexchange.com/” . $filename; } else { $file = $upload_dir[‘basedir’] . “https://wordpress.stackexchange.com/” . $filename; } file_put_contents( $file, $image_data ); $wp_filetype = wp_check_filetype( $filename, null ); $attachment = array( ‘post_mime_type’ => … Read more

Image Upload from URL

you can write a php script, or make your own plugin of this code here, i used it in one of my projects where i had to import a large number of images. first, get the image, and store it in your upload-directory: $uploaddir = wp_upload_dir(); $uploadfile = $uploaddir[‘path’] . “https://wordpress.stackexchange.com/” . $filename; $contents= file_get_contents(‘http://mydomain.com/folder/image.jpg’); … Read more

How do I get the avatar URL instead of an HTML IMG tag when using get_avatar?

Good news for WordPress versions 4.2+ Since version 4.2 the handy get_avatar_url() function, introduced as a feature request in ticket #21195 few years ago, now ships with the core: /** * Retrieve the avatar URL. * * @since 4.2.0 * * @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar … Read more

Filter to remove image dimension attributes?

Thanks all! The image_send_to_editor filter was the one I was looking for… thanks @t31os for pointing it out. Here’s my functions now. add_filter( ‘post_thumbnail_html’, ‘remove_thumbnail_dimensions’, 10 ); add_filter( ‘image_send_to_editor’, ‘remove_thumbnail_dimensions’, 10 ); function remove_thumbnail_dimensions( $html ) { $html = preg_replace( ‘/(width|height)=\”\d*\”\s/’, “”, $html ); return $html; } This removes inline dimension attributes from images retrieved … Read more

How do I disable responsive images in WP 4.4?

Here are few things you could try to remove the responsive image support in 4.4: /** * Disable responsive image support (test!) */ // Clean the up the image from wp_get_attachment_image() add_filter( ‘wp_get_attachment_image_attributes’, function( $attr ) { if( isset( $attr[‘sizes’] ) ) unset( $attr[‘sizes’] ); if( isset( $attr[‘srcset’] ) ) unset( $attr[‘srcset’] ); return $attr; … Read more

Restricting users to view only media library items they have uploaded?

You could always filter the media list using a pre_get_posts filter that first determines the page, and the capabilities of the user, and sets the author parameter when certain conditions are met.. Example add_action(‘pre_get_posts’,’users_own_attachments’); function users_own_attachments( $wp_query_obj ) { global $current_user, $pagenow; $is_attachment_request = ($wp_query_obj->get(‘post_type’)==’attachment’); if( !$is_attachment_request ) return; if( !is_a( $current_user, ‘WP_User’) ) return; … Read more

show hide image script after 4 seconds [closed]

If you had for example, <img src=”https://wordpress.stackexchange.com/questions/228932/rdp_banner.jpg” id=”logoimage”> You could just do… add_action(‘init’,’checkvisitcookie’); function checkvisitcookie() { if (isset($_COOKIE[‘firsttimevisit’])) {return;} setCookie(‘firsttimevisit’,’1′,100*365*24*60*60); add_action(‘wp_footer’,’fadelogoout’); } function fadelogoout() { echo “<script> jQuery(document).ready(function() { setTimeout(function() { jQuery(‘#logoimage’).fadeOut(); }, 5000); }); </script>”; } Just to make it almost relevant to WordPress 😉