~canonical-sysadmins/wordpress/4.2.4

« back to all changes in this revision

Viewing changes to wp-admin/themes.php

  • Committer: Nick Moffitt
  • Date: 2015-01-15 11:05:37 UTC
  • mfrom: (1.1.1 wp4-upstream)
  • Revision ID: nick.moffitt@canonical.com-20150115110537-8bp1y42eyg0jsa7c
Tags: 4.1
MergeĀ upstreamĀ versionĀ 4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
require_once( dirname( __FILE__ ) . '/admin.php' );
11
11
 
12
12
if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
13
 
        wp_die( __( 'Cheatin’ uh?' ) );
 
13
        wp_die( __( 'Cheatin’ uh?' ), 403 );
14
14
 
15
15
if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
16
16
        if ( 'activate' == $_GET['action'] ) {
17
17
                check_admin_referer('switch-theme_' . $_GET['stylesheet']);
18
18
                $theme = wp_get_theme( $_GET['stylesheet'] );
19
19
                if ( ! $theme->exists() || ! $theme->is_allowed() )
20
 
                        wp_die( __( 'Cheatin’ uh?' ) );
 
20
                        wp_die( __( 'Cheatin’ uh?' ), 403 );
21
21
                switch_theme( $theme->get_stylesheet() );
22
22
                wp_redirect( admin_url('themes.php?activated=true') );
23
23
                exit;
25
25
                check_admin_referer('delete-theme_' . $_GET['stylesheet']);
26
26
                $theme = wp_get_theme( $_GET['stylesheet'] );
27
27
                if ( !current_user_can('delete_themes') || ! $theme->exists() )
28
 
                        wp_die( __( 'Cheatin’ uh?' ) );
29
 
                delete_theme($_GET['stylesheet']);
30
 
                wp_redirect( admin_url('themes.php?deleted=true') );
 
28
                        wp_die( __( 'Cheatin’ uh?' ), 403 );
 
29
                $active = wp_get_theme();
 
30
                if ( $active->get( 'Template' ) == $_GET['stylesheet'] ) {
 
31
                        wp_redirect( admin_url( 'themes.php?delete-active-child=true' ) );
 
32
                } else {
 
33
                        delete_theme( $_GET['stylesheet'] );
 
34
                        wp_redirect( admin_url( 'themes.php?deleted=true' ) );
 
35
                }
31
36
                exit;
32
37
        }
33
38
}
119
124
        <h2><?php esc_html_e( 'Themes' ); ?>
120
125
                <span class="title-count theme-count"><?php echo count( $themes ); ?></span>
121
126
        <?php if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
122
 
                <a href="<?php echo admin_url( 'theme-install.php' ); ?>" class="hide-if-no-js add-new-h2"><?php echo esc_html( _x( 'Add New', 'Add new theme' ) ); ?></a>
 
127
                <a href="<?php echo admin_url( 'theme-install.php' ); ?>" class="hide-if-no-js add-new-h2"><?php echo esc_html_x( 'Add New', 'Add new theme' ); ?></a>
123
128
        <?php endif; ?>
124
129
        </h2>
125
130
<?php
133
138
                }
134
139
        elseif ( isset($_GET['deleted']) ) : ?>
135
140
<div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
 
141
<?php elseif ( isset( $_GET['delete-active-child'] ) ) : ?>
 
142
        <div id="message4" class="error"><p><?php _e( 'You cannot delete a theme while it has an active child theme.' ); ?></p></div>
136
143
<?php
137
144
endif;
138
145
 
157
164
                                continue;
158
165
                        // 0 = name, 1 = capability, 2 = file
159
166
                        if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
160
 
                                $class = ' class="current"';
 
167
                                $class = ' current';
161
168
                        if ( !empty($submenu[$item[2]]) ) {
162
169
                                $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
163
170
                                $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
164
171
                                if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
165
 
                                        $current_theme_actions[] = "<a class='button button-secondary' href='admin.php?page={$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
 
172
                                        $current_theme_actions[] = "<a class='button button-secondary$class' href='admin.php?page={$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
166
173
                                else
167
 
                                        $current_theme_actions[] = "<a class='button button-secondary' href='{$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
168
 
                        } else if ( current_user_can($item[1]) ) {
 
174
                                        $current_theme_actions[] = "<a class='button button-secondary$class' href='{$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
 
175
                        } elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
169
176
                                $menu_file = $item[2];
170
 
                                if ( false !== ( $pos = strpos( $menu_file, '?' ) ) )
 
177
 
 
178
                                if ( current_user_can( 'customize' ) ) {
 
179
                                        if ( 'custom-header' === $menu_file ) {
 
180
                                                $current_theme_actions[] = "<a class='button button-secondary hide-if-no-customize$class' href='customize.php?autofocus[control]=header_image'>{$item[0]}</a>";
 
181
                                        } elseif ( 'custom-background' === $menu_file ) {
 
182
                                                $current_theme_actions[] = "<a class='button button-secondary hide-if-no-customize$class' href='customize.php?autofocus[control]=background_image'>{$item[0]}</a>";
 
183
                                        }
 
184
                                }
 
185
 
 
186
                                if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) {
171
187
                                        $menu_file = substr( $menu_file, 0, $pos );
 
188
                                }
 
