forked from piffpaffpuff/woocommerce-delivery-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-delivery-notes.php
201 lines (174 loc) · 6.43 KB
/
woocommerce-delivery-notes.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
/**
* Print invoices & delivery notes for WooCommerce orders.
*
* Plugin Name: WooCommerce Print Invoice & Delivery Note
* Plugin URI: https://github.com/piffpaffpuff/woocommerce-delivery-notes
* Description: Print Invoices & Delivery Notes for WooCommerce Orders.
* Version: 3.4.2
* Author: Triggvy Gunderson
* Author URI: https://github.com/piffpaffpuff/woocommerce-delivery-notes
* License: GPLv3 or later
* License URI: http://www.opensource.org/licenses/gpl-license.php
* Text Domain: woocommerce-delivery-notes
* Domain Path: /languages/
*
* Copyright 2014 Triggvy Gunderson, David Decker
*
* This file is part of WooCommerce Print Invoices & Delivery Notes,
* a plugin for WordPress.
*
* WooCommerce Print Invoice & Delivery Note is free software:
* You can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option)
* any later version.
*
* WooCommerce Print Invoice & Delivery Note is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WordPress. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Exit if accessed directly
*/
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Base class
*/
if ( !class_exists( 'WooCommerce_Delivery_Notes' ) ) {
final class WooCommerce_Delivery_Notes {
public static $plugin_version;
public static $plugin_prefix;
public static $plugin_url;
public static $plugin_path;
public static $plugin_basefile;
public static $plugin_basefile_path;
public $writepanel;
public $settings;
public $print;
public $theme;
/**
* Constructor
*/
public function __construct() {
// Define the constants
self::$plugin_version = '3.4.2';
self::$plugin_prefix = 'wcdn_';
self::$plugin_basefile_path = __FILE__;
self::$plugin_basefile = plugin_basename( self::$plugin_basefile_path );
self::$plugin_url = plugin_dir_url( self::$plugin_basefile );
self::$plugin_path = trailingslashit( dirname( self::$plugin_basefile_path ) );
// Set hooks and wait for WooCommerce to load
add_action( 'plugins_loaded', array( $this, 'localise' ) );
add_action( 'woocommerce_init', array( $this, 'load' ) );
}
/**
* Include the main plugin classes and functions
*/
public function include_classes() {
include_once( 'includes/class-wcdn-print.php' );
include_once( 'includes/class-wcdn-settings.php' );
include_once( 'includes/class-wcdn-writepanel.php' );
include_once( 'includes/class-wcdn-theme.php' );
}
/**
* Function used to init Template Functions.
* This makes them pluggable by plugins and themes.
*/
public function include_template_functions() {
include_once( 'includes/wcdn-template-functions.php' );
include_once( 'includes/wcdn-template-hooks.php' );
}
/**
* Load the localisation
*/
public function localise() {
load_plugin_textdomain( 'woocommerce-delivery-notes', false, dirname( self::$plugin_basefile ) . '/languages/' );
}
/**
* Include the main plugin classes and functions
*/
public function load() {
// WooCommerce activation required
if ( $this->is_woocommerce_activated() ) {
// Include the classes
$this->include_classes();
// Create the instances
$this->print = new WooCommerce_Delivery_Notes_Print();
$this->settings = new WooCommerce_Delivery_Notes_Settings();
$this->writepanel = new WooCommerce_Delivery_Notes_Writepanel();
$this->theme = new WooCommerce_Delivery_Notes_Theme();
// Load the hooks for the template after the objetcs.
// Like this the template has full access to all objects.
add_action( 'admin_init', array( $this, 'load_admin_hooks' ) );
add_action( 'init', array( $this, 'include_template_functions' ) );
}
}
/**
* Load the admin hooks
*/
public function load_admin_hooks() {
$this->update();
add_filter( 'plugin_action_links_' . self::$plugin_basefile, array( $this, 'add_settings_link') );
}
/**
* Install ord update the default settings
*/
public function update() {
// Define default settings
if( get_option( self::$plugin_prefix . 'version' ) != self::$plugin_version ) {
// Print slug for the frontend
$endpoint = get_option( self::$plugin_prefix . 'print_order_page_endpoint' );
if( !$endpoint ) {
update_option( self::$plugin_prefix . 'print_order_page_endpoint', 'print-order' );
// Flush the rewrite rules when a fresh install
set_transient( self::$plugin_prefix . 'flush_rewrite_rules', true );
}
// Template types
$invoice = get_option( self::$plugin_prefix . 'template_type_invoice' );
if( !$invoice ) {
update_option( self::$plugin_prefix . 'template_type_invoice', 1 );
}
$delivery_note = get_option( self::$plugin_prefix . 'template_type_delivery_note' );
if( !$delivery_note ) {
update_option( self::$plugin_prefix . 'template_type_delivery_note', 1 );
}
// Update the settings to the latest version
update_option( self::$plugin_prefix . 'version', self::$plugin_version );
}
}
/**
* Add settings link to plugin page
*/
public function add_settings_link( $links ) {
$url = esc_url( admin_url( add_query_arg( array( 'page' => 'wc-settings', 'tab' => $this->settings->tab_name ), 'admin.php' ) ) );
$settings = sprintf( '<a href="%s" title="%s">%s</a>' , $url, __( 'Go to the settings page', 'woocommerce-delivery-notes' ) , __( 'Settings', 'woocommerce-delivery-notes' ) );
array_unshift( $links, $settings );
return $links;
}
/**
* Check if woocommerce is activated
*/
public function is_woocommerce_activated() {
$blog_plugins = get_option( 'active_plugins', array() );
$site_plugins = get_site_option( 'active_sitewide_plugins', array() );
$woocommerce_basename = plugin_basename( WC_PLUGIN_FILE );
if( ( in_array( $woocommerce_basename, $blog_plugins ) || isset( $site_plugins[$woocommerce_basename] ) ) && version_compare( WC_VERSION, '2.1', '>=' )) {
return true;
} else {
return false;
}
}
}
}
/**
* Instance of the plugin
*/
$wcdn = new WooCommerce_Delivery_Notes();
?>