Loading...
Loading...
Loading...
Loading...
Loading...
In version 3.0, we introduced an auto-upgrade system for plugins and themes, along with some neat features. To make your plugins and themes able to use this new feature, you need to use the Update URI param on the description of your creations. The Update URI should be unique per theme/plugin and reply a JSON response with the following format:
s_version: Any alphanumeric string is ok, but we encourage only-numeric ones to be able to check is a version is greater or not than the installed one, preferred A.B.C style, as "1.0.2" or "2.1.0"
e_type: e_type has to be one of these options THEME or PLUGIN or "LANGUAGE"
The enqueue functions are used for loading your javascript and css files. The reason they were added is because many plugins make use of javascript frameworks such as JQuery, JQuery-ui, and fancybox just to name a few. There is a high chance that these javascript files could be loaded multiple times and that is where the enqueue functions come into play. The enqueue functions help to reduce the chances of the same file getting loaded more than once.
javascript related functions
osc_enqueue_script($id)
- Enqueue script
osc_remove_script($id)
- Remove script from the queue, so it will not be loaded
osc_register_script($id, $url, $dependencies = null)
- Add script to be loaded
osc_unregister_script($id)
- Remove script from the queue, so it will not be loaded
osc_load_scripts()
- Print the HTML tags to make the script load
css related functions
osc_enqueue_style($id, $url)
- Add style to be loaded
osc_remove_style($id)
- Remove style from the queue, so it will not be loaded
osc_load_styles()
- Print the HTML tags to make the style load
Good naming practices
If you're going to use another js library/file which is not in oc-load (for example fancybox, or any other jquery plugin) please, use a "good" name.
If you're going to use "Jquery My plugin", do not register it as "my_extrange_name", because if someone else could be registering it with a different name and then it would be loaded twice.
registering a javascript file
osc_register_script('jCarouselLite', osc_base_url() . 'oc-content/plugins/carousel_for_osclass/js/jCarouselLite.js', 'jquery');
Enqueueing the script
osc_enqueue_script('jCarouselLite');
Enqueueing a style
You may have noticed that i did not register the style and that is because it is not required and there is no function to do so.
Ok now onto a real life example.
To use these functions you will want to create a function for this example I am going to use ex_load_scripts() please use a unique function name in your plugin if you are planning on releasing it otherwise we could end up with conflicting function names.
Once you add that code you will then need to add the following hook to your index.php file of your plugin.
To load the script on the admin side you would use this hook
That is all that you have to do to get your javascript and css files working in 3.1.+
For theme developers a good example can be found in the head.php file of the modern theme.
Osclass pre registers some of the more common javascript files.
Here is the list of pre registered javascript files.
You could extend Osclass with plugins, and sometimes you need to create a special page, for example to show more options to your users.
In previous versions, the url will look like:
domain.tld/index.php?page=custom&file=your_plugin/page.php
Which isn't the prettiest url you could see, and also the file path are visible which is not a problem, but it's not good. In 3.2 we added "routes" that will transform that ugly url into a more beauty one, like:
domain.tld/your_plugin_page
They even works with regular expressions to accept variables on the url.
To make routes works, we first need to create them:
Later we just need to get the url:
Here is an example
Parameters in the $url should be enclosed between "{" and "}", example "{parameter}"
Parameters should have the same name (case sensitive) in both, osc_add_route and osc_route_url
Additionally, any file located in a folder called "admin" will be opened in admin panel, but show a 404 error in the public site
Remember that regular expressions could be tricky, make them truly unique so they will not collide with any other rule.
An example plugin could be found in github : https://github.com/osclass/osclass-plugins/tree/routes_example
At admin panel since osclass version 3.0, there is a toolbar which is visible around the admin panel, can have shortcuts to actions like: add a new listing, show pending updates, ...
Developers can add to the toolbar whatever they want, with hooks, and calling AdminToolbar functions like add_menu($array)
Usually plugin and themes needs to add menus in the Administrator panel for provide access to screens. The best way is adding a menu section in the Administration menu that allows the user to access the screens.
There are some functions for manipulate the Administration Menu.
Add menu page to Administration Menu.
Add submenu page to Administration Menu page given a menu parent identifier.
Remove menu page from Administrator Menu.
Remove submenu page given parent menu page identifier.
Helpers can add submenus to existing menus, like:Submenu Listings
Helpers are available for these pages:
Listings
Categories
Pages
Appearance
Plugins
Settings
Tools
Users
Statistics
Examples: