-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-ajax.php
182 lines (162 loc) · 4.49 KB
/
wp-ajax.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
<?php
/**
* Plugin Name: WP AJAX
* Plugin URI: https://github.com/chintalp0910
* Description: How to work with wordpress AJAX
* Version: 1.0.0
* Author: ChintalP
* Author URI: https://github.com/chintalp0910
* Text Domain: wp-ajax
* Domain Path: languages
*
* @package WP AJAX
* @category Core
* @author ChintalP
*/
/**
* Basic plugin definitions
*
* @package WP AJAX
* @since 1.0.0
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Basic Plugin Definitions
*
* @package WP AJAX
* @since 1.0.0
*/
if( !defined( 'WP_AJAX_VERSION' ) ) {
define( 'WP_AJAX_VERSION', '1.0.0' ); //version of plugin
}
if( !defined( 'WP_AJAX_DIR' ) ) {
define( 'WP_AJAX_DIR', dirname( __FILE__ ) ); // plugin dir
}
if( !defined( 'WP_AJAX_ADMIN' ) ) {
define( 'WP_AJAX_ADMIN', WP_AJAX_DIR . '/includes/admin' ); // plugin admin dir
}
if( !defined( 'WP_AJAX_URL' ) ) {
define( 'WP_AJAX_URL', plugin_dir_url( __FILE__ ) ); // plugin url
}
if( !defined( 'WP_AJAX_IMG_URL' ) ) {
define( 'WP_AJAX_IMG_URL', WP_AJAX_URL . 'includes/images' ); // plugin image url
}
if( !defined( 'WP_AJAX_TEXT_DOMAIN' ) ) {
define( 'WP_AJAX_TEXT_DOMAIN', 'wp-ajax' ); // text domain for doing language translation
}
//metabox prefix
if( !defined( 'WP_AJAX_META_PREFIX' )) {
define( 'WP_AJAX_META_PREFIX', '_wp_ajax_' );
}
if( !defined( 'WP_AJAX_PLUGIN_BASENAME' ) ) {
define( 'WP_AJAX_PLUGIN_BASENAME', basename( WP_AJAX_DIR ) ); //Plugin base name
}
/**
* Load Text Domain
*
* This gets the plugin ready for translation.
*
* @package WP AJAX
* @since 1.0.0
*/
function wp_ajax_load_textdomain() {
// Set filter for plugin's languages directory
$wp_ajax_lang_dir = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
$wp_ajax_lang_dir = apply_filters( 'wp_ajax_languages_directory', $wp_ajax_lang_dir );
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), 'wp-ajax' );
$mofile = sprintf( '%1$s-%2$s.mo', 'wp-ajax', $locale );
// Setup paths to current locale file
$mofile_local = $wp_ajax_lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/' . WP_AJAX_PLUGIN_BASENAME . '/' . $mofile;
if ( file_exists( $mofile_global ) ) { // Look in global /wp-content/languages/wp-ajax folder
load_textdomain( 'wp-ajax', $mofile_global );
} elseif ( file_exists( $mofile_local ) ) { // Look in local /wp-content/plugins/wp-ajax/languages/ folder
load_textdomain( 'wp-ajax', $mofile_local );
} else { // Load the default language files
load_plugin_textdomain( 'wp-ajax', false, $wp_ajax_lang_dir );
}
}
/**
* Activation hook
*
* Register plugin activation hook.
*
* @package WP AJAX
* @since 1.0.0
*/
register_activation_hook( __FILE__, 'wp_ajax_install' );
/**
* Deactivation hook
*
* Register plugin deactivation hook.
*
* @package WP AJAX
* @since 1.0.0
*/
register_deactivation_hook( __FILE__, 'wp_ajax_uninstall' );
/**
* Plugin Setup Activation hook call back
*
* Initial setup of the plugin setting default options
* and database tables creations.
*
* @package WP AJAX
* @since 1.0.0
*/
function wp_ajax_install() {
global $wpdb;
}
/**
* Plugin Setup (On Deactivation)
*
* Does the drop tables in the database and
* delete plugin options.
*
* @package WP AJAX
* @since 1.0.0
*/
function wp_ajax_uninstall() {
global $wpdb;
}
/**
* Load Plugin
*
* Handles to load plugin after
* dependent plugin is loaded
* successfully
*
* @package WP AJAX
* @since 1.0.0
*/
function wp_ajax_plugin_loaded() {
// load first plugin text domain
wp_ajax_load_textdomain();
}
//add action to load plugin
add_action( 'plugins_loaded', 'wp_ajax_plugin_loaded' );
/**
* Initialize all global variables
*
* @package WP AJAX
* @since 1.0.0
*/
global $wp_ajax_scripts,$wp_ajax_renderer,$wp_ajax_public;
/**
* Includes
*
* Includes all the needed files for plugin
*
* @package WP AJAX
* @since 1.0.0
*/
require_once( WP_AJAX_DIR . '/includes/class-wp-ajax-scripts.php');
$wp_ajax_scripts = new Wp_Ajax_Scripts();
$wp_ajax_scripts->add_hooks();
require_once( WP_AJAX_DIR . '/includes/class-wp-ajax-renderer.php');
$wp_ajax_renderer = new Wp_Ajax_Renderer();
//Public Pages Class for handling front side functionalities
require_once( WP_AJAX_DIR . '/includes/class-wp-ajax-public-pages.php' );
$wp_ajax_public = new Wp_Ajax_Public_Pages();
$wp_ajax_public->add_hooks();