PHP Help

Chat about just about anything else
Post Reply
User avatar
wizzybang
Level 1
Level 1
Posts: 43
Joined: Fri Nov 10, 2017 6:57 pm

PHP Help

Post by wizzybang » Sat Nov 25, 2017 8:42 pm

Is there anyone around who has any PHP knowledge who could help me with a niggling issue, or more of an OCD issue lol?
Success is the ability to go from one failure to the next without any loss of enthusiasm.....

User avatar
JoeFootball
Level 6
Level 6
Posts: 1262
Joined: Tue Nov 24, 2009 1:52 pm
Location: /home/usa/mn/minneapolis/joe

Re: PHP Help

Post by JoeFootball » Mon Nov 27, 2017 11:52 am

wizzybang wrote:... help me with a niggling issue, or more of an OCD issue ...
Perhaps if you could provide more information on your issue, you may get more responses. :) I do have some PHP experience, but admit that I'm no wizard.

Joe

User avatar
wizzybang
Level 1
Level 1
Posts: 43
Joined: Fri Nov 10, 2017 6:57 pm

Re: PHP Help

Post by wizzybang » Mon Nov 27, 2017 4:15 pm

Thanks for the repsonse Joe, the detail always helps sorry!!. Basically I've got a self hosted wordpress blog which utilizes a tweet button for sharing. Basically I'm not a fan of the way it constructs the tweet. I've tried contacting the people who wrote the original script but no joy.

This tweet is constructed like this:
Tweet text goes here via @username https://******.com/ralf-little-destroys-jeremy-hunts-lies-andrew-marr-show/
I would like to move the via @username to the end so it looks like this:
Topic Title Text https://******.com/ralf-little-destroys-jeremy-hunts-lies-andrew-marr-show/ via @username
This is the code that constructs the tweet:

Code: Select all

'twitter' => array(
'url' => 'https://twitter.com/intent/tweet?text='. $post_title . $share_twitter_username .'&url='. $post_link,
'text' => esc_html__( 'Twitter', 'jannah' ),
),
This is the $share_twitter_username code that constructs and calls the via @username:

Code: Select all

$share_twitter_username = jannah_get_option( 'share_twitter_username' ) ? ' via %40'.jannah_get_option( 'share_twitter_username' ) : '';
In the first code that constructs the tweet I have tried moving $share_twitter_username to the end but it doesn't work, it just breaks the tweet, I'm not sure if I'm missing some PHP part.

Really hope it makes sense.

Thanks in advance.

Many thanks in advance and I hope the above makes sense.
Success is the ability to go from one failure to the next without any loss of enthusiasm.....

User avatar
JoeFootball
Level 6
Level 6
Posts: 1262
Joined: Tue Nov 24, 2009 1:52 pm
Location: /home/usa/mn/minneapolis/joe

Re: PHP Help

Post by JoeFootball » Tue Nov 28, 2017 8:39 am

wizzybang wrote:In the first code that constructs the tweet I have tried moving $share_twitter_username to the end but it doesn't work, it just breaks the tweet, I'm not sure if I'm missing some PHP part.
Hmmm, that was going to be my answer. Perhaps it's a limitation of the Twitter API that requires certain elements to be in a certain order?

If you were to echo $share_twitter_username after that last line of code, perhaps its content would yield some ideas? Perhaps you take the resulting $share_twitter_username and further manipulate it to your liking?

Joe

User avatar
wizzybang
Level 1
Level 1
Posts: 43
Joined: Fri Nov 10, 2017 6:57 pm

Re: PHP Help

Post by wizzybang » Tue Nov 28, 2017 6:19 pm

Cheers for the reply.

I've now noticed that when I do some testing once I've manipulated it, the whole URL gets screwed up so for some reason it looks like this:

bangsthought.com/twang-barney-rubble/%20via%20%40BangsThought

So instead of @Username at the end its just garbage, but when you look at the share box once called the garbage at the end isn't actually displayed its being stripped somewhere along the lines. I only found it by accident by looking at links clicked on the website. So you're probably right in terms of how the twitter API handles the code once I've played around with it, back to the drawing board I think!!
Success is the ability to go from one failure to the next without any loss of enthusiasm.....

Mick-Cork
Level 2
Level 2
Posts: 84
Joined: Sun Mar 23, 2014 10:10 pm
Location: West Cork & London

Re: PHP Help

Post by Mick-Cork » Tue Nov 28, 2017 11:09 pm

I got curious and did a bit of digging. Have a look at the structure of this URL (and click on it)...

https://twitter.com/intent/tweet?via=Ba ... marr-show/

The Tweet button/link parameters allow for more than just 'url' and 'text' in the HTTP Get method - https://dev.twitter.com/web/tweet-button/parameters. You can also add a 'via' parameter. The API appears to sequence the share output in the order that you're after, ie: Text, Link, @Username regardless of the order of those parameters in the URL.

The current PHP seems to be wrapping the @username into the 'text' parameter which I think is the wrong way to approach it. I haven't got an immediate way to test this but you could try playing with the code along the following lines:

Code: Select all

'twitter' => array(
'url' => 'https://twitter.com/intent/tweet?via='.$share_twitter_username.'&text='. $post_title .'&url='. $post_link,
'text' => esc_html__( 'Twitter', 'jannah' ),
),


I might have that syntax slightly wrong (the single quotes and dots around $share_twitter_username) so you might have to try a few variants. Anyway, hope that at least points you in the right direction - see how you get on?

User avatar
wizzybang
Level 1
Level 1
Posts: 43
Joined: Fri Nov 10, 2017 6:57 pm

Re: PHP Help

Post by wizzybang » Fri Jan 26, 2018 11:25 am

Hi Mick,

Thanks for the message, very much appreciated. I’ve not had a chance to look at it been snowed under with work, but will try and have a look this weekend.

Cheers

Sam
Success is the ability to go from one failure to the next without any loss of enthusiasm.....

Post Reply

Return to “Open chat”