Skip to content

Commit

Permalink
Theme API in "functions.php" no longer requires its theme name as a s…
Browse files Browse the repository at this point in the history
…uffix (improvement #969)
  • Loading branch information
mystralkk committed Sep 12, 2019
1 parent 08f2709 commit 9d45d69
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
6 changes: 6 additions & 0 deletions public_html/docs/english/theme.html
Expand Up @@ -203,6 +203,12 @@ <h3><a name="tips">Tips and tricks</a></h3>

<h2><a id="changes">Changes</a></h2>

<h2><a name="changes221">Theme changes in Geeklog 2.2.1</a></h2>

<ul>
<li>Theme API in a theme's "functions.php" no longer requires the theme name as its suffix. For example, theme_config_mytheme() is still valid, but theme_config() is accepted as well. This change will be useful especially when creating a child theme.</li>
</ul>

<h2><a name="changes220">Theme changes in Geeklog 2.2.0</a></h2>

<ul>
Expand Down
6 changes: 6 additions & 0 deletions public_html/docs/japanese/theme.html
Expand Up @@ -110,6 +110,12 @@ <h3><a name="tips">ヒントと注意点</a></h3>

<h2><a id="changes">変更点</a></h2>

<h2><a name="changes221">Geeklog 2.2.1におけるテーマの変更点</a></h2>

<ul>
<li>"functions.php"中のAPIがテーマ名を接尾辞として必要としなくなりました。たとえば、theme_config_mytheme()は依然として有効ですが、theme_config()も受け入れられるようになりました。この変更は特に子テーマを作るときに役立つでしょう。</li>
</ul>

<h2><a name="changes220">Geeklog 2.2.0におけるテーマの変更点</a></h2>

<ul>
Expand Down
43 changes: 36 additions & 7 deletions public_html/lib-common.php
Expand Up @@ -308,8 +308,13 @@
$_CONF['theme_etag'] = false;
$_CONF['theme_plugins'] = ''; // Default is none - CANNOT be a child theme
$_CONF['theme_options'] = array(); // Default is empty array
$func = "theme_config_" . $_CONF['theme'];
if (function_exists($func)) {

$func = 'theme_config_' . $_CONF['theme'];
if (!is_callable($func)) {
$func = 'theme_config';
}

if (is_callable($func)) {
$theme_config = $func();
$_CONF['doctype'] = $theme_config['doctype'];
$_IMAGE_TYPE = $theme_config['image_type'];
Expand Down Expand Up @@ -462,7 +467,11 @@

// Include scripts on behalf of the theme
$func = 'theme_css_' . $_CONF['theme'];
if (function_exists($func)) {
if (!is_callable($func)) {
$func = 'theme_css';
}

if (is_callable($func)) {
foreach ($func() as $info) {
$file = (!empty($info['file'])) ? $info['file'] : '';
$name = (!empty($info['name'])) ? $info['name'] : md5(!empty($file) ? $file : strval(time()));
Expand All @@ -472,8 +481,13 @@
$_SCRIPTS->setCSSFile($name, $file, $constant, $attributes, $priority, 'theme');
}
}

$func = 'theme_js_libs_' . $_CONF['theme'];
if (function_exists($func)) {
if (!is_callable($func)) {
$func = 'theme_js_libs';
}

if (is_callable($func)) {
foreach ($func() as $info) {
$footer = true;
if (isset($info['footer']) && !$info['footer']) {
Expand All @@ -482,8 +496,13 @@
$_SCRIPTS->setJavaScriptLibrary($info['library'], $footer);
}
}

$func = 'theme_js_files_' . $_CONF['theme'];
if (function_exists($func)) {
if (!is_callable($func)) {
$func = 'theme_js_files';
}

if (is_callable($func)) {
foreach ($func() as $info) {
$footer = true;
if (isset($info['footer']) && !$info['footer']) {
Expand All @@ -493,8 +512,13 @@
$_SCRIPTS->setJavaScriptFile(md5($info['file']), $info['file'], $footer, $priority);
}
}

$func = 'theme_js_' . $_CONF['theme'];
if (function_exists($func)) {
if (!is_callable($func)) {
$func = 'theme_js';
}

if (is_callable($func)) {
foreach ($func() as $info) {
$wrap = true;
if (isset($info['wrap']) && !$info['wrap']) {
Expand All @@ -507,8 +531,13 @@
$_SCRIPTS->setJavaScript($info['code'], $wrap, $footer);
}
}

$func = 'theme_init_' . $_CONF['theme'];
if (function_exists($func)) {
if (!is_callable($func)) {
$func = 'theme_init';
}

if (is_callable($func)) {
$func();
}
unset($theme_config, $func);
Expand Down

0 comments on commit 9d45d69

Please sign in to comment.