首页
学习
活动
专区
圈层
工具
发布

WP无效
EN

WordPress Development用户
提问于 2019-09-06 15:45:09
回答 1查看 540关注 0票数 1

有一个快速脚本来搜索未翻译的页面,然后返回一个翻译链接。(Polylang为翻译做了一个新的帖子,然后链接到原文。)

一切都很顺利,除了现在:

代码语言:javascript
复制
$url = admin_url('post-new.php?post_type=product&from_post=' . $ID . '&new_lang=' . $lang);

$nonce_url = wp_nonce_url($url);

返回格式优美的url,其中有一个无效的nonce:

https://yaddayadda.com/wp-admin/post-new.php?post_type=product&from_post=2851&new_lang=nl&_wpnonce=fb63ac7002

管理面板中的链接读起来完全相同,但使用的是工作状态:

https://yaddayadda.com/wp-admin/post-new.php?post_type=product&from_post=2851&new_lang=nl&_wpnonce=c17b1a3a2a

我想我可以接受WP,但这是打破了我的头。有人知道为什么会产生无效的链接吗??

完整代码:

代码语言:javascript
复制
require_once('../../../wp-load.php');

$lang = $_POST['lang'];
if ($lang == 'nl') { $language = 'Dutch';}
elseif ($lang == 'pt') { $language = 'Portuguese';}
else { $language = 'Something is going awry, I dont know ' . $lang;}

echo 'Missing ' . $language . ' translations';
// An array of all published WC_Product Objects
$products = wc_get_products( array( 'status' => 'publish', 'limit' => -1,'lang' => 'en', ) );

// Displaying the number of products in this array
echo 'Total number of products published: ' . sizeof( $products ) . '';

// Loop through products and save some data using WC_Product and stuff in array
$tobearray = [];
$count = 0;
foreach ( $products as $product ){
    $ID = $product->get_id();
    $title = $product->get_title();

    if (!pll_get_post($ID, $lang)) {

                  $url = admin_url('post-new.php?post_type=product&from_post=' . $ID . '&new_lang=' . $lang);

                  $nonce_url = wp_nonce_url($url);
                      //wp_nonce_url( $url);  // Adding our nonce to the url with a unique id made from the expiry timestamp

        $addpostlink = ' click here';


        $tobearray[] = ['ID' => $ID, 'Title' => $title, 'Link' => $addpostlink ];
        $count++;
        }
}
echo 'Number of Products that are missing their ' . $lang . ' translation: ' . $count . '';
echo 'Posts that need a ' . $language . ' translation: ';

?>

    Click on the link in the table below to create a new translation.  After the link opens (its a bit slow, pls wait), just open the original English product to copy and paste the title and description so you can translate them.

');
  echo('');
  echo('');
} ?>

IDTitleLink 
');
  echo(implode('', $row));
  echo('
EN

回答 1

WordPress Development用户

回答已采纳

发布于 2019-09-09 16:14:00

找出了问题所在。Polylang插件验证了非new,所以您需要将它传递给“新翻译后”arg。

解决方案是: wp_nonce_url( $link,新译后);

它可能对某人有帮助,但也许没有;)

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/346759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档