-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasyAjax.php
37 lines (33 loc) · 1.15 KB
/
EasyAjax.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
<?php
/**
* Plugin Name: Easy Ajax
* Author: Giuseppe Mazzapica
* Version: 0.3.1
* Description: Makes ajax in WordPress ridiculously simple.
*/
/**
* @package EasyAjax
* @version 0.3.1
*/
if ( ! defined( 'ABSPATH' ) ) die();
if ( ! function_exists( 'easyajax' ) ) {
/**
* Setup and launch easyajax
*
* @param object $scope the object scope that will execute action if given
* @param string $where 'priv', 'nopriv' or 'both'. Limit actions to logged in users or not
* @param array $allowed list of allowed actions
* @return null
* @access public
*/
function easyajax( $scope = '', $where = '', $allowed = array () ) {
$action = ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ? 'admin_init' : 'wp_footer';
if ( did_action( $action ) ) return;
if ( ! defined( 'EASYAJAX_URL' ) ) define( 'EASYAJAX_URL', plugins_url( '/', __FILE__ ) );
if ( ! class_exists( 'EasyAjax\Front' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
}
$instance = new EasyAjax\Front( new \EasyAjax\Proxy );
$instance->setup( $scope, $where, $allowed );
}
}