Example #1
0
 function wpsugar_text_block_shortcode($atts = array(), $content = null)
 {
     if (!$atts['id']) {
         return '';
     }
     $atts = array_merge(array('template' => 'wpsugar-text-block', 'class' => ''), $atts);
     $post = get_post($atts['id']);
     if (!$post) {
         return '';
     }
     $item = array('id' => $post->ID, 'title' => WPSugar\Localization::getTranslatedContent($post->post_title), 'text' => WPSugar\Localization::getTranslatedContent($post->post_content));
     $meta = get_post_meta($post->ID);
     if ($meta && is_array($meta)) {
         foreach ($meta as $key => $value) {
             if (strstr($key, $post->post_type)) {
                 $item[str_replace($post->post_type . '_', '', $key)] = WPSugar\Localization::getTranslatedContent($value[0]);
             }
         }
     }
     $style = '';
     if (isset($atts['style']) && is_array($atts['style'])) {
         foreach ($atts['style'] as $name => $value) {
             $style .= "{$name}: {$value};";
         }
     }
     return WPSugar\View::render($atts['template'], array('result' => $item, 'style' => $style, 'class' => $atts['class']), false);
 }
Example #2
0
 function wpsugar_posts_list_shortcode($atts)
 {
     if (!$atts['type']) {
         return '';
     }
     $atts = array_merge(array('count' => 10, 'template' => 'wpsugar-posts-list', 'sort' => 'sort', 'order' => 'ASC'), $atts);
     $posts = get_posts(array('post_type' => $atts['type'], 'posts_per_page' => $atts['count'], 'meta_key' => $atts['type'] . '_' . $atts['sort'], 'orderby' => $atts['sort'] == 'sort' ? 'meta_value_num' : 'meta_value', 'order' => $atts['order']));
     if (!$posts) {
         return '';
     }
     $items = array();
     foreach ($posts as $post) {
         $items[] = WPSugar\Utils::postToArray($post);
     }
     return WPSugar\View::render($atts['template'], array('items' => $items, 'type' => $atts['type']), false);
 }
Example #3
0
 function wpsugar_form_shortcode($atts = array())
 {
     if (!isset($atts['form']) || !$atts['form']) {
         return '';
     }
     $atts = array_merge(array('template' => 'wpsugar-form'), $atts);
     $config = WPSugar\Config::get();
     if (!$config || !isset($config['forms']) || !is_array($config['forms'])) {
         return;
     }
     foreach ($config['forms'] as $item) {
         if ($item['name'] === $atts['form']) {
             $form = $item;
             break;
         }
     }
     if (!isset($form) || !$form) {
         return;
     }
     return WPSugar\View::render($atts['template'], array('form' => $form), false);
 }