Filter
uncanny-automator
automator_linkedin_get_refresh_token_remaining_days
Filters the remaining days before a LinkedIn refresh token expires, allowing customization of the expiration check.
add_filter( 'automator_linkedin_get_refresh_token_remaining_days', $callback, 10, 2 );
Description
Filters the remaining days before a LinkedIn refresh token expires. Developers can use this to adjust the calculated expiration days, perhaps for caching or custom user notifications, before the token becomes invalid.
Usage
add_filter( 'automator_linkedin_get_refresh_token_remaining_days', 'your_function_name', 10, 2 );
Parameters
-
$days_remaining(mixed) - This parameter represents the calculated number of days remaining until the LinkedIn refresh token expires.
-
$this(mixed) - This parameter represents the number of days remaining until the LinkedIn refresh token expires.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the automator_linkedin_get_refresh_token_remaining_days hook.
* This example adds an extra 7 days to the remaining days if the current user has
* the 'manage_options' capability, simulating a premium feature or a grace period.
*/
add_filter(
'automator_linkedin_get_refresh_token_remaining_days',
function ( $days_remaining, $linkedin_app_helper_instance ) {
// Check if the current user has a specific capability that might grant them more time.
if ( current_user_can( 'manage_options' ) ) {
// Add an extra 7 days as a grace period for administrators.
$days_remaining += 7;
}
// Ensure the returned value is an integer.
return (int) $days_remaining;
},
10, // Priority: standard priority
2 // Accepted args: $days_remaining and $this (the LinkedIn app helper instance)
);
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/linkedin/helpers/linkedin-app-helpers.php:373
public function get_refresh_token_remaining_days( $credentials = array() ) {
$credentials = ! empty( $credentials ) ? $credentials : $this->get_credentials();
$expires_on = absint( $credentials['refresh_token_expires_on'] ?? 0 );
$seconds_remaining = $expires_on - strtotime( current_time( 'mysql' ) );
$days_remaining = floor( $seconds_remaining / DAY_IN_SECONDS );
return (int) apply_filters( 'automator_linkedin_get_refresh_token_remaining_days', $days_remaining, $this );
}