/wp-admin/includes/class-automatic-upgrader-skin.php

https://gitlab.com/sihabudinahmad/asppi · PHP · 115 lines · 53 code · 11 blank · 51 comment · 8 complexity · f3d19ee4c85726b0f24cdd1f36c414f9 MD5 · raw file

  1. <?php
  2. /**
  3. * Upgrader API: Automatic_Upgrader_Skin class
  4. *
  5. * @package WordPress
  6. * @subpackage Upgrader
  7. * @since 4.6.0
  8. */
  9. /**
  10. * Upgrader Skin for Automatic WordPress Upgrades
  11. *
  12. * This skin is designed to be used when no output is intended, all output
  13. * is captured and stored for the caller to process and log/email/discard.
  14. *
  15. * @since 3.7.0
  16. * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
  17. *
  18. * @see Bulk_Upgrader_Skin
  19. */
  20. class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
  21. protected $messages = array();
  22. /**
  23. * Determines whether the upgrader needs FTP/SSH details in order to connect
  24. * to the filesystem.
  25. *
  26. * @since 3.7.0
  27. * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
  28. *
  29. * @see request_filesystem_credentials()
  30. *
  31. * @param bool $error Optional. Whether the current request has failed to connect.
  32. * Default false.
  33. * @param string $context Optional. Full path to the directory that is tested
  34. * for being writable. Default empty.
  35. * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
  36. * @return bool True on success, false on failure.
  37. */
  38. public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
  39. if ( $context ) {
  40. $this->options['context'] = $context;
  41. }
  42. // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
  43. // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
  44. ob_start();
  45. $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
  46. ob_end_clean();
  47. return $result;
  48. }
  49. /**
  50. * @access public
  51. *
  52. * @return array
  53. */
  54. public function get_upgrade_messages() {
  55. return $this->messages;
  56. }
  57. /**
  58. * @param string|array|WP_Error $data
  59. */
  60. public function feedback( $data ) {
  61. if ( is_wp_error( $data ) ) {
  62. $string = $data->get_error_message();
  63. } elseif ( is_array( $data ) ) {
  64. return;
  65. } else {
  66. $string = $data;
  67. }
  68. if ( ! empty( $this->upgrader->strings[ $string ] ) )
  69. $string = $this->upgrader->strings[ $string ];
  70. if ( strpos( $string, '%' ) !== false ) {
  71. $args = func_get_args();
  72. $args = array_splice( $args, 1 );
  73. if ( ! empty( $args ) )
  74. $string = vsprintf( $string, $args );
  75. }
  76. $string = trim( $string );
  77. // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
  78. $string = wp_kses( $string, array(
  79. 'a' => array(
  80. 'href' => true
  81. ),
  82. 'br' => true,
  83. 'em' => true,
  84. 'strong' => true,
  85. ) );
  86. if ( empty( $string ) )
  87. return;
  88. $this->messages[] = $string;
  89. }
  90. /**
  91. * @access public
  92. */
  93. public function header() {
  94. ob_start();
  95. }
  96. /**
  97. * @access public
  98. */
  99. public function footer() {
  100. $output = ob_get_clean();
  101. if ( ! empty( $output ) )
  102. $this->feedback( $output );
  103. }
  104. }