Forum Replies Created

Viewing 15 replies - 1 through 15 (of 111 total)
  • Thread Starter hsysgrp

    (@hsysgrp)

    I solved my problem of different menus for different viewers. The relevant code in the functions.php file in the twentyfourteen child directory is below.

    The correct code is displayed , and subscriber and contributor members are directed to the blog page, and public and admin land on the Home page with the appropriate menus. Thank you for your help.

    function my_wp_nav_menu_args($args = '') {
    	// Logged in menu to display;Public = 10 Members = 9 Admin = 11
    	// Public is for non-members Members is for HFA members Admin is for Admin functions
    
    	if ( is_user_logged_in() ) {
    
    		if ( current_user_can( 'activate_plugins' ) ) {
    			$args['menu'] = 11; // admin only menu
    		} else {
    			$args['menu'] = 9;
    		}
    
    	} else {
    		// Non-logged-in menu to display
    
    		$args['menu'] = 10;
    	}
    	return $args;
    }
    add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args');
    
    function custom_login_redirect( $redirect_to, $request, $user ) {
        // Get the current user's role
        $user_role = $user->roles[0];
     
        // Set the URL to redirect users to based on their role
        if ( $user_role == 'subscriber' ) {
            $redirect_to = '/blog/';
        } elseif ( $user_role == 'contributor' ) {
            $redirect_to = '/blog/';
        }
     
        return $redirect_to;
    }
    add_filter( 'login_redirect', 'custom_login_redirect', 10, 3 );
    
    Thread Starter hsysgrp

    (@hsysgrp)

    Thank you for your response.

    on line 1328 is

    // If the user doesn’t belong to a blog, send them to user admin. If the user can’t edit posts, send them to their profile.

    Now I know why the member lands on the profile. The issue is, how do I change the redirect code for the member user to be redirected to the Home page of the appropriate menu?

    Thread Starter hsysgrp

    (@hsysgrp)

    add_filter( 'login_redirect', 'ur_redirect_after_login', 10, 2 );

    Still have the original problem, admin(menu=11) and a public user(menu=10) are presented with the correct menus and directed to the Home page; a member user (menu=9)is directed to hawesfamilyassociation.com/wp-login/profile.php.

    The 2 parameters are the $redirect (the return URL, and the $user, correct? the user is global here?

    Thread Starter hsysgrp

    (@hsysgrp)

    I added add_filter( ‘login_redirect’, ‘ur_redirect_after_login’, ); but the logged in user is still directed to the profile page. Why is there a comma after login if there are no parameters? The return is the URL, right,?

    Thread Starter hsysgrp

    (@hsysgrp)

    Absolutely right, changed the paired squiggles to apostrophes and functions.php was updated with the edit. However the user is still redirected to the profile.php page instead of the home page that does display the correct menu 9.

    function ur_redirect_after_login( $redirect, $user ) {
    return ‘https://www.hawesfamilyassociation.com’ ;
    }
    add_filter( ‘user_registration_login_redirect’, ‘ur_redirect_after_login’, 10, 2 );
    Thread Starter hsysgrp

    (@hsysgrp)

    <?php
    // functions.php in 2014 child theme 4/8/2023
    // Exit if accessed directly
    if ( !defined( 'ABSPATH' ) ) exit;
    
    // BEGIN ENQUEUE PARENT ACTION
    // AUTO GENERATED - Do not modify or remove comment markers above or below:
    
            
    if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
        function chld_thm_cfg_parent_css() {
            wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css' );
        }
    endif;
    add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css' );
    
    // END ENQUEUE PARENT ACTION
    
    function my_wp_nav_menu_args($args = '') {
    	// Logged in menu to display;Public = 10 Menu = 9 Admin = 11
    	// Public is for non-members Menu is for HFA members Admin is for Admin functions
    
    	if ( is_user_logged_in() ) {
    
    		if ( current_user_can( 'activate_plugins' ) ) {
    			$args['menu'] = 11; // admin only menu
    		} else {
    			$args['menu'] = 9;
    		}
    
    	} else {
    		// Non-logged-in menu to display
    
    		$args['menu'] = 10;
    	}
    	return $args;
    }
    add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args');

    Success. The code above successfully presents different menus based on user category: admin, group member, and public. The first try had $args[’menu’] = 11; I’m looking at the answer above, and see the line as $args[‘menu’] = 11;

    Somewhere in copying the code from the Forum to notepad to FileZilla to theme file editor the bracket got changed to #091; syntax for the menu choices, and the php evidently choked on that. Will definitely research which version of php is being used, and watch out for substitutions in the future. Thank you for your help.

    Thread Starter hsysgrp

    (@hsysgrp)

    Version information:?4.9.11 in BlueHost. Basically Admin is me. I want to see the Admin menu if I log in, the Menu menu if the members log in, and the Public menu if its a visitor. Bluehost if refusing to update functions.php with the code above, declaring there is an extra parenthesis. Debug.txt says the same.

    Thread Starter hsysgrp

    (@hsysgrp)

    Debug says syntax error, unexpected ‘}’ in /home4/hsysgrpc/public_html/hawesfamilyassociation/wp-content/themes/twentyfourteen-child/functions.php on line 46. All of the parenthesis match, I’m wondering if the code should be

    if ( is_user_logged_in() ) 
    
    		and ( current_user_can( 'activate_plugins' ) ) {
    Thread Starter hsysgrp

    (@hsysgrp)

    Thank you. The “current user can activate plugins” is just the determinant I was looking for. However I get a fatal error.. my functions.php in the child is:

    <?php
    // Exit if accessed directly
    if ( !defined( 'ABSPATH' ) ) exit;
    
    // BEGIN ENQUEUE PARENT ACTION
    // AUTO GENERATED - Do not modify or remove comment markers above or below:
    
            
    if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
        function chld_thm_cfg_parent_css() {
            wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css' );
        }
    endif;
    add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css' );
    
    // END ENQUEUE PARENT ACTION
    
    function my_wp_nav_menu_args($args = '') {
    	// Logged in menu to display;Public = 10 Menu = 9 Admin = 11
    	// Public is for non-members Menu is for HFA members Admin is for Admin functions
    
    	if ( is_user_logged_in() ) {
    
    		if ( current_user_can( 'activate_plugins' ) ) {
    			$args['menu'] = 11; // admin only menu
    		} else {
    			$args['menu'] = 9;
    		}
    
    	} else {
    		// Non-logged-in menu to display
    
    		$args['menu'] = 10;
    	}
    	return $args;
    }
    add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args');
    

    Which if any of the menus should be designated as the primary?

    Thread Starter hsysgrp

    (@hsysgrp)

    
    </tbody>
    </table>
    <input type = "submit" name ="submit" Value = "Save"> 
    </form>
    <p> Enter extended text for  Hawes Line descent in the box</p>
    
    <textarea rows = "4" cols = "40" name = "HawesLine" form = "HawesLinefrm"> Enter Hawes Line text here...</textarea><br>
    

    The data gets inserted ok. So now the form ends with the save button and the textarea box is below the form. Is there a way to place the “save” button after the form border? Yes, I am always concerned with how it looks… and have novice skills with css.

    Thread Starter hsysgrp

    (@hsysgrp)

    Result for type “text” is a box that stretches for 250 across the page:

    Result for type “textarea” is the default box as though the rows = “4” cols = “40” is ignored entirely. Data can be retrieved and updated ok.

    <input type="text" id="Notes" name="Notes" size = 250 value="<?php echo $row->Notes; ?>"><br> 
     <input type="textarea"  rows = "4" cols = "40" id="HawesLine" name="HawesLine" value="<?php echo $row->HawesLine; ?>"><br>
    
    
    Thread Starter hsysgrp

    (@hsysgrp)

    Thank you for your reply. Have tried to substitute input textarea for input text but cannot get the syntax right. I want to enter the form data for HawesLine in a box instead of a text box that stretches across the form.

      
     <label for="Notes">Notes:</label>
      <input type="text" id="Notes" name="Notes" size = 250 value="<?php echo $row->Notes; ?>"><br>
     <label for="HawesLine">Hawes Line:</label>
      <input type="textarea"  rows = "4" cols = "40" id="HawesLine" name="HawesLine" value="<?php echo $row->HawesLine; ?>"><br>
     
                
               
    Thread Starter hsysgrp

    (@hsysgrp)

    Thank you for your response, the problem was a coding error somewhere, never found it, rewrote and it worked.

    	if (isset($_POST['submit'])){
    	echo "submit checked";
    	$tablename = 'HFA_Members';
    	echo $tablename . "<br>";
    
    $data_update =  array(	      
    	'Title' => $Title,
       	'FirstName' => $FirstName,
    	'LastName'=> $LastName,
    	'Address'=> $Address,
    	'City'=> $City,
    	'State'=> $State,
    	'Country'=> $Country,
    	'Zip'=> $Zip,
    	'Phone'=> $Phone,
    	'CellPhone'=> $CellPhone,
    	'Email'=> $Email,
    	'Notes'=>$Notes
        
        ) ;
    $data_where =   array(    
    		'ID' => $ID  	
        );	
    $result_check = $wpdb->update($tablename, $data_update, $data_where);
    
    				
    if($result_check){
       echo "successfully updated"; 
    	 '<br/>';//successfully inserted.
    }else{
      echo "no dice"; //something gone wrong
    } //end $result_check
    
    
    mysqli_close($link);
    } //end isset
    ?>
    Thread Starter hsysgrp

    (@hsysgrp)

    
    
    <form id = 2 action= "https://hawesfamilyassociation.com/wp-content/themes/twentyfourteen-child/HFA_Members_UpdateDesc.php/" method='POST'>

    <label for="FirstName">First name:</label>
    <input type="text" id="FirstName" name="FirstName" value="<?php echo $row->FirstName; ?>"><br>
    <label for="LastName">Last name:</label>
    <input type="text" id="LastName" name="LastName" value="<?php echo $row->LastName;?>"><br>
    <label for="Address">Address:</label>
    <input type="text" id="Address" name="Address" value="<?php echo $row->Address; ?>"><br>
    <label for="City">City:</label>
    <input type="text" id="City" name="City" value="<?php echo $row->City;?>"><br>
    <label for="State">State:</label>
    <input type="text" id="State" name="State" value="<?php echo $row->State; ?>"><br>
    <label for="Country">Country:</label>
    <input type="text" id="Country" name="Country" value="<?php echo $row->Country;?>"><br>
    <label for="Zip">Zip:</label>
    <input type="text" id="Zip" name="Zip" value="<?php echo $row->Zip; ?>"><br>
    <label for="Phone">Phone:</label>
    <input type="text" id="Phone" name="Phone" value="<?php echo $row->Phone;?>"><br>
    <label for="CellPhone">CellPhone:</label>
    <input type="text" id="CellPhone" name="CellPhone" value="<?php echo $row->CellPhone;?>"><br>
    <label for="Email">Email:</label>
    <input type="text" id="Email" name="Email" value="<?php echo $row->Email;?>"><br>
    <label for="Notes">Notes:</label>
    <input type="text" id="Notes" name="Notes" value="<?php echo $row->Notes; ?>"><br>

    <input type="submit" name = "submit" value="Update">
    </form>
    I narrowed it down to POST is not sending data to the update script. The script is accessed, but echo "$ID"; is null.
    Thank you for your response.
    Thread Starter hsysgrp

    (@hsysgrp)

    OK, will try that. thank you.

Viewing 15 replies - 1 through 15 (of 111 total)