find_field() public static method

This function finds field in meta boxes registered by 'rwmb_meta_boxes' filter.
public static find_field ( string $field_id, integer $post_id = null ) : array | false
$field_id string Field ID
$post_id integer
return array | false Field params (array) if success. False otherwise.
Beispiel #1
0
 function cruxstore_meta($key, $args = array(), $post_id = null)
 {
     if (function_exists('rwmb_meta')) {
         /**
          * If meta boxes is registered in the backend only, we can't get field's params
          * This is for backward compatibility with version < 4.8.0
          */
         $field = RWMB_Helper::find_field($key);
         if (false === $field || isset($args['type'])) {
             return apply_filters('rwmb_meta', RWMB_Helper::meta($key, $args, $post_id));
         }
         $meta = in_array($field['type'], array('oembed', 'map')) ? rwmb_the_value($key, $args, $post_id, false) : rwmb_get_value($key, $args, $post_id);
         return apply_filters('rwmb_meta', $meta, $key, $args, $post_id);
     } else {
         return null;
     }
 }
Beispiel #2
0
/**
 * Display the value of a field
 *
 * @param  string   $field_id Field ID. Required.
 * @param  array    $args     Additional arguments. Rarely used. See specific fields for details
 * @param  int|null $post_id  Post ID. null for current post. Optional.
 * @param  bool     $echo     Display field meta value? Default `true` which works in almost all cases. We use `false` for  the [rwmb_meta] shortcode
 *
 * @return string
 */
function rwmb_the_field($field_id, $args = array(), $post_id = null, $echo = true)
{
    // Find field
    $field = RWMB_Helper::find_field($field_id);
    if (!$field) {
        return '';
    }
    $output = call_user_func(array(RW_Meta_Box::get_class_name($field), 'the_value'), $field, $args, $post_id);
    /**
     * Allow developers to change the returned value of field
     *
     * @param mixed    $value   Field HTML output
     * @param array    $field   Field parameter
     * @param array    $args    Additional arguments. Rarely used. See specific fields for details
     * @param int|null $post_id Post ID. null for current post. Optional.
     */
    $output = apply_filters('rwmb_the_field', $output, $field, $args, $post_id);
    if ($echo) {
        echo $output;
    }
    return $output;
}
 /**
  * Display the value of a field
  *
  * @param  string   $field_id Field ID. Required.
  * @param  array    $args     Additional arguments. Rarely used. See specific fields for details
  * @param  int|null $post_id  Post ID. null for current post. Optional.
  * @param  bool     $echo     Display field meta value? Default `true` which works in almost all cases. We use `false` for  the [rwmb_meta] shortcode
  *
  * @return string
  */
 function rwmb_the_value($field_id, $args = array(), $post_id = null, $echo = true)
 {
     $args = wp_parse_args($args);
     $field = RWMB_Helper::find_field($field_id, $post_id);
     if (!$field) {
         return '';
     }
     $output = RWMB_Field::call('the_value', $field, $args, $post_id);
     /**
      * Allow developers to change the returned value of field
      * For version < 4.8.2, the filter name was 'rwmb_get_field'
      *
      * @param mixed    $value   Field HTML output
      * @param array    $field   Field parameter
      * @param array    $args    Additional arguments. Rarely used. See specific fields for details
      * @param int|null $post_id Post ID. null for current post. Optional.
      */
     $output = apply_filters('rwmb_the_value', $output, $field, $args, $post_id);
     if ($echo) {
         echo $output;
     }
     return $output;
 }
Beispiel #4
0
 /**
  * Display the value of a field
  *
  * @param  string   $key     Meta key. Required.
  * @param  int|null $post_id Post ID. null for current post. Optional.
  * @param  bool     $echo    Display field meta value? Default `true` which works in almost all cases. We use `false` for the [rwmb_meta] shortcode
  *
  * @return string
  */
 function rwmb_the_field($key, $post_id = null, $echo = true)
 {
     // Find field
     $field = RWMB_Helper::find_field($key);
     if (!$field) {
         return;
     }
     // Get field meta value
     $meta = RWMB_Helper::meta($key, $field, $post_id);
     if (empty($meta)) {
         return;
     }
     // Default output is meta value
     $output = $meta;
     switch ($field['type']) {
         case 'checkbox':
             $output = $field['name'];
             break;
         case 'radio':
             $output = $field['options'][$meta];
             break;
         case 'file':
         case 'file_advanced':
             $output = '<ul>';
             foreach ($meta as $file) {
                 $output .= sprintf('<li><a href="%s" title="%s">%s</a></li>', $file['url'], $file['title'], $file['name']);
             }
             $output .= '</ul>';
             break;
         case 'image':
         case 'plupload_image':
         case 'thickbox_image':
         case 'image_advanced':
             $output = '<ul>';
             foreach ($meta as $image) {
                 $output .= sprintf('<li><img src="%s" alt="%s" title="%s" /></li>', $image['url'], $image['alt'], $image['title']);
             }
             $output .= '</ul>';
             break;
         case 'taxonomy':
             $output = '<ul>';
             foreach ($meta as $term) {
                 $output .= sprintf('<li><a href="%s" title="%s">%s</a></li>', get_term_link($term, $field['taxonomy']), $term->name, $term->name);
             }
             $output .= '</ul>';
             break;
         default:
             if (is_array($meta)) {
                 $output = '<ul><li>' . implode('</li><li>', $meta) . '</li></ul>';
             }
     }
     if ($echo) {
         echo $output;
     }
     return $output;
 }