Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('jnews_after_account_nav',function (){
- $user = wp_get_current_user(get_current_user_id());
- if (user_can( $user, "subscriber" )){
- ?>
- <div class="frontend-submit-button" id="change-to-author">
- <a class="button" href="#"><i class="fa fa-file-text-o"></i>Switch to Author</a>
- </div>
- <script>
- (function ($){
- element = document.getElementById('change-to-author')
- element.addEventListener('click',function (e){
- e.preventDefault()
- $.ajax({
- url:jnews_ajax_url,
- method:'post',
- dataType: 'json',
- data: {
- action:'subscribe_to_author',
- user:<?=$user->ID?>,
- },
- }).success(function (data){
- console.log('success')
- window.location.reload()
- })
- })
- })(jQuery)
- </script>
- <?php
- } elseif (user_can( $user, "author" )) {
- ?>
- <div class="frontend-submit-button" id="change-to-author">
- <a class="button" href="#"><i class="fa fa-file-text-o"></i>Subscriber</a>
- </div>
- <script>
- (function ($){
- element = document.getElementById('change-to-author')
- element.addEventListener('click',function (e){
- e.preventDefault()
- $.ajax({
- url:jnews_ajax_url,
- method:'post',
- dataType: 'json',
- data: {
- action:'author_to_subscriber',
- user:<?=$user->ID?>,
- },
- }).success(function (data){
- console.log('success')
- window.location.reload()
- })
- })
- })(jQuery)
- </script>
- <?php
- }
- });
- add_action('jnews_ajax_subscribe_to_author',function (){
- $user = wp_get_current_user($_REQUEST['user']);
- $user->remove_role('subscriber');
- $user->add_role('author');
- wp_send_json('');
- });
- add_action('jnews_ajax_author_to_subscriber',function (){
- $user = wp_get_current_user($_REQUEST['user']);
- $user->remove_role('author');
- $user->add_role('subscriber');
- wp_send_json('');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement