setup_globals(); $this->setup_actions(); $this->setup_help(); } /** * Setup the admin hooks, actions and filters * * @since bbPress (r2646) * @access private * * @uses add_action() To add various actions * @uses add_filter() To add various filters * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type */ function setup_actions() { // Add some general styling to the admin area add_action( 'admin_head', array( $this, 'admin_head' ) ); // Messages add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); // Topic column headers. add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'topics_column_headers' ) ); // Topic columns (in post row) add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'topics_column_data' ), 10, 2 ); add_filter( 'post_row_actions', array( $this, 'topics_row_actions' ), 10, 2 ); // Topic metabox actions add_action( 'add_meta_boxes', array( $this, 'topic_attributes_metabox' ) ); add_action( 'save_post', array( $this, 'topic_attributes_metabox_save' ) ); // Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed add_action( 'bbp_admin_init', array( $this, 'toggle_topic' ) ); add_action( 'admin_notices', array( $this, 'toggle_topic_notice' ) ); // Anonymous metabox actions add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) ); add_action( 'save_post', array( $this, 'author_metabox_save' ) ); // Add ability to filter topics and replies per forum add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) ); add_filter( 'request', array( $this, 'filter_post_rows' ) ); } /** * Admin globals * * @since bbPress (r2646) * @access private */ function setup_globals() { // Setup the post type for this admin component $this->post_type = bbp_get_topic_post_type(); } /** * Contextual help for topics * * @since bbPress (r3119) * @access private */ function setup_help() { // Define local variable(s) $contextual_help = array(); /** New/Edit **********************************************************/ $bbp_contextual_help[] = __( 'The topic title field and the big topic editing area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of the box. Use the Screen Options tab to unhide more boxes (Topic Tags, Topic Attributes, or Slug) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ); $bbp_contextual_help[] = __( 'Title - Enter a title for your topic. After you enter a title, you will see the permalink below, which you can edit.', 'bbpress' ); $bbp_contextual_help[] = __( 'Post editor - Enter the text for your topic. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The screen icon just before that allows you to expand the edit box to full screen. The HTML mode allows you to enter raw HTML along with your forum text. You can insert media files by clicking the icons above the post editor and following the directions.', 'bbpress' ); $bbp_contextual_help[] = __( 'Topic Attributes - Select the attributes that your topic should have. The Forum dropdown determines the parent forum that the topic belongs to. Select the forum or category from the dropdown, or leave the default (No Forum) to post the topic without an assigned forum.', 'bbpress' ); $bbp_contextual_help[] = __( 'Publish - The Publish box will allow you to save your topic as Draft or Pending Review. You may Preview your topic before it is published as well. The Visibility will determine whether the topic is Public, Password protected (requiring a password on the site to view) or Private (only the author will have access to it). Topics may be published immediately by clicking the dropdown, or at a specific date and time by clicking the Edit link.', 'bbpress' ); $bbp_contextual_help[] = __( 'Topic Tags - You can assign keywords to your topics using Topic Tags. Unlike categories, tags have no hierarchy, meaning there is no relationship from one tag to another. Topics can be added and modified further from the Topic Tags screen.', 'bbpress' ); $bbp_contextual_help[] = __( 'Revisions - Revisions show past versions of the saved topic. Each revision can be compared to the current version, or another revision. Revisions can also be restored to the current version.', 'bbpress' ); $bbp_contextual_help[] = __( 'For more information:', 'bbpress' ); $bbp_contextual_help[] = '
' . $paragraph . '
'; // Add help add_contextual_help( bbp_get_topic_post_type(), $contextual_help ); // Reset $contextual_help = $bbp_contextual_help = ''; /** Post Rows *********************************************************/ $bbp_contextual_help[] = __( 'This screen displays the topics created on your site.', 'bbpress' ); $bbp_contextual_help[] = __( 'You can customize the display of this screen in a number of ways:', 'bbpress' ); $bbp_contextual_help[] = '' . $paragraph . '
'; // Add help add_contextual_help( bbp_get_topic_post_type(), $contextual_help ); // Reset $contextual_help = $bbp_contextual_help = ''; /** Topic Tags **********************************************************/ $bbp_contextual_help[] = __( 'You can change the display of this screen using the Screen Options tab to set how many items are displayed per screen (20 by default) and to display/hide columns in the table (Description, Slug, and Topics).', 'bbpress' ); $bbp_contextual_help[] = __( 'You can assign keywords to your topics using Topic Tags. Unlike categories, tags have no hierarchy, meaning there is no relationship from one tag to another.', 'bbpress' ); $bbp_contextual_help[] = __( 'Normally, tags are ad-hoc keywords that identify important information in your topic (names, subjects, etc) that may or may not recur in other topics. If you think of your forum like a book, the tags are like the terms in the index.', 'bbpress' ); $bbp_contextual_help[] = __( 'When editing a topic tag on this screen, you will fill in the following fields:', 'bbpress' ); $bbp_contextual_help[] = '' . $paragraph . '
'; // Add help global $bbp; add_contextual_help( 'edit-' . bbp_get_topic_tag_tax_id(), $contextual_help ); } /** * Add the topic attributes metabox * * @since bbPress (r2744) * * @uses bbp_get_topic_post_type() To get the topic post type * @uses add_meta_box() To add the metabox * @uses do_action() Calls 'bbp_topic_attributes_metabox' */ function topic_attributes_metabox() { add_meta_box ( 'bbp_topic_attributes', __( 'Topic Attributes', 'bbpress' ), 'bbp_topic_metabox', $this->post_type, 'side', 'high' ); do_action( 'bbp_topic_attributes_metabox' ); } /** * Pass the topic attributes for processing * * @since bbPress (r2746) * * @param int $topic_id Topic id * @uses current_user_can() To check if the current user is capable of * editing the topic * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the * topic id and parent id * @return int Parent id */ function topic_attributes_metabox_save( $topic_id ) { // Bail if doing an autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $topic_id; // Bail if not a post request if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) ) return $topic_id; // Bail if post_type is not a topic if ( get_post_type( $topic_id ) != $this->post_type ) return; // Bail if current user cannot edit this topic if ( !current_user_can( 'edit_topic', $topic_id ) ) return $topic_id; // Get the forum ID $forum_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0; // Formally update the topic bbp_update_topic( $topic_id, $forum_id ); // Allow other fun things to happen do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $forum_id ); return $topic_id; } /** * Add the author info metabox * * @since bbPress (r2828) * * @uses bbp_get_topic() To get the topic * @uses bbp_get_reply() To get the reply * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses add_meta_box() To add the metabox * @uses do_action() Calls 'bbp_author_metabox' with the topic/reply * id */ function author_metabox() { global $current_screen; // Bail if post_type is not a topic if ( ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) ) || ( get_post_type() != $this->post_type ) ) return; // Add the metabox add_meta_box( 'bbp_author_metabox', __( 'Author Information', 'bbpress' ), 'bbp_author_metabox', $this->post_type, 'side', 'high' ); do_action( 'bbp_author_metabox', get_the_ID() ); } /** * Save the author information for the topic * * @since bbPress (r2828) * * @param int $post_id Topic or reply id * @uses bbp_get_topic() To get the topic * @uses bbp_get_reply() To get the reply * @uses current_user_can() To check if the current user can edit the * topic or reply * @uses bbp_filter_author_post_data() To filter the author data * @uses update_post_meta() To update the anonymous user data * @uses do_action() Calls 'bbp_author_metabox_save' with the topic id and * anonymous data * @return int Topic or reply id */ function author_metabox_save( $post_id ) { // Bail if no post_id if ( empty( $post_id ) ) return $post_id; // Bail if doing an autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; // Bail if not a post request if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) ) return $post_id; // Bail if post_type is not a topic or reply if ( get_post_type( $post_id ) != $this->post_type ) return; // Bail if user cannot edit replies if ( !current_user_can( 'edit_topic', $post_id ) ) return $post_id; $anonymous_data = bbp_filter_anonymous_post_data(); update_post_meta( $post_id, '_bbp_anonymous_name', $anonymous_data['bbp_anonymous_name'] ); update_post_meta( $post_id, '_bbp_anonymous_email', $anonymous_data['bbp_anonymous_email'] ); update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] ); do_action( 'bbp_author_metabox_save', $post_id, $anonymous_data ); return $post_id; } /** * Add some general styling to the admin area * * @since bbPress (r2464) * * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses sanitize_html_class() To sanitize the classes * @uses do_action() Calls 'bbp_admin_head' */ function admin_head() { if ( get_post_type() == $this->post_type ) : ?> $topic_id ); // Prelim array if ( !$topic = bbp_get_topic( $topic_id ) ) // Which topic? wp_die( __( 'The topic was not found!', 'bbpress' ) ); if ( !current_user_can( 'moderate', $topic->ID ) ) // What is the user doing here? wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) ); switch ( $action ) { case 'bbp_toggle_topic_close' : check_admin_referer( 'close-topic_' . $topic_id ); $is_open = bbp_is_topic_open( $topic_id ); $message = true == $is_open ? 'closed' : 'opened'; $success = true == $is_open ? bbp_close_topic( $topic_id ) : bbp_open_topic( $topic_id ); break; case 'bbp_toggle_topic_stick' : check_admin_referer( 'stick-topic_' . $topic_id ); $is_sticky = bbp_is_topic_sticky( $topic_id ); $is_super = ( empty( $is_sticky ) && !empty( $_GET['super'] ) && 1 == (int) $_GET['super'] ) ? true : false; $message = true == $is_sticky ? 'unsticked' : 'sticked'; $message = true == $is_super ? 'super_sticked' : $message; $success = true == $is_sticky ? bbp_unstick_topic( $topic_id ) : bbp_stick_topic( $topic_id, $is_super ); break; case 'bbp_toggle_topic_spam' : check_admin_referer( 'spam-topic_' . $topic_id ); $is_spam = bbp_is_topic_spam( $topic_id ); $message = true == $is_spam ? 'unspammed' : 'spammed'; $success = true == $is_spam ? bbp_unspam_topic( $topic_id ) : bbp_spam_topic( $topic_id ); break; } $message = array( 'bbp_topic_toggle_notice' => $message, 'topic_id' => $topic->ID ); if ( false == $success || is_wp_error( $success ) ) $message['failed'] = '1'; // Do additional topic toggle actions (admin side) do_action( 'bbp_toggle_topic_admin', $success, $post_data, $action, $message ); // Redirect back to the topic $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'topic_id' ) ) ); wp_redirect( $redirect ); // For good measure exit(); } } /** * Toggle topic notices * * Display the success/error notices from * {@link BBP_Admin::toggle_topic()} * * @since bbPress (r2727) * * @uses bbp_get_topic() To get the topic * @uses bbp_get_topic_title() To get the topic title of the topic * @uses esc_html() To sanitize the topic title * @uses apply_filters() Calls 'bbp_toggle_topic_notice_admin' with * message, topic id, notice and is it a failure */ function toggle_topic_notice() { // Only proceed if GET is a topic toggle action if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['bbp_topic_toggle_notice'] ) && in_array( $_GET['bbp_topic_toggle_notice'], array( 'opened', 'closed', 'super_sticked', 'sticked', 'unsticked', 'spammed', 'unspammed' ) ) && !empty( $_GET['topic_id'] ) ) { $notice = $_GET['bbp_topic_toggle_notice']; // Which notice? $topic_id = (int) $_GET['topic_id']; // What's the topic id? $is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure? // Empty? No topic? if ( empty( $notice ) || empty( $topic_id ) || !$topic = bbp_get_topic( $topic_id ) ) return; $topic_title = esc_html( bbp_get_topic_title( $topic->ID ) ); switch ( $notice ) { case 'opened' : $message = $is_failure == true ? sprintf( __( 'There was a problem opening the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully opened.', 'bbpress' ), $topic_title ); break; case 'closed' : $message = $is_failure == true ? sprintf( __( 'There was a problem closing the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully closed.', 'bbpress' ), $topic_title ); break; case 'super_sticked' : $message = $is_failure == true ? sprintf( __( 'There was a problem sticking the topic "%1$s" to front.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked to front.', 'bbpress' ), $topic_title ); break; case 'sticked' : $message = $is_failure == true ? sprintf( __( 'There was a problem sticking the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked.', 'bbpress' ), $topic_title ); break; case 'unsticked' : $message = $is_failure == true ? sprintf( __( 'There was a problem unsticking the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unsticked.', 'bbpress' ), $topic_title ); break; case 'spammed' : $message = $is_failure == true ? sprintf( __( 'There was a problem marking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully marked as spam.', 'bbpress' ), $topic_title ); break; case 'unspammed' : $message = $is_failure == true ? sprintf( __( 'There was a problem unmarking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unmarked as spam.', 'bbpress' ), $topic_title ); break; } // Do additional topic toggle notice filters (admin side) $message = apply_filters( 'bbp_toggle_topic_notice_admin', $message, $topic->ID, $notice, $is_failure ); ?>