Example #1
0
 function get_edit_form($showheader = false)
 {
     global $post, $wp_version, $edit_post, $post_id, $post_ID;
     if (!current_user_can('edit_wiki', $post->ID) && !current_user_can('edit_wikis', $post->ID) && !current_user_can('edit_others_wikis', $post->ID) && !current_user_can('edit_published_wikis', $post->ID)) {
         return __('You do not have permission to view this page.', 'wiki');
     }
     $return = '';
     $stack = debug_backtrace();
     // Jet pack compatibility
     if (isset($stack[3]) && isset($stack[3]['class']) && isset($stack[3]['function']) && $stack[3]['class'] == 'Jetpack_PostImages' && $stack[3]['function'] == 'from_html') {
         return $showheader;
     }
     if ($showheader) {
         $return .= '<div class="incsub_wiki incsub_wiki_single">';
         $return .= '<div class="incsub_wiki_tabs incsub_wiki_tabs_top">' . $this->tabs() . '<div class="incsub_wiki_clear"></div></div>';
     }
     $return .= '<h2>' . __('Edit', 'wiki') . '</h2>';
     $return .= '<form action="' . get_permalink() . '" method="post">';
     if (isset($_REQUEST['eaction']) && $_REQUEST['eaction'] == 'create') {
         $edit_post = $this->get_default_post_to_edit($post->post_type, true, $post->ID);
         $return .= '<input type="hidden" name="parent_id" id="parent_id" value="' . $post->ID . '" />';
         $return .= '<input type="hidden" name="original_publish" id="original_publish" value="Publish" />';
         $return .= '<input type="hidden" name="publish" id="publish" value="Publish" />';
     } else {
         $edit_post = $post;
         $return .= '<input type="hidden" name="parent_id" id="parent_id" value="' . $edit_post->post_parent . '" />';
         $return .= '<input type="hidden" name="original_publish" id="original_publish" value="Update" />';
     }
     $post_id = $edit_post->ID;
     $post_ID = $post_id;
     $return .= '<input type="hidden" name="post_type" id="post_type" value="' . $edit_post->post_type . '" />';
     $return .= '<input type="hidden" name="post_ID" id="wiki_id" value="' . $edit_post->ID . '" />';
     if ('private' == $edit_post->post_status) {
         $edit_post->post_password = '';
         $visibility = 'private';
         $visibility_trans = __('Private');
     } elseif (!empty($edit_post->post_password)) {
         $visibility = 'password';
         $visibility_trans = __('Password protected');
     } else {
         $visibility = 'public';
         $visibility_trans = __('Public');
     }
     $return .= '<input type="hidden" name="post_status" id="wiki_post_status" value="' . $edit_post->post_status . '" />';
     $return .= '<input type="hidden" name="visibility" id="wiki_visibility" value="' . $visibility . '" />';
     $return .= '<input type="hidden" name="comment_status" id="comment_status" value="' . $edit_post->comment_status . '" />';
     $return .= '<input type="hidden" name="action" id="wiki_action" value="editpost" />';
     $return .= '<div><input type="text" name="post_title" id="wiki_title" value="' . $edit_post->post_title . '" class="incsub_wiki_title" size="30" /></div>';
     $return .= '<div>';
     if (@ob_start()) {
         // Output buffering is on, capture the output from wp_editor() and append it to the $return variable
         wp_editor($edit_post->post_content, 'wikicontent', array('textarea_name' => 'content'));
         $return .= ob_get_clean();
     } else {
         /*
         This is hacky, but without output buffering on we needed to make a copy of the built-in _WP_Editors class and
         change the editor() method to return the output instead of echo it. The only bad thing about this is that we
         also had to remove the media_buttons action so plugins/themes won't be able to tie into it
         */
         require_once $this->plugin_dir . 'lib/classes/WPEditor.php';
         $return .= WikiEditor::editor($edit_post->post_content, 'wikicontent', array('textarea_name' => 'content'));
     }
     $return .= '</div>';
     $return .= '<input type="hidden" name="_wpnonce" id="_wpnonce" value="' . wp_create_nonce("wiki-editpost_{$edit_post->ID}") . '" />';
     if (is_user_logged_in()) {
         $return .= $this->get_meta_form(true);
     }
     $return .= '<div class="incsub_wiki_clear incsub_wiki_form_buttons">';
     $return .= '<input type="submit" name="save" id="btn_save" value="' . __('Save', 'wiki') . '" />&nbsp;';
     $return .= '<a href="' . get_permalink() . '">' . __('Cancel', 'wiki') . '</a>';
     $return .= '</div>';
     $return .= '</form>';
     if ($showheader) {
         $return .= '</div>';
     }
     $return .= '<style type="text/css">' . '#comments { display: none; }' . '.comments { display: none; }' . '</style>';
     return $return;
 }