1

我正在开发一个插件,该插件可以在 wordpress 页面内容中找到一些特殊的 url,然后如果找到匹配的 URL,然后自动将该 url 更改为另一个 url,例如不给该站点提供反向链接。

例如:如果我定义了一个以 www.site2.com 开头的站点,并且我想将其重定向到另一个站点 www.site3.com

现在插件会将在页面上找到 www.site.com 的 url 转换为 www.site.com/og.php=www.site2.com 现在如果用户单击此 url,这将被重定向到 www.site3.com

安装并激活插件后,发现 url 正在转换,但是当我点击它们时出现错误“/og.php”文件未找到

当我尝试打开选项页面以添加更多 url 或更改页面上的某些设置时,它给了我错误“您无权访问此页面”

您可以在下面查看我的两个页面的代码

选项页代码:

<?php
/*
Author: Tasleem
Author URI: http://www.alitips.in
Description: Admin options for Automatic Affiliate Links on the fly
*/

$location = get_option('siteurl') . '/wp-admin/st_auto_affiliate_links_options.php'; // Form Action URI


// Set a few defaults to get people started and use as examples
add_option('st_aal_before', 'http://www.hammacher.com
http://www.thinkgeek.com
http://www.blogrush.com');

add_option('st_aal_after', 'http://www.dpbolvw.net/j6117p-85-7NPVWPRURNPORVORWO?url=%ENCODED_TARGET%&cm_ven=CJ&cm_cat=1511450&cm_pla=1781363&cm_ite=Hammacher+Schlemmer&sid=%TARGET%
http://www.anrdoezrs.net/se121lnwtnvACIJCEHEACBEGHEDF?url=%ENCODED_TARGET%&sid=cg-%TARGET%
http://www.blogrush.com/r58661417');;

/*check form submission and update options*/
if ('process' == $_POST['stage'])
{
    update_option('st_aal_before', $_POST['st_aal_before']);
    update_option('st_aal_after', $_POST['st_aal_after']);
}

/* Get options for form fields */
$st_aal_before = get_option('st_aal_before');
$st_aal_after = get_option('st_aal_after');

?>


<div class="wrap"> 
  <h2><?php _e('Automatic Affiliate Links Options', 'st_ts_') ?></h2> 
  <form name="form1" method="post" action="<?php echo $location ?>&amp;updated=true">
    <input type="hidden" name="stage" value="process" />
    <table width="100%" cellspacing="2" cellpadding="5" class="editform">
    <tr>
        <td width="50%" valign="top"><strong>URLs that start with</strong></td>
        <td><strong>Replace with</strong></td>
    </tr>
    <tr>
        <td valign="top"><textarea name="st_aal_before" id="st_aal_before" style="width: 95%;" rows="15" cols="50"><?php echo $st_aal_before; ?></textarea></td>
        <td valign="top"><textarea name="st_aal_after" id="st_aal_after" style="width: 95%;" rows="15" cols="50"><?php echo $st_aal_after; ?></textarea>
        <strong>Tokens:</strong><br>
        <i>%TARGET%</i> - original URL<br>
        <i>%ENCODED_TARGET%</i> - original URL encoded to be html friendly
        </td>
    </tr>
    </table>
        <p class="submit">
      <input type="submit" name="Submit" value="<?php _e('Update Options', 'st_ts_') ?> &raquo;" />
    </p>
      </form>
</div>

将重定向 url 的编程页面的代码

<?php
/*
Plugin Name: Automatic Affiliate Links
Plugin URI: http://www.alitips.in
Author: Tasleem
Author URI: http://www.alitips.in
Description: Changes Affiliate URLs to local URL which will then be forwarded by the local script
Date: September 18th, 2007
Version: 1.1
History:
18/09/2007  1.0.0   Initial Version
19/9/2007   1.0.01  Modifed (hacked) to cope with multiple ?s and &s in the initial URL

*/


$OutGoingURL =   "/og.php";

function ConvertURLs($aText)
{
    global $OutGoingURL;

    $st_aal_before = get_option('st_aal_before');
    $searchfor = explode("\r\n", trim($st_aal_before));

    for($i = 0; $i < count($searchfor); $i++)
    {
        $searchfor[$i] = "|href=['\"](" . $searchfor[$i] . ".*)/?['\"]|Ui";
    }

    get_option('siteurl');
    $aText = preg_replace($searchfor, "href='" . get_option('siteurl'). "$OutGoingURL?url=$1" ."'", $aText);    
    return $aText;
}


if(strstr( $_SERVER['REQUEST_URI'], $OutGoingURL))
{
    $st_aal_after = get_option('st_aal_after');
    $replacewith = explode("\r\n", trim($st_aal_after));

    $st_aal_before = get_option('st_aal_before');
    $searchfor = explode("\r\n", trim($st_aal_before));
    for($i = 0; $i < count($searchfor); $i++)
    {
        $searchfor[$i] = "|(" . $searchfor[$i] . ").*|Ui";
    }

    $lURL = $_SERVER['QUERY_STRING'];
    // Bit of a hack, the query string may have multiple ? and & so just knock the url= bit off the querystring
    $lURL = substr($lURL, 4, strlen($lURL));
    $lNewURL = preg_replace($searchfor, $replacewith, $lURL);   
    $lNewURL = str_replace("%TARGET%", $lURL, $lNewURL);;
    $lNewURL = str_replace("%ENCODED_TARGET%", urlencode($lURL), $lNewURL);;

    header("location: $lNewURL"); 
    exit;
}


function st_affiliate_links_options_page()
{
    add_options_page('Automatic Affiliate Links Options', 'Automatic Affiliate Links', 9, 'st_auto_affiliate_links_options.php');
}


if (function_exists('add_action') && function_exists('add_filter')) 
{
    add_action('admin_head', 'st_affiliate_links_options_page');
    add_filter('the_content', 'ConvertURLs', 1);
}
?>
4

1 回答 1

0

你还有一个 lonnnnnng 方式的年轻蚱蜢。您要解决的第一个问题是“权限不足问题”。其次,您将希望将 wordpress 链接用于您的表单操作,即:<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>

然后,您可能想要查看会话处理以解决您一定会遇到的其他各种问题。见这里:http ://devondev.com/2012/02/03/using-the-php-session-in-wordpress/

我会分享更多链接,但我知道谷歌会引导你到正确的地方。我知道这是真的,就像我 1 周前的情况一样。

于 2013-08-14T18:16:48.750 回答