Created
July 27, 2017 14:00
-
-
Save stonor/dcbaa57a9bb0441ab5f764b1d87b7b0c to your computer and use it in GitHub Desktop.
Birchpress performance hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/web/wp-content/plugins/birchschedule/framework/includes/birch.php b/web/wp-content/plugins/birchschedule/framework/includes/birch.php | |
index 3ef2a13a..76b5b0a3 100644 | |
--- a/web/wp-content/plugins/birchschedule/framework/includes/birch.php | |
+++ b/web/wp-content/plugins/birchschedule/framework/includes/birch.php | |
@@ -96,14 +96,70 @@ function __invoke() { | |
$args = func_get_args(); | |
$message_name = $this->get_message_name(); | |
- $event_before = $message_name . '_before'; | |
- if ( has_action( $event_before ) ) { | |
- do_action_ref_array( $event_before, $args ); | |
- } | |
+ // Birchpress invokes a bunch of WP hooks for all function calls and it slows | |
+ // down the plugin a lot. However, a lot of those hooks are not used and we are | |
+ // surpressing the hooks for the most invoked functions that are seems to have | |
+ // unused hooks. | |
+ // This is a workaround. The real solution would be to completely refactor the | |
+ // hook handling. | |
+ | |
+ $ignore_hooks = array( | |
+ "birchpress_db__preprocess_config", | |
+ "birchpress_db_get", | |
+ "birchschedule_model_post_get", | |
+ "birchschedule_model_get", | |
+ "birchschedule_model_cpt_appointment_is_model_appointment", | |
+ "birchpress_util_get_wp_timezone", | |
+ "birchpress_util_get_wp_datetime", | |
+ "birchpress_db_is_valid_id", | |
+ "birchschedule_model_cpt_client_is_model_client", | |
+ "birchschedule_model_cpt_location_is_model_location", | |
+ "birchschedule_model_cpt_service_is_model_service", | |
+ "birchschedule_model_cpt_payment_is_model_payment", | |
+ "birchschedule_model_cpt_appointment_post_get", | |
+ "birchpress_util_starts_with", | |
+ "birchschedule_model_cpt_staff_is_model_staff", | |
+ "birchpress_util_convert_to_datetime", | |
+ "birchpress_util_date_i18n", | |
+ "birchpress_util_get_datetime_separator", | |
+ "birchschedule_cintegration_post_get_staff", | |
+ "birchpress_db_get_base_keys", | |
+ "birchpress_db_get_meta_keys", | |
+ "birchschedule_eadmin_get_calendar_appointment_title", | |
+ "birchpress_load_package", | |
+ "birchschedule_model_get_staff_schedule_by_location", | |
+ "birchschedule_bwindow_get_staff_schedule_by_location", | |
+ "birchpress_init_package", | |
+ "birchschedule_model_query", | |
+ "birchpress_db_query", | |
+ "birchschedule_acontrol_filter_others_for_author", | |
+ "birchpress_db_get_post_columns", | |
+ "birchpress_db_get_essential_post_columns", | |
+ "birchschedule_lbservices_post_get_service", | |
+ "birchpress_util_convert_mins_to_time_option", | |
+ "birchschedule_bwindow_get_staff_schedule_date_start", | |
+ "birchschedule_ccode_is_module_ccode", | |
+ "birchschedule_bwindow_get_staff_schedule_date_end", | |
+ "birchschedule_upgrade_module", | |
+ "birchschedule_model_is_valid_id", | |
+ "birchschedule_cintegration_is_module_cintegration", | |
+ "birchschedule_enotification_is_module_enotification", | |
+ "birchschedule_fbuilder_is_module_fbuilder", | |
+ "birchpress_util_to_mysql_date", | |
+ "birchschedule_gsettings_is_module_gsettings" | |
+ ); | |
+ | |
+ | |
+ if (!in_array($message_name, $ignore_hooks)) { | |
+ $event_before = $message_name . '_before'; | |
+ if ( has_action( $event_before ) ) { | |
+ do_action_ref_array( $event_before, $args ); | |
+ } | |
- $event_pre = $message_name . '_args'; | |
- if ( has_filter( $event_pre ) ) { | |
- $args = apply_filters_ref_array( $event_pre, $args ); | |
+ $event_pre = $message_name . '_args'; | |
+ if ( has_filter( $event_pre ) ) { | |
+ $args = apply_filters_ref_array( $event_pre, $args ); | |
+ } | |
} | |
$result = null; | |
@@ -111,16 +167,19 @@ function __invoke() { | |
if ( is_callable( $fn ) ) { | |
$result = call_user_func_array( $fn, $args ); | |
} | |
- if ( has_filter( $message_name ) ) { | |
- $new_args = array_merge( array( $result ), $args ); | |
- $result = apply_filters_ref_array( $message_name, $new_args ); | |
- } | |
- $event_after = $message_name . '_after'; | |
- if ( has_action( $event_after ) ) { | |
- do_action_ref_array( $event_after, array_merge( $args, array( $result ) ) ); | |
- } | |
+ if (!in_array($message_name, $ignore_hooks)) { | |
+ if ( has_filter( $message_name ) ) { | |
+ $new_args = array_merge( array( $result ), $args ); | |
+ $result = apply_filters_ref_array( $message_name, $new_args ); | |
+ } | |
+ | |
+ $event_after = $message_name . '_after'; | |
+ if ( has_action( $event_after ) ) { | |
+ do_action_ref_array( $event_after, array_merge( $args, array( $result ) ) ); | |
+ } | |
+ } | |
return $result; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment