質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

Q&A

1回答

3218閲覧

ワードプレス[bbPress - Private Replies]の全コードです。「トピック投稿者」に対して「プライベート返信」が表示されません!何故?分かる方、お力を貸して下さい!

ugzero

総合スコア14

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

0グッド

1クリップ

投稿2018/10/28 12:51

前提・実現したいこと

[bbPress - Private Replies]プラグインを使って、トピックに対する一部の返信をプライベート化し、投稿者と返信者(と管理者[Keymaster])だけが見れるようにしたい、と思っています。

発生している問題・エラーメッセージ

本来トピック投稿者が見れるはずのプライベート返信が、投稿者に対しても隠されて表示され、内容が見れません。  ・トピック投稿者が「投稿した人」として認識されていない?  ・権限設定の問題でしょうか。    フォーラム権限が参加者[participant]の方が投稿&返信する前提です。    ※ワードプレスの権限は上記とは別に、「購読者」としています。 ・管理者[Keymaster]が作成したプライベート返信のみ、投稿者から閲覧可能でした。     ・プライベート返信を作成した本人は、閲覧できます。 どなたか、お力を貸して下さいませ。 コード全文はこちらです →https://github.com/pippinsplugins/bbPress-Private-replies/blob/master/bbp-private-replies.php 文字数が許す限り、途中まで以下にも添付させて頂きます。

該当のソースコード

<?php /* Plugin Name: bbPress - Private Replies Description: Allows users to set replies as private so that only the original poster and admins can see it */ class BBP_Private_Replies { /** * The capability required to view private posts. * * @since 1.3.3 * * @var string $capability */ public $capability = 'moderate'; /*--------------------------------------------* * Constructor *--------------------------------------------*/ /** * Initializes the plugin by setting localization, filters, and administration functions. */ function __construct() { // load the plugin translation files add_action( 'init', array( $this, 'textdomain' ) ); // Allow others to change the capability required to view private posts. add_action( 'plugins_loaded', array( $this, 'filter_capability' ) ); // show the "Private Reply?" checkbox add_action( 'bbp_theme_before_reply_form_submit_wrapper', array( $this, 'checkbox' ) ); // save the private reply state add_action( 'bbp_new_reply', array( $this, 'update_reply' ), 0, 6 ); add_action( 'bbp_edit_reply', array( $this, 'update_reply' ), 0, 6 ); // hide reply content add_filter( 'bbp_get_reply_excerpt', array( $this, 'hide_reply' ), 999, 2 ); add_filter( 'bbp_get_reply_content', array( $this, 'hide_reply' ), 999, 2 ); add_filter( 'the_content', array( $this, 'hide_reply' ), 999 ); add_filter( 'the_excerpt', array( $this, 'hide_reply' ), 999 ); // prevent private replies from being sent in email subscriptions add_filter( 'bbp_subscription_mail_message', array( $this, 'prevent_subscription_email' ), 999999, 3 ); // add a class name indicating the read status add_filter( 'post_class', array( $this, 'reply_post_class' ) ); // register css files add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) ); } // end constructor /** * Load the plugin's text domain * * @since 1.0 * * @return void */ public function textdomain() { load_plugin_textdomain( 'bbp_private_replies', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } /** * Called during the plugins_loaded action to filter the capability * required to view private replies. * * @since 1.3.3 * * @return void */ public function filter_capability() { $this->capability = apply_filters( 'bbp_private_replies_capability', $this->capability ); } /** * Retrieves the no reply address. * * @since 1.3.3 * * @return string */ public function get_no_reply() { return apply_filters( 'bbp_private_replies_no_reply_address', bbp_get_do_not_reply_address() ); } /** * Outputs the "Set as private reply" checkbox * * @since 1.0 * * @return void */ public function checkbox() { ?> <p> <input name="bbp_private_reply" id="bbp_private_reply" type="checkbox"<?php checked( '1', $this->is_private( bbp_get_reply_id() ) ); ?> value="1" tabindex="<?php bbp_tab_index(); ?>" /> <?php if ( bbp_is_reply_edit() && ( get_the_author_meta( 'ID' ) != bbp_get_current_user_id() ) ) : ?> <label for="bbp_private_reply"><?php _e( 'Set author\'s post as private.', 'bbp_private_replies' ); ?></label> <?php else : ?> <label for="bbp_private_reply"><?php _e( 'Set as private reply', 'bbp_private_replies' ); ?></label> <?php endif; ?> </p> <?php } /** * Stores the private state on reply creation and edit * * @since 1.0 * * @param $reply_id int The ID of the reply * @param $topic_id int The ID of the topic the reply belongs to * @param $forum_id int The ID of the forum the topic belongs to * @param $anonymous_data bool Are we posting as an anonymous user? * @param $author_id int The ID of user creating the reply, or the ID of the replie's author during edit * @param $is_edit bool Are we editing a reply? * * @return void */ public function update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false ) { if( isset( $_POST['bbp_private_reply'] ) ) update_post_meta( $reply_id, '_bbp_reply_is_private', '1' ); else delete_post_meta( $reply_id, '_bbp_reply_is_private' ); } /** * Determines if a reply is marked as private * * @since 1.0 * * @param $reply_id int The ID of the reply * * @return bool */ public function is_private( $reply_id = 0 ) { $retval = false; // Checking a specific reply id if ( !empty( $reply_id ) ) { $reply = bbp_get_reply( $reply_id ); $reply_id = !empty( $reply ) ? $reply->ID : 0; // Using the global reply id } elseif ( bbp_get_reply_id() ) { $reply_id = bbp_get_reply_id(); // Use the current post id } elseif ( !bbp_get_reply_id() ) { $reply_id = get_the_ID(); } if ( ! empty( $reply_id ) ) { $retval = get_post_meta( $reply_id, '_bbp_reply_is_private', true ); } return (bool) apply_filters( 'bbp_reply_is_private', (bool) $retval, $reply_id ); } /** * Hides the reply content for users that do not have permission to view it * * @since 1.0 * * @param $content string The content of the reply * @param $reply_id int The ID of the reply * * @return string */ public function hide_reply( $content = '', $reply_id = 0 ) { if( empty( $reply_id ) ) $reply_id = bbp_get_reply_id( $reply_id ); if( $this->is_private( $reply_id ) ) { $can_view = false; $current_user = is_user_logged_in() ? wp_get_current_user() : false; $topic_author = bbp_get_topic_author_id(); $reply_author = bbp_get_reply_author_id( $reply_id ); if ( ! empty( $current_user ) && $topic_author === $current_user->ID && user_can( $reply_author, $this->capability ) ) { // Let the thread author view replies if the reply author is from a moderator $can_view = true; } if ( ! empty( $current_user ) && $reply_author === $current_user->ID ) { // Let the reply author view their own reply $can_view = true; } if( current_user_can( $this->capability ) ) { // Let moderators view all replies $can_view = true; } if( ! $can_view ) { $content = __( 'This reply has been marked as private.', 'bbp_private_replies' ); } } return $content; } /** * Prevents a New Reply notification from being sent if the user doesn't have permission to view it * * @since 1.0 * * @param $message string The email message * @param $reply_id int The ID of the reply * @param $topic_id int The ID of the reply's topic * * @return mixed */ public function prevent_subscription_email( $message, $reply_id, $topic_id ) { if( $this->is_private( $reply_id ) ) { $this->subscription_email( $message, $reply_id, $topic_id ); return false; } return $message; // message unchanged } /** * Sends the new reply notification email to moderators on private replies * * @since 1.2 * * @param $message string The email message * @param $reply_id int The ID of the reply * @param $topic_id int The ID of the reply's topic * * @return void */ public function subscription_email( $message, $reply_id, $topic_id ) { if( ! $this->is_private( $reply_id ) ) { return false; // reply isn't private so do nothing } $topic_author = bbp_get_topic_author_id( $topic_id ); $reply_author = bbp_get_reply_author_id( $reply_id ); $reply_author_name = bbp_get_reply_author_display_name( $reply_id ); // Strip tags from text and setup mail data $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) ); $reply_url = bbp_get_reply_url( $reply_id ); $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id ); // Array to hold BCC's $headers = array(); // Setup the From header $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <' . $this->get_no_reply() . '>'; // Get topic subscribers and bail if empty $user_ids = bbp_get_topic_subscribers( $topic_id, true ); if ( empty( $user_ids ) ) { return false; } // Loop through users foreach ( (array) $user_ids as $user_id ) { // Don't send notifications to the person who made the post if ( ! empty( $reply_author ) && (int) $user_id === (int) $reply_author ) { continue; } $should_notify_op = user_can( $reply_author, $this->capability ) && (int) $topic_author === (int) $user_id; if( user_can( $user_id, $this->capability ) || $should_notify_op ) { // Get email address of subscribed user $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email; } } wp_mail( $this->get_no_reply(), $subject, $message, $headers ); } /** * Adds a new class to replies that are marked as private * * @since 1.0 * * @param $classes array An array of current class names * * @return bool */

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ugzero

2018/10/30 12:22

すみません。同じ件でしてより詳しく書こうと思い新たな質問を立てたのですが、前のを消し忘れていました。削除リクエスト中です。
guest

回答1

0

色々試しているうちに少し理解が進んだのですが、
・キーマスターからのプライベート返信は、投稿者側で見れる
・モデレーターからのプライベート返信も、投稿者側で見れる
・参加者が作成したプライベート返信のみ、投稿者側で見ることができない
という状況です。

解決に至っておりませんが、中間報告をさせて頂きます。

投稿2018/10/28 13:38

ugzero

総合スコア14

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問