Skip to content
Snippets Groups Projects
conditional-form-actions-for-acfe.php 4.48 KiB
Newer Older
  • Learn to ignore specific revisions
  • Christian Wach's avatar
    Christian Wach committed
     * Conditional Form Actions for ACFE
     *
    
     * Plugin Name:       Conditional Form Actions for ACFE
     * Description:       Provides some ACF Extended Form Actions that have a Conditional Field.
     * Plugin URI:        https://develop.tadpole.cc/plugins/conditional-form-actions-for-acfe
     * Update URI:        https://develop.tadpole.cc/plugins/conditional-form-actions-for-acfe
    
     * Version:           0.2.1a
    
     * Author:            Tadpole Collective
     * Author URI:        https://tadpole.cc/
     * License:           GPLv2 or later
     * License URI:       https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
     * Requires at least: 6.0
     * Requires PHP:      7.4
     * Text Domain:       conditional-form-actions-for-acfe
     * Domain Path:       /languages
    
     *
     * @package Conditional_Form_Actions_For_ACFE
    
     * @link    https://develop.tadpole.cc/plugins/conditional-form-actions-for-acfe
     * @license GPL v2 or later
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 2 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
    
    Christian Wach's avatar
    Christian Wach committed
    
    // Set plugin version here.
    
    define( 'CFAFA_VERSION', '0.2.1a' );
    
    Christian Wach's avatar
    Christian Wach committed
    
    // Store reference to this file.
    if ( ! defined( 'CFAFA_FILE' ) ) {
    	define( 'CFAFA_FILE', __FILE__ );
    }
    
    // Store URL to this plugin's directory.
    if ( ! defined( 'CFAFA_URL' ) ) {
    	define( 'CFAFA_URL', plugin_dir_url( CFAFA_FILE ) );
    }
    
    // Store PATH to this plugin's directory.
    if ( ! defined( 'CFAFA_PATH' ) ) {
    	define( 'CFAFA_PATH', plugin_dir_path( CFAFA_FILE ) );
    }
    
    /**
     * Conditional Form Actions for ACFE Class.
     *
     * A class that encapsulates this plugin's functionality.
     *
     * @since 0.1
     */
    class Conditional_Form_Actions_For_ACFE {
    
    	/**
    	 * ACF Extended object.
    	 *
    	 * @since 0.1
    	 * @access public
    
    	 * @var CFAFA_ACFE
    
    Christian Wach's avatar
    Christian Wach committed
    	 */
    	public $acfe;
    
    	/**
    	 * Initialises this object.
    	 *
    	 * @since 0.1
    	 */
    	public function __construct() {
    
    		// Always load translations.
    
    		add_action( 'init', [ $this, 'translation' ] );
    
    Christian Wach's avatar
    Christian Wach committed
    
    
    		// Initialise when plugins have been loaded.
    		add_action( 'plugins_loaded', [ $this, 'initialise' ] );
    
    Christian Wach's avatar
    Christian Wach committed
    
    	}
    
    	/**
    	 * Initialise this plugin.
    	 *
    	 * @since 0.1
    	 */
    	public function initialise() {
    
    		// Only do this once.
    		static $done;
    
    Christian Wach's avatar
    Christian Wach committed
    		if ( isset( $done ) && true === $done ) {
    
    Christian Wach's avatar
    Christian Wach committed
    			return;
    		}
    
    		// Include files.
    		$this->include_files();
    
    		// Set up objects and references.
    		$this->setup_objects();
    
    		/**
    		 * Broadcast that this plugin is loaded.
    		 *
    		 * @since 0.1
    		 */
    		do_action( 'cfafa/loaded' );
    
    		// We're done.
    		$done = true;
    
    	}
    
    	/**
    	 * Enable translation.
    	 *
    	 * @since 0.1
    	 */
    	public function translation() {
    
    		// Load translations.
    		load_plugin_textdomain(
    
    			'conditional-form-actions-for-acfe',
    
    Christian Wach's avatar
    Christian Wach committed
    			false, // Deprecated argument.
    
    			dirname( plugin_basename( CFAFA_FILE ) ) . '/languages/'
    
    Christian Wach's avatar
    Christian Wach committed
    		);
    
    	}
    
    	/**
    	 * Include files.
    	 *
    	 * @since 0.1
    	 */
    	public function include_files() {
    
    		// Load our class files.
    
    Christian Wach's avatar
    Christian Wach committed
    		require CFAFA_PATH . 'includes/class-cfafa-acfe.php';
    
    Christian Wach's avatar
    Christian Wach committed
    
    	}
    
    	/**
    	 * Set up this plugin's objects.
    	 *
    	 * @since 0.1
    	 */
    	public function setup_objects() {
    
    		// Initialise objects.
    		$this->acfe = new CFAFA_ACFE( $this );
    
    	}
    
    
    Christian Wach's avatar
    Christian Wach committed
    }
    
    Christian Wach's avatar
    Christian Wach committed
    
    /**
     * Load plugin if not yet loaded and return reference.
     *
     * @since 0.1
     *
     * @return Conditional_Form_Actions_For_ACFE $plugin The plugin reference.
     */
    function cfafa() {
    
    	static $plugin;
    
    	// Instantiate plugin if not yet instantiated.
    	if ( ! isset( $plugin ) ) {
    		$plugin = new Conditional_Form_Actions_For_ACFE();
    	}
    
    	// --<
    	return $plugin;
    
    }
    
    // Load immediately.
    cfafa();
    
    /**
     * Performs plugin activation tasks.
     *
     * @since 0.1
     */
    function cfafa_activate() {
    
    	/**
    	 * Broadcast that this plugin has been activated.
    	 *
    	 * @since 0.1
    	 */
    	do_action( 'cfafa/activated' );
    
    }
    
    // Activation.
    register_activation_hook( __FILE__, 'cfafa_activate' );
    
    /**
     * Performs plugin deactivation tasks.
     *
     * @since 0.1
     */
    function cfafa_deactivated() {
    
    	/**
    	 * Broadcast that this plugin has been deactivated.
    	 *
    	 * @since 0.1
    	 */
    	do_action( 'cfafa/deactivated' );
    
    }
    
    // Deactivation.
    register_deactivation_hook( __FILE__, 'cfafa_deactivated' );
    
    
    /*
     * Uninstall uses the 'uninstall.php' method.
     * @see http://codex.wordpress.org/Function_Reference/register_uninstall_hook
     */