Constants, Hooks & Functions

A php developer can use our inbuilt constants, hooks & functions to do powerful things. For example, a constant will return you important values while hooks help you to bind contents into the framework. If you have worked with Wordpress hooks, this will be too easy for you.

NOTE: Only for PHP Programmers

What are constants?

RND Engine will define some important constants when it initiates the page load event. These constants will be stored in the memory where you can easily access via php codes.

echo SITE_NAME;

Above php code will print “RND Framework” on the web page, as it is configured in site settings.

settings.json file will keeps many data and you can access them via php constants as shown on the following table.

Json Key PHP Constant Current Output
site_nameSITE_NAMERND Framework
site_tagSITE_TAGOfficial Documentation of RND Framework
site_urlSITE_URLhttps://www.rndvn.com/docs
site_phoneSITE_PHONE+84367737640
site_emailSITE_EMAILngan @ rndvn.com
site_engine_versionSITE_ENGINE_VERSION2.0.3
site_template_nameSITE_TEMPLATE_NAMEsimple
seo_titleSEO_TITLERND Framework - Build Your Website Quickly!
seo_descriptionSEO_DESCRIPTIONDeveloping a complex website is a huge challenge for a startup. This official documentation of RND Framework will teach you how to build your website quickly!
seo_keywordsSEO_KEYWORDSrnd framework official documentation

And the following special constants are set by the RND Engine to do more stuff.

PHP Constant Usage Current Output
APP_URLReturns the public address of your website.https://www.rndvn.com/docs
MEDIA_URLAccess your uploaded media easily using this constant.https://www.rndvn.com/docs/rnd-content/uploads
APP_TMPLInternal path where your site contents are located.*** Not Public ***
APP_TMPL_URLPublic path where your site contents are located.https://www.rndvn.com/docs/rnd-content
APP_ROOTInternal path of RND Engine.*** Not Public ***
APP_ROOT_URLPublic path of RND Engine.https://www.rndvn.com/docs/rnd-engine
RND_THEME_PATHInternal path of your current template.*** Not Public ***

What Are Hooks?

Hooking is the concept that we use to bind actions & filters to the framework. This can be a bit complicated for a beginner, though many Wordpress developers know how to work with this. RND Framework only uses simple Actions & Filters to render the page.

We recommend you to use these hooks only when you develop a plugin or a template.

Actions

Actions will execute something at the point you call it to do it. Before everything, you have to register the action with the RND Engine by using the following code.

add_action('your_action_name', 'your_action_function'); 

The command will register your_action_name, if it is not registered. Then assign your_action_function to execute when you call it later. Down below, you can see a complete registration of an action.

    function my_first_function() {
        echo "I love RND Framework!";
    }
    add_action('my_first_action', 'my_first_function');

After successful registration, you can execute your action as below,

get_action('my_first_action'); 

Above code will print “I love RND Framework!” on the page as it is programmed when you register the action. Watch our video tutorials, if you cannot understand this.

Filters

Unlike actions, filters are used to modify content on the page. For example, if you want to add extra content to the footer area, you can easily use filters to achieve it. Filters do NOT do executions. They just bind content to the framework and return all when the page is rendered.

Like actions, you have to register your filters with the RND Engine using following method.

add_filter('your_filter_name', 'your_filter_function'); 

It will register your_filter_name, if it is not registered. Then assign your_filter_function. Just look at the complete example below.

    function my_second_function($items) {
        $modified   = "RND Filters Modified This: " . $items ;
        return $modified;
    }
    add_filter('my_first_filter', 'my_second_function');

Unlike actions, you can see that we can pass contents into the function and modify them. PHP variable $items will include previously added contents in my_first_filter and you can easily edit/add/remove these contents to get different results.

Finally, you have to use the following command to get the filter on your page. Just take time and try to identify the pattern.

get_filter('my_first_filter', ''); 

Unlike get_action() command, get_filter() function helps you to bind extra contents using an additional parameter. Just check the following example.

    $extra_content   = "RND filters are so powerful!" ;
    
    get_filter('my_first_filter', $extra_content );

