-
-
Notifications
You must be signed in to change notification settings - Fork 6
Refurbish #27
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
Closed
Refurbish #27
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ed55b23
refurbish
pfefferle 0b492e9
update composer settings
pfefferle 56ac9fa
fix docker for M1 Processors
pfefferle c4f16d4
rename resource identifier
pfefferle 5bf1388
Merge branch 'main' into refurbish
pfefferle 6b139ea
fix PHPCS issue
pfefferle d87b8de
Merge branch 'main' into refurbish
pfefferle 87e4c0b
Merge branch 'main' into refurbish
pfefferle de3cde4
Merge branch 'main' into refurbish
pfefferle fc2efb6
class-admin.php aktualisieren
pfefferle 2e1df81
profile-settings.php aktualisieren
pfefferle aa4ac43
profile-settings.php aktualisieren
pfefferle 30fa6c9
class-admin.php aktualisieren
pfefferle 152a5f0
class-admin.php aktualisieren
pfefferle 8aa56c9
profile-settings.php aktualisieren
pfefferle 2f072db
class-admin.php aktualisieren
pfefferle db6bc4d
class-admin.php aktualisieren
pfefferle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| <?php | ||
|
|
||
| namespace Webfinger; | ||
|
|
||
| use WP_User_Query; | ||
|
|
||
| class Admin { | ||
|
|
||
| /** | ||
| * Initialize the class, registering WordPress hooks. | ||
| */ | ||
| public static function init() { | ||
| add_action( 'show_user_profile', array( static::class, 'add_profile' ) ); | ||
|
|
||
| // Add the save action to user's own profile editing screen update. | ||
| add_action( | ||
| 'personal_options_update', | ||
| array( static::class, 'update_user_meta' ) | ||
| ); | ||
|
|
||
| // Add the save action to user profile editing screen update. | ||
| add_action( | ||
| 'edit_user_profile_update', | ||
| array( static::class, 'update_user_meta' ) | ||
| ); | ||
|
|
||
| add_filter( | ||
| 'user_profile_update_errors', | ||
| array( static::class, 'maybe_show_errors' ), | ||
| 10, | ||
| 3 | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Load settings template | ||
| * | ||
| * @param stdClass $user The WordPress user | ||
| * | ||
| * @return void | ||
| */ | ||
| public static function add_profile( $user ) { | ||
| load_template( dirname( __FILE__ ) . '/../templates/profile-settings.php', true, array( 'user' => $user ) ); | ||
| } | ||
|
|
||
| /** | ||
| * The save action. | ||
| * | ||
| * @param int $user_id the ID of the current user. | ||
| * | ||
| * @return bool Meta ID if the key didn't exist, true on successful update, false on failure. | ||
| */ | ||
| public static function update_user_meta( $user_id ) { | ||
| // check that the current user have the capability to edit the $user_id | ||
| if ( ! current_user_can( 'edit_user', $user_id ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| // Verify nonce to prevent CSRF | ||
| if ( | ||
| ! isset( $_POST['webfinger_profile_nonce'] ) || | ||
| ! wp_verify_nonce( $_POST['webfinger_profile_nonce'], 'webfinger_profile_settings' ) | ||
| ) { | ||
| return false; | ||
| } | ||
|
|
||
| if ( ! isset( $_POST['webfinger_resource'] ) ) { | ||
| return false; | ||
| } | ||
| if ( empty( $_POST['webfinger_resource'] ) ) { | ||
| delete_user_meta( $user_id, 'webfinger_resource' ); | ||
| return false; | ||
| } | ||
|
|
||
| $valid = self::is_valid_webfinger_resource( $_POST['webfinger_resource'], $user_id ); | ||
|
|
||
| if ( ! $valid ) { | ||
| return; | ||
| } | ||
|
|
||
| $webfinger = sanitize_title( $_POST['webfinger_resource'], true ); | ||
|
|
||
| // create/update user meta for the $user_id | ||
| update_user_meta( | ||
| $user_id, | ||
| 'webfinger_resource', | ||
| $webfinger | ||
| ); | ||
|
|
||
| return $webfinger; | ||
| } | ||
|
|
||
| /** | ||
| * Check if an error should be shown | ||
| * | ||
| * @param WP_Error $errors WP_Error object (passed by reference). | ||
| * @param bool $update Whether this is a user update. | ||
| * @param stdClass $user User object (passed by reference). | ||
| * | ||
| * @return array Updated list of errors | ||
| */ | ||
| public static function maybe_show_errors( $errors, $update, $user ) { | ||
pfefferle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Verify nonce for CSRF protection | ||
| if ( ! isset( $_POST['webfinger_profile_nonce'] ) || ! wp_verify_nonce( $_POST['webfinger_profile_nonce'], 'webfinger_profile_settings' ) ) { | ||
| return $errors; | ||
| } | ||
| if ( ! isset( $_POST ) || ! isset( $_POST['webfinger_resource'] ) ) { | ||
| return $errors; | ||
| } | ||
|
|
||
| $valid = self::is_valid_webfinger_resource( $_POST['webfinger_resource'], $user->ID ); | ||
|
|
||
| if ( ! $valid ) { | ||
| $errors->add( 'webfinger_resource', __( 'WebFinger resource is already in use by a different user', 'webfinger' ) ); | ||
| } | ||
|
|
||
| return $errors; | ||
| } | ||
|
|
||
| /** | ||
| * Check if the WebFinger resource is valid | ||
| * | ||
| * @param string $resource The WebFinger resource | ||
| * @param int $user_id The user ID | ||
| * | ||
| * @return boolean | ||
| */ | ||
| public static function is_valid_webfinger_resource( $resource, $user_id ) { | ||
| $webfinger = sanitize_title( $resource, true ); | ||
|
|
||
| $args = array( | ||
| 'meta_key' => 'webfinger_resource', | ||
| 'meta_value' => $webfinger, | ||
| 'meta_compare' => '=', | ||
| 'exclude' => $user_id, | ||
| ); | ||
|
|
||
| // check if already exists | ||
| $user_query = new WP_User_Query( $args ); | ||
| $results = $user_query->get_results(); | ||
|
|
||
| return empty( $results ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct access to
$_POSTwithout nonce verification creates a CSRF vulnerability. Add nonce verification before processing the form data.