Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helpers for common checks #37

Open
kraftner opened this issue Oct 25, 2016 · 4 comments
Open

Helpers for common checks #37

kraftner opened this issue Oct 25, 2016 · 4 comments

Comments

@kraftner
Copy link
Member

There are plenty of places where things like "Does the user have an avatar set?" or "Is this upload on/from the profile page?" are checked. Currently a lot of these checks are just C&P. Maybe it is worth having some central helper that does this in a reusable way.

@franz-josef-kaiser
Copy link
Member

Added to the Backlog until we have a definitive list.

@franz-josef-kaiser
Copy link
Member

There might be some class:

class AvatarMeta {

    const HAS_AVATAR = 1;
    const NO_AVATAR = 2;

    private $key;

    /** @type string $key */
    public function __construct( $key ) {
        $this->key = $key;
    }

    public function getKey() {
        return $this->key;
    }

    /** @type int $userID */
    public function hasAvatar( $userID ) {
        $meta = get_user_meta( $userID, $this->key, true );
        return empty( $meta )
            ? self::HAS_AVATAR
            : self::NO_AVATAR;
    }
}

This would allow for repetitive checks against the constant:

$meta = new AvatarMeta( apply_filters( 'wcm.avatar.meta_key', 'user_avatar' ) );
foreach ( $users as $user ) {
    var_dump( $meta->hasAvatar( $user->ID ) === AvatarMeta::HAS_AVATAR );
}

This would also remove the necessity of putting the key into the AvatarExistsLimitService.php. We still would need at least another use case and a clean up before taking this on.

@kraftner
Copy link
Member Author

Okay let's start with a list of things that are being checked again and again all over the place that would be worth having in a unified way:

Are we on a profile page or doing something initiated from there? (either the users own one or from someone else)

Some of these checks directly ask WP (e.g. using get_current_screen()->base but some rely on data that can't be trusted like from $_POST so be careful to properly handle those different cases.

Is this profile from the current user or some other?

Has a user a custom avatar set?

@kraftner
Copy link
Member Author

Okay now that I've found #59, #60 and #64 it has become more and more obvious that we need some central way to check all those things. Way to much duplication happening already and to fix those bugs it would become even worse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants