Brak opisu

class.jetpack-json-api-themes-delete-endpoint.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. class Jetpack_JSON_API_Themes_Delete_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
  3. // POST /sites/%s/plugins/%s/delete
  4. protected $needed_capabilities = 'delete_themes';
  5. protected $action = 'delete';
  6. protected function delete() {
  7. foreach( $this->themes as $theme ) {
  8. // Don't delete an active child theme
  9. if ( is_child_theme() && $theme == get_stylesheet() ) {
  10. $error = $this->log[ $theme ]['error'] = 'You cannot delete a theme while it is active on the main site.';
  11. continue;
  12. }
  13. if( $theme == get_template() ) {
  14. $error = $this->log[ $theme ]['error'] = 'You cannot delete a theme while it is active on the main site.';
  15. continue;
  16. }
  17. /**
  18. * Filters whether to use an alternative process for deleting a WordPress.com theme.
  19. * The alternative process can be executed during the filter.
  20. *
  21. * The filter can also return an instance of WP_Error; in which case the endpoint response will
  22. * contain this error.
  23. *
  24. * @module json-api
  25. *
  26. * @since 4.4.2
  27. *
  28. * @param bool $use_alternative_delete_method Whether to use the alternative method of deleting
  29. * a WPCom theme.
  30. * @param string $theme_slug Theme name (slug). If it is a WPCom theme,
  31. * it should be suffixed with `-wpcom`.
  32. */
  33. $result = apply_filters( 'jetpack_wpcom_theme_delete', false, $theme );
  34. if ( ! $result ) {
  35. $result = delete_theme( $theme );
  36. }
  37. if ( is_wp_error( $result ) ) {
  38. $error = $this->log[ $theme ]['error'] = $result->get_error_messages();
  39. } else {
  40. $this->log[ $theme ][] = 'Theme deleted';
  41. }
  42. }
  43. if( ! $this->bulk && isset( $error ) ) {
  44. return new WP_Error( 'delete_theme_error', $error, 400 );
  45. }
  46. return true;
  47. }
  48. }