PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
jetpack / json-endpoints / jetpack / class.jetpack-json-api-themes-delete-endpoint.php

class.jetpack-json-api-themes-delete-endpoint.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3, at json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php

88 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit( 0 );
5 }
6
7 /**
8 * Themes delete endpoint class.
9 * POST /sites/%s/plugins/%s/delete
10 *
11 * @phan-constructor-used-for-side-effects
12 */
13 class Jetpack_JSON_API_Themes_Delete_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
14
15 /**
16 * Needed capabilities.
17 *
18 * @var string
19 */
20 protected $needed_capabilities = 'delete_themes';
21
22 /**
23 * The action.
24 *
25 * @var string
26 */
27 protected $action = 'delete';
28
29 /**
30 * Delete the theme.
31 *
32 * @return bool|WP_Error
33 */
34 protected function delete() {
35
36 foreach ( $this->themes as $theme ) {
37
38 // Don't delete an active child theme
39 if ( is_child_theme() && $theme === get_stylesheet() ) {
40 $error = 'You cannot delete a theme while it is active on the main site.';
41 $this->log[ $theme ]['error'] = $error;
42 continue;
43 }
44
45 if ( $theme === get_template() ) {
46 $error = 'You cannot delete a theme while it is active on the main site.';
47 $this->log[ $theme ]['error'] = $error;
48 continue;
49 }
50
51 /**
52 * Filters whether to use an alternative process for deleting a WordPress.com theme.
53 * The alternative process can be executed during the filter.
54 *
55 * The filter can also return an instance of WP_Error; in which case the endpoint response will
56 * contain this error.
57 *
58 * @module json-api
59 *
60 * @since 4.4.2
61 *
62 * @param bool $use_alternative_delete_method Whether to use the alternative method of deleting
63 * a WPCom theme.
64 * @param string $theme_slug Theme name (slug). If it is a WPCom theme,
65 * it should be suffixed with `-wpcom`.
66 */
67 $result = apply_filters( 'jetpack_wpcom_theme_delete', false, $theme );
68
69 if ( ! $result ) {
70 $result = delete_theme( $theme );
71 }
72
73 if ( is_wp_error( $result ) ) {
74 $error = $result->get_error_messages();
75 $this->log[ $theme ]['error'] = $error;
76 } else {
77 $this->log[ $theme ][] = 'Theme deleted';
78 }
79 }
80
81 if ( ! $this->bulk && isset( $error ) ) {
82 return new WP_Error( 'delete_theme_error', $error, 400 );
83 }
84
85 return true;
86 }
87 }
88