Skip to content

Commit

Permalink
Better manage of actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ice committed Oct 24, 2016
1 parent d9789ea commit dba5e3a
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 54 deletions.
2 changes: 1 addition & 1 deletion includes/js/nsp_dashboard.js
@@ -1,7 +1,7 @@
(function($) {
$( "#nsp_error-dashboard").hide();
$.post(nsp_externalAjax_dashboard.ajaxurl, {
action : 'nsp_external_dashboard',
action : 'nsp_external',
VAR: "dashboard",
KEY: nsp_externalAjax_dashboard.Key,
PAR: "",
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_alltotalvisits.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_alltotalvisits.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_alltotalvisits.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_monthtotalpageviews.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_monthtotalpageviews.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_monthtotalpageviews.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_mvisits.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_mvisits.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_mvisits.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_thistotalvisits.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_thistotalvisits.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_thistotalvisits.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_todaytotalpageviews.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_todaytotalpageviews.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_todaytotalpageviews.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_totalpageviews.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_totalpageviews.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_totalpageviews.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_totalvisits.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_totalvisits.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_totalvisits.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_visits.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_visits.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_visits.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_widget_topposts.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_widget_topposts.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_widget_topposts.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_wvisits.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_wvisits.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_wvisits.VAR,
Expand Down
2 changes: 1 addition & 1 deletion includes/js/nsp_variables_yvisits.js
Expand Up @@ -4,7 +4,7 @@ jQuery.post(
// here we declare the parameters to send along with the request
// this means the following action hooks will be fired:
// wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit
action : 'nsp_variables_'+nsp_variablesAjax_yvisits.VAR,
action : 'nsp_variables',

// other parameters can be added along with "action"
VAR : nsp_variablesAjax_yvisits.VAR,
Expand Down
48 changes: 6 additions & 42 deletions newstatpress.php
Expand Up @@ -256,51 +256,15 @@ function nsp_load_textdomain() {
require ('includes/api/external.php');
require ('includes/nsp_core.php');

// register actions for ajax variables API
add_action( 'wp_ajax_nsp_variables', 'nsp_variablesAjax' );
add_action( 'wp_ajax_nopriv_nsp_variables', 'nsp_variablesAjax' ); // need this to serve non logged in users

nsp_RegisterVarAjaxAction(); // register actions for ajax variables API
nsp_RegisterExtenalApiAjaxAction(); // register actions for ajax external API
// register actions for ajax external API
add_action( 'wp_ajax_nsp_external', 'nsp_externalApiAjax' );
add_action( 'wp_ajax_nopriv_nsp_external', 'nsp_externalApiAjax' ); // need this to serve non logged in users


/**
* Register the actions for ajax variable API
*/
function nsp_RegisterExtenalApiAjaxAction() {
$vars_list=array('version',
'wpversion',
'dashboard',
'overview'
);

# look for $vars_list
foreach($vars_list as $var) {
add_action( 'wp_ajax_nsp_external_'.$var, 'nsp_externalApiAjax' );
add_action( 'wp_ajax_nopriv_nsp_external_'.$var, 'nsp_externalApiAjax' ); // need this to serve non logged in users
}
}

/**
* Register the actions for ajax variable API
*/
function nsp_RegisterVarAjaxAction() {
$vars_list=array('visits',
'yvisits',
'mvisits',
'wvisits',
'totalvisits',
'totalpageviews',
'todaytotalpageviews',
'alltotalvisits',
'monthtotalpageviews',
'thistotalvisits'
);

# look for $vars_list
foreach($vars_list as $var) {
add_action( 'wp_ajax_nsp_variables_'.$var, 'nsp_variablesAjax' );
add_action( 'wp_ajax_nopriv_nsp_variables_'.$var, 'nsp_variablesAjax' ); // need this to serve non logged in users
}
}

/*************************************
* Add pages for NewStatPress plugin *
*************************************/
Expand Down

0 comments on commit dba5e3a

Please sign in to comment.