Completed
Pull Request — develop (#571)
by Juliette
02:18
created

example.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file represents an example of the code that themes would use to register
4
 * the required plugins.
5
 *
6
 * It is expected that theme authors would copy and paste this code into their
7
 * functions.php file, and amend to suit.
8
 *
9
 * @see http://tgmpluginactivation.com/configuration/ for detailed documentation.
10
 *
11
 * @package    TGM-Plugin-Activation
12
 * @subpackage Example
13
 * @version    2.5.2
14
 * @author     Thomas Griffin, Gary Jones, Juliette Reinders Folmer
15
 * @copyright  Copyright (c) 2011, Thomas Griffin
16
 * @license    http://opensource.org/licenses/gpl-2.0.php GPL v2 or later
17
 * @link       https://github.com/TGMPA/TGM-Plugin-Activation
18
 */
19
20
/**
21
 * Include the TGM_Plugin_Activation class.
22
 *
23
 * Depending on your implementation, you may want to change the include call:
24
 *
25
 * Parent Theme:
26
 * require_once get_template_directory() . '/path/to/class-tgm-plugin-activation.php';
27
 *
28
 * Child Theme:
29
 * require_once get_stylesheet_directory() . '/path/to/class-tgm-plugin-activation.php';
30
 *
31
 * Plugin:
32
 * require_once dirname( __FILE__ ) . '/path/to/class-tgm-plugin-activation.php';
33
 */
34
require_once dirname( __FILE__ ) . '/class-tgm-plugin-activation.php';
35
36
add_action( 'tgmpa_register', 'my_theme_register_required_plugins' );
37
38
/**
39
 * Register the required plugins for this theme.
40
 *
41
 * In this example, we register five plugins:
42
 * - one included with the TGMPA library
43
 * - two from an external source, one from an arbitrary source, one from a GitHub repository
44
 * - two from the .org repo, where one demonstrates the use of the `is_callable` argument
45
 *
46
 * The variables passed to the `tgmpa()` function should be:
47
 * - an array of plugin arrays;
48
 * - optionally a configuration array.
49
 * If you are not changing anything in the configuration array, you can remove the array and remove the
50
 * variable from the function call: `tgmpa( $plugins );`.
51
 * In that case, the TGMPA default settings will be used.
52
 *
53
 * This function is hooked into `tgmpa_register`, which is fired on the WP `init` action on priority 10.
54
 */
55
function my_theme_register_required_plugins() {
56
	/*
57
	 * Array of plugin arrays. Required keys are name and slug.
58
	 * If the source is NOT from the .org repo, then source is also required.
59
	 */
60
	$plugins = array(
61
62
		// This is an example of how to include a plugin bundled with a theme.
63
		array(
64
			'name'               => 'TGM Example Plugin', // The plugin name.
65
			'slug'               => 'tgm-example-plugin', // The plugin slug (typically the folder name).
66
			'source'             => get_stylesheet_directory() . '/lib/plugins/tgm-example-plugin.zip', // The plugin source.
67
			'required'           => true, // If false, the plugin is only 'recommended' instead of required.
68
			'version'            => '', // 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.
69
			'force_activation'   => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch.
70
			'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins.
71
			'external_url'       => '', // If set, overrides default API URL and points to an external URL.
72
			'is_callable'        => '', // If set, this callable will be be checked for availability to determine if a plugin is active.
73
		),
74
75
		// This is an example of how to include a plugin from an arbitrary external source in your theme.
76
		array(
77
			'name'         => 'TGM New Media Plugin', // The plugin name.
78
			'slug'         => 'tgm-new-media-plugin', // The plugin slug (typically the folder name).
79
			'source'       => 'https://s3.amazonaws.com/tgm/tgm-new-media-plugin.zip', // The plugin source.
80
			'required'     => true, // If false, the plugin is only 'recommended' instead of required.
81
			'external_url' => 'https://github.com/thomasgriffin/New-Media-Image-Uploader', // If set, overrides default API URL and points to an external URL.
82
		),
83
84
		// This is an example of how to include a plugin from a GitHub repository in your theme.
85
		// This presumes that the plugin code is based in the root of the GitHub repository
86
		// and not in a subdirectory ('/src') of the repository.
87
		array(
88
			'name'      => 'Adminbar Link Comments to Pending',
89
			'slug'      => 'adminbar-link-comments-to-pending',
90
			'source'    => 'https://github.com/jrfnl/WP-adminbar-comments-to-pending/archive/master.zip',
91
		),
92
93
		// This is an example of how to include a plugin from the WordPress Plugin Repository.
94
		array(
95
			'name'      => 'BuddyPress',
96
			'slug'      => 'buddypress',
97
			'required'  => false,
98
		),
99
100
		// This is an example of the use of 'is_callable' functionality. A user could - for instance -
101
		// have WPSEO installed *or* WPSEO Premium. The slug would in that last case be different, i.e.
102
		// 'wordpress-seo-premium'.
103
		// By setting 'is_callable' to either a function from that plugin or a class method
104
		// `array( 'class', 'method' )` similar to how you hook in to actions and filters, TGMPA can still
105
		// recognize the plugin as being installed.
106
		array(
107
			'name'        => 'WordPress SEO by Yoast',
108
			'slug'        => 'wordpress-seo',
109
			'is_callable' => 'wpseo_init',
110
		),
111
112
	);
113
114
	/*
115
	 * Array of configuration settings. Amend each line as needed.
116
	 *
117
	 * TGMPA will start providing localized text strings soon. If you already have translations of our standard
118
	 * strings available, please help us make TGMPA even better by giving us access to these translations or by
119
	 * sending in a pull-request with .po file(s) with the translations.
120
	 *
121
	 * Only uncomment the strings in the config array if you want to customize the strings.
122
	 */
123
	$config = array(
124
		'id'           => 'tgmpa',                 // Unique ID for hashing notices for multiple instances of TGMPA.
125
		'default_path' => '',                      // Default absolute path to bundled plugins.
126
		'menu'         => 'tgmpa-install-plugins', // Menu slug.
127
		'parent_slug'  => 'themes.php',            // Parent menu slug.
128
		'capability'   => 'edit_theme_options',    // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
129
		'has_notices'  => true,                    // Show admin notices or not.
130
		'dismissable'  => true,                    // If false, a user cannot dismiss the nag message.
131
		'dismiss_msg'  => '',                      // If 'dismissable' is false, this message will be output at top of nag.
132
		'is_automatic' => false,                   // Automatically activate plugins after installation or not.
133
		'message'      => '',                      // Message to output right before the plugins table.
134
135
		/*
1 ignored issue
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
136
		'strings'      => array(
137
			'page_title'                      => __( 'Install Required Plugins', 'theme-slug' ),
138
			'menu_title'                      => __( 'Install Plugins', 'theme-slug' ),
139
			/* translators: %s: plugin name. * /
140
			'installing'                      => __( 'Installing Plugin: %s', 'theme-slug' ),
141
			/* translators: %s: plugin name. * /
142
			'updating'                        => __( 'Updating Plugin: %s', 'theme-slug' ),
143
			'oops'                            => __( 'Something went wrong with the plugin API.', 'theme-slug' ),
144
			'notice_can_install_required'     => _n_noop(
145
				/* translators: 1: plugin name(s). * /
146
				'This theme requires the following plugin: %1$s.',
147
				'This theme requires the following plugins: %1$s.',
148
				'theme-slug'
149
			),
150
			'notice_can_install_recommended'  => _n_noop(
151
				/* translators: 1: plugin name(s). * /
152
				'This theme recommends the following plugin: %1$s.',
153
				'This theme recommends the following plugins: %1$s.',
154
				'theme-slug'
155
			),
156
			'notice_ask_to_update'            => _n_noop(
157
				/* translators: 1: plugin name(s). * /
158
				'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.',
159
				'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.',
160
				'theme-slug'
161
			),
162
			'notice_ask_to_update_maybe'      => _n_noop(
163
				/* translators: 1: plugin name(s). * /
164
				'There is an update available for: %1$s.',
165
				'There are updates available for the following plugins: %1$s.',
166
				'theme-slug'
167
			),
168
			'notice_can_activate_required'    => _n_noop(
169
				/* translators: 1: plugin name(s). * /
170
				'The following required plugin is currently inactive: %1$s.',
171
				'The following required plugins are currently inactive: %1$s.',
172
				'theme-slug'
173
			),
174
			'notice_can_activate_recommended' => _n_noop(
175
				/* translators: 1: plugin name(s). * /
176
				'The following recommended plugin is currently inactive: %1$s.',
177
				'The following recommended plugins are currently inactive: %1$s.',
178
				'theme-slug'
179
			),
180
			'install_link'                    => _n_noop(
181
				'Begin installing plugin',
182
				'Begin installing plugins',
183
				'theme-slug'
184
			),
185
			'update_link' 					  => _n_noop(
186
				'Begin updating plugin',
187
				'Begin updating plugins',
188
				'theme-slug'
189
			),
190
			'activate_link'                   => _n_noop(
191
				'Begin activating plugin',
192
				'Begin activating plugins',
193
				'theme-slug'
194
			),
195
			'return'                          => __( 'Return to Required Plugins Installer', 'theme-slug' ),
196
			'plugin_activated'                => __( 'Plugin activated successfully.', 'theme-slug' ),
197
			'activated_successfully'          => __( 'The following plugin was activated successfully:', 'theme-slug' ),
198
			/* translators: 1: plugin name. * /
199
			'plugin_already_active'           => __( 'No action taken. Plugin %1$s was already active.', 'theme-slug' ),
200
			/* translators: 1: plugin name. * /
201
			'plugin_needs_higher_version'     => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'theme-slug' ),
202
			/* translators: 1: dashboard link. * /
203
			'complete'                        => __( 'All plugins installed and activated successfully. %1$s', 'theme-slug' ),
204
			'dismiss'                         => __( 'Dismiss this notice', 'tgmpa' ),
205
			'notice_cannot_install_activate'  => __( 'There are one or more required or recommended plugins to install, update or activate.', 'theme-slug' ),
206
			'contact_admin'                   => __( 'Please contact the administrator of this site for help.', 'theme-slug' ),
207
208
			'nag_type'                        => '', // Determines admin notice type - can only be one of the typical WP notice classes, such as 'updated', 'update-nag', 'notice-warning', 'notice-info' or 'error'. Some of which may not work as expected in older WP versions.
209
		),
210
		*/
211
	);
212
213
	tgmpa( $plugins, $config );
214
}
215