. */ global $post; /** * Add language options */ load_plugin_textdomain( 'always-edit-in-html', false, basename( dirname( __FILE__ ) ) . '/lang' ); // 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', $post ); /** * Turn off the rich editing capability * * Removes the tab that switches to the visual editor */ function always_edit_in_html_handler(){ global $post; echo ''; // Get the meta value and check that it's switched on $editInHTML = getHTMLEditStatus( $post->ID ); if ( $editInHTML ){ // Hide "Visual" tab echo ''; } } /** * 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', '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 */ 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', 'always-edit-in-html' ).'

'; echo ' '; echo ''; } /** * Grabs the Always Edit in HTML option field and checks to see if it's set * * @return bool */ 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 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' ); $updateStatus = true; } else{ update_post_meta( $post_id, 'editInHTML', 'off' ); $updateStatus = true; } // Returns update status to allow for future checcks return $updateStatus; } ?>