[Plugin: Front-End Users] Ajax for users with restricted roles
-
To give ajax access to user with restricted access to admin:
Edits In
front_end_users.php
>restrict_admin_access
1) Add the name of your function to valid ajax actions array
$valid_admin_ajax_actions = array( 'user_avatar_add_photo', 'my_ajax_function' );
2) Change the 1st clause of the
if
statement to allow for non-root installations$_SERVER['SCRIPT_FILENAME'] == $_SERVER['DOCUMENT_ROOT'] . substr( $_SERVER['SCRIPT_NAME'], 0, -24 ) . '/wp-admin/admin-ajax.php'
3) Change the 2nd clause of the
if
statement to accept $_POST( isset($_GET['action']) && in_array($_GET['action'], $valid_admin_ajax_actions) ) || ( isset($_POST['action']) && in_array($_POST['action'], $valid_admin_ajax_actions) )
So the whole function should look like this:
public function restrict_admin_access() { if (is_admin()) { $valid_admin_ajax_actions = array( 'user_avatar_add_photo', 'my_ajax_function' ); if ( $_SERVER['SCRIPT_FILENAME'] == $_SERVER['DOCUMENT_ROOT'] . substr( $_SERVER['SCRIPT_NAME'], 0, -24 ) . '/wp-admin/admin-ajax.php' && ( ( isset($_GET['action']) && in_array($_GET['action'], $valid_admin_ajax_actions) ) || ( isset($_POST['action']) && in_array($_POST['action'], $valid_admin_ajax_actions) ) )) { return true; } if (!$this->is_logged_in()) { $this->render_page('not-logged-in'); } else if (!$this->has_admin_access()) { $this->render_404(); } } }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘[Plugin: Front-End Users] Ajax for users with restricted roles’ is closed to new replies.