#7325 closed enhancement (fixed)
Removal of create_function usage for BP 2.8
Reported by: | tw2113 | Owned by: | tw2113 |
---|---|---|---|
Milestone: | 2.8 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Core | Keywords: | has-patch |
Cc: |
Description
With BuddyPress 2.8 slated to be PHP 5.3 or higher, we finally have the opportunity to remove usage of create_function from the codebase.
Proposing the solution of simply replacing the spots inline, moving them to PHP5.3 anonymous functions.
Make sure to run unit tests suite to help ensure as little breakage as possible, and provide new unit tests if at all possible.
Attachments (11)
Change History (24)
#1
follow-up:
↓ 2
@
8 years ago
These ones will need to remain due to PHP 5.4+ only support for $this in closures.
src/bp-groups/classes/class-bp-group-extension.php:756: add_action( 'bp_template_content_header', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) );
src/bp-groups/classes/class-bp-group-extension.php:757: add_action( 'bp_template_title', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) );
src/bp-groups/classes/class-bp-group-extension.php:1191: create_function( '', 'do_action( "bp_groups_admin_meta_box_content_' . $this->slug . '", ' . $group_id . ' );' ),
#2
in reply to:
↑ 1
@
8 years ago
- Milestone changed from Awaiting Review to 2.8
Replying to tw2113:
These ones will need to remain due to PHP 5.4+ only support for $this in closures.
src/bp-groups/classes/class-bp-group-extension.php:756: add_action( 'bp_template_content_header', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) ); src/bp-groups/classes/class-bp-group-extension.php:757: add_action( 'bp_template_title', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) ); src/bp-groups/classes/class-bp-group-extension.php:1191: create_function( '', 'do_action( "bp_groups_admin_meta_box_content_' . $this->slug . '", ' . $group_id . ' );' ),
We can pass only the required value to anonymous functions in these cases, as only 1 property from $this
is used there.
#3
@
8 years ago
I am not sure about these, due to the legacy theme and the deprecated file that we are no longer even loading for new installs.
src/bp-core/deprecated/1.6.php add_action( 'wp_ajax_' . $action, create_function( '', 'exit;' ), 9999 ); add_action( 'wp_ajax_nopriv_' . $action, create_function( '', 'exit;' ), 9999 ); src/bp-templates/bp-legacy/buddypress-functions.php add_filter( 'bp_get_the_thread_message_css_class', create_function( '$retval', '
I'm fine with leaving them for the moment.
This ticket was mentioned in Slack in #buddypress by slaffik. View the logs.
8 years ago
#6
@
8 years ago
- Owner set to tw2113
- Status changed from new to assigned
https://buddypress.trac.wordpress.org/attachment/ticket/7325/7325-friends-anonymous-functions.diff - don't put a space between -
and 1
in the closure.
https://buddypress.trac.wordpress.org/attachment/ticket/7325/7325-members-anonymous-functions.diff Have you verified that the slashing behavior is OK with the addslashes()
juggling act removed?
Other than that, looks good. @tw2113 Go forth and anonymize.
#8
@
8 years ago
@boonebgorges perhaps I should confirm that the slashes stuff are somehow related to the create_function() itself, or in regards to the filter in place.
Committed the rest of the patches, except the members portion.
#10
@
8 years ago
FYI: PHP 7.2 will deprecate create_function
: https://wiki.php.net/rfc/deprecations_php_7_2#create_function
This ticket was mentioned in Slack in #buddypress by tw2113. View the logs.
8 years ago
This ticket was mentioned in Slack in #buddypress by djpaul. View the logs.
7 years ago
#13
@
7 years ago
Current list of existing ones that were skipped previously or missed earlier:
src/bp-core/deprecated/1.6.php
268: add_action( 'wp_ajax_' . $action, create_function( , 'exit;' ), 9999 );
269: add_action( 'wp_ajax_nopriv_' . $action, create_function( , 'exit;' ), 9999 );
src/bp-groups/classes/class-bp-group-extension.php
756: add_action( 'bp_template_content_header', create_function( , 'echo "' . esc_attr( $this->name ) . '";' ) );
757: add_action( 'bp_template_title', create_function( , 'echo "' . esc_attr( $this->name ) . '";' ) );
1202: create_function( , 'do_action( "bp_groups_admin_meta_box_content_' . $this->slug . '", ' . $group_id . ' );' ),
src/bp-members/bp-members-screens.php
198: add_action( 'bp_' . $fieldname . '_errors', create_function( , 'echo apply_filters(\'bp_members_signup_error_message\', "<div class=\"error\">" . stripslashes( \ . addslashes( $error_message ) . '\' ) . "</div>" );' ) );
src/bp-templates/bp-legacy/buddypress-functions.php
1611: add_filter( 'bp_get_the_thread_message_css_class', create_function( '$retval', '
Current list of create_function usage