<?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>たねっぱ！ &#187; WordPress</title>
	<atom:link href="https://taneppa.net/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>https://taneppa.net</link>
	<description>コツコツあつめるWeb作りのためのたね　たねっぱ！Web系情報ブログ　Webのお役立ちネタ配信中！</description>
	<lastBuildDate>Tue, 09 May 2023 00:02:06 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>【WordPress】投稿一覧画面からクイック編集機能を削除する方法</title>
		<link>https://taneppa.net/wp_quick_delete/</link>
		<comments>https://taneppa.net/wp_quick_delete/#comments</comments>
		<pubDate>Thu, 30 Jun 2016 03:22:21 +0000</pubDate>
		<dc:creator>tanippa!</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">https://taneppa.net/?p=2956</guid>
		<description><![CDATA[WordPressの管理画面内、投稿一覧画面で「クイック編集」機能というものを使って投稿を簡易的に編集することが出来るのですが、WordPressをカスタマイズしてるとこの機能が邪魔になることが結構あります。今回はこの「クイック編集」機能を削除する方法をご紹介したいと思います。]]></description>
				<content:encoded><![CDATA[<h2 id="-">結論</h2>
<p>以下のコードをfunctions.phpに追加すればOKです。</p>
<pre class="brush: xml; title: ; notranslate">
function remove_quickedit_from_postlist($actions, $post) {
  unset($actions['inline hide-if-no-js']);

  return $actions;
}
add_filter('post_row_actions', 'remove_quickedit_from_postlist', 10, 2);
</pre>
<h2 id="-">説明</h2>
<p>変数$actionsの中身をvar_dumpすると以下のようになっています。</p>
<pre class="brush: xml; title: ; notranslate">
array(4) {
  [&quot;edit&quot;]=&gt;
    string(137) &quot;&lt;a title=&quot;この項目を編集&quot; href=&quot;http://wp.localhost/wp-admin/post.php?post=31&amp;action=edit&quot;&gt;編集&lt;/a&gt;&quot;
  [&quot;inline hide-if-no-js&quot;]=&gt;
    string(101) &quot;&lt;a class=&quot;editinline&quot; title=&quot;この項目をインラインで編集&quot; href=&quot;#&quot;&gt;クイック編集&lt;/a&gt;&quot;
  [&quot;trash&quot;]=&gt;
    string(205) &quot;&lt;a class=&quot;submitdelete&quot; title=&quot;この項目をゴミ箱へ移動する &quot; href=&quot;http://wp.localhost/wp-admin/post.php?post=31&amp;action=trash&amp;_wpnonce=52d4da28cb&quot;&gt;ゴミ箱&lt;/a&gt;&quot;
  [&quot;view&quot;]=&gt;
    string(223) &quot;&lt;a title=&quot;hogehogeを表示&quot; href=&quot;http://wp.localhost/2016/04/01/hogehoge/&quot; rel=&quot;permalink&quot;&gt;表示&lt;/a&gt;&quot;
}
</pre><br /><br />
<p>見て頂ければ分かる通り、表示する項目が$actionsに保管されています。</p>
<p>今回はクイック編集機能が邪魔なので、</p>
<pre class="brush: xml; title: ; notranslate">
unset($actions['inline hide-if-no-js']);
</pre><br /><br />
<p>によってクイック編集の項目が配列から削除され、表示されなくなります。</p>
<p>また、今回は利用していませんが、$postに投稿のデータが入っているので、投稿に応じた分岐等を行いたい場合は$postを利用して行うことが可能です。</p>
<h2 id="-">さらに</h2>
<p>削除することはもちろん、必要に応じて項目を追加することも可能です。</p>
<p>例えば、（必要かどうかは置いておいて）Googleへのリンクを追加したい場合は</p>
<pre class="brush: xml; title: ; notranslate">
function add_google_to_postlist($actions, $post) {
  $actions['google'] = '&lt;a href=&quot;http://google.com/&quot; target=&quot;_blank&quot;&gt;Google&lt;/a&gt;';

  return $actions;
}
add_filter('post_row_actions', 'add_google_to_postlist', 10, 2);
</pre>
<p>このようにすれば</p>
<p><a href="https://taneppa.net/wp-content/uploads/2016/04/スクリーンショット-2016-04-04-16.11.19.png"><img class="alignnone size-full wp-image-2958" alt="スクリーンショット 2016-04-04 16.11.19" src="https://taneppa.net/wp-content/uploads/2016/04/スクリーンショット-2016-04-04-16.11.19.png" width="465" height="306" /></a></p>
<p>こんな感じでGoogleへのリンクが（必要かどうかは置いておいて）設置されます。</p>
<p>今のところ良い使用用途が思い浮かばないのでこんな例になってしまいましたが、覚えておくとどこかで役に立つかもしれません。</p>
<h2 id="-">以上</h2>
<p>管理画面が使いにくいとWordPressを導入する意味が薄れてしまいますので、管理画面のカスタマイズ方法は出来るだけ仕入れて使いやすい管理画面を作れるようにしたいですね。</p>
<p>以上、たにっぱでした〜</p>
]]></content:encoded>
			<wfw:commentRss>https://taneppa.net/wp_quick_delete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[WordPress]記事投稿時に、タイトルの入力チェックをする方法</title>
		<link>https://taneppa.net/wp_titlechec/</link>
		<comments>https://taneppa.net/wp_titlechec/#comments</comments>
		<pubDate>Mon, 19 Oct 2015 01:34:00 +0000</pubDate>
		<dc:creator>tanippa!</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">https://taneppa.net/?p=2835</guid>
		<description><![CDATA[WordPressでは、記事タイトルの入力チェックをする機能を提供しておりませんので自分で作成する必要があります。なので今回は、タイトルの入力の有無をチェックする方法をご紹介したいと思います。]]></description>
				<content:encoded><![CDATA[<p>AdvancedCustomField(以下ACF)を使っていると、ACFで設定した項目に関しては入力の有無のチェックすることが出来るのですが、残念ながら記事タイトルに関しては入力のチェックをしてくれないので空タイトルの状態でも更新が出来てしまいます。</p>
<p>タイトルは基本的に必須にしたい場合がほとんどだと思いますので、今回はタイトルの入力の有無をチェックする方法をご紹介したいと思います。</p>
<h2 id="-">流れ</h2>
<ul>
  <li>タイトルの入力チェックをするためのJSファイルの作成</li>
  <li>作成したJSファイルを、functions.phpを弄って読み込ませる</li>
</ul>
<h2 id="js-">JSファイルの作成</h2>

<pre class="brush: xml; title: ; notranslate">;(function($){
  var $submitBtn = $('#publish');
  var $titleForm = $('#title');

  $submitBtn.on('click', function(){
    var title = $titleForm.val();

    if (title.length &lt;= 0) {
      alert('タイトルを設定してください。');

      return false;
    }
  });
})(jQuery);</pre>

<p>JSの処理は非常に単純です。</p>
<p>更新ボタンクリック時にタイトルの入力チェックをして、未入力ならアラートを出してキャンセルしています。</p>

<h2 id="functions-php-">functions.phpを弄って読み込ませる</h2>

<pre class="brush: xml; title: ; notranslate">function set_admin_script() {
  print('&lt;script type=&quot;text/javascript&quot; src=&quot;'.get_template_directory_uri().'/common/js/admin.js&quot;&gt;&lt;/script&gt;');
}
add_action('admin_footer', 'set_admin_script');</pre>

<p>「admin_footer」フックを利用することで、管理画面のフッターに任意のコードを出力することが出来ます。</p>
<p>今回は、先ほど作成したJSファイルを読み込ませるようscriptタグを出力させています。</p>
<h2 id="-">以上</h2>
<p>WordPressは管理画面側のカスタマイズが複雑なことが多く、中々上手くいかないこともありますが管理画面が使いにくいとWordPressを導入する意味がなくなってしまいますので頑張って調整しましょう。</p>
<p>以上、たにっぱでした〜</p>]]></content:encoded>
			<wfw:commentRss>https://taneppa.net/wp_titlechec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[WordPress]functions.phpを無名関数を使って簡潔に書こう</title>
		<link>https://taneppa.net/noname_functions/</link>
		<comments>https://taneppa.net/noname_functions/#comments</comments>
		<pubDate>Tue, 13 Oct 2015 01:32:50 +0000</pubDate>
		<dc:creator>tanippa!</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">https://taneppa.net/?p=2831</guid>
		<description><![CDATA[Wordpressではフックを使ってカスタマイズをするのが基本ですが、その際のソースの書き方に関して、無名関数を使用したほうが無駄なくソースを書けるのにネットを見る限り中々浸透していないようです。そこで、今回は無名関数を使用した簡潔な書き方をご紹介したいと思います。]]></description>
				<content:encoded><![CDATA[<p>WordPressではフックを使ってカスタマイズをするのが基本ですが、その際のソースの書き方に関して、無名関数を使用したほうが無駄なくソースを書けるのにネットを見る限り中々浸透していないようです。</p>
<p>そこで、今回は無名関数を使用した簡潔な書き方をご紹介したいと思います。</p>
<h2 id="-">無名関数を使用した簡潔な書き方</h2>
<p>カスタム投稿タイプをfunctions.phpから作成したい場合、以下のようなコードになると思います。</p>

<pre class="brush: xml; title: ; notranslate">function add_news_post_type() {
  $args = array(
    'public' =&gt; true,
    'label'  =&gt; 'News'
  );
  register_post_type('news', $args);
}
add_action('init', 'add_news_post_type');</pre>

<p>この「add_news_post_type」という関数ですが、直後のadd_actionでしか使わないのにわざわざ関数名をつけないといけないの面倒に思いませんか？僕はめちゃくちゃ思います。</p>
<p>これを無名関数を使って書き換えると以下のようになります。</p>

<pre class="brush: xml; title: ; notranslate">add_action('init', function() {
  $args = array(
    'public' =&gt; true,
    'label'  =&gt; 'News'
  );
  register_post_type('news', $args);
});</pre>

<p>この場合の関数「function() {~}」のことを「無名関数」と言います。普通関数は「function get_some_values() {}」みたいな感じにfunctionの後ろには名前が必要なのに今回付いてないですよね？なので「無名」関数です。jQueryを使った経験のある方にはお馴染みですね。</p>
<p>この書き方の何がいいかというと、関数名を考えなくていいので</p>
<ul>
  <li>関数名に悩む時間を節約できる</li>
  <li>関数名の重複による問題に悩まされずに済む</li>
</ul>
<p>の２点です。</p>
<p>注意としては、無名関数はPHP5.3以降からの対応となるので、少なくなっては来ましたがPHP5.2以下の環境では使えないということに注意しましょう。</p>
<h2 id="-">以上</h2>
<p>自分は変数名・関数名を考えるのに時間を掛けてしまうタイプなので、出来るだけ考えなくていい場面では考えずに済ませるようにしたいと思ってこの書き方は最近多用しています。</p>
<p>以上たにっぱでした〜</p>]]></content:encoded>
			<wfw:commentRss>https://taneppa.net/noname_functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
