1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: if ( ! mautic_is_activate_woocommerce() ) {
14: $mauticommerce_err = new Mauticommerce_Err();
15: $mauticommerce_err->activation_fail();
16: return false;
17: }
18: define( 'MAUTICOMMERCE_PATH', plugin_dir_path( __FILE__ ) );
19: define( 'MAUTICOMMERCE_URL', plugin_dir_url( __FILE__ ) );
20: define( 'MAUTICOMMERCE_ROOT', __FILE__ );
21:
22: require_once 'inc/class.admin.php';
23: require_once 'inc/class.order.php';
24:
25: $mauticommerce = Mauticommerce::get_instance();
26: $mauticommerce->init();
27:
28: class Mauticommerce {
29: private static $instance;
30: private static $text_domain;
31:
32: private function __construct() {
33: }
34:
35: public static function get_instance() {
36: if ( ! isset( self::$instance ) ) {
37: $c = __CLASS__;
38: self::$instance = new $c();
39: }
40: return self::$instance;
41: }
42:
43: 44: 45: 46: 47: 48:
49: public static function text_domain() {
50: static $text_domain;
51:
52: if ( ! $text_domain ) {
53: $data = get_file_data( MAUTICOMMERCE_ROOT , array( 'text_domain' => 'Text Domain' ) );
54: $text_domain = $data['text_domain'];
55: }
56: return $text_domain;
57: }
58:
59: public function init() {
60: $admin = Mauticommerce_Admin::get_instance();
61: add_action( 'admin_menu', array( $admin, 'add_admin_menu' ) );
62: add_action( 'admin_init', array( $admin, 'settings_init' ) );
63: $order = Mauticommerce_Order::get_instance();
64: add_action( 'woocommerce_checkout_update_order_meta', array( $order, 'subscribe_to_mautic' ) );
65: }
66: }
67:
68: class Mauticommerce_Err {
69: 70: 71: 72: 73:
74: public function activation_fail() {
75: $msg = array(
76: __( 'MautiCommerce Need "WooCommerce" Plugin.' , 'mauticommerce' ),
77: __( 'Please Activate it.' , 'mauticommerce' ),
78: );
79: $e = new WP_Error( 'MautiCommerce Activation Error', $msg );
80: $this->show_error_message( $e );
81: add_action( 'admin_notices', array( $this, 'admin_notices' ) );
82: return $e;
83: }
84:
85: 86: 87: 88: 89:
90: public function admin_notices() {
91: if ( $message_list = get_transient( 'mautic-admin-errors' ) ) {
92: $this->show_notice_html( $message_list );
93: }
94: }
95:
96: 97: 98: 99: 100: 101:
102: public function show_error_message( $msg ) {
103: if ( ! is_wp_error( $msg ) ) {
104: $e = new WP_Error();
105: $e->add( 'error' , $msg , 'mautic-admin-errors' );
106: } else {
107: $e = $msg;
108: }
109: set_transient( 'mautic-admin-errors' , $e->get_error_messages(), 10 );
110: }
111:
112: 113: 114: 115: 116: 117:
118: public function show_notice_html( $message_list ) {
119: foreach ( $message_list as $key => $messages ) {
120: $html = "<div class='error'><ul>";
121: foreach ( (array) $messages as $key => $message ) {
122: $html .= "<li>{$message}</li>";
123: }
124: $html .= '</ul></div>';
125: }
126: echo $html;
127: }
128: }
129:
130: 131: 132: 133: 134: 135:
136: function mautic_is_activate_woocommerce() {
137: $active_plugins = get_option( 'active_plugins' );
138: $plugin = 'woocommerce/woocommerce.php';
139: if ( ! array_search( $plugin, $active_plugins ) && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) {
140: return false;
141: } else {
142: return true;
143: }
144: }
145: