Newer
Older
<?php
/**
* ACF Extended Class.
*
* Handles general "ACF Extended" functionality.
*
* @package Conditional_Form_Actions_For_ACFE
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* "ACF Extended" Class.
*
* A class that encapsulates ACF Extended functionality.
*
* @since 0.1
*/
class CFAFA_ACFE {
/**
* Plugin object.
*
* @since 0.1
* @access public
* @var Conditional_Form_Actions_For_ACFE
/**
* ACF Extended plugin version.
*
* @since 0.2.0
* @access public
* @var string
*/
public $acfe_version;
/**
* Constructor.
*
* @since 0.1
*
* @param object $plugin The plugin object.
*/
public function __construct( $plugin ) {
// Store references to objects.
$this->plugin = $plugin;
// Init when ACF class is loaded.
add_action( 'cfafa/loaded', [ $this, 'initialise' ] );
}
/**
* Initialise this object.
*
* @since 0.1
*/
public function initialise() {
// Only do this once.
static $done;
// Bail if ACFE is not present.
if ( ! defined( 'ACFE_VERSION' ) ) {
$done = true;
return;
}
// Store ACFE version.
$this->acfe_version = ACFE_VERSION;
// Register hooks.
$this->register_hooks();
/**
* Broadcast that this class is now loaded.
*
* @since 0.1
*/
do_action( 'cfafa/acfe/loaded' );
// We're done and loaded.
$done = true;
}
/**
* Register hooks.
*
* @since 0.1
*/
if ( version_compare( $this->acfe_version, '0.9', '>=' ) && version_compare( $this->acfe_version, '895', '<' ) ) {
add_action( 'acf/include_field_types', [ $this, 'register_form_actions_latest' ], 50 );
} else {
add_action( 'acfe/include_form_actions', [ $this, 'register_form_actions_legacy' ], 50 );
}
add_action( 'acfe/form/submit', [ $this, 'form_action_query_vars_clear' ] );
*/
}
/**
* Clear the Form Action Query Vars.
*
* This means we get a fresh set of Query Vars during the load process after
* a Form has been submitted.
*
* @since 0.1
*/
public function form_action_query_vars_clear() {
// Clear the array of Action results.
set_query_var( 'acfe_form_actions', [] );
}
/**
* Register Form Actions for ACFE version 0.9.x.
* @since 0.2.0
*/
public function register_form_actions_latest() {
// Include class files.
include CFAFA_PATH . 'includes/form-actions/acfe-0.9.x/class-cfafa-form-action-base.php';
include CFAFA_PATH . 'includes/form-actions/acfe-0.9.x/class-cfafa-form-action-redirect.php';
include CFAFA_PATH . 'includes/form-actions/acfe-0.9.x/class-cfafa-form-action-email.php';
// Register the Form Actions.
acfe_register_form_action_type( 'CFAFA_ACFE_Form_Action_Redirect' );
acfe_register_form_action_type( 'CFAFA_ACFE_Form_Action_Email' );
// Maybe add WooCommerce Product Action.
if ( function_exists( 'WC' ) ) {
include CFAFA_PATH . 'includes/form-actions/acfe-0.9.x/class-cfafa-form-action-product.php';
acfe_register_form_action_type( 'CFAFA_ACFE_Form_Action_Product' );
}
}
/**
* Register Form Actions for ACFE version 0.8.x.
*
* @since 0.2.0
public function register_form_actions_legacy() {
include CFAFA_PATH . 'includes/form-actions/acfe-0.8.x/class-cfafa-form-action-base.php';
include CFAFA_PATH . 'includes/form-actions/acfe-0.8.x/class-cfafa-form-action-redirect.php';
include CFAFA_PATH . 'includes/form-actions/acfe-0.8.x/class-cfafa-form-action-email.php';
// Instantiate the Form Actions.
new CFAFA_Form_Action_Redirect( $this );
new CFAFA_Form_Action_Email( $this );
// Maybe add WooCommerce Product Action.
if ( function_exists( 'WC' ) ) {
include CFAFA_PATH . 'includes/form-actions/acfe-0.8.x/class-cfafa-form-action-product.php';
new CFAFA_Form_Action_Product( $this );
}
}