Members only template files/funcs added (unfinished)
authorLaury GvR <laury@gaslightmedia.com>
Tue, 14 May 2019 20:16:57 +0000 (16:16 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Tue, 14 May 2019 20:16:57 +0000 (16:16 -0400)
functions.php
includes/lib/glm-members-only-login-form.php [new file with mode: 0644]
includes/lib/glm-members-only-template.php [new file with mode: 0644]
page.php

index cf91de1..7badae0 100644 (file)
@@ -842,3 +842,82 @@ function my_ajax_callback_function() {
 }
 add_action( 'wp_ajax_numGolfers', 'my_ajax_callback_function' );    // If called from admin panel
 add_action( 'wp_ajax_nopriv_numGolfers', 'my_ajax_callback_function' );
+
+
+/*
+ * This function returns true when the current page is the page given by ID
+ *  or a descendent thereof.
+ */
+if (!function_exists('is_in_tree')) {
+    function is_in_tree( $pid ) {
+        global $post;
+        if ( is_page($pid) ) {
+            return true;
+        }
+        $anc = get_post_ancestors( $post->ID );
+        foreach ( $anc as $ancestor ) {
+            if( is_page() && $ancestor == $pid ) {
+                return true;
+            }
+        }
+        return false;
+    }
+}
+
+// Menu for the members only section
+if ( ! function_exists( 'glm_members_only_menu')) {
+    function glm_members_only_menu() {
+        wp_nav_menu(array(
+            'container' => false,                           // remove nav container
+            'container_class' => 'members-only-menu',                        // class of container
+            'menu' => '',                                   // menu name
+            'menu_class' => 'members-only-menu',                             // adding custom nav class
+            'theme_location' => 'members-only-menu',             // where it's located in the theme
+            'before' => '',                                 // before each link <a>
+            'after' => '',                                  // after each link </a>
+            'link_before' => '',                            // before each link text
+            'link_after' => '',                             // after each link text
+            'depth' => 2,                                   // limit the depth of the nav
+            'fallback_cb' => false,                         // fallback function (see below)
+            'items_wrap' => '%3$s',
+            'walker' => new GLM_Members_Only_Walker()
+        ));
+    }
+}
+
+// Walker for the menu for the members only section
+if ( ! class_exists( 'GLM_Members_Only_Walker' ) ) :
+class GLM_Members_Only_Walker extends Walker_Nav_Menu {
+
+    function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
+        $element->has_children = ! empty( $children_elements[ $element->ID ] );
+        $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : '';
+        $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'page_item_has_children' : '';
+        $element->classes[] = 'page_item';
+
+        parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
+    }
+
+    function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
+        $item_html = '';
+        parent::start_el( $item_html, $object, $depth, $args );
+
+        $classes = empty( $object->classes ) ? array() : (array) $object->classes;
+
+        if ( in_array( 'label', $classes ) ) {
+            $item_html = preg_replace( '/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html );
+        }
+
+        $output .= $item_html;
+    }
+
+    function start_lvl( &$output, $depth = 0, $args = array() ) {
+        $output .= "\n<ul class=\"children\">\n";
+    }
+
+    function end_lvl(&$output, $depth = 0, $args = array()){
+        $output .= '</ul>';
+    }
+
+}
+endif;
\ No newline at end of file
diff --git a/includes/lib/glm-members-only-login-form.php b/includes/lib/glm-members-only-login-form.php
new file mode 100644 (file)
index 0000000..354bf62
--- /dev/null
@@ -0,0 +1,69 @@
+<div class="wp_login_error">
+    <p id="glm-member-login-notification">
+        <?php if( isset( $_GET['login'] ) && $_GET['login'] == 'failed' ) { ?>
+            The information you entered is incorrect. Please try again.
+        <?php }
+            else if( isset( $_GET['login'] ) && $_GET['login'] == 'empty' ) { ?>
+            Please enter both username and password.
+        <?php } else { ?>
+            <?php $glmAssociateConfig = apply_filters('glm_associate_config', null);
+                $supportEmail = $glmAssociateConfig['settings']['members_only_support_email'];
+                $supportPhone = $glmAssociateConfig['settings']['members_only_support_phone'];
+                $glmTerm = $glmAssociateConfig['terms']['term_member'];
+            ?>
+            Please log in with your <?php echo $glmTerm; ?> username and password.
+
+            <?php if ($supportEmail || $supportPhone) {
+                echo "<br>If you need assistance, ";
+                if ($supportEmail) {
+                    echo "email (".$supportEmail.")";
+                    if ($supportPhone) {
+                        echo " or ";
+                    }
+                }
+                if ($supportPhone) {
+                    echo "call (".$supportPhone.")";
+                }
+            }
+            ?>
+        <?php } ?>
+    </p>
+</div>
+<div id='glm-member-login-form'>
+    <?php
+        update_option('glm_members_database_frontend_login_request', 'true');
+    $args = array(
+        'echo'    => false,
+        'form_id' => 'glm_login_form'
+    );
+    $loginForm = wp_login_form($args);
+    $captcha   = apply_filters('cptch_display', '', 'glm_login_form');
+    $form      = str_replace( '<p class="login-remember">', $captcha . '<p class="login-remember">', $loginForm );
+    echo $form;
+    ?>
+</div>
+
+<a id="glm-member-password-lost-link" title="Lost Password">Lost Password?</a>
+<div id="glm-member-password-lost-form">
+
+    <p>
+        <?php
+            _e(
+                "Enter your email address and we'll send you a link you can use to pick a new password.",
+                'personalize_login'
+            );
+        ?>
+    </p>
+
+    <form id="lostpasswordform" action="<?php echo wp_lostpassword_url(); ?>" method="post">
+        <p class="form-row">
+            <label for="user_login"><?php _e( 'Email', 'personalize-login' ); ?>
+            <input type="text" name="user_login" id="user_login">
+        </p>
+
+        <p class="lostpassword-submit">
+            <input type="submit" name="submit" class="lostpassword-button"
+                    value="<?php _e( 'Reset Password', 'personalize-login' ); ?>"/>
+        </p>
+    </form>
+</div>
diff --git a/includes/lib/glm-members-only-template.php b/includes/lib/glm-members-only-template.php
new file mode 100644 (file)
index 0000000..e45800e
--- /dev/null
@@ -0,0 +1,28 @@
+<div id="members-only-wrapper">
+    <?php if ( current_user_can("glm_members_member") ) { ?>
+        <!-- If user is logged in as a member, display members side bar, top bar & content -->
+        <div id="members-only-sidebar">
+            <h2> Members Only Area </h2>
+            <?php glm_members_only_menu(); ?>
+        </div>
+        <div id="members-only-content">
+            <div id="glm-member-front-header" class="small-12 columns">
+                <div class='glm-member-greeting'>Hello,     <?php $current_user = wp_get_current_user();echo $current_user->user_login ?>.</div>
+                <a class='button glm-button' href="<?php echo wp_logout_url( home_url() ); ?>">Logout</a>
+                <?php if (current_user_can("glm_members_member")) { ?>
+                    <?php apply_filters('glm_associate_terms', $glmAssociateTerms);?>
+                    <a class='button glm-button' href='<?php echo get_admin_url(); ?>'>Enter <?php echo $glmAssociateTerms['term_member_cap']; ?> Admin Area</a>                        
+                <?php } ?>
+            </div>
+            <?php the_content(); ?>
+        </div>
+    <?php } else if (get_the_ID() == get_option("glm_members_database_option_members_only_id")) {?>
+        <!-- If user is not logged in as member, but it's the main members only page, display content & form -->
+        <?php the_content(); ?>
+        <?php include("lib/glm-members-only-login-form.php"); ?>
+    <?php } else { ?>
+        <!-- Otherwise, display main members only page content & form -->
+        <?php echo get_post_page_content(get_option("glm_members_database_option_members_only_id")); ?>
+        <?php include("lib/glm-members-only-login-form.php"); ?>
+    <?php } ?>
+</div>
\ No newline at end of file
index 82d551b..1e997ea 100644 (file)
--- a/page.php
+++ b/page.php
@@ -35,7 +35,13 @@ if ( ! defined( 'ABSPATH' ) ) {
                        <?php echo fusion_render_rich_snippets_for_pages(); // WPCS: XSS ok. ?>
                        <?php avada_featured_images_for_pages(); ?>
                        <div class="post-content">
-                               <?php the_content(); ?>
+                               <?php if ( is_in_tree( get_option("glm_members_database_option_members_only_id") ) ) { ?>
+                                       <!-- if this is a page in the members only tree, go through members only content -->
+                                       <?php include("inc/glm-members-only-template.php"); ?>
+                               <?php } else { ?>
+                                       <!-- if this is not a members-only template, show the regular content -->
+                                       <?php the_content(); ?>
+                               <?php } ?>
                                <?php fusion_link_pages(); ?>
                        </div>
                        <?php if ( ! post_password_required( $post->ID ) ) : ?>