PluginProbe
Social Media Auto Poster – Schedule & Publish to Buffer / trunk
Social Media Auto Poster – Schedule & Publish to Buffer vtrunk
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 trunk, at includes/functions.php

46 lines 1.4 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 against
11 * all accounts that have the existing access token.
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 IDs based on the existing access token.
25 $account_ids = $wp_to_buffer->get_class( 'settings' )->get_account_ids_by_access_token( $existing_access_token );
26
27 // Bail if no accounts are found.
28 if ( count( $account_ids ) === 0 ) {
29 return;
30 }
31
32 // Update the access and refresh tokens for each account.
33 foreach ( $account_ids as $account_id ) {
34 $wp_to_buffer->get_class( 'settings' )->update_account_credentials(
35 $result['access_token'],
36 $result['refresh_token'],
37 $result['token_expires'],
38 $account_id
39 );
40 }
41
42 }
43
44 // Update Access Token when refreshed by the API class.
45 add_action( 'wp_to_buffer_api_refresh_token', 'wp_to_buffer_update_credentials', 10, 3 );
46