Nenhuma Descrição

class-wp-ms-themes-list-table.php 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. <?php
  2. /**
  3. * List Table API: WP_MS_Themes_List_Table class
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. * @since 3.1.0
  8. */
  9. /**
  10. * Core class used to implement displaying themes in a list table for the network admin.
  11. *
  12. * @since 3.1.0
  13. * @access private
  14. *
  15. * @see WP_List_Table
  16. */
  17. class WP_MS_Themes_List_Table extends WP_List_Table {
  18. public $site_id;
  19. public $is_site_themes;
  20. private $has_items;
  21. /**
  22. * Whether to show the auto-updates UI.
  23. *
  24. * @since 5.5.0
  25. *
  26. * @var bool True if auto-updates UI is to be shown, false otherwise.
  27. */
  28. protected $show_autoupdates = true;
  29. /**
  30. * Constructor.
  31. *
  32. * @since 3.1.0
  33. *
  34. * @see WP_List_Table::__construct() for more information on default arguments.
  35. *
  36. * @global string $status
  37. * @global int $page
  38. *
  39. * @param array $args An associative array of arguments.
  40. */
  41. public function __construct( $args = array() ) {
  42. global $status, $page;
  43. parent::__construct(
  44. array(
  45. 'plural' => 'themes',
  46. 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  47. )
  48. );
  49. $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
  50. if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken', 'auto-update-enabled', 'auto-update-disabled' ), true ) ) {
  51. $status = 'all';
  52. }
  53. $page = $this->get_pagenum();
  54. $this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false;
  55. if ( $this->is_site_themes ) {
  56. $this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
  57. }
  58. $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'theme' ) &&
  59. ! $this->is_site_themes && current_user_can( 'update_themes' );
  60. }
  61. /**
  62. * @return array
  63. */
  64. protected function get_table_classes() {
  65. // @todo Remove and add CSS for .themes.
  66. return array( 'widefat', 'plugins' );
  67. }
  68. /**
  69. * @return bool
  70. */
  71. public function ajax_user_can() {
  72. if ( $this->is_site_themes ) {
  73. return current_user_can( 'manage_sites' );
  74. } else {
  75. return current_user_can( 'manage_network_themes' );
  76. }
  77. }
  78. /**
  79. * @global string $status
  80. * @global array $totals
  81. * @global int $page
  82. * @global string $orderby
  83. * @global string $order
  84. * @global string $s
  85. */
  86. public function prepare_items() {
  87. global $status, $totals, $page, $orderby, $order, $s;
  88. wp_reset_vars( array( 'orderby', 'order', 's' ) );
  89. $themes = array(
  90. /**
  91. * Filters the full array of WP_Theme objects to list in the Multisite
  92. * themes list table.
  93. *
  94. * @since 3.1.0
  95. *
  96. * @param WP_Theme[] $all Array of WP_Theme objects to display in the list table.
  97. */
  98. 'all' => apply_filters( 'all_themes', wp_get_themes() ),
  99. 'search' => array(),
  100. 'enabled' => array(),
  101. 'disabled' => array(),
  102. 'upgrade' => array(),
  103. 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
  104. );
  105. if ( $this->show_autoupdates ) {
  106. $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
  107. $themes['auto-update-enabled'] = array();
  108. $themes['auto-update-disabled'] = array();
  109. }
  110. if ( $this->is_site_themes ) {
  111. $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
  112. $allowed_where = 'site';
  113. } else {
  114. $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
  115. $allowed_where = 'network';
  116. }
  117. $current = get_site_transient( 'update_themes' );
  118. $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current;
  119. foreach ( (array) $themes['all'] as $key => $theme ) {
  120. if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
  121. unset( $themes['all'][ $key ] );
  122. continue;
  123. }
  124. if ( $maybe_update && isset( $current->response[ $key ] ) ) {
  125. $themes['all'][ $key ]->update = true;
  126. $themes['upgrade'][ $key ] = $themes['all'][ $key ];
  127. }
  128. $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
  129. $themes[ $filter ][ $key ] = $themes['all'][ $key ];
  130. $theme_data = array(
  131. 'update_supported' => isset( $theme->update_supported ) ? $theme->update_supported : true,
  132. );
  133. // Extra info if known. array_merge() ensures $theme_data has precedence if keys collide.
  134. if ( isset( $current->response[ $key ] ) ) {
  135. $theme_data = array_merge( (array) $current->response[ $key ], $theme_data );
  136. } elseif ( isset( $current->no_update[ $key ] ) ) {
  137. $theme_data = array_merge( (array) $current->no_update[ $key ], $theme_data );
  138. } else {
  139. $theme_data['update_supported'] = false;
  140. }
  141. $theme->update_supported = $theme_data['update_supported'];
  142. /*
  143. * Create the expected payload for the auto_update_theme filter, this is the same data
  144. * as contained within $updates or $no_updates but used when the Theme is not known.
  145. */
  146. $filter_payload = array(
  147. 'theme' => $key,
  148. 'new_version' => '',
  149. 'url' => '',
  150. 'package' => '',
  151. 'requires' => '',
  152. 'requires_php' => '',
  153. );
  154. $filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) );
  155. $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $filter_payload );
  156. if ( ! is_null( $auto_update_forced ) ) {
  157. $theme->auto_update_forced = $auto_update_forced;
  158. }
  159. if ( $this->show_autoupdates ) {
  160. $enabled = in_array( $key, $auto_updates, true ) && $theme->update_supported;
  161. if ( isset( $theme->auto_update_forced ) ) {
  162. $enabled = (bool) $theme->auto_update_forced;
  163. }
  164. if ( $enabled ) {
  165. $themes['auto-update-enabled'][ $key ] = $theme;
  166. } else {
  167. $themes['auto-update-disabled'][ $key ] = $theme;
  168. }
  169. }
  170. }
  171. if ( $s ) {
  172. $status = 'search';
  173. $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
  174. }
  175. $totals = array();
  176. $js_themes = array();
  177. foreach ( $themes as $type => $list ) {
  178. $totals[ $type ] = count( $list );
  179. $js_themes[ $type ] = array_keys( $list );
  180. }
  181. if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) {
  182. $status = 'all';
  183. }
  184. $this->items = $themes[ $status ];
  185. WP_Theme::sort_by_name( $this->items );
  186. $this->has_items = ! empty( $themes['all'] );
  187. $total_this_page = $totals[ $status ];
  188. wp_localize_script(
  189. 'updates',
  190. '_wpUpdatesItemCounts',
  191. array(
  192. 'themes' => $js_themes,
  193. 'totals' => wp_get_update_data(),
  194. )
  195. );
  196. if ( $orderby ) {
  197. $orderby = ucfirst( $orderby );
  198. $order = strtoupper( $order );
  199. if ( 'Name' === $orderby ) {
  200. if ( 'ASC' === $order ) {
  201. $this->items = array_reverse( $this->items );
  202. }
  203. } else {
  204. uasort( $this->items, array( $this, '_order_callback' ) );
  205. }
  206. }
  207. $start = ( $page - 1 ) * $themes_per_page;
  208. if ( $total_this_page > $themes_per_page ) {
  209. $this->items = array_slice( $this->items, $start, $themes_per_page, true );
  210. }
  211. $this->set_pagination_args(
  212. array(
  213. 'total_items' => $total_this_page,
  214. 'per_page' => $themes_per_page,
  215. )
  216. );
  217. }
  218. /**
  219. * @param WP_Theme $theme
  220. * @return bool
  221. */
  222. public function _search_callback( $theme ) {
  223. static $term = null;
  224. if ( is_null( $term ) ) {
  225. $term = wp_unslash( $_REQUEST['s'] );
  226. }
  227. foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
  228. // Don't mark up; Do translate.
  229. if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) {
  230. return true;
  231. }
  232. }
  233. if ( false !== stripos( $theme->get_stylesheet(), $term ) ) {
  234. return true;
  235. }
  236. if ( false !== stripos( $theme->get_template(), $term ) ) {
  237. return true;
  238. }
  239. return false;
  240. }
  241. // Not used by any core columns.
  242. /**
  243. * @global string $orderby
  244. * @global string $order
  245. * @param array $theme_a
  246. * @param array $theme_b
  247. * @return int
  248. */
  249. public function _order_callback( $theme_a, $theme_b ) {
  250. global $orderby, $order;
  251. $a = $theme_a[ $orderby ];
  252. $b = $theme_b[ $orderby ];
  253. if ( $a === $b ) {
  254. return 0;
  255. }
  256. if ( 'DESC' === $order ) {
  257. return ( $a < $b ) ? 1 : -1;
  258. } else {
  259. return ( $a < $b ) ? -1 : 1;
  260. }
  261. }
  262. /**
  263. */
  264. public function no_items() {
  265. if ( $this->has_items ) {
  266. _e( 'No themes found.' );
  267. } else {
  268. _e( 'No themes are currently available.' );
  269. }
  270. }
  271. /**
  272. * @return array
  273. */
  274. public function get_columns() {
  275. $columns = array(
  276. 'cb' => '<input type="checkbox" />',
  277. 'name' => __( 'Theme' ),
  278. 'description' => __( 'Description' ),
  279. );
  280. if ( $this->show_autoupdates ) {
  281. $columns['auto-updates'] = __( 'Automatic Updates' );
  282. }
  283. return $columns;
  284. }
  285. /**
  286. * @return array
  287. */
  288. protected function get_sortable_columns() {
  289. return array(
  290. 'name' => 'name',
  291. );
  292. }
  293. /**
  294. * Gets the name of the primary column.
  295. *
  296. * @since 4.3.0
  297. *
  298. * @return string Unalterable name of the primary column name, in this case, 'name'.
  299. */
  300. protected function get_primary_column_name() {
  301. return 'name';
  302. }
  303. /**
  304. * @global array $totals
  305. * @global string $status
  306. * @return array
  307. */
  308. protected function get_views() {
  309. global $totals, $status;
  310. $status_links = array();
  311. foreach ( $totals as $type => $count ) {
  312. if ( ! $count ) {
  313. continue;
  314. }
  315. switch ( $type ) {
  316. case 'all':
  317. /* translators: %s: Number of themes. */
  318. $text = _nx(
  319. 'All <span class="count">(%s)</span>',
  320. 'All <span class="count">(%s)</span>',
  321. $count,
  322. 'themes'
  323. );
  324. break;
  325. case 'enabled':
  326. /* translators: %s: Number of themes. */
  327. $text = _nx(
  328. 'Enabled <span class="count">(%s)</span>',
  329. 'Enabled <span class="count">(%s)</span>',
  330. $count,
  331. 'themes'
  332. );
  333. break;
  334. case 'disabled':
  335. /* translators: %s: Number of themes. */
  336. $text = _nx(
  337. 'Disabled <span class="count">(%s)</span>',
  338. 'Disabled <span class="count">(%s)</span>',
  339. $count,
  340. 'themes'
  341. );
  342. break;
  343. case 'upgrade':
  344. /* translators: %s: Number of themes. */
  345. $text = _nx(
  346. 'Update Available <span class="count">(%s)</span>',
  347. 'Update Available <span class="count">(%s)</span>',
  348. $count,
  349. 'themes'
  350. );
  351. break;
  352. case 'broken':
  353. /* translators: %s: Number of themes. */
  354. $text = _nx(
  355. 'Broken <span class="count">(%s)</span>',
  356. 'Broken <span class="count">(%s)</span>',
  357. $count,
  358. 'themes'
  359. );
  360. break;
  361. case 'auto-update-enabled':
  362. /* translators: %s: Number of themes. */
  363. $text = _n(
  364. 'Auto-updates Enabled <span class="count">(%s)</span>',
  365. 'Auto-updates Enabled <span class="count">(%s)</span>',
  366. $count
  367. );
  368. break;
  369. case 'auto-update-disabled':
  370. /* translators: %s: Number of themes. */
  371. $text = _n(
  372. 'Auto-updates Disabled <span class="count">(%s)</span>',
  373. 'Auto-updates Disabled <span class="count">(%s)</span>',
  374. $count
  375. );
  376. break;
  377. }
  378. if ( $this->is_site_themes ) {
  379. $url = 'site-themes.php?id=' . $this->site_id;
  380. } else {
  381. $url = 'themes.php';
  382. }
  383. if ( 'search' !== $type ) {
  384. $status_links[ $type ] = sprintf(
  385. "<a href='%s'%s>%s</a>",
  386. esc_url( add_query_arg( 'theme_status', $type, $url ) ),
  387. ( $type === $status ) ? ' class="current" aria-current="page"' : '',
  388. sprintf( $text, number_format_i18n( $count ) )
  389. );
  390. }
  391. }
  392. return $status_links;
  393. }
  394. /**
  395. * @global string $status
  396. *
  397. * @return array
  398. */
  399. protected function get_bulk_actions() {
  400. global $status;
  401. $actions = array();
  402. if ( 'enabled' !== $status ) {
  403. $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
  404. }
  405. if ( 'disabled' !== $status ) {
  406. $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
  407. }
  408. if ( ! $this->is_site_themes ) {
  409. if ( current_user_can( 'update_themes' ) ) {
  410. $actions['update-selected'] = __( 'Update' );
  411. }
  412. if ( current_user_can( 'delete_themes' ) ) {
  413. $actions['delete-selected'] = __( 'Delete' );
  414. }
  415. }
  416. if ( $this->show_autoupdates ) {
  417. if ( 'auto-update-enabled' !== $status ) {
  418. $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' );
  419. }
  420. if ( 'auto-update-disabled' !== $status ) {
  421. $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' );
  422. }
  423. }
  424. return $actions;
  425. }
  426. /**
  427. */
  428. public function display_rows() {
  429. foreach ( $this->items as $theme ) {
  430. $this->single_row( $theme );
  431. }
  432. }
  433. /**
  434. * Handles the checkbox column output.
  435. *
  436. * @since 4.3.0
  437. *
  438. * @param WP_Theme $theme The current WP_Theme object.
  439. */
  440. public function column_cb( $theme ) {
  441. $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
  442. ?>
  443. <input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" id="<?php echo $checkbox_id; ?>" />
  444. <label class="screen-reader-text" for="<?php echo $checkbox_id; ?>" ><?php _e( 'Select' ); ?> <?php echo $theme->display( 'Name' ); ?></label>
  445. <?php
  446. }
  447. /**
  448. * Handles the name column output.
  449. *
  450. * @since 4.3.0
  451. *
  452. * @global string $status
  453. * @global int $page
  454. * @global string $s
  455. *
  456. * @param WP_Theme $theme The current WP_Theme object.
  457. */
  458. public function column_name( $theme ) {
  459. global $status, $page, $s;
  460. $context = $status;
  461. if ( $this->is_site_themes ) {
  462. $url = "site-themes.php?id={$this->site_id}&amp;";
  463. $allowed = $theme->is_allowed( 'site', $this->site_id );
  464. } else {
  465. $url = 'themes.php?';
  466. $allowed = $theme->is_allowed( 'network' );
  467. }
  468. // Pre-order.
  469. $actions = array(
  470. 'enable' => '',
  471. 'disable' => '',
  472. 'delete' => '',
  473. );
  474. $stylesheet = $theme->get_stylesheet();
  475. $theme_key = urlencode( $stylesheet );
  476. if ( ! $allowed ) {
  477. if ( ! $theme->errors() ) {
  478. $url = add_query_arg(
  479. array(
  480. 'action' => 'enable',
  481. 'theme' => $theme_key,
  482. 'paged' => $page,
  483. 's' => $s,
  484. ),
  485. $url
  486. );
  487. if ( $this->is_site_themes ) {
  488. /* translators: %s: Theme name. */
  489. $aria_label = sprintf( __( 'Enable %s' ), $theme->display( 'Name' ) );
  490. } else {
  491. /* translators: %s: Theme name. */
  492. $aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) );
  493. }
  494. $actions['enable'] = sprintf(
  495. '<a href="%s" class="edit" aria-label="%s">%s</a>',
  496. esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ),
  497. esc_attr( $aria_label ),
  498. ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) )
  499. );
  500. }
  501. } else {
  502. $url = add_query_arg(
  503. array(
  504. 'action' => 'disable',
  505. 'theme' => $theme_key,
  506. 'paged' => $page,
  507. 's' => $s,
  508. ),
  509. $url
  510. );
  511. if ( $this->is_site_themes ) {
  512. /* translators: %s: Theme name. */
  513. $aria_label = sprintf( __( 'Disable %s' ), $theme->display( 'Name' ) );
  514. } else {
  515. /* translators: %s: Theme name. */
  516. $aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) );
  517. }
  518. $actions['disable'] = sprintf(
  519. '<a href="%s" aria-label="%s">%s</a>',
  520. esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ),
  521. esc_attr( $aria_label ),
  522. ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) )
  523. );
  524. }
  525. if ( ! $allowed && ! $this->is_site_themes
  526. && current_user_can( 'delete_themes' )
  527. && get_option( 'stylesheet' ) !== $stylesheet
  528. && get_option( 'template' ) !== $stylesheet
  529. ) {
  530. $url = add_query_arg(
  531. array(
  532. 'action' => 'delete-selected',
  533. 'checked[]' => $theme_key,
  534. 'theme_status' => $context,
  535. 'paged' => $page,
  536. 's' => $s,
  537. ),
  538. 'themes.php'
  539. );
  540. /* translators: %s: Theme name. */
  541. $aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) );
  542. $actions['delete'] = sprintf(
  543. '<a href="%s" class="delete" aria-label="%s">%s</a>',
  544. esc_url( wp_nonce_url( $url, 'bulk-themes' ) ),
  545. esc_attr( $aria_label ),
  546. __( 'Delete' )
  547. );
  548. }
  549. /**
  550. * Filters the action links displayed for each theme in the Multisite
  551. * themes list table.
  552. *
  553. * The action links displayed are determined by the theme's status, and
  554. * which Multisite themes list table is being displayed - the Network
  555. * themes list table (themes.php), which displays all installed themes,
  556. * or the Site themes list table (site-themes.php), which displays the
  557. * non-network enabled themes when editing a site in the Network admin.
  558. *
  559. * The default action links for the Network themes list table include
  560. * 'Network Enable', 'Network Disable', and 'Delete'.
  561. *
  562. * The default action links for the Site themes list table include
  563. * 'Enable', and 'Disable'.
  564. *
  565. * @since 2.8.0
  566. *
  567. * @param string[] $actions An array of action links.
  568. * @param WP_Theme $theme The current WP_Theme object.
  569. * @param string $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
  570. */
  571. $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
  572. /**
  573. * Filters the action links of a specific theme in the Multisite themes
  574. * list table.
  575. *
  576. * The dynamic portion of the hook name, `$stylesheet`, refers to the
  577. * directory name of the theme, which in most cases is synonymous
  578. * with the template name.
  579. *
  580. * @since 3.1.0
  581. *
  582. * @param string[] $actions An array of action links.
  583. * @param WP_Theme $theme The current WP_Theme object.
  584. * @param string $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
  585. */
  586. $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, $context );
  587. echo $this->row_actions( $actions, true );
  588. }
  589. /**
  590. * Handles the description column output.
  591. *
  592. * @since 4.3.0
  593. *
  594. * @global string $status
  595. * @global array $totals
  596. *
  597. * @param WP_Theme $theme The current WP_Theme object.
  598. */
  599. public function column_description( $theme ) {
  600. global $status, $totals;
  601. if ( $theme->errors() ) {
  602. $pre = 'broken' === $status ? __( 'Broken Theme:' ) . ' ' : '';
  603. echo '<p><strong class="error-message">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
  604. }
  605. if ( $this->is_site_themes ) {
  606. $allowed = $theme->is_allowed( 'site', $this->site_id );
  607. } else {
  608. $allowed = $theme->is_allowed( 'network' );
  609. }
  610. $class = ! $allowed ? 'inactive' : 'active';
  611. if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
  612. $class .= ' update';
  613. }
  614. echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
  615. <div class='$class second theme-version-author-uri'>";
  616. $stylesheet = $theme->get_stylesheet();
  617. $theme_meta = array();
  618. if ( $theme->get( 'Version' ) ) {
  619. /* translators: %s: Theme version. */
  620. $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) );
  621. }
  622. /* translators: %s: Theme author. */
  623. $theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) );
  624. if ( $theme->get( 'ThemeURI' ) ) {
  625. /* translators: %s: Theme name. */
  626. $aria_label = sprintf( __( 'Visit %s homepage' ), $theme->display( 'Name' ) );
  627. $theme_meta[] = sprintf(
  628. '<a href="%s" aria-label="%s">%s</a>',
  629. $theme->display( 'ThemeURI' ),
  630. esc_attr( $aria_label ),
  631. __( 'Visit Theme Site' )
  632. );
  633. }
  634. if ( $theme->parent() ) {
  635. $theme_meta[] = sprintf(
  636. /* translators: %s: Theme name. */
  637. __( 'Child theme of %s' ),
  638. '<strong>' . $theme->parent()->display( 'Name' ) . '</strong>'
  639. );
  640. }
  641. /**
  642. * Filters the array of row meta for each theme in the Multisite themes
  643. * list table.
  644. *
  645. * @since 3.1.0
  646. *
  647. * @param string[] $theme_meta An array of the theme's metadata, including
  648. * the version, author, and theme URI.
  649. * @param string $stylesheet Directory name of the theme.
  650. * @param WP_Theme $theme WP_Theme object.
  651. * @param string $status Status of the theme.
  652. */
  653. $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
  654. echo implode( ' | ', $theme_meta );
  655. echo '</div>';
  656. }
  657. /**
  658. * Handles the auto-updates column output.
  659. *
  660. * @since 5.5.0
  661. *
  662. * @global string $status
  663. * @global int $page
  664. *
  665. * @param WP_Theme $theme The current WP_Theme object.
  666. */
  667. public function column_autoupdates( $theme ) {
  668. global $status, $page;
  669. static $auto_updates, $available_updates;
  670. if ( ! $auto_updates ) {
  671. $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
  672. }
  673. if ( ! $available_updates ) {
  674. $available_updates = get_site_transient( 'update_themes' );
  675. }
  676. $stylesheet = $theme->get_stylesheet();
  677. if ( isset( $theme->auto_update_forced ) ) {
  678. if ( $theme->auto_update_forced ) {
  679. // Forced on.
  680. $text = __( 'Auto-updates enabled' );
  681. } else {
  682. $text = __( 'Auto-updates disabled' );
  683. }
  684. $action = 'unavailable';
  685. $time_class = ' hidden';
  686. } elseif ( empty( $theme->update_supported ) ) {
  687. $text = '';
  688. $action = 'unavailable';
  689. $time_class = ' hidden';
  690. } elseif ( in_array( $stylesheet, $auto_updates, true ) ) {
  691. $text = __( 'Disable auto-updates' );
  692. $action = 'disable';
  693. $time_class = '';
  694. } else {
  695. $text = __( 'Enable auto-updates' );
  696. $action = 'enable';
  697. $time_class = ' hidden';
  698. }
  699. $query_args = array(
  700. 'action' => "{$action}-auto-update",
  701. 'theme' => $stylesheet,
  702. 'paged' => $page,
  703. 'theme_status' => $status,
  704. );
  705. $url = add_query_arg( $query_args, 'themes.php' );
  706. if ( 'unavailable' === $action ) {
  707. $html[] = '<span class="label">' . $text . '</span>';
  708. } else {
  709. $html[] = sprintf(
  710. '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
  711. wp_nonce_url( $url, 'updates' ),
  712. $action
  713. );
  714. $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
  715. $html[] = '<span class="label">' . $text . '</span>';
  716. $html[] = '</a>';
  717. }
  718. if ( isset( $available_updates->response[ $stylesheet ] ) ) {
  719. $html[] = sprintf(
  720. '<div class="auto-update-time%s">%s</div>',
  721. $time_class,
  722. wp_get_auto_update_message()
  723. );
  724. }
  725. $html = implode( '', $html );
  726. /**
  727. * Filters the HTML of the auto-updates setting for each theme in the Themes list table.
  728. *
  729. * @since 5.5.0
  730. *
  731. * @param string $html The HTML for theme's auto-update setting, including
  732. * toggle auto-update action link and time to next update.
  733. * @param string $stylesheet Directory name of the theme.
  734. * @param WP_Theme $theme WP_Theme object.
  735. */
  736. echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme );
  737. echo '<div class="notice notice-error notice-alt inline hidden"><p></p></div>';
  738. }
  739. /**
  740. * Handles default column output.
  741. *
  742. * @since 4.3.0
  743. *
  744. * @param WP_Theme $theme The current WP_Theme object.
  745. * @param string $column_name The current column name.
  746. */
  747. public function column_default( $theme, $column_name ) {
  748. $stylesheet = $theme->get_stylesheet();
  749. /**
  750. * Fires inside each custom column of the Multisite themes list table.
  751. *
  752. * @since 3.1.0
  753. *
  754. * @param string $column_name Name of the column.
  755. * @param string $stylesheet Directory name of the theme.
  756. * @param WP_Theme $theme Current WP_Theme object.
  757. */
  758. do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
  759. }
  760. /**
  761. * Handles the output for a single table row.
  762. *
  763. * @since 4.3.0
  764. *
  765. * @param WP_Theme $item The current WP_Theme object.
  766. */
  767. public function single_row_columns( $item ) {
  768. list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
  769. foreach ( $columns as $column_name => $column_display_name ) {
  770. $extra_classes = '';
  771. if ( in_array( $column_name, $hidden, true ) ) {
  772. $extra_classes .= ' hidden';
  773. }
  774. switch ( $column_name ) {
  775. case 'cb':
  776. echo '<th scope="row" class="check-column">';
  777. $this->column_cb( $item );
  778. echo '</th>';
  779. break;
  780. case 'name':
  781. $active_theme_label = '';
  782. /* The presence of the site_id property means that this is a subsite view and a label for the active theme needs to be added */
  783. if ( ! empty( $this->site_id ) ) {
  784. $stylesheet = get_blog_option( $this->site_id, 'stylesheet' );
  785. $template = get_blog_option( $this->site_id, 'template' );
  786. /* Add a label for the active template */
  787. if ( $item->get_template() === $template ) {
  788. $active_theme_label = ' &mdash; ' . __( 'Active Theme' );
  789. }
  790. /* In case this is a child theme, label it properly */
  791. if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
  792. $active_theme_label = ' &mdash; ' . __( 'Active Child Theme' );
  793. }
  794. }
  795. echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display( 'Name' ) . $active_theme_label . '</strong>';
  796. $this->column_name( $item );
  797. echo '</td>';
  798. break;
  799. case 'description':
  800. echo "<td class='column-description desc{$extra_classes}'>";
  801. $this->column_description( $item );
  802. echo '</td>';
  803. break;
  804. case 'auto-updates':
  805. echo "<td class='column-auto-updates{$extra_classes}'>";
  806. $this->column_autoupdates( $item );
  807. echo '</td>';
  808. break;
  809. default:
  810. echo "<td class='$column_name column-$column_name{$extra_classes}'>";
  811. $this->column_default( $item, $column_name );
  812. echo '</td>';
  813. break;
  814. }
  815. }
  816. }
  817. /**
  818. * @global string $status
  819. * @global array $totals
  820. *
  821. * @param WP_Theme $theme
  822. */
  823. public function single_row( $theme ) {
  824. global $status, $totals;
  825. if ( $this->is_site_themes ) {
  826. $allowed = $theme->is_allowed( 'site', $this->site_id );
  827. } else {
  828. $allowed = $theme->is_allowed( 'network' );
  829. }
  830. $stylesheet = $theme->get_stylesheet();
  831. $class = ! $allowed ? 'inactive' : 'active';
  832. if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
  833. $class .= ' update';
  834. }
  835. printf(
  836. '<tr class="%s" data-slug="%s">',
  837. esc_attr( $class ),
  838. esc_attr( $stylesheet )
  839. );
  840. $this->single_row_columns( $theme );
  841. echo '</tr>';
  842. if ( $this->is_site_themes ) {
  843. remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
  844. }
  845. /**
  846. * Fires after each row in the Multisite themes list table.
  847. *
  848. * @since 3.1.0
  849. *
  850. * @param string $stylesheet Directory name of the theme.
  851. * @param WP_Theme $theme Current WP_Theme object.
  852. * @param string $status Status of the theme.
  853. */
  854. do_action( 'after_theme_row', $stylesheet, $theme, $status );
  855. /**
  856. * Fires after each specific row in the Multisite themes list table.
  857. *
  858. * The dynamic portion of the hook name, `$stylesheet`, refers to the
  859. * directory name of the theme, most often synonymous with the template
  860. * name of the theme.
  861. *
  862. * @since 3.5.0
  863. *
  864. * @param string $stylesheet Directory name of the theme.
  865. * @param WP_Theme $theme Current WP_Theme object.
  866. * @param string $status Status of the theme.
  867. */
  868. do_action( "after_theme_row_{$stylesheet}", $stylesheet, $theme, $status );
  869. }
  870. }