Adding Custom Field Support in Shorcodes
-
I was wondering if it would be possible to add custom field support in the shortcode.
I’m doing this manually currently with the following modification by using the shortcode $content variable.[vdo][field key=field_587a44be392fa][/vdo]
Edit of vdo_shortcode function
if(!empty($content)){ $content = trim(do_shortcode($content)); if(strlen($content)==32){ $video = $content; } }else{
Complete
function vdo_shortcode( $atts, $content='' ) { extract( shortcode_atts( array( 'title' => 'TITLE_OF_VIDEO', 'width' => get_option('vdo_default_width') . "px", 'height' => get_option('vdo_default_height') . "px", 'id' => 'id', 'no_annotate'=> false, 'version'=> 0, ), $atts ) ); if(!isset($atts['id'])){ if(!empty($content)){ $content = trim(do_shortcode($content)); if(strlen($content)==32){ $video = $content; } }else{ if(!$atts['title']) return "Required argument id for embedded video not found."; $params = array( 'search'=>array( 'title'=>$title ), 'page'=>1, 'limit'=>30, 'type'=>'json' ); $video = vdo_send("videos", $params); $video = json_decode($video); if($video == null) return "404. Video not found."; $video = $video[0]->id; if ($video == null) { return "No video with given title found."; } } } else $video = $id; $params = array( 'video'=>$video ); $anno = false; if (!function_exists("eval_date")) { function eval_date($matches){ return current_time($matches[1]); } } if (get_option('vdo_annotate_code') != "") { $current_user = wp_get_current_user(); $vdo_annotate_code = get_option('vdo_annotate_code'); $vdo_annotate_code = apply_filters('vdocipher_annotate_preprocess', $vdo_annotate_code); if (is_user_logged_in()) { $vdo_annotate_code = str_replace('{name}', $current_user->display_name , $vdo_annotate_code); $vdo_annotate_code = str_replace('{email}', $current_user->user_email , $vdo_annotate_code); $vdo_annotate_code = str_replace('{username}', $current_user->user_login , $vdo_annotate_code); $vdo_annotate_code = str_replace('{id}', $current_user->ID , $vdo_annotate_code); } $vdo_annotate_code = str_replace('{ip}', $_SERVER['REMOTE_ADDR'] , $vdo_annotate_code); $vdo_annotate_code = preg_replace_callback('/\{date\.([^\}]+)\}/', "eval_date" , $vdo_annotate_code); $vdo_annotate_code = apply_filters('vdocipher_annotate_postprocess', $vdo_annotate_code); if(!$no_annotate) $anno = array("annotate" => $vdo_annotate_code); } $OTP = vdo_send("otp", $params, $anno); $OTP = json_decode($OTP); if(is_null($OTP)){ $output = "<span id='vdo$OTP' style='background:#555555;color:#FFFFFF'><h4>Video not found</h4></span>"; return $output; } $OTP = $OTP->otp; // $version = $atts['version']; //handled by extract function $output = "<div id='vdo$OTP' style='height:$height;width:$width;max-width:100%' ></div>"; $output .= "<script> (function(v,i,d,e,o){v[o]=v[o]||{}; v[o].add = v[o].add || function V(a){ (v[o].d=v[o].d||[]).push(a);};"; $output .= "if(!v[o].l) { v[o].l=1*new Date(); a=i.createElement(d), m=i.getElementsByTagName(d)[0]; a.async=1; a.src=e; m.parentNode.insertBefore(a,m);}"; $output .= " })(window,document,'script','//de122v0opjemw.cloudfront.net/vdo.js','vdo'); vdo.add({ "; $output .= "o: '$OTP', "; if ($version == 32) $output .= "version: '$version' "; $output .= "}); </script>"; return $output; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Adding Custom Field Support in Shorcodes’ is closed to new replies.