Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 34bc73a089
...
compare: 4cc045aa07
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 16, 2012
@Myatu Updated CSS for new layout in customizer
Fixed sanitizer for true/false values in Customizer
4cc045a
View
198 app/Myatu/WordPress/BackgroundManager/Customizer/Customizer.php
@@ -6,7 +6,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-
+
namespace Myatu\WordPress\BackgroundManager\Customizer;
use Myatu\WordPress\BackgroundManager\Main;
@@ -23,7 +23,7 @@
class Customizer
{
const PG_BGM = 'background';
-
+
/** Preview Options */
const P_GALLERY = 'active_gallery';
const P_SELECTOR = 'image_selection';
@@ -50,17 +50,17 @@ class Customizer
const P_PIN_IT_BTN_L = 'pin_it_btn_location';
const P_FS_ADJUST = 'full_screen_adjust';
const P_FS_CENTER = 'full_screen_center';
-
+
/** Magic method prefixes, see @__call */
const M_PREVIEW = 'OnPreview_';
const M_SAVE = 'OnSave_';
const M_FILTER = 'OnFilter_';
-
+
protected $owner;
protected $preview_values = array();
protected $active_customizations = array();
-
- /**
+
+ /**
* Constructor
*
* @param Main $owner Reference to a WordpressPlugin / Owner object
@@ -75,18 +75,18 @@ public function __construct(Main $owner)
static::P_CHANGE_FREQ => array('label' => __('Select an image', $this->owner->getName()), 'priority' => 12),
static::P_CHANGE_FCST => array('label' => __('Interval (seconds)', $this->owner->getName()), 'priority' => 13, 'sanitize' => 'onSanitizeCustomFreq'),
static::P_COLOR => array('label' => __('Background Color', $this->owner->getName()), 'priority' => 14, 'sanitize' => 'onSanitizeColor', 'option' => array($this, 'onSaveColor')),
- static::P_BG_SIZE => array('label' => __('Size', $this->owner->getName()), 'priority' => 20),
+ static::P_BG_SIZE => array('label' => __('Size', $this->owner->getName()), 'priority' => 20),
static::P_BG_POS => array('label' => __('Position', $this->owner->getName()), 'priority' => 21),
static::P_BG_TILE => array('label' => __('Tiling', $this->owner->getName()), 'priority' => 21),
static::P_BG_SCROLL => array('label' => __('Scrolling', $this->owner->getName()), 'priority' => 21),
static::P_OPACITY => array('label' => __('Opacity', $this->owner->getName()), 'priority' => 21, 'sanitize' => 'onSanitizeOpacity'),
static::P_BG_ST_VER => array('label' => __('Stretch Vertical', $this->owner->getName()), 'priority' => 22, 'sanitize' => 'onSanitizeCheckbox'),
- static::P_BG_ST_HOR => array('label' => __('Stretch Horizontal', $this->owner->getName()), 'priority' => 22, 'sanitize' => 'onSanitizeCheckbox'),
+ static::P_BG_ST_HOR => array('label' => __('Stretch Horizontal', $this->owner->getName()), 'priority' => 22, 'sanitize' => 'onSanitizeCheckbox'),
static::P_TRANSITION => array('label' => __('Transition Effect', $this->owner->getName()), 'priority' => 30),
static::P_TRANS_SPD => array('label' => __('Transition Speed', $this->owner->getName()), 'priority' => 31, 'sanitize' => 'onSanitizeTransitionSpeed'),
static::P_FS_ADJUST => array('label' => __('Adjust Image Size', $this->owner->getName()), 'priority' => 32, 'sanitize' => 'onSanitizeCheckbox'),
static::P_FS_CENTER => array('label' => __('Center Image', $this->owner->getName()), 'priority' => 33, 'sanitize' => 'onSanitizeCheckbox'),
- static::P_OVERLAY => array('label' => __('Overlay', $this->owner->getName()), 'priority' => 40),
+ static::P_OVERLAY => array('label' => __('Overlay', $this->owner->getName()), 'priority' => 40),
static::P_OVERLAY_O => array('label' => __('Overlay Opacity', $this->owner->getName()), 'priority' => 41, 'sanitize' => 'onSanitizeOpacity'),
static::P_INFO_TAB => array('label' => __('Display [ + ] Icon', $this->owner->getName()), 'priority' => 50, 'sanitize' => 'onSanitizeCheckbox'),
static::P_INFO_TAB_T => array('label' => __('Show thumbnail', $this->owner->getName()), 'priority' => 51, 'sanitize' => 'onSanitizeCheckbox'),
@@ -94,21 +94,21 @@ public function __construct(Main $owner)
static::P_INFO_TAB_LN => array('label' => __('Enable linking', $this->owner->getName()), 'priority' => 51, 'sanitize' => 'onSanitizeCheckbox'),
static::P_INFO_TAB_L => array('label' => __('Location', $this->owner->getName()), 'priority' => 52),
static::P_PIN_IT_BTN => array('label' => __('Display "Pin It" Button', $this->owner->getName()), 'priority' => 60, 'sanitize' => 'onSanitizeCheckbox'),
- static::P_PIN_IT_BTN_L => array('label' => __('Location', $this->owner->getName()), 'priority' => 61),
- );
-
+ static::P_PIN_IT_BTN_L => array('label' => __('Location', $this->owner->getName()), 'priority' => 61),
+ );
+
// Set actions
add_action('customize_register', array($this, 'onCustomizeRegister')); // Controls on Theme Customizer
add_action('customize_preview_init', array($this, 'onPreviewInit')); // Called when a preview is requested
add_action('customize_controls_enqueue_scripts', array($this, 'onEnqueue')); // Called when ready to queue control scripts
-
+
// "Magic" actions (@see __call)
foreach (array_keys($this->active_customizations) as $customization) {
add_action('customize_preview_' . Main::BASE_PUB_PREFIX . $customization, array($this, static::M_PREVIEW . $customization));
add_action('customize_save_' . Main::BASE_PUB_PREFIX . $customization, array($this, static::M_SAVE . $customization));
}
}
-
+
/**
* Magic handler
*
@@ -119,23 +119,23 @@ public function __construct(Main $owner)
public function __call($name, $arguments)
{
list($func, $id) = explode('_', $name, 2);
-
+
// Re-add trailing delimiter
$func .= '_';
-
+
switch ($func) {
case static::M_PREVIEW :
$this->setPreviewValue($id);
break;
-
+
case static::M_FILTER :
return $this->getPreviewValue($id, $arguments[0]);
break;
-
+
case static::M_SAVE :
if ($this->getSaveValue($id, $value)) {
$save_details = $this->active_customizations[$id];
-
+
if (array_key_exists('option', $save_details)) {
// Complex save
call_user_func($save_details['option'], $value);
@@ -145,30 +145,30 @@ public function __call($name, $arguments)
}
}
break;
-
+
default :
throw new \BadFunctionCallException('Function ' . $name . ' does not exist');
break;
}
}
-
+
/* ----------- Helpers ----------- */
-
+
/**
* Overrides the original value if a preview value is present
*
* @param string $id Setting ID
* @param mixed $original Original value (or null)
- * @return mixed
+ * @return mixed
*/
protected function getPreviewValue($id, $original = null)
{
if (isset($this->preview_values[$id]) && !is_null($this->preview_values[$id]))
return $this->preview_values[$id];
-
+
return $original;
}
-
+
/**
* Stores the preview value
*
@@ -177,22 +177,22 @@ protected function getPreviewValue($id, $original = null)
protected function setPreviewValue($id)
{
global $wp_customize;
-
+
if (!is_a($wp_customize, '\WP_Customize'))
return;
-
+
$setting = $wp_customize->get_setting(Main::BASE_PUB_PREFIX . $id);
-
+
if (is_a($setting, '\WP_Customize_Setting')) {
$value = $setting->post_value();
-
+
if (!is_null($value) && array_key_exists('sanitize', $this->active_customizations[$id]))
$value = call_user_func(array($this, $this->active_customizations[$id]['sanitize']), $value);
-
+
$this->preview_values[$id] = $value;
}
}
-
+
/**
* Sets the value to be saved, returns true if we should save
*
@@ -203,10 +203,10 @@ protected function getSaveValue($id, &$value)
{
$this->setPreviewValue($id);
$value = $this->getPreviewValue($id);
-
+
return !is_null($value);
}
-
+
/**
* Adds a setting and control in one go
*
@@ -220,17 +220,17 @@ protected function getSaveValue($id, &$value)
protected function addSettingControl($id, $details, $type = 'text', $choices = array())
{
global $wp_customize;
-
+
if (!is_a($wp_customize, '\WP_Customize'))
return;
-
+
$priority = isset($details['priority']) ? $details['priority'] : 10;
-
+
$wp_customize->add_setting(Main::BASE_PUB_PREFIX . $id, array(
'default' => $this->owner->options->$id,
'type' => 'myatu_bgm',
));
-
+
if (is_string($type)) {
$wp_customize->add_control(Main::BASE_PUB_PREFIX . $id, array(
'label' => $details['label'],
@@ -241,7 +241,7 @@ protected function addSettingControl($id, $details, $type = 'text', $choices = a
));
}
}
-
+
/**
* Adds a divider control
*
@@ -251,12 +251,12 @@ protected function addSettingControl($id, $details, $type = 'text', $choices = a
protected function addDividerControl($priority, $label = '')
{
global $wp_customize;
-
+
if (!is_a($wp_customize, '\WP_Customize'))
return;
-
+
$id = 'divider_' . strtr(strtolower($label), ' -', '__');
-
+
$wp_customize->add_setting($id, array('type' => 'none'));
$wp_customize->add_control(new DividerControl($wp_customize, $id, array(
'priority' => $priority,
@@ -265,9 +265,9 @@ protected function addDividerControl($priority, $label = '')
'label' => $label,
)));
}
-
+
/* ----------- Events ----------- */
-
+
/**
* Enqueue Scripts
*/
@@ -277,28 +277,28 @@ public function onEnqueue()
list($js_url, $version, $debug) = $this->owner->getResourceUrl();
wp_enqueue_script($this->owner->getName() . '-functions', $js_url . 'functions' . $debug . '.js', array('jquery'), $version);
wp_enqueue_script($this->owner->getName() . '-customize', $js_url . 'customize' . $debug . '.js', array($this->owner->getName() . '-functions'), $version);
-
+
// Enueue CSS
list($css_url, $version, $debug) = $this->owner->getResourceUrl('css');
wp_enqueue_style($this->owner->getName() . '-customize', $css_url . 'customize' . $debug . '.css', false, $version);
}
-
+
/**
* Event called when a preview is requested
*
* Registers the filters for retrieving the preview values
*/
public function onPreviewInit()
- {
+ {
global $wp_customize;
-
+
// Initialize the filters
foreach (array_keys($this->active_customizations) as $customization) {
// 'myatu_bgm_' . 'active_overlay' ... array($this, 'OnFilter_' . 'active_overlay'
add_filter(Main::BASE_PUB_PREFIX . $customization, array($this, static::M_FILTER . $customization), 90);
}
}
-
+
/**
* Register controls for Customize Theme settings
*
@@ -307,99 +307,99 @@ public function onPreviewInit()
public function onCustomizeRegister()
{
global $wp_customize;
-
+
if (!is_a($wp_customize, '\WP_Customize'))
return;
-
+
$wp_customize->add_section(static::PG_BGM, array(
'title' => __('Background', $this->owner->getName()),
'priority' => 30,
));
-
+
// Iterate active customizations and create controls for them
foreach ($this->active_customizations as $id=>$details) {
// Determine display priority for controls
$priority = isset($details['priority']) ? $details['priority'] : 10;
-
+
switch($id) {
case static::P_GALLERY :
// Background Image Set
$choices = array(0 => __('-- None (deactivated) --', $this->owner->getName()));
-
+
foreach($this->owner->getSettingGalleries($this->owner->options->active_gallery) as $gallery) {
$choices[$gallery['id']] = $gallery['name'];
}
-
+
$this->addSettingControl($id, $details, 'select', $choices);
break;
-
+
case static::P_SELECTOR :
$choices = array(Images::SO_RANDOM => __('Random'), Images::SO_ASC => __('Ascending'), Images::SO_DESC => __('Descending'));
$this->addSettingControl($id, $details, 'radio', $choices);
-
+
break;
-
+
case static::P_CHANGE_FREQ :
$choices = array(
'session' => __('At each browser session', $this->owner->getName()),
'load' => __('On a page (re)load', $this->owner->getName()),
'custom' => __('At a specified interval', $this->owner->getName()),
);
-
+
$this->addSettingControl($id, $details, 'radio', $choices);
break;
-
+
case static::P_CHANGE_FCST :
$this->addSettingControl($id, $details, 'text');
break;
-
+
case static::P_COLOR :
// Background Color - Note that the exposed ID needs to be prefixed
$wp_customize->add_setting(Main::BASE_PUB_PREFIX . $id, array(
'default' => get_background_color(),
'type' => 'myatu_bgm',
));
-
+
$wp_customize->add_control(new \WP_Customize_Color_Control($wp_customize, Main::BASE_PUB_PREFIX . $id, array(
'label' => __('Background Color', $this->owner->getName()),
'priority' => $priority,
'section' => static::PG_BGM,
)));
break;
-
+
case static::P_BG_SIZE :
- // Background Layout (Size)
+ // Background Layout (Size)
$choices = array(
'as-is' => __('Normal', $this->owner->getName()),
'full' => __('Full Screen', $this->owner->getName()),
);
-
+
$this->addSettingControl($id, $details, 'radio', $choices);
$this->addDividerControl($priority-1, __('Background Layout', $this->owner->getName()));
break;
-
+
case static::P_BG_POS :
// Background Layout (Position)
$this->addSettingControl($id, $details, 'radio', $this->owner->getBgOptions('position', true));
break;
-
+
case static::P_BG_TILE :
// Background Layout (Tiling/Repeat)
$this->addSettingControl($id, $details, 'radio', $this->owner->getBgOptions('repeat', true));
break;
-
+
case static::P_OVERLAY :
// Overlay
$choices = array('' => __('-- None (deactivated) --', $this->owner->getName()));
-
+
foreach($this->owner->getSettingOverlays($this->owner->options->active_overlay) as $overlay) {
$choices[$overlay['value']] = $overlay['desc'];
}
-
+
$this->addSettingControl($id, $details, 'select', $choices);
$this->addDividerControl($priority-1, __('Background Overlay', $this->owner->getName()));
break;
-
+
case static::P_OPACITY :
case static::P_OVERLAY_O :
// Overlay Opacity
@@ -407,24 +407,24 @@ public function onCustomizeRegister()
'default' => $this->owner->options->$id,
'type' => 'myatu_bgm',
));
-
+
$wp_customize->add_control(new SlideControl($wp_customize, Main::BASE_PUB_PREFIX . $id, array(
'label' => $details['label'],
'priority' => $priority,
'section' => static::PG_BGM,
'owner' => $this->owner,
)));
- break;
-
+ break;
+
case static::P_BG_SCROLL :
$choices = array(
'scroll' => __('Scroll with the screen'),
'fixed' => __('Fixed'),
);
-
+
$this->addSettingControl($id, $details, 'radio', $choices);
break;
-
+
case static::P_BG_ST_VER :
case static::P_BG_ST_HOR :
case static::P_INFO_TAB_T :
@@ -434,19 +434,19 @@ public function onCustomizeRegister()
case static::P_FS_CENTER :
$this->addSettingControl($id, $details, 'checkbox');
break;
-
+
case static::P_TRANSITION :
$this->addSettingControl($id, $details, 'select', $this->owner->getBgOptions('transition', true));
$this->addDividerControl($priority-1, __('Background Transitioning Effect', $this->owner->getName()));
break;
-
+
case static::P_TRANS_SPD :
// Overlay Opacity
$wp_customize->add_setting(Main::BASE_PUB_PREFIX . $id, array(
'default' => $this->owner->options->$id,
'type' => 'myatu_bgm',
));
-
+
$wp_customize->add_control(new SlideControl($wp_customize, Main::BASE_PUB_PREFIX . $id, array(
'label' => $details['label'],
'priority' => $priority,
@@ -460,28 +460,28 @@ public function onCustomizeRegister()
'max' => 15000,
'step' => 100,
'range' => false,
- )));
+ )));
break;
-
+
case static::P_INFO_TAB :
$this->addSettingControl($id, $details, 'checkbox');
$this->addDividerControl($priority-1, __('Background Information', $this->owner->getName()));
break;
-
+
case static::P_PIN_IT_BTN :
$this->addSettingControl($id, $details, 'checkbox');
$this->addDividerControl($priority-1, __('Pinterest', $this->owner->getName()));
break;
-
+
case static::P_INFO_TAB_L :
case static::P_PIN_IT_BTN_L :
$this->addSettingControl($id, $details, 'radio', $this->owner->getBgOptions('corner', true));
break;
-
+
} // switch
} // foreach
}
-
+
/**
* Sanitize the color
*
@@ -490,13 +490,13 @@ public function onCustomizeRegister()
public function onSanitizeColor($value)
{
$value = ltrim($value, '#');
-
+
if (!empty($value) && !preg_match('/^([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?$/', $value))
return null;
-
+
return $value;
}
-
+
/**
* Saves the color
*
@@ -517,13 +517,13 @@ public function onSaveColor($value)
public function onSanitizeOpacity($value)
{
$value = (int)$value;
-
+
if ($value > 100 || $value < 1)
return null;
-
+
return $value;
}
-
+
/**
* Sanitize the checkbox return value
*
@@ -531,12 +531,12 @@ public function onSanitizeOpacity($value)
*/
public function onSanitizeCheckbox($value)
{
- if ($value == 'true')
+ if ($value != 'false' || !empty($value))
return true;
-
+
return false;
}
-
+
/**
* Sanitize the transition speed
*
@@ -545,13 +545,13 @@ public function onSanitizeCheckbox($value)
public function onSanitizeTransitionSpeed($value)
{
$value = (int)$value;
-
+
if ($value > 15000 || $value < 100)
return null;
-
+
return $value;
}
-
+
/**
* Sanitize the custom change frequency (seconds)
*
@@ -560,10 +560,10 @@ public function onSanitizeTransitionSpeed($value)
public function onSanitizeCustomFreq($value)
{
$value = (int)$value;
-
+
if ($value < 1)
$value = 10;
-
+
return $value;
}
-}
+}
View
18 resources/css/customize.dev.css
@@ -33,21 +33,9 @@
}
.myatu_bgm_slider_control {
- width: 80px;
-}
-
-/* Specific adjustments */
-
-#customize-control-myatu_bgm_change_freq_custom input {
- width: 60px;
-}
+ width: 200px;
-#customize-control-myatu_bgm_background_color .customize-control-content,
-#customize-section-background .customize-control-select select {
- width: 120px;
}
-
-#customize-control-myatu_bgm_background_color .farbtastic-placeholder {
- width: 100%;
+#customize-control-myatu_bgm_change_freq_custom input{
+ width: 60px;
}
-

No commit comments for this range

Something went wrong with that request. Please try again.