#4955 closed enhancement (fixed)
Improvements to BP_Group_Extension
Reported by: | boonebgorges | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 1.8 | Priority: | high |
Severity: | major | Version: | |
Component: | Groups | Keywords: | commit has-patch |
Cc: |
Description
This is a master ticket for 1.8 improvements to BP_Group_Extension
. Items I plan to look at:
- Setting up and checking nonces automatically, instead of forcing plugin authors to manage it themselves
- Do a better job of checking whether to run display callbacks. Eg, there's no reason why plugin authors should have to check
if ( ! bp_is_group_creation_step( $this->slug ) )
before rendering theiredit_screen
markup. - The markup requirements on
edit_screen()
andcreate_screen()
are slightly different, in particular regarding the Submit button. Think about ways this can be made more consistent. - More intelligent defaults for
enable_create_step
, etc. Eg, if there's nocreate_step()
method, we can pretty safely assume thatenable_create_step
should be disabled, at least by default. See also #4785
Attachments (6)
Change History (27)
#5
@
11 years ago
Wondering if it makes more sense to set a variable in the current object for the current group_id rather than create new methods just to pass the group ID around. Thoughts?
#6
@
11 years ago
The purpose of the call_edit_screen()
method is to pass the group_id param directly to the edit_screen()
callback. We need the middleman because call_edit_screen()
(and, previously, edit_screen()
itself) is hooked to bp_template_content
. The only way to pass a value to a callback on a WP action is to pass it as an additional parameter to do_action()
, eg do_action( 'bp_template_content', bp_get_current_group_id() )
. But doing this would require modifying template files, which won't work for backward compatibility (and is also ugly). Having the call_
method allows for full backward compatibility with existing themes and BP_Group_Extension
plugins.
#7
@
11 years ago
4955.01.patch is a first pass at a major cleanup of BP_Group_Extension
. Several of the problems I needed to solve had to be solved at the same time, thus the huge patch. A summary of the improvements:
- Markup requirements are now standardized between
edit_screen()
,admin_screen()
, andcreate_screen()
. You no longer need to provide a Submit button in youredit_screen()
markup - we provide it for you (though if an existing plugin *does* provide its own Submit button, we detect it and do not add a second one). Nonces are now created and checked automatically for all form contexts. AndBP_Group_Extension
is smart about checking whether your markup should appear in a given place - you don't have to checkif ( bp_is_group_creation_step( $this->slug ) )
etc anymore, because we do it for you.
- Because markup and logic requirements for the
_screen()
and_screen_save()
functions are now identical, I've introduced support for generic fallback methods calledsettings_screen()
andsettings_screen_save()
. When you define these methods in your extension, they'll provide the markup and save-logic for your Create, Edit, and Admin panels. If you provide the specific methods for a given context (say,edit_screen()
andcreate_screen_save()
),BP_Group_Extension
detects it, and uses the more specific ones instead. So: maximum flexibility for plugin authors, while making it as simple as possible for the majority of plugins (which will share logic/markup between all those screens).
- Instead of configuring your extension using a hodge-podge of object properties (like
$this->enable_nav_item = true;
in your__construct()
method), I've converted to using an array of config options, which should then be passed toparent::init()
at the end of the extension constructor. This has several major benefits:- It keeps all config in a single place
- It mirrors the way that
BP_Component
extensions work - It allows us to use
wp_parse_args()
style logic to parse custom params with defaults. One very cool feature here is that I've added a recursive version ofwp_parse_args()
, which means that your config array only has to contain the specific values that you want to change, even if they're one or two levels deep in the array -BP_Group_Extension
will parse them intelligently with the default config. (It's like child theming for your config arrays :) )
See the patch, and the inline documentation, for more details on how these arguments look. (They're mostly ported directly over, except for those that are specific to 'edit', 'create', and 'admin', in which case they've been moved to a structured 'screens' array.)
- Complete backward compatibility with existing
BP_Group_Extension
plugins. I had to do a couple of tricks to ensure that plugin configured the old way could be converted to the new way (see the 'Legacy Support' section of the patch). I've written unit tests for the trickiest bits of this backward compatibility layer. Testing with a dozen or so plugins that useBP_Group_Extension
in different ways.
- Basic reorganization and modularizing.
BP_Group_Extension
is currently a rat's nest, especially the_register()
method and its inline logic. I have reorganized the class so that it makes much more sense. I've broken logic out into its own separate (and testable) methods. And I've written inline docs for the entire thing.
I'm attaching three files:
- 4955.01.patch is the patch, which includes unit tests
- bp-group-extension.php is a clean copy of the newly reorganized class. You might find this a bit easier to read, if you're going to get into the nitty-gritty.
- bpge_test.zip is a small plugin that demonstrates how awesome the
BP_Group_Extension
class. It contains two extensions: one is basic, and one is a bit more customized. You might consider starting with this plugin *first* (before spending much time with the patch), so that you can see firsthand how the changes in 4955.01.patch makeBP_Group_Extension
so much more flexible and pleasant to use.
Thanks in advance for your feedback.
#8
@
11 years ago
Patch looks good to me, let's think about getting this in soon. My updated patch is largely functionally the same as 4955.01.patch, with a few edits:
- Random code clean-up.
- Bail early where possible to avoid the extra indentation.
- Added more strict comparison checking.
- Added default values to class variables and method parameters.
- Fixed a $this->is_initialized that should be $this->initialized.
- Fixed a 'false;' that should be 'return false;
#10
@
11 years ago
We should think about pulling the parse_args_r() function out of the class, and into a function. We can spruce it up with filters ala bbp_parse_args() in bbPress also, and replace all instances of wp_parse_args() in bbPress core.
#11
@
11 years ago
Also, long term (1.9?) it would be sahweet if the core functionality of the Groups component was extracted out to use the BP_Group_Extension class. Would make core a great example for others to learn from, ala register_post_type() in WordPress core.
#13
@
11 years ago
I'm marking this one complete, as I've made all the changes that I'd set out to in the original ticket. Please open separate tickets for new issues.
#16
@
11 years ago
@boonebgorges Am leaving a comment here even though the ticket is closed because I'd like to check out your demo code in bpge_test.zip. However, when I download it, it unpacks into bpge_test.zip.cpgz, which unpacks into bpge_test.zip recursively! Could you please reattach? Many thanks - the new class looks great.
#17
@
11 years ago
needle - Weird, it's unzipping fine for me. I've rezipped and attached as bpge_test_2.zip - let me know if that works for you.
In 6986: