Skip to content

Commit 415e293

Browse files
committed
Added TMGPA example
1 parent 1d31625 commit 415e293

4 files changed

Lines changed: 71 additions & 4 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Author](https://img.shields.io/badge/author-Daniel%20M.%20Hendricks-blue.svg)](https://www.danhendricks.com)
22
[![GitHub License](https://img.shields.io/badge/license-GPLv2-green.svg)](https://raw.githubusercontent.com/dmhendricks/wordpress-base-plugin/master/LICENSE)
3-
[![Twitter](https://img.shields.io/twitter/url/https/github.com/dmhendricks/wordpress-base-plugin.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D)
3+
[![Twitter](https://img.shields.io/twitter/url/https/github.com/dmhendricks/wordpress-base-plugin.svg?style=social)](https://twitter.com/danielhendricks)
44

55
# WordPress Base Plugin
66

@@ -35,17 +35,18 @@ It may also be used as the means of [separating custom code](http://www.billeric
3535
1. Modify `composer.json` to suit your needs
3636
1. Run `composer install` to install dependencies and autoload namespace
3737

38+
**Note:** `hgoebl/mobile-detect` is just loaded as an example. Feel free to remove it.
39+
3840
## Planned Features & TODO
3941

4042
* Fix i18n issues, add `gulp-wp-pot` support
4143
* Add deactivation/uninstall hooks
4244
* Add task runner, related documentation, update .gitignore and rearrange `./assets`
4345
* Improve configuration management
4446
* Add Ajax call example
45-
* Add encrypt/decrypt example. Allow specifying custom salt, else default to WordPress.
47+
* Add encrypt/decrypt example.
4648
* Add `password` field with encrypted `hidden` field
4749
* Add [wordpress-settings-api-class](https://github.com/tareq1988/wordpress-settings-api-class) example
48-
* Add [TGMPA](http://tgmpluginactivation.com/) example
4950
* Add GitHub update class (GitHub Updater 7 is destroying my memory consumption)
5051
* Add Customizer example
5152
* Add dynamically-created CSS/JS files based on settings
@@ -57,10 +58,11 @@ Release changes are noted on the [Releases](https://github.com/dmhendricks/wordp
5758
#### Branch: `master`
5859

5960
* Bumped minimum PHP version check to 5.4
60-
* Added initial `plugin.json` for configuration
61+
* Added `plugin.json` for configuration
6162
* Fixed caching expiration bug
6263
* Removed Carbon Fields as dependency in favor of [plugin](https://github.com/dmhendricks/carbon-fields-loader) loader
6364
* Added Utils::encrypt/decrypt helpers, `WP_ENCRYPT_KEY` constant
65+
* Added [TGMPA](http://tgmpluginactivation.com/) example
6466

6567
## Credits
6668

app/Plugin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public function load_plugin() {
5858

5959
if( !$this->verify_dependencies( 'carbon_fields' ) ) return;
6060

61+
// Add admin settings page(s)
62+
new TGMPA();
63+
6164
// Add admin settings page(s)
6265
new Settings();
6366

app/TGMPA.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace VendorName\MyPlugin;
3+
4+
class TGMPA extends Plugin {
5+
6+
function __construct() {
7+
8+
// Check for required/recommended plugins
9+
add_action( 'tgmpa_register', array( $this, 'register_required_plugins' ) );
10+
11+
}
12+
13+
/**
14+
* Uses the TGMPA library to check for required/recommended plugins.
15+
* @since 0.3.0
16+
* @link http://tgmpluginactivation.com/configuration/ Configuring TGMPA
17+
*/
18+
public function register_required_plugins() {
19+
20+
/*
21+
* Array of plugin arrays. Required keys are name and slug.
22+
* If the source is NOT from the .org repo, then source is also required.
23+
*/
24+
$plugins = array(
25+
26+
// This is an example of how to include a plugin bundled with a theme.
27+
array(
28+
'name' => 'Carbon Fields Loader', // The plugin name.
29+
'slug' => 'carbon-fields-loader', // The plugin slug (typically the folder name).
30+
'source' => 'https://github.com/dmhendricks/carbon-fields-loader/archive/master.zip', // The plugin source.
31+
'required' => true, // If false, the plugin is only 'recommended' instead of required.
32+
'version' => '2.0.0', // E.g. 1.0.0. If set, the active plugin must be this version or higher. If the plugin version is higher than the plugin version installed, the user will be notified to update the plugin.
33+
'force_activation' => true // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch.
34+
)
35+
36+
);
37+
38+
/*
39+
* Array of configuration settings. Amend each line as needed.
40+
*
41+
* TGMPA will start providing localized text strings soon. If you already have translations of our standard
42+
* strings available, please help us make TGMPA even better by giving us access to these translations or by
43+
* sending in a pull-request with .po file(s) with the translations.
44+
*
45+
* Only uncomment the strings in the config array if you want to customize the strings.
46+
*/
47+
$config = array(
48+
'id' => $this->prefix( 'tgmpa' ), // Unique ID for hashing notices for multiple instances of TGMPA.
49+
'menu' => 'tgmpa-install-plugins', // Menu slug.
50+
'parent_slug' => 'themes.php', // Parent menu slug.
51+
'capability' => 'edit_theme_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
52+
'has_notices' => true, // Show admin notices or not.
53+
'dismissable' => true, // If false, a user cannot dismiss the nag message.
54+
'is_automatic' => true // Automatically activate plugins after installation or not.
55+
);
56+
57+
tgmpa( $plugins, $config );
58+
59+
}
60+
61+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"php": ">=5.4.0",
4444
"PHLAK/Config": "^2.0.0",
4545
"jjgrainger/posttypes": "dev-master",
46+
"tgmpa/tgm-plugin-activation": "^2.6.0",
4647
"hgoebl/mobile-detect": ">=1.3.0",
4748
"composer/installers": "~1.3.0"
4849
},

0 commit comments

Comments
 (0)