Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined( 'ABSPATH' ) ) exit;
- //restrict admin access
- function restrict_admin()
- {
- 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) {
- wp_redirect( site_url() );
- }
- }
- add_action( 'admin_init', 'restrict_admin', 1 );
- // init and display login
- function forest_init(){
- global $pagenow,$edd_options;
- switch ($pagenow){
- case "wp-login.php":
- edd_unset_error( 'no_gateways' );
- forest_login_form();
- die();
- break;
- }
- }
- add_action('init', 'forest_init', 100);
- /**
- * Process reset login Form
- * @param array $data Data sent from the reset login form
- * @return void
- */
- function forest_process_reset_login_form( $data ) {
- if ( wp_verify_nonce( $data['edd_login_nonce'], 'edd-login-nonce' ) ) {
- $errors = retrieve_password();
- if ( isset($errors) && is_array($errors) ){
- foreach($errors as $error) {
- if(count($error) > 0) {
- foreach($error as $e) {
- edd_set_error( 'email_incorrect', $e[0]);
- }
- }
- }
- }
- // Check for errors and redirect if none present
- $errors = edd_get_errors();
- if ( ! $errors ) {
- $redirect = $data['edd_redirect'];
- wp_redirect( $redirect );
- exit;
- }
- }
- }
- add_action( 'edd_user_reset_login', 'forest_process_reset_login_form' );
- /**
- * Process registre Form
- * @param array $data Data sent from the reset login form
- * @return void
- */
- function forest_process_registre_form( $data ) {
- if ( wp_verify_nonce( $data['edd-registre-nonce'], 'edd-registre-nonce' ) ) {
- $errors = register_new_user($data['user_login'], $data['user_email']);
- if ( isset($errors) && is_array($errors) ){
- foreach($errors as $error) {
- if(count($error) > 0) {
- foreach($error as $e) {
- edd_set_error( 'email_incorrect', $e[0]);
- }
- }
- }
- }
- // Check for errors and redirect if none present
- $errors = edd_get_errors();
- if ( ! $errors ) {
- $redirect = apply_filters( 'edd_login_redirect', $data['edd_redirect'], $user_ID );
- wp_redirect( $redirect );
- exit;
- }
- }
- }
- add_action( 'edd_user_registre', 'forest_process_registre_form' );
- /**
- * Login Form
- *
- * @global $edd_options
- * @global $post
- * @param string $redirect Redirect page URL
- * @return string Login form
- */
- function forest_login_form( $redirect = '' ) {
- global $edd_options, $post, $current_user;
- get_currentuserinfo();
- if ( ! is_user_logged_in() ) {
- get_header();
- ?>
- <div class="page-info">
- <div class="container">
- <h1 class="page-title" itemprop="name">
- <?php
- if(isset ( $_REQUEST["action"] ) && $_REQUEST["action"] == 'register'){
- echo __('Create a new Account','forest');
- }else if(isset ( $_REQUEST["action"] ) && $_REQUEST["action"] == 'lostpassword'){
- echo __('Reset password','forest');
- } else {
- echo __('Sign in to','forest').' '.get_bloginfo('name');
- }
- ?>
- </h1>
- </div>
- <div id="page-tabs">
- <ul>
- <li
- class="<?php echo isset ( $_REQUEST["action"] ) && $_REQUEST["action"] == 'register' ? '' : 'selected';?>">
- <div></div> <a href="<?php bloginfo('url') ?>/wp-login.php"><?php echo __('Sign in','forest'); ?>
- </a>
- </li>
- <li
- class="last <?php echo isset ( $_REQUEST["action"] ) && $_REQUEST["action"] == 'register' ? 'selected' : '';?>">
- <div></div> <a
- href="<?php bloginfo('url') ?>/wp-login.php?action=register"><?php echo __('Create Account','forest'); ?>
- </a>
- <div class="last"></div>
- </li>
- </ul>
- </div>
- </div>
- <?php
- if(isset ($_REQUEST["action"]) && $_REQUEST["action"] == 'register'){
- get_template_part('users/sign_up');
- }else if(isset ($_REQUEST["action"]) && ($_REQUEST["action"] == 'lostpassword' || $_REQUEST["action"] == 'retrievepassword')){
- get_template_part('users/password_resets');
- }else if(isset ($_REQUEST["action"]) && ($_REQUEST["action"] == 'rp' || $_REQUEST["action"] =='resetpass')){
- get_template_part('users/resetpass');
- } else {
- get_template_part('users/sign_in');
- }
- ?>
- <div class="clear">
- <!-- -->
- </div>
- <?php
- get_footer();
- }else{
- $action = isset($_REQUEST["action"]) ? $_REQUEST["action"]:'';
- switch ($action) {
- case "logout":
- wp_clear_auth_cookie();
- do_action('wp_logout');
- nocache_headers();
- wp_redirect(home_url());
- exit();
- break;
- default:
- wp_redirect(home_url());
- break;
- }
- }
- }
- // Take the pages array, and return the pages array without the excluded pages
- function forest_exclude_pages( $pages ) {
- global $edd_options;
- $forest_popular_post = isset( $edd_options['forest_popular_post'] ) ? $edd_options['forest_popular_post'] : '';
- $forest_all_post = isset( $edd_options['forest_all_post'] ) ? $edd_options['forest_all_post'] : '';
- $forest_getting_started = isset( $edd_options['forest_getting_started'] ) ? $edd_options['forest_getting_started'] : '';
- $forest_free_download = isset( $edd_options['forest_free_download'] ) ? $edd_options['forest_free_download'] : '';
- $forest_free_filelist = isset( $edd_options['forest_free_filelist'] ) ? $edd_options['forest_free_filelist'] : '';
- $purchase_page = isset( $edd_options['purchase_page'] ) ? $edd_options['purchase_page'] : '';
- $success_page = isset( $edd_options['success_page'] ) ? $edd_options['success_page'] : '';
- $failure_page = isset( $edd_options['failure_page'] ) ? $edd_options['failure_page'] : '';
- $bail_out = ( ( defined( 'WP_ADMIN' ) && WP_ADMIN == true ) || ( strpos( $_SERVER[ 'PHP_SELF' ], 'wp-admin' ) !== false ) );
- if ( $bail_out ) return $pages;
- $excluded_ids = array($forest_popular_post, $forest_all_post, $forest_getting_started, $forest_free_download, $forest_free_filelist, $purchase_page, $success_page, $failure_page);
- $length = count($pages);
- // Ensure the array only has unique values
- $delete_ids = array_unique( $excluded_ids );
- // Loop though the $pages array and actually unset/delete stuff
- for ( $i=0; $i<$length; $i++ ) {
- $page = & $pages[$i];
- // If one of the ancestor pages is excluded, add it to our exclude array
- if ( in_array( $page->ID, $delete_ids ) ) {
- // Finally, delete something(s)
- unset( $pages[$i] );
- }
- }
- // Reindex the array, for neatness
- // SWFIXME: Is reindexing the array going to create a memory optimisation problem for large arrays of WP post/page objects?
- if ( ! is_array( $pages ) ) $pages = (array) $pages;
- $pages = array_values( $pages );
- return $pages;
- }
- add_action('get_pages', 'forest_exclude_pages');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement