Validate Uploaded Image using WordPress’ Built-in Functions?

All of the code in your question can be replaced with: require_once( ABSPATH . ‘wp-admin/includes/image.php’ ); require_once( ABSPATH . ‘wp-admin/includes/file.php’ ); require_once( ABSPATH . ‘wp-admin/includes/media.php’ ); if ( $_FILES ) { foreach ($_FILES as $file => $array) { $image_post_id = media_handler_upload( $file ); if ( is_wp_error( $image_post_id ) ) { $error .= $image_post_id->get_error_message(); } else … Read more

Plupload resize for worpdress

I’ve done a Plupload using the Front End. The WordPress Plupload is very customised, so I’ve implemented from the scratch as a Plugin. I’ll show an example using functions.php Download the Plupload from http://www.plupload.com/download/ and put in your theme inside a js/thirdparty/plupload/{all_files} Code to use on functions.php //Plupload File wp_enqueue_script( ‘plupload’, get_template_directory_uri() . ‘/js/thirdparty/plupload/js/plupload.full.min.js’, array( … Read more

How to show only posts with images?

No need for post IDs what has no thumbnail. Use meta query to get only those what has thumbnail. Add meta query function get_only_posts_with_images( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘meta_query’, array( array( ‘key’ => ‘_thumbnail_id’ ) ) ); } } add_action( ‘pre_get_posts’, ‘get_only_posts_with_images’ ); Or use custom query. $query … Read more

Featured image (responsive) above content is too small after update to WordPress 4.4

How can the global $content_width affect the post thumbnail ? Let’s check how the global $content_width can affect the output of the_post_thumbnail( ‘large’ ) and trace out the relevant function dependencies: the_post_thumbnail() \ \__ get_the_post_thumbnail() \ \__ wp_get_attachment_image() \ \__ wp_get_attachment_image_src() \ \__ image_downsize() \ \__ image_constrain_size_for_editor() and for the large size we have specifically … Read more

Get Meta from Custom Field of Image URL

I can already tell that you’re using ACF – if you don’t want to change the return settings for the field, you can bypass ACF and just pull the image ID directly from post meta: $image_url = get_field( ‘my_field_name’ ); $image_id = get_post_meta( $post->ID, ‘my_field_name’, true ); $image_meta = wp_get_attachment_metadata( $image_id );

Count total number of images in post and echo results as number

Use regex to find all the urls and filter by type. $post = get_post( 504 ); $content = $post->post_content; // match all urls preg_match_all( ‘/(http:|https:)?\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/’, $content, $matches ); $count = 0; if ( ! empty( $matches ) && ! empty( $matches[ 0 ] ) ) { foreach ( $matches[ 0 ] as $url ) { … Read more