Home › Forums › Newsletter Plugin Support › {profile_form} for logged in users
- This topic has 10 replies, 2 voices, and was last updated 9 years, 8 months ago by
lustek.
-
AuthorPosts
-
January 23, 2014 at 2:24 pm #10358
lustek
ParticipantI 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
January 23, 2014 at 8:26 pm #10365Stefano
KeymasterThe 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.
January 24, 2014 at 10:59 am #10377lustek
ParticipantAt 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.
January 24, 2014 at 5:42 pm #10385Stefano
KeymasterThat call sends out a redirect. To show the form use NewsletterSubscription::instance()->profile_form() (if I remeber well, I have not the code here)
January 27, 2014 at 5:17 pm #10409lustek
ParticipantI get:
Fatal error: Call to undefined method NewsletterSubscription::profile_form()🙁
January 28, 2014 at 9:18 am #10410lustek
Participantok, 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?
January 28, 2014 at 10:13 am #10411lustek
Participantafter 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.
January 28, 2014 at 2:16 pm #10412Stefano
KeymasterThe 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.
January 28, 2014 at 4:46 pm #10419lustek
Participantok, 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?
February 1, 2014 at 9:48 am #10442Stefano
KeymasterNot 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.
February 2, 2014 at 4:21 pm #10445lustek
Participantthanks, it’s exactly what I needed!
-
AuthorPosts
- You must be logged in to reply to this topic.