+ * @global WP_Filesystem_Base $wp_filesystem Subclass
+ *
+ * @param string $stylesheet Stylesheet of the theme to delete
+ * @param string $redirect Redirect to page when complete.
+ * @return void|bool|WP_Error When void, echoes content.
+ */
+function delete_theme($stylesheet, $redirect = '') {
+ global $wp_filesystem;
+
+ if ( empty($stylesheet) )
+ return false;
+
+ ob_start();
+ if ( empty( $redirect ) )
+ $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet);
+ if ( false === ($credentials = request_filesystem_credentials($redirect)) ) {
+ $data = ob_get_clean();
+
+ if ( ! empty($data) ){
+ include_once( ABSPATH . 'wp-admin/admin-header.php');
+ echo $data;
+ include( ABSPATH . 'wp-admin/admin-footer.php');
+ exit;
+ }
+ return;
+ }
+
+ if ( ! WP_Filesystem($credentials) ) {
+ request_filesystem_credentials($redirect, '', true); // Failed to connect, Error and request again
+ $data = ob_get_clean();
+
+ if ( ! empty($data) ) {
+ include_once( ABSPATH . 'wp-admin/admin-header.php');
+ echo $data;
+ include( ABSPATH . 'wp-admin/admin-footer.php');
+ exit;
+ }
+ return;
+ }
+
+ if ( ! is_object($wp_filesystem) )
+ return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
+
+ if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
+ return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
+
+ // Get the base plugin folder.
+ $themes_dir = $wp_filesystem->wp_themes_dir();
+ if ( empty( $themes_dir ) ) {
+ return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
+ }
+
+ $themes_dir = trailingslashit( $themes_dir );
+ $theme_dir = trailingslashit( $themes_dir . $stylesheet );
+ $deleted = $wp_filesystem->delete( $theme_dir, true );
+
+ if ( ! $deleted ) {
+ return new WP_Error( 'could_not_remove_theme', sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ) );
+ }
+
+ $theme_translations = wp_get_installed_translations( 'themes' );
+
+ // Remove language files, silently.
+ if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
+ $translations = $theme_translations[ $stylesheet ];
+
+ foreach ( $translations as $translation => $data ) {
+ $wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
+ $wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
+ }
+ }
+
+ // Force refresh of theme update information.
+ delete_site_transient( 'update_themes' );
+
+ return true;
+}
+
+/**
+ * Get the Page Templates available in this theme
+ *
+ * @since 1.5.0
+ *
+ * @param WP_Post|null $post Optional. The post being edited, provided for context.
+ * @return array Key is the template name, value is the filename of the template
+ */
+function get_page_templates( $post = null ) {
+ return array_flip( wp_get_theme()->get_page_templates( $post ) );
+}
+
+/**
+ * Tidies a filename for url display by the theme editor.
+ *
+ * @since 2.9.0
+ * @access private
+ *
+ * @param string $fullpath Full path to the theme file
+ * @param string $containingfolder Path of the theme parent folder
+ * @return string
+ */
+function _get_template_edit_filename($fullpath, $containingfolder) {
+ return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath);
+}
+
+/**
+ * Check if there is an update for a theme available.
+ *
+ * Will display link, if there is an update available.
+ *
+ * @since 2.7.0
+ * @see get_theme_update_available()
+ *
+ * @param WP_Theme $theme Theme data object.
+ */
+function theme_update_available( $theme ) {
+ echo get_theme_update_available( $theme );
+}
+
+/**
+ * Retrieve the update link if there is a theme update available.
+ *
+ * Will return a link if there is an update available.
+ *
+ * @since 3.8.0
+ *
+ * @staticvar object $themes_update
+ *
+ * @param WP_Theme $theme WP_Theme object.
+ * @return false|string HTML for the update link, or false if invalid info was passed.