. */ // Add acctions for adding to post/page and saving the option add_action('admin_init','always_edit_in_html_create_options_box'); add_action('admin_head','always_edit_in_html_handler'); add_action('save_post','always_edit_in_html_save_postdata'); // Turn off the rich editing capability // Effectively removed the "Visual" and "HTML" tabs leaving a plain editor. function always_edit_in_html_handler(){ global $post; $editInHTML = getHTMLEditStatus($post->ID); if ($editInHTML){ add_filter('user_can_richedit',create_function(null,'return false;'),5000); } } // Adds the option box to Pages and Posts in the RHS column function always_edit_in_html_create_options_box(){ add_meta_box('always-edit-in-html',__( 'Always edit in HTML','myplugin_textdomain' ), 'always_edit_in_html_custom_box', 'page' , 'side'); add_meta_box('always-edit-in-html',__( 'Always edit in HTML','myplugin_textdomain' ), 'always_edit_in_html_custom_box','post','side'); } // Creates the Edit in HTML options box function always_edit_in_html_custom_box($post){ // Check that data is from this post wp_nonce_field(plugin_basename(__FILE__),'always_edit_in_html_noncename'); // Get the current status for this post $editInHTML=getHTMLEditStatus($post->ID); // Create the form with the options field and brief explaination of what it does. echo '

Removes the Visual and HTML editor tabs and opens this page/post in HTML mode.

'; echo ' '; echo ''; } // Grabs the Always Edit in HTML option field and checks to see if it's set // Return true for being used (on) and false for unset (off) function getHTMLEditStatus($id){ $editInHTML=get_post_meta($id,"editInHTML",true); if($editInHTML=="on"){ return true; } else{ return false; } } // Save the Always Edit in HTML options along with the post update function always_edit_in_html_save_postdata($post_id){ //assume data hasn't been saved $updateStaus=false; // Quick check to make sure data belongs to this post if(!wp_verify_nonce($_POST['always_edit_in_html_noncename'],plugin_basename(__FILE__))){ return $post_id; } // Don't do anything for an autosave if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ return $post_id; } // Make aure we have the permissions to update a post or page if('page'==$_POST['post_type']){ if(!current_user_can('edit_page',$post_id)){ return $post_id; } } else{ if(!current_user_can('edit_post',$post_id)){ return $post_id; } } // Checks all done so save the option if(isset($_POST['always_edit_in_html'])){ update_post_meta($post_id,'editInHTML','on'); $updateStatus=tue; } else{ update_post_meta($post_id,'editInHTML','off'); $updateStatus=true; } // returns update status to allow for future checcks return $updateStatus; } ?>