Ejemplo n.º 1
0
 /**
  * Validates the arguments array.
  *
  * @since 0.5.0
  * @param WPPTD\Components\PostType $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 (in_array($this->slug, array('post_format', 'link_category', 'nav_menu'))) {
             return new UtilError('no_valid_taxonomy', sprintf(__('The taxonomy slug %s is forbidden since it would interfere with WordPress Core functionality.', 'post-types-definitely'), $this->slug), '', ComponentManager::get_scope());
         }
         // show notice if slug contains dashes
         if (strpos($this->slug, '-') !== false) {
             App::doing_it_wrong(__METHOD__, sprintf(__('The taxonomy slug %s contains dashes which is discouraged. It will still work for the most part, but we recommend to adjust the slug if possible.', 'post-types-definitely'), $this->slug), '0.5.0');
         }
         // generate titles if not provided
         $this->args = Utility::validate_titles($this->args, $this->slug, 'taxonomy');
         // generate taxonomy labels
         $this->args = Utility::validate_labels($this->args, 'labels', 'taxonomy');
         // generate taxonomy updated messages
         $this->args = Utility::validate_labels($this->args, 'messages', 'taxonomy');
         // set some defaults
         if (null === $this->args['rewrite']) {
             if ($this->args['public']) {
                 $this->args['rewrite'] = array('slug' => str_replace('_', '-', $this->slug), 'with_front' => true, 'hierarchical' => $this->args['hierarchical'], 'ep_mask' => EP_NONE);
             } else {
                 $this->args['rewrite'] = false;
             }
         }
         // handle REST API default
         if (null === $this->args['show_in_rest']) {
             if (null !== $this->args['public']) {
                 $this->args['show_in_rest'] = $this->args['public'];
             } else {
                 $this->args['show_in_rest'] = false;
             }
         }
         $this->args = Utility::validate_ui_args($this->args);
         $this->args = Utility::validate_position_args($this->args);
         // handle term table
         $this->args = TaxonomyTableHandler::validate_args($this->args);
         // handle help
         $this->args = Utility::validate_help_args($this->args, 'help');
         // handle list help
         $this->args = Utility::validate_help_args($this->args, 'list_help');
     }
     return $status;
 }
 /**
  * Validates the post type component arguments that are related to the list table.
  *
  * @since 0.5.0
  * @see WPPTD\Components\PostType::validate()
  * @param array $args the original arguments
  * @return array the validated arguments
  */
 public static function validate_args($args)
 {
     // handle admin table columns
     if (!$args['show_ui'] || !is_array($args['table_columns'])) {
         $args['table_columns'] = array();
     }
     $_table_columns = $args['table_columns'];
     $args['table_columns'] = array();
     $core_column_slugs = array('title', 'author', 'comments', 'date');
     foreach ($_table_columns as $column_slug => $column_args) {
         if (strpos($column_slug, 'meta-') === 0 || strpos($column_slug, 'taxonomy-') === 0 || strpos($column_slug, 'custom-') === 0 || in_array($column_slug, $core_column_slugs)) {
             if (false !== $column_args) {
                 if (!is_array($column_args)) {
                     $column_args = array();
                 }
                 $column_args = wp_parse_args($column_args, array('title' => '', 'filterable' => false, 'sortable' => false));
                 if (strpos($column_slug, 'meta-') === 0) {
                     if (!isset($column_args['meta_key']) || empty($column_args['meta_key'])) {
                         $column_args['meta_key'] = substr($column_slug, strlen('meta-'));
                     }
                 } elseif (strpos($column_slug, 'taxonomy-') === 0) {
                     if (!isset($column_args['taxonomy_slug']) || empty($column_args['taxonomy_slug'])) {
                         $column_args['taxonomy_slug'] = substr($column_slug, strlen('taxonomy-'));
                     }
                 } elseif (strpos($column_slug, 'custom-') === 0) {
                     if (!isset($column_args['custom_callback']) || empty($column_args['custom_callback'])) {
                         $column_args['custom_callback'] = substr($column_slug, strlen('custom-'));
                     }
                 }
             }
             $args['table_columns'][$column_slug] = $column_args;
         } else {
             App::doing_it_wrong(__METHOD__, sprintf(__('The admin table column slug %s is invalid. It must be prefixed with either "meta-", "taxonomy-" or "custom-".', 'post-types-definitely'), $column_slug), '0.5.0');
         }
     }
     $args = PostTypeActionHandler::validate_args($args);
     return $args;
 }
