PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/df_home/static/test/portalbkd/wp-admin/includes/class-wp-ms-themes-list-table.php

https://gitlab.com/darmawan.fatria/df-skp-2014
PHP | 480 lines | 272 code | 79 blank | 129 comment | 66 complexity | b7d8cddc268e99caa0fd867cc57a9d15 MD5 | raw file
  1. <?php
  2. /**
  3. * MS Themes List Table class.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. * @access private
  9. */
  10. class WP_MS_Themes_List_Table extends WP_List_Table {
  11. public $site_id;
  12. public $is_site_themes;
  13. private $has_items;
  14. /**
  15. * Constructor.
  16. *
  17. * @since 3.1.0
  18. * @access public
  19. *
  20. * @see WP_List_Table::__construct() for more information on default arguments.
  21. *
  22. * @param array $args An associative array of arguments.
  23. */
  24. public function __construct( $args = array() ) {
  25. global $status, $page;
  26. parent::__construct( array(
  27. 'plural' => 'themes',
  28. 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  29. ) );
  30. $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
  31. if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) )
  32. $status = 'all';
  33. $page = $this->get_pagenum();
  34. $this->is_site_themes = ( 'site-themes-network' == $this->screen->id ) ? true : false;
  35. if ( $this->is_site_themes )
  36. $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  37. }
  38. protected function get_table_classes() {
  39. // todo: remove and add CSS for .themes
  40. return array( 'widefat', 'plugins' );
  41. }
  42. public function ajax_user_can() {
  43. if ( $this->is_site_themes )
  44. return current_user_can( 'manage_sites' );
  45. else
  46. return current_user_can( 'manage_network_themes' );
  47. }
  48. public function prepare_items() {
  49. global $status, $totals, $page, $orderby, $order, $s;
  50. wp_reset_vars( array( 'orderby', 'order', 's' ) );
  51. $themes = array(
  52. /**
  53. * Filter the full array of WP_Theme objects to list in the Multisite
  54. * themes list table.
  55. *
  56. * @since 3.1.0
  57. *
  58. * @param array $all An array of WP_Theme objects to display in the list table.
  59. */
  60. 'all' => apply_filters( 'all_themes', wp_get_themes() ),
  61. 'search' => array(),
  62. 'enabled' => array(),
  63. 'disabled' => array(),
  64. 'upgrade' => array(),
  65. 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
  66. );
  67. if ( $this->is_site_themes ) {
  68. $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
  69. $allowed_where = 'site';
  70. } else {
  71. $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
  72. $allowed_where = 'network';
  73. }
  74. $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' );
  75. foreach ( (array) $themes['all'] as $key => $theme ) {
  76. if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
  77. unset( $themes['all'][ $key ] );
  78. continue;
  79. }
  80. if ( $maybe_update && isset( $current->response[ $key ] ) ) {
  81. $themes['all'][ $key ]->update = true;
  82. $themes['upgrade'][ $key ] = $themes['all'][ $key ];
  83. }
  84. $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
  85. $themes[ $filter ][ $key ] = $themes['all'][ $key ];
  86. }
  87. if ( $s ) {
  88. $status = 'search';
  89. $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
  90. }
  91. $totals = array();
  92. foreach ( $themes as $type => $list )
  93. $totals[ $type ] = count( $list );
  94. if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
  95. $status = 'all';
  96. $this->items = $themes[ $status ];
  97. WP_Theme::sort_by_name( $this->items );
  98. $this->has_items = ! empty( $themes['all'] );
  99. $total_this_page = $totals[ $status ];
  100. if ( $orderby ) {
  101. $orderby = ucfirst( $orderby );
  102. $order = strtoupper( $order );
  103. if ( $orderby == 'Name' ) {
  104. if ( 'ASC' == $order )
  105. $this->items = array_reverse( $this->items );
  106. } else {
  107. uasort( $this->items, array( $this, '_order_callback' ) );
  108. }
  109. }
  110. $start = ( $page - 1 ) * $themes_per_page;
  111. if ( $total_this_page > $themes_per_page )
  112. $this->items = array_slice( $this->items, $start, $themes_per_page, true );
  113. $this->set_pagination_args( array(
  114. 'total_items' => $total_this_page,
  115. 'per_page' => $themes_per_page,
  116. ) );
  117. }
  118. /**
  119. * @staticvar string $term
  120. * @param WP_Theme $theme
  121. * @return bool
  122. */
  123. public function _search_callback( $theme ) {
  124. static $term;
  125. if ( is_null( $term ) )
  126. $term = wp_unslash( $_REQUEST['s'] );
  127. foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
  128. // Don't mark up; Do translate.
  129. if ( false !== stripos( $theme->display( $field, false, true ), $term ) )
  130. return true;
  131. }
  132. if ( false !== stripos( $theme->get_stylesheet(), $term ) )
  133. return true;
  134. if ( false !== stripos( $theme->get_template(), $term ) )
  135. return true;
  136. return false;
  137. }
  138. // Not used by any core columns.
  139. /**
  140. * @global string $orderby
  141. * @global string $order
  142. * @param array $theme_a
  143. * @param array $theme_b
  144. * @return int
  145. */
  146. public function _order_callback( $theme_a, $theme_b ) {
  147. global $orderby, $order;
  148. $a = $theme_a[ $orderby ];
  149. $b = $theme_b[ $orderby ];
  150. if ( $a == $b )
  151. return 0;
  152. if ( 'DESC' == $order )
  153. return ( $a < $b ) ? 1 : -1;
  154. else
  155. return ( $a < $b ) ? -1 : 1;
  156. }
  157. public function no_items() {
  158. if ( ! $this->has_items )
  159. _e( 'No themes found.' );
  160. else
  161. _e( 'You do not appear to have any themes available at this time.' );
  162. }
  163. public function get_columns() {
  164. global $status;
  165. return array(
  166. 'cb' => '<input type="checkbox" />',
  167. 'name' => __( 'Theme' ),
  168. 'description' => __( 'Description' ),
  169. );
  170. }
  171. protected function get_sortable_columns() {
  172. return array(
  173. 'name' => 'name',
  174. );
  175. }
  176. protected function get_views() {
  177. global $totals, $status;
  178. $status_links = array();
  179. foreach ( $totals as $type => $count ) {
  180. if ( !$count )
  181. continue;
  182. switch ( $type ) {
  183. case 'all':
  184. $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
  185. break;
  186. case 'enabled':
  187. $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
  188. break;
  189. case 'disabled':
  190. $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
  191. break;
  192. case 'upgrade':
  193. $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
  194. break;
  195. case 'broken' :
  196. $text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count );
  197. break;
  198. }
  199. if ( $this->is_site_themes )
  200. $url = 'site-themes.php?id=' . $this->site_id;
  201. else
  202. $url = 'themes.php';
  203. if ( 'search' != $type ) {
  204. $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
  205. esc_url( add_query_arg('theme_status', $type, $url) ),
  206. ( $type == $status ) ? ' class="current"' : '',
  207. sprintf( $text, number_format_i18n( $count ) )
  208. );
  209. }
  210. }
  211. return $status_links;
  212. }
  213. protected function get_bulk_actions() {
  214. global $status;
  215. $actions = array();
  216. if ( 'enabled' != $status )
  217. $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
  218. if ( 'disabled' != $status )
  219. $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
  220. if ( ! $this->is_site_themes ) {
  221. if ( current_user_can( 'update_themes' ) )
  222. $actions['update-selected'] = __( 'Update' );
  223. if ( current_user_can( 'delete_themes' ) )
  224. $actions['delete-selected'] = __( 'Delete' );
  225. }
  226. return $actions;
  227. }
  228. public function display_rows() {
  229. foreach ( $this->items as $theme )
  230. $this->single_row( $theme );
  231. }
  232. /**
  233. * @global string $status
  234. * @global int $page
  235. * @global string $s
  236. * @global array $totals
  237. * @param WP_Theme $theme
  238. */
  239. public function single_row( $theme ) {
  240. global $status, $page, $s, $totals;
  241. $context = $status;
  242. if ( $this->is_site_themes ) {
  243. $url = "site-themes.php?id={$this->site_id}&amp;";
  244. $allowed = $theme->is_allowed( 'site', $this->site_id );
  245. } else {
  246. $url = 'themes.php?';
  247. $allowed = $theme->is_allowed( 'network' );
  248. }
  249. // Pre-order.
  250. $actions = array(
  251. 'enable' => '',
  252. 'disable' => '',
  253. 'edit' => '',
  254. 'delete' => ''
  255. );
  256. $stylesheet = $theme->get_stylesheet();
  257. $theme_key = urlencode( $stylesheet );
  258. if ( ! $allowed ) {
  259. if ( ! $theme->errors() )
  260. $actions['enable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>';
  261. } else {
  262. $actions['disable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=disable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'disable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__('Disable this theme') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>';
  263. }
  264. if ( current_user_can('edit_themes') )
  265. $actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . $theme_key ) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
  266. if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) )
  267. $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&amp;checked[]=' . $theme_key . '&amp;theme_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-themes' ) ) . '" title="' . esc_attr__( 'Delete this theme' ) . '" class="delete">' . __( 'Delete' ) . '</a>';
  268. /**
  269. * Filter the action links displayed for each theme in the Multisite
  270. * themes list table.
  271. *
  272. * The action links displayed are determined by the theme's status, and
  273. * which Multisite themes list table is being displayed - the Network
  274. * themes list table (themes.php), which displays all installed themes,
  275. * or the Site themes list table (site-themes.php), which displays the
  276. * non-network enabled themes when editing a site in the Network admin.
  277. *
  278. * The default action links for the Network themes list table include
  279. * 'Network Enable', 'Network Disable', 'Edit', and 'Delete'.
  280. *
  281. * The default action links for the Site themes list table include
  282. * 'Enable', 'Disable', and 'Edit'.
  283. *
  284. * @since 2.8.0
  285. *
  286. * @param array $actions An array of action links.
  287. * @param WP_Theme $theme The current WP_Theme object.
  288. * @param string $context Status of the theme.
  289. */
  290. $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
  291. /**
  292. * Filter the action links of a specific theme in the Multisite themes
  293. * list table.
  294. *
  295. * The dynamic portion of the hook name, `$stylesheet`, refers to the
  296. * directory name of the theme, which in most cases is synonymous
  297. * with the template name.
  298. *
  299. * @since 3.1.0
  300. *
  301. * @param array $actions An array of action links.
  302. * @param WP_Theme $theme The current WP_Theme object.
  303. * @param string $context Status of the theme.
  304. */
  305. $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context );
  306. $class = ! $allowed ? 'inactive' : 'active';
  307. $checkbox_id = "checkbox_" . md5( $theme->get('Name') );
  308. $checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $stylesheet ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $theme->display('Name') . "</label>";
  309. $id = sanitize_html_class( $theme->get_stylesheet() );
  310. if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) )
  311. $class .= ' update';
  312. echo "<tr id='$id' class='$class'>";
  313. list( $columns, $hidden ) = $this->get_column_info();
  314. foreach ( $columns as $column_name => $column_display_name ) {
  315. $style = '';
  316. if ( in_array( $column_name, $hidden ) )
  317. $style = ' style="display:none;"';
  318. switch ( $column_name ) {
  319. case 'cb':
  320. echo "<th scope='row' class='check-column'>$checkbox</th>";
  321. break;
  322. case 'name':
  323. echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>";
  324. echo $this->row_actions( $actions, true );
  325. echo "</td>";
  326. break;
  327. case 'description':
  328. echo "<td class='column-description desc'$style>";
  329. if ( $theme->errors() ) {
  330. $pre = $status == 'broken' ? __( 'Broken Theme:' ) . ' ' : '';
  331. echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
  332. }
  333. echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
  334. <div class='$class second theme-version-author-uri'>";
  335. $theme_meta = array();
  336. if ( $theme->get('Version') )
  337. $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') );
  338. $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') );
  339. if ( $theme->get('ThemeURI') )
  340. $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
  341. /**
  342. * Filter the array of row meta for each theme in the Multisite themes
  343. * list table.
  344. *
  345. * @since 3.1.0
  346. *
  347. * @param array $theme_meta An array of the theme's metadata,
  348. * including the version, author, and
  349. * theme URI.
  350. * @param string $stylesheet Directory name of the theme.
  351. * @param WP_Theme $theme WP_Theme object.
  352. * @param string $status Status of the theme.
  353. */
  354. $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
  355. echo implode( ' | ', $theme_meta );
  356. echo "</div></td>";
  357. break;
  358. default:
  359. echo "<td class='$column_name column-$column_name'$style>";
  360. /**
  361. * Fires inside each custom column of the Multisite themes list table.
  362. *
  363. * @since 3.1.0
  364. *
  365. * @param string $column_name Name of the column.
  366. * @param string $stylesheet Directory name of the theme.
  367. * @param WP_Theme $theme Current WP_Theme object.
  368. */
  369. do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
  370. echo "</td>";
  371. }
  372. }
  373. echo "</tr>";
  374. if ( $this->is_site_themes )
  375. remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
  376. /**
  377. * Fires after each row in the Multisite themes list table.
  378. *
  379. * @since 3.1.0
  380. *
  381. * @param string $stylesheet Directory name of the theme.
  382. * @param WP_Theme $theme Current WP_Theme object.
  383. * @param string $status Status of the theme.
  384. */
  385. do_action( 'after_theme_row', $stylesheet, $theme, $status );
  386. /**
  387. * Fires after each specific row in the Multisite themes list table.
  388. *
  389. * The dynamic portion of the hook name, `$stylesheet`, refers to the
  390. * directory name of the theme, most often synonymous with the template
  391. * name of the theme.
  392. *
  393. * @since 3.5.0
  394. *
  395. * @param string $stylesheet Directory name of the theme.
  396. * @param WP_Theme $theme Current WP_Theme object.
  397. * @param string $status Status of the theme.
  398. */
  399. do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status );
  400. }
  401. }