function ccgn_get_post_form($group_id = false)
{
    $group_id = !$group_id ? bp_get_current_group_id() : $group_id;
    // Should the user be able to visit this page?
    if (!ccgn_current_user_can_post()) {
        echo '<div id="message" class="error"><p>You do not have the capability to edit or create posts in this group.</p></div>';
        return;
    }
    //If the $_POST array is set, we should save the post and redirect to the edit page.
    if ($_POST) {
        ccgn_save_narrative($group_id);
    }
    //Edit page functionality
    $actions = bp_action_variables();
    if ('edit' == $actions[0]) {
        if (!$actions[1]) {
            // This is a new post and we need to auto-draft it.
            $post_id = wp_insert_post(array('post_title' => __('Auto Draft'), 'post_type' => 'group_story', 'post_status' => 'auto-draft'));
        } else {
            //This is an existing post and we need to pre-fill the form
            $post_id = (int) $actions[1];
            $post = get_post($post_id, OBJECT, 'edit');
            $post_content = $post->post_content;
            $post_title = $post->post_title;
            $post_published = $post->post_status;
            $comment_status = $post->comment_status;
        }
    }
    //Warn WP that we're going to want the media js
    //TODO I'm skeptical of this
    $args = array('post' => $post_id);
    wp_enqueue_media($args);
    // $GLOBALS['post_ID'] = $post_id;
    ?>

	<form enctype="multipart/form-data" action="<?php 
    echo ccgn_get_home_permalink() . "/edit/" . $post_id;
    ?>
" method="post" class="standard-form">

		<label for="ccgn_title">Title&emsp;<input type="text" value="<?php 
    echo apply_filters("the_title", $post_title);
    ?>
" name="ccgn_title" size="80"></label>

		<?php 
    $args = array('tinymce' => true, 'media_buttons' => true, 'editor_height' => 360, 'tabfocus_elements' => 'insert-media-button,save-post');
    wp_editor($post_content, 'ccgn_content', $args);
    ?>

		<div class="narrative-meta">
			<div id="ccgn_categories" class="ccgn_category_checkboxes">
				<p class="info">Choose the groups to which this narrative should be published.</p>
				<?php 
    ccgn_related_group_checkboxes($group_id, $post_id);
    ?>
			</div>

			<p>
				<label for="ccgn_published">Published Status</label>
				<select name="ccgn_published" id="ccgn_published">
					<option value="publish" <?php 
    selected($post_published, "publish");
    ?>
>Published</option>
					<option  value="draft" <?php 
    if (empty($post_published) || $post_published == 'draft') {
        echo 'selected="selected"';
    }
    ?>
>Draft</option>
				</select>
			</p>

			<p>
				<label for="ccgn_comment_status"> <input type="checkbox" value="open" id="ccgn_comment_status" name="ccgn_comment_status" <?php 
    if (empty($comment_status) || $comment_status == 'open') {
        echo 'checked="checked"';
    }
    ?>
> Allow comments on this post.</label>
			</p>
		</div>

		<input type="hidden" name="group_id" value="<?php 
    echo $group_id;
    ?>
">
		<!-- This is created for the media modal to reference
		TODO: This doesn't work.-->
		<input id="post_ID" type="hidden" value="<?php 
    echo $post_id;
    ?>
" name="post_ID">

		<input type="hidden" name="post_form_url" value="<?php 
    echo ccgn_get_home_permalink() . "/edit/" . $post_id;
    ?>
">
		<br />
		<?php 
    wp_nonce_field('edit_group_narrative_' . $post_id);
    ?>
		<input type="submit" value="Save Changes" name="group_narrative_post_submitted" id="submit">
	</form>
<?php 
}
예제 #2
0
function ccgn_edit_post_link()
{
    //TODO: I think that the narrative should only be editable from within the group where it originated, so should only be editable by users who are "can_post" for that group.
    $post_id = get_the_ID();
    if (ccgn_current_user_can_post($post_id)) {
        // Get the origin group
        $origin_group = ccgn_get_origin_group($post_id);
        // var_dump($post);
        echo '<a href="' . ccgn_get_home_permalink($origin_group) . '/edit/' . $post_id . '" class="button">Edit</a>';
    }
}