Advertisement
GochiSiyan

First load action.php

Oct 3rd, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. <?php
  2. /**
  3. * @author : Jegtheme
  4. */
  5. namespace JNews\Ajax;
  6.  
  7. /**
  8. * Class JNews Website Fragment
  9. */
  10. Class FirstLoadAction
  11. {
  12. public function build_response($action) {
  13. $response = apply_filters('jnews_do_first_load_action', array(), $action);
  14.  
  15. wp_send_json($response);
  16. }
  17.  
  18. public function account_nonce()
  19. {
  20. return wp_create_nonce('jnews_nonce');
  21. }
  22.  
  23. public function top_bar_account()
  24. {
  25. if(!is_user_logged_in()) {
  26.  
  27. $output = "<li><a href=\"" . wp_login_url() . "\" class=\"jeg_popuplink\"><i class=\"fa fa-lock\"></i> " . jnews_return_translation('Login', 'jnews', 'login') . "</a></li>";
  28.  
  29. if(get_option( 'users_can_register' )) {
  30. $output .= "<li><a href=\"" . wp_registration_url() . "\" class=\"jeg_popuplink\"><i class=\"fa fa-user\"></i> " . jnews_return_translation('Register', 'jnews', 'register') . "</a></li>";
  31. }
  32.  
  33. } else {
  34. $current_user = wp_get_current_user();
  35. $endpoint = \JNews\AccountPage::getInstance()->get_endpoint();
  36. $account_url = apply_filters('jnews_top_bar_account_url', esc_url( home_url_multilang($endpoint['account']['slug']) ) );
  37.  
  38. $output =
  39. "<li>
  40. <a href=\"" . $account_url . "\" class=\"logged\">
  41. " . get_avatar( $current_user->ID, '22', '', $current_user->display_name, array( 'class' => 'img-rounded' ) ) . jeg_get_author_name( $current_user->ID ) . "
  42. </a>
  43. " . $this->dropdown() . "
  44. </li>";
  45. }
  46.  
  47. return $output;
  48. }
  49.  
  50. public function mobile_account()
  51. {
  52. $cartoutput = "";
  53.  
  54. if(function_exists('is_woocommerce')) {
  55. $cartoutput = "<li class=\"cart\"><a href=\"" . wc_get_cart_url() . "\"><i class=\"fa fa-shopping-cart\"></i> " . jnews_return_translation('Cart', 'jnews', 'cart') . "</a></li>";
  56. }
  57.  
  58. if(!is_user_logged_in()) {
  59.  
  60. $registeroutput = "";
  61.  
  62. if(get_option( 'users_can_register' )) {
  63. $registeroutput = "<li><a href=\"#jeg_registerform\" class=\"jeg_popuplink\"><i class=\"fa fa-user\"></i> " . jnews_return_translation('Sign Up', 'jnews', 'sign_up') . "</a></li>";
  64. }
  65.  
  66. $output =
  67. "<ul class=\"jeg_accountlink\">
  68. <li><a href=\"#jeg_loginform\" class=\"jeg_popuplink\"><i class=\"fa fa-lock\"></i> " . jnews_return_translation('Login', 'jnews', 'login') . "</a></li>
  69. {$registeroutput}
  70. {$cartoutput}
  71. </ul>";
  72.  
  73. } else {
  74.  
  75. $current_user = wp_get_current_user();
  76. $endpoint = \JNews\AccountPage::getInstance()->get_endpoint();
  77. $account_url = apply_filters('jnews_mobile_account_url', esc_url( home_url('/' . $endpoint['account']['slug']) ) );
  78.  
  79. $output =
  80. "<div class=\"profile_box\">
  81. <a href=\"{$account_url}\" class=\"profile_img\">" . get_avatar( $current_user->user_email, 55 ) . "</a>
  82. <h3><a href=\"{$account_url}\" class=\"profile_name\">" . esc_html(get_the_author_meta('display_name', get_current_user_id())) . "</a></h3>
  83. <ul class=\"profile_links\">
  84. <li><a href=\"{$account_url}\"><i class=\"fa fa-user\"></i> " . jnews_return_translation('Account', 'jnews', 'account') . "</a></li>
  85. {$cartoutput}
  86. <li><a href=\"" . esc_url(wp_logout_url()) . "\" class=\"logout\"><i class=\"fa fa-sign-out\"></i> " . jnews_return_translation('Logout', 'jnews', 'logout') . "</a></li>
  87. </ul>
  88. </div>";
  89.  
  90. }
  91.  
  92. return apply_filters( 'jnews_mobile_account_element', $output ) ;
  93. }
  94.  
  95. public function dropdown()
  96. {
  97. $dropdown_html = '';
  98. $dropdown = array();
  99.  
  100. if(function_exists('is_woocommerce'))
  101. {
  102. $dropdown['order'] = array(
  103. 'text' => jnews_return_translation('Order List', 'jnews', 'order_list'),
  104. 'url' => wc_get_account_endpoint_url('orders')
  105. );
  106.  
  107. $dropdown['edit-account'] = array(
  108. 'text' => jnews_return_translation('Edit Account', 'jnews', 'edit_profile'),
  109. 'url' => wc_get_account_endpoint_url('edit-account')
  110. );
  111. }
  112.  
  113. $dropdown['logout'] = array(
  114. 'text' => jnews_return_translation('Logout', 'jnews', 'logout'),
  115. 'url' => wp_logout_url()
  116. );
  117.  
  118. $dropdown = apply_filters('jnews_dropdown_link', $dropdown);
  119.  
  120. foreach($dropdown as $key => $value)
  121. {
  122. $dropdown_html .= "<li><a href=\"{$value['url']}\" class=\"{$key}\">{$value['text']}</a></li>";
  123. }
  124.  
  125. return "<ul>" . $dropdown_html . "</ul>";
  126. }
  127.  
  128. public function social_login()
  129. {
  130. $output = "<h3>" . jnews_return_translation('Welcome Back!', 'jnews', 'welcome_back') . "</h3>";
  131. return defined('JNEWS_SOCIAL_LOGIN') ? $output .= apply_filters( 'jnews_social_login', '', 'login' ) : $output;
  132. }
  133.  
  134. public function social_register()
  135. {
  136. $output = "<h3>" . jnews_return_translation('Create New Account!', 'jnews', 'create_new_account') . "</h3>";
  137. return defined('JNEWS_SOCIAL_LOGIN') ? $output .= apply_filters( 'jnews_social_login', '', 'register' ) : $output;
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement