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 ProgrammersWhat 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_name | SITE_NAME | RND Framework |
site_tag | SITE_TAG | Official Documentation of RND Framework |
site_url | SITE_URL | https://www.rndvn.com/docs |
site_phone | SITE_PHONE | +84367737640 |
site_email | SITE_EMAIL | ngan @ rndvn.com |
site_engine_version | SITE_ENGINE_VERSION | 2.0.3 |
site_template_name | SITE_TEMPLATE_NAME | simple |
seo_title | SEO_TITLE | RND Framework - Build Your Website Quickly! |
seo_description | SEO_DESCRIPTION | Developing 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_keywords | SEO_KEYWORDS | rnd framework official documentation |
And the following special constants are set by the RND Engine to do more stuff.
PHP Constant | Usage | Current Output |
---|---|---|
APP_URL | Returns the public address of your website. | https://www.rndvn.com/docs |
MEDIA_URL | Access your uploaded media easily using this constant. | https://www.rndvn.com/docs/rnd-content/uploads |
APP_TMPL | Internal path where your site contents are located. | *** Not Public *** |
APP_TMPL_URL | Public path where your site contents are located. | https://www.rndvn.com/docs/rnd-content |
APP_ROOT | Internal path of RND Engine. | *** Not Public *** |
APP_ROOT_URL | Public path of RND Engine. | https://www.rndvn.com/docs/rnd-engine |
RND_THEME_PATH | Internal 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_html | Action | |
rnd__html | Action | |
rnd_body | Action | |
rnd__body | Action | |
rnd_head | Action/Filter |