protected function get_theme_info_html(WP_Theme $theme)
    {
        $name = $theme->display('Name');
        $version = $theme->display('Version');
        $description = $theme->display('Description');
        $desc_title = esc_attr($theme->get('Description'));
        $author = $theme->display('Author');
        $screenshot = $theme->get_screenshot();
        $thumbnail_style = $screenshot !== false ? sprintf('style="background-image:url(%s);"', $screenshot) : '';
        $theme_url = network_admin_url(add_query_arg('theme', $theme->get_stylesheet(), 'themes.php'));
        $version_label = __('Version:', 'wtaiu');
        $author_label = __('By', 'wtaiu');
        $output = <<<OUTPUT

<div class="theme-info" title="{$desc_title}">
    <a href="{$theme_url}" class="theme-screenshot" {$thumbnail_style}></a>
    <div class="theme-info-wrap">
        <h3 class="theme-info-header" title="{$name}">
            <a href="{$theme_url}" class="theme-name">{$name}</a>
        </h3>
        <p class="theme-version">{$version_label} {$version}</p>
        <p class="theme-author">{$author_label} {$author}</p>
    </div>
</div>

OUTPUT;
        return $output;
    }
Beispiel #2
0
/**
 * Retrieve theme data from parsed theme file.
 *
 * @since 1.5.0
 * @deprecated 3.4.0
 * @deprecated Use wp_get_theme()
 * @see wp_get_theme()
 *
 * @param string $theme_file Theme file path.
 * @return array Theme data.
 */
function get_theme_data($theme_file)
{
    _deprecated_function(__FUNCTION__, '3.4', 'wp_get_theme()');
    $theme = new WP_Theme(basename(dirname($theme_file)), dirname(dirname($theme_file)));
    $theme_data = array('Name' => $theme->get('Name'), 'URI' => $theme->display('ThemeURI', true, false), 'Description' => $theme->display('Description', true, false), 'Author' => $theme->display('Author', true, false), 'AuthorURI' => $theme->display('AuthorURI', true, false), 'Version' => $theme->get('Version'), 'Template' => $theme->get('Template'), 'Status' => $theme->get('Status'), 'Tags' => $theme->get('Tags'), 'Title' => $theme->get('Name'), 'AuthorName' => $theme->get('Author'));
    foreach (apply_filters('extra_theme_headers', array()) as $extra_header) {
        if (!isset($theme_data[$extra_header])) {
            $theme_data[$extra_header] = $theme->get($extra_header);
        }
    }
    return $theme_data;
}
 /**
  * @param WP_Theme $theme
  * @return bool
  */
 public function search_theme($theme)
 {
     // Search the features
     foreach ($this->features as $word) {
         if (!in_array($word, $theme->get('Tags'))) {
             return false;
         }
     }
     // Match all phrases
     foreach ($this->search_terms as $word) {
         if (in_array($word, $theme->get('Tags'))) {
             continue;
         }
         foreach (array('Name', 'Description', 'Author', 'AuthorURI') as $header) {
             // Don't mark up; Do translate.
             if (false !== stripos(strip_tags($theme->display($header, false, true)), $word)) {
                 continue 2;
             }
         }
         if (false !== stripos($theme->get_stylesheet(), $word)) {
             continue;
         }
         if (false !== stripos($theme->get_template(), $word)) {
             continue;
         }
         return false;
     }
     return true;
 }
Beispiel #4
0
function tc_get_theme_data($theme_file)
{
    if (!class_exists('WP_Theme')) {
        return get_theme_data($theme_file);
    }
    $theme = new WP_Theme(basename(dirname($theme_file)), dirname(dirname($theme_file)));
    $theme_data = array('Name' => $theme->get('Name'), 'URI' => $theme->display('ThemeURI', true, false), 'Description' => $theme->display('Description', true, false), 'Author' => $theme->display('Author', true, false), 'AuthorURI' => $theme->display('AuthorURI', true, false), 'Version' => $theme->get('Version'), 'Template' => $theme->get('Template'), 'Status' => $theme->get('Status'), 'Tags' => $theme->get('Tags'), 'Title' => $theme->get('Name'), 'AuthorName' => $theme->display('Author', false, false), 'License' => $theme->display('License', false, false), 'License URI' => $theme->display('License URI', false, false), 'Template Version' => $theme->display('Template Version', false, false));
    return $theme_data;
}
Beispiel #5
0
/**
 * 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
 *
 * @param WP_Theme $theme WP_Theme object.
 * @return false|string HTML for the update link, or false if invalid info was passed.
 */
function get_theme_update_available($theme)
{
    static $themes_update;
    if (!current_user_can('update_themes')) {
        return false;
    }
    if (!isset($themes_update)) {
        $themes_update = get_site_transient('update_themes');
    }
    if (!$theme instanceof WP_Theme) {
        return false;
    }
    $stylesheet = $theme->get_stylesheet();
    $html = '';
    if (isset($themes_update->response[$stylesheet])) {
        $update = $themes_update->response[$stylesheet];
        $theme_name = $theme->display('Name');
        $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.
        $update_url = wp_nonce_url(admin_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet)), 'upgrade-theme_' . $stylesheet);
        $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;"';
        if (!is_multisite()) {
            if (!current_user_can('update_themes')) {
                $html = sprintf('<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>.') . '</strong></p>', $theme_name, esc_url($details_url), esc_attr($theme['Name']), $update['new_version']);
            } elseif (empty($update['package'])) {
                $html = sprintf('<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>') . '</strong></p>', $theme_name, esc_url($details_url), esc_attr($theme['Name']), $update['new_version']);
            } else {
                $html = sprintf('<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a> or <a href="%5$s">update now</a>.') . '</strong></p>', $theme_name, esc_url($details_url), esc_attr($theme['Name']), $update['new_version'], $update_url, $update_onclick);
            }
        }
    }
    return $html;
}
 /**
  * @ticket 26873
  */
 function test_display_method_on_get_method_failure()
 {
     $theme = new WP_Theme('nonexistent', $this->theme_root);
     $this->assertEquals('nonexistent', $theme->get('Name'));
     $this->assertFalse($theme->get('AuthorURI'));
     $this->assertFalse($theme->get('Tags'));
     $this->assertFalse($theme->display('Tags'));
 }
 /**
  * @staticvar string $term
  * @param WP_Theme $theme
  * @return bool
  */
 public function _search_callback($theme)
 {
     static $term;
     if (is_null($term)) {
         $term = wp_unslash($_REQUEST['s']);
     }
     foreach (array('Name', 'Description', 'Author', 'Author', 'AuthorURI') as $field) {
         // Don't mark up; Do translate.
         if (false !== stripos($theme->display($field, false, true), $term)) {
             return true;
         }
     }
     if (false !== stripos($theme->get_stylesheet(), $term)) {
         return true;
     }
     if (false !== stripos($theme->get_template(), $term)) {
         return true;
     }
     return false;
 }
Beispiel #8
0
/**
 * 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.
 */
function get_theme_update_available($theme)
{
    static $themes_update = null;
    if (!current_user_can('update_themes')) {
        return false;
    }
    if (!isset($themes_update)) {
        $themes_update = get_site_transient('update_themes');
    }
    if (!$theme instanceof WP_Theme) {
        return false;
    }
    $stylesheet = $theme->get_stylesheet();
    $html = '';
    if (isset($themes_update->response[$stylesheet])) {
        $update = $themes_update->response[$stylesheet];
        $theme_name = $theme->display('Name');
        $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.
        $update_url = wp_nonce_url(admin_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet)), 'upgrade-theme_' . $stylesheet);
        if (!is_multisite()) {
            if (!current_user_can('update_themes')) {
                /* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
                $html = sprintf('<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.') . '</strong></p>', $theme_name, esc_url($details_url), sprintf('class="thickbox open-plugin-details-modal" aria-label="%s"', esc_attr(sprintf(__('View %1$s version %2$s details'), $theme_name, $update['new_version']))), $update['new_version']);
            } elseif (empty($update['package'])) {
                /* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
                $html = sprintf('<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>') . '</strong></p>', $theme_name, esc_url($details_url), sprintf('class="thickbox open-plugin-details-modal" aria-label="%s"', esc_attr(sprintf(__('View %1$s version %2$s details'), $theme_name, $update['new_version']))), $update['new_version']);
            } else {
                /* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
                $html = sprintf('<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.') . '</strong></p>', $theme_name, esc_url($details_url), sprintf('class="thickbox open-plugin-details-modal" aria-label="%s"', esc_attr(sprintf(__('View %1$s version %2$s details'), $theme_name, $update['new_version']))), $update['new_version'], $update_url, sprintf('aria-label="%s" id="update-theme" data-slug="%s"', esc_attr(sprintf(__('Update %s now'), $theme_name)), $stylesheet));
            }
        }
    }
    return $html;
}
 /**
  * Handles the description column output.
  *
  * @since 4.3.0
  * @access public
  *
  * @global string $status
  * @global array  $totals
  *
  * @param WP_Theme $theme The current WP_Theme object.
  */
 public function column_description($theme)
 {
     global $status, $totals;
     if ($theme->errors()) {
         $pre = $status == 'broken' ? __('Broken Theme:') . ' ' : '';
         echo '<p><strong class="error-message">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
     }
     if ($this->is_site_themes) {
         $allowed = $theme->is_allowed('site', $this->site_id);
     } else {
         $allowed = $theme->is_allowed('network');
     }
     $class = !$allowed ? 'inactive' : 'active';
     if (!empty($totals['upgrade']) && !empty($theme->update)) {
         $class .= ' update';
     }
     echo "<div class='theme-description'><p>" . $theme->display('Description') . "</p></div>\n\t\t\t<div class='{$class} second theme-version-author-uri'>";
     $stylesheet = $theme->get_stylesheet();
     $theme_meta = array();
     if ($theme->get('Version')) {
         $theme_meta[] = sprintf(__('Version %s'), $theme->display('Version'));
     }
     $theme_meta[] = sprintf(__('By %s'), $theme->display('Author'));
     if ($theme->get('ThemeURI')) {
         $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__('Visit theme homepage') . '">' . __('Visit Theme Site') . '</a>';
     }
     /**
      * Filter the array of row meta for each theme in the Multisite themes
      * list table.
      *
      * @since 3.1.0
      *
      * @param array    $theme_meta An array of the theme's metadata,
      *                             including the version, author, and
      *                             theme URI.
      * @param string   $stylesheet Directory name of the theme.
      * @param WP_Theme $theme      WP_Theme object.
      * @param string   $status     Status of the theme.
      */
     $theme_meta = apply_filters('theme_row_meta', $theme_meta, $stylesheet, $theme, $status);
     echo implode(' | ', $theme_meta);
     echo '</div>';
 }
Beispiel #10
0
/**
 * Retrieve theme data from parsed theme file.
 *
 * @since 1.5.0
 * @deprecated 3.4.0
 * @deprecated Use wp_get_theme()
 * @see wp_get_theme()
 *
 * @param string $theme_file Theme file path.
 * @return array Theme data.
 */
function get_theme_data($theme_file)
{
    _deprecated_function(__FUNCTION__, 3.4, 'wp_get_theme()');
    $theme = new WP_Theme(basename(dirname($theme_file)), dirname(dirname($theme_file)));
    $theme_data = array('Name' => $theme->get('Name'), 'URI' => $theme->display('ThemeURI', true, false), 'Description' => $theme->display('Description', true, false), 'Author' => $theme->display('Author', true, false), 'AuthorURI' => $theme->display('AuthorURI', true, false), 'Version' => $theme->get('Version'), 'Template' => $theme->get('Template'), 'Status' => $theme->get('Status'), 'Tags' => $theme->get('Tags'), 'Title' => $theme->get('Name'), 'AuthorName' => $theme->display('Author', false, false));
    return $theme_data;
}
Beispiel #11
0
/**
 * 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.
 */
function get_theme_update_available($theme)
{
    static $themes_update = null;
    if (!current_user_can('update_themes')) {
        return false;
    }
    if (!isset($themes_update)) {
        $themes_update = get_site_transient('update_themes');
    }
    if (!$theme instanceof WP_Theme) {
        return false;
    }
    $stylesheet = $theme->get_stylesheet();
    $html = '';
    if (isset($themes_update->response[$stylesheet])) {
        $update = $themes_update->response[$stylesheet];
        $theme_name = $theme->display('Name');
        $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.
        $update_url = wp_nonce_url(admin_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet)), 'upgrade-theme_' . $stylesheet);
        if (!current_user_can('update_themes')) {
            /* translators: 1: theme name, 2: theme details URL, 3: theme version number */
            $html = sprintf('<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox">View version %3$s details</a>.') . '</strong></p>', $theme_name, esc_url($details_url), $update['new_version']);
        } elseif (empty($update['package'])) {
            /* translators: 1: theme name, 2: theme details URL, 3: theme version number */
            $html = sprintf('<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox">View version %3$s details</a>. <em>Automatic update is unavailable for this theme.</em>') . '</strong></p>', $theme_name, esc_url($details_url), $update['new_version']);
        } else {
            /* translators: 1: theme name, 2: theme details URL, 3: theme version number, 4: theme update URL */
            $html = sprintf('<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox">View version %3$s details</a> or <a href="%4$s">update now</a>.') . '</strong></p>', $theme_name, esc_url($details_url), $update['new_version'], $update_url);
        }
    }
    return $html;
}