Search Results for 'code'
-
Search Results
-
Topic: User Last Login
Hello there!
I was trying to integrate a code, so other users can see the last login of any user. The integration in the admin panel worked out with a snippet, which I found in the internet, but still, I couldn’t figure it out how to show it in the profile page.
The snippet, which I used is shown underneath (can be found here: https://www.wpbeginner.com/plugins/how-to-show-users-last-login-date-in-wordpress/). I did some changes in the function wpb_lastlogin:
<?php /** * Capture user login and add it as timestamp in user meta data * */ function user_last_login( $user_login, $user ) { update_user_meta( $user->ID, 'last_login', time() ); } add_action( 'wp_login', 'user_last_login', 10, 2 ); /** * Display last login time * */ function wpb_lastlogin() { $last_login = get_the_author_meta('last_login'); (also tried: get_user_meta( $user_id 'last_login', true ); $the_login_date = human_time_diff($last_login); - changed to: date_i18n(get_option('date_format'), $last_login); return $the_login_date; } /** * Add Shortcode lastlogin * */ add_shortcode('lastlogin','wpb_lastlogin'); ?>
This code above I have in my function.php file in my child theme. Till here everything works fine. Besides BBPress I use a forum theme (Disputo), where I want to integrate the last login in the profile page of the user. Therefore I was trying to figure out a code to do so. The page (as an example, my own user page) is: https://www.denkerecke.de/benutzer/lukas/. For that I was using the user-profile.php , which is also used by the theme. I also used the code from the website, which I mentioned before:
<?php echo 'Last seen: '. do_shortcode('[lastlogin]') .' ago'; ?>
Still, it didn’t work out. The problem is that on every user page only the last login of myself (the admin) is shown. I think its because somewhere in the code is a mistake, so not the user id of the user profile page is filtered, rather the user id of the current logged in user or the admin.
Does anyone have an idea to fix it? I would appreciate your help.
Greetings,
Lukas HerrmannWordPress version: 5.6
bbPress version: 2.6.6Hi there,
How do we make site visitors who are not logged-in redirect to a registration page when they click on any topic or post in the forum? It should be a code in functions.php, I think. Any suggestions?
It would be great to automatically send them back to where they came from once registration is complete. Is this possible?
Many thanks,
BI have this function to display advertisement after first paragprah in posts:
add_filter( 'the_content', 'post_ads_1_paragraph' ); function post_ads_1_paragraph( $content ) { $ad_code = '<div class="advert" style="display: none;">Reklama1</div>'; if ( is_single() && ! is_admin() ) { return prefix_insert_after_1nd_paragraph( $ad_code, 1, $content ); } return $content; } function prefix_insert_after_1nd_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '</p>'; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $insertion; } } return implode( '', $paragraphs ); }
The problem is that this function is somehow hooked to bbpress forum listing (forum description) to, and shows after forum description.
So how can I remove it from bbpress so it affects only posts?See word “reklama1” after each forum description: https://mllapan.com/forumi/forum/magazin/
Topic: My new BBPress forum site
Hi there!
Check it out my new BBPress forum site with customs design and codes:
Cheers!
I have been trying to assign some js files only to their respective pages on my site, instead of loading them everywhere and have been successful apart from with my forum area.
in my functions.php file i have tried the following:add_action ('wp_print_scripts', 'deregister_forum_scripts'); function deregister_forum_scripts(){ if ( !is_page('forum') (is_page() && in_array( 19306, get_post_ancestors( get_the_ID() ) ) ) ) { wp_deregister_script('forum-js'); }}
whereby i got the id 19306 from my database by doing:
select ID from wp_posts where post_name = 'forum';
As the page is http://www.apis.de/forum/
The issue is, even if I leave out the second part of the “if” statement (i.e. “is_page()….), it doesn’t work.
I assume this is because my forum is implemented differently to the rest of my site and is not a normal “is_page(….)”.
Can anyone advise here how to target the forum via PHP?
Also, i don’t think i should be using “get_post_ancestors
” but “get_page_children
“. But that is another topic.