Ejemplo n.º 3
0
 /**
  * Validates a meta value.
  *
  * @since 0.5.0
  * @param WPPTD\Components\Field $field field object to validate the meta value for
  * @param mixed $meta_value the meta value to validate
  * @param mixed $meta_value_old the previous meta value
  * @return array an array containing the validated value, a variable possibly containing a WP_Error object and a boolean value whether the meta value has changed
  */
 protected function validate_meta_value($field, $meta_value, $meta_value_old)
 {
     $meta_value = $field->validate_meta_value($meta_value);
     $error = false;
     $changed = false;
     if (is_wp_error($meta_value)) {
         $error = $meta_value;
         $meta_value = $meta_value_old;
     } elseif ($meta_value != $meta_value_old) {
         if (has_action('wpptd_update_meta_value_' . $this->slug . '_' . $field->slug)) {
             App::deprecated_action('wpptd_update_meta_value_' . $this->slug . '_' . $field->slug, '0.6.0', 'wpptd_update_post_meta_value_' . $this->slug . '_' . $field->slug);
             /**
              * This action can be used to perform additional steps when the meta value for a specific field of this post type has been updated.
              *
              * @since 0.5.0
              * @deprecated 0.6.0
              * @param mixed the updated meta value
              * @param mixed the previous meta value
              */
             do_action('wpptd_update_meta_value_' . $this->slug . '_' . $field->slug, $meta_value, $meta_value_old);
         }
         /**
          * This action can be used to perform additional steps when the meta value for a specific field of this post type has been updated.
          *
          * @since 0.6.0
          * @param mixed the updated meta value
          * @param mixed the previous meta value
          */
         do_action('wpptd_update_post_meta_value_' . $this->slug . '_' . $field->slug, $meta_value, $meta_value_old);
         $changed = true;
     }
     return array($meta_value, $error, $changed);
 }
 /**
  * Renders the term metabox.
  *
  * It displays the title and description (if available) for the metabox.
  * Then it shows the fields of this metabox or, if no fields are available, calls the callback function.
  *
  * @since 0.6.0
  * @param WP_Term $term the term currently being shown
  */
 public function render($term)
 {
     $parent_taxonomy = $this->get_parent();
     if ('side' == $this->args['context']) {
         echo '<div class="wpdlib-narrow">';
     }
     /**
      * This action can be used to display additional content on top of this term metabox.
      *
      * @since 0.6.0
      * @param string the slug of the current metabox
      * @param array the arguments array for the current metabox
      * @param string the slug of the current taxonomy
      */
     do_action('wpptd_term_metabox_before', $this->slug, $this->args, $parent_taxonomy->slug);
     if (!empty($this->args['description'])) {
         echo '<p class="description">' . $this->args['description'] . '</p>';
     }
     if (count($this->get_children()) > 0) {
         $table_atts = array('class' => 'form-table wpdlib-form-table');
         /**
          * This filter can be used to adjust the term editing form table attributes.
          *
          * @since 0.6.0
          * @param array the associative array of form table attributes
          * @param WPPTD\Components\TermMetabox current metabox instance
          */
         $table_atts = apply_filters('wpptd_term_table_atts', $table_atts, $this);
         echo '<table' . FieldManager::make_html_attributes($table_atts, false, false) . '>';
         foreach ($this->get_children() as $field) {
             $field->render($term);
         }
         echo '</table>';
     } elseif ($this->args['callback'] && is_callable($this->args['callback'])) {
         call_user_func($this->args['callback'], $term);
     } else {
         App::doing_it_wrong(__METHOD__, sprintf(__('There are no fields to display for metabox %s. Either add some or provide a valid callback function instead.', 'post-types-definitely'), $this->slug), '0.5.0');
     }
     /**
      * This action can be used to display additional content at the bottom of this term metabox.
      *
      * @since 0.6.0
      * @param string the slug of the current metabox
      * @param array the arguments array for the current metabox
      * @param string the slug of the current taxonomy
      */
     do_action('wpptd_term_metabox_after', $this->slug, $this->args, $parent_taxonomy->slug);
     if ('side' == $this->args['context']) {
         echo '</div>';
     }
 }
Ejemplo n.º 5
0
 /**
  * Returns the keys of the arguments array and their default values.
  *
  * Read the plugin guide for more information about the post meta field arguments.
  *
  * @since 0.5.0
  * @return array
  */
 protected function get_defaults()
 {
     $defaults = array('title' => __('Field title', 'post-types-definitely'), 'description' => '', 'type' => 'text', 'class' => '', 'default' => null, 'required' => false, 'position' => null, 'show_in_rest' => false, 'rest_description' => '', 'rest_auth_callback' => null);
     if (has_filter('wpptd_field_defaults')) {
         App::deprecated_filter('wpptd_field_defaults', '0.6.0', 'wpptd_post_field_defaults');
         /**
          * This filter can be used by the developer to modify the default values for each field component.
          *
          * @since 0.5.0
          * @deprecated 0.6.0
          * @param array the associative array of default values
          */
         $defaults = apply_filters('wpptd_field_defaults', $defaults);
     }
     /**
      * This filter can be used by the developer to modify the default values for each post meta field component.
      *
      * @since 0.6.0
      * @param array the associative array of default values
      */
     return apply_filters('wpptd_post_field_defaults', $defaults);
 }
Ejemplo n.º 6
0
 /**
  * Returns the keys of the arguments array and their default values.
  *
  * Read the plugin guide for more information about the post metabox arguments.
  *
  * @since 0.5.0
  * @return array
  */
 protected function get_defaults()
 {
     $defaults = array('title' => __('Metabox title', 'post-types-definitely'), 'description' => '', 'context' => null, 'priority' => null, 'callback' => false, 'position' => null);
     if (has_filter('wpptd_metabox_defaults')) {
         App::deprecated_filter('wpptd_metabox_defaults', '0.6.0', 'wpptd_post_metabox_defaults');
         /**
          * This filter can be used by the developer to modify the default values for each metabox component.
          *
          * @since 0.5.0
          * @deprecated 0.6.0
          * @param array the associative array of default values
          */
         $defaults = apply_filters('wpptd_metabox_defaults', $defaults);
     }
     /**
      * This filter can be used by the developer to modify the default values for each post metabox component.
      *
      * @since 0.6.0
      * @param array the associative array of default values
      */
     return apply_filters('wpptd_post_metabox_defaults', $defaults);
 }