publishpress / wordpress-version-notices
Library for displaying version notices for Pro plugins in WordPress.
Installs: 12 768
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: >=7.2.5
- publishpress/pimple-pimple: ^3.5.0.0
- publishpress/psr-container: ^2.0.1.0
Requires (Dev)
- codeception/module-asserts: ^1.0
- codeception/module-cli: ^1.0
- codeception/module-db: ^1.0
- codeception/module-filesystem: ^1.0
- codeception/module-phpbrowser: ^1.0
- codeception/module-rest: ^1.3
- codeception/module-webdriver: ^1.0
- codeception/util-universalframework: ^1.0
- composer/composer: 2.2.12
- lucatume/wp-browser: ^3
- overtrue/phplint: ^2.1
- publishpress/version-loader-generator: ^1.0
README
Description
Library for displaying ads for Pro plugins in WordPress.
Installation
$ composer require publishpress/wordpress-version-notices
Loading the library
The library is now loaded automatically by a special include file and Versions class generated by the lib PublishPress Version Loader Generator.
You just need to load the vendor/autoload.php file in your plugin or theme in the main context, out of any WP hook, including plugins_loaded
.
Top Notice
add_filter(\PublishPress\WordpressVersionNotices\Module\TopNotice\Module::SETTINGS_FILTER, function ($settings) { $settings['dumb-plugin-one'] = [ 'message' => 'You\'re using Dumb Plugin One Free. Please, %supgrade to pro%s.', 'link' => 'http://example.com/upgrade', 'screens' => [ [ 'base' => 'edit', 'id' => 'edit-post', 'post_type' => 'post', ], ] ]; return $settings; });
Params
- message: Type the respective message for the banner, adding the button text between '%s'. This string will be used as format for
sprint
. - link: The full link for the button.
- screen: An array of screen parameters used to decide what page should display the banner. Each item of the array can be a boolean or an array with a key-value array specifying the required params from the screen (WP_Screen) object. You can bypass the library's filter algorithm adding a
true
item to it. This allows you to create your own function to check the screen returning a boolean value.
Menu link
add_filter(\PublishPress\WordpressVersionNotices\Module\MenuLink\Module::SETTINGS_FILTER, function ($settings) { $settings['dumb-plugin-one'] = [ 'label' => 'Upgrade', 'link' => 'http://example.com/upgrade', 'parent' => 'parent-menu-alias' ]; return $settings; });
If the plugin has alternative parent menus (in case some modules are disabled) you can specify a set of valid menus as parent. The first that is found as parent menu is used as the parent.
add_filter(\PublishPress\WordpressVersionNotices\Module\MenuLink\Module::SETTINGS_FILTER, function ($settings) { $settings['dumb-plugin-one'] = [ 'label' => 'Upgrade', 'link' => 'http://example.com/upgrade', 'parent' => [ 'parent-menu-alias-1', 'parent-menu-alias-2', 'parent-menu-alias-3', ] ]; return $settings; });
Params
- label: Type the respective label for the menu item.
- link: The full link for the menu link.
- parent: The parent menu we should add the link. A string or an array.
Testing
Create a new WordPress installation dedicated for testing.
Make sure to copy the file .env.testing.dist
as .env.testing
and update the variables according to your environment.
Install the dependencies using composer:
$ composer install
or
$ composer update
Run the script:
$ composer test
The scripts were implemented for *nix systems. Not adapted for Windows.
License
License: GPLv3 or later