PluginProbe
Gianism / 3.0.1
Gianism v3.0.1
4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.4.0 5.0.0 5.0.1 5.0.2 5.1.0 5.2.1 5.2.2 5.3.0 6.0.0 6.0.1 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 65 releases
gianism / templates / advanced.php

advanced.php in Gianism 3.0.1, at templates/advanced.php

145 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 &quot;read an article&quot; 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( sprintf(
28 $code,
29 $this->_( 'URL which user will be redirected' ),
30 $this->_( 'Action name fired after authentication' ),
31 $this->_( 'Additional arguments passed to hook function' )
32 ) );
33 ?>
34 </pre>
35
36 <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>
37
38 <pre class="brush: php">
39 <?php
40 $code = <<<'EOS'
41 // %s
42 add_action( 'my_facebook_auth_hook', 'my_facebook_auth', 10, 3 );
43
44 /**
45 * %s
46 * @param Facebook\Facebook $facebook
47 * @param array $args
48 * @param string $token
49 */
50 function my_facebook_auth( $facebook, $args $token ) {
51 // %s
52 if(isset(\$args['post_id']) && (\$post = get_post(\$args['post_id']))){
53 try{
54 $facebook->post("/me/feed", [
55 "message" => "%s",
56 "link" => get_permalink($post->ID),
57 "name" => get_the_title($post->ID),
58 "description" => strip_tags($post->post_content),
59 "action" => json_encode( [
60 "name" => get_bloginfo( 'name' ),
61 "link" => home_url( '/' )
62 ] )
63 ], $token);
64 } catch ( FacebookApiException \$e ) {
65 // %s
66 }
67 }
68 // %s
69 }
70 EOS;
71 echo esc_html( sprintf( $code,
72 $this->_( 'Register action hook which you registered above.' ),
73 $this->_( 'This funciton will be executed after authentication' ),
74 $this->_( 'Check if argument is propery passed and if post exists.' ),
75 $this->_( 'Read an artcile.' ),
76 $this->_( 'Do error handling if you wish.' ),
77 $this->_( 'This funcion been executed, user will be redirected.' ) ) );
78 ?>
79 </pre>
80
81 <p class="notice"><?php printf( $this->_( '<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>.' ), 'https://developers.facebook.com/docs/reference/php/' ); ?></p>
82
83
84 <h3><?php $this->e( 'Make tweet with your account' ); ?></h3>
85
86 <p class="description"><?php $this->e( 'You can make tweet by registered application\'s account.' ); ?></p>
87
88 <pre class="brush: php">
89 <?php
90 $code = <<<EOS
91 gianism_update_twitter_status( '%s' );
92 EOS;
93 echo esc_html( sprintf( $code, $this->_( 'Hello, my followers. I updated new post.' ) ) );
94 ?>
95 </pre>
96
97 <p><?php $this->e( 'This function itself makes no sense, but you can use some hook to make auto post.' ); ?></p>
98
99 <pre class="brush: php">
100 <?php
101 $code = <<<EOS
102 /**
103 * Tweet when post is published.
104 *
105 * @param string \$new_status
106 * @param string \$old_status
107 * @param int \$post
108 */
109 function _my_gianism_publish_tweet(\$new_status, \$old_status, \$post){
110 // If post status is changed to publish, tweet.
111 if('publish' == \$new_status && 'post' == \$post->post->type){
112 switch(\$old_status){
113 case 'draft':
114 case 'pending':
115 case 'auto-draft':
116 case 'future':
117 \$url = wp_get_shortlink(\$post->ID);
118 \$author = get_the_author_meta('display_name', \$post->post_author);
119 \$string = sprintf('%s',
120 \$author, \$post->post_title, \$url);
121 break;
122 }
123 }
124 }
125 // Hook on post status transition
126 add_action('transition_post_status', '_my_gianism_publish_tweet', 10, 3);
127 EOS;
128 echo esc_html( sprintf( $code, $this->_( '%1$s pulbished %2$s. Please visit %3$s' ) ) );
129 ?>
130 </pre>
131
132 <p class="notice"><?php $this->e( '<strong>Note:</strong> Currently, only twitter application\'s account(thus, admin\'s twitter account) can tweet.' ); ?></p>
133
134
135
136 <h3><?php $this->e( 'More Detailed Information' ); ?></h3>
137 <p>
138 <?php printf(
139 $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>.' ),
140 gianism_utm_link( 'https://gianism.info/', [
141 'utm_medium' => 'advanced',
142 ] )
143 ); ?>
144 </p>
145