Skip to content

Allowing user to specify full URL to social page in widget#6016

Closed
howtoaddict wants to merge 2 commits intoAutomattic:masterfrom
howtoaddict:master
Closed

Allowing user to specify full URL to social page in widget#6016
howtoaddict wants to merge 2 commits intoAutomattic:masterfrom
howtoaddict:master

Conversation

@howtoaddict
Copy link
Copy Markdown

Previously user could only specify username on Social media. This caused
problems with some sites like Youtube... on which you can have both User
(http://youtube.com/u/Username) and Channel
(http://youtube.com/c/Channel).

Previously user could only specify username on Social media. This caused
problems with some sites like Youtube... on which you can have both User
(http://youtube.com/u/Username) and Channel
(http://youtube.com/c/Channel).
@jeherve jeherve added [Feature] Extra Sidebar Widgets [Pri] Low [Status] Needs Review This PR is ready for review. Enhancement Changes to an existing feature — removing, adding, or changing parts of it labels Jan 9, 2017
@jeherve jeherve added this to the 4.6 milestone Jan 9, 2017
@jeherve
Copy link
Copy Markdown
Member

jeherve commented Jan 9, 2017

Fixes #6010

@jeherve jeherve modified the milestones: 2/17 - February, 4.7.0 - March 2017 Jan 30, 2017
@samhotchkiss samhotchkiss removed this from the 4.7.0 - March 2017 milestone Feb 3, 2017
Copy link
Copy Markdown
Contributor

@eliorivero eliorivero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @howtoaddict for the work on this. This works well and it's a very necessary addition.
I'm blocking this for now mainly due to the translation issue but the other one should be addressed too for more concise code.
Thank you!

$html[ $index ] =
'<a href="' . $username
. '" class="genericon genericon-' . $service . '" target="_blank"><span class="screen-reader-text">'
. 'View our profile on '. $service_name
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text must be made available for translation like this:

/* Translators: the placeholder is a social network name. */
. esc_html( sprintf( __( 'View our profile on %s', 'jetpack' ), $service_name ) )


/** Check if full URL entered in configuration, use it instead of tinkering **/
if ( substr( $username, 0, 5 ) === "http:"
|| substr( $username, 0, 6 ) === "https:"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be replaced with

if ( preg_match( '#^https?://#', $username ) ) {

@eliorivero eliorivero added [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Feb 6, 2017
@howtoaddict
Copy link
Copy Markdown
Author

@eliorivero updated

@jeherve jeherve added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Feb 8, 2017
@georgestephanis
Copy link
Copy Markdown
Contributor

Would this change let someone paste in a link to "http://hackmysite.tld" and have it show with the social media icon of the relevant service? I'm not sure if it may be wise to build in some sort of domain name verification, or if that's being overly and unnecessarily cautious.

@jeherve jeherve added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Feb 8, 2017
@eliorivero
Copy link
Copy Markdown
Contributor

Yeah, George is right. We shouldn't allow people to do evil. Maybe something like this would be enough?

is_valid_social_network( $url ) {
    return in_array( parse_url( $url, PHP_URL_HOST ), array(
        'twitter.com',
        'facebook.com',
        etc etc
    ) );
}

@howtoaddict
Copy link
Copy Markdown
Author

@georgestephanis @eliorivero yeah... like you can't use other components in Jetpack to do exactly that - put COMPLETELY custom HTML.

I've invested time trying to help and this is obviously beneficial and requested feature. If you guys don't want to add it don't merge it. I'm giving up on this pull request.

@dereksmart
Copy link
Copy Markdown
Contributor

Right, @howtoaddict has a very valid point. There are many many places throughout WordPress core and Jetpack features that allow inserting custom HTML. Someone could do the same thing with a simple WordPress text widget. I don't think it's very realistic to expect us to filter all of these instances.

@eliorivero's suggestion does seem pretty reasonable in theory, but that would require us having to create an index of full/shorthand/custom social media URLs that are used everywhere. IMO more effort than it's worth.

@eliorivero eliorivero added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Feb 23, 2017
@eliorivero
Copy link
Copy Markdown
Contributor

Let's 🐑 this. Thanks @howtoaddict 👍

@zinigor
Copy link
Copy Markdown
Contributor

zinigor commented Feb 27, 2017

Closing this in favour of #6508, thanks for the idea and the implementation!

@zinigor zinigor closed this Feb 27, 2017
@zinigor zinigor removed the [Status] Ready to Merge Go ahead, you can push that green button! label Feb 27, 2017
singerb pushed a commit that referenced this pull request Mar 8, 2017
* Allowing user to specify full URL to social page in widget

Previously user could only specify username on Social media. This caused
problems with some sites like Youtube... on which you can have both User
(http://youtube.com/u/Username) and Channel
(http://youtube.com/c/Channel).

* Changes resulting from code review

#6016 (review)

* Sanitized URLs, fixed screen reader text for predefined URLs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Extra Sidebar Widgets [Pri] Low Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants