| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) or die(); |
| 4 |
|
| 5 |
/** @var \Gianism\UI\SettingScreen $this */ |
| 6 |
|
| 7 |
?> |
| 8 |
|
| 9 |
<h3><?php $this->e( 'Get publish permission of Facebook account' ); ?></h3> |
| 10 |
|
| 11 |
<p class="description"><?php $this->e( 'You can get permission to publish information to user\'s Facebook wall.' ); ?></p> |
| 12 |
|
| 13 |
<p><?php $this->e( 'For example, display link to post action "read an article" to Facebook wall.' ); ?></p> |
| 14 |
|
| 15 |
<pre class="brush: php"> |
| 16 |
<?php |
| 17 |
$code = <<<EOS |
| 18 |
<?php |
| 19 |
\$url = gianism_get_facebook_publish_permission_link( |
| 20 |
\$redirect_url, //%s, |
| 21 |
'my_facebook_auth_hook', //%s |
| 22 |
array('post_id' => 10), //%s |
| 23 |
); |
| 24 |
?> |
| 25 |
<a href="<?php echo esc_url(\$url); ?>" rel="nofollow">Publish to Facebook</a> |
| 26 |
EOS; |
| 27 |
echo esc_html( |
| 28 |
sprintf( |
| 29 |
$code, |
| 30 |
$this->_( 'URL which user will be redirected' ), |
| 31 |
$this->_( 'Action name fired after authentication' ), |
| 32 |
$this->_( 'Additional arguments passed to hook function' ) |
| 33 |
) |
| 34 |
); |
| 35 |
?> |
| 36 |
</pre> |
| 37 |
|
| 38 |
<p><?php $this->e( 'If user click this link, he will be redirected to Facebook and see permission dialog. After authentication, the aciton you registered will be fired. Now hook on it and execute publication.' ); ?></p> |
| 39 |
|
| 40 |
<pre class="brush: php"> |
| 41 |
<?php |
| 42 |
$code = <<<'EOS' |
| 43 |
// %s |
| 44 |
add_action( 'my_facebook_auth_hook', 'my_facebook_auth', 10, 3 ); |
| 45 |
|
| 46 |
/** |
| 47 |
* %s |
| 48 |
* @param Facebook\Facebook $facebook |
| 49 |
* @param array $args |
| 50 |
* @param string $token |
| 51 |
*/ |
| 52 |
function my_facebook_auth( $facebook, $args $token ) { |
| 53 |
// %s |
| 54 |
if(isset(\$args['post_id']) && (\$post = get_post(\$args['post_id']))){ |
| 55 |
try{ |
| 56 |
$facebook->post("/me/feed", [ |
| 57 |
"message" => "%s", |
| 58 |
"link" => get_permalink($post->ID), |
| 59 |
"name" => get_the_title($post->ID), |
| 60 |
"description" => strip_tags($post->post_content), |
| 61 |
"action" => json_encode( [ |
| 62 |
"name" => get_bloginfo( 'name' ), |
| 63 |
"link" => home_url( '/' ) |
| 64 |
] ) |
| 65 |
], $token); |
| 66 |
} catch ( FacebookApiException \$e ) { |
| 67 |
// %s |
| 68 |
} |
| 69 |
} |
| 70 |
// %s |
| 71 |
} |
| 72 |
EOS; |
| 73 |
echo esc_html( |
| 74 |
sprintf( |
| 75 |
$code, |
| 76 |
$this->_( 'Register action hook which you registered above.' ), |
| 77 |
$this->_( 'This funciton will be executed after authentication' ), |
| 78 |
$this->_( 'Check if argument is propery passed and if post exists.' ), |
| 79 |
$this->_( 'Read an artcile.' ), |
| 80 |
$this->_( 'Do error handling if you wish.' ), |
| 81 |
$this->_( 'This funcion been executed, user will be redirected.' ) |
| 82 |
) |
| 83 |
); |
| 84 |
?> |
| 85 |
</pre> |
| 86 |
|
| 87 |
<p class="notice"> |
| 88 |
<?php |
| 89 |
echo wp_kses_post( |
| 90 |
sprintf( |
| 91 |
// translators: %s is URL. |
| 92 |
__( '<strong>Note:</strong> <code>$facebook</code> object is instance of Facebook class which is part of Facebook PHP SDK. To know what you can do with it, read the <a href="%s">documentation</a>.', 'wp-gianism' ), |
| 93 |
'https://developers.facebook.com/docs/reference/php/' |
| 94 |
) |
| 95 |
); |
| 96 |
?> |
| 97 |
</p> |
| 98 |
|
| 99 |
|
| 100 |
<h3><?php $this->e( 'Make tweet with your account' ); ?></h3> |
| 101 |
|
| 102 |
<p class="description"><?php $this->e( 'You can make tweet by registered application\'s account.' ); ?></p> |
| 103 |
|
| 104 |
<pre class="brush: php"> |
| 105 |
<?php |
| 106 |
$code = <<<EOS |
| 107 |
gianism_update_twitter_status( '%s' ); |
| 108 |
EOS; |
| 109 |
echo esc_html( sprintf( $code, $this->_( 'Hello, my followers. I updated new post.' ) ) ); |
| 110 |
?> |
| 111 |
</pre> |
| 112 |
|
| 113 |
<p><?php $this->e( 'This function itself makes no sense, but you can use some hook to make auto post.' ); ?></p> |
| 114 |
|
| 115 |
<pre class="brush: php"> |
| 116 |
<?php |
| 117 |
$code = <<<EOS |
| 118 |
/** |
| 119 |
* Tweet when post is published. |
| 120 |
* |
| 121 |
* @param string \$new_status |
| 122 |
* @param string \$old_status |
| 123 |
* @param int \$post |
| 124 |
*/ |
| 125 |
function _my_gianism_publish_tweet(\$new_status, \$old_status, \$post){ |
| 126 |
// If post status is changed to publish, tweet. |
| 127 |
if('publish' == \$new_status && 'post' == \$post->post->type){ |
| 128 |
switch(\$old_status){ |
| 129 |
case 'draft': |
| 130 |
case 'pending': |
| 131 |
case 'auto-draft': |
| 132 |
case 'future': |
| 133 |
\$url = wp_get_shortlink(\$post->ID); |
| 134 |
\$author = get_the_author_meta('display_name', \$post->post_author); |
| 135 |
\$string = sprintf('%s', |
| 136 |
\$author, \$post->post_title, \$url); |
| 137 |
break; |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
// Hook on post status transition |
| 142 |
add_action('transition_post_status', '_my_gianism_publish_tweet', 10, 3); |
| 143 |
EOS; |
| 144 |
echo esc_html( sprintf( $code, $this->_( '%1$s pulbished %2$s. Please visit %3$s' ) ) ); |
| 145 |
?> |
| 146 |
</pre> |
| 147 |
|
| 148 |
<p class="notice"><?php $this->e( '<strong>Note:</strong> Currently, only twitter application\'s account(thus, admin\'s twitter account) can tweet.' ); ?></p> |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
<h3><?php $this->e( 'More Detailed Information' ); ?></h3> |
| 153 |
<p> |
| 154 |
<?php |
| 155 |
printf( |
| 156 |
$this->_( 'You can do many things with SNS API. But every solution is very specific and little bit difficult. If you need more, please visit our <a target="_blank" href="%s">support site</a>.' ), |
| 157 |
gianism_utm_link( |
| 158 |
'https://gianism.info/', |
| 159 |
[ |
| 160 |
'utm_medium' => 'advanced', |
| 161 |
] |
| 162 |
) |
| 163 |
); |
| 164 |
?> |
| 165 |
</p> |
| 166 |
|