-
Notifications
You must be signed in to change notification settings - Fork 80
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
Enable Mastodon Apps: support profile editing, blog user #788
Changes from 26 commits
71fc2c8
29db809
8ef9566
6fbc881
0737a74
a33cbd2
9195851
0813733
9d33f3d
59fe2eb
394063d
daa12f7
c624802
c371b97
074684f
a86d145
278a1b2
9e615cc
ba9c3f0
2950898
a19f59b
f1eb441
9607002
0367637
d357d86
6803bdb
c4b65bc
864cb01
aa4b568
03f23d1
a2bed42
5bb67b4
750b039
287daec
ce2316d
d4084d6
404588b
fcdf8e1
365af49
f5a55b4
d022392
a600761
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,8 +205,8 @@ public function get_preferred_username() { | |
* @return array The User-Icon. | ||
*/ | ||
public function get_icon() { | ||
// try site icon first | ||
$icon_id = get_option( 'site_icon' ); | ||
// try site_logo, falling back to site_icon, first | ||
$icon_id = get_option( 'site_logo', get_option( 'site_icon' ) ); | ||
|
||
// try custom logo second | ||
if ( ! $icon_id ) { | ||
|
@@ -389,11 +389,37 @@ public function get_indexable() { | |
} | ||
|
||
/** | ||
* Get the User-Hashtags. | ||
* Update User profile attributes | ||
* | ||
* @param string $key The attribute to update. | ||
* @param mixed $value The new value. Possible values: | ||
* - name: The User-Name. | ||
* - summary: The User-Description. | ||
* - icon: The User-Icon. | ||
* - header: The User-Header-Image. | ||
* @return bool True if the attribute was updated, false otherwise. | ||
*/ | ||
public function save( $key, $value ) { | ||
switch ( $key ) { | ||
case 'name': | ||
return \update_option( 'blogname', $value ); | ||
case 'summary': | ||
return \update_option( 'blogdescription', $value ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, maybe rather with an override? |
||
case 'icon': | ||
return \update_option( 'site_logo', $value ) && \update_option( 'site_icon', $value ); | ||
case 'header': | ||
return \update_option( 'activitypub_header_image', $value ); | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Get the User - Hashtags . | ||
* | ||
* @see https://docs.joinmastodon.org/spec/activitypub/#Hashtag | ||
* | ||
* @return array The User-Hashtags. | ||
* @return array The User - Hashtags . | ||
*/ | ||
public function get_tag() { | ||
$hashtags = array(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,14 @@ public function get_preferred_username() { | |
} | ||
|
||
public function get_icon() { | ||
$icon = get_user_option( 'activitypub_icon', $this->_id ); | ||
if ( $icon ) { | ||
return array( | ||
'type' => 'Image', | ||
'url' => $icon, | ||
); | ||
} | ||
|
||
$icon = \esc_url( | ||
\get_avatar_url( | ||
$this->_id, | ||
|
@@ -150,20 +158,15 @@ public function get_icon() { | |
|
||
public function get_image() { | ||
$header_image = get_user_option( 'activitypub_header_image', $this->_id ); | ||
$image_url = null; | ||
|
||
if ( $header_image ) { | ||
pfefferle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$image_url = \wp_get_attachment_url( $header_image ); | ||
} | ||
|
||
if ( ! $image_url && \has_header_image() ) { | ||
$image_url = \get_header_image(); | ||
if ( ! $header_image && \has_header_image() ) { | ||
$header_image = \get_header_image(); | ||
} | ||
|
||
if ( $image_url ) { | ||
if ( $header_image ) { | ||
return array( | ||
'type' => 'Image', | ||
'url' => esc_url( $image_url ), | ||
'url' => esc_url( $header_image ), | ||
); | ||
} | ||
|
||
|
@@ -277,4 +280,50 @@ public function get_indexable() { | |
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Update User profile attributes | ||
* | ||
* @param string $key The attribute to update. | ||
* @param mixed $value The new value. | ||
* Possible values: | ||
* - name: The User-Name. | ||
* - summary: The User-Description. | ||
* - icon: The User-Icon. | ||
* - header: The User-Header-Image. | ||
* @return bool True if the attribute was updated, false otherwise. | ||
*/ | ||
public function save( $key, $value ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rename that, so that we will be able to have a generic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to have dedicated functions. I went in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for maybe not being precise enough: My proposal was to simply not use the generic |
||
switch ( $key ) { | ||
case 'name': | ||
$userdata = [ 'ID' => $this->_id, 'display_name' => $value ]; | ||
return \wp_update_user( $userdata ); | ||
case 'summary': | ||
return \update_user_meta( $this->_id, 'description', $value ); | ||
case 'icon': | ||
$maybe_id = (int) $value; | ||
// we were passed an integer, which should be an attachment ID. | ||
if ( $maybe_id ) { | ||
$image = \wp_get_attachment_image_src( $maybe_id, 'full' ); | ||
if ( ! $image ) { | ||
return false; | ||
} | ||
$value = \wp_get_attachment_url( $maybe_id ); | ||
} | ||
return update_user_option( $this->_id, 'activitypub_icon', $value ); | ||
case 'header': | ||
$maybe_id = (int) $value; | ||
// we were passed an integer, which should be an attachment ID. | ||
if ( $maybe_id ) { | ||
$image = wp_get_attachment_image( $maybe_id, 'full' ); | ||
if ( ! $image ) { | ||
return false; | ||
} | ||
$value = wp_get_attachment_url( $maybe_id ); | ||
} | ||
return update_user_option( $this->_id, 'activitypub_header_image', $value ); | ||
default: | ||
return false; | ||
} | ||
} | ||
} |
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.
That seems a bit dangerous, you might not realize that you're changing the whole blog name. Should this just be an override?
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.
It's tricky. Once we introduce an override, now you have to go into wp-admin to also change the blogname, if that's what you want to do, and/or being able to delete the override, falling back to the blogname, which you can now only edit in wp-admin. If you want a consistent name, you have to go to wp-admin. I'm thinking more of somebody who never wants to go there at all.
I'm erring on the side of consistency, not on the side of safety. And if somebody doesn't like the change they made, they can go back and change it again, without having to go to wp-admin.
At least that's the kind of thinking I was doing when I made it behave this way