/** * Prepare template data to replace * * @since 1.0.0 * @param array $atts output attributes */ public static function setup_template_data($data, $atts, $content = null) { require_once CHERRY_SHORTCODES_DIR . 'inc/template-callbacks.php'; $callbacks = new Cherry_Shortcodes_Template_Callbacks($atts, $content); $full_data = array('title' => array($callbacks, 'title'), 'date' => array($callbacks, 'date'), 'button' => array($callbacks, 'button'), 'image' => array($callbacks, 'image'), 'excerpt' => array($callbacks, 'excerpt'), 'content' => array($callbacks, 'content'), 'author' => array($callbacks, 'author'), 'comments' => array($callbacks, 'comments'), 'taxonomy' => array($callbacks, 'taxonomy'), 'permalink' => array($callbacks, 'permalink'), 'color' => array($callbacks, 'banner_color'), 'bgcolor' => array($callbacks, 'banner_bgcolor'), 'url' => array($callbacks, 'banner_url')); $_data = array(); foreach ($data as $key) { if (!empty($full_data[$key])) { $_data = array_merge($_data, array($key => $full_data[$key])); } } self::$post_data = apply_filters('cherry_shortcodes_data_callbacks', $_data, $atts); }
public function permalink() { global $post; $shortcode = Cherry_Shortcodes_Handler::get_shortcode_name(); $permalink = esc_url(get_permalink($post->ID)); if (empty($permalink)) { return; } return apply_filters('cherry_shortcodes_permalink_template_callbacks', $permalink, $this->atts, $shortcode); }
/** * Retrieve a post permalink. * * @since 1.0.0 * @global WP_Post $post WP_Post object. * @return string Post permalink. */ public function permalink() { global $post; $shortcode = Cherry_Shortcodes_Handler::get_shortcode_name(); $permalink = esc_url(get_permalink($post->ID)); if (empty($permalink)) { return; } /** * Filter a post permalink. * * @since 1.0.0 * @param string $permalink Post permalink. * @param array $atts Shortcode attributes. * @param string $shortcode Shortcode name. */ return apply_filters('cherry_shortcodes_permalink_template_callbacks', $permalink, $this->atts, $shortcode); }
/** * Callback-function for [col], [col_inner] shortcode. */ public function col($original_atts = null, $content = null) { $atts = shortcode_atts(array('size_xs' => 'none', 'size_sm' => 'none', 'size_md' => 'none', 'size_lg' => 'none', 'offset_xs' => '', 'offset_sm' => '', 'offset_md' => '', 'offset_lg' => '', 'pull_xs' => '', 'pull_sm' => '', 'pull_md' => '', 'pull_lg' => '', 'push_xs' => '', 'push_sm' => '', 'push_md' => '', 'push_lg' => '', 'collapse' => 'no', 'class' => '', 'bg_type' => 'none', 'preset' => '', 'bg_color' => '', 'bg_image' => '', 'bg_position' => 'center', 'bg_repeat' => 'no-repeat', 'bg_attachment' => 'scroll', 'bg_size' => 'auto'), $original_atts, 'col'); $class = ''; // Size $class .= 'none' == $atts['size_xs'] ? '' : ' col-xs-' . sanitize_key($atts['size_xs']); $class .= 'none' == $atts['size_sm'] ? '' : ' col-sm-' . sanitize_key($atts['size_sm']); $class .= 'none' == $atts['size_md'] ? '' : ' col-md-' . sanitize_key($atts['size_md']); $class .= 'none' == $atts['size_lg'] ? '' : ' col-lg-' . sanitize_key($atts['size_lg']); // Offset if (!empty($original_atts['offset_xs'])) { $class .= 'none' == $original_atts['offset_xs'] ? ' col-xs-offset-0' : ' col-xs-offset-' . sanitize_key($atts['offset_xs']); } if (!empty($original_atts['offset_sm'])) { $class .= 'none' == $original_atts['offset_sm'] ? ' col-sm-offset-0' : ' col-sm-offset-' . sanitize_key($atts['offset_sm']); } if (!empty($original_atts['offset_md'])) { $class .= 'none' == $original_atts['offset_md'] ? ' col-md-offset-0' : ' col-md-offset-' . sanitize_key($atts['offset_md']); } if (!empty($original_atts['offset_lg'])) { $class .= 'none' == $original_atts['offset_lg'] ? ' col-lg-offset-0' : ' col-lg-offset-' . sanitize_key($atts['offset_lg']); } // Pull if (!empty($original_atts['pull_xs'])) { $class .= 'none' == $original_atts['pull_xs'] ? ' col-xs-pull-0' : ' col-xs-pull-' . sanitize_key($atts['pull_xs']); } if (!empty($original_atts['pull_sm'])) { $class .= 'none' == $original_atts['pull_sm'] ? ' col-sm-pull-0' : ' col-sm-pull-' . sanitize_key($atts['pull_sm']); } if (!empty($original_atts['pull_md'])) { $class .= 'none' == $original_atts['pull_md'] ? ' col-md-pull-0' : ' col-md-pull-' . sanitize_key($atts['pull_md']); } if (!empty($original_atts['pull_lg'])) { $class .= 'none' == $original_atts['pull_lg'] ? ' col-lg-pull-0' : ' col-lg-pull-' . sanitize_key($atts['pull_lg']); } // Push if (!empty($original_atts['push_xs'])) { $class .= 'none' == $original_atts['push_xs'] ? ' col-xs-push-0' : ' col-xs-push-' . sanitize_key($atts['push_xs']); } if (!empty($original_atts['push_sm'])) { $class .= 'none' == $original_atts['push_sm'] ? ' col-sm-push-0' : ' col-sm-push-' . sanitize_key($atts['push_sm']); } if (!empty($original_atts['push_md'])) { $class .= 'none' == $original_atts['push_md'] ? ' col-md-push-0' : ' col-md-push-' . sanitize_key($atts['push_md']); } if (!empty($original_atts['push_lg'])) { $class .= 'none' == $original_atts['push_lg'] ? ' col-lg-push-0' : ' col-lg-push-' . sanitize_key($atts['push_lg']); } // Collapse? $class .= 'yes' != $atts['collapse'] ? '' : ' collapse-col'; $class .= cherry_esc_class_attr($atts); // Backgroud Type $bg_type = sanitize_key($atts['bg_type']); if ('image' == $bg_type) { $_atts = $atts; if (!empty($_atts['class'])) { $_atts['class'] = ''; } $_content = Cherry_Shortcodes_Handler::box($_atts, $content); } else { $_content = do_shortcode($content); } $output = '<div class="' . trim(esc_attr($class)) . '">' . $_content . '</div>'; return apply_filters('cherry_shortcodes_output', $output, $atts, 'col'); }