| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Gutenify |
| 4 |
* Plugin URI: http://gutenify.com/?page=plugin |
| 5 |
* Description: WordPress plugin with great collection of page building WordPress blocks for the new Gutenberg WordPress block editor. |
| 6 |
* Version: 0.0.3 |
| 7 |
* Author: Gutenify |
| 8 |
* Author URI: http://gutenify.com/?page=author |
| 9 |
* Requires at least: 5.3.2 |
| 10 |
* Requires PHP: 5.5 |
| 11 |
* Tested up to: 5.3.2 |
| 12 |
* |
| 13 |
* Text Domain: gutenify |
| 14 |
* Domain Path: /i18n/languages/ |
| 15 |
* |
| 16 |
* @package Gutenify |
| 17 |
* @category Core |
| 18 |
* @author Gutenify |
| 19 |
*/ |
| 20 |
|
| 21 |
|
| 22 |
// Exit if accessed directly. |
| 23 |
if ( ! defined( 'ABSPATH' ) ) { |
| 24 |
exit; |
| 25 |
} |
| 26 |
|
| 27 |
if ( ! class_exists( 'Gutenify' ) ) : |
| 28 |
|
| 29 |
/** |
| 30 |
* Main Gutenify Class (singleton). |
| 31 |
* |
| 32 |
* @since 0.0.1 |
| 33 |
*/ |
| 34 |
final class Gutenify { |
| 35 |
|
| 36 |
/** |
| 37 |
* Gutenify version. |
| 38 |
* |
| 39 |
* @var string |
| 40 |
*/ |
| 41 |
public $version = '0.0.3'; |
| 42 |
|
| 43 |
/** |
| 44 |
* The single instance of the class. |
| 45 |
* |
| 46 |
* @var Gutenify |
| 47 |
* @since 0.0.1 |
| 48 |
*/ |
| 49 |
protected static $_instance = null; |
| 50 |
|
| 51 |
/** |
| 52 |
* Main Gutenify Instance. |
| 53 |
* Ensures only one instance of Gutenify is loaded or can be loaded. |
| 54 |
* |
| 55 |
* @static |
| 56 |
* @see Gutenify() |
| 57 |
* @return Gutenify - Main instance. |
| 58 |
*/ |
| 59 |
public static function instance() { |
| 60 |
if ( is_null( self::$_instance ) ) { |
| 61 |
self::$_instance = new self(); |
| 62 |
} |
| 63 |
return self::$_instance; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Gutenify Constructor. |
| 68 |
*/ |
| 69 |
function __construct() { |
| 70 |
$this->define_constants(); |
| 71 |
$this->includes(); |
| 72 |
$this->init_hooks(); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Define Gutenify Constants. |
| 77 |
*/ |
| 78 |
private function define_constants() { |
| 79 |
$this->define( 'GUTENIFY_PLUGIN_FILE', __FILE__ ); |
| 80 |
$this->define( 'GUTENIFY_ABSPATH', dirname( __FILE__ ) . '/' ); |
| 81 |
$this->define( 'GUTENIFY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 82 |
$this->define( 'GUTENIFY_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
| 83 |
$this->define( 'GUTENIFY_VERSION', $this->version ); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Hook into actions and filters. |
| 88 |
* |
| 89 |
* @since 0.0.1 |
| 90 |
* @return void |
| 91 |
*/ |
| 92 |
private function init_hooks() { |
| 93 |
Gutenify_Blocks_Loader::init(); |
| 94 |
add_action( 'init', array( $this, 'set_script_translations' ) ); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Include required core files used in admin and on the frontend. |
| 99 |
* |
| 100 |
* @return void |
| 101 |
*/ |
| 102 |
function includes() { |
| 103 |
include_once('inc/class-helpers.php'); |
| 104 |
include_once('inc/class-blocks-loader.php'); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Define constants. |
| 109 |
*/ |
| 110 |
public function define( $name, $value ) { |
| 111 |
if ( ! defined( $name ) ) { |
| 112 |
define( $name, $value ); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* What type of request is this? |
| 118 |
* |
| 119 |
* @param string $type admin, ajax, cron or frontend. |
| 120 |
* @return bool |
| 121 |
*/ |
| 122 |
private function is_request( $type ) { |
| 123 |
switch ( $type ) { |
| 124 |
case 'admin' : |
| 125 |
return is_admin(); |
| 126 |
case 'ajax' : |
| 127 |
return defined( 'DOING_AJAX' ); |
| 128 |
case 'cron' : |
| 129 |
return defined( 'DOING_CRON' ); |
| 130 |
case 'frontend' : |
| 131 |
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
function set_script_translations() { |
| 136 |
wp_set_script_translations( 'gutenify-script', 'gutenify', plugin_dir_path( __FILE__ ) . 'i18n/languages' ); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
} |
| 141 |
endif; |
| 142 |
/** |
| 143 |
* Main instance of gutenify. |
| 144 |
* |
| 145 |
* Returns the main instance of Gutenify to prevent the need to use globals. |
| 146 |
* |
| 147 |
* @since 0.0.1 |
| 148 |
* @return gutenify |
| 149 |
*/ |
| 150 |
function gutenify() { |
| 151 |
return Gutenify::instance(); |
| 152 |
} |
| 153 |
|
| 154 |
// Start gutenify. |
| 155 |
gutenify(); |
| 156 |
|