WordPress.org

Make WordPress Core

Ticket #40922: 40922.7.diff

File 40922.7.diff, 3.8 KB (added by flixos90, 4 years ago)
  • src/wp-includes/capabilities.php

     
    440440                else
    441441                        $caps[] = 'do_not_allow';
    442442                break;
    443         case 'customize' :
    444                 $caps[] = 'edit_theme_options';
    445                 break;
    446443        case 'delete_site':
    447444                if ( is_multisite() ) {
    448445                        $caps[] = 'manage_options';
     
    862859
    863860        return $allcaps;
    864861}
     862
     863/**
     864 * Filters the user capabilities to grant the 'customize' capability as necessary.
     865 *
     866 * A user must have the 'edit_theme_options' capability for it to be granted.
     867 *
     868 * @since 4.9.0
     869 *
     870 * @param array $allcaps An array of all the user's capabilities.
     871 * @return array Filtered array of the user's capabilities.
     872 */
     873function wp_maybe_grant_customize_cap( $allcaps ) {
     874        if ( ! empty( $allcaps['edit_theme_options'] ) ) {
     875                $allcaps['customize'] = true;
     876        }
     877
     878        return $allcaps;
     879}
     880
     881/**
     882 * Filters the user capabilities to grant customize changeset capabilities as necessary.
     883 *
     884 * The capabilities are granted based on whether the user can 'customize'.
     885 *
     886 * @since 4.9.0
     887 *
     888 * @param array $allcaps An array of all the user's capabilities.
     889 * @return array Filtered array of the user's capabilities.
     890 */
     891function wp_maybe_grant_customize_changesets_caps( $allcaps ) {
     892        if ( ! empty( $allcaps['customize'] ) ) {
     893                $post_type = get_post_type_object( 'customize_changeset' );
     894                foreach ( get_object_vars( $post_type->cap ) as $post_cap => $changeset_cap ) {
     895                        if ( '_posts' === substr( $post_cap, -6 ) ) {
     896                                $allcaps[ $changeset_cap ] = true;
     897                        }
     898                }
     899        }
     900
     901        return $allcaps;
     902}
  • src/wp-includes/default-filters.php

     
    514514
    515515// Capabilities
    516516add_filter( 'user_has_cap', 'wp_maybe_grant_install_languages_cap', 1 );
     517add_filter( 'user_has_cap', 'wp_maybe_grant_customize_cap', 1 );
     518add_filter( 'user_has_cap', 'wp_maybe_grant_customize_changesets_caps', 10 );
    517519
    518520unset( $filter, $action );
  • src/wp-includes/post.php

     
    176176                'delete_with_user' => false,
    177177                'supports' => array( 'title', 'author' ),
    178178                'capability_type' => 'customize_changeset',
    179                 'capabilities' => array(
    180                         'create_posts' => 'customize',
    181                         'delete_others_posts' => 'customize',
    182                         'delete_post' => 'customize',
    183                         'delete_posts' => 'customize',
    184                         'delete_private_posts' => 'customize',
    185                         'delete_published_posts' => 'customize',
    186                         'edit_others_posts' => 'customize',
    187                         'edit_post' => 'customize',
    188                         'edit_posts' => 'customize',
    189                         'edit_private_posts' => 'customize',
    190                         'edit_published_posts' => 'do_not_allow',
    191                         'publish_posts' => 'customize',
    192                         'read' => 'read',
    193                         'read_post' => 'customize',
    194                         'read_private_posts' => 'customize',
    195                 ),
    196179        ) );
    197180
    198181        register_post_status( 'publish', array(
     
    29642947 *     @type string $guid                  Global Unique ID for referencing the post. Default empty.
    29652948 *     @type array  $post_category         Array of category names, slugs, or IDs.
    29662949 *                                         Defaults to value of the 'default_category' option.
    2967  *     @type array  $tags_input            Array of tag names, slugs, or IDs. Default empty. 
     2950 *     @type array  $tags_input            Array of tag names, slugs, or IDs. Default empty.
    29682951 *     @type array  $tax_input             Array of taxonomy terms keyed by their taxonomy name. Default empty.
    29692952 *     @type array  $meta_input            Array of post meta values keyed by their post meta key. Default empty.
    29702953 * }