189
 
172
190
                                if ( file_exists( ABSPATH . "wp-admin/$menu_file" ) ) {
173
 
                                        $current_theme_actions[] = "<a class='button button-secondary' href='{$item[2]}'$class>{$item[0]}</a>";
 
191
                                        $current_theme_actions[] = "<a class='button button-secondary$class' href='{$item[2]}'>{$item[0]}</a>";
174
192
                                } else {
175
 
                                        $current_theme_actions[] = "<a class='button button-secondary' href='themes.php?page={$item[2]}'$class>{$item[0]}</a>";
 
193
                                        $current_theme_actions[] = "<a class='button button-secondary$class' href='themes.php?page={$item[2]}'>{$item[0]}</a>";
176
194
                                }
177
195
                        }
178
196
                }
216
234
                        <a class="button button-primary customize load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Customize' ); ?></a>
217
235
                <?php } ?>
218
236
        <?php } else { ?>
219
 
                <a class="button button-primary activate" href="<?php echo $theme['actions']['activate']; ?>"><?php _e( 'Activate' ); ?></a>
 
237
                <a class="button button-secondary activate" href="<?php echo $theme['actions']['activate']; ?>"><?php _e( 'Activate' ); ?></a>
220
238
                <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
221
 
                        <a class="button button-secondary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
 
239
                        <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
222
240
                        <a class="button button-secondary hide-if-customize" href="<?php echo $theme['actions']['preview']; ?>"><?php _e( 'Preview' ); ?></a>
223
241
                <?php } ?>
224
242
        <?php } ?>
246
264
<h3><?php _e('Broken Themes'); ?></h3>
247
265
<p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
248
266
 
 
267
<?php
 
268
$can_delete = current_user_can( 'delete_themes' );
 
269
?>
249
270
<table>
250
271
        <tr>
251
272
                <th><?php _ex('Name', 'theme name'); ?></th>
252
273
                <th><?php _e('Description'); ?></th>
 
274
                <?php if ( $can_delete ) { ?>
 
275
                        <th></th>
 
276
                <?php } ?>
 
277
                </tr>
253
278
        </tr>
254
 
<?php
255
 
        foreach ( $broken_themes as $broken_theme ) {
256
 
                echo "
 
279
        <?php foreach ( $broken_themes as $broken_theme ) : ?>
257
280
                <tr>
258
 
                         <td>" . ( $broken_theme->get( 'Name' ) ? $broken_theme->get( 'Name' ) : $broken_theme->get_stylesheet() ) . "</td>
259
 
                         <td>" . $broken_theme->errors()->get_error_message() . "</td>
260
 
                </tr>";
261
 
        }
262
 
?>
 
281
                        <td><?php echo $broken_theme->get( 'Name' ) ? $broken_theme->display( 'Name' ) : $broken_theme->get_stylesheet(); ?></td>
 
282
                        <td><?php echo $broken_theme->errors()->get_error_message(); ?></td>
 
283
                        <?php
 
284
                        if ( $can_delete ) {
 
285
                                $stylesheet = $broken_theme->get_stylesheet();
 
286
                                $delete_url = add_query_arg( array(
 
287
                                        'action'     => 'delete',
 
288
                                        'stylesheet' => urlencode( $stylesheet ),
 
289
                                ), admin_url( 'themes.php' ) );
 
290
                                $delete_url = wp_nonce_url( $delete_url, 'delete-theme_' . $stylesheet );
 
291
                                ?>
 
292
                                <td><a href="<?php echo esc_url( $delete_url ); ?>" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a></td>
 
293
                                <?php
 
294
                        }
 
295
                        ?>
 
296
                </tr>
 
297
        <?php endforeach; ?>
263
298
</table>
264
299
</div>
265
300
 
297
332
                        <a class="button button-primary customize load-customize hide-if-no-customize" href="{{ data.actions.customize }}"><?php _e( 'Customize' ); ?></a>
298
333
                <# } #>
299
334
        <# } else { #>
300
 
                <a class="button button-primary activate" href="{{{ data.actions.activate }}}"><?php _e( 'Activate' ); ?></a>
301
 
                <a class="button button-secondary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
 
335
                <a class="button button-secondary activate" href="{{{ data.actions.activate }}}"><?php _e( 'Activate' ); ?></a>
 
336
                <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
302
337
                <a class="button button-secondary hide-if-customize" href="{{{ data.actions.preview }}}"><?php _e( 'Preview' ); ?></a>
303
338
        <# } #>
304
339
 
358
393
                        </div>
359
394
                        <div class="inactive-theme">
360
395
                                <# if ( data.actions.activate ) { #>
361
 
                                        <a href="{{{ data.actions.activate }}}" class="button button-primary activate"><?php _e( 'Activate' ); ?></a>
 
396
                                        <a href="{{{ data.actions.activate }}}" class="button button-secondary activate"><?php _e( 'Activate' ); ?></a>
362
397
                                <# } #>
363
 
                                <a href="{{{ data.actions.customize }}}" class="button button-secondary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
 
398
                                <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
364
399
                                <a href="{{{ data.actions.preview }}}" class="button button-secondary hide-if-customize"><?php _e( 'Preview' ); ?></a>
365
400
                        </div>
366
401