Thread Owner
- Messages
- 617
- Reaction score
- 458
- Points
- 63
Online
In XenForo PHP Callbackis a type of dedicated widget that allows you to produce the contents of a widget directly with PHP.
Normal widgets are usually based on templates, HTML, or specific data types; however PHP callback, it allows you to write your own logic and turn the output as you wish.
The following is a more comprehensive, simple and clear explanation:
What Does PHP Callback Widget Provide?
This widget type adds a "calling point" specific to XenForo's widget system.
You define a PHP class and a method within this class;
XenForo calls this method and displays the data that the method returns as a widget.
So:
Normal widgets are usually based on templates, HTML, or specific data types; however PHP callback, it allows you to write your own logic and turn the output as you wish.
The following is a more comprehensive, simple and clear explanation:
What Does PHP Callback Widget Provide?
This widget type adds a "calling point" specific to XenForo's widget system.
You define a PHP class and a method within this class;
XenForo calls this method and displays the data that the method returns as a widget.
So:
- You can write your own query (veritabani thread, user, message, custom table...)
- You can make your own calculation
- You can do data manipulation
- You can determine Widget’s HTML output entirely by yourself (usually combined with template)
- Do advanced things that standard widget types do not allow
- Where to use?
XenForo AdminCP Appearance Widgets Add widget
Widget type list: PHP callback visible.
When adding, you fill in the following fields:
- Callback class full name of PHP class (e.g. AddOn's MyAddon'Widget's MyWidget)
- Callback method - The method that runs Widget (e.g. rendering)
- Optional extra parameters
- How Does It Work? (General Logic)
You write a class:
CSS:namespace AddOn\MyAddon\Widget; class MyWidget { public static function render(array $widget, array $position, array $params, \XF\Template\Templater $templater) { // 1) Veri çekersin // 2) İşlersin // 3) Bir template döndürürsün return $templater->renderTemplate('my_widget_template', [ 'data' => $veriler ]); } }
The XenForo widget system invites this method and shows the rotating result as a widget on the site.
Advantages
- There is no limit: You can do anything that standard widgets can't.
- Full control: you're all about how to pull the data, how to process it.
- Performance friendly: Can be integrated into Cache system.
- Dynamic content: Member-specific content, statistics, external API, complex calculations...
- When to Use?
If you want more exclusive content than the standard widget
If you will extract special data from specific threads, categories
If you want output that varies according to the user (online/offline, level, badge, etc.)
If you will receive data from the External API
If you are going to create a fully custom HTML block
What is not?
- HTML/CSS is not widget
- Not simple static widget
- Template-only is not widget
- "Let the piece of code work" is not the type of "Let the piece of code work" . . . . . .
In short
The PHP callback widget is the call of a PHP function that is specifically written into the XenForo’s widget system.
