Skip to:
Content

Opened 11 months ago

Closed 9 months ago

Last modified 3 months ago

#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)

create_functions.txt (3.8 KB) - added by tw2113 11 months ago.
Current list of create_function usage
7325-activity-anonymous-functions.diff (2.5 KB) - added by tw2113 11 months ago.
7325-core-anonymous-functions.diff (661 bytes) - added by tw2113 11 months ago.
7325-forums-anonymous-functions.diff (512 bytes) - added by tw2113 11 months ago.
7325-friends-anonymous-functions.diff (970 bytes) - added by tw2113 11 months ago.
7325-groups-anonymous-functions.diff (1.6 KB) - added by tw2113 11 months ago.
7325-members-anonymous-functions.diff (1.3 KB) - added by tw2113 11 months ago.
7325-tests-anonymous-functions.diff (637 bytes) - added by tw2113 11 months ago.
7325-widget-registration-anonymous-functions.diff (3.9 KB) - added by tw2113 11 months ago.
7325-xprofile-anonymous-functions.diff (727 bytes) - added by tw2113 11 months ago.
7325-group-extension-class-anonymous-functions.diff (1.8 KB) - added by tw2113 11 months ago.

Download all attachments as: .zip

Change History (24)

@tw2113
11 months ago

Current list of create_function usage

#1 follow-up: @tw2113
11 months 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 @slaFFik
11 months 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 @tw2113
11 months 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.


9 months ago

#5 @slaFFik
9 months ago

  • Keywords has-patch added

Performance wise - lets do it!

#6 @boonebgorges
9 months 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.

#7 @tw2113
9 months ago

In 11366:

Removes usage of create_function across various BuddyPress components.

See #7325.

#8 @tw2113
9 months 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.

#9 @DJPaul
9 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

This ticket was mentioned in Slack in #buddypress by tw2113. View the logs.


4 months ago

This ticket was mentioned in Slack in #buddypress by djpaul. View the logs.


3 months ago

#13 @tw2113
3 months 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', '

Note: See TracTickets for help on using tickets.