Italian (Italy)

apply_filters( 'vikbooking_load_conditional_rules', array $return )

Fired during the plugin installation, it's necessary to define the driver paths to let VikBooking recognize them as Conditional Rule drivers. Your driver(s) will then be available for selection in the apposite back-end list of rules when creating a new Conditional Text.


Description

This hook is needed when creating a new native Wordpress plugin that will be used by VikBooking to extend its Conditional Rules framework. Such rules are useful to manipulate email messages or to include texts dynamically, if all conditions defined by the rules are met. With this plugin you can add custom rules to verify.


Parameters

$return

Function where you'll return the file paths for the callback of the filter 'vikbooking_load_conditional_rules'

Example

The example below shows how to define two custom Conditional Rule driver files that will be installed in VikBooking.

<?php
/*
Plugin Name:  VBO Custom Conditional Rules
Plugin URI:   https://vikwp.com/plugin/vikbooking
Description:  Custom Conditional Rules for VikBooking.
Version:      1.0.0
Author:       E4J s.r.l.
Author URI:   https://vikwp.com
License:      GPL2
License URI:  https://www.gnu.org/licenses/gpl-2.0.html
Text Domain:  vbocustomcondrules
*/

// no direct access
defined('ABSPATH') or die('No script kiddies please!');

// register callback for filter "vikbooking_load_conditional_rules"
add_filter('vikbooking_load_conditional_rules', function($return)
{
    if (!$return)
    {
        // first plugin running
        $return = [];
    }

    /**
     * Since multiple plugins could add their own custom rules, it
     * is necessary to always merge the paths to the rule files of
     * this plugin to any previous report that may have already been injected.
     * Simply define an array of absolute paths to the PHP files that declare
     * the needed class by VikBooking to load a rule driver.
     * 
     * In this example, we are telling VikBooking to load two custom Conditional Rules.
     */
    return array_merge($return, [
        // WP_PLUGIN_DIR         = absolute server path to plugin's directory
        // vbocustomcondrules    = the name of this custom plugin
        // rules                 = a private/internal folder of this custom plugin
        // custom_one.php        = the class file that declares the PMS Report
        WP_PLUGIN_DIR . '/vbocustomcondrules/rules/custom_one.php',

        // custom_two.php        = the class file that declares the PMS Report
        WP_PLUGIN_DIR . '/vbocustomcondrules/rules/custom_two.php',
    ]);
});

By using the code above inside the main plugin file (vbocustomcondrules.php) you can load as many custom conditional text rules as you want. The tree below shows the files and folders structure of the custom plugin you can install on your WordPress website:

  • Folder: vbocustomcondrules
    • File: vbocustomcondrules.php
    • Folder: rules
      • File: custom_one.php
      • File: custom_two.php

At this point you need to actually code your custom Conditional Rule driver files to let them declare the options and verify the compliance for each reservation. We strongly recommend to check the source code of some existing conditional text rule driver files to understand the logic.

Ultimo aggiornamento: 2024-02-22
Utile?
100% delle persone lo ha trovato utile.