Skip to content

Commit

Permalink
Added option to replace fonts for the entire website
Browse files Browse the repository at this point in the history
  • Loading branch information
raspi0124 committed Feb 10, 2023
1 parent 0864c5a commit 8508775
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
28 changes: 27 additions & 1 deletion japanese-tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,30 @@ function tinyjpfont_add_default_font()
wp_enqueue_style('tinyjpfont-default-font');
}
}
add_action('init', 'tinyjpfont_add_default_font');
add_action('init', 'tinyjpfont_add_default_font');

//Font for entire site
function tinyjpfont_getwholefonturl()
{
$config6 = get_option('tinyjpfont_whole_font');
$wholefontname = $config6;
if (!isset($config6) || $config6 != "" || $config6 == "noselect") {
//選択されていない場合はとりあえずaddfont.cssを返す
return plugin_dir_url(__FILE__) . "addfont.css";
} else {
$defaultfont_url = plugin_dir_url(__FILE__) . "whole-font-css.php?fn=" . $fontname;
return $defaultfont_url;
}
}
function tinyjpfont_add_whole_font()
{
$config6 = get_option('tinyjpfont_whole_font');
if (!isset($config6) || $config6 != "" || $config6 == "noselect") {
return;
} else {
$wholefont_url = tinyjpfont_getwholefonturl();
wp_register_style('tinyjpfont-whole-font', $wholefont_url);
wp_enqueue_style('tinyjpfont-whole-font');
}
}
add_action('init', 'tinyjpfont_add_whole_font');
21 changes: 21 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,27 @@ function tinyjpfont_options_page()
</td>
</th>
</tr>
<tr>
<th scope="row"><label for="tinyjpfont_whole_font">
<h3>ウェブサイト全体適用フォント</h3>
<p>ウェブサイト全体に適用されるフォントです。</p>
</label></th><br>
<td>
<select name="tinyjpfont_whole_font" id="tinyjpfont_whole_font">
<option value="noselect"
<?php selected("noselect", get_option('tinyjpfont_whole_font')); ?>>
選択しない</option>
<option value="Noto Sans Japanese"
<?php selected("noto", get_option('tinyjpfont_whole_font')); ?>>Noto Sans Japanese
</option>
<option value="Huifont" <?php selected("Huifont", get_option('tinyjpfont_whole_font')); ?>>
ふい字</option>
<option value="kokorom" <?php selected("kokorom", get_option('tinyjpfont_whole_font')); ?>>
こころ明朝体</option>
</select>
</td>
</th>
</tr>
<br>
</table>
<?php submit_button(); ?>
Expand Down
22 changes: 22 additions & 0 deletions whole-font-css.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
header("Content-type: text/css; charset: UTF-8");
if (!isset($_GET["fn"])) {
//なぜかデフォルトフォントが設定されてないのにここに迷い込んできた場合は""
$fontname = "";
}
$fnis = $_GET["fn"];
if ($fnis == "Noto" or $fnis == "noto") {
$fontname = "Noto Sans Japanese";
}
if ($fnis == "Huifont") {
$fontname = "Huifont";
}
if ($fnis == "kokorom") {
$fontname = "kokorom";
} else {
$fontname = "";
}
?>
body {
font-family: <?php echo $fontname; ?>;
}

0 comments on commit 8508775

Please sign in to comment.