WordPress.org

Make WordPress Core

Ticket #30352: 30352.patch

File 30352.patch, 1.3 KB (added by mrahmadawais, 7 years ago)

prevent_front_page_delete_by_editor function added to wp-includes/pluggable.php

  • wp-includes/pluggable.php

     
    22932293}
    22942294endif;
    22952295
     2296if ( !function_exists( 'prevent_front_page_delete_by_editor' ) ) :
     2297/**
     2298 * If a front page is set then this function prevents an editor user roles from deleting it.
     2299 * @param  array $allcaps an array of all the capabilities, each one set to true or false
     2300 * @param  array $caps    an array of the capabilities being requested by the current operation
     2301 * @param  array $args    an array of arguments relevant to this operation
     2302 */
     2303function prevent_front_page_delete_by_editor( $allcaps, $caps, $args ) {
     2304
     2305        if (isset($args[0]) && isset($args[2]) && $args[0] == 'delete_post') {
     2306            $post = get_post ($args[2]);
     2307
     2308            //Checkt if the page is published and user it not admin i.e. Editor
     2309            if ($post->post_status == 'publish' && $post->post_type == 'page' && !current_user_can( 'manage_options' )) {
     2310                if ( $post->ID == get_option('page_on_front') )
     2311                    $allcaps[$caps[0]] = false;
     2312            }
     2313        }
     2314    return $allcaps;
     2315}
     2316add_filter ('user_has_cap', 'prevent_front_page_delete_by_editor', 10, 3);
     2317endif;
     2318 No newline at end of file