カテゴリー
wordpress

mixi OpenIDを使ったコメント欄を作る

mixi OpenIDを使って、mixiにアカウントがある人なら名前やURLをmixiから取得して簡単にコメントを送信できる機能を実装する。

参考にしたページは次のとおり。

最初、https://id.mixi.jp/nnn は使えるけど https://mixi.jp/ は使えないということに悩んだが、どうやらOpenIDプラグインに内包されているphp-openidモジュールがだめだったらしく、portsからsecurity/php-Auth_OpenID2をインストールしたら直った。

さて、プラグインをインストールしただけでは、ただ単に普通のコメント欄でOpenIDが使えるだけなので、専用のフォームを用意する。テーマのcomments.phpの出したい位置に以下を記述。


<form class="post" method="post" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" id="commentsForm">
<fieldset>
<legend>コメントフォーム For mixiユーザー</legend>
<div>
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
<input type="hidden" name="openid_identifier" id="openid_identifier" value="https://mixi.jp/"/>
<input type="hidden" class="inputField" id="comment-author" name="author" value="test" />
<input type="hidden" class="inputField" id="comment-email" name="email" value="foo@example.com" />
<input type="hidden" id="login_with_openid" name="login_with_openid" value="checked" />
</div>
<dl>
<dt><label for="comment-text"><?php if ( allowed_tags() ) : ?><span>
<?php _e('You can use some <abbr title="Hyper Text Markup Language">HTML</abbr> tags for decorating.', 'vicuna'); ?>
</span><?php else : ?><span>
<?php _e('You cannot use <abbr title="Hyper Text Markup Language">HTML</abbr> tags', 'vicuna'); ?>
</span><?php endif; ?></label></dt>
<dd><textarea name="comment" id="comment" cols="50" rows="8"></textarea>
</dl>
<div class="action">
<input name="submit" type="submit" id="submit" tabindex="5" value="mixiで認証して送信">
</div>
</fieldset>
</form>

これで、この記事の下にあるような「コメントフォーム For mixiユーザー」が出来上がり、ボタン1つで気軽にコメントが送れるようになった。

ということで、mixiユーザーは試しにコメントしてみてくれるとうれしいかも。

Share this...

「mixi OpenIDを使ったコメント欄を作る」への13件の返信

そういえばopenid.ne.jpのアカウント持ってたなぁ、と思ってテストしようとしたら、パスワード忘れてて、しかも再設定メールが届かない(汗)。
調べてみます。

上記以外の設定で何か変更することとかってあります・・・?
OpenID認証後、下記のエラーが出るんですけども(´・ω・`)

—————-
OpenID Authentication Error

We were unable to authenticate your claimed OpenID, however you can continue to post your comment without OpenID

うちのサイトに書き込みしようとしたときにエラーになるんですよねぇ。
ちょっとわからないので、調べてみます。

コメントは受け付けていません。

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny