# PublishPress WordPress Reviews Library
The PublishPress WordPress Reviews is a library for displaying a banner to users asking for a five-star review.
## Installation
We do recommend using composer for adding this library as a requirement:
```shell
$ composer require publishpress/wordpress-reviews
```
## How to use it
If your plugin does not load the composer's autoloader yet, you need to add the following code:
```php
<?php
require_once 'vendor/autoload.php';
```
**Only free plugins should initialize this library**.
It can be instantiated and initialized in the method that loads the main WordPress hooks.
When instantiating this library, you have to pass three params:
* the plugin slug (the same one used in the URL of the WordPress repository)
* the plugin's name
* the URL for the logo (optional)
### Configuring the criteria to display the banner in the Free plugin
It by default displays the banner when the following conditional is true:
```php
is_admin() && current_user_can('edit_posts')
```
But you can specify custom criteria to display the banner hooking into the filter `<plugin_slug>_wp_reviews_allow_display_notice`.
```php
<?php
use PublishPress\WordPressReviews\ReviewsController;
class MyPlugin
{
/**
* @var ReviewsController
*/
private $reviewController;
public function __construct()
{
$this->reviewController = new ReviewsController(
'my-plugin',
'My Plugin',
MY_PLUGIN_URL . '/assets/img/logo.png'
);
}
public function init()
{
// .......
add_filter('my-plugin_wp_reviews_allow_display_notice', [$this, 'shouldDisplayBanner']);
$this->reviewController->init();
}
public function shouldDisplayBanner($shouldDisplay)
{
global $pagenow;
if (! is_admin() || ! current_user_can('edit_posts')) {
return false;
}
if ($pagenow === 'admin.php' && isset($_GET['page'])) {
if ($_GET['page'] === 'pp-page1') {
return true;
}
if ($_GET['page'] === 'pp-page2') {
return true;
}
}
if ($pagenow === 'edit.php' && isset($_GET['post_type'])) {
if ($_GET['post_type'] === 'pp_custom_post_type') {
return true;
}
}
return false;
}
// .......
}
```
### Configuring the criteria to display the banner in the Pro plugin
In case the Pro plugin has additional pages where you want to display the banner, feel free to use the same filter as
in the free plugin but with a higher priority. You can choose to override the conditions used in the Free plugin
or to append more conditions, for different pages.
```php
add_filter('my-plugin_wp_reviews_allow_display_notice', [$this, 'shouldDisplayBanner'], 20);
```
```php
/**
* @param $shouldDisplay
* @return bool|null
*/
public function shouldDisplayBanner($shouldDisplay)
{
global $pagenow;
if ($shouldDisplay) {
return true;
}
if ($pagenow === 'edit.php' && isset($_GET['post_type'])) {
if ($_GET['post_type'] === 'custom-posttype') {
return true;
}
}
return $shouldDisplay;
}
```
### Backward compatibility with older versions
By default, the library will use the plugin's slug as a prefix for the actions, metadata, and options:
```php
[
'action_ajax_handler' => $this->pluginSlug . '_action',
'option_installed_on' => $this->pluginSlug . '_wp_reviews_installed_on',
'nonce_action' => $this->pluginSlug . '_wp_reviews_action',
'user_meta_dismissed_triggers' => '_' . $this->pluginSlug . '_wp_reviews_dismissed_triggers',
'user_meta_last_dismissed' => '_' . $this->pluginSlug . '_wp_reviews_last_dismissed',
'user_meta_already_did' => '_' . $this->pluginSlug . '_wp_reviews_already_did',
'filter_triggers' => $this->pluginSlug . '_wp_reviews_triggers',
]
```
If you already use the original library in your plugin and want to keep compatibility with current sites data, you can customize the
hooks and keys for the data stored in the DB using the filter `<plugin_slug>_wp_reviews_meta_map`:
```php
<?php
add_filter('my-plugin_wp_reviews_meta_map', 'my_plugin_wp_reviews_meta_map');
function my_plugin_wp_reviews_meta_map($metaMap)
{
// You can override all the array, or specific keys.
$metaMap = [
'action_ajax_handler' => 'legacy_slug_ajax_action',
'option_installed_on' => 'legacy_slug_wp_reviews_installed_on',
'nonce_action' => 'legacy_slug_wp_reviews_action',
'user_meta_dismissed_triggers' => '_legacy_slug_wp_reviews_dismissed_triggers',
'user_meta_last_dismissed' => '_legacy_slug_wp_reviews_last_dismissed',
'user_meta_already_did' => '_legacy_slug_wp_reviews_already_did',
'filter_triggers' => 'legacy_slug_wp_reviews_triggers',
];
return $metaMap;
}
```
## Common questions
### Should I use this library on Pro plugins?
Pro plugins that embed the free plugin code **should not instantiate or initialize this library** otherwise, users will
probably see duplicated admin notices or will be asked for a review twice.
Keeping the library activated only by the free plugin allows both versions, free and pro,
to share the same options and metadata stored in the database, avoiding duplicated banners or review requests.
Please, **only initialize this library in the Free plugin** and do not disable or block it in the Pro version. We want to keep it enabled
for both free and pro users.
## Testing
You can test the banner in the WordPress admin by changing the option `<plugin-slug>_wp_reviews_installed_on` in the options table. Set it for older data to make sure the time difference is bigger than the selected trigger
## Copyright
Based on the [library](https://github.com/danieliser/WP-Product-In-Dash-Review-Requests) created by [Daniel Iser](https://danieliser.com).
没有合适的资源?快使用搜索试试~ 我知道了~
【WordPress插件】2022年最新版完整功能demo+插件v2.3.4.zip
共214个文件
php:116个
js:13个
css:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 73 浏览量
2022-04-03
07:20:39
上传
评论
收藏 876KB ZIP 举报
温馨提示
"【WordPress插件】2022年最新版完整功能demo+插件v2.3.4 PublishPress Capabilities Pro PublishPress功能Pro" ---------- 泰森云每天更新发布最新WordPress主题、HTML主题、WordPress插件、shopify主题、opencart主题、PHP项目源码、安卓项目源码、ios项目源码,更有超10000个资源可供选择,如有需要请站内联系。
资源推荐
资源详情
资源评论
收起资源包目录
【WordPress插件】2022年最新版完整功能demo+插件v2.3.4.zip (214个子文件)
CHANGELOG 1KB
admin.css 14KB
chosen.css 12KB
chosen.min.css 10KB
pro.css 6KB
pressshack-admin.css 6KB
admin.css 3KB
admin.css 3KB
status-caps.css 544B
pp-roles-admin.css 499B
edd-license-style.css 205B
edd-license-style.css 199B
profile.css 0B
.env.testing.dist 708B
phpunit.xml.dist 448B
wpspin_light.gif 2KB
.gitignore 60B
.gitignore 37B
.gitignore 35B
.gitignore 31B
.gitignore 24B
.gitignore 7B
.gitignore 7B
chosen.proto.js 47KB
chosen.jquery.js 46KB
chosen.proto.min.js 29KB
chosen.jquery.min.js 28KB
admin.dev.js 12KB
admin.js 8KB
admin.dev.js 6KB
admin.js 5KB
settings-pro.dev.js 4KB
settings-pro.js 3KB
pp-roles-admin.js 3KB
features-block-script.js 1KB
profile.js 967B
installed.json 7KB
composer.json 1KB
composer.json 1KB
composer.json 819B
composer.json 794B
composer.json 686B
composer.json 654B
composer.json 622B
composer.json 622B
composer.json 557B
LICENSE 34KB
LICENSE 1KB
LICENSE 1KB
LICENSE 1KB
composer.lock 294KB
composer.lock 273KB
composer.lock 8KB
composer.lock 6KB
README.md 6KB
README.md 1KB
README.md 1KB
LICENSE.md 1KB
README.md 278B
capsman-enhanced-es_ES.mo 119KB
capsman-enhanced-fr_FR.mo 116KB
capsman-enhanced-it_IT.mo 112KB
capsman-enhanced-ru_RU.mo 6KB
capsman-enhanced-by_BY.mo 5KB
capsman-enhanced-ca.mo 5KB
capsman-enhanced-de_DE.mo 5KB
capsman-enhanced-sv_SE.mo 5KB
capsman-enhanced-en_US.mo 764B
wp-edd-license-integration.mo 390B
wp-edd-license-integration.mo 390B
admin.php 59KB
manager.php 34KB
admin-menus.php 27KB
backup.php 27KB
ReviewsController.php 22KB
admin.php 22KB
admin-features.php 22KB
EDD_SL_Plugin_Updater.php 21KB
EDD_SL_Plugin_Updater.php 21KB
settings-ui.php 20KB
nav-menus.php 18KB
PimpleTest.php 18KB
cap-helper.php 17KB
restrict-editor-features.php 17KB
handler.php 16KB
admin-load.php 16KB
class-pp-roles-actions.php 15KB
class-pp-roles-list-table.php 15KB
admin-load.php 14KB
restrict-admin-features.php 14KB
ClassLoader.php 13KB
pp-ui.php 13KB
editor-features.php 13KB
admin-features-block-url.php 12KB
functions-admin.php 11KB
admin-features-css-hide.php 11KB
custom-config.php 11KB
Pro.php 10KB
filters.php 9KB
Container.php 9KB
共 214 条
- 1
- 2
- 3
资源评论
Lee达森
- 粉丝: 957
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功