PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.7.3
Jetpack – WP Security, Backup, Speed, & Growth v12.7.3
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 13.7.2 13.8.3 All 506 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 12.7.3, at json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php

82 lines 2.2 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 /**
4 * Themes delete endpoint class.
5 * POST /sites/%s/plugins/%s/delete
6 */
7 class Jetpack_JSON_API_Themes_Delete_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
8
9 /**
10 * Needed capabilities.
11 *
12 * @var string
13 */
14 protected $needed_capabilities = 'delete_themes';
15
16 /**
17 * The action.
18 *
19 * @var string
20 */
21 protected $action = 'delete';
22
23 /**
24 * Delete the theme.
25 *
26 * @return bool|WP_Error
27 */
28 protected function delete() {
29
30 foreach ( $this->themes as $theme ) {
31
32 // Don't delete an active child theme
33 if ( is_child_theme() && $theme === get_stylesheet() ) {
34 $error = 'You cannot delete a theme while it is active on the main site.';
35 $this->log[ $theme ]['error'] = $error;
36 continue;
37 }
38
39 if ( $theme === get_template() ) {
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 /**
46 * Filters whether to use an alternative process for deleting a WordPress.com theme.
47 * The alternative process can be executed during the filter.
48 *
49 * The filter can also return an instance of WP_Error; in which case the endpoint response will
50 * contain this error.
51 *
52 * @module json-api
53 *
54 * @since 4.4.2
55 *
56 * @param bool $use_alternative_delete_method Whether to use the alternative method of deleting
57 * a WPCom theme.
58 * @param string $theme_slug Theme name (slug). If it is a WPCom theme,
59 * it should be suffixed with `-wpcom`.
60 */
61 $result = apply_filters( 'jetpack_wpcom_theme_delete', false, $theme );
62
63 if ( ! $result ) {
64 $result = delete_theme( $theme );
65 }
66
67 if ( is_wp_error( $result ) ) {
68 $error = $result->get_error_messages();
69 $this->log[ $theme ]['error'] = $error;
70 } else {
71 $this->log[ $theme ][] = 'Theme deleted';
72 }
73 }
74
75 if ( ! $this->bulk && isset( $error ) ) {
76 return new WP_Error( 'delete_theme_error', $error, 400 );
77 }
78
79 return true;
80 }
81 }
82