-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
get_plugin_type()
method and implement it via the register()
…
…method.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1008,14 +1008,18 @@ public function register( $plugin ) { | |
); | ||
|
||
// Prepare the received data | ||
$plugin = wp_parse_args( $plugin, $defaults ); | ||
$plugin['file_path'] = $this->_get_plugin_basename_from_slug( $plugin['slug'] ); | ||
$plugin = wp_parse_args( $plugin, $defaults ); | ||
|
||
// Forgive users for using string versions of booleans or floats for version nr | ||
$plugin['version'] = (string) $plugin['version']; | ||
$plugin['required'] = TGM_Utils::validate_bool( $plugin['required'] ); | ||
$plugin['force_activation'] = TGM_Utils::validate_bool( $plugin['force_activation'] ); | ||
$plugin['force_deactivation'] = TGM_Utils::validate_bool( $plugin['force_deactivation'] ); | ||
$plugin['version'] = (string) $plugin['version']; | ||
$plugin['source'] = empty( $plugin['source'] ) ? 'repo' : $plugin['source']; | ||
$plugin['required'] = TGM_Utils::validate_bool( $plugin['required'] ); | ||
$plugin['force_activation'] = TGM_Utils::validate_bool( $plugin['force_activation'] ); | ||
$plugin['force_deactivation'] = TGM_Utils::validate_bool( $plugin['force_deactivation'] ); | ||
|
||
// Enrich the received data | ||
$plugin['file_path'] = $this->_get_plugin_basename_from_slug( $plugin['slug'] ); | ||
$plugin['type'] = $this->get_plugin_type( $plugin['source'] ); | ||
|
||
// Set the class properties | ||
$this->plugins[ $plugin['slug'] ] = $plugin; | ||
|
@@ -1032,6 +1036,29 @@ public function register( $plugin ) { | |
} | ||
} | ||
|
||
/** | ||
* Determine what type of source the plugin comes from. | ||
* | ||
* @param string $source The source of the plugin as provided, either empty (= WP repo), a file path | ||
* (= bundled) or an external url. | ||
* @return string 'repo', 'external', or 'bundled' | ||
*/ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jrfnl
Author
Contributor
|
||
protected function get_plugin_type( $source ) { | ||
|
||
// Is this a WP repo plugin ? | ||
if ( 'repo' === $source || preg_match( self::WP_REPO_REGEX, $source ) ) { | ||
return 'repo'; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
GaryJones
Member
|
||
// Is this an external package url ? | ||
elseif ( preg_match( self::IS_URL_REGEX, $source ) ) { | ||
return 'external'; | ||
} | ||
// This must be a bundled/pre-packaged plugin. | ||
else { | ||
return 'bundled'; | ||
} | ||
} | ||
|
||
/** | ||
* Amend default configuration settings. | ||
* | ||
|
"type" is a very generic word in coding - ambiguous, especially when associated with a whole plugin. Could we be a bit more specific, at the expense of a few more bytes and call this
get_plugin_source_type()
orget_source_type()
. Maybe even remove the word "type" altogether, i.e.get_source_category()
and then have all of the array key and relevant variables updated to be['source_category']
/$source_category
? That's a more descriptive property than just "type" IMO.