Last active
January 9, 2018 04:57
-
-
Save mt8/7b1cab105d9a29f2ec931d798f32712e to your computer and use it in GitHub Desktop.
[WordPress] bbPressのカスタマイズサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//「今後の返信をメールで通知」の後にフック | |
add_action('bbp_theme_after_reply_form_subscription', 'my_bbp_theme_after_reply_form_subscription'); | |
/** | |
* トピック回答フォームの「今後の返信をメールで通知」項目の後のアクションフック処理 | |
*/ | |
function my_bbp_theme_after_reply_form_subscription() { | |
?> | |
<p> | |
<input name="bbp_reply_limited" id="bbp_reply_limited" type="checkbox" value="1" <?php bbp_form_reply_limited(); ?> ?> /> | |
<label for="bbp_reply_limited"><?php echo 'この回答を会員限定にする'; ?></label> | |
</p> | |
<?php | |
} | |
//返信の作成・編集にフック | |
add_action('bbp_new_reply', 'my_bbp_update_reply', 10, 7); | |
add_action('bbp_edit_reply', 'my_bbp_update_reply', 10, 7); | |
/** | |
* 返信の作成・編集にフック | |
* @param int $reply_id | |
* @param int $topic_id | |
* @param int $forum_id | |
* @param boolean $anonymous_data | |
* @param int $author_id | |
* @param boolean $is_edit | |
* @param int $reply_to | |
*/ | |
function my_bbp_update_reply($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0) { | |
$reply_limited = (bool) $_POST['bbp_reply_limited']; | |
update_post_meta($reply_id, '_bbp_reply_limited', $reply_limited); | |
} | |
/** | |
* 返信が会員限定か出力する | |
*/ | |
function bbp_form_reply_limited() { | |
echo bbp_get_form_reply_limited(); | |
} | |
/** | |
* 返信が会員限定か取得する | |
* @return string | |
*/ | |
function bbp_get_form_reply_limited() { | |
// Get _POST data | |
if ( bbp_is_post_request() && isset( $_POST['bbp_reply_limited'] ) ) { | |
$reply_limited = (bool) $_POST['bbp_reply_limited']; | |
// Get edit data | |
} elseif ( bbp_is_reply_edit() ) { | |
$reply_id = get_the_ID(); | |
$reply_limited = (bool) get_post_meta( $reply_id, '_bbp_reply_limited', true ); | |
} else { | |
$reply_limited = false; | |
} | |
// Get checked output | |
return checked( $reply_limited, true, false ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('wp_loaded', 'my_wp_loaded'); | |
/** | |
* WordPress 処理完了時にフック | |
*/ | |
function my_wp_loaded() { | |
//ログイン時で、リダイレクト先が指定されている場合 | |
if (is_user_logged_in()) { | |
//BBPressのログインページ用のショートコードを削除してオリジナル処理に切り替える | |
remove_shortcode('bbp-login'); | |
add_shortcode('bbp-login', 'my_bbp_login'); | |
} | |
} | |
/** | |
* [bbp_login]ショートコードでログイン時に元のページ戻るための処理 | |
*/ | |
function my_bbp_login() { | |
$re = ( isset($_GET['re']) ) ? $_GET['re'] : ''; | |
if ($re != '') { | |
wp_safe_redirect($re); | |
} else { | |
wp_safe_redirect(get_home_url()); | |
} | |
exit; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//トピックの作成・編集にフック | |
add_action('bbp_new_topic', 'my_bbp_update_topic', 10, 5); | |
add_action('bbp_edit_topic', 'my_bbp_update_topic', 10, 5); | |
/** | |
* トピックの作成・編集にフック | |
* @param int $topic_id | |
* @param int $forum_id | |
* @param boolean $anonymous_data | |
* @param int $author_id | |
* @param boolean $is_edit | |
*/ | |
function my_bbp_update_topic($topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false) { | |
//トピックを取得 | |
$topic = bbp_get_topic($topic_id); | |
} | |
//回答の作成・編集にフック | |
add_action('bbp_new_reply', 'my_bbp_update_reply', 10, 7); | |
add_action('bbp_edit_reply', 'my_bbp_update_reply', 10, 7 ); | |
/** | |
* 返信の作成・編集にフック | |
* @param int $reply_id | |
* @param int $topic_id | |
* @param int $forum_id | |
* @param boolean $anonymous_data | |
* @param int $author_id | |
* @param boolean $is_edit | |
* @param int $reply_to | |
*/ | |
function my_bbp_update_reply($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0) { | |
//回答を取得 | |
$reply = bbp_get_reply($reply_id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mail_to_keymaster($subject, $message) { | |
$keymasters = get_users(array('role' => 'bbp_keymaster')); | |
if (!$keymasters) { | |
return; | |
} | |
$keymaster = $keymasters[0]; | |
wp_mail($keymaster->user_email, $subject, $message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment