| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: GamiPress - WP WeForms integration |
| 4 |
* Plugin URI: https://wordpress.org/plugins/gamipress-weforms-integration/ |
| 5 |
* Description: Connect GamiPress with WP WeForms. |
| 6 |
* Version: 1.0.0 |
| 7 |
* Author: GamiPress |
| 8 |
* Author URI: https://gamipress.com/ |
| 9 |
* Text Domain: gamipress-weforms-integration |
| 10 |
* Domain Path: /languages/ |
| 11 |
* Requires at least: 4.4 |
| 12 |
* Tested up to: 6.6 |
| 13 |
* License: GNU AGPL v3.0 (http://www.gnu.org/licenses/agpl.txt) |
| 14 |
* |
| 15 |
* @package GamiPress\WeForms |
| 16 |
* @author GamiPress |
| 17 |
* @copyright Copyright (c) GamiPress |
| 18 |
*/ |
| 19 |
|
| 20 |
final class GamiPress_Integration_WeForms { |
| 21 |
|
| 22 |
/** |
| 23 |
* @var GamiPress_Integration_WeForms $instance The one true GamiPress_Integration_WeForms |
| 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 GamiPress_Integration_WeForms self::$instance The one true GamiPress_Integration_WeForms |
| 34 |
*/ |
| 35 |
public static function instance() { |
| 36 |
if( !self::$instance ) { |
| 37 |
self::$instance = new GamiPress_Integration_WeForms(); |
| 38 |
self::$instance->constants(); |
| 39 |
self::$instance->includes(); |
| 40 |
self::$instance->hooks(); |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
return self::$instance; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Setup plugin constants |
| 49 |
* |
| 50 |
* @access private |
| 51 |
* @since 1.0.0 |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
private function constants() { |
| 55 |
// Plugin version |
| 56 |
define( 'GAMIPRESS_WEFORMS_VER', '1.0.0' ); |
| 57 |
|
| 58 |
// Plugin path |
| 59 |
define( 'GAMIPRESS_WEFORMS_DIR', plugin_dir_path( __FILE__ ) ); |
| 60 |
|
| 61 |
// Plugin URL |
| 62 |
define( 'GAMIPRESS_WEFORMS_URL', plugin_dir_url( __FILE__ ) ); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Include plugin files |
| 67 |
* |
| 68 |
* @access private |
| 69 |
* @since 1.0.0 |
| 70 |
* @return void |
| 71 |
*/ |
| 72 |
private function includes() { |
| 73 |
|
| 74 |
if( $this->meets_requirements() ) { |
| 75 |
|
| 76 |
require_once GAMIPRESS_WEFORMS_DIR . 'includes/admin.php'; |
| 77 |
require_once GAMIPRESS_WEFORMS_DIR . 'includes/functions.php'; |
| 78 |
require_once GAMIPRESS_WEFORMS_DIR . 'includes/listeners.php'; |
| 79 |
require_once GAMIPRESS_WEFORMS_DIR . 'includes/requirements.php'; |
| 80 |
require_once GAMIPRESS_WEFORMS_DIR . 'includes/rules-engine.php'; |
| 81 |
require_once GAMIPRESS_WEFORMS_DIR . 'includes/scripts.php'; |
| 82 |
require_once GAMIPRESS_WEFORMS_DIR . 'includes/triggers.php'; |
| 83 |
|
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Setup plugin hooks |
| 89 |
* |
| 90 |
* @access private |
| 91 |
* @since 1.0.0 |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
private function hooks() { |
| 95 |
// Setup our activation and deactivation hooks |
| 96 |
register_activation_hook( __FILE__, array( $this, 'activate' ) ); |
| 97 |
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); |
| 98 |
|
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Activation hook for the plugin. |
| 104 |
* |
| 105 |
* @since 1.0.0 |
| 106 |
*/ |
| 107 |
function activate() { |
| 108 |
|
| 109 |
if( $this->meets_requirements() ) { |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Deactivation hook for the plugin. |
| 117 |
* |
| 118 |
* @since 1.0.0 |
| 119 |
*/ |
| 120 |
function deactivate() { |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Check if there are all plugin requirements |
| 126 |
* |
| 127 |
* @since 1.0.0 |
| 128 |
* |
| 129 |
* @return bool True if installation meets all requirements |
| 130 |
*/ |
| 131 |
private function meets_requirements() { |
| 132 |
|
| 133 |
if ( ! class_exists( 'GamiPress' ) ) { |
| 134 |
return false; |
| 135 |
} |
| 136 |
|
| 137 |
// Requirements on multisite install |
| 138 |
if( is_multisite() && is_main_site() && function_exists('gamipress_is_network_wide_active') && gamipress_is_network_wide_active() ) { |
| 139 |
|
| 140 |
// On main site, need to check if integrated plugin is installed on any sub site to load all configuration files |
| 141 |
if( gamipress_is_plugin_active_on_network( 'weforms/weforms.php' ) ) { |
| 142 |
return true; |
| 143 |
} |
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
if ( ! class_exists( 'WeForms' ) ) { |
| 148 |
return false; |
| 149 |
} |
| 150 |
|
| 151 |
return true; |
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* The main function responsible for returning the one true GamiPress_Integration_WeForms instance to functions everywhere |
| 159 |
* |
| 160 |
* @since 1.0.0 |
| 161 |
* @return \GamiPress_Integration_WeForms The one true GamiPress_Integration_WeForms |
| 162 |
*/ |
| 163 |
function GamiPress_Integration_WeForms() { |
| 164 |
return GamiPress_Integration_WeForms::instance(); |
| 165 |
} |
| 166 |
add_action( 'gamipress_pre_init', 'GamiPress_Integration_WeForms' ); |
| 167 |
|