Advertisement
Guest User

Untitled

a guest
Sep 14th, 2013
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.61 KB | None | 0 0
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2.  
  3. //restrict admin access
  4. function restrict_admin()
  5. {
  6.     if ( ! current_user_can( 'manage_options' ) && is_admin() && !current_user_can( 'administrator' ) && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) && strpos(strtolower($_SERVER['REQUEST_URI']), '/wp-admin') !== false) {
  7.         wp_redirect( site_url() );
  8.     }
  9. }
  10. add_action( 'admin_init', 'restrict_admin', 1 );
  11.  
  12. // init and display login
  13. function forest_init(){
  14.     global $pagenow,$edd_options;
  15.     switch ($pagenow){
  16.         case "wp-login.php":
  17.             edd_unset_error( 'no_gateways' );
  18.             forest_login_form();
  19.             die();
  20.             break;
  21.     }
  22. }
  23. add_action('init', 'forest_init', 100);
  24.  
  25. /**
  26.  * Process reset login Form
  27.  * @param array $data Data sent from the reset login form
  28.  * @return void
  29.  */
  30. function forest_process_reset_login_form( $data ) {
  31.     if ( wp_verify_nonce( $data['edd_login_nonce'], 'edd-login-nonce' ) ) {
  32.  
  33.         $errors = retrieve_password();
  34.         if ( isset($errors) && is_array($errors) ){
  35.             foreach($errors as $error) {
  36.                 if(count($error) > 0) {
  37.                     foreach($error as $e) {
  38.                         edd_set_error( 'email_incorrect', $e[0]);
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.         // Check for errors and redirect if none present
  44.         $errors = edd_get_errors();
  45.         if ( ! $errors ) {
  46.             $redirect =  $data['edd_redirect'];
  47.             wp_redirect( $redirect );
  48.             exit;
  49.         }
  50.     }
  51. }
  52. add_action( 'edd_user_reset_login', 'forest_process_reset_login_form' );
  53.  
  54. /**
  55.  * Process registre Form
  56.  * @param array $data Data sent from the reset login form
  57.  * @return void
  58.  */
  59. function forest_process_registre_form( $data ) {
  60.     if ( wp_verify_nonce( $data['edd-registre-nonce'], 'edd-registre-nonce' ) ) {
  61.  
  62.         $errors = register_new_user($data['user_login'], $data['user_email']);
  63.         if ( isset($errors) && is_array($errors) ){
  64.             foreach($errors as $error) {
  65.                 if(count($error) > 0) {
  66.                     foreach($error as $e) {
  67.                         edd_set_error( 'email_incorrect', $e[0]);
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.         // Check for errors and redirect if none present
  73.         $errors = edd_get_errors();
  74.         if ( ! $errors ) {
  75.             $redirect = apply_filters( 'edd_login_redirect', $data['edd_redirect'], $user_ID );
  76.             wp_redirect( $redirect );
  77.             exit;
  78.         }
  79.     }
  80. }
  81. add_action( 'edd_user_registre', 'forest_process_registre_form' );
  82.  
  83. /**
  84.  * Login Form
  85.  *
  86.  * @global $edd_options
  87.  * @global $post
  88.  * @param string $redirect Redirect page URL
  89.  * @return string Login form
  90.  */
  91. function forest_login_form( $redirect = '' ) {
  92.     global $edd_options, $post, $current_user;
  93.     get_currentuserinfo();
  94.  
  95.     if ( ! is_user_logged_in() ) {
  96.         get_header();
  97.         ?>
  98.  
  99. <div class="page-info">
  100.     <div class="container">
  101.    
  102.         <h1 class="page-title" itemprop="name">
  103.         <?php
  104.         if(isset ( $_REQUEST["action"] ) && $_REQUEST["action"] == 'register'){
  105.             echo __('Create a new Account','forest');
  106.         }else if(isset ( $_REQUEST["action"] ) && $_REQUEST["action"] == 'lostpassword'){
  107.             echo __('Reset password','forest');
  108.         } else {
  109.             echo __('Sign in to','forest').' '.get_bloginfo('name');
  110.         }
  111.         ?>
  112.         </h1>
  113.     </div>
  114.  
  115.     <div id="page-tabs">
  116.         <ul>
  117.             <li
  118.                 class="<?php echo isset ( $_REQUEST["action"] ) && $_REQUEST["action"] == 'register' ?  '' : 'selected';?>">
  119.                 <div></div> <a href="<?php bloginfo('url') ?>/wp-login.php"><?php echo __('Sign in','forest'); ?>
  120.             </a>
  121.             </li>
  122.             <li
  123.                 class="last <?php echo isset ( $_REQUEST["action"] ) && $_REQUEST["action"] == 'register' ?  'selected' : '';?>">
  124.                 <div></div> <a
  125.                 href="<?php bloginfo('url') ?>/wp-login.php?action=register"><?php echo __('Create Account','forest'); ?>
  126.             </a>
  127.                 <div class="last"></div>
  128.             </li>
  129.         </ul>
  130.     </div>
  131. </div>
  132.  
  133.         <?php
  134.         if(isset ($_REQUEST["action"]) && $_REQUEST["action"] == 'register'){
  135.             get_template_part('users/sign_up');
  136.         }else if(isset ($_REQUEST["action"]) && ($_REQUEST["action"] == 'lostpassword' || $_REQUEST["action"] == 'retrievepassword')){
  137.             get_template_part('users/password_resets');
  138.         }else if(isset ($_REQUEST["action"]) && ($_REQUEST["action"] == 'rp' || $_REQUEST["action"] =='resetpass')){
  139.             get_template_part('users/resetpass');
  140.         } else {
  141.             get_template_part('users/sign_in');
  142.         }
  143.         ?>
  144.  
  145.  
  146. <div class="clear">
  147.     <!-- -->
  148. </div>
  149.  
  150.         <?php
  151.  
  152.         get_footer();
  153.     }else{
  154.         $action = isset($_REQUEST["action"]) ? $_REQUEST["action"]:'';
  155.         switch ($action) {
  156.             case "logout":
  157.                 wp_clear_auth_cookie();
  158.                 do_action('wp_logout');
  159.                 nocache_headers();
  160.                 wp_redirect(home_url());
  161.                 exit();
  162.                 break;
  163.             default:
  164.                 wp_redirect(home_url());
  165.                 break;
  166.         }
  167.  
  168.     }
  169. }
  170.  
  171. // Take the pages array, and return the pages array without the excluded pages
  172. function forest_exclude_pages( $pages ) {
  173.  
  174.     global $edd_options;
  175.  
  176.     $forest_popular_post  = isset( $edd_options['forest_popular_post'] ) ? $edd_options['forest_popular_post']  : '';
  177.     $forest_all_post   = isset( $edd_options['forest_all_post'] ) ? $edd_options['forest_all_post']  : '';
  178.     $forest_getting_started     = isset( $edd_options['forest_getting_started'] )   ? $edd_options['forest_getting_started']    : '';
  179.     $forest_free_download  = isset( $edd_options['forest_free_download'] ) ? $edd_options['forest_free_download']  : '';
  180.     $forest_free_filelist   = isset( $edd_options['forest_free_filelist'] ) ? $edd_options['forest_free_filelist']  : '';
  181.     $purchase_page     = isset( $edd_options['purchase_page'] )   ? $edd_options['purchase_page']    : '';
  182.     $success_page     = isset( $edd_options['success_page'] )   ? $edd_options['success_page']    : '';
  183.     $failure_page    = isset( $edd_options['failure_page'] )   ? $edd_options['failure_page']    : '';
  184.  
  185.     $bail_out = ( ( defined( 'WP_ADMIN' ) && WP_ADMIN == true ) || ( strpos( $_SERVER[ 'PHP_SELF' ], 'wp-admin' ) !== false ) );
  186.     if ( $bail_out ) return $pages;
  187.  
  188.     $excluded_ids = array($forest_popular_post, $forest_all_post, $forest_getting_started, $forest_free_download, $forest_free_filelist, $purchase_page, $success_page, $failure_page);
  189.     $length       = count($pages);
  190.  
  191.     // Ensure the array only has unique values
  192.     $delete_ids = array_unique( $excluded_ids );
  193.  
  194.     // Loop though the $pages array and actually unset/delete stuff
  195.     for ( $i=0; $i<$length; $i++ ) {
  196.         $page = & $pages[$i];
  197.         // If one of the ancestor pages is excluded, add it to our exclude array
  198.         if ( in_array( $page->ID, $delete_ids ) ) {
  199.             // Finally, delete something(s)
  200.             unset( $pages[$i] );
  201.         }
  202.     }
  203.  
  204.     // Reindex the array, for neatness
  205.     // SWFIXME: Is reindexing the array going to create a memory optimisation problem for large arrays of WP post/page objects?
  206.     if ( ! is_array( $pages ) ) $pages = (array) $pages;
  207.     $pages = array_values( $pages );
  208.  
  209.     return $pages;
  210. }
  211. add_action('get_pages', 'forest_exclude_pages');
  212.  
  213. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement