Div Detection Class

One thing that is helpful when address browser and OS compatibility issues is to determine which browser and OS you are using. Thankfully if you’re using the Div Library plugin then you can take advantage of the DIV_Detection class included to populate the browser and OS within the <body> tag of your HTML. Simple add the following to your header.php

<?php if(class_exists('DIV_Detection')) $detection = new DIV_Detection(); ?>

This will instantiate the class allowing it to construct the HTTP_USER_AGENT details in the body class which can then be used to make CSS adjustments specifically to that browser and/or OS combination. Try it out for yourself its a great addition to have in your arsenal.

Div Module Class: Loop()

Get All Published Entries

The loop() method is part of the DIV_Module class which is used for setting up a custom post type module (CPT Module). This allows for quick implementation of content loops for your custom post types. To start you merely need two lines of code:

$my_cpt = new my_cpt();
$my_cpt->loop();

Above these two lines simply instantiate your CPT class and then call the loop() method without any options passed to the method. By default this will list 10 iterations of your custom post type and display them according to the loop-{cpt}.php within your CPT module. If you want to modify the number of iterations simply pass a number like so:

$my_cpt->loop(3);

Also, rather than passing an integer, you can pass an array of options just as you would to WP_Query directly. Any options you pass will be used to override the WP_Query.

Customize The Content

As for the content there are a couple available options. As mentioned, you can simply edit the loop-{cpt}.php file to get your desired result or perhaps your needs have varying results, simply use the loop_content_{cpt} filter like so:

add_filter( 'loop_content_{cpt}', function($s){
  return DIV_Helper::return_output(__DIR__.'/loop-custom.php');
});

There is also a second optional parameter, by default it is set to TRUE to return the content loop as described above, but if you set it to false then it will just return the query results from WP_Query allowing you to set up a custom loop.

NOTE: By default the page-{cpt}.php within the CPT Module directory uses the loop()

Why we used the Singleton pattern

For the library, there was much debate on the use of the Singleton pattern. There are very few use cases for it, and we tried really hard to move forward without it. However, when it came down to building an abstract widget class that extended the WP_Widget class, our hand was forced. At that point, the class has no connection to the library class. There was no way to pass an instance of the library class into the widget class and so there were only 2 ways to access the library class from the widget class:

1. Create a global variable and access it from within the class.

2. Setup the library as a singleton and access it as a local variable that points to the instance of the library class.

We chose option number 2. We did this because the Woocommerce plugin apparently found value in moving away from globals and to the singleton patterns, AND because this article set our mind at ease: http://eamann.com/tech/the-case-for-singletons/.

Div Starter: Shortcodes

Shortcodes are great, until they get overused and bloat your code with pointless vulnerabilities. “The Div Blend Way” is about finding the right balance to great tools like these. Often shortcodes provide helpful functionality for custom solutions, but very quickly they overstep their bounds. Meaning from within the theme or theme framework you have many develops adding what we refer to as “business logic” but the “WordPress Way” or philosophy is to keep this logic within the plugin’s scope, and instead keep only “visual logic” within the theme structure. For this reason Div Starter is a plugin framework for creating shortcodes within a site plugin.

Create a class that extends DS_Shortcodes

class My_Shortcodes extend DS_Shortcodes {

    public function __construct {
        //filter $shortcodes array
        //or filter existing ds shortcodes
    }

    public static function my_shortcode ($atts) {
        return self::shortcode_wrapper ( array( 'Custom_Class','method'), $atts);
    }

} //end of site app shortcodes

Add an action for your class

add_action('init', array('My_Shortcodes','__construct') );

Include your shortcode class

more details coming soon….