Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_featured_image_title( $post_id ) {
- $attachment_id = get_post_thumbnail_id( $post_id );
- if ( ! $attachment_id ) {
- return false;
- }
- $attachment_data = wp_get_attachment_metadata( $attachment_id );
- if ( ! isset( $attachment_data['image_meta']['title'] ) ) {
- return false;
- }
- return $attachment_data['image_meta']['title'];
- }
- function disable_empty_content_check( $maybe_empty, $postarr ) {
- if ( ! $maybe_empty ) {
- return $maybe_empty;
- }
- if ( 'showcase' !== $postarr['post_type'] ) {
- return $maybe_empty;
- }
- if ( wp_is_post_revision( $postarr['ID'] ) ) {
- return $maybe_empty;
- }
- if ( get_featured_image_title( $postarr['ID'] ) ) {
- $maybe_empty = false;
- }
- return $maybe_empty;
- }
- add_filter( 'wp_insert_post_empty_content', 'disable_empty_content_check', 10, 2 );
- function auto_populate_post_title( $data, $postarr ) {
- if ( 'showcase' !== $postarr['post_type'] ) {
- return $data;
- }
- if ( wp_is_post_revision( $postarr['ID'] ) ) {
- return $data;
- }
- $featured_image_title = get_featured_image_title( $postarr['ID'] );
- if ( ! $data['post_title'] && $featured_image_title ) {
- $data['post_title'] = $featured_image_title;
- }
- return $data;
- }
- add_filter( 'wp_insert_post_data', 'auto_populate_post_title', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment