/**
  * @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;
 }
 /**
  * Returns field from theme data if cookie is set to valid theme.
  *
  * @param string $field_name
  * @param mixed  $default
  *
  * @deprecated :2.0
  *
  * @return mixed
  */
 public static function get_theme_field($field_name, $default = false)
 {
     if (!empty(self::$theme)) {
         return self::$theme->get($field_name);
     }
     return $default;
 }
    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;
    }
 /**
  * Constructor.
  *
  * @param string $store_url  This is the URL to your store.
  * @param int    $product_id This is the product ID of your plugin.
  * @param array  $args       Additional args.
  *
  * @throws Exception
  */
 public function __construct($store_url, $product_id, $args = array())
 {
     $this->store_url = trailingslashit($store_url);
     $this->product_id = $product_id;
     $this->theme = wp_get_theme();
     if (empty($args['version'])) {
         $this->version = $this->theme->get('Version');
     } else {
         $this->version = $args['version'];
     }
     if ($args['key']) {
         $this->key = $args['key'];
     }
     if ($args['activation_id']) {
         $this->id = absint($args['activation_id']);
     }
     add_filter('pre_set_site_transient_update_themes', array($this, 'check_for_update'));
     add_action("in_theme_update_message-{$this->theme->get_stylesheet()}", array($this, 'show_upgrade_notice_on_list'), 10, 2);
 }
Example #5
0
 /**
  * Returns the version of the the current theme.
  * 
  * @return string
  *   The version of the current theme.
  * 
  * @ingroup helperfunc
  */
 function get_theme_version()
 {
     if (class_exists('WP_Theme')) {
         $theme = new WP_Theme(get_theme_name(), get_theme_root());
         return $theme->get('Version');
     } else {
         $theme_data = get_theme_data(get_template_directory() . '/style.css');
         return $theme_data['Version'];
     }
 }
 public static function resolveLanguagesPath(\WP_Theme $theme)
 {
     // as taken from wp-includes/class-wp-theme.php:1114
     $path = $theme->get_stylesheet_directory();
     if ($domainpath = $theme->get('DomainPath')) {
         $path .= $domainpath;
     } else {
         $path .= '/languages';
     }
     return $path;
 }
Example #7
0
 /**
  * @ticket 20313
  */
 function test_new_WP_Theme_subdir_bad_root()
 {
     // This is what get_theme_data() does when you pass it a style.css file for a theme in a subdir.
     $theme = new WP_Theme('theme2', $this->theme_root . '/subdir');
     //Meta
     $this->assertEquals('My Subdir Theme', $theme->get('Name'));
     $this->assertEquals('http://example.org/', $theme->get('ThemeURI'));
     $this->assertEquals('An example theme in a sub directory', $theme->get('Description'));
     $this->assertEquals('Mr. WordPress', $theme->get('Author'));
     $this->assertEquals('http://wordpress.org/', $theme->get('AuthorURI'));
     $this->assertEquals('0.1', $theme->get('Version'));
     $this->assertEquals('', $theme->get('Template'));
     $this->assertEquals('publish', $theme->get('Status'));
     $this->assertEquals(array(), $theme->get('Tags'));
     //Important
     $this->assertEquals('subdir/theme2', $theme->get_stylesheet());
     $this->assertEquals('subdir/theme2', $theme->get_template());
 }
