Exemplo n.º 1
0
 /**
  * The run() method.
  *
  * This will initialize the plugin on the 'after_setup_theme' action.
  * If we are currently in the WordPress admin area, the WPCD\Admin class will be instantiated.
  *
  * @since 0.5.0
  */
 protected function run()
 {
     FieldManager::init();
     Customizer::instance();
     AJAX::instance();
     CSSGenerator::instance();
     // use after_setup_theme action so it is initialized as soon as possible, but also so that both plugins and themes can use the action
     add_action('after_setup_theme', array($this, 'init'), 3);
     add_filter('wpcd_panel_validated', array($this, 'panel_validated'), 10, 2);
     add_filter('wpcd_section_validated', array($this, 'section_validated'), 10, 2);
 }
 public function preprocess_customizer_setting($value, $callback, $args)
 {
     $preprocessed = '';
     switch ($callback) {
         case 'post_id_to_field':
             if (!empty($value)) {
                 $args['id'] = $value;
                 $preprocessed = AJAX::instance()->manual_request('wpcd-post-id-to-field', $args);
             }
             break;
         case 'get_attachment_url':
             if (!empty($value)) {
                 $args['id'] = $value;
                 $preprocessed = AJAX::instance()->manual_request('wpcd-get-attachment-url', $args);
             }
             break;
         case 'number_format_i18n':
             if (!empty($value)) {
                 $args['number'] = $value;
                 $preprocessed = AJAX::instance()->manual_request('wpcd-number-format-i18n', $args);
             }
             break;
         case 'date_i18n':
             if (!empty($value)) {
                 $args['date'] = $value;
                 $preprocessed = AJAX::instance()->manual_request('wpcd-date-i18n', $args);
             }
             break;
         case 'content_format':
             if (!empty($value)) {
                 $args['content'] = $value;
                 $preprocessed = AJAX::instance()->manual_request('wpcd-content-format', $args);
             }
             break;
         case 'value_to_label':
             $preprocessed = array();
             if (!is_array($value)) {
                 $value = array($value);
             }
             foreach ($value as $v) {
                 if ('label' === $args['mode'] && isset($args['labels'][$v])) {
                     $preprocessed[] = $args['labels'][$v];
                 } else {
                     $preprocessed[] = $v;
                 }
             }
             $preprocessed = implode(', ', $preprocessed);
             break;
         case 'do_not_process':
             $preprocessed = $value;
             break;
         default:
             $preprocessed = apply_filters('wpcd_preprocess_' . $callback . '_value', $value, $args);
     }
     if (is_wp_error($preprocessed)) {
         $preprocessed = '';
     }
     return $preprocessed;
 }