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; } }
/** * 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; }
/** * Get post meta * * @param string $key Meta key. Required. * @param int|null $post_id Post ID. null for current post. Optional * @param array $args Array of arguments. Optional. * * @return mixed */ function rwmb_meta($key, $args = array(), $post_id = null) { return RWMB_Helper::meta($key, $args, $post_id); }
/** * 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; }
/** * Get value of custom field. * This is used to replace old version of rwmb_meta key. rwmb_meta will be used internally only. * * @uses rwmb_meta() * @param string $key Meta key. Required. * @param int|null $post_id Post ID. null for current post. Optional. * @return mixed false if field doesn't exist. Field value otherwise. */ function rwmb_get_field($key, $post_id = null) { /** * Search all the registered meta box to find needed field * The field will have all needed parameters which we can pass to rwmb_meta function without * having users to manually set them (field type, multiple, ect.). So users only need to remember * field ID only. */ $found = false; $meta_boxes = apply_filters('rwmb_meta_boxes', array()); foreach ($meta_boxes as $meta_box) { foreach ($meta_box['fields'] as $field) { if ($key == $field['id']) { $found = true; break; } } } // If field doesn't exist, return false if (!$found) { return false; } // Normalize field to make sure all params are set properly $field = wp_parse_args($field, array('id' => '', 'multiple' => false, 'clone' => false, 'std' => '', 'desc' => '', 'format' => '', 'before' => '', 'after' => '', 'field_name' => isset($field['id']) ? $field['id'] : '', 'required' => false, 'placeholder' => '')); $field = call_user_func(array(RW_Meta_Box::get_class_name($field), 'normalize_field'), $field); // Get field value return RWMB_Helper::meta($key, $field, $post_id); }