繁体   English   中英

WP ThirstyAffiliates插件挂钩

[英]WP ThirstyAffiliates plugin hook

我正在使用ThirstyAffiliates插件,并且需要对函数thirstyRedirectUrl()进行一些更改。 问题是更新插件后,我的更改将消失。 我如何在哪里钩?

我的改变是

if (isset($_GET['token']) && $_GET['token'] != '')
  $redirectUrl = apply_filters('thirstyFilterRedirectUrlToken', $redirectUrl, $_GET['token']);
else
  $redirectUrl = apply_filters('thirstyFilterRedirectUrl', $redirectUrl);

这是函数的所有代码

function thirstyRedirectUrl() {
global $post;

if (get_post_type($post) == 'thirstylink') {
    // Get link data and set the redirect url
    $linkData = unserialize(get_post_meta($post->ID, 'thirstyData', true));
    $thirstyOptions = get_option('thirstyOptions');

    // Set redirect URL
    $redirectUrl = htmlspecialchars_decode($linkData['linkurl'], ENT_COMPAT);

    // Set redirect type
    $redirectType = $linkData['linkredirecttype'];
    if (empty($redirectType))
        $redirectType = $thirstyOptions['linkredirecttype'];

    // Apply any filters to the url before redirecting
    if (isset($_GET['token']) && $_GET['token'] != '')
        $redirectUrl = apply_filters('thirstyFilterRedirectUrlToken', $redirectUrl, $_GET['token']);
    else
        $redirectUrl = apply_filters('thirstyFilterRedirectUrl', $redirectUrl);
    $redirectType = apply_filters('thirstyFilterRedirectType', $redirectType);

    // Perform any actions before redirecting
    do_action('thirstyBeforeLinkRedirect', $post->ID, $redirectUrl, $redirectType);

    if (empty($redirectType))
        $redirectType = 301; // default to 301 redirect

    // Redirect the page
    if (!empty($redirectUrl))
        wp_redirect($redirectUrl, intval($redirectType));
    exit();
}
}

我看了看插件的源代码。 我认为不需要更改它。 实际上,如果您希望能够对其进行升级,则无法更改-您需要使用开发人员提供的钩子,并且如果开发人员不提供任何钩子,那么您不走运。 这适用于所有插件,而不仅仅是这个。

回滚您的更改,然后将以下内容添加到您的主题中(未经测试,但这应该为您指明正确的方向):

function myThirstyFilterRedirectUrl($redirecturl) {
    $result = ''; // a filter action needs to return a value
    if (isset($_GET['token']) && $_GET['token'] != '') {
        // Do your token processing here, and set $result
    }
    else {
        // Do your non-token processing here, and set $result
    }
    return $result;
}

add_filter('thirstyFilterRedirectUrl', 'myThirstyFilterRedirectUrl');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM