Make WordPress Core

Opened 4 years ago

Closed 10 months ago

#57379 closed defect (bug) (fixed)

A Way to Disable Export Theme

Reported by: unsalkorkmaz Owned by: audrasjb
Priority: normal Milestone: 6.9
Component: Administration Version: 6.1.1
Severity: normal Keywords: has-unit-tests has-patch commit gutenberg-merge
Cc: Focuses:

Description

related Github issue;
https://github.com/WordPress/gutenberg/issues/46661

## What problem does this address?
This button tries to zip my whole theme which as node_modules with 500MB content:
https://user-images.githubusercontent.com/207720/208480389-b2929241-76de-4d24-89fb-94be7223d039.png

Here is the video:
https://www.youtube.com/watch?v=9F1LtmMrjsY
You can see CPU spike in right macos m1 menu..

And lets say I want to show a demo for my premium theme.. Why would I want a download button?

## What is your proposed solution?
I need a way to disable this.

Change History (27)

This ticket was mentioned in PR #6966 on WordPress/wordpress-develop by @rajinsharwar.


2 years ago
#1

  • Keywords has-patch added

Fixing issue with node_modules not getting ignored while in sub-directory and adding new filter for permission capability for Export button. New filter "allowed_user_role_to_export_theme" added to add control over the permission callback of that Export Functionality.

https://github.com/WordPress/wordpress-develop/assets/68213636/371cb20e-365c-4d2e-8e21-d71361dc0f00

Trac ticket: https://core.trac.wordpress.org/ticket/57379

#2 @rajinsharwar
2 years ago

  • Milestone Awaiting Review6.7
  • Summary A Way to Disable Export ThemeNode Modules in sub-directories not getting ignored while exporting the theme, and a way to disable the theme export

I have fixed the issue where node_modules were not ignored in the subdirectories.

Also now, anyone can create a new user capability, and using the new filter "allowed_user_role_to_export_theme", use that to add restrictions over that Export Functionality. Something like this:

add_filter( 'allowed_user_role_to_export_theme', function( $role ){
        $role = 'my_custom_user_capability';
        return $role;
} );

In this way, instead of the default capability "edit_theme_options", the "my_custom_user_capability" will be used while checking for permissions.

Also, updated the title of the ticket to mention the change about node_modules. Slating for 6.7 release.

#3 @rajinsharwar
2 years ago

  • Keywords needs-unit-tests added

#4 @peterwilsoncc
2 years ago

@rajinsharwar I think these should be seperate tickets, one to ignore the node modules and one to discuss the need for a new filter.

#5 @rajinsharwar
2 years ago

  • Summary Node Modules in sub-directories not getting ignored while exporting the theme, and a way to disable the theme exportA Way to Disable Export Theme

@peterwilsoncc Reverted the node_modules change, so that we can discuss about the new filter in thic ticket.

#6 @rajinsharwar
2 years ago

New ticket created for the Node Modules issue: #61575

#7 @peterwilsoncc
2 years ago

Thanks @rajinsharwar.

WordPress includes an export capability that controls the ability of users to export the contents of a site. With the introduction of the Site Editor, this also includes the posts and images used for customizing a theme.

As exporting a theme includes exporting these post types and combining them with the existing theme, I am wondering if the appropriate change for the exporting of themes from the site editor is to also use the export capability.

#8 @rajinsharwar
2 years ago

@peterwilsoncc Yeah, maybe we can just change that to the default export cap. Pushed that!

#9 @Mamaduka
2 years ago

Using the export capability makes sense; a user is exporting Site Editor content.

The client-side code should also be able to check if a user can perform an export action and show/hide menu items based on this.

This could be done by adding action to the theme responses.

Example from posts controller - https://github.com/WordPress/wordpress-develop/blob/74e03e3cbef2f2565028f446c76acb2dabf749bd/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2201-L2203

#10 @TimothyBlynJacobs
2 years ago

