-
Notifications
You must be signed in to change notification settings - Fork 1
/
easy-amazon-links.php
168 lines (143 loc) · 4.91 KB
/
easy-amazon-links.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
<?php
/**
* Plugin Name: Easy Amazon Links
* Plugin URI: https://wordpress.org/plugins/easy-amazon-links/
* Description: Easily create text affiliate links for Amazon Associates
* Version: 1.0.1
* Author: flowdee
* Author URI: https://coder.flowdee.de
* Text Domain: easy-amazon-links
*
* @package EAL
* @author flowdee
* @copyright Copyright (c) flowdee
*
* Copyright (c) 2017 - flowdee ( https://twitter.com/flowdee )
*/
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) exit;
if( ! class_exists( 'Easy_Amazon_Links' ) ) {
/**
* Main Easy_Amazon_Links class
*
* @since 1.0.0
*/
class Easy_Amazon_Links {
/**
* @var Easy_Amazon_Links $instance The one true Easy_Amazon_Links
* @since 1.0.0
*/
private static $instance;
/**
* Get active instance
*
* @access public
* @since 1.0.0
* @return object self::$instance The one true Easy_Amazon_Links
*/
public static function instance() {
if( !self::$instance ) {
self::$instance = new Easy_Amazon_Links();
self::$instance->setup_constants();
self::$instance->includes();
self::$instance->load_textdomain();
}
return self::$instance;
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0.0
* @return void
*/
private function setup_constants() {
// Plugin name
define( 'EAL_NAME', 'Easy Amazon Links' );
// Plugin version
define( 'EAL_VER', '1.0.1' );
// Plugin path
define( 'EAL_DIR', plugin_dir_path( __FILE__ ) );
// Plugin URL
define( 'EAL_URL', plugin_dir_url( __FILE__ ) );
// Plugin Settings
define ( 'EAL_SETTINGS_PAGE_SLUG', 'easy-amazon-links' );
}
/**
* Include necessary files
*
* @access private
* @since 1.0.0
* @return void
*/
private function includes() {
// Basic
require_once EAL_DIR . 'includes/helper.php';
require_once EAL_DIR . 'includes/scripts.php';
// Admin only
if ( is_admin() ) {
require_once EAL_DIR . 'includes/admin/plugins.php';
require_once EAL_DIR . 'includes/admin/class.settings.php';
require_once EAL_DIR . 'includes/admin/editor.php';
}
// Anything else
require_once EAL_DIR . 'includes/functions.php';
require_once EAL_DIR . 'includes/hooks.php';
require_once EAL_DIR . 'includes/shortcodes.php';
}
/**
* Internationalization
*
* @access public
* @since 1.0.0
* @return void
*/
public function load_textdomain() {
// Set filter for language directory
$lang_dir = EAL_DIR . '/languages/';
$lang_dir = apply_filters( 'eal_languages_directory', $lang_dir );
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), 'easy-amazon-links' );
$mofile = sprintf( '%1$s-%2$s.mo', 'easy-amazon-links', $locale );
// Setup paths to current locale file
$mofile_local = $lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/easy-amazon-links/' . $mofile;
if( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/easy-amazon-links/ folder
load_textdomain( 'easy-amazon-links', $mofile_global );
} elseif( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/easy-amazon-links/languages/ folder
load_textdomain( 'easy-amazon-links', $mofile_local );
} else {
// Load the default language files
load_plugin_textdomain( 'easy-amazon-links', false, $lang_dir );
}
}
}
} // End if class_exists check
/**
* The main function responsible for returning the one true Easy_Amazon_Links
* instance to functions everywhere
*
* @since 1.0.0
* @return \Easy_Amazon_Links The one true Easy_Amazon_Links
*
*/
function eal_load() {
return Easy_Amazon_Links::instance();
}
add_action( 'plugins_loaded', 'eal_load' );
/**
* The activation hook
*/
function eal_activation() {
// Create your tables here
}
register_activation_hook( __FILE__, 'eal_activation' );
/**
* The deactivation hook
*/
function eal_deactivation() {
// Cleanup your tables, transients etc. here
}
register_deactivation_hook(__FILE__, 'eal_deactivation');