| @@ -1,0 +1,195 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Plugin Name: AutomatorWP - JetFormBuilder integration | |
| 4 | + * Plugin URI: https://automatorwp.com/add-ons/jetformbuilder/ | |
| 5 | + * Description: Connect AutomatorWP with JetFormBuilder. | |
| 6 | + * Version: 1.0.0 | |
| 7 | + * Author: AutomatorWP | |
| 8 | + * Author URI: https://automatorwp.com/ | |
| 9 | + * Text Domain: automatorwp-integration | |
| 10 | + * Domain Path: /languages/ | |
| 11 | + * Requires at least: 4.4 | |
| 12 | + * Tested up to: 5.8 | |
| 13 | + * License: GNU AGPL v3.0 (http://www.gnu.org/licenses/agpl.txt) | |
| 14 | + * | |
| 15 | + * @package AutomatorWP\JetFormBuilder | |
| 16 | + * @author AutomatorWP | |
| 17 | + * @copyright Copyright (c) AutomatorWP | |
| 18 | + */ | |
| 19 | + | |
| 20 | +final class AutomatorWP_Integration_JetFormBuilder { | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * @var AutomatorWP_Integration_JetFormBuilder $instance The one true AutomatorWP_Integration_JetFormBuilder | |
| 24 | + * @since 1.0.0 | |
| 25 | + */ | |
| 26 | + private static $instance; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Get active instance | |
| 30 | + * | |
| 31 | + * @access public | |
| 32 | + * @since 1.0.0 | |
| 33 | + * @return AutomatorWP_Integration_JetFormBuilder self::$instance The one true AutomatorWP_Integration_JetFormBuilder | |
| 34 | + */ | |
| 35 | + public static function instance() { | |
| 36 | + if( !self::$instance ) { | |
| 37 | + self::$instance = new AutomatorWP_Integration_JetFormBuilder(); | |
| 38 | + | |
| 39 | + if( ! self::$instance->pro_installed() ) { | |
| 40 | + | |
| 41 | + self::$instance->constants(); | |
| 42 | + self::$instance->includes(); | |
| 43 | + | |
| 44 | + } | |
| 45 | + | |
| 46 | + self::$instance->hooks(); | |
| 47 | + } | |
| 48 | + | |
| 49 | + return self::$instance; | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Setup plugin constants | |
| 54 | + * | |
| 55 | + * @access private | |
| 56 | + * @since 1.0.0 | |
| 57 | + * @return void | |
| 58 | + */ | |
| 59 | + private function constants() { | |
| 60 | + // Plugin version | |
| 61 | + define( 'AUTOMATORWP_JETFORMBUILDER_VER', '1.0.0' ); | |
| 62 | + | |
| 63 | + // Plugin file | |
| 64 | + define( 'AUTOMATORWP_JETFORMBUILDER_FILE', __FILE__ ); | |
| 65 | + | |
| 66 | + // Plugin path | |
| 67 | + define( 'AUTOMATORWP_JETFORMBUILDER_DIR', plugin_dir_path( __FILE__ ) ); | |
| 68 | + | |
| 69 | + // Plugin URL | |
| 70 | + define( 'AUTOMATORWP_JETFORMBUILDER_URL', plugin_dir_url( __FILE__ ) ); | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Include plugin files | |
| 75 | + * | |
| 76 | + * @access private | |
| 77 | + * @since 1.0.0 | |
| 78 | + * @return void | |
| 79 | + */ | |
| 80 | + private function includes() { | |
| 81 | + | |
| 82 | + if( $this->meets_requirements() ) { | |
| 83 | + | |
| 84 | + // Includes | |
| 85 | + require_once AUTOMATORWP_JETFORMBUILDER_DIR . 'includes/functions.php'; | |
| 86 | + | |
| 87 | + // Triggers | |
| 88 | + require_once AUTOMATORWP_JETFORMBUILDER_DIR . 'includes/triggers/submit-form.php'; | |
| 89 | + require_once AUTOMATORWP_JETFORMBUILDER_DIR . 'includes/triggers/anonymous-submit-form.php'; | |
| 90 | + | |
| 91 | + } | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Setup plugin hooks | |
| 96 | + * | |
| 97 | + * @access private | |
| 98 | + * @since 1.0.0 | |
| 99 | + * @return void | |
| 100 | + */ | |
| 101 | + private function hooks() { | |
| 102 | + | |
| 103 | + add_action( 'automatorwp_init', array( $this, 'register_integration' ) ); | |
| 104 | + | |
| 105 | + // Setup our activation and deactivation hooks | |
| 106 | + register_activation_hook( __FILE__, array( $this, 'activate' ) ); | |
| 107 | + register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Registers this integration | |
| 112 | + * | |
| 113 | + * @since 1.0.0 | |
| 114 | + */ | |
| 115 | + function register_integration() { | |
| 116 | + | |
| 117 | + automatorwp_register_integration( 'jetformbuilder', array( | |
| 118 | + 'label' => 'JetFormBuilder', | |
| 119 | + 'icon' => AUTOMATORWP_JETFORMBUILDER_URL . 'assets/jetformbuilder.svg', | |
| 120 | + ) ); | |
| 121 | + | |
| 122 | + } | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * Activation hook for the plugin. | |
| 126 | + * | |
| 127 | + * @since 1.0.0 | |
| 128 | + */ | |
| 129 | + function activate() { | |
| 130 | + | |
| 131 | + if( $this->meets_requirements() ) { | |
| 132 | + | |
| 133 | + } | |
| 134 | + | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * Deactivation hook for the plugin. | |
| 139 | + * | |
| 140 | + * @since 1.0.0 | |
| 141 | + */ | |
| 142 | + function deactivate() { | |
| 143 | + | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Check if there are all plugin requirements | |
| 148 | + * | |
| 149 | + * @since 1.0.0 | |
| 150 | + * | |
| 151 | + * @return bool True if installation meets all requirements | |
| 152 | + */ | |
| 153 | + private function meets_requirements() { | |
| 154 | + | |
| 155 | + if ( ! class_exists( 'AutomatorWP' ) ) { | |
| 156 | + return false; | |
| 157 | + } | |
| 158 | + | |
| 159 | + if ( ! function_exists( 'jet_form_builder_init' ) ) { | |
| 160 | + return false; | |
| 161 | + } | |
| 162 | + | |
| 163 | + return true; | |
| 164 | + | |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * Check if the pro version of this integration is installed | |
| 169 | + * | |
| 170 | + * @since 1.0.0 | |
| 171 | + * | |
| 172 | + * @return bool True if pro version installed | |
| 173 | + */ | |
| 174 | + private function pro_installed() { | |
| 175 | + | |
| 176 | + if ( ! class_exists( 'AutomatorWP_JetFormBuilder' ) ) { | |
| 177 | + return false; | |
| 178 | + } | |
| 179 | + | |
| 180 | + return true; | |
| 181 | + | |
| 182 | + } | |
| 183 | + | |
| 184 | +} | |
| 185 | + | |
| 186 | +/** | |
| 187 | + * The main function responsible for returning the one true AutomatorWP_Integration_JetFormBuilder instance to functions everywhere | |
| 188 | + * | |
| 189 | + * @since 1.0.0 | |
| 190 | + * @return \AutomatorWP_Integration_JetFormBuilder The one true AutomatorWP_Integration_JetFormBuilder | |
| 191 | + */ | |
| 192 | +function AutomatorWP_Integration_JetFormBuilder() { | |
| 193 | + return AutomatorWP_Integration_JetFormBuilder::instance(); | |
| 194 | +} | |
| 195 | +add_action( 'automatorwp_pre_init', 'AutomatorWP_Integration_JetFormBuilder' ); | |