Changeset 1219543
- Timestamp:
- 08/12/2015 09:27:49 PM (11 years ago)
- Location:
- resize-editor/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
resize-editor.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
resize-editor/trunk/readme.txt
r705218 r1219543 2 2 Contributors: s-hiroshi 3 3 Tags: editor 4 Requires at least: 3.5.15 Tested up to: 3.5.16 Stable tag: 1. 0.44 Requires at least: 4.2.4 5 Tested up to: 4.2.4 6 Stable tag: 1.1.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
resize-editor/trunk/resize-editor.php
r705219 r1219543 2 2 /* 3 3 Plugin Name: Resize Editor 4 Plugin URI: http://www. findxfine.com4 Plugin URI: http://www.creationlabs.net/resize-editor 5 5 Description: Resize post editor width. 6 6 Text Domain: resize-editor 7 7 Domain Path: /languages/ 8 8 Author: Hiroshi Sawai 9 Author URI: http://www. findxfine.com10 Version: 1. 0.49 Author URI: http://www.info-town.jp 10 Version: 1.1.0 11 11 */ 12 12 … … 28 28 */ 29 29 30 /* 31 * Defines plugin constant values 32 */ 30 33 if ( ! defined( 'RESIZE_EDITOR_DIR' ) ) { 31 define( 'RESIZE_EDITOR_DIR', dirname( __FILE__ ) );34 define( 'RESIZE_EDITOR_DIR', dirname( __FILE__ ) ); 32 35 } 33 36 if ( ! defined( 'RESIZE_EDITOR_STYLE' ) ) { 34 define( 'RESIZE_EDITOR_STYLE', RESIZE_EDITOR_DIR . '/' . 'style.css' );37 define( 'RESIZE_EDITOR_STYLE', RESIZE_EDITOR_DIR . '/' . 'style.css' ); 35 38 } 36 39 37 40 /* 38 * validate parameter is number 39 */ 40 function isPlusInteger( $str ) 41 { 42 if ( '0' === $str ) { 43 return false; 44 } 45 if ( 1 !== preg_match( '/^[0-9]+$/', $str ) ) { 46 return false; 47 } 48 if ( 0 === intval( $str ) ) { 49 return false; 50 } 51 return true; 52 } 53 54 /* 55 * load text domain 41 * Set up plugin 56 42 */ 57 43 add_action( 'init', 'resize_editor_init' ); 58 44 function resize_editor_init() 59 45 { 60 load_plugin_textdomain( 'resize-editor', false, 'resize-editor/languages' ); 61 if ( function_exists( 'register_uninstall_hook' ) ) { 62 register_uninstall_hook( __FILE__, 'uninstall_resize_editor' ); 63 } 64 if ( function_exists( 'register_deactivation_hook' ) ) { 65 register_deactivation_hook(__FILE__, 'deactivation_resize_editor'); 66 } 46 // load text domin 47 load_plugin_textdomain( 'resize-editor', false, 'resize-editor/languages' ); 48 // register deactivation function 49 if ( function_exists( 'register_deactivation_hook' ) ) { 50 register_deactivation_hook( __FILE__, 'deactivation_resize_editor' ); 51 } 52 // register uninstall function 53 if ( function_exists( 'register_uninstall_hook' ) ) { 54 register_uninstall_hook( __FILE__, 'uninstall_resize_editor' ); 55 } 67 56 } 68 69 57 70 58 /* 71 59 * Deactivate Resize Editor plugin 72 60 * 73 * delete Resize Editor stylesheet(style.css)74 * delete option(postdivrichwidth) from wp_options61 * delete Resize Editor css(/style.css) 62 * delete added option(postdivrichwidth) from wp_options 75 63 */ 76 function deactivation_resize_editor() { 77 delete_option( 'postdivrichwidth' ); 78 if ( true === file_exists( RESIZE_EDITOR_STYLE ) ) { 79 unlink( RESIZE_EDITOR_STYLE ); 80 } 64 function deactivation_resize_editor() 65 { 66 // delete options that has been added by Resize Editor 67 delete_option( 'postdivrichwidth' ); 68 // delete css that has been added by Resize Eitor 69 if ( true === file_exists( RESIZE_EDITOR_STYLE ) ) { 70 unlink( RESIZE_EDITOR_STYLE ); 71 } 81 72 } 82 73 83 84 74 /* 85 * DeleteResize Editor plugin75 * Uninstall Resize Editor plugin 86 76 * 87 * delete Resize Editor stylesheet(style.css)88 * delete option(postdivrichwidth) from wp_options77 * delete Resize Editor css(/style.css) 78 * delete added option(postdivrichwidth) from wp_options 89 79 */ 90 80 function uninstall_resize_editor() 91 81 { 92 delete_option( 'postdivrichwidth' ); 93 if ( true === file_exists( RESIZE_EDITOR_STYLE ) ) { 94 unlink( RESIZE_EDITOR_STYLE ); 95 } 82 // delete options that has been added by Resize Editor 83 delete_option( 'postdivrichwidth' ); 84 // delete css that has been added by Resize Eitor 85 if ( true === file_exists( RESIZE_EDITOR_STYLE ) ) { 86 unlink( RESIZE_EDITOR_STYLE ); 87 } 96 88 } 97 89 98 99 90 /* 100 * add resize editor stylesheet(style.css)91 * Add resize editor css(style.css) 101 92 */ 102 93 add_action( 'admin_init', 'add_resize_editor_style' ); 103 function add_resize_editor_style() { 104 wp_register_style( 'resize_editor', plugins_url( '', __FILE__) . '/style.css' ); 105 wp_enqueue_style( 'resize_editor' ); 94 function add_resize_editor_style() 95 { 96 wp_register_style( 'resize_editor', plugins_url( '', __FILE__ ) . '/style.css' ); 97 wp_enqueue_style( 'resize_editor' ); 106 98 } 107 108 99 109 100 /* … … 113 104 function resize_editor() 114 105 { 115 add_options_page( 'Resize Editor Options', 'Resize Editor', 'manage_options', 'resize-editor', 'resize_editor_options' ); 106 add_options_page( 107 'Resize Editor Options', 108 'Resize Editor', 109 'manage_options', 110 'resize-editor', 111 'resize_editor_options' 112 ); 116 113 } 117 // display setting page 114 115 /* 116 * Display setting page 117 */ 118 118 function resize_editor_options() 119 119 { 120 if ( ! current_user_can( 'manage_options' ) ) { 121 wp_die( __( 'You do not have sufficient permissions to access this page' ) ); 122 } 123 if ( isset( $_POST[ 'postdivrichwidth' ] ) ) { 124 if ( isPlusInteger( $_POST[ 'postdivrichwidth'] ) ) { 125 $width = $_POST[ 'postdivrichwidth' ]; 126 // update options 127 check_admin_referer( 'update-options' ); 128 update_option( 'postdivrichwidth', $width ); 129 // create style.css 130 $filename = 'style.css'; 131 $css = <<<CSS 132 @charset "utf-8"; 133 #postdivrich { 134 width: {$width}px; 135 overflow: hidden; 136 } 137 CSS; 138 $fp = fopen( RESIZE_EDITOR_STYLE, 'w' ) or die( __( 'Can not open file' ) ); 139 flock( $fp, LOCK_EX ); 140 fputs( $fp, $css ); 141 flock( $fp, LOCK_UN ); 142 fclose( $fp ); 143 } else { 120 if ( ! current_user_can( 'manage_options' ) ) { 121 wp_die( __( 'You do not have sufficient permissions to access this page' ) ); 122 } 123 if ( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] ) { 124 if ( check_admin_referer( 'safe-resize', '_wpnonce' ) ) { 125 if ( isset( $_POST['postdivrichwidth'] ) && absint( $_POST['postdivrichwidth'] ) ) { 126 $width = absint( $_POST['postdivrichwidth'] ); 127 // update option 128 update_option( 'postdivrichwidth', $width ); 129 // create style.css 130 $css = '@charset "utf-8";' . PHP_EOL 131 . '#postdivrich { width:' . $width . 'px; overflow: hidden; }'; 132 $fp = fopen( RESIZE_EDITOR_STYLE, 'w' ) or die( __( 'Can not open file' ) ); 133 flock( $fp, LOCK_EX ); 134 fputs( $fp, $css ); 135 flock( $fp, LOCK_UN ); 136 fclose( $fp ); 137 } else { 138 delete_option( 'postdivrichwidth' ); 139 if ( true === file_exists( RESIZE_EDITOR_STYLE ) ) { 140 unlink( RESIZE_EDITOR_STYLE ); 141 } 142 } 143 } 144 } 144 145 145 delete_option( 'postdivrichwidth' ); 146 if ( true === file_exists( RESIZE_EDITOR_STYLE ) ) { 147 unlink( RESIZE_EDITOR_STYLE ); 148 149 } 150 } 151 } 152 153 // options setting form 154 echo '<div class="wrap">' . PHP_EOL; 155 echo '<h2>Resize Editor</h2>' . PHP_EOL; 156 echo '<form method="post" action="">' . PHP_EOL; 157 echo wp_nonce_field( 'update-options' ) . PHP_EOL; 158 echo '<table class="form-table">' . PHP_EOL; 159 echo '<tr><th>Rich Editor Width</th><td><input type="text" name="postdivrichwidth" ' 160 . 'value="' . esc_html( get_option( 'postdivrichwidth' ) ) . '" size="6"/> px<br>' 161 . __('Empty or 0 reset existing value', 'resize-editor' ) . '</td></tr>' . PHP_EOL; 162 echo '</table>' . PHP_EOL; 163 echo '<p class="submit"><input type="submit" class="button-primary" value="' . __('Save changes', 'resize-editor') . '" /></p>' . PHP_EOL; 164 echo '</form>' . PHP_EOL; 165 echo '</div>'; 146 // options setting form 147 echo '<div class="wrap">' . PHP_EOL; 148 echo '<h2>Resize Editor</h2>' . PHP_EOL; 149 echo '<form method="post" action="">' . PHP_EOL; 150 echo wp_nonce_field( 'safe-resize', '_wpnonce' ) . PHP_EOL; 151 echo '<table class="form-table">' . PHP_EOL; 152 echo '<tr><th>Rich Editor Width</th><td><input type="text" name="postdivrichwidth" ' 153 . 'value="' . esc_html( get_option( 'postdivrichwidth' ) ) . '" size="6"/> px<br>' 154 . __( 'Empty or 0 reset existing value', 'resize-editor' ) . '</td></tr>' . PHP_EOL; 155 echo '</table>' . PHP_EOL; 156 echo '<p class="submit"><input type="submit" class="button-primary" value="' . __( 157 'Save changes', 158 'resize-editor' 159 ) . '" /></p>' . PHP_EOL; 160 echo '</form>' . PHP_EOL; 161 echo '</div>'; 166 162 } 167 163
Note: See TracChangeset
for help on using the changeset viewer.