简体   繁体   English

WP ThirstyAffiliates插件挂钩

[英]WP ThirstyAffiliates plugin hook

I'm using ThirstyAffiliates plugin and I need to do some changes in function thirstyRedirectUrl(). 我正在使用ThirstyAffiliates插件,并且需要对函数thirstyRedirectUrl()进行一些更改。 The trouble is after update plugin my changes will disappear. 问题是更新插件后,我的更改将消失。 How and where can I make some hook? 我如何在哪里钩?

My change is 我的改变是

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

Here is all code of the function 这是函数的所有代码

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();
}
}

I've had a look at the source code for the plugin. 我看了看插件的源代码。 I don't think it needs to be changed. 我认为不需要更改它。 In fact, it can't be changed if you want to be able to upgrade it - you need to use the hooks the developers provide, and if they don't provide any you're out of luck. 实际上,如果您希望能够对其进行升级,则无法更改-您需要使用开发人员提供的钩子,并且如果开发人员不提供任何钩子,那么您不走运。 That goes for all plugins, not just this one. 这适用于所有插件,而不仅仅是这个。

Roll back your changes, then add something like the following to your theme (untested, but it should point you in the right direction): 回滚您的更改,然后将以下内容添加到您的主题中(未经测试,但这应该为您指明正确的方向):

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