Esempio n. 1
0
 public function get_meta($field = '', $single = false, $formatted = false)
 {
     $use_wpptd = null === $single || $formatted;
     if ($field) {
         if ($use_wpptd && function_exists('wpptd_get_post_meta_value')) {
             return wpptd_get_post_meta_value($this->item->ID, $field, $single, $formatted);
         }
         if (!$single) {
             $single = false;
         }
         return get_post_meta($this->item->ID, $field, $single);
     } else {
         if ($use_wpptd && function_exists('wpptd_get_post_meta_values')) {
             return wpptd_get_post_meta_values($this->item->ID, $single, $formatted);
         }
         return get_post_meta($this->item->ID);
     }
 }
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * Renders the meta value of this field for usage in a posts list table column.
  *
  * @since 0.5.0
  * @param integer $post_id the post ID to display the meta value for
  */
 public function render_table_column($post_id)
 {
     $formatted = Utility::get_default_formatted($this->type);
     $output = wpptd_get_post_meta_value($post_id, $this->slug, null, $formatted);
     if (has_filter('wpptd_' . get_post_type($post_id) . '_table_meta_' . $this->slug . '_output')) {
         App::deprecated_filter('wpptd_' . get_post_type($post_id) . '_table_meta_' . $this->slug . '_output', '0.6.0', 'wpptd_' . get_post_type($post_id) . '_post_table_meta_' . $this->slug . '_output');
         /**
          * This filter can be used by the developer to modify the way a specific meta value is printed in the posts list table.
          *
          * @since 0.5.0
          * @deprecated 0.6.0
          * @param mixed the formatted meta value
          * @param integer the post ID
          */
         $output = apply_filters('wpptd_' . get_post_type($post_id) . '_table_meta_' . $this->slug . '_output', $output, $post_id);
     }
     /**
      * This filter can be used by the developer to modify the way a specific meta value is printed in the posts list table.
      *
      * @since 0.6.0
      * @param mixed the formatted meta value
      * @param integer the post ID
      */
     echo apply_filters('wpptd_' . get_post_type($post_id) . '_post_table_meta_' . $this->slug . '_output', $output, $post_id);
 }