wp/wp-admin/includes/class-wp-themes-list-table.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Themes List Table class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage List_Table
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
class WP_Themes_List_Table extends WP_List_Table {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
	protected $search_terms = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
	public $features = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
	 * Constructor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
	 * @see WP_List_Table::__construct() for more information on default arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
	 * @param array $args An associative array of arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
	public function __construct( $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		parent::__construct( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
			'ajax' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
			'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
	public function ajax_user_can() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		// Do not check edit_theme_options here. AJAX calls for available themes require switch_themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		return current_user_can( 'switch_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
	public function prepare_items() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		$themes = wp_get_themes( array( 'allowed' => true ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		if ( ! empty( $_REQUEST['s'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
			$this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		if ( ! empty( $_REQUEST['features'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
			$this->features = $_REQUEST['features'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		if ( $this->search_terms || $this->features ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
			foreach ( $themes as $key => $theme ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
				if ( ! $this->search_theme( $theme ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
					unset( $themes[ $key ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		unset( $themes[ get_option( 'stylesheet' ) ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
		WP_Theme::sort_by_name( $themes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		$per_page = 36;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		$page = $this->get_pagenum();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		$start = ( $page - 1 ) * $per_page;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
		$this->items = array_slice( $themes, $start, $per_page, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		$this->set_pagination_args( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
			'total_items' => count( $themes ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
			'per_page' => $per_page,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
			'infinite_scroll' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
	public function no_items() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		if ( $this->search_terms || $this->features ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
			_e( 'No items found.' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
		if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
			if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
				printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ), network_admin_url( 'theme-install.php' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
			} elseif ( current_user_can( 'manage_network_themes' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
				printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
			// Else, fallthrough. install_themes doesn't help if you can't enable it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
			if ( current_user_can( 'install_themes' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
				printf( __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress.org Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.' ), admin_url( 'theme-install.php' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		// Fallthrough.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
	 * @param string $which
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
	 * @return null
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
	public function tablenav( $which = 'top' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
		if ( $this->get_pagination_arg( 'total_pages' ) <= 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		<div class="tablenav themes <?php echo $which; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
			<?php $this->pagination( $which ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
			<span class="spinner"></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
			<br class="clear" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
	public function display() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		<?php $this->tablenav( 'top' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		<div id="availablethemes">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
			<?php $this->display_rows_or_placeholder(); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		<?php $this->tablenav( 'bottom' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	public function get_columns() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
	public function display_rows_or_placeholder() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		if ( $this->has_items() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			$this->display_rows();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
			echo '<div class="no-items">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
			$this->no_items();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
			echo '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
	public function display_rows() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
		$themes = $this->items;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
		foreach ( $themes as $theme ):
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
			?><div class="available-theme"><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
			$template   = $theme->get_template();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
			$stylesheet = $theme->get_stylesheet();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
			$title      = $theme->display('Name');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
			$version    = $theme->display('Version');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
			$author     = $theme->display('Author');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
			$activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=" . urlencode( $template ) . "&amp;stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			$preview_link = esc_url( add_query_arg(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
				array( 'preview' => 1, 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), 'preview_iframe' => true, 'TB_iframe' => 'true' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
				home_url( '/' ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
			$actions = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
			$actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
				. esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Activate' ) . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
			$actions['preview'] = '<a href="' . $preview_link . '" class="hide-if-customize" title="'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
				. esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Preview' ) . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
			if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
				$actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="load-customize hide-if-no-customize">'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
					. __( 'Live Preview' ) . '</a>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
			if ( ! is_multisite() && current_user_can( 'delete_themes' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
				$actions['delete'] = '<a class="submitdelete deletion" href="' . wp_nonce_url( 'themes.php?action=delete&amp;stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
					. '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n  'Cancel' to stop, 'OK' to delete." ), $title ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
					. "' );" . '">' . __( 'Delete' ) . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
			/** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
			$actions       = apply_filters( 'theme_action_links', $actions, $theme );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
			/** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
			$actions       = apply_filters( "theme_action_links_$stylesheet", $actions, $theme );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
			$delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
			unset( $actions['delete'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
			<a href="<?php echo $preview_link; ?>" class="screenshot hide-if-customize">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
				<?php if ( $screenshot = $theme->get_screenshot() ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
					<img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
				<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
			</a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
			<a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
				<?php if ( $screenshot = $theme->get_screenshot() ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
					<img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
				<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
			</a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
			<h3><?php echo $title; ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			<div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
			<div class="action-links">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
				<ul>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
					<?php foreach ( $actions as $action ): ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
						<li><?php echo $action; ?></li>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
					<?php endforeach; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
					<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
				</ul>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
				<?php echo $delete_action; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
				<?php theme_update_available( $theme ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
			</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
			<div class="themedetaildiv hide-if-js">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
				<p><strong><?php _e('Version:'); ?></strong> <?php echo $version; ?></p>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
				<p><?php echo $theme->display('Description'); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
				<?php if ( $theme->parent() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
					printf( ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
						__( 'https://codex.wordpress.org/Child_Themes' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
						$theme->parent()->display( 'Name' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
				} ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
			</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
			</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
		endforeach;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
	 * @param WP_Theme $theme
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
	 * @return bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   230
	public function search_theme( $theme ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
		// Search the features
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		foreach ( $this->features as $word ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			if ( ! in_array( $word, $theme->get('Tags') ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
		// Match all phrases
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
		foreach ( $this->search_terms as $word ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
			if ( in_array( $word, $theme->get('Tags') ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
			foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
				// Don't mark up; Do translate.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
				if ( false !== stripos( strip_tags( $theme->display( $header, false, true ) ), $word ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
					continue 2;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   246
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
			if ( false !== stripos( $theme->get_stylesheet(), $word ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
			if ( false !== stripos( $theme->get_template(), $word ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	 * Send required variables to JavaScript land
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   264
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
	 * @param array $extra_args
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
	public function _js_vars( $extra_args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		$search_string = isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
		$args = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
			'search' => $search_string,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
			'features' => $this->features,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
			'paged' => $this->get_pagenum(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
			'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		if ( is_array( $extra_args ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			$args = array_merge( $args, $extra_args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
		printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", wp_json_encode( $args ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
		parent::_js_vars();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
}