author | Anthony Ly <anthonyly.com@gmail.com> |
Mon, 19 Nov 2012 18:26:13 +0100 | |
changeset 194 | 32102edaa81b |
parent 136 | bde1974c263b |
child 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Theme Install Administration API |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
$themes_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()), |
|
10 |
'abbr' => array('title' => array()), 'acronym' => array('title' => array()), |
|
11 |
'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(), |
|
12 |
'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(), |
|
13 |
'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), |
|
14 |
'img' => array('src' => array(), 'class' => array(), 'alt' => array()) |
|
15 |
); |
|
16 |
||
17 |
$theme_field_defaults = array( 'description' => true, 'sections' => false, 'tested' => true, 'requires' => true, |
|
18 |
'rating' => true, 'downloaded' => true, 'downloadlink' => true, 'last_updated' => true, 'homepage' => true, |
|
19 |
'tags' => true, 'num_ratings' => true |
|
20 |
); |
|
21 |
||
22 |
/** |
|
23 |
* Retrieve list of WordPress theme features (aka theme tags) |
|
24 |
* |
|
25 |
* @since 2.8.0 |
|
26 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
27 |
* @deprecated since 3.1.0 Use get_theme_feature_list() instead. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
28 |
* |
136 | 29 |
* @return array |
30 |
*/ |
|
31 |
function install_themes_feature_list( ) { |
|
32 |
if ( !$cache = get_transient( 'wporg_theme_feature_list' ) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
33 |
set_transient( 'wporg_theme_feature_list', array( ), 10800); |
136 | 34 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
35 |
if ( $cache ) |
136 | 36 |
return $cache; |
37 |
||
38 |
$feature_list = themes_api( 'feature_list', array( ) ); |
|
39 |
if ( is_wp_error( $feature_list ) ) |
|
40 |
return $features; |
|
41 |
||
42 |
set_transient( 'wporg_theme_feature_list', $feature_list, 10800 ); |
|
43 |
||
44 |
return $feature_list; |
|
45 |
} |
|
46 |
||
47 |
/** |
|
48 |
* Display search form for searching themes. |
|
49 |
* |
|
50 |
* @since 2.8.0 |
|
51 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
52 |
function install_theme_search_form( $type_selector = true ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
53 |
$type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : 'term'; |
136 | 54 |
$term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : ''; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
55 |
if ( ! $type_selector ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
56 |
echo '<p class="install-help">' . __( 'Search for themes by keyword.' ) . '</p>'; |
136 | 57 |
?> |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
58 |
<form id="search-themes" method="get" action=""> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
59 |
<input type="hidden" name="tab" value="search" /> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
60 |
<?php if ( $type_selector ) : ?> |
136 | 61 |
<select name="type" id="typeselector"> |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
62 |
<option value="term" <?php selected('term', $type) ?>><?php _e('Keyword'); ?></option> |
136 | 63 |
<option value="author" <?php selected('author', $type) ?>><?php _e('Author'); ?></option> |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
64 |
<option value="tag" <?php selected('tag', $type) ?>><?php _ex('Tag', 'Theme Installer'); ?></option> |
136 | 65 |
</select> |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
66 |
<?php endif; ?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
67 |
<input type="search" name="s" size="30" value="<?php echo esc_attr($term) ?>" /> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
68 |
<?php submit_button( __( 'Search' ), 'button', 'search', false ); ?> |
136 | 69 |
</form> |
70 |
<?php |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* Display tags filter for themes. |
|
75 |
* |
|
76 |
* @since 2.8.0 |
|
77 |
*/ |
|
78 |
function install_themes_dashboard() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
79 |
install_theme_search_form( false ); |
136 | 80 |
?> |
81 |
<h4><?php _e('Feature Filter') ?></h4> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
82 |
<p class="install-help"><?php _e( 'Find a theme based on specific features.' ); ?></p> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
83 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
84 |
<form method="get" action=""> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
85 |
<input type="hidden" name="tab" value="search" /> |
136 | 86 |
<?php |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
87 |
$feature_list = get_theme_feature_list( ); |
136 | 88 |
echo '<div class="feature-filter">'; |
89 |
||
90 |
foreach ( (array) $feature_list as $feature_name => $features ) { |
|
91 |
$feature_name = esc_html( $feature_name ); |
|
92 |
echo '<div class="feature-name">' . $feature_name . '</div>'; |
|
93 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
94 |
echo '<ol class="feature-group">'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
95 |
foreach ( $features as $feature => $feature_name ) { |
136 | 96 |
$feature_name = esc_html( $feature_name ); |
97 |
$feature = esc_attr($feature); |
|
98 |
?> |
|
99 |
||
100 |
<li> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
101 |
<input type="checkbox" name="features[]" id="feature-id-<?php echo $feature; ?>" value="<?php echo $feature; ?>" /> |
136 | 102 |
<label for="feature-id-<?php echo $feature; ?>"><?php echo $feature_name; ?></label> |
103 |
</li> |
|
104 |
||
105 |
<?php } ?> |
|
106 |
</ol> |
|
107 |
<br class="clear" /> |
|
108 |
<?php |
|
109 |
} ?> |
|
110 |
||
111 |
</div> |
|
112 |
<br class="clear" /> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
113 |
<?php submit_button( __( 'Find Themes' ), 'button', 'search' ); ?> |
136 | 114 |
</form> |
115 |
<?php |
|
116 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
117 |
add_action('install_themes_dashboard', 'install_themes_dashboard'); |
136 | 118 |
|
119 |
function install_themes_upload($page = 1) { |
|
120 |
?> |
|
121 |
<h4><?php _e('Install a theme in .zip format') ?></h4> |
|
122 |
<p class="install-help"><?php _e('If you have a theme in a .zip format, you may install it by uploading it here.') ?></p> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
123 |
<form method="post" enctype="multipart/form-data" action="<?php echo self_admin_url('update.php?action=upload-theme') ?>"> |
136 | 124 |
<?php wp_nonce_field( 'theme-upload') ?> |
125 |
<input type="file" name="themezip" /> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
126 |
<?php submit_button( __( 'Install Now' ), 'button', 'install-theme-submit', false ); ?> |
136 | 127 |
</form> |
128 |
<?php |
|
129 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
130 |
add_action('install_themes_upload', 'install_themes_upload', 10, 1); |
136 | 131 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
132 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
133 |
* Prints a theme on the Install Themes pages. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
134 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
135 |
* @deprecated 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
136 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
137 |
function display_theme( $theme ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
138 |
_deprecated_function( __FUNCTION__, '3.4' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
139 |
global $wp_list_table; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
140 |
return $wp_list_table->single_row( $theme ); |
136 | 141 |
} |
142 |
||
143 |
/** |
|
144 |
* Display theme content based on theme list. |
|
145 |
* |
|
146 |
* @since 2.8.0 |
|
147 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
148 |
function display_themes() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
149 |
global $wp_list_table; |
136 | 150 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
151 |
$wp_list_table->display(); |
136 | 152 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
153 |
add_action('install_themes_search', 'display_themes'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
154 |
add_action('install_themes_featured', 'display_themes'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
155 |
add_action('install_themes_new', 'display_themes'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
156 |
add_action('install_themes_updated', 'display_themes'); |
136 | 157 |
|
158 |
/** |
|
159 |
* Display theme information in dialog box form. |
|
160 |
* |
|
161 |
* @since 2.8.0 |
|
162 |
*/ |
|
163 |
function install_theme_information() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
164 |
global $tab, $themes_allowedtags, $wp_list_table; |
136 | 165 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
166 |
$theme = themes_api( 'theme_information', array( 'slug' => stripslashes( $_REQUEST['theme'] ) ) ); |
136 | 167 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
168 |
if ( is_wp_error( $theme ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
169 |
wp_die( $theme ); |
136 | 170 |
|
171 |
iframe_header( __('Theme Install') ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
172 |
$wp_list_table->theme_installer_single( $theme ); |
136 | 173 |
iframe_footer(); |
174 |
exit; |
|
175 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
176 |
add_action('install_themes_pre_theme-information', 'install_theme_information'); |