Appearance
wpda.callService(action, args, callback, error)
Calls a custom PHP function from a JavaScript hook or computed field. This feature allows you to execute server-side logic at pre-defined points in your application.
Scope: GLOBAL
🛡️ Important
Each server call must be authorized in the App Manager. In the Authorize Server Calls section, enter the PHP function name (e.g., myPhpFunction) or the PHP class and method name (e.g., myClass.myMethod) for each function and class/method combination.
> Read more about Authorizing Server Calls...
Parameters
| Parameter | Type | Description |
|---|---|---|
| action | string | The name of a PHP function, or an array containing a PHP class and method name. |
| args | object | An object containing the arguments to pass to the server-side function. |
| callback | function | The JavaScript function to execute upon a successful response. |
| error | function | The JavaScript function to handle any errors returned by the call. |
Return Value
any
✨ Example Calling a PHP function
js
wpda.callService(
"myFunction",
{
param1: "param1 value",
param2: "param2 value",
},
function(response) {
console.log(response)
// Your code here...
},
function(error) {
console.error(error)
// Your error handling here...
},
)✨ Example Calling a PHP Class Method
js
wpda.callService(
[
"myClass",
"myMethod"
],
{
param1: "param1 value",
param2: "param2 value",
},
function(response) {
console.log(response)
// Your code here...
},
function(error) {
console.error(error)
// Your error handling here...
},
)Preparing the PHP Server Code
For wpda.callService to work, your PHP code must be properly exposed through the plugin's REST API.
✨ Code Manager Example
You can prepare your server code in several ways. The example below implements the server-side logic for the client-side examples above using the Code Manager. The code must be defined as Library Code, which is a premium feature.

📌 App permission is automatically applied to prevent unauthorized users from accessing your PHP functions.
