Permalink
Browse files

Add shortcode `[rwmb_meta meta_key="..."]`.

Attributes are the same as `rwmb_meta` function
  • Loading branch information...
1 parent a3362c8 commit 39507d6d5117854ce7fd21421e95480a6564cafc @rilwis committed Oct 13, 2012
Showing with 127 additions and 8 deletions.
  1. +103 −4 inc/helpers.php
  2. +2 −2 meta-box.php
  3. +11 −1 readme.md
  4. +11 −1 readme.txt
  5. BIN screenshot-1.png
View
@@ -7,6 +7,105 @@
// Prevent loading this file directly
defined( 'ABSPATH' ) || exit;
+add_shortcode( 'rwmb_meta', 'rwmb_meta_shortcode' );
+
+/**
+ * Shortcode to display meta value
+ *
+ * @param $atts Array of shortcode attributes, same as rwmb_meta function, but has more "meta_key" parameter
+ * @see rwmb_meta function below
+ *
+ * @return string
+ */
+function rwmb_meta_shortcode( $atts )
+{
+ $atts = wp_parse_args( $atts, array(
+ 'type' => 'text',
+ 'post_id' => get_the_ID(),
+ ) );
+ if ( empty( $atts['meta_key'] ) )
+ return '';
+
+ $meta = rwmb_meta( $atts['meta_key'], $atts, $atts['post_id'] );
+
+ // Get uploaded files info
+ if ( 'file' == $atts['type'] )
+ {
+ $content = '<ul>';
+ foreach ( $meta as $file )
+ {
+ $content .= sprintf(
+ '<li><a href="%s" title="%s">%s</a></li>',
+ $file['url'],
+ $file['title'],
+ $file['name']
+ );
+ }
+ $content .= '</ul>';
+ }
+
+ // Get uploaded images info
+ elseif ( in_array( $atts['type'], array( 'image', 'plupload_image', 'thickbox_image' ) ) )
+ {
+ $content = '<ul>';
+ foreach ( $meta as $image )
+ {
+ // Link thumbnail to full size image?
+ if ( isset( $atts['link'] ) && $atts['link'] )
+ {
+ $content .= sprintf(
+ '<li><a href="%s" title="%s"><img src="%s" alt="%s" title="%s" /></a></li>',
+ $image['full_url'],
+ $image['title'],
+ $image['url'],
+ $image['alt'],
+ $image['title']
+ );
+ }
+ else
+ {
+ $content .= sprintf(
+ '<li><img src="%s" alt="%s" title="%s" /></li>',
+ $image['url'],
+ $image['alt'],
+ $image['title']
+ );
+ }
+ }
+ $content .= '</ul>';
+ }
+
+ // Get post terms
+ elseif ( 'taxonomy' == $atts['type'] )
+ {
+
+ $content = '<ul>';
+ foreach ( $meta as $term )
+ {
+ $content .= sprintf(
+ '<li><a href="%s" title="%s">%s</a></li>',
+ get_term_link( $term, $atts['taxonomy'] ),
+ $term->name,
+ $term->name
+ );
+ }
+ $content .= '</ul>';
+ }
+
+ // Normal multiple fields: checkbox_list, select with multiple values
+ elseif ( is_array( $meta ) )
+ {
+ $content = '<ul><li>' . implode( '</li><li>', $meta ) . '</li></ul>';
+ }
+
+ else
+ {
+ $content = $meta;
+ }
+
+ return apply_filters( __FUNCTION__, $content );
+}
+
/**
* Get post meta
*
@@ -32,7 +131,7 @@ function rwmb_meta( $key, $args = array(), $post_id = null )
// Get uploaded files info
if ( 'file' == $args['type'] )
{
- if ( is_array( $meta ) && ! empty( $meta ) )
+ if ( is_array( $meta ) && !empty( $meta ) )
{
$files = array();
foreach ( $meta as $id )
@@ -46,10 +145,10 @@ function rwmb_meta( $key, $args = array(), $post_id = null )
// Get uploaded images info
elseif ( in_array( $args['type'], array( 'image', 'plupload_image', 'thickbox_image' ) ) )
{
- if ( is_array( $meta ) && ! empty( $meta ) )
+ if ( is_array( $meta ) && !empty( $meta ) )
{
global $wpdb;
- $meta = implode( ',' , $meta );
+ $meta = implode( ',', $meta );
// Re-arrange images with 'menu_order'
$meta = $wpdb->get_col( "
@@ -74,7 +173,7 @@ function rwmb_meta( $key, $args = array(), $post_id = null )
$meta = empty( $args['taxonomy'] ) ? array() : wp_get_post_terms( $post_id, $args['taxonomy'] );
}
- return $meta;
+ return apply_filters( __FUNCTION__, $meta );
}
/**
View
@@ -3,7 +3,7 @@
Plugin Name: Meta Box
Plugin URI: http://www.deluxeblogtips.com/meta-box
Description: Create meta box for editing pages in WordPress. Compatible with custom post types since WP 3.0
-Version: 4.1.11
+Version: 4.2
Author: Rilwis
Author URI: http://www.deluxeblogtips.com
License: GPL2+
@@ -13,7 +13,7 @@
defined( 'ABSPATH' ) || exit;
// Script version, used to add version for scripts and styles
-define( 'RWMB_VER', '4.1.9' );
+define( 'RWMB_VER', '4.2' );
// Define plugin URLs, for fast enqueuing scripts and styles
if ( ! defined( 'RWMB_URL' ) )
View
@@ -22,6 +22,7 @@ Meta Box plugin provides an API to easily implement custom meta boxes in editing
- file
- hidden
- image
+- number
- password
- plupload_image
- radio
@@ -61,13 +62,22 @@ To getting started with the plugin API, please read [this tutorial](http://www.d
## Changelog
+#### 4.2
+* Bug fix: save only last element of `select` field with `multiple` values. [Link](http://wordpress.org/support/topic/plugin-meta-box-multiple-declaration-for-select-fields-no-longer-working?replies=5#post-3254534)
+* Improvement: add `js_options` attribute for `date`, `datetime`, `time` fields to adjust jQuery date/datetime picker options. See `demo/demo.php` for usage
+* Improvement: add `options` attribute for `wysiwyg`. You now can pass arguments same as for `wp_editor` function
+* Improvement: clone feature now works with `checkbox_list` and `select` with `multiple` values
+* Improvement: add `rwmb-{$field_type}-wrapper` class to field markup
+* Improvement: Add [rwmb_meta meta_key="..."] shortcode. Attributes are the same as `rwmb_meta` function.
+* Code refactored
+
#### 4.1.11
* Bug fix: helper function for getting `taxonomy` field type
* Bug fix: `multiple` attribute for `select` field type
#### 4.1.10
* Allow helper functions can be used in admin area
-* Allow cloned fields to have a uniquely indexed `name` attribute
+* Allow cloned fields to have a uniquely indexed `name` attribute
* Add Swedish translation
* Allow hidden field has its own value
* Taxonomy field now supported by `rwmb_meta` function
View
@@ -28,6 +28,7 @@ Meta Box plugin provides an API to easily implement custom meta boxes in editing
- file
- hidden
- image
+- number
- password
- plupload_image
- radio
@@ -58,13 +59,22 @@ To getting started with the plugin API, please read [this tutorial](http://www.d
== Changelog ==
+= 4.2 =
+* Bug fix: save only last element of `select` field with `multiple` values. [Link](http://wordpress.org/support/topic/plugin-meta-box-multiple-declaration-for-select-fields-no-longer-working?replies=5#post-3254534)
+* Improvement: add `js_options` attribute for `date`, `datetime`, `time` fields to adjust jQuery date/datetime picker options. See `demo/demo.php` for usage
+* Improvement: add `options` attribute for `wysiwyg`. You now can pass arguments same as for `wp_editor` function
+* Improvement: clone feature now works with `checkbox_list` and `select` with `multiple` values
+* Improvement: add `rwmb-{$field_type}-wrapper` class to field markup
+* Improvement: Add [rwmb_meta meta_key="..."] shortcode. Attributes are the same as `rwmb_meta` function.
+* Code refactored
+
= 4.1.11 =
* Bug fix: helper function for getting `taxonomy` field type
* Bug fix: `multiple` attribute for `select` field type
= 4.1.10 =
* Allow helper functions can be used in admin area
-* Allow cloned fields to have a uniquely indexed `name` attribute
+* Allow cloned fields to have a uniquely indexed `name` attribute
* Add Swedish translation
* Allow hidden field has its own value
* Taxonomy field now supported by `rwmb_meta` function
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 39507d6

Please sign in to comment.