I think ideally this would end up getting exposed by the client doing an OPTIONS or HEAD request to the export endpoint.

I think a link would also be a good idea. But instead of an action link, we could link to the export endpoint using a rel like w:export-theme if the theme is a block theme, and include an appropriate targetHint.

#11 @Mamaduka
2 years ago

@TimothyBlynJacobs, I suggest a link because export doesn't really fit into CRUD actions that API usually checks via OPTIONS or HEAD requests.

This ticket was mentioned in Slack in #core by chaion07. View the logs.


2 years ago

This ticket was mentioned in Slack in #core by chaion07. View the logs.


2 years ago

This ticket was mentioned in Slack in #core-test by sppramodh. View the logs.


22 months ago

#16 @peterwilsoncc
22 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed
  • Milestone 6.76.8
  • Severity majornormal
  • Status newreopened

I've reopened this as the ticket is focusing on changing the permissions for allowing export, which needs implementation in both the UI and the API endpoint.

As there hasn't been any progress for a while, I've moved this off the 6.7 milestone.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


19 months ago

@audrasjb commented on PR #6966:


19 months ago
#18

I committed the change proposed by Peter.

#19 @desrosj
18 months ago

+1 from me to use export capability.

@Mamaduka what is required on the editor side to properly support this change. Is it too late to include in 6.8?

If so, let's punt this now and get the required changes ready for 6.9.

#20 @Mamaduka
18 months ago

Definitely doable for 6.8. Here's a draft PR for the client code changes - https://github.com/WordPress/gutenberg/pull/69107.

PR implements permission check via OPTIONS request and canUser selector.

I think a link would also be a good idea. But instead of an action link, we could link to the export endpoint using a rel like w:export-theme if the theme is a block theme, and include an appropriate targetHint.

@TimothyBlynJacobs, do you have an example of this? I don't think I've seen a similar pattern before. If my proposed canUser resolve changes aren't viable, we could use it as an alternative.

Last edited 18 months ago by Mamaduka (previous) (diff)

#21 @audrasjb
18 months ago

  • Keywords commit added
  • Owner set to audrasjb
  • Status reopenedreviewing

Self assigning for final review and commit.

#22 @audrasjb
18 months ago

  • Resolutionfixed
  • Status reviewingclosed

In 59924:

Editor: Use the export cap to determine whether users can export themes.

This changeset replaces edit_theme_options with the export capability to determine whether the current user can export themes. That condition determines whether to show the Export Theme button in the Site Editor. Using export capability makes it more consistent with general export capabilities across the administration.

Props unsalkorkmaz, rajinsharwar, audrasjb, peterwilsoncc, desrosj, Mamaduka, TimothyBlynJacobs.
Fixes #57379.

@Mamaduka commented on PR #8770:


16 months ago
#24

@audrasjb, since you're the owner of the original ticket, would you prefer to reopen it, or should I create a new one?

I plan to add some basic unit tests and then commit this.

#25 @wildworks
10 months ago

  • Keywords gutenberg-merge added
  • Milestone 6.86.9

@audrasjb @Mamaduka As I understand it, PR #8770 is a backport from Gutenberg and should be committed in the 6.9 cycle, so I'd like to update the milestone.

#26 @Mamaduka
10 months ago

  • Resolution fixed
  • Status closedreopened

Re-opening for the remaining REST API change.

@Mamaduka commented on PR #8770:


10 months ago
#27

The same code has been tested inside the Gutenberg plugin for months now without any issue. I think it's okay to merge this.

cc @ellatrix, @t-hamano

#28 @Mamaduka
10 months ago

  • Resolutionfixed
  • Status reopenedclosed

In 60984:

REST API: Add export rel link for active theme response.

The targetHints.allow value is used by the Site Editor to enable/disable the theme export feature.

Props mamaduka, wildworks.
Fixes #57379.

Note: See TracTickets for help on using tickets.