GochiSiyan

Subcriber to Author

Feb 7th, 2021
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. add_action('jnews_after_account_nav',function (){
  2. $user = wp_get_current_user(get_current_user_id());
  3. if (user_can( $user, "subscriber" )){
  4. ?>
  5. <div class="frontend-submit-button" id="change-to-author">
  6. <a class="button" href="#"><i class="fa fa-file-text-o"></i>Switch to Author</a>
  7. </div>
  8. <script>
  9. (function ($){
  10. element = document.getElementById('change-to-author')
  11. element.addEventListener('click',function (e){
  12. e.preventDefault()
  13. $.ajax({
  14. url:jnews_ajax_url,
  15. method:'post',
  16. dataType: 'json',
  17. data: {
  18. action:'subscribe_to_author',
  19. user:<?=$user->ID?>,
  20. },
  21. }).success(function (data){
  22. window.location.reload()
  23. })
  24. })
  25. })(jQuery)
  26. </script>
  27. <?php
  28. }
  29. });
  30.  
  31. add_action('jnews_ajax_subscribe_to_author',function (){
  32. $user = wp_get_current_user($_REQUEST['user']);
  33. $user->remove_role('subscriber');
  34. $user->add_role('author');
  35. wp_send_json();
  36. });
Advertisement
Add Comment
Please, Sign In to add comment