-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoice-management.php
executable file
·201 lines (169 loc) · 7.96 KB
/
invoice-management.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* Plugin Name: Invoice Management for Woocommerce
* Plugin URI: -
* Description: Invoice Management for Woocommerce allows you to create purchase order with the products assigned to supplier,
* Version: 0.1.0
* Author: Empye
* Author URI: https://www.empye.org/
* Text Domain: inv_empye
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
*/
defined('ABSPATH') or die('Nope, not accessing this');
// Define INV_EMPYE_PLUGIN_FILE
if (!defined('INV_EMPYE_PLUGIN_FILE')) {
define('INV_EMPYE_PLUGIN_FILE', __FILE__);
}
if (!class_exists('INV_EMPYE_Plugin')) {
class INV_EMPYE_Plugin
{
// +-------------------+
// | CLASS CONSTRUCTOR |
// +-------------------+
public function __construct()
{
if (is_admin()) {
$this->define_constants(); // Define plugin constants
// Go out if Woocommerce is not installed…
if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
add_action('admin_notices', array($this, 'show_woocommerce_notice'));
add_filter( 'script_loader_src', array( $this, 'wpse47206_src') );
add_filter( 'style_loader_src', array( $this,'wpse47206_src') );
return;
}
$this->includes(); // Include plugin files
$this->init_hooks(); // Init hooks in Wordpress
$inv_notice = new INV_EMPYE_Notice();
$inv_notice->init();
}
}
public function wpse47206_src( $url )
{
// if( is_admin() ) return $url;
return str_replace( site_url(), '', $url );
}
// +---------------+
// | CLASS METHODS |
// +---------------+
/**
* Define plugin constants
*/
private function define_constants()
{
$this->define('INV_EMPYE_PLUGIN_NAME', 'Invoice Management for Woocommerce');
$this->define('INV_EMPYE_PLUGIN_VERSION', '0.2.0');
$this->define('INV_EMPYE_ABSPATH', dirname(INV_EMPYE_PLUGIN_FILE) . '/');
$this->define('INV_EMPYE_PLUGIN_BASENAME', plugin_basename(INV_EMPYE_PLUGIN_FILE));
$this->define('INV_EMPYE_PLUGIN_URL', __FILE__);
$this->define('INV_EMPYE_POST_TYPE', 'inv_supplier');
$this->define('INV_EMPYE_TEXT_DOMAIN', 'inv_empye');
}
/**
* Include any classes we need within admin.
*/
public function includes()
{
include_once(INV_EMPYE_ABSPATH . 'includes/supplier-post-type.class.php');
include_once(INV_EMPYE_ABSPATH . 'includes/admin/menu.class.php');
include_once(INV_EMPYE_ABSPATH . 'includes/admin/settings.class.php');
include_once(INV_EMPYE_ABSPATH . 'includes/admin/editor.class.php');
include_once(INV_EMPYE_ABSPATH . 'includes/admin/wc-products.class.php');
include_once(INV_EMPYE_ABSPATH . 'includes/admin/wc-product.class.php');
include_once(WP_PLUGIN_DIR . '/woocommerce/includes/data-stores/class-wc-data-store-wp.php');
include_once(WP_PLUGIN_DIR . '/woocommerce/includes/interfaces/class-wc-abstract-order-data-store-interface.php');
include_once(WP_PLUGIN_DIR . '/woocommerce/includes/interfaces/class-wc-object-data-store-interface.php');
include_once(WP_PLUGIN_DIR . '/woocommerce/includes/data-stores/abstract-wc-order-data-store-cpt.php');
include_once(WP_PLUGIN_DIR . '/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-items.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/wp-includes/class-wp-customize-manager.php');
include_once(INV_EMPYE_ABSPATH . 'includes/admin/class-wc-admin-meta-boxes.php');
include_once(INV_EMPYE_ABSPATH . 'includes/admin/meta-boxes/class-wc-meta-box-order-items.php');
include_once(INV_EMPYE_ABSPATH . 'includes/class-wc-ajax.php');
include_once(WP_PLUGIN_DIR . '/woocommerce/includes/interfaces/class-wc-order-data-store-interface.php');
include_once(WP_PLUGIN_DIR . '/woocommerce/includes/data-stores/abstract-wc-order-data-store-cpt.php');
include_once(INV_EMPYE_ABSPATH . 'includes/classes/class-wc-purchase-order-data-store-cpt.php');
include_once(INV_EMPYE_ABSPATH . 'includes/classes/supplier.class.php');
include_once(INV_EMPYE_ABSPATH . 'includes/classes/po.class.php');
include_once(INV_EMPYE_ABSPATH . 'includes/classes/notice.class.php');
}
/**
* Initiate plugin hooks in Wordpress
*/
public function init_hooks()
{
add_action('plugins_loaded', array($this, 'load_translation_files')); // Load translation files
add_action('admin_enqueue_scripts', array($this, 'admin_style'));
}
/**
* Load translation files located in the /languages folder
*/
public function load_translation_files()
{
load_plugin_textdomain(
INV_EMPYE_TEXT_DOMAIN,
false,
basename(dirname(__FILE__)) . '/languages'
);
}
public function admin_style()
{
// Enqueue style files
wp_enqueue_style(INV_EMPYE_POST_TYPE . '_datatables-style', plugins_url("/invoice-management-for-woocommerce/assets/css/jquery.dataTables.min.css"), '1.1', true);
wp_enqueue_style(INV_EMPYE_POST_TYPE . '_admin-style', plugins_url("/invoice-management-for-woocommerce/assets/css/" . INV_EMPYE_POST_TYPE . "_style.css"),'1.1', true );
// Enqueue script files
wp_enqueue_script(INV_EMPYE_POST_TYPE . '_datatables-script', plugins_url("/invoice-management-for-woocommerce/assets/js/jquery.dataTables.min.js"), array('jquery'), '1.1', true);
// wp_enqueue_script(INV_EMPYE_POST_TYPE . '_admin-script', __FILE__ . "/assets/js/" . INV_EMPYE_POST_TYPE . "_script.js", array(INV_EMPYE_POST_TYPE . '_datatables-script'));
wp_enqueue_script(
'wpo-wcpdf',
plugins_url('/invoice-management-for-woocommerce/assets/js/order-script.js'),
array( 'jquery' ),
'0.0.1'
);
wp_dequeue_script('wc-admin-order-meta-boxes');
wp_enqueue_script( 'wc-admin-order-meta-boxes', plugins_url('/invoice-management-for-woocommerce/assets/js/admin/meta-boxes-order.js'), array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), '0.1.0' );
wp_localize_script(
'wpo-wcpdf',
'wpo_wcpdf_ajax',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ), // URL to WordPress ajax handling page
'nonce' => wp_create_nonce('generate_wpo_wcpdf'),
'confirm_delete' => __( 'Are you sure you want to delete this document? This cannot be undone.', 'woocommerce-pdf-invoices-packing-slips'),
'confirm_regenerate' => __( 'Are you sure you want to regenerate this document? This will make the document reflect the most current settings (such as footer text, document name, etc.) rather than using historical settings.', 'woocommerce-pdf-invoices-packing-slips'),
)
);
}
// +---------+
// | NOTICES |
// +---------+
/**
* Show notice when Woocommerce is not installed
* @return string
*/
public function show_woocommerce_notice()
{
?>
<div class="notice notice-warning">
<p><?php _e("Woocommerce is not installed. Please install and active it to use <b>Invoice Management</b> plugin.", INV_EMPYE_TEXT_DOMAIN); ?></p>
</div>
<?php
}
// +--------+
// | OTHERS |
// +--------+
/**
* Define constant if not already set.
*
* @param string $name Constant name.
* @param string|bool $value Constant value.
*/
private function define($name, $value)
{
if (!defined($name)) {
define($name, $value);
}
}
}
}
// Launch plugin
new INV_EMPYE_Plugin();