comment demander une image avant de pouvoir publier un article wordpress

Solutions on MaxInterview for comment demander une image avant de pouvoir publier un article wordpress by the best coders in the world

showing results for - "comment demander une image avant de pouvoir publier un article wordpress"
Melina
30 Apr 2017
1<?php
2add_action('save_post', 'wpds_check_thumbnail');
3add_action('admin_notices', 'wpds_thumbnail_error');
4function wpds_check_thumbnail($post_id) {
5    // change to any custom post type
6    if(get_post_type($post_id) != 'post')
7        return;
8    if ( !has_post_thumbnail( $post_id ) ) {
9        // set a transient to show the users an admin message
10        set_transient( "has_post_thumbnail", "no" );
11        // unhook this function so it doesn't loop infinitely
12        remove_action('save_post', 'wpds_check_thumbnail');
13        // update the post set it to draft
14        wp_update_post(array('ID' => $post_id, 'post_status' => 'draft')); 
15        add_action('save_post', 'wpds_check_thumbnail');
16    } else {
17        delete_transient( "has_post_thumbnail" );
18    }
19}
20function wpds_thumbnail_error()
21{
22    // check if the transient is set, and display the error message
23    if ( get_transient( "has_post_thumbnail" ) == "no" ) {
24        echo "<div id='message' class='error'><p><strong>You must select Featured Image. Your Post is saved but it can not be published.</strong></p></div>";
25        delete_transient( "has_post_thumbnail" );
26    } 
27}
28?>
similar questions