Sin descripción

class.jetpack-client-server.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. use Automattic\Jetpack\Connection\Webhooks;
  3. /**
  4. * Client = Plugin
  5. * Client Server = API Methods the Plugin must respond to
  6. */
  7. class Jetpack_Client_Server {
  8. /**
  9. * Handle the client authorization error.
  10. *
  11. * @param WP_Error $error The error object.
  12. */
  13. public static function client_authorize_error( $error ) {
  14. if ( $error instanceof WP_Error ) {
  15. Jetpack::state( 'error', $error->get_error_code() );
  16. }
  17. }
  18. /**
  19. * The user is already authorized, we set the Jetpack state and adjust the redirect URL.
  20. *
  21. * @return string
  22. */
  23. public static function client_authorize_already_authorized_url() {
  24. Jetpack::state( 'message', 'already_authorized' );
  25. return Jetpack::admin_url();
  26. }
  27. /**
  28. * The authorization processing has started.
  29. */
  30. public static function client_authorize_processing() {
  31. Jetpack::log( 'authorize' );
  32. }
  33. /**
  34. * The authorization has completed (successfully or not), and the redirect URL is empty.
  35. * We set the Jetpack Dashboard as the default URL.
  36. *
  37. * @return string
  38. */
  39. public static function client_authorize_fallback_url() {
  40. return Jetpack::admin_url();
  41. }
  42. /**
  43. * Authorization handler.
  44. *
  45. * @deprecated since Jetpack 9.5.0
  46. * @see Webhooks::handle_authorize()
  47. */
  48. public function client_authorize() {
  49. _deprecated_function( __METHOD__, 'jetpack-9.5.0', 'Automattic\\Jetpack\\Connection\\Webhooks::handle_authorize' );
  50. ( new Webhooks() )->handle_authorize();
  51. }
  52. public static function deactivate_plugin( $probable_file, $probable_title ) {
  53. include_once ABSPATH . 'wp-admin/includes/plugin.php';
  54. if ( is_plugin_active( $probable_file ) ) {
  55. deactivate_plugins( $probable_file );
  56. return 1;
  57. } else {
  58. // If the plugin is not in the usual place, try looking through all active plugins.
  59. $active_plugins = Jetpack::get_active_plugins();
  60. foreach ( $active_plugins as $plugin ) {
  61. $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
  62. if ( $data['Name'] == $probable_title ) {
  63. deactivate_plugins( $plugin );
  64. return 1;
  65. }
  66. }
  67. }
  68. return 0;
  69. }
  70. /**
  71. * @deprecated since Jetpack 9.5.0
  72. * @see Jetpack::init()
  73. */
  74. public function get_jetpack() {
  75. _deprecated_function( __METHOD__, 'jetpack-9.5.0', 'Jetpack::init' );
  76. return Jetpack::init();
  77. }
  78. /**
  79. * No longer used.
  80. *
  81. * @deprecated since Jetpack 9.5.0
  82. */
  83. public function do_exit() {
  84. _deprecated_function( __METHOD__, 'jetpack-9.5.0' );
  85. exit;
  86. }
  87. }