예제 #1
0
 /**
  * Renders the post meta field.
  *
  * This function will show the input field(s) in the post editing screen.
  *
  * @since 0.5.0
  * @param WP_Post $post the post currently being shown
  */
 public function render($post)
 {
     $parent_metabox = $this->get_parent();
     $parent_post_type = $parent_metabox->get_parent();
     echo '<tr>';
     echo '<th scope="row"><label for="' . esc_attr($this->args['id']) . '">' . $this->args['title'] . '</label></th>';
     echo '<td>';
     if (has_action('wpptd_field_before')) {
         App::deprecated_action('wpptd_field_before', '0.6.0', 'wpptd_post_field_before');
         /**
          * This action can be used to display additional content on top of this field.
          *
          * @since 0.5.0
          * @deprecated 0.6.0
          * @param string the slug of the current field
          * @param array the arguments array for the current field
          * @param string the slug of the current metabox
          * @param string the slug of the current post type
          */
         do_action('wpptd_field_before', $this->slug, $this->args, $parent_metabox->slug, $parent_post_type->slug);
     }
     /**
      * This action can be used to display additional content on top of this post meta field.
      *
      * @since 0.6.0
      * @param string the slug of the current field
      * @param array the arguments array for the current field
      * @param string the slug of the current metabox
      * @param string the slug of the current post type
      */
     do_action('wpptd_post_field_before', $this->slug, $this->args, $parent_metabox->slug, $parent_post_type->slug);
     $meta_value = wpptd_get_post_meta_value($post->ID, $this->slug);
     $this->_field->display($meta_value);
     if (!empty($this->args['description'])) {
         echo '<br/><span class="description">' . $this->args['description'] . '</span>';
     }
     if (has_action('wpptd_field_after')) {
         App::deprecated_action('wpptd_field_after', '0.6.0', 'wpptd_post_field_after');
         /**
          * This action can be used to display additional content at the bottom of this field.
          *
          * @since 0.5.0
          * @deprecated 0.6.0
          * @param string the slug of the current field
          * @param array the arguments array for the current field
          * @param string the slug of the current metabox
          * @param string the slug of the current post type
          */
         do_action('wpptd_field_after', $this->slug, $this->args, $parent_metabox->slug, $parent_post_type->slug);
     }
     /**
      * This action can be used to display additional content at the bottom of this post meta field.
      *
      * @since 0.6.0
      * @param string the slug of the current field
      * @param array the arguments array for the current field
      * @param string the slug of the current metabox
      * @param string the slug of the current post type
      */
     do_action('wpptd_post_field_after', $this->slug, $this->args, $parent_metabox->slug, $parent_post_type->slug);
     echo '</td>';
     echo '</tr>';
 }
예제 #2
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);
 }
예제 #3
0
 /**
  * Renders the post 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.5.0
  * @param WP_Post $post the post currently being shown
  */
 public function render($post)
 {
     $parent_post_type = $this->get_parent();
     if ('side' == $this->args['context']) {
         echo '<div class="wpdlib-narrow">';
     }
     if (has_action('wpptd_metabox_before')) {
         App::deprecated_action('wpptd_metabox_before', '0.6.0', 'wpptd_post_metabox_before');
         /**
          * This action can be used to display additional content on top of this metabox.
          *
          * @since 0.5.0
          * @deprecated 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 post type
          */
         do_action('wpptd_metabox_before', $this->slug, $this->args, $parent_post_type->slug);
     }
     /**
      * This action can be used to display additional content on top of this post 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 post type
      */
     do_action('wpptd_post_metabox_before', $this->slug, $this->args, $parent_post_type->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');
         if (has_filter('wpptd_table_atts')) {
             App::deprecated_filter('wpptd_table_atts', '0.6.0', 'wpptd_post_table_atts');
             /**
              * This filter can be used to adjust the form table attributes.
              *
              * @since 0.5.0
              * @deprecated 0.6.0
              * @param array the associative array of form table attributes
              * @param WPPTD\Components\Metabox current metabox instance
              */
             $table_atts = apply_filters('wpptd_table_atts', $table_atts, $this);
         }
         /**
          * This filter can be used to adjust the post editing form table attributes.
          *
          * @since 0.6.0
          * @param array the associative array of form table attributes
          * @param WPPTD\Components\Metabox current metabox instance
          */
         $table_atts = apply_filters('wpptd_post_table_atts', $table_atts, $this);
         echo '<table' . FieldManager::make_html_attributes($table_atts, false, false) . '>';
         foreach ($this->get_children() as $field) {
             $field->render($post);
         }
         echo '</table>';
     } elseif ($this->args['callback'] && is_callable($this->args['callback'])) {
         call_user_func($this->args['callback'], $post);
     } 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');
     }
     if (has_action('wpptd_metabox_after')) {
         App::deprecated_action('wpptd_metabox_after', '0.6.0', 'wpptd_post_metabox_after');
         /**
          * This action can be used to display additional content at the bottom of this metabox.
          *
          * @since 0.5.0
          * @deprecated 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 post type
          */
         do_action('wpptd_metabox_after', $this->slug, $this->args, $parent_post_type->slug);
     }
     /**
      * This action can be used to display additional content at the bottom of this post 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 post type
      */
     do_action('wpptd_post_metabox_after', $this->slug, $this->args, $parent_post_type->slug);
     if ('side' == $this->args['context']) {
         echo '</div>';
     }
 }