. */ global $post; /** * Add language options */ load_plugin_textdomain( 'always-edit-in-html', false, basename( dirname( __FILE__ ) ) . '/lang' ); // Add actions for adding to post/page and saving the option if ( is_admin() ){ 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', $post ); } /** * Turn off the rich editing capability * * Removes the tab that switches to the visual editor */ function always_edit_in_html_handler(){ global $post; // Check that we have a post object here, else return if( $post == null ) return; echo ''; // Get the meta value and check that it's switched on $editInHTML = always_edit_in_html_get_html_edit_status( $post->ID ); if ( $editInHTML ){ // Hide "Visual" tab echo ''; // Set the editor to HTML ("Text") add_filter( 'wp_default_editor', create_function(null,'return "html";') ); } } /** * Adds the option box to Pages and Posts in the RHS column */ function always_edit_in_html_create_options_box(){ global $post; add_meta_box( 'always-edit-in-html', __( 'Always edit in HTML', 'always-edit-in-html' ), 'always_edit_in_html_custom_box', 'page' , 'side'); add_meta_box( 'always-edit-in-html', __( 'Always edit in HTML', 'always-edit-in-html' ), 'always_edit_in_html_custom_box','post','side'); } /** * Creates the Edit in HTML options box on post/page * * @param $post */ 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 = always_edit_in_html_get_html_edit_status( $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', 'always-edit-in-html' ).'
'; echo ' '; echo ''; } /** * Grabs the Always Edit in HTML option field and checks to see if it's set * * @param $id * @return bool */ function always_edit_in_html_get_html_edit_status( $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 * * @param $post_id * @return mixed */ function always_edit_in_html_save_postdata( $post_id ){ // Quick check to make sure data belongs to this post if( ( !isset($_POST['always_edit_in_html_noncename']) ) || ( !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 sure 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' ); } else{ update_post_meta( $post_id, 'editInHTML', 'off' ); } // Returns $post_id to preserve other filters return $post_id ; } ?>