Example #8
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;
}
 /**
  * Method to implement ArrayAccess for keys formerly returned by get_themes()
  */
 public function offsetGet($offset)
 {
     switch ($offset) {
         case 'Name':
         case 'Version':
         case 'Status':
             return $this->get($offset);
         case 'Title':
             return $this->get('Name');
             // Author, Author Name, Author URI, and Description did not
             // previously return translated data. We are doing so now.
             // Title and Name could have been used as the key for get_themes(),
             // so both to remain untranslated for back compatibility.
         // Author, Author Name, Author URI, and Description did not
         // previously return translated data. We are doing so now.
         // Title and Name could have been used as the key for get_themes(),
         // so both to remain untranslated for back compatibility.
         case 'Author':
             return $this->display('Author');
         case 'Author Name':
             return $this->display('Author', false);
         case 'Author URI':
             return $this->display('AuthorURI');
         case 'Description':
             return $this->display('Description');
         case 'Template':
             return $this->get_template();
         case 'Stylesheet':
             return $this->get_stylesheet();
         case 'Template Files':
             $files = $this->get_files('php');
             foreach ($files as &$file) {
                 $file = $this->theme_root . '/' . $file;
             }
             return $files;
         case 'Stylesheet Files':
             $files = $this->get_files('css');
             foreach ($files as &$file) {
                 $file = $this->theme_root . '/' . $file;
             }
             return $files;
         case 'Template Dir':
             return $this->get_template_directory();
         case 'Stylesheet Dir':
             return $this->get_stylesheet_directory();
         case 'Screenshot':
             return $this->get_screenshot('relative');
         case 'Tags':
             return $this->get('Tags');
         case 'Theme Root':
             return $this->get_theme_root();
         case 'Theme Root URI':
             return $this->get_theme_root_uri();
         case 'Parent Theme':
             return $this->parent ? $this->parent->get('Name') : '';
         default:
             return null;
     }
 }
 /**
  * @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'));
 }
Example #11
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;
}
Example #12
0
 /**
  * Do a several Clean Up
  *
  * @brief Clean Up
  */
 public function _init()
 {
     /* Text Domain */
     if ($this->setup->autoload_text_domain) {
         load_theme_textdomain($this->theme->get('TextDomain'), trailingslashit(TEMPLATEPATH) . $this->theme->get('DomainPath'));
     }
     /* Clean up wp_head */
     if ($this->setup->cleanup_wp_head) {
         remove_action('wp_head', 'feed_links_extra', 3);
         // Category Feeds
         remove_action('wp_head', 'feed_links', 2);
         // Post and Comment Feeds
         remove_action('wp_head', 'rsd_link');
         // EditURI link
         remove_action('wp_head', 'wlwmanifest_link');
         // Windows Live Writer
         remove_action('wp_head', 'index_rel_link');
         // index link
         remove_action('wp_head', 'parent_post_rel_link', 10, 0);
         // previous link
         remove_action('wp_head', 'start_post_rel_link', 10, 0);
         // start link
         remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
         // Links for Adjacent Posts
         remove_action('wp_head', 'wp_generator');
         // WP vers
     }
 }
 /**
  * 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>';
 }
Example #14
0
	/**
	 * If theme is in list of allowed to be switched to.
	 *
	 * @param WP_Theme $theme
	 *
	 * @return bool
	 */
	static function is_allowed( $theme ) {

		return array_key_exists( $theme->get( 'Name' ), self::get_allowed_themes() );
	}
 /**
  * Prepare item for response
  *
  * @param WP_Theme $item
  * @param WP_REST_Request $request
  *
  * @return array
  */
 public function prepare_item_for_response($item, $request)
 {
     return array('name' => $item->get('Name'), 'slug' => $item->slug, 'version' => $item->get('Version'), 'description' => $item->get('Description'), 'author' => $item->get('Author'), 'author_uri' => $item->get('AuthorURI'), 'text_domain' => $item->get('TextDomain'), 'domain_path' => $item->get('DomainPath'), 'tags' => $item->get('Tags'));
 }
 /**
  * _theme_to_array method
  *
  * Convert `WP_Theme` object to map of useful properties.
  *
  * @param WP_Theme $theme Theme to convert to array
  *
  * @return array Map of theme information keys
  */
 protected function _theme_to_array(WP_Theme $theme)
 {
     static $keys = array('Name', 'ThemeURI', 'Description', 'Author', 'AuthorURI', 'Version', 'Template', 'Status', 'TextDomain', 'DomainPath');
     $remapped = array();
     foreach ($keys as $key) {
         $remapped[$key] = $theme->get($key);
     }
     return $remapped;
 }
Example #17
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;
}
/**
 * Get theme version number from WP_Theme object (cached)
 *
 * @since Wall Street 1.0
*/
function wallstreet_get_theme_version()
{
    $wallstreet_theme_file = get_template_directory() . '/style.css';
    $wallstreet_theme = new WP_Theme(basename(dirname($wallstreet_theme_file)), dirname(dirname($wallstreet_theme_file)));
    return $wallstreet_theme->get('Version');
}
Example #19
0
 /**
  * Returns if the $theme is a match for the search.
  *
  * @param WP_Theme $theme
  * @param array $search
  * @param array $features
  *
  * @return boolean
  */
 public function theme_matches($theme, array $search, array $features)
 {
     static $fields = array('Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet');
     $tags = array_map('sanitize_title_with_dashes', $theme['Tags']);
     // Match all phrases
     if (count($search) > 0) {
         foreach ($search as $word) {
             // In a tag?
             if (!in_array($word, $tags)) {
                 return false;
             }
             // In one of the fields?
             foreach ($fields as $field) {
                 if (false === stripos($theme->get($field), $word)) {
                     return false;
                 }
             }
         }
     }
     // Now search the features
     if (count($features) > 0) {
         foreach ($features as $word) {
             // In a tag?
             if (!in_array($word, $tags)) {
                 return false;
             }
         }
     }
     // Only get here if each word exists in the tags or one of the fields
     return true;
 }
Example #20
0
 /**
  * Check to see if the current page is webcomic-related.
  * 
  * We have to do this as early as possible to ensure that the
  * correct template can be set if the collection is using a custom
  * theme. Unfortunately, this means checking even before any
  * conditional tags are available.
  * 
  * @uses Webcomic::$config
  * @uses Webcomic::$integrate
  * @uses Webcomic::$collection
  * @hook setup_theme
  */
 public function setup_theme()
 {
     global $wp_rewrite;
     $match = $permalinks = array();
     if ($wp_rewrite->using_permalinks()) {
         $tokens = array('%year%' => '(?P<year>\\d{4})', '%monthnum%' => '(?P<monthnum>0[1-9]|1[012])', '%day%' => '(?P<day>0[1-9]|[12][0-9]|3[01])', '%hour%' => '(?P<hour>0[0-9]|1[0-9]|2[0-3])', '%minute%' => '(?P<minute>0[1-9]|[1-5][0-9])', '%second%' => '(?P<second>0[1-9]|[1-5][0-9])', '%post_id%' => '(?P<post_id>\\d+)', '%author%' => '(?P<author>[\\w-]+)');
         foreach (self::$config['collections'] as $k => $v) {
             $tokens["%{$k}_storyline%"] = "(?P<{$k}_storyline>([\\w-]+/?)+)";
             $permalinks["{$k}_archive"] = $v['slugs']['archive'];
             $permalinks["{$k}_webcomic"] = str_replace(array_keys($tokens), $tokens, $v['slugs']['webcomic']);
             $permalinks["{$k}_storyline"] = $v['slugs']['storyline'];
             $permalinks["{$k}_character"] = $v['slugs']['character'];
         }
     }
     if ((preg_match('/webcomic\\d+(_(storyline|character))?/', implode(' ', array_keys($_GET)), $match) or isset($_GET['post_type']) and isset(self::$config['collections'][$_GET['post_type']]) and $match[0] = $_GET['post_type'] or $wp_rewrite->using_permalinks() and preg_match('{/(' . implode('|', $permalinks) . ')/}', $_SERVER['REQUEST_URI'], $match) or $id = url_to_postid($_SERVER['REQUEST_URI']) and $match[0] = get_post_meta($id, 'webcomic_collection', true) and isset(self::$config['collections'][$match[0]])) and $match) {
         if (2 < count($match) and $permalinks) {
             foreach ($permalinks as $k => $v) {
                 if (false !== strpos($k, '_webcomic') and preg_match('{' . $v . '}', $match[1])) {
                     self::$collection = str_replace('_webcomic', '', $k);
                     break;
                 }
             }
         } else {
             $match[0] = preg_replace('/_(storyline|character)$/', '', $match[0]);
             self::$collection = empty(self::$config['collections'][$match[0]]) ? preg_replace('/_(archive|webcomic|storyline|character)$/', '', array_search($match[1], $permalinks)) : $match[0];
         }
     }
     $active_theme = new WP_Theme(get_stylesheet_directory(), '');
     self::$integrate = !$active_theme->get('Webcomic');
 }
 protected function outputThemeInfo($theme)
 {
     $theme_path = wordpress_path('wp-content/themes/') . $theme;
     // check
     if (!file_exists($theme_path)) {
         throw new \InvalidArgumentException("Theme '{$theme}' is not found.");
     }
     $theme_object = new \WP_Theme($theme, dirname($theme_path));
     //        // MEMO: template_dir べ搌じ
     //        $this->line("<info>[path]</info> '{$theme_path}'");
     $properties_wordpress = ['name', 'title', 'version', 'parent_theme', 'template_dir', 'stylesheet_dir', 'template', 'stylesheet', 'screenshot', 'description', 'author', 'tags', 'theme_root', 'theme_root_uri'];
     foreach ($properties_wordpress as $property) {
         $value = $theme_object->{$property};
         if (is_array($value)) {
             $value = '[' . implode(', ', $value) . ']';
         }
         $this->line("<info>[{$property}]</info> {$value}");
     }
     $properties_extra = ['php_namespace' => 'PHP Namespace'];
     foreach ($properties_extra as $property => $field) {
         $value = $theme_object->get($field);
         if (is_array($value)) {
             $value = '[' . implode(', ', $value) . ']';
         }
         $this->line("<info>[{$property}]</info> {$value}");
     }
 }
Example #22
0
 /**
  * Is a compatible version of Webcomic installed?
  * 
  * This is mostly useful to verify that a compatible version of
  * Webcomic is installed when constructing Webcomic-ready themes,
  * but we can also check for an arbitrary version if necessary.
  * 
  * @param string $version Minimum version to check for. Defaults to the active themes version.
  * @return boolean
  * @uses Webcomic::$version
  * @uses Webcomic::$theme_version
  */
 public static function webcomic($version = '')
 {
     if (empty($version)) {
         $directory = get_stylesheet_directory();
         $theme = new WP_Theme(basename($directory), dirname($directory));
         $version = $theme->get('Webcomic');
     }
     return $version and version_compare(self::$version, $version, '>=');
 }