Home Forums Newsletter Plugin Support {profile_form} for logged in users

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #10358
    lustek
    Participant

    I use buddypress on my site. i need a way to show a link to {profile_form} for logged in users in site menu. i see that the only part of url that is variable is nk parameter. what would be the php code to get it based on user login?

    second case is logged in users, who are not signed up for newsletter. can you suggest how to make a modification on subscription page? I already have their email, so it would be handy to fill in the input box with this email, so that users should only press subscribe button

    #10365
    Stefano
    Keymaster

    The nk parameter is the subscriber id plus the token, both on wp_newsletter table. To make a modification on the user profile page (I image since you said they are logged in), youshould intercept the saving of the user data, check for a value you added (a checkbox to subscribe to the newsletter) and add a subscriber connected to the current user id. Not so easy, but feasible.

    #10377
    lustek
    Participant

    At the beginning I wanted to add code like this to functions.php to add buddypress menu:

    function profile_screen_newsletter() {
     
            add_action( 'bp_template_content', 'my_profile_page_function_to_show_screen_content' );
            bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
            }
            function my_profile_page_function_to_show_screen_title() {
                    echo 'Newsletter';
            }
            function my_profile_page_function_to_show_screen_content() {
     
            echo do_shortcode('[newsletter]');
     
            }

    but as I mentioned before it only works to show profile, when I add nk parameter at the end of url. it’s not really a tidy solution, when other urls in profile don’t have any parameters. So I decided to do it differently. I looked around plugin’s files and found profile.php in “do” directory

    so I tried to alter it and use code below instead of echoing the newsleter shortcode.

    function profile_screen_newsletter() {
     
            add_action( 'bp_template_content', 'my_profile_page_function_to_show_screen_content' );
            bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
            }
            function my_profile_page_function_to_show_screen_title() {
                    echo 'Newsletter';
            }
            function my_profile_page_function_to_show_screen_content() {
    $user = wp_get_current_user();
    if ($user == null) die('No subscriber found.');
    NewsletterSubscription::instance()->show_message('profile', $user);
    }

    but I get this warning message:

    Warning: Cannot modify header information – headers already sent by (output started at /…/wp-content/themes/clippy/header.php:5) in /…/wp-content/plugins/newsletter/subscription/subscription.php on line 491

    I’m not a proggramer, so it’s a bit blind code copy-pasting. I would really appriciate if you had a minute to look on this. thanks in advance.

    #10385
    Stefano
    Keymaster

    That call sends out a redirect. To show the form use NewsletterSubscription::instance()->profile_form() (if I remeber well, I have not the code here)

    #10409
    lustek
    Participant

    I get:
    Fatal error: Call to undefined method NewsletterSubscription::profile_form()

    🙁

    #10410
    lustek
    Participant

    ok, i found it. you forgot about “get” 😉

    my code is like this:

    $user = wp_get_current_user();
    echo NewsletterSubscription::instance()->get_profile_form($user);

    but it shows subscription form not the profile form. so i can’t use wp user to find newsletter user. is there any function that returns newsletter user based on $user->email?

    #10411
    lustek
    Participant

    after more test I have something like this:

    $current_user = wp_get_current_user();
    $newsletter_user = NewsletterSubscription::instance()->get_user($current_user->user_email);
    echo NewsletterSubscription::instance()->get_profile_form($newsletter_user);

    but it still shows subscription form instead of profile form. the only difference is that now the input box is automatically filled in with user email.

    #10412
    Stefano
    Keymaster

    The subscription form and the profile form is almost identical. Are you sure the one display IS NOT the profile form? With profile form I mean the Newsletter set of subscriber data.

    #10419
    lustek
    Participant

    ok, I understand it now. I see the content of {profile_form} shortcode and nothing more. What i want is all the other content I added in the admin panel in this tab: subscription steps/profile. for example the unsubscribe link is missing.

    is there any function to get not only {profile_form} but also all the stuff around i added in admin panel?

    #10442
    Stefano
    Keymaster

    Not an already ready function but:

    $module = NewsletterSubscription::instance();
    $user = ; // this is a subscriber not a wp user!
    $message_key = $module->get_message_key_from_request();
    $message = Newsletter::instance()->replace($module->options[‘profile_text’], $user);

    $message will contain the profile page.

    #10445
    lustek
    Participant

    thanks, it’s exactly what I needed!

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.