Пример #1
0
 /**
  * Callback for the `save_post` hook to handle meta boxes.
  *
  * @since  1.0.0
  * @access public
  * @param  int     $post_id
  * @param  object  $post
  * @return void
  */
 function save_post($post_id, $post)
 {
     /* Fix for attachment save issue in WordPress 3.5. @link http://core.trac.wordpress.org/ticket/21963 */
     if (!is_object($post)) {
         $post = get_post();
     }
     if (mb_get_forum_post_type() !== $post->post_type) {
         return;
     }
     if (!isset($_POST['mb_forum_attr_nonce']) || !wp_verify_nonce($_POST['mb_forum_attr_nonce'], '_mb_forum_attr_nonce')) {
         return;
     }
     /* Set the forum type. */
     if (isset($_POST['mb_forum_type']) && mb_get_forum_type($post_id) !== $_POST['mb_forum_type']) {
         mb_set_forum_type($post_id, sanitize_key($_POST['mb_forum_type']));
     }
 }
Пример #2
0
/**
 * Front end edit forum handler.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function mb_handler_edit_forum()
{
    /* Verify the nonce. */
    if (!mb_check_post_nonce('mb_edit_forum_nonce', 'mb_edit_forum_action')) {
        return;
    }
    /* Make sure we have a forum ID. */
    if (!isset($_POST['mb_forum_id'])) {
        mb_bring_the_doom('what-edit');
    }
    /* Get the forum ID. */
    $forum_id = mb_get_forum_id($_POST['mb_forum_id']);
    /* Make sure the current user can edit this forum. */
    if (!current_user_can('edit_forum', $forum_id)) {
        mb_bring_the_doom('no-permission');
    }
    /* Make sure we have a forum title. */
    if (empty($_POST['mb_forum_title'])) {
        mb_bring_the_doom('no-title');
    }
    /* Post title. */
    $post_title = apply_filters('mb_pre_insert_forum_title', $_POST['mb_forum_title']);
    /* Post content. */
    $post_content = apply_filters('mb_pre_insert_forum_content', $_POST['mb_forum_content']);
    /* Forum ID. */
    $post_parent = isset($_POST['mb_post_parent']) ? absint($_POST['mb_post_parent']) : mb_get_forum_parent_id($forum_id);
    /* Menu order. */
    $menu_order = isset($_POST['mb_menu_order']) ? intval($_POST['mb_menu_order']) : mb_get_forum_order($forum_id);
    /* Update the forum. */
    $published = wp_update_post(array('ID' => $forum_id, 'post_title' => $post_title, 'post_content' => $post_content, 'post_parent' => $post_parent, 'menu_order' => $menu_order));
    /* If the post was published. */
    if ($published && !is_wp_error($published)) {
        $user_id = mb_get_forum_author_id($published);
        /* Forum type. */
        if (isset($_POST['mb_forum_type'])) {
            mb_set_forum_type($published, sanitize_key($_POST['mb_forum_type']));
        }
        /* If the user chose to subscribe to the forum. */
        if (isset($_POST['mb_forum_subscribe']) && 1 === absint($_POST['mb_forum_subscribe'])) {
            mb_add_user_forum_subscription($user_id, $published);
        } else {
            mb_remove_user_forum_subscription($user_id, $published);
        }
        /* Redirect to the published topic page. */
        wp_safe_redirect(get_permalink($published));
        exit;
    }
}