WP ThirstyAffiliates插件钩子

时间:2016-03-10 02:05:30

标签: php wordpress wordpress-plugin

我正在使用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();
}
}

1 个答案:

答案 0 :(得分:1)

我已经看过插件的源代码了。我认为不需要改变它。事实上,如果您希望能够升级它,就无法进行更改 - 您需要使用开发人员提供的挂钩,如果他们不提供任何您&# 39;运气不好这适用于所有插件,而不仅仅是这个插件。

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

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');