wrapping functions in if !function exists to prevent conflicts
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 3 Dec 2018 18:21:12 +0000 (13:21 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 3 Dec 2018 18:21:12 +0000 (13:21 -0500)
glm-blocks.php

index 7f7c164..8927cb7 100644 (file)
@@ -53,41 +53,43 @@ if (!function_exists('fetch_all_glm_blocks')) {
         return $frontController->fetchAllBlocks($catId);
     }
 }
-function landing_page_blocks( $atts ){
-    
-    $out = '';
-    extract(shortcode_atts(
-        array('category' => '-1'), $atts, 'glm-blocks')
-    );
-    if(function_exists('fetch_all_glm_blocks')):
-        $category = filter_var($atts['category'], FILTER_VALIDATE_INT);
+if (!function_exists('landing_page_blocks')) {
+    function landing_page_blocks( $atts ){
         
-        $blocks = fetch_all_glm_blocks($category);
-        $out .= '<div id="glm-blocks" class="glm-blocks-container">';
-        $count = 0;
-        foreach ($blocks as $block):
-            $post_image_id = get_post_thumbnail_id($block->ID);
-            $thumbnail = wp_get_attachment_image_src( $post_image_id, 'landing_page');
-            $out .= '<div class="small-text-center medium-text-left glm-block">';
-            if($block->url):
-                $out .= '<a href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>';
-            endif;
-            $out .= '<img src="'.$thumbnail[0].'"/>';
-            $out .= '<div class="land-page-block-image" style="background: url('.$thumbnail.');"></div>';
-            $out .= '<h5 class="glm-block-title">'.$block->post_title.'</h5>';
-            if($block->url):
-                $out .= '</a>';
-            endif;
-            if($block->url):
-                $buttonText = ($count < 1) ? "SIGN UP" : "BUY NOW";
-                $out .= '<a class="sign-up-button" href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>' . $buttonText .'</div>';
-            endif;
+        $out = '';
+        extract(shortcode_atts(
+            array('category' => '-1'), $atts, 'glm-blocks')
+        );
+        if(function_exists('fetch_all_glm_blocks')):
+            $category = filter_var($atts['category'], FILTER_VALIDATE_INT);
+            
+            $blocks = fetch_all_glm_blocks($category);
+            $out .= '<div id="glm-blocks" class="glm-blocks-container">';
+            $count = 0;
+            foreach ($blocks as $block):
+                $post_image_id = get_post_thumbnail_id($block->ID);
+                $thumbnail = wp_get_attachment_image_src( $post_image_id, 'landing_page');
+                $out .= '<div class="small-text-center medium-text-left glm-block">';
+                if($block->url):
+                    $out .= '<a href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>';
+                endif;
+                $out .= '<img src="'.$thumbnail[0].'"/>';
+                $out .= '<div class="land-page-block-image" style="background: url('.$thumbnail.');"></div>';
+                $out .= '<h5 class="glm-block-title">'.$block->post_title.'</h5>';
+                if($block->url):
+                    $out .= '</a>';
+                endif;
+                if($block->url):
+                    $buttonText = ($count < 1) ? "SIGN UP" : "BUY NOW";
+                    $out .= '<a class="sign-up-button" href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>' . $buttonText .'</div>';
+                endif;
+                $out .= '</div>';
+                $count++;
+            endforeach;
             $out .= '</div>';
-            $count++;
-        endforeach;
-        $out .= '</div>';
-    endif;
-    return $out;
+        endif;
+        return $out;
+    }
 }
 if (!function_exists('fetch_blocks_by_slug')) {
     function fetch_blocks_by_slug($cat)
@@ -98,41 +100,43 @@ if (!function_exists('fetch_blocks_by_slug')) {
         return $frontController->fetch_blocks_by_slug($cat);
     }
 }
-function action_item_blocks( $atts ){
+if (!function_exists('action_item_blocks')) {
+    function action_item_blocks( $atts ){
 
-    $out = '';
-    extract(shortcode_atts(
-        array('category' => '-1'), $atts, 'glm-blocks')
-    );
-    if(function_exists('fetch_blocks_by_slug')):
-        $category = filter_var($atts['category'], FILTER_SANITIZE_STRING);
-        fetch_blocks_by_slug($category);
-        $blocks = fetch_blocks_by_slug($category);
-        $out .= '<div id="glm-blocks" class="glm-blocks-container">';
-        $count = 0;
-        foreach ($blocks as $block):
-            $post_image_id = get_post_thumbnail_id($block->ID);
-            $thumbnail = wp_get_attachment_image_src( $post_image_id, 'landing_page');
-            $out .= '<div class="small-text-center medium-text-left glm-block">';
-            if($block->url):
-                $out .= '<a href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>';
-            endif;
-            $out .= '<img src="'.$thumbnail[0].'"/>';
-            $out .= '<div class="land-page-block-image" style="background: url('.$thumbnail.');"></div>';
-            $out .= '<h5 class="glm-block-title">'.$block->post_title.'</h5>';
-            if($block->url):
-                $out .= '</a>';
-            endif;
-            if($block->url):
-                $buttonText = ($count < 1) ? "SIGN UP" : "BUY NOW";
-                $out .= '<a class="sign-up-button" href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>' . $buttonText .'</a>';
-            endif;
+        $out = '';
+        extract(shortcode_atts(
+            array('category' => '-1'), $atts, 'glm-blocks')
+        );
+        if(function_exists('fetch_blocks_by_slug')):
+            $category = filter_var($atts['category'], FILTER_SANITIZE_STRING);
+            fetch_blocks_by_slug($category);
+            $blocks = fetch_blocks_by_slug($category);
+            $out .= '<div id="glm-blocks" class="glm-blocks-container">';
+            $count = 0;
+            foreach ($blocks as $block):
+                $post_image_id = get_post_thumbnail_id($block->ID);
+                $thumbnail = wp_get_attachment_image_src( $post_image_id, 'landing_page');
+                $out .= '<div class="small-text-center medium-text-left glm-block">';
+                if($block->url):
+                    $out .= '<a href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>';
+                endif;
+                $out .= '<img src="'.$thumbnail[0].'"/>';
+                $out .= '<div class="land-page-block-image" style="background: url('.$thumbnail.');"></div>';
+                $out .= '<h5 class="glm-block-title">'.$block->post_title.'</h5>';
+                if($block->url):
+                    $out .= '</a>';
+                endif;
+                if($block->url):
+                    $buttonText = ($count < 1) ? "SIGN UP" : "BUY NOW";
+                    $out .= '<a class="sign-up-button" href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>' . $buttonText .'</a>';
+                endif;
+                $out .= '</div>';
+                $count++;
+            endforeach;
             $out .= '</div>';
-            $count++;
-        endforeach;
-        $out .= '</div>';
-    endif;
-    return $out;
+        endif;
+        return $out;
+    }
 }
 add_shortcode('glm-blocks-action-items', 'action_item_blocks');
 add_shortcode('glm-blocks', 'landing_page_blocks');
\ No newline at end of file