-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpets.php
executable file
·230 lines (201 loc) · 6.02 KB
/
pets.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/**
* Plugin Name: Pets
* Plugin URI: http://petswp.com
* Description: Manage Pets and Animal Shelters
* Author: ibenic
* Author URI: https://ibenic.com
* Text Domain: pets
* Domain Path: /languages
* Version: 1.4.0
*
* @package Pets
*/
namespace Pets;
if( ! defined( 'ABSPATH' ) ) {
return;
}
if ( ! function_exists( 'pet_fs' ) ) {
// Create a helper function for easy SDK access.
function pet_fs() {
global $pet_fs;
if ( ! isset( $pet_fs ) ) {
// Include Freemius SDK.
require_once dirname( __FILE__ ) . '/freemius/start.php';
$pet_fs = fs_dynamic_init( array(
'id' => '2120',
'slug' => 'pets',
'type' => 'plugin',
'public_key' => 'pk_d54c88070fcd447603456014d42ba',
'is_premium' => true,
'has_addons' => false,
'has_paid_plans' => true,
'menu' => array(
'slug' => 'edit.php?post_type=pets',
'contact' => false,
'support' => false,
),
) );
}
return $pet_fs;
}
// Init Freemius.
pet_fs();
// Signal that SDK was initiated.
do_action( 'pet_fs_loaded' );
}
final class Pets {
/**
* Version
* @var string
*/
public $version = '1.4.0';
/**
* Run everything
* @return void
*/
public function run() {
$this->define_constants();
$this->includes();
$this->init();
$this->hooks();
}
public function define_constants() {
define( 'PETS_PATH', plugin_dir_path( __FILE__ ) );
define( 'PETS_URL', plugin_dir_url( __FILE__ ) );
define( 'PETS_VERSION', $this->version );
}
/**
* Including files
* @return void
*/
private function includes() {
include_once 'includes/class-pets-cpt.php';
include_once 'includes/class-pets-fields.php';
include_once 'includes/class-pets-cache.php';
include_once 'includes/class-pets-search.php';
include_once 'includes/class-pets-shortcodes.php';
include_once 'includes/class-pets-pet.php';
include_once 'includes/class-pets-widgets.php';
include_once 'includes/class-pets-installer.php';
include_once 'includes/class-pets-missing.php';
include_once 'includes/class-pets-add.php';
include_once 'includes/class-pets-emails.php';
// Settings Class.
include_once 'includes/admin/settings/class-settings.php';
include_once 'includes/functions-settings.php';
include_once 'includes/widgets/class-widgets-single-pet.php';
include_once 'includes/widgets/class-widgets-search.php';
include_once 'includes/widgets/class-widgets-add-missing.php';
include_once 'includes/widgets/class-widgets-add.php';
include_once 'includes/functions-templates.php';
include_once 'includes/functions-upgrades.php';
/**
* Database Classes
*/
include_once 'includes/abstracts/class-db.php';
include_once 'includes/db/class-pets-fields.php';
include_once 'includes/db/class-pets-sections.php';
if( is_admin() ) {
include_once 'includes/admin/class-admin.php';
} else {
include_once 'includes/class-pets-template.php';
}
}
/**
* Include integrations
*/
public function include_integrations() {
include_once 'includes/integrations/class-give.php';
include_once 'includes/integrations/class-petfinder.php';
}
/**
* Activation method.
*/
public function activation() {
$installer = new Pets_Installer();
$installer->install();
$cpt = new CPT();
$cpt->init();
flush_rewrite_rules();
}
/**
* Initialize classes, settings.
* @return void
*/
public function init() {
\register_activation_hook( __FILE__, array( $this, 'activation' ) );
if( is_admin() ) {
$admin = new Admin\Admin();
$admin->load();
} else {
$template = new Pets_Template();
$template->init();
new Shortcodes();
new Missing();
new Add();
New Pets_Emails();
}
}
/**
* Action/Filters Hooks
* @return void
*/
private function hooks() {
$cpt = new CPT();
$widgets = new Widgets();
/**
* Actions
*/
add_action( 'init', array( $cpt, 'init' ) );
add_action( 'init', array( $this, 'check_versions' ) );
add_action( 'init', array( $this, 'add_image_sizes' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue' ) );
add_action( 'plugins_loaded', array( $this, 'include_integrations') );
add_action( 'pets_before_loop', array( '\Pets\Search', 'add_form' ) );
add_action( 'pre_get_posts', array( '\Pets\Search', 'pets_per_page' ) );
add_action( 'pre_get_posts', array( '\Pets\Search', 'pets_search_fields' ) );
add_action( 'pre_get_posts', array( '\Pets\Search', 'pets_search_filter_with_fields' ) );
add_action( 'widgets_init', array( $widgets, 'register_widgets' ) );
/**
* Filters
*/
add_filter( 'post_updated_messages', array( $cpt, 'update_messages' ) );
}
/**
* Enqueueing Scripts and Styles for Public.
*/
public function enqueue() {
wp_enqueue_style( 'pets-css', PETS_URL . '/assets/css/public/pets.css', '', '' );
wp_enqueue_style( 'pets-fontawesome', 'https://use.fontawesome.com/releases/v5.1.0/css/all.css' );
}
/**
* Define Image sizes.
*/
public function add_image_sizes() {
if ( ! \has_image_size( 'pets-thumbnail' ) ) {
\add_image_size( 'pets-thumbnail', 360 );
}
}
/**
* Checking for version, updating if necessary
* @return void
*/
public function check_versions() {
if ( ! defined( 'IFRAME_REQUEST' ) && get_option( 'pets_version', '0.2.0' ) !== $this->version ) {
$installer = new Pets_Installer();
$installer->install();
$installer->update( get_option( 'pets_version', '0.2.0' ) );
do_action( 'pets_updated' );
}
}
}
/**
* Starting our plugin
* @return void
*/
function run() {
$pets = new Pets();
$pets->run();
}
run();