PluginProbe
Social Media Auto Poster – Schedule & Publish to Buffer / 6.0.0
Social Media Auto Poster – Schedule & Publish to Buffer v6.0.0
6.2.3 6.2.2 6.2.1 6.2.0 6.1.2 6.1.1 6.1.0 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 All 124 releases
wp-to-buffer / includes / functions.php

functions.php in Social Media Auto Poster – Schedule & Publish to Buffer 6.0.0, at includes/functions.php

44 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WordPress to Buffer general plugin functions.
4 *
5 * @package WP_To_Buffer
6 * @author WP Zinc
7 */
8
9 /**
10 * Saves the new access token, refresh token and its expiry, and schedules
11 * a WordPress Cron event to refresh the token on expiry.
12 *
13 * @since 6.0.0
14 *
15 * @param array $result New Access Token, Refresh Token and Expiry timestamp.
16 * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
17 * @param string $existing_access_token Existing Access Token.
18 */
19 function wp_to_buffer_update_credentials( $result, $client_id, $existing_access_token ) {
20
21 // Get Plugin instance.
22 $wp_to_buffer = WP_To_Buffer::get_instance();
23
24 // Get the account ID based on the existing access token.
25 $account_id = $wp_to_buffer->get_class( 'settings' )->get_account_id_by_access_token( $existing_access_token );
26
27 // Bail if the account ID is not found.
28 if ( empty( $account_id ) ) {
29 return;
30 }
31
32 // Update the access and refresh tokens in the Plugin settings.
33 $wp_to_buffer->get_class( 'settings' )->update_account_credentials(
34 $result['access_token'],
35 $result['refresh_token'],
36 $result['token_expires'],
37 $account_id
38 );
39
40 }
41
42 // Update Access Token when refreshed by the API class.
43 add_action( 'wp_to_buffer_pro_api_refresh_token', 'wp_to_buffer_update_credentials', 10, 3 );
44