<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Function &#8211; WordPress Memo</title>
	<atom:link href="https://blog.riverforest-wp.info/category/function/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.riverforest-wp.info</link>
	<description>WordPress に関する覚え書き</description>
	<lastBuildDate>Fri, 09 May 2025 12:48:52 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.riverforest-wp.info/wp-content/uploads/2018/05/cropped-icon-256x256-1-32x32.png</url>
	<title>Function &#8211; WordPress Memo</title>
	<link>https://blog.riverforest-wp.info</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WordPress での CSV 出力について</title>
		<link>https://blog.riverforest-wp.info/wp-csv-export-function/</link>
		
		<dc:creator><![CDATA[Katsushi Kawamori]]></dc:creator>
		<pubDate>Wed, 20 Dec 2023 12:44:23 +0000</pubDate>
				<category><![CDATA[Function]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[SplFileObject]]></category>
		<category><![CDATA[WP_Filesystem]]></category>
		<guid isPermaLink="false">https://blog.riverforest-wp.info/?p=3619</guid>

					<description><![CDATA[はじめに 最近、Plugin Check というプラグインチームが作成したプラグインで自分のプラグインをチェックしているのですが、以下の様な警告が出てきます。 「json_encode を、wp_json_encode  [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">はじめに</h3>



<p>最近、<strong>Plugin Check</strong> というプラグインチームが作成したプラグインで自分のプラグインをチェックしているのですが、以下の様な警告が出てきます。</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc632d99bce&quot;}" data-wp-interactive="core/image" data-wp-key="69cc632d99bce" class="wp-block-image aligncenter size-full wp-lightbox-container"><img fetchpriority="high" loading="eager" decoding="async" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" width="860" height="758" src="https://blog.riverforest-wp.info/wp-content/uploads/20231220/plugincheck_bad.png" alt="" class="wp-image-3629" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20231220/plugincheck_bad.png 860w, https://blog.riverforest-wp.info/wp-content/uploads/20231220/plugincheck_bad-300x264.png 300w, https://blog.riverforest-wp.info/wp-content/uploads/20231220/plugincheck_bad-768x677.png 768w" sizes="(max-width: 860px) 100vw, 860px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>「<a href="https://www.php.net/manual/ja/function.json-encode.php">json_encode</a> を、<a href="https://developer.wordpress.org/reference/functions/wp_json_encode/">wp_json_encode</a> にしなさい」というのと、「<a href="https://www.php.net/manual/ja/function.fopen.php">fopen</a>、<a href="https://www.php.net/manual/ja/function.fclose.php">fclose</a>、<a href="https://www.php.net/manual/ja/function.fputcsv.php">fputcsv</a> などの php のファイルシステムは使用せずに、<a href="https://developer.wordpress.org/reference/functions/wp_filesystem/">WP_Filesystem</a> を使用しなさい」というのが主です。</p>



<div class="pluginstatsview-card-wrap">
	<div>
		<img decoding="async" src="https://ps.w.org/plugin-check/assets/icon.svg?rev=3166100" alt="Plugin Check (PCP) のアイコン" class="pluginstatsview-card-icon" />
		<div class="pluginstatsview-after-icon">
			<div class="pluginstatsview-bold"><a href="https://github.com/WordPress/plugin-check" class="pluginstatsview-astyle">Plugin Check (PCP)</a></div>
			<div class="pluginstatsview-small">Plugin Check は WordPress.org のツールで、プラグインがディレクトリの要件を満たし、様々なベストプラク&#8230;</div>
			<div class="pluginstatsview-small">作者: <a href="https://profiles.wordpress.org/wordpressdotorg/">WordPress.org</a></div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<div style="clear: both;"></div>

	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left"><a href="https://github.com/WordPress/plugin-check#reviews" title="4.4(5点満点中)" class="pluginstatsview-astyle">	<span class="pluginstatsview-stars">
					<span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-half"></span>
			</span>
	</a>(32)</span>
		<span class="pluginstatsview-card-right">最終更新: 2週間 前</span>
	</div>
	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left">8,000以上サイトで有効化中</span>
		<span class="pluginstatsview-card-right">検証済み: 7.0</span>
	</div>
	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left">ダウンロード: <a href="https://downloads.wordpress.org/plugin/plugin-check.1.9.0.zip" class="dashicons dashicons-download pluginstatsview-download"></a></span>
		<span class="pluginstatsview-card-right">リリース: 2011-09-04</span>
	</div>
	<div class="pluginstatsview-small pluginstatsview-card-center">
		2026-03-31 09:30 時点の統計	</div>
</div>



<p>WP_Filesystem に関しては、テーマなどで、<a href="https://www.php.net/manual/ja/function.file-get-contents.php">file_get_contents</a>、<a href="https://www.php.net/manual/ja/function.file-put-contents.php">file_put_contents</a> などの代わりに使用するように推奨していたようですが、プラグインに関しても推奨するようになってきたのかという感じです。しかし、必ずしもすべてこの通りにしなければならないというものでもないようで、その辺りの事が、<a href="https://ja.wordpress.org/plugins/plugin-check/#why%20does%20it%20flag%20something%20as%20bad%3F">FAQ</a> に書かれています。実際、上記の非推奨のものを使用していてトラブルになったおぼえはありません。</p>



<p>自分の場合には、CSV 出力関連ですが、WP_Filesystem には、fputcsv の代替えのものがありません。file_put_contents の代替えのものはあるのですがコードが煩雑になり遠回りになってしまいます。そこで、<a href="https://www.php.net/manual/ja/class.splfileobject.php">SplFileObject クラス</a> を使用してみたところ、<strong>Plugin Check</strong> に怒られなく？なりました。</p>



<h3 class="wp-block-heading">コード</h3>



<p>$csvs は、CSV にするための配列とします。$csv_file は、フルパスを含むファイル名です。フィルターに関しては無くても動作しますが、Windows の Excel で直接開きたい場合には、必要です。</p>



<p>fputcsv を用いたコード</p>



<pre class="prism line-numbers"><code class="language-php language-html">$f = fopen( $csv_file, 'w' );
stream_filter_prepend( $f, 'convert.iconv.utf-8/cp932//TRANSLIT' );
if ( $f ) {
	foreach ( $csvs as $line ) {
		fputcsv( $f, $line );
	}
}
fclose( $f );</code></pre>



<p>SplFileObject クラスを用いたコード</p>



<pre class="prism line-numbers"><code class="language-php language-html">$filter = urlencode( 'convert.iconv.utf-8/cp932//TRANSLIT' );
$file = new SplFileObject( 'php://filter/write=' . $filter . '/resource=' . $csv_file, 'a' );
foreach ( $csvs as $line ) {
	$file->fputcsv( $line );
}
$file = null;</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>ブロックの日本語化に関する補足事項</title>
		<link>https://blog.riverforest-wp.info/block-internationalization/</link>
		
		<dc:creator><![CDATA[Katsushi Kawamori]]></dc:creator>
		<pubDate>Wed, 22 Nov 2023 07:13:30 +0000</pubDate>
				<category><![CDATA[Function]]></category>
		<category><![CDATA[block.json]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[ブロック]]></category>
		<category><![CDATA[国際化]]></category>
		<category><![CDATA[日本語化]]></category>
		<guid isPermaLink="false">https://blog.riverforest-wp.info/?p=3545</guid>

					<description><![CDATA[はじめに 現在、自作ブロックの日本語化を、「ブロックエディターハンドブック／開発ガイド／国際化」に準じて行っていますが、現在の、block.json でスクリプトをロードする方法には適していないので、ここに捕捉事項として [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">はじめに</h3>



<p>現在、自作ブロックの日本語化を、「ブロックエディターハンドブック／開発ガイド／国際化」に準じて行っていますが、現在の、block.json でスクリプトをロードする方法には適していないので、ここに捕捉事項として記す事にします。</p>



<style>
.simpleblogcard_img_blockbc4cfd61f183a35754f7746a35ba79e2 {
  float: right;
  padding: 10px;
}
.simpleblogcard_borderbc4cfd61f183a35754f7746a35ba79e2 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_titlebc4cfd61f183a35754f7746a35ba79e2 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_descriptionbc4cfd61f183a35754f7746a35ba79e2 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://ja.wordpress.org/team/handbook/block-editor/how-to-guides/internationalization/>
				<figure class="simpleblogcard_img_blockbc4cfd61f183a35754f7746a35ba79e2">
			<img decoding="async" style="border-radius: 5px; width: 100px; height: 56px;" src="https://s.w.org/images/home/wordpress-default-ogimage.png" alt="国際化 – Japanese Team – WordPress.org 日本語" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_borderbc4cfd61f183a35754f7746a35ba79e2">
			ja.wordpress.org			<div class="simpleblogcard_titlebc4cfd61f183a35754f7746a35ba79e2">
				国際化 – Japanese Team – WordPress.org 日本語			</div>
							<div class="simpleblogcard_descriptionbc4cfd61f183a35754f7746a35ba79e2">
					国際化とは何か ? 国際化とはソフトウエア、特にここでは WordPress に対して複数言語のサポートを提供…				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>



<h3 class="wp-block-heading">ハンドル名の指定</h3>



<p>上記でのハンドル名の指定方法は、以下の様になっています。この方法では、wp_register_script で、ハンドル名 <strong>myguten-script</strong> を指定し、register_block_type の、editor_script で、<strong>myguten-script </strong>を再度指定しています。</p>



<pre class="prism line-numbers"><code class="language-php language-html">&lt;?php
/**
 * Plugin Name: Simple Block
 * Text Domain: myguten
 */
function myguten_simple_block_init() {
    wp_register_script(
        'myguten-script',
        plugins_url( 'block.js', __FILE__ ),
        array( 'wp-blocks', 'wp-element', 'wp-i18n', 'wp-block-editor' )
    );
 
    register_block_type( 'myguten/simple-block', array(
        'api_version' =&gt; 2,
        'editor_script' =&gt; 'myguten-script',
    ) );
}
add_action( 'init', 'myguten_simple_block_init' );</code></pre>



<p>その後に、php で、<strong>wp_set_script_translations</strong> の第一引数に <strong>registrer_block_type</strong> で登録したハンドル名 <strong>myguten-script</strong> を指定する方式です。</p>



<style>
.simpleblogcard_img_block8d0c3ce0ec94d5a842c2efb0819a8694 {
  float: right;
  padding: 10px;
}
.simpleblogcard_border8d0c3ce0ec94d5a842c2efb0819a8694 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title8d0c3ce0ec94d5a842c2efb0819a8694 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description8d0c3ce0ec94d5a842c2efb0819a8694 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://developer.wordpress.org/reference/functions/wp_set_script_translations/>
				<figure class="simpleblogcard_img_block8d0c3ce0ec94d5a842c2efb0819a8694">
			<img decoding="async" style="border-radius: 5px; width: 100px; height: 52px;" src="https://developer.wordpress.org/wp-content/themes/wporg-developer-2023/images/opengraph-image.png" alt="wp_set_script_translations() – Function | Developer.WordPress.org" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border8d0c3ce0ec94d5a842c2efb0819a8694">
			developer.wordpress.org			<div class="simpleblogcard_title8d0c3ce0ec94d5a842c2efb0819a8694">
				wp_set_script_translations() – Function | Developer.WordPress.org			</div>
							<div class="simpleblogcard_description8d0c3ce0ec94d5a842c2efb0819a8694">
					Sets translated strings for a script.				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>



<pre class="prism line-numbers"><code class="language-php language-html">&lt;?php
function myguten_set_script_translations() {
    wp_set_script_translations( 'myguten-script', 'myguten' );
}
add_action( 'init', 'myguten_set_script_translations' );</code></pre>



<p>上記のやり方を、現在の block.json で読み込む方式に置き換えると以下の様になります。</p>



<pre class="prism line-numbers"><code class="language-php language-html">&lt;?php
/**
 * Plugin Name: Simple Block
 * Text Domain: myguten
 */
function myguten_simple_block_init() {
	register_block_type(
		__DIR__ . '/block/build',
	);
}
add_action( 'init', 'myguten_simple_block_init' );</code></pre>



<p>block.json を置いたディレクトリを検索してそれを読み込むという形です。ここでは、ハンドル名は指定していません。block.json の方を見てみると、editorScript の項目がそれらしいのですが、スクリプトのハンドルという言葉はあるのですが、ファイルへのパスを指定するのが通常の様です。</p>



<style>
.simpleblogcard_img_block9bee9ad58d6389b3a6fabbcdafe6a8e7 {
  float: right;
  padding: 10px;
}
.simpleblogcard_border9bee9ad58d6389b3a6fabbcdafe6a8e7 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title9bee9ad58d6389b3a6fabbcdafe6a8e7 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description9bee9ad58d6389b3a6fabbcdafe6a8e7 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/>
				<figure class="simpleblogcard_img_block9bee9ad58d6389b3a6fabbcdafe6a8e7">
			<img decoding="async" style="border-radius: 5px; width: 100px; height: 52px;" src="https://developer.wordpress.org/wp-content/themes/wporg-developer-2023/images/opengraph-image.png" alt="Metadata in block.json – Block Editor Handbook | Developer.WordPress.org" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border9bee9ad58d6389b3a6fabbcdafe6a8e7">
			developer.wordpress.org			<div class="simpleblogcard_title9bee9ad58d6389b3a6fabbcdafe6a8e7">
				Metadata in block.json – Block Editor Handbook | Developer.WordPress.org			</div>
							<div class="simpleblogcard_description9bee9ad58d6389b3a6fabbcdafe6a8e7">
					Starting with the WordPress 5.8 release, we recommend using the block.json metadata file a&#8230;				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>



<p><strong>register_block_type</strong> では、ハンドル名を渡さずに、WordPress の php の関数 <strong>generate_block_asset_handle</strong> で第１引数にブロック名、第２引数に editorScript を渡したらハンドル名を取得し国際化が上手くいきましたので、以下に示します。</p>



<pre class="prism line-numbers"><code class="language-php language-html">function myguten_set_script_translations() {
　　$script_handle = generate_block_asset_handle( 'myguten/simple-block', 'editorScript' );
　　wp_set_script_translations( $script_handle, 'myguten' );
}
add_action( 'init', 'myguten_set_script_translations' );</code></pre>



<style>
.simpleblogcard_img_block42de8ae8ecc027abb6bbbdf1a6584967 {
  float: right;
  padding: 10px;
}
.simpleblogcard_border42de8ae8ecc027abb6bbbdf1a6584967 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title42de8ae8ecc027abb6bbbdf1a6584967 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description42de8ae8ecc027abb6bbbdf1a6584967 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://developer.wordpress.org/reference/functions/generate_block_asset_handle/>
				<figure class="simpleblogcard_img_block42de8ae8ecc027abb6bbbdf1a6584967">
			<img decoding="async" style="border-radius: 5px; width: 100px; height: 52px;" src="https://developer.wordpress.org/wp-content/themes/wporg-developer-2023/images/opengraph-image.png" alt="generate_block_asset_handle() – Function | Developer.WordPress.org" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border42de8ae8ecc027abb6bbbdf1a6584967">
			developer.wordpress.org			<div class="simpleblogcard_title42de8ae8ecc027abb6bbbdf1a6584967">
				generate_block_asset_handle() – Function | Developer.WordPress.org			</div>
							<div class="simpleblogcard_description42de8ae8ecc027abb6bbbdf1a6584967">
					Generates the name for an asset based on the name of the block and the field name provided&#8230;				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>



<h3 class="wp-block-heading">block.json の日本語化</h3>



<p>ついでにわかりにくい、block.json の日本語化について以下に記します。上記の、<strong>register_block_type</strong> に、配列で翻訳対象を列記します。keywords は複数あるので更なる配列にします。</p>



<pre class="prism line-numbers"><code class="language-php language-html">&lt;?php
/**
 * Plugin Name: Simple Block
 * Text Domain: myguten
 */
function myguten_simple_block_init() {
	register_block_type(
		__DIR__ . '/block/build',
		array(
			'title' =&gt; _x( 'Simple Block', 'block title', 'myguten' ),
			'description' =&gt; _x( 'Example static block scaffolded with Create Block tool.', 'block description', 'myguten' ),
			'keywords' =&gt; array(
				_x( 'simple', 'block keyword', 'myguten' ),
				_x( 'static', 'block keyword', 'myguten' ),
				_x( 'tool', 'block keyword', 'myguten' ),
			),
		)
	);
}
add_action( 'init', 'myguten_simple_block_init' );</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>WordPress 6.4 からの Lightbox 追加を一括で行う</title>
		<link>https://blog.riverforest-wp.info/wp64-lightbox-wpcli/</link>
		
		<dc:creator><![CDATA[Katsushi Kawamori]]></dc:creator>
		<pubDate>Sat, 30 Sep 2023 01:48:38 +0000</pubDate>
				<category><![CDATA[Function]]></category>
		<category><![CDATA[Lightbox]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress 6.4]]></category>
		<category><![CDATA[wp-cli]]></category>
		<guid isPermaLink="false">https://blog.riverforest-wp.info/?p=3405</guid>

					<description><![CDATA[はじめに WordPress 6.4 から、Lightbox 機能が追加されます。投稿内の html のコメント部分を変更します。具体的には、wp:image の中に、lightbox&#8221;:{&#8220;en [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">はじめに</h3>



<p>WordPress 6.4 から、Lightbox 機能が追加されます。投稿内の html のコメント部分を変更します。具体的には、wp:image の中に、lightbox&#8221;:{&#8220;enabled&#8221;:true} を加える形式です。</p>



<figure class="wp-block-video aligncenter"><video height="778" style="aspect-ratio: 1458 / 778;" width="1458" controls src="https://blog.riverforest-wp.info/wp-content/uploads/20230930/wp-lightbox.mp4"></video></figure>



<p>以前からのサイトに適用させる場合は、html 内の wp:image にこれを追加すれば良いので、WP-CLI でサイト内の全投稿と全固定ページを一括で変更するものを作ってみました。</p>



<p>WP-CLI が必要です。</p>



<pre class="prism line-numbers"><code class="language-php language-html">/* 第１引数：on で、Lightbox を On。off で、Lightbox を Off */
wp box on
wp box off
/* 第２引数：投稿や画像のID を指定できる */
wp box off 9110 /* 投稿 ID 9110 のみ Off */
wp box on 9031 /* メディア ID 9031 のみ On */</code></pre>



<h3 class="wp-block-heading">コード</h3>



<style>
.simpleblogcard_img_blockdf6f7be6bdcdacb6ce5b53f0f529d956 {
  float: right;
  padding: 10px;
}
.simpleblogcard_borderdf6f7be6bdcdacb6ce5b53f0f529d956 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_titledf6f7be6bdcdacb6ce5b53f0f529d956 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_descriptiondf6f7be6bdcdacb6ce5b53f0f529d956 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://github.com/katsushi-kawamori/wp-cli-Lightbox-command-on-off/ target="_blank" rel="noopener">
				<figure class="simpleblogcard_img_blockdf6f7be6bdcdacb6ce5b53f0f529d956">
			<img decoding="async" style="border-radius: 5px; width: 100px; height: 50px;" src="https://opengraph.githubassets.com/c439f0287ec596e32238ea05a8e294d3c51a058e4414b3bbc7456f128902cfda/katsushi-kawamori/wp-cli-Lightbox-command-on-off" alt="GitHub - katsushi-kawamori/wp-cli-Lightbox-command-on-off · GitHub" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_borderdf6f7be6bdcdacb6ce5b53f0f529d956">
			github.com			<div class="simpleblogcard_titledf6f7be6bdcdacb6ce5b53f0f529d956">
				GitHub &#8211; katsushi-kawamori/wp-cli-Lightbox-command-on-off · GitHub			</div>
							<div class="simpleblogcard_descriptiondf6f7be6bdcdacb6ce5b53f0f529d956">
					Contribute to katsushi-kawamori/wp-cli-Lightbox-command-on-off development by creating an &#8230;				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>



<h3 class="wp-block-heading">使い方</h3>



<figure class="wp-block-video aligncenter"><video height="742" style="aspect-ratio: 1412 / 742;" width="1412" controls src="https://blog.riverforest-wp.info/wp-content/uploads/20230930/wp-lightbox-cli-2.mp4"></video></figure>
]]></content:encoded>
					
		
		<enclosure url="https://blog.riverforest-wp.info/wp-content/uploads/20230930/wp-lightbox.mp4" length="25853129" type="video/mp4" />
<enclosure url="https://blog.riverforest-wp.info/wp-content/uploads/20230930/wp-lightbox-cli-2.mp4" length="47912265" type="video/mp4" />

			</item>
		<item>
		<title>コンテンツの複製を拒否するシンプルなコード</title>
		<link>https://blog.riverforest-wp.info/contents-no-copy/</link>
		
		<dc:creator><![CDATA[Katsushi Kawamori]]></dc:creator>
		<pubDate>Thu, 20 Apr 2023 04:47:57 +0000</pubDate>
				<category><![CDATA[Function]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[コンテンツコピー]]></category>
		<category><![CDATA[画像コピー]]></category>
		<guid isPermaLink="false">https://blog.riverforest-wp.info/?p=3197</guid>

					<description><![CDATA[はじめに コンテンツの盗用による被害が結構な頻度で見受けられます。それに対応する一番シンプルな方法を以下に記します。以下の方法は、ブラウザや Javascript に少しでも知見のある方なら破れますが、無いよりは良いので [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">はじめに</h3>



<p>コンテンツの盗用による被害が結構な頻度で見受けられます。それに対応する一番シンプルな方法を以下に記します。以下の方法は、ブラウザや Javascript に少しでも知見のある方なら破れますが、無いよりは良いのではないかと思います。</p>



<h3 class="wp-block-heading">コード</h3>



<pre class="prism line-numbers"><code class="language-php language-html">/* スクリプトを読み込みます */
add_action(
	'wp_enqueue_scripts',
	function() {
		/* 管理画面以外で */
		if ( ! is_admin() ) {
			?>
			&lt;script>
			/* ブラウザの右クリックを無効にします */
			 document.oncontextmenu = function () { return false; }
			&lt;/script>
			&lt;style>
			/* タブレットやスマートフォンの長押しを無効にします */
			.nocopy {
			 -webkit-touch-callout: none;
			 -webkit-user-select: none;
			 -khtml-user-select: none;
			 -moz-user-select: none;
			 -ms-user-select: none;
			 user-select: none;
			}
			&lt;/style>
			&lt;?php
		}
	},
	10,
	1
);
/* 上記の 'nocopy' クラスを、body タグに追加します */
add_filter( 'body_class',
	function() {
		/* 管理画面以外で */
		if ( ! is_admin() ) {
			return array( 'nocopy' );
		}
	},
	10,
	1
);</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>自プラグインの各種情報を取得</title>
		<link>https://blog.riverforest-wp.info/my-plugin-info/</link>
		
		<dc:creator><![CDATA[Katsushi Kawamori]]></dc:creator>
		<pubDate>Thu, 27 Oct 2022 11:06:24 +0000</pubDate>
				<category><![CDATA[Function]]></category>
		<category><![CDATA[プラグイン]]></category>
		<category><![CDATA[情報]]></category>
		<guid isPermaLink="false">https://blog.riverforest-wp.info/?p=3002</guid>

					<description><![CDATA[はじめに プラグインの開発者には、新たなバージョンの WordPress がリリースされる前に、Tested up to:(検証済み最新バージョン:)の値を確認するように、以下の様なメールが届きます。同じ事をやってみよう [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">はじめに</h3>



<p>プラグインの開発者には、新たなバージョンの WordPress がリリースされる前に、Tested up to:(検証済み最新バージョン:)の値を確認するように、以下の様なメールが届きます。同じ事をやってみようと思いコードを書いてみました。</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc632d9c41f&quot;}" data-wp-interactive="core/image" data-wp-key="69cc632d9c41f" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" width="548" height="439" src="https://blog.riverforest-wp.info/wp-content/uploads/20221027/2022-10-27-testedupto.png" alt="" class="wp-image-3005" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20221027/2022-10-27-testedupto.png 548w, https://blog.riverforest-wp.info/wp-content/uploads/20221027/2022-10-27-testedupto-300x240.png 300w" sizes="auto, (max-width: 548px) 100vw, 548px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h3 class="wp-block-heading">概要</h3>



<p>プラグイン単体の場合は、<a href="https://developer.wordpress.org/reference/functions/plugins_api/">plugins_api</a> で取得できます。全プラグインの情報の場合、取得できる関数が見当たらないので、プロフィールサイトから取得する事にしました。プロフィールサイトには以下の様に各プラグインのリンクにスタイルをあてるクラス「<strong>plugin-info-container</strong>」があったので、そこからスクレイピングしました。</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc632d9c994&quot;}" data-wp-interactive="core/image" data-wp-key="69cc632d9c994" class="wp-block-image size-large wp-lightbox-container"><img loading="lazy" decoding="async" width="1024" height="568" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://blog.riverforest-wp.info/wp-content/uploads/20221027/2022-10-27-133305-1024x568.png" alt="" class="wp-image-3001" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20221027/2022-10-27-133305-1024x568.png 1024w, https://blog.riverforest-wp.info/wp-content/uploads/20221027/2022-10-27-133305-300x166.png 300w, https://blog.riverforest-wp.info/wp-content/uploads/20221027/2022-10-27-133305-768x426.png 768w, https://blog.riverforest-wp.info/wp-content/uploads/20221027/2022-10-27-133305.png 1520w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>WordPress の関数を使えるように、<strong>wp-load.php</strong> を読み込めるようにしました。</p>



<p>また、コマンドラインオプションを設け、プラグイン単体での各属性を取得できるようにしました。各属性に関しては、<a href="https://developer.wordpress.org/reference/functions/plugins_api/">plugins_api</a> を参照してください。</p>



<p>以下に動作を動画（倍速）で示します。</p>



<figure class="wp-block-video"><video height="628" style="aspect-ratio: 1116 / 628;" width="1116" controls muted src="https://blog.riverforest-wp.info/wp-content/uploads/20221027/profiles-plugins.mp4"></video></figure>



<h3 class="wp-block-heading">コード</h3>



<pre class="prism line-numbers"><code class="language-php language-html">&lt;?php
/**
 * Name:        profiles-plugins.php
 * Version:     1.00
 * Author:      Katsushi Kawamori
 * Author URI:  https://riverforest-wp.info/
 * License:     GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 *
 * @package     profiles-plugins
 */

/* Your WordPress profile url */
const WP_PROFILE_URL = 'https://profiles.wordpress.org/katsushi-kawamori/';

/* Wp load. This file =&gt; wp-content/uploads/profiles-plugins.php */
list( $abspath, $mypath ) = explode( 'wp-content', dirname( __FILE__ ), 2 );
$wp_load_path = $abspath . 'wp-load.php';
require_once( $wp_load_path );

/* For plugins_api */
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';

$cmdoptions = array();
/* Example -a active_installs -p woocommerce */
$cmdoptions = getopt( 'a:p:' );

/* Default atribute 'tested' */
if ( isset( $cmdoptions&#91;'a'] ) &amp;&amp; ! empty( $cmdoptions&#91;'a'] ) ) {
	$atr = $cmdoptions&#91;'a'];
} else {
	$atr = 'tested';
}

if ( isset( $cmdoptions&#91;'p'] ) &amp;&amp; ! empty( $cmdoptions&#91;'p'] ) ) {
	$slug = $cmdoptions&#91;'p'];
	$plugin_s = array(
		'name' =&gt; read_plugins_api( $slug, 'name' ),
		'link' =&gt; read_plugins_api( $slug, 'homepage' ),
		'slug' =&gt; $slug,
		$atr =&gt; read_plugins_api( $slug, $atr ),
	);
	print_r( $plugin_s );
} else {
	/* Scraping */
	$dom = new DOMDocument( '1.0', 'UTF-8' );
	$html = file_get_contents( WP_PROFILE_URL );
	@$dom-&gt;loadHTML( $html );
	$xpath = new DOMXpath( $dom );
	/* Get &lt;a&gt; tag within class plugin-info-container */
	$a_tags = $xpath-&gt;query( '//div&#91;@class="plugin-info-container"]&#91;1]//a' );
	$count = 0;
	foreach ( $a_tags as $node ) {
		/* Get href attribute from within &lt;a&gt; tag */
		$link_url = 'https:' . $node-&gt;getAttribute( 'href' );
		/* Get slug from URL */
		$link_s = untrailingslashit( $link_url );
		$links = explode( '/', $link_s );
		$slug = end( $links );

		++$count;
		$plugin_s = array(
			'count' =&gt; $count,
			'name' =&gt; $node-&gt;nodeValue,
			'link' =&gt; $link_url,
			'slug' =&gt; $slug,
			$atr =&gt; read_plugins_api( $slug, $atr ),
		);
		print_r( $plugin_s );
	}
}

/** ==================================================
 * Get api and value
 *
 * @param string $slug  slug.
 * @param string $atr  atribute.
 * @return mixed api value.
 * @since 1.00
 */
function read_plugins_api( $slug, $atr ) {

	/* Call API */
	$call_api = plugins_api(
		'plugin_information',
		array(
			'slug' =&gt; $slug,
			'fields' =&gt; array(
				'short_description' =&gt; true,
				'description' =&gt; true,
				'active_installs' =&gt; true,
				'downloaded' =&gt; true,
				'icons' =&gt; true,
				'banners' =&gt; true,
				'ratings' =&gt; true,
			),
		)
	);

	return $call_api-&gt;$atr;

}</code></pre>
]]></content:encoded>
					
		
		<enclosure url="https://blog.riverforest-wp.info/wp-content/uploads/20221027/profiles-plugins.mp4" length="6436233" type="video/mp4" />

			</item>
		<item>
		<title>フォルダー内のコードの総行数とサイズを調べる</title>
		<link>https://blog.riverforest-wp.info/folder-code-line-zise/</link>
		
		<dc:creator><![CDATA[Katsushi Kawamori]]></dc:creator>
		<pubDate>Sun, 22 Aug 2021 02:57:20 +0000</pubDate>
				<category><![CDATA[Function]]></category>
		<category><![CDATA[コード]]></category>
		<category><![CDATA[サイズ]]></category>
		<category><![CDATA[行数]]></category>
		<guid isPermaLink="false">https://blog.riverforest-wp.info/?p=2851</guid>

					<description><![CDATA[はじめに 今回の記事は、ちょっとしたお遊び記事です。 作成した公式プラグインが、気づいたら「１００万ダウンロード」と「５万以上サイトで有効化中」になっていました。この数値は、Plugin Stats View という私の [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">はじめに</h3>



<p>今回の記事は、ちょっとしたお遊び記事です。</p>



<p>作成した公式プラグインが、気づいたら「<strong>１００万ダウンロード</strong>」と「<strong>５万以上サイトで有効化中</strong>」になっていました。この数値は、<strong>Plugin Stats View</strong> という私のプラグインで出したもので、<strong>plugins_api</strong> を利用して集計しています。</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc632d9d8b0&quot;}" data-wp-interactive="core/image" data-wp-key="69cc632d9d8b0" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" width="324" height="253" src="https://blog.riverforest-wp.info/wp-content/uploads/20210822/Screenshot-2021-08-22-at-11-21-08-Riverforest-Plugins.png" alt="" class="wp-image-2856" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20210822/Screenshot-2021-08-22-at-11-21-08-Riverforest-Plugins.png 324w, https://blog.riverforest-wp.info/wp-content/uploads/20210822/Screenshot-2021-08-22-at-11-21-08-Riverforest-Plugins-300x234.png 300w" sizes="auto, (max-width: 324px) 100vw, 324px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<style>
.simpleblogcard_img_block6b898a19b5b4ac365fcb711b2d5488a6 {
  float: right;
  padding: 10px;
}
.simpleblogcard_border6b898a19b5b4ac365fcb711b2d5488a6 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title6b898a19b5b4ac365fcb711b2d5488a6 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description6b898a19b5b4ac365fcb711b2d5488a6 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://ja.wordpress.org/plugins/plugin-stats-view/>
			<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border6b898a19b5b4ac365fcb711b2d5488a6">
			ja.wordpress.org			<div class="simpleblogcard_title6b898a19b5b4ac365fcb711b2d5488a6">
				Plugin Stats View – WordPress プラグイン | WordPress.org 日本語			</div>
							<div class="simpleblogcard_description6b898a19b5b4ac365fcb711b2d5488a6">
					プラグイン情報をブロックあるいはショートコードで表示します。				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<style>
.simpleblogcard_img_block9c92b728278d1fb04091716a0d633325 {
  float: right;
  padding: 10px;
}
.simpleblogcard_border9c92b728278d1fb04091716a0d633325 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title9c92b728278d1fb04091716a0d633325 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description9c92b728278d1fb04091716a0d633325 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://developer.wordpress.org/reference/functions/plugins_api/>
				<figure class="simpleblogcard_img_block9c92b728278d1fb04091716a0d633325">
			<img decoding="async" style="border-radius: 5px; width: 100px; height: 52px;" src="https://developer.wordpress.org/wp-content/themes/wporg-developer-2023/images/opengraph-image.png" alt="plugins_api() – Function | Developer.WordPress.org" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border9c92b728278d1fb04091716a0d633325">
			developer.wordpress.org			<div class="simpleblogcard_title9c92b728278d1fb04091716a0d633325">
				plugins_api() – Function | Developer.WordPress.org			</div>
							<div class="simpleblogcard_description9c92b728278d1fb04091716a0d633325">
					Retrieves plugin installer pages from the WordPress.org Plugins API.				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>
</div>
</div>



<p>ここまで良くやったなあとは思いつつ、今まで何行書いたんだろうと思い、行数とサイズを調べるプログラムを php で作成してみました。</p>



<h3 class="wp-block-heading">下準備 &amp; 仕様</h3>



<p>作業ディレクトリを作成し、６６個のプラグインをコピーしました。あらかじめ、自分以外の方が書いたライブラリなどを削除しました。</p>



<ul class="wp-block-list"><li>コマンドライン上で実行します。</li><li>コード中に指定したディレクトリを再帰検索して、php, js , css ファイルをカウントします。</li><li>php, js, css のそれぞれと全ての行数の総和と、サイズの総和を出力します。</li></ul>



<h3 class="wp-block-heading">コード</h3>



<pre class="prism line-numbers"><code class="language-php language-html">&lt;?php
/**
 * Plugin Name: Program number of line
 * Author:      Katsushi Kawamori
 * Author URI:  https://riverforest-wp.info/
 * License:     GPL2
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 *
 */

/*
	Copyright (c) 2021- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; version 2 of the License.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

$line_all = pnol_scan_file( 'ディレクトリをフルパスで指定します' );

foreach ( $line_all as $key =&gt; $value ) {
	echo $key . ' : ' . number_format( $value&#91;'line'] ) . '行 - ' . number_format( $value&#91;'size'] / 1024 / 1024, 2 ) . 'Mbyte' . PHP_EOL;
}

echo PHP_EOL;

/** ==================================================
 * Scan file
 *
 * @param string $dir  dir.
 * @return array $count
 * @since 1.00
 */
function pnol_scan_file( $dir ) {

	$iterator = new RecursiveDirectoryIterator(
		$dir,
		FilesystemIterator::CURRENT_AS_FILEINFO |
		FilesystemIterator::KEY_AS_PATHNAME |
		FilesystemIterator::SKIP_DOTS
	);
	$iterator = new RecursiveIteratorIterator( $iterator );
	$iterator = new RegexIterator( $iterator, '/\.php$|\.js$|\.css$/i', RecursiveRegexIterator::MATCH );

	$count = array(
		'all' =&gt; array(
			'line' =&gt; 0,
			'size' =&gt; 0,
		),
		'php' =&gt; array(
			'line' =&gt; 0,
			'size' =&gt; 0,
		),
		'js' =&gt; array(
			'line' =&gt; 0,
			'size' =&gt; 0,
		),
		'css' =&gt; array(
			'line' =&gt; 0,
			'size' =&gt; 0,
		),
	);
	if ( ! empty( $iterator ) ) {
		foreach ( $iterator as $file_path =&gt; $file_info ) {
			if ( $file_info-&gt;isFile() ) {
				$line = exec( 'wc -l '. $file_path );
				$count&#91;'all']&#91;'line'] += trim( str_replace( $file_path, '', $line ) );
				$count&#91;'all']&#91;'size'] += $file_info-&gt;getSize();
				switch ( $file_info-&gt;getExtension() ) {
					case 'php':
						$count&#91;'php']&#91;'line'] += trim( str_replace( $file_path, '', $line ) );
						$count&#91;'php']&#91;'size'] += $file_info-&gt;getSize();
						break;
					case 'js':
						$count&#91;'js']&#91;'line'] += trim( str_replace( $file_path, '', $line ) );
						$count&#91;'js']&#91;'size'] += $file_info-&gt;getSize();
						break;
					case 'css':
						$count&#91;'css']&#91;'line'] += trim( str_replace( $file_path, '', $line ) );
						$count&#91;'css']&#91;'size'] += $file_info-&gt;getSize();
						break;
				}
			}
		}
	}

	return $count;

}

?&gt;</code></pre>



<h3 class="wp-block-heading">実行</h3>



<p>以下の様な結果になりました。</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc632d9e84f&quot;}" data-wp-interactive="core/image" data-wp-key="69cc632d9e84f" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" width="328" height="125" src="https://blog.riverforest-wp.info/wp-content/uploads/20210822/pgnol.png" alt="" class="wp-image-2855" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20210822/pgnol.png 328w, https://blog.riverforest-wp.info/wp-content/uploads/20210822/pgnol-300x114.png 300w" sizes="auto, (max-width: 328px) 100vw, 328px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h3 class="wp-block-heading">終わりに</h3>



<p>最近、自プロダクトの「<strong>競技会採点システム</strong>」の方に時間を割く事が多くなったので、今後、公式プラグインの方はあまり力を入れないと思います。フォーラムで応答が無くても、ご容赦ください。</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<style>
.simpleblogcard_img_blockd80d44ca8d0b86c77322984ff96ee6ef {
  float: right;
  padding: 10px;
}
.simpleblogcard_borderd80d44ca8d0b86c77322984ff96ee6ef {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_titled80d44ca8d0b86c77322984ff96ee6ef {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_descriptiond80d44ca8d0b86c77322984ff96ee6ef {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://compe-scoring.com/>
			<div class="simpleblogcard_inner">
		<div class="simpleblogcard_borderd80d44ca8d0b86c77322984ff96ee6ef">
			compe-scoring.com			<div class="simpleblogcard_titled80d44ca8d0b86c77322984ff96ee6ef">
				Competition Scoring System – Competition Scoring System			</div>
							<div class="simpleblogcard_descriptiond80d44ca8d0b86c77322984ff96ee6ef">
					Features of the Service This service is a scoring system for competitions or contests. Aut&#8230;				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>
</div>
</div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>WordPress 5.3 からのメディアライブラリにおける大画像の問題について</title>
		<link>https://blog.riverforest-wp.info/media-large-image-wp5-3/</link>
		
		<dc:creator><![CDATA[Katsushi Kawamori]]></dc:creator>
		<pubDate>Tue, 19 Nov 2019 22:49:00 +0000</pubDate>
				<category><![CDATA[Function]]></category>
		<category><![CDATA[オリジナルファイル]]></category>
		<category><![CDATA[スケーリング]]></category>
		<category><![CDATA[フィルター]]></category>
		<category><![CDATA[メディアライブラリ]]></category>
		<category><![CDATA[大画像]]></category>
		<guid isPermaLink="false">https://blog.riverforest-wp.info/?p=1806</guid>

					<description><![CDATA[はじめに WordPress 5.3 から、メディアアップロード時に大画像を検知して、スケーリングする機能が追加されました。デフォルトでは 2560px 以上の画像で動作します。この事が、大画像を扱う方達の間で問題を引き [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">はじめに</h3>



<p>WordPress 5.3 から、メディアアップロード時に大画像を検知して、スケーリングする機能が追加されました。デフォルトでは 2560px 以上の画像で動作します。この事が、大画像を扱う方達の間で問題を引き起こしています。</p>



<h3 class="wp-block-heading">オリジナル画像は？</h3>



<p>大画像をアップロードすると以下のように、元ファイルに「<strong>-scaled</strong>」と付加されたファイルがメディアライブラリの画像になります。スケーリングされた画像であり元の画像ではありません。</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc632d9f994&quot;}" data-wp-interactive="core/image" data-wp-key="69cc632d9f994" class="wp-block-image aligncenter size-large wp-lightbox-container"><img loading="lazy" decoding="async" width="1024" height="681" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://blog.riverforest-wp.info/wp-content/uploads/20191120/media-1024x681.png" alt="" class="wp-image-1811" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20191120/media-1024x681.png 1024w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/media-300x199.png 300w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/media-768x510.png 768w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/media.png 1267w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>サーバーを見てみると、元の画像は存在しますが、管理画面からは見れません。</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc632d9fed3&quot;}" data-wp-interactive="core/image" data-wp-key="69cc632d9fed3" class="wp-block-image aligncenter size-large wp-lightbox-container"><img loading="lazy" decoding="async" width="1024" height="621" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://blog.riverforest-wp.info/wp-content/uploads/20191120/files-1024x621.png" alt="" class="wp-image-1810" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20191120/files-1024x621.png 1024w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/files-300x182.png 300w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/files-768x466.png 768w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/files.png 1088w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>どのように管理されているかデータベースを調べてみると、メタデータの中に <strong>original_image</strong> というメタデータがありそこにファイル名が記されていました。</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc632da03ee&quot;}" data-wp-interactive="core/image" data-wp-key="69cc632da03ee" class="wp-block-image size-large wp-lightbox-container"><img loading="lazy" decoding="async" width="1024" height="626" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://blog.riverforest-wp.info/wp-content/uploads/20191120/meta-1024x626.png" alt="" class="wp-image-1813" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20191120/meta-1024x626.png 1024w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/meta-300x183.png 300w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/meta-768x469.png 768w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/meta.png 1198w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h3 class="wp-block-heading">この動作を抑制するには？</h3>



<p>以下のフィルターを使用して抑制するとスケーリングしなくなります。</p>



<pre class="prism line-numbers"><code class="language-php language-html">add_filter( 'big_image_size_threshold', '__return_zero', 10, 2 );</code></pre>



<p>また私の作成したプラグイン <strong>Disable Generate Thumbnails</strong> では、設定メニューから ON・OFF できます。</p>



<div class="pluginstatsview-card-wrap">
	<div>
		<img decoding="async" src="https://ps.w.org/disable-generate-thumbnails/assets/icon-256x256.png?rev=2187340" alt="Disable Generate Thumbnails のアイコン" class="pluginstatsview-card-icon" />
		<div class="pluginstatsview-after-icon">
			<div class="pluginstatsview-bold"><a href="https://wordpress.org/plugins/disable-generate-thumbnails/" class="pluginstatsview-astyle">Disable Generate Thumbnails</a></div>
			<div class="pluginstatsview-small">サムネイルと機能を選択して無効にします。</div>
			<div class="pluginstatsview-small">作者: <a href="https://profiles.wordpress.org/katsushi-kawamori/">Katsushi Kawamori</a></div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<div style="clear: both;"></div>

	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left"><a href="https://wordpress.org/plugins/disable-generate-thumbnails/#reviews" title="5.0(5点満点中)" class="pluginstatsview-astyle">	<span class="pluginstatsview-stars">
					<span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span>
			</span>
	</a>(15)</span>
		<span class="pluginstatsview-card-right">最終更新: 2日 前</span>
	</div>
	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left">6,000以上サイトで有効化中</span>
		<span class="pluginstatsview-card-right">検証済み: 7.0</span>
	</div>
	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left">ダウンロード: <a href="https://downloads.wordpress.org/plugin/disable-generate-thumbnails.2.21.zip" class="dashicons dashicons-download pluginstatsview-download"></a></span>
		<span class="pluginstatsview-card-right">リリース: 2019-11-06</span>
	</div>
	<div class="pluginstatsview-small pluginstatsview-card-center">
		2026-03-31 09:30 時点の統計	</div>
</div>



<h3 class="wp-block-heading">オリジナル画像の URL は？</h3>



<p>メディアライブラリのファイル名から「<strong>-scaled</strong>」をとったものです。</p>



<p>URL は、以下の関数で取得できます。</p>



<style>
.simpleblogcard_img_blocke48aa0c4713e4cc3c8d35554b872f045 {
  float: right;
  padding: 10px;
}
.simpleblogcard_bordere48aa0c4713e4cc3c8d35554b872f045 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_titlee48aa0c4713e4cc3c8d35554b872f045 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_descriptione48aa0c4713e4cc3c8d35554b872f045 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://developer.wordpress.org/reference/functions/wp_get_original_image_url/>
				<figure class="simpleblogcard_img_blocke48aa0c4713e4cc3c8d35554b872f045">
			<img decoding="async" style="border-radius: 5px; width: 100px; height: 52px;" src="https://developer.wordpress.org/wp-content/themes/wporg-developer-2023/images/opengraph-image.png" alt="wp_get_original_image_url() – Function | Developer.WordPress.org" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_bordere48aa0c4713e4cc3c8d35554b872f045">
			developer.wordpress.org			<div class="simpleblogcard_titlee48aa0c4713e4cc3c8d35554b872f045">
				wp_get_original_image_url() – Function | Developer.WordPress.org			</div>
							<div class="simpleblogcard_descriptione48aa0c4713e4cc3c8d35554b872f045">
					Retrieves the URL to an original attachment image.				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>



<p>フルパスは、以下の関数で取得できます。</p>



<style>
.simpleblogcard_img_block378306328a33df3857b6616f89fd6310 {
  float: right;
  padding: 10px;
}
.simpleblogcard_border378306328a33df3857b6616f89fd6310 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title378306328a33df3857b6616f89fd6310 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description378306328a33df3857b6616f89fd6310 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://developer.wordpress.org/reference/functions/wp_get_original_image_path/>
				<figure class="simpleblogcard_img_block378306328a33df3857b6616f89fd6310">
			<img decoding="async" style="border-radius: 5px; width: 100px; height: 52px;" src="https://developer.wordpress.org/wp-content/themes/wporg-developer-2023/images/opengraph-image.png" alt="wp_get_original_image_path() – Function | Developer.WordPress.org" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border378306328a33df3857b6616f89fd6310">
			developer.wordpress.org			<div class="simpleblogcard_title378306328a33df3857b6616f89fd6310">
				wp_get_original_image_path() – Function | Developer.WordPress.org			</div>
							<div class="simpleblogcard_description378306328a33df3857b6616f89fd6310">
					Retrieves the path to an uploaded image file.				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>



<p>また私の作成したプラグイン <strong>Media Metadata List</strong> からオリジナル画像の URL とサイズを知る事ができます。 </p>



<div class="pluginstatsview-card-wrap">
	<div>
		<img decoding="async" src="https://ps.w.org/media-metadata-list/assets/icon-256x256.png?rev=2129332" alt="Media Metadata List のアイコン" class="pluginstatsview-card-icon" />
		<div class="pluginstatsview-after-icon">
			<div class="pluginstatsview-bold"><a href="https://wordpress.org/plugins/media-metadata-list/" class="pluginstatsview-astyle">Media Metadata List</a></div>
			<div class="pluginstatsview-small">メディアライブラリのリストビューにメタデータのリストを表示します。</div>
			<div class="pluginstatsview-small">作者: <a href="https://profiles.wordpress.org/katsushi-kawamori/">Katsushi Kawamori</a></div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<div style="clear: both;"></div>

	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left"><a href="https://wordpress.org/plugins/media-metadata-list/#reviews" title="4.5(5点満点中)" class="pluginstatsview-astyle">	<span class="pluginstatsview-stars">
					<span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-half"></span>
			</span>
	</a>(2)</span>
		<span class="pluginstatsview-card-right">最終更新: 2日 前</span>
	</div>
	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left">100以上サイトで有効化中</span>
		<span class="pluginstatsview-card-right">検証済み: 7.0</span>
	</div>
	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left">ダウンロード: <a href="https://downloads.wordpress.org/plugin/media-metadata-list.2.03.zip" class="dashicons dashicons-download pluginstatsview-download"></a></span>
		<span class="pluginstatsview-card-right">リリース: 2019-07-26</span>
	</div>
	<div class="pluginstatsview-small pluginstatsview-card-center">
		2026-03-31 09:30 時点の統計	</div>
</div>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc632da0eaf&quot;}" data-wp-interactive="core/image" data-wp-key="69cc632da0eaf" class="wp-block-image size-large wp-lightbox-container"><img loading="lazy" decoding="async" width="1024" height="681" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://blog.riverforest-wp.info/wp-content/uploads/20191120/media-metadata-list-1024x681.png" alt="" class="wp-image-1812" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20191120/media-metadata-list-1024x681.png 1024w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/media-metadata-list-300x199.png 300w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/media-metadata-list-768x510.png 768w, https://blog.riverforest-wp.info/wp-content/uploads/20191120/media-metadata-list.png 1267w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h3 class="wp-block-heading">その他</h3>



<p>私の作成したプラグイン <strong>Media from FTP</strong> でスケーリングされた画像を再検索してしまう問題を、Version 11.03 で修正しました。</p>


]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
