Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/theme.php

    r14411 r17264  
    1010 * {@internal Missing Short Description}}
    1111 *
    12  * @since unknown
     12 * @since 2.0.0
    1313 *
    1414 * @return unknown
     
    4444 *
    4545 * @param string $template Template directory of the theme to delete
     46 * @param string $redirect Redirect to page when complete.
    4647 * @return mixed
    4748 */
    48 function delete_theme($template) {
     49function delete_theme($template, $redirect = '') {
    4950    global $wp_filesystem;
    5051
     
    5354
    5455    ob_start();
    55     $url = wp_nonce_url('themes.php?action=delete&template=' . $template, 'delete-theme_' . $template);
    56     if ( false === ($credentials = request_filesystem_credentials($url)) ) {
     56    if ( empty( $redirect ) )
     57        $redirect = wp_nonce_url('themes.php?action=delete&template=' . $template, 'delete-theme_' . $template);
     58    if ( false === ($credentials = request_filesystem_credentials($redirect)) ) {
    5759        $data = ob_get_contents();
    5860        ob_end_clean();
     
    107109 * {@internal Missing Short Description}}
    108110 *
    109  * @since unknown
     111 * @since 1.5.0
    110112 *
    111113 * @return unknown
     
    160162 * Get the Page Templates available in this theme
    161163 *
    162  * @since unknown
     164 * @since 1.5.0
    163165 *
    164166 * @return array Key is template name, Value is template name
     
    240242        $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
    241243        $update_url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
    242         $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Upgrading this theme will lose any customizations you have made.  'Cancel' to stop, 'OK' to upgrade.") ) . '\') ) {return true;}return false;"';
    243 
    244         if ( ! current_user_can('update_themes') )
    245             printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
    246         else if ( empty($update['package']) )
    247             printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> <em>automatic upgrade unavailable for this theme</em>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
    248         else
    249             printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> or <a href="%4$s" %5$s>upgrade automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
    250     }
     244        $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Updating this theme will lose any customizations you have made.  'Cancel' to stop, 'OK' to update.") ) . '\') ) {return true;}return false;"';
     245
     246        if ( !is_multisite() ) {
     247            if ( ! current_user_can('update_themes') )
     248                printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
     249            else if ( empty($update['package']) )
     250                printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>. <em>Automatic update is unavailable for this theme.</em>') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
     251            else
     252                printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a> or <a href="%4$s" %5$s>update automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
     253        }
     254    }
     255}
     256
     257/**
     258 * Retrieve list of WordPress theme features (aka theme tags)
     259 *
     260 * @since 3.1.0
     261 *
     262 * @return array  Array of features keyed by category with translations keyed by slug.
     263 */
     264function get_theme_feature_list() {
     265    // Hard-coded list is used if api not accessible.
     266    $features = array(
     267            __('Colors') => array(
     268                'black'   => __( 'Black' ),
     269                'blue'    => __( 'Blue' ),
     270                'brown'   => __( 'Brown' ),
     271                'green'   => __( 'Green' ),
     272                'orange'  => __( 'Orange' ),
     273                'pink'    => __( 'Pink' ),
     274                'purple'  => __( 'Purple' ),
     275                'red'     => __( 'Red' ),
     276                'silver'  => __( 'Silver' ),
     277                'tan'     => __( 'Tan' ),
     278                'white'   => __( 'White' ),
     279                'yellow'  => __( 'Yellow' ),
     280                'dark'    => __( 'Dark' ),
     281                'light'   => __( 'Light ')
     282            ),
     283
     284        __('Columns') => array(
     285            'one-column'    => __( 'One Column' ),
     286            'two-columns'   => __( 'Two Columns' ),
     287            'three-columns' => __( 'Three Columns' ),
     288            'four-columns'  => __( 'Four Columns' ),
     289            'left-sidebar'  => __( 'Left Sidebar' ),
     290            'right-sidebar' => __( 'Right Sidebar' )
     291        ),
     292
     293        __('Width') => array(
     294            'fixed-width'    => __( 'Fixed Width' ),
     295            'flexible-width' => __( 'Flexible Width' )
     296        ),
     297
     298        __( 'Features' ) => array(
     299            'blavatar'             => __( 'Blavatar' ),
     300            'buddypress'           => __( 'BuddyPress' ),
     301            'custom-background'    => __( 'Custom Background' ),
     302            'custom-colors'        => __( 'Custom Colors' ),
     303            'custom-header'        => __( 'Custom Header' ),
     304            'custom-menu'          => __( 'Custom Menu' ),
     305            'editor-style'         => __( 'Editor Style' ),
     306            'front-page-post-form' => __( 'Front Page Posting' ),
     307            'microformats'         => __( 'Microformats' ),
     308            'sticky-post'          => __( 'Sticky Post' ),
     309            'theme-options'        => __( 'Theme Options' ),
     310            'threaded-comments'    => __( 'Threaded Comments' ),
     311            'translation-ready'    => __( 'Translation Ready' ),
     312            'rtl-language-support' => __( 'RTL Language Support' )
     313        ),
     314
     315        __( 'Subject' )  => array(
     316            'holiday' => __( 'Holiday' ),
     317            'photoblogging' => __( 'Photoblogging' ),
     318            'seasonal' => __( 'Seasonal' )
     319        )
     320    );
     321
     322    if ( !current_user_can('install_themes') )
     323        return $features;
     324
     325    if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) )
     326        set_site_transient( 'wporg_theme_feature_list', array( ),  10800);
     327
     328    if ( !$feature_list ) {
     329        $feature_list = themes_api( 'feature_list', array( ) );
     330        if ( is_wp_error( $feature_list ) )
     331            return $features;
     332    }
     333
     334    if ( !$feature_list )
     335        return $features;
     336
     337    set_site_transient( 'wporg_theme_feature_list', $feature_list, 10800 );
     338
     339    $category_translations = array( 'Colors' => __('Colors'), 'Columns' => __('Columns'), 'Width' => __('Width'),
     340                                   'Features' => __('Features'), 'Subject' => __('Subject') );
     341
     342    // Loop over the wporg canonical list and apply translations
     343    $wporg_features = array();
     344    foreach ( (array) $feature_list as $feature_category => $feature_items ) {
     345        if ( isset($category_translations[$feature_category]) )
     346            $feature_category = $category_translations[$feature_category];
     347        $wporg_features[$feature_category] = array();
     348
     349        foreach ( $feature_items as $feature ) {
     350            if ( isset($features[$feature_category][$feature]) )
     351                $wporg_features[$feature_category][$feature] = $features[$feature_category][$feature];
     352            else
     353                $wporg_features[$feature_category][$feature] = $feature;
     354        }
     355    }
     356
     357    return $wporg_features;
     358}
     359
     360/**
     361 * Retrieve theme installer pages from WordPress Themes API.
     362 *
     363 * It is possible for a theme to override the Themes API result with three
     364 * filters. Assume this is for themes, which can extend on the Theme Info to
     365 * offer more choices. This is very powerful and must be used with care, when
     366 * overridding the filters.
     367 *
     368 * The first filter, 'themes_api_args', is for the args and gives the action as
     369 * the second parameter. The hook for 'themes_api_args' must ensure that an
     370 * object is returned.
     371 *
     372 * The second filter, 'themes_api', is the result that would be returned.
     373 *
     374 * @since 2.8.0
     375 *
     376 * @param string $action
     377 * @param array|object $args Optional. Arguments to serialize for the Theme Info API.
     378 * @return mixed
     379 */
     380function themes_api($action, $args = null) {
     381
     382    if ( is_array($args) )
     383        $args = (object)$args;
     384
     385    if ( !isset($args->per_page) )
     386        $args->per_page = 24;
     387
     388    $args = apply_filters('themes_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
     389    $res = apply_filters('themes_api', false, $action, $args); //NOTE: Allows a theme to completely override the builtin WordPress.org API.
     390
     391    if ( ! $res ) {
     392        $request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
     393        if ( is_wp_error($request) ) {
     394            $res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
     395        } else {
     396            $res = unserialize($request['body']);
     397            if ( ! $res )
     398            $res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), $request['body']);
     399        }
     400    }
     401    //var_dump(array($args, $res));
     402    return apply_filters('themes_api_result', $res, $action, $args);
    251403}
    252404
Note: See TracChangeset for help on using the changeset viewer.