Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/simplify passed info #368

Merged
merged 5 commits into from
Apr 28, 2015
Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Apr 28, 2015

Tested reasonably extensively

Improve plugin registration method

  • register plugins with the $slug as associative array key
  • ensure that all plugins have defaults registered for the keys not passed
  • add $has_forced_activation and $has_forced_deactivation properties to the TGMPA class which are set from the plugin registration method and used to determine whether to add the relevant actions
  • add $sort_order property which holds the plugin names for use in sorting the $plugins property for internal use
  • as - no matter what - we'll always need the file_path, we might as well also set it in the registration method and get rid of the repeated calls to $this->populate_file_path()
  • also made the populate_file_path() a little bit more flexible so it can be used in a leaner manner for those cases where it's still needed

Simplify the table generation, install and activate code

  • retrieve most information we need from our $plugins array rather than pass it through URL or $_POST
  • properly sanitize and validate received information from URL or $_POST
  • leverage the use of the WP_filesystem API
  • show an appropriate error message if user tries to activate an already active plugin
  • deprecate the TGMPA_List_Table::_get_plugin_data_from_name() method which is no longer needed as we have access to the TGM_Plugin_Activation::_get_plugin_data_from_name() method
  • Fix unauthorized issue on bulk installs when not using direct file access caused by Default WP_List_Table Styles Rule for UI Improvement #227
  • Only prepare some variables and update recently activated plugins option when we actually need to

Also:

  • abstract the regexes which are used a number of times to class constants
  • combine multiple isset()'s if used within the same if statement
  • don't nest what doesn't need nesting
  • unset loop variables if the function doesn't return straight after

- register plugins with the $slug as array key
- ensure that all plugins have defaults registered for the keys not passed
- add `$has_forced_activation` and `$has_forced_deactivation` properties to the TGMPA class which are set from the plugin registration method and used to determine whether to add the relevant actions
- add `$sort_order` property which holds the plugin names for use in sorting the `$plugins` property for internal use
- as - no matter what - we'll always need the file_path, we might as well also set it in the registration method and get rid of the repeated calls to `$this->populate_file_path()`
- also made the `populate_file_path()` a little bit more flexible so it can be used in a leaner manner for those cases where it's still needed
- retrieve most information we need from our `$plugins` array rather than pass it through URL or $_POST
- properly sanitize and validate received information from URL or $_POST
- leverage the use of the WP_filesystem API
- show an appropriate error message if user tries to activate an already active plugin
- deprecate the `TGMPA_List_Table::_get_plugin_data_from_name()` method which is no longer needed as we have access to the `TGM_Plugin_Activation::_get_plugin_data_from_name()` method
- Fix unauthorized issue on bulk installs when not using direct file access caused by #227
- Only prepare some variables and update recently activated plugins option when we actually need to

Also:
- abstract the regexes which are used a number of times to class constants
- combine multiple `isset()`'s if used within the same if statement
- don't nest what doesn't need nesting
- unset loop variables if the function doesn't return straight after
@jrfnl jrfnl added this to the 2.5.0 milestone Apr 28, 2015
@@ -758,17 +775,17 @@ public function notices() {
$install_link = true; // We need to display the 'install' action link.
$install_link_count++; // Increment the install link count.
if ( current_user_can( 'install_plugins' ) ) {
if ( isset( $plugin['required'] ) && $plugin['required'] ) {
$message['notice_can_install_required'][] = $plugin['name'];
if ( true === $plugin['required'] ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if the user has registered slightly incorrect as a string:

required => 'true',

? We should allow a little leeway for 2.5, and then make it stricter for 3.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some type casting to the registration method now to account for this. Using some of the filter/filter emulate code I pointed to elsewhere from the WPSEO plugin. Not giving credit to them as I wrote it ;-)

@GaryJones
Copy link
Member

Phew! Excellent stuff. I realise some of my suggestions may well be other PRs once this is merged, but wanted to mention them to get them on your radar if they weren't already.

Most notable addition is a new class with two new validation methods for validating booleans and the use of this code in the plugin registration function
@jrfnl jrfnl force-pushed the feature/simplify-passed-info branch from 516c3b8 to 5650c61 Compare April 28, 2015 14:52
GaryJones added a commit that referenced this pull request Apr 28, 2015
Simplify the handling of information that is passed around.
@GaryJones GaryJones merged commit 2f41962 into develop Apr 28, 2015
@GaryJones GaryJones deleted the feature/simplify-passed-info branch April 28, 2015 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants