kamalyon/wp-nonce

此插件在面向对象环境中启用wordpress nonce功能。

安装次数: 10

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 0

开放问题: 0

类型:wordpress-plugin

dev-master 2016-01-29 11:19 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:42:11 UTC


README

WordPress插件,在面向对象环境中启用wordpress nonce功能。

##安装方法

将此包作为require添加到您的composer.json文件中,然后运行'composer update'

"kamalyon/wp-nonce": "1.0.*"

或者直接运行

composer require kamalyon/wp-nonce

##使用方法

创建nonce

$Wp_Nonce = new Wp_Nonce();
$nonce = $Wp_Nonce->createNonce('my-nonce');

打印nonce输入字段

$Wp_Nonce = new Wp_Nonce();
$Wp_Nonce->nonceField('name-of-my-action', 'name-of-nonce-field');

创建nonce URL

$Wp_Nonce = new Wp_Nonce();
$url = $Wp_Nonce->nonceURL('http://my-url.com', 'doing-something', 'my-nonce');

验证nonce

$nonce = $_REQUEST['nonce'];
$Wp_Nonce = new Wp_Nonce();
if ($Wp_Nonce->verifyNonce($nonce, 'my-nonce')) {
    //OK  
}else{
    //KO
}

检查管理员引用

$Wp_Nonce = new Wp_Nonce();
if ($Wp_Nonce->checkAdminReferer('name-of-my-action', 'name-of-nonce-field')) {
   //OK
}else{
   //KO
}

##如何运行单元测试

  1. 安装WordPress开发者套件
// Make the directory for the tools (assumes that ~/svn exists; 
// you can create it by running "$ mkdir ~/svn")
$ mkdir ~/svn/wordpress-dev
 
// Change to the new directory we just made.
$ cd ~/svn/wordpress-dev
 
// Check out the developer tools with SVN.
$ svn co http://develop.svn.wordpress.org/trunk/
  1. 检查WordPress开发者套件是否正常运行
// Change to the trunk directory.
$ cd ~/svn/wordpress-dev/trunk/
 
// Make sure the checkout is up to date.
$ svn up
 
// Run all of the tests.
$ phpunit
 
// Run only, e.g., the cache tests.
$ phpunit tests/phpunit/tests/cache
  1. 安装此插件
composer require kamalyon/wp-nonce
  1. 更改插件bootstrap.php文件中的路径
// The path to the WordPress tests checkout.
define( 'WP_TESTS_DIR', '/Users/me/workspace/wordpress-dev/trunk/tests/phpunit/' );
// The path to the main file of the plugin to test.
define( 'TEST_PLUGIN_FILE', '/Users/me/workspace/wp-nonce/wp-nonce.php' );
  1. 运行单元测试
// Go to the plugin's folder
cd /Users/me/workspace/wp-nonce/
// Run the tests
phpunit