예제 #1
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);
 }
예제 #2
0
 /**
  * Validates a post's meta values for all meta fields of the post type.
  *
  * It iterates through all the meta fields of the post and validates each one's value.
  * If a field is not set for some reason, its default value is saved.
  *
  * Furthermore this function adds settings errors if any occur.
  *
  * @since 0.5.0
  * @param array $meta_values array of submitted meta values
  * @param integer $post_id the current post ID
  * @return array the validated meta values
  */
 protected function validate_meta_values($meta_values, $post_id)
 {
     $meta_values_validated = array();
     $meta_values_old = array();
     $errors = array();
     $changes = false;
     foreach ($this->get_children('WPPTD\\Components\\Metabox') as $metabox) {
         foreach ($metabox->get_children() as $field) {
             $meta_value_old = wpptd_get_post_meta_value($post_id, $field->slug);
             if ($meta_value_old === null) {
                 $meta_value_old = $field->default;
             }
             $meta_values_old[$field->slug] = $meta_value_old;
             $meta_value = null;
             if (isset($meta_values[$field->slug])) {
                 $meta_value = $meta_values[$field->slug];
             }
             list($meta_value_validated, $error, $changed) = $this->validate_meta_value($field, $meta_value, $meta_value_old);
             $meta_values_validated[$field->slug] = $meta_value_validated;
             if ($error) {
                 $errors[$field->slug] = $error;
             } elseif ($changed) {
                 $changes = true;
             }
         }
     }
     if ($changes) {
         if (has_action('wpptd_update_meta_values_' . $this->slug)) {
             App::deprecated_action('wpptd_update_meta_values_' . $this->slug, '0.6.0', 'wpptd_update_post_meta_values_' . $this->slug);
             /**
              * This action can be used to perform additional steps when the meta values of this post type were updated.
              *
              * @since 0.5.0
              * @deprecated 0.6.0
              * @param array the updated meta values as $field_slug => $value
              * @param array the previous meta values as $field_slug => $value
              */
             do_action('wpptd_update_meta_values_' . $this->slug, $meta_values_validated, $meta_values_old);
         }
         /**
          * This action can be used to perform additional steps when the meta values of this post type were updated.
          *
          * @since 0.6.0
          * @param array the updated meta values as $field_slug => $value
          * @param array the previous meta values as $field_slug => $value
          */
         do_action('wpptd_update_post_meta_values_' . $this->slug, $meta_values_validated, $meta_values_old);
     }
     if (has_filter('wpptd_validated_meta_values')) {
         App::deprecated_filter('wpptd_validated_meta_values', '0.6.0', 'wpptd_validated_post_meta_values_' . $this->slug);
         /**
          * This filter can be used by the developer to modify the validated meta values right before they are saved.
          *
          * @since 0.5.0
          * @deprecated 0.6.0
          * @param array the associative array of meta keys (fields slugs) and their values
          */
         $meta_values_validated = apply_filters('wpptd_validated_meta_values', $meta_values_validated);
     }
     /**
      * This filter can be used by the developer to modify the validated meta values right before they are saved.
      *
      * @since 0.6.0
      * @param array the associative array of meta keys (fields slugs) and their values
      */
     $meta_values_validated = apply_filters('wpptd_validated_post_meta_values_' . $this->slug, $meta_values_validated);
     $this->add_settings_message($errors, $post_id);
     return $meta_values_validated;
 }
예제 #3
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);
 }