-
Notifications
You must be signed in to change notification settings - Fork 4
/
bea-post-views-counter.php
107 lines (87 loc) · 3.1 KB
/
bea-post-views-counter.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
<?php
/*
Plugin Name: BEA Post Views Counter
Version: 0.6.9
Plugin URI: https://github.com/beapi/bea-post-views-counter
Description: Counts views for any post type. Compatible with static cache plugins, with an asynchronous AJAX implementation.
Author: BE API Technical team
Author URI: http://www.beapi.fr
Domain Path: languages
Network: false
Text Domain: bea-post-views-counter
Provides: bea-post-views-counter
TODO:
Import from Post view counter
Append total counter at the end of post
----
Copyright 2023 BE API Technical team ([email protected])
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// don't load directly
if ( !defined('ABSPATH') )
die('-1');
// Plugin tables
global $wpdb;
$wpdb->tables[] = 'post_views_counter';
$wpdb->post_views_counter = $wpdb->prefix . 'post_views_counter';
// Plugin constants
define('BEA_PVC_VERSION', '0.6.9');
// Plugin URL and PATH
define('BEA_PVC_URL', plugin_dir_url ( __FILE__ ));
define('BEA_PVC_DIR', plugin_dir_path( __FILE__ ));
// Function for easy load files
function _bea_pb_load_files($dir, $files, $prefix = '') {
foreach ($files as $file) {
if ( is_file($dir . $prefix . $file . ".php") ) {
require_once($dir . $prefix . $file . ".php");
}
}
}
// Plugin functions
_bea_pb_load_files(BEA_PVC_DIR . 'functions/', array('api', 'template'));
// Plugin client classes
_bea_pb_load_files(BEA_PVC_DIR . 'classes/', array('main', 'plugin', 'widget', 'shortcode', 'counter', 'query'));
// Plugin admin classes
if (is_admin()) {
_bea_pb_load_files(BEA_PVC_DIR . 'classes/admin/', array('main', 'settings'));
// Load class for API settings
if ( !class_exists('WeDevs_Settings_API') ) {
require_once(BEA_PVC_DIR.'librairies/wordpress-settings-api-class/class.settings-api.php');
}
}
// Plugin activate/desactive hooks
register_activation_hook(__FILE__, array('BEA_PVC_Plugin', 'activate'));
register_deactivation_hook(__FILE__, array('BEA_PVC_Plugin', 'deactivate'));
add_action('plugins_loaded', 'init_bea_pvc_plugin');
function init_bea_pvc_plugin() {
// Init session
$current_options = get_option('bea-pvc-main');
if ( isset($current_options['session']) && $current_options['session'] == 'on' ) {
if (!isset($_SESSION)) {
session_start();
}
}
// Client
new BEA_PVC_Main();
new BEA_PVC_Query();
new BEA_PVC_Shortcode();
// Admin
if (is_admin()) {
new BEA_PVC_Admin_Main();
new BEA_PVC_Admin_Settings();
}
// Widget
add_action( 'widgets_init', function () {
return register_widget("BEA_PVC_Widget");
} );
}