Predefined Actions & Filters

We use predefined actions and filters to manage the framework easily. These actions & filters can be accessed by plugins, templates and php pages. Just look at the following table to learn more about them.

Hook Name Hook Type Common Usage
rnd_htmlActionPrint the <html> starting tag of the page.
rnd__htmlActionPrint the </html> end tag.
rnd_bodyActionPrint the <body> starting tag of the page.
rnd__bodyActionPrint the </body> end tag.
rnd_headAction/FilterYou can take the page <head> using this hook. Action will print it while Filter set the contents. If you need to put any <link>, this is the best place to put them. Page <style> also will be printed here.
rnd_headerAction/FilterHandle the top area of the <body> tag. In most cases, top menu will be executed here.
rnd_left_sideAction/FilterA theme or plugin can add a left side menu or other contents using this reserved hook.
rnd_contentAction/FilterHere you can post page contents. This area will be divided to 3 areas. content_header, content_body, content_footer
rnd_right_sideAction/FilterA theme or plugin can add a right side menu/widgets using this reserved hook.
rnd_footerAction/FilterThe area of the end of html body. Here you can hook social links, javascripts, footer menus, and other widgets.
page_styleFilterStoring global styles to print on the final output of the page. Will be printed in <head> section.
page_scriptFilterKeeping all JavaScripts in the page to print right after the footer.
rnd_top_navAction/FilterThe list of <li> of the top primary menu.
rnd_side_navAction/FilterThe list of <li> of the side navigation menu.
rnd_footer_navAction/FilterThe list of <li> of the footer menu.

How to manipulate contents with hooks?

Actions & Plugins can only be registered via Plugins or Templates. We will explain this under another section. However you can execute them on Page Level php codes.

If you are a beginner, this can be totally rocket science. But after learning this pattern, you will see the power of hooks and you will fall in love with Actions & Filters.

Let say you want to change the footer background colour. It can be done using the following php codes.

        function change_footer_background_color($items) {

            $css = "#footer{background:#595;}";

            return $items.$css;
        }
        add_filter('page_style', 'change_footer_background_color');
    

Again, you need to create a plugin, or a template to use hooks to do powerful stuff. Otherwise, you only can execute them via Page Level PHP files.

You can find Hooks On Templates Here.

Also explore Hooks On Plugins Here.


Available Functions

There are some inbuilt functions in RND Framework that you can use in your templates & plugins. Please check the table below.

Function Return Usage
is_home()BooleanReturn “true” if the web page’s path is the home page. Otherwise return “false”.
clean_header()NoneRemoving the default header of the page silently.
clean_content()NoneRemoving the default content of the page silently.
clean_footer()NoneRemoving the default footer of the page silently.
get_file_contents_from_a_file( file_path )StringUse this function to read contents of a local or a remote file. You have to put “file_path”, otherwise it will not work.
_p( string_to_print )StringUse this function to print string data. Similar to the print() function in PHP. You have to put “string_to_print”
_e( string_to_print )StringUse this function to print string data. Similar to the echo function in PHP. You have to put “string_to_print”
_d( date_time_format )StringUse this function to print datetime. Similar to the date() function in PHP. You have to put “date_time_format”. Eg. 'Y-m-d'
sanitize_output( data )Stringstrip whitespaces after tags, except space, strip whitespaces before tags, except space, shorten multiple whitespace sequences, Remove HTML comments
utf8ize( data )String/Arrayutf8_encode() an array or a string.
generateRandomString( length )StringIt will generate a random string, and you can define the length of the string. Eg. generateRandomString(12)
get_arr_value( array_key, data_array, default_value)StringUse this function to get a value from an array. If the array_key is not existing, it will return the dafault_value.

Please note, there are many functions that you can create and submit to our developing team. Also you can use all available PHP functions with the RND framework, depending on your PHP version.


Actually, we are proud of you!

We feel you keep studying well. Now it’s time to learn how to create page layouts that saves your coding hours in web development. Just give it a try, or take a little rest!


Try Page Layouts