| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: Custom Content Width |
| 4 |
* Plugin URI: http://wordpress.org/plugins/custom-content-width/ |
| 5 |
* Description: Adds a 'Custom Content Width' setting to the Settings > Media screen, to let users override their theme's content width. |
| 6 |
* Author: George Stephanis |
| 7 |
* Version: 1.0.2 |
| 8 |
* Author URI: http://stephanis.info/ |
| 9 |
*/ |
| 10 |
|
| 11 |
class Stephanis_Custom_Content_Width { |
| 12 |
static $instance; |
| 13 |
var $original_content_width = null; |
| 14 |
|
| 15 |
function __construct() { |
| 16 |
self::$instance = $this; |
| 17 |
add_action( 'init', array( $this, 'override_content_width' ) ); |
| 18 |
add_action( 'admin_init', array( $this, 'register_settings' ) ); |
| 19 |
} |
| 20 |
|
| 21 |
function override_content_width() { |
| 22 |
global $content_width; |
| 23 |
|
| 24 |
if( ! empty( $content_width ) ) |
| 25 |
$this->original_content_width = $content_width; |
| 26 |
|
| 27 |
if( $custom_content_width = get_option( 'custom_content_width' ) ) |
| 28 |
$content_width = absint( $custom_content_width ); |
| 29 |
} |
| 30 |
|
| 31 |
function register_settings() { |
| 32 |
register_setting( 'media', 'custom_content_width', 'intval' ); |
| 33 |
$label = __('Custom Content Width', 'custom_content_width' ); |
| 34 |
add_settings_field( 'custom_content_width', "<label for='custom_content_width'>{$label}</label>" , array( $this, 'custom_content_width_cb' ) , 'media' ); |
| 35 |
} |
| 36 |
|
| 37 |
function custom_content_width_cb() { |
| 38 |
$value = get_option( 'custom_content_width' ); |
| 39 |
?> |
| 40 |
<input type="number" class="small-text" min="0" id="custom_content_width" name="custom_content_width" value="<?php echo $value ? absint( $value ) : ''; ?>" /> |
| 41 |
<label for="custom_content_width">px</label> |
| 42 |
<?php if( ! empty( $this->original_content_width ) ): ?> |
| 43 |
<?php if( $value ): ?> |
| 44 |
<small><a href="javascript:;" onclick="jQuery('#custom_content_width').val('');"><?php _e('clear custom value', 'custom_content_width'); ?></a></small> |
| 45 |
<?php endif; ?> |
| 46 |
<br /><em><?php printf( __('Your theme’s default content width is %s pixels.', 'custom_content_width'), absint( $this->original_content_width ) ); ?></em> |
| 47 |
<?php endif; |
| 48 |
} |
| 49 |
} |
| 50 |
new Stephanis_Custom_Content_Width; |
| 51 |
|