Skip to content

Instantly share code, notes, and snippets.

@kuraga
Created October 17, 2014 19:02
Show Gist options
  • Save kuraga/6dba9f9bf1ba9abddd56 to your computer and use it in GitHub Desktop.
Save kuraga/6dba9f9bf1ba9abddd56 to your computer and use it in GitHub Desktop.
custom-content-shortcode-wck-image.patch
From: Kurakin Alexander <kuraga333@mail.ru>
Date: Thu, 16 Oct 2014 18:25:04 +0400
Subject: [PATCH] Add shortcode for WCK images
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
includes/wck.php | 56 ++++++++++++++++++++
1 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/includes/wck.php b/includes/wck.php
index 42efd45..1dc50a9 100644
--- a/includes/wck.php
+++ b/includes/wck.php
@@ -25,6 +25,7 @@ class CCS_To_WCK {
if (function_exists('the_cfc_field') && function_exists('get_cfc_meta')) {
add_shortcode( 'wck-field', array($this, 'wck_field_shortcode') );
+ add_shortcode( 'wck-field-image', array($this, 'wck_field_image_shortcode') );
add_shortcode( 'wck-repeat', array($this, 'wck_repeater_shortcode') );
}
@@ -101,6 +102,61 @@ class CCS_To_WCK {
/*========================================================================
*
+ * [wck-field-image]
+ *
+ *=======================================================================*/
+
+ function wck_field_image_shortcode( $atts ) {
+
+ extract( shortcode_atts( array(
+ 'meta' => '',
+ 'name' => '',
+ 'id' => '',
+ 'size' => 'thumbnail',
+ 'icon' => '0',
+ 'attr' => '',
+ ), $atts ) );
+
+ /* Inside repeater? */
+
+ if ( self::$state['is_wck_repeater']=='true' ) {
+
+ // Get meta key
+
+ if (empty($meta))
+ $meta = self::$state['wck_repeater_meta'];
+
+ $key = self::$state['wck_repeater_key'];
+ if (!empty(self::$state['wck_repeater_id']))
+ $id = self::$state['wck_repeater_id'];
+ }
+
+ $out = null;
+ if ( (!empty($meta)) && (!empty($name)) ) {
+
+ if (self::$state['is_wck_repeater']=='true') {
+
+ // In a repeater loop
+
+ if (!empty($id)) $res = get_cfc_field( $meta, $name, $id, $key );
+ else $res = get_cfc_field( $meta, $name, false, $key );
+ }
+ else {
+
+ // Single meta and field
+
+ if (!empty($id)) $res = get_cfc_field( $meta, $name, $id );
+ else $res = get_cfc_field( $meta, $name );
+ }
+
+ $out = wp_get_attachment_image($res['id'], $size, $icon, $attr);
+ }
+ return $out;
+ }
+
+
+ /*========================================================================
+ *
* [wck-repeat]
*
*=======================================================================*/
--
1.7.2.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment