예제 #1
0
 /**
  * Validates the arguments array.
  *
  * @since 0.5.0
  * @param WPWD\Components\Widget $parent the parent component
  * @return bool|WPDLib\Util\Error an error object if an error occurred during validation, true if it was validated, false if it did not need to be validated
  */
 public function validate($parent = null)
 {
     $status = parent::validate($parent);
     if ($status === true) {
         $this->args = Utility::validate_position_args($this->args);
     }
     return $status;
 }
예제 #2
0
 protected function get_template_part($args, $instance)
 {
     $sidebar_slug = $args['id'];
     do_action('get_template_part_' . $this->slug, $this->slug, $sidebar_slug);
     $template_names = array($this->slug . '-' . $sidebar_slug . '.php', $this->slug . '.php');
     $template_paths = Utility::get_template_paths();
     $located = false;
     foreach ($template_names as $template_name) {
         foreach ($template_paths as $template_path) {
             if (file_exists($template_path . $template_name)) {
                 $located = $template_path . $template_name;
                 break;
             }
         }
         if ($located) {
             break;
         }
     }
     if ($located) {
         $this->load_template_file($located, $instance);
     } elseif ($this->args['template_file'] && file_exists($this->args['template_file'])) {
         $this->load_template_file($this->args['template_file'], $instance);
     } elseif ($this->args['template_callback'] && is_callable($this->args['template_callback'])) {
         $this->load_template_callback($this->args['template_callback'], $instance);
     } else {
         App::doing_it_wrong(__METHOD__, sprintf(__('The widget %s is missing a valid template file or callback. You must provide either a template file or a callback function for it.', 'widgets-definitely'), $this->slug), '0.5.0');
     }
 }
예제 #3
0
 /**
  * Validates the arguments array.
  *
  * @since 0.5.0
  * @param WPWD\Components\Section $parent the parent component
  * @return bool|WPDLib\Util\Error an error object if an error occurred during validation, true if it was validated, false if it did not need to be validated
  */
 public function validate($parent = null)
 {
     $status = parent::validate($parent);
     if ($status === true) {
         if (is_array($this->args['class'])) {
             $this->args['class'] = implode(' ', $this->args['class']);
         }
         if (!empty($this->args['class'])) {
             $this->args['class'] .= ' ';
         }
         $this->args['class'] .= 'widefat';
         if (isset($this->args['options']) && !is_array($this->args['options'])) {
             $this->args['options'] = array();
         }
         $this->_field = FieldManager::get_instance($this->args);
         if ($this->_field === null) {
             return new UtilError('no_valid_field_type', sprintf(__('The field type %1$s assigned to the field component %2$s is not a valid field type.', 'widgets-definitely'), $this->args['type'], $this->slug), '', ComponentManager::get_scope());
         }
         if (null === $this->args['default']) {
             $this->args['default'] = $this->_field->validate();
         }
         $this->args = Utility::validate_position_args($this->args);
     }
     return $status;
 }