ログイン時のみ見える情報を作るプラグイン「Private Content」

≪≪この記事をすべて読むには約 5 分かかります≫≫

ブログに書いた記事はそのまま誰にでも見えるのが基本だと思います。ただ、時々後で見返した時に自分が参考にしたいこともあるのではないかと思います。

ログインしたユーザー(もしくは特定のユーザー)だけが見られる部分を作るプラグイン「Private Content」を別サイトで導入しました。

Private Content

ショートコードを入れるとその部分だけ特定ユーザーにのみ見えるようになるというプラグインです。PHPをいじれば作れるという情報はあちこちにありますが、プラグインの形でないと、忘れたころにメンテナンスできなくなるのが難点だと思っています。

別のサイトに移植するときとか、壊れた時に再現するのが大変です。ブログに載せていたとしても、結構大変ですよね。function.phpに設定した項目を何年もたって覚えているのか、とか、テーマを変えた時になくなってしまって困ったとか、最近よく困っています。

そういうものを解決するには、やはり配布されているプラグインに頼るのが良いです。CSSで指定するとかそういうものと違って、ソースコードにも表示されないのでまあまあ安心できます。

見出し一覧

使い方

有効にしたら、必要な部位にショートコードを挿入します。

[[private]] ログインユーザーにのみ見せたい情報 [[/private]](一重の【】で囲む)

が基本です。 privateの後に [[private role=administrator]]などを入れると管理者のみ見られる、などのカスタマイズができます。

administratorAdministratorsのみ
editorEditors and Administrators
editor-onlyEditorsのみ
authorAuthors, Editors, Administrators.
author-onlyAuthorsのみ
contributorContributors, Authors, Editors, Administrators.
contributor-onlyContributorsのみ
subscriberSubscribers, Contributors, Authors, Editors, Administrators.
subscriber-onlySubscribersのみ
visitor / visitor-onlyゲストのみ見られるが、Administratorsは読める
noneWhen used, it is mandatory to use also the recipient option. The hidden text is shown only to users in the recipient list. Administrators cannot read the hidden text.
customWhen used, it is mandatory to use also the custom_role option. The hidden text is shown only to users that have a role in the custom_role list. Administrators can read the hidden text.
custom-onlyWhen used, it is mandatory to use also the custom_role option. The hidden text is shown only to users that have a role in the custom_role list. Administrators cannot read the hidden text.

後半のはさらに複雑です。role以外のオプションも指定して記載する必要があります。そこまでする必要があることが、Wordpressで必要なのかは疑問ですが・・・。