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

Add filters to enable more customization #188

Merged
merged 4 commits into from
Jun 13, 2014
Merged

Conversation

zackkatz
Copy link
Contributor

  • Added tgmpa_submenu_parent_slug filter - modify what menu the sub-page is under, instead of requiring it under "Appearance". This allows the page to be added to a plugin's sub-menu.
  • Added tgmpa_table_columns filter - modify table columns in table view
  • Added tgmpa_table_data_item filter - modify plugin data that's ready for the table output
  • Added tgmpa_notice_rendered_action_links filter - modify final action link output

I wanted to add a "Description" column that says why should an user install this plugin.

array(
    'name'      => 'WordPress SEO by Yoast',
    'slug'      => 'wordpress-seo',
    'description' => 'This is a valuable SEO plugin.',
);

These filters allow much more flexibility in the setup.

* Added `tgmpa_submenu_parent_slug` filter - modify what menu the sub-page is under, instead of requiring it under "Appearance". This allows the page to be added to a plugin's sub-menu.
* Added `tgmpa_table_columns` filter - modify table columns in table view
* Added `tgmpa_table_data_item` filter - modify plugin data that's ready for the table output
* Added `tgmpa_notice_rendered_action_links` filter - modify final action link output

I wanted to add a "Description" column that says why should an user install this plugin.

```
array(
    'name'      => 'WordPress SEO by Yoast',
    'slug'      => 'wordpress-seo',
    'description' => 'This is a valuable SEO plugin.',
);
```

These filters allow much more flexibility in the setup.
@zackkatz
Copy link
Contributor Author

Here's an example of how I'm doing adding a column.

add_filter( 'tgmpa_table_data_item', 'idx_plus_tgmpa_table_data_item', 10, 2 );

/**
 * Add the content for the decription row.
 * @param  array $row    $table_data[$i] from `_gather_plugin_data` method
 * @param  array $plugin $plugin  from `_gather_plugin_data` method
 * @return array         Possibly modified $row
 */
function idx_plus_tgmpa_table_data_item($row, $plugin) {
    $row['description'] = isset($plugin['description']) ? $plugin['description'] : '';
    return $row;
}

add_filter('tgmpa_table_columns', 'idx_plus_tgmpa_table_columns');

/**
 * Add a column to the Suggested Plugins table
 * @param  array $columns Array of columns key => value
 * @return array          Modified array
 */
function idx_plus_tgmpa_table_columns($columns) {

    // I also don't want these other columns.
    unset($columns['type'], $columns['source']);

    $columns['description'] = 'Description';

    return $columns;
}

And here's what it looks like:

screenshot 2014-04-16 23 36 10

@thomasgriffin
Copy link
Contributor

I like the changes, but the biggest issue is changing add_theme_page to add_submenu_page, which will not pass Theme Check or many other plugin/theme checks. If you have any ideas beyond this, like possibly filtering the function call itself and making that dynamic instead, that would be great.

Maybe it could be separated. Have the function name itself filtered, and then have the args themselves filtered as well. I'm pretty sure dynamic function names are cool in PHP 5.2 and greater, so I don't see why you couldn't do this as well.

@zackkatz
Copy link
Contributor Author

I was going to do call_user_func, but the add_theme_page and add_submenu_page accept a different # of arguments and also the callback was all screwy.

What about a simple boolean check with tgmpa_admin_menu_use_add_theme_page?

$args = apply_filters('tgmpa_admin_menu_args', array(
    'parent_slug'=> 'themes.php',
    'page_title' => $this->strings['page_title'],          // Page title.
    'menu_title' => $this->strings['menu_title'],          // Menu title.
    'capability' => 'edit_theme_options',                  // Capability.
    'menu_slug'  => $this->menu,                           // Menu slug.
    'function'   => array( $this, 'install_plugins_page' ) // Callback.
));

// Convert $args['page_title'] to $page_title
extract($args);

if(apply_filters( 'tgmpa_admin_menu_use_add_theme_page', true )) {
    add_theme_page($page_title, $menu_title, $capability, $menu_slug, $function);
} else {
    add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function);
}

* Removed `tgmpa_submenu_parent_slug` filter - now filtering all args 
* added `tgmpa_admin_menu_args` filter
* added `tgmpa_admin_menu_use_add_theme_page` filter
@zackkatz
Copy link
Contributor Author

I got rid of the extract() - less clean looking, but more secure.

@zackkatz
Copy link
Contributor Author

zackkatz commented May 1, 2014

@thomasgriffin have you had a chance to look at this?

@thomasgriffin
Copy link
Contributor

I'm down with this if you could just fix the spacing to match the rest of the class (for WPCS).

Also merge in the `is_callable` commit.
@zackkatz
Copy link
Contributor Author

I've updated the formatting to match.

thomasgriffin added a commit that referenced this pull request Jun 13, 2014
Add filters to enable more customization
@thomasgriffin thomasgriffin merged commit aece2ef into TGMPA:master Jun 13, 2014
@thomasgriffin
Copy link
Contributor

Looks good - thanks!

@jrfnl
Copy link
Contributor

jrfnl commented May 4, 2015

@zackkatz Just thought I'd let you know that I intend to deprecate the tgmpa_admin_menu_use_add_theme_page filter in v2.5.0 as you can now set the parent_slug from the $config array, making the filter superfluous.

Let me know if you have any questions about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants