PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label author. Show all posts
Showing posts with label author. Show all posts

Sunday, July 10, 2022

[FIXED] How to get message author id in discord.py? - Discord Python

 July 10, 2022     author, discord, discord.py, message, python     No comments   

Issue

Problem is, if i try to use message.author.id, it will say

"Cannot find reference 'author' in 'message.py'

Basically what i want to do in the code bellow is: a command that only certain id's have access to and that they can use to give their role away to someone.

Thanks for any help!

@client.command(pass_context=True)
@commands.has(939236844137226290)
async def asteroid(ctx, user: discord.Member):
    if  message.author.id == 939236844137226290:
        role = ctx.guild.get_role(939236844137226290)
        await user.add_roles(role)
        await ctx.send(f"{user.name} has received {role} from {ctx.author.name}!")
    else:
        await ctx.send("Only asteroidblues has permission to give the role away")

Solution

The problem is probably that you imported discord.Message but you have to use message.author.id when message is a variable containing a discord.Message instance, which you don't have in this case. But what you do have is ctx, the context, from which you can access the author id by using ctx.author.id.



Answered By - Chuaat
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, July 8, 2022

[FIXED] How to make a Wordpress post only visible for the author and through a direct link?

 July 08, 2022     author, posts, wordpress     No comments   

Issue

I want to make a Wordpress site where users can register them self. They only need the ability to update there profile and write a post. This post should be only visible to the author or through a direct link.

Does anybody know how I can make the post of the author invisible on the website but when the author logs in the post is visible and when someone uses the direct link to the post it's also visible. Is there some kind of plugin what can do this or some kind of code which I can edit so this will work.

Also there are multiple authors with each there own posts.

Thank you


Solution

  1. Go to your posts

  2. Open the desired one.

  3. Set post visibility to Private

Also you can vizit this page: http://wordpress.org/support/topic/let-author-only-see-their-posts



Answered By - 5wpthemes
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, July 3, 2022

[FIXED] How to load User Meta?

 July 03, 2022     author, meta, multisite, php, wordpress     No comments   

Issue

Wordpress author.php is not loading the correct information from user meta. It's loading whoever is currently logged in to the blog and not displaying the person who it links to for example:

http://www.website.com/author/username1
http://www.website.com/author/username2

is displaying the same despite been two different users. I've done what is asked, however I'm still confused to why its only loading the currently user meta and not the meta of the username?

This is my author template:

<?php get_header(); ?>  

<div class="author-name">
<?php echo get_the_author_meta('first_name'); ?>
<?php echo get_the_author_meta('last_name'); ?> 
<?php echo get_user_role('user_role'); ?>
</div>

<div class="author-information">
Username: <?php echo get_the_author('user_nicename'); ?>
</div>

<?php get_footer(); ?>  

Solution

You must supply the User ID when using get_the_author_meta() to get a different user than the one in the loop or currently logged in.

Assuming username1 and username2 are actual usernames in the users database table you can get the username from the URL by using the following snippet:

$username_from_url = basename( get_permalink() );

And then:

$user = get_user_by( 'login', $username_from_url );

Now you have the full $user object with ID and everything.

Edit: complete solution

User visits an URL with the following pattern /page/somename where somename corresponds to the user´s user_nicename in the database table users.

<?php
    $username_from_url = basename( get_permalink() );
    $user = get_user_by( 'slug', $username_from_url );

    echo get_the_author_meta( 'first_name', $user->ID );
    echo get_the_author_meta( 'last_name', $user->ID );

    foreach ($user->roles as $role) {
        // You can also use get_role( $role ) to get more data on the role
        echo $role;
    }

    echo __( "Username:" ) . " " . $user->user_nicename;
?>


Answered By - Niklas Brunberg
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing