1. Home
  2. Docs
  3. Subscribe2
  4. Hooks, API & Customization
  5. s2_custom_keywords

s2_custom_keywords

This hook was introduced in version 9.3 of Subscribe2. It allows for developers to add their own custom keywords to Subscribe2 for inclusion in the notification template. The following code adds a {BITLYLINK} keyword to use in place of the current {PERMALINK} or {TINYLINK} keywords.

function bitly_keyword( $string, $token = 'PUT YOUR API TOKEN HERE') {
    global $mysubscribe2;
    $link = $mysubscribe2->get_tracking_link( $mysubscribe2->permalink );
    $bitlydata = wp_remote_get('https://api-ssl.bitly.com/v3/shorten?access_token=' . $token . '&longUrl=' . urlencode($link));
    $data = json_decode( wp_remote_retrieve_body( $bitlydata ) );
    if  ( 'ok' === strtolower($data->status_txt) && 200 === (int)$data->status_code ) {
        $bitlylink = '<a>data->url . '">' . $data->data->url . '</a>';
    } else {
        $bitlylink = '<a href="' . $link . '">' . $link . '</a>';
    }
    return str_replace('{BITLYLINK}', $bitlylink, $string);
}
add_filter('s2_custom_keywords', 'bitly_keyword');
Was this article helpful to you? Yes No

How can we help?