| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: AutomatorWP - WPCode |
| 4 |
* Plugin URI: https://automatorwp.com/add-ons/wpcode/ |
| 5 |
* Description: Connect AutomatorWP with WPCode. |
| 6 |
* Version: 1.0.0 |
| 7 |
* Author: AutomatorWP |
| 8 |
* Author URI: https://automatorwp.com/ |
| 9 |
* Text Domain: automatorwp-wpcode |
| 10 |
* Domain Path: /languages/ |
| 11 |
* Requires at least: 4.4 |
| 12 |
* Tested up to: 6.2 |
| 13 |
* License: GNU AGPL v3.0 (http://www.gnu.org/licenses/agpl.txt) |
| 14 |
* |
| 15 |
* @package AutomatorWP\WPCode |
| 16 |
* @author AutomatorWP |
| 17 |
* @copyright Copyright (c) AutomatorWP |
| 18 |
*/ |
| 19 |
|
| 20 |
final class AutomatorWP_Integration_WPCode { |
| 21 |
|
| 22 |
/** |
| 23 |
* @var AutomatorWP_Integration_WPCode $instance The one true AutomatorWP_Integration_WPCode |
| 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_WPCode self::$instance The one true AutomatorWP_Integration_WPCode |
| 34 |
*/ |
| 35 |
public static function instance() { |
| 36 |
if( !self::$instance ) { |
| 37 |
self::$instance = new AutomatorWP_Integration_WPCode(); |
| 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_WPCODE_VER', '1.0.0' ); |
| 62 |
|
| 63 |
// Plugin file |
| 64 |
define( 'AUTOMATORWP_WPCODE_FILE', __FILE__ ); |
| 65 |
|
| 66 |
// Plugin path |
| 67 |
define( 'AUTOMATORWP_WPCODE_DIR', plugin_dir_path( __FILE__ ) ); |
| 68 |
|
| 69 |
// Plugin URL |
| 70 |
define( 'AUTOMATORWP_WPCODE_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_WPCODE_DIR . 'includes/ajax-functions.php'; |
| 86 |
require_once AUTOMATORWP_WPCODE_DIR . 'includes/functions.php'; |
| 87 |
|
| 88 |
// Actions |
| 89 |
require_once AUTOMATORWP_WPCODE_DIR . 'includes/actions/activate-snippet.php'; |
| 90 |
require_once AUTOMATORWP_WPCODE_DIR . 'includes/actions/deactivate-snippet.php'; |
| 91 |
|
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Setup plugin hooks |
| 97 |
* |
| 98 |
* @access private |
| 99 |
* @since 1.0.0 |
| 100 |
* @return void |
| 101 |
*/ |
| 102 |
private function hooks() { |
| 103 |
|
| 104 |
add_action( 'automatorwp_init', array( $this, 'register_integration' ) ); |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Registers this integration |
| 110 |
* |
| 111 |
* @since 1.0.0 |
| 112 |
*/ |
| 113 |
function register_integration() { |
| 114 |
|
| 115 |
automatorwp_register_integration( 'wpcode', array( |
| 116 |
'label' => 'WPCode', |
| 117 |
'icon' => AUTOMATORWP_WPCODE_URL . 'assets/wpcode.svg', |
| 118 |
) ); |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Check if there are all plugin requirements |
| 124 |
* |
| 125 |
* @since 1.0.0 |
| 126 |
* |
| 127 |
* @return bool True if installation meets all requirements |
| 128 |
*/ |
| 129 |
private function meets_requirements() { |
| 130 |
|
| 131 |
if ( ! class_exists( 'AutomatorWP' ) ) { |
| 132 |
return false; |
| 133 |
} |
| 134 |
|
| 135 |
if ( ! class_exists('WPCode_Premium') ) { // PRO version |
| 136 |
if ( ! class_exists( 'WPCode' ) ) { |
| 137 |
return false; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
return true; |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Check if the pro version of this integration is installed |
| 147 |
* |
| 148 |
* @since 1.0.0 |
| 149 |
* |
| 150 |
* @return bool True if pro version installed |
| 151 |
*/ |
| 152 |
private function pro_installed() { |
| 153 |
|
| 154 |
if ( ! class_exists( 'AutomatorWP_WPCode' ) ) { |
| 155 |
return false; |
| 156 |
} |
| 157 |
|
| 158 |
return true; |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* The main function responsible for returning the one true AutomatorWP_Integration_WPCode instance to functions everywhere |
| 166 |
* |
| 167 |
* @since 1.0.0 |
| 168 |
* @return \AutomatorWP_Integration_WPCode The one true AutomatorWP_Integration_WPCode |
| 169 |
*/ |
| 170 |
function AutomatorWP_Integration_WPCode() { |
| 171 |
return AutomatorWP_Integration_WPCode::instance(); |
| 172 |
} |
| 173 |
add_action( 'automatorwp_pre_init', 'AutomatorWP_Integration_WPCode' ); |
| 174 |
|