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

Do not load debug code if WP_DEBUG is not set to true #183

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 5 additions & 43 deletions bp-templates/bp-nouveau/buddypress-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ private function includes() {
require $this->includes_dir . 'classes.php';
require $this->includes_dir . 'template-tags.php';

// Load debug code only if debug mode is on.
if ( true === WP_DEBUG ) {
require $this->includes_dir . 'debug.php';
}

// Test suite requires the AJAX functions early.
if ( function_exists( 'tests_add_filter' ) ) {
require $this->includes_dir . 'ajax.php';
Expand Down Expand Up @@ -487,9 +492,6 @@ public function localize_scripts() {
$params['objects'] = $supported_objects;
$params['nonces'] = $object_nonces;

// Add Warnings if any
$params['warnings'] = $this->developer_feedbacks();

// Used to transport the settings inside the Ajax requests
if ( is_customize_preview() ) {
$params['customizer_settings'] = bp_nouveau_get_temporary_setting( 'any' );
Expand Down Expand Up @@ -632,46 +634,6 @@ public function setup_directory_nav() {
}
}

/**
* Inform developers about the Legacy hooks
* we are not using. This will be output as
* warnings inside the Browser console to avoid
* messing with the page display.
*
* @since 1.0.0
*
* @return string HTML Output
*/
public function developer_feedbacks() {
$notices = array();

// If debug is not on, stop!
if ( ! WP_DEBUG ) {
return;
}

// Get The forsaken hooks.
$forsaken_hooks = bp_nouveau_get_forsaken_hooks();

// Loop to check if deprecated hooks are used.
foreach ( $forsaken_hooks as $hook => $feedback ) {
if ( 'action' === $feedback['hook_type'] ) {
if ( ! has_action( $hook ) ) {
continue;
}

} elseif ( 'filter' === $feedback['hook_type'] ) {
if ( ! has_filter( $hook ) ) {
continue;
}
}

$notices[] = $feedback['message'];
}

return $notices;
}

/**
* We'll handle template notices from BP Nouveau.
*
Expand Down
278 changes: 278 additions & 0 deletions bp-templates/bp-nouveau/includes/debug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
<?php
/**
* Debug code loader.
*
* @since 1.0.0
*
* @package BP Nouveau
*/

/**
* BP Nouveau will not use this hooks anymore
*
* @since 1.0.0
*
* @return array the list of disused legacy hooks
*/
function bp_nouveau_get_forsaken_hooks() {
$forsaken_hooks = array(
'bp_members_directory_member_types' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'the \'bp_members_directory_member_types\' action will soon be deprecated in the BP Nouveau template pack, use the \'bp_nouveau_get_members_directory_nav_items\' filter instead', 'bp-nouveau' ),
),
'bp_before_activity_type_tab_all' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'the \'bp_before_activity_type_tab_all\' action will soon be deprecated in the BP Nouveau template pack, use the \'bp_nouveau_get_activity_directory_nav_items\' filter instead', 'bp-nouveau' ),
),
'bp_before_activity_type_tab_friends' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'the \'bp_before_activity_type_tab_friends\' action will soon be deprecated in the BP Nouveau template pack, use the \'bp_nouveau_get_activity_directory_nav_items\' filter instead', 'bp-nouveau' ),
),
'bp_before_activity_type_tab_groups' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'the \'bp_before_activity_type_tab_groups\' action will soon be deprecated in the BP Nouveau template pack, use the \'bp_nouveau_get_activity_directory_nav_items\' filter instead', 'bp-nouveau' ),
),
'bp_before_activity_type_tab_favorites' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'the \'bp_before_activity_type_tab_favorites\' action will soon be deprecated in the BP Nouveau template pack, use the \'bp_nouveau_get_activity_directory_nav_items\' filter instead', 'bp-nouveau' ),
),
'bp_before_activity_type_tab_mentions' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'the \'bp_before_activity_type_tab_mentions\' action will soon be deprecated in the BP Nouveau template pack, use the \'bp_nouveau_get_activity_directory_nav_items\' filter instead', 'bp-nouveau' ),
),
'bp_activity_type_tabs' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'the \'bp_activity_type_tabs\' action will soon be deprecated in the BP Nouveau template pack, use the \'bp_nouveau_get_activity_directory_nav_items\' filter instead', 'bp-nouveau' ),
),
'bp_groups_directory_group_filter' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'the \'bp_groups_directory_group_filter\' action will soon be deprecated in the BP Nouveau template pack, use the \'bp_nouveau_get_activity_directory_nav_items\' filter instead', 'bp-nouveau' ),
),
'bp_blogs_directory_blog_types' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'the \'bp_blogs_directory_blog_types\' action will soon be deprecated in the BP Nouveau template pack, use the \'bp_nouveau_get_activity_directory_nav_items\' filter instead', 'bp-nouveau' ),
),
'bp_members_directory_order_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_members_directory_order_options\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_members_filters\' filter instead', 'bp-nouveau' ),
),
'bp_groups_members_order_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_groups_members_order_options\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_members_filters\' filter instead', 'bp-nouveau' ),
),
'bp_member_friends_order_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_member_friends_order_options\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_members_filters\' filter instead', 'bp-nouveau' ),
),
'bp_activity_filter_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'Instead of using the \'bp_activity_filter_options\' action you should register your activity types using the function \'bp_activity_set_action\'', 'bp-nouveau' ),
),
'bp_member_activity_filter_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'Instead of using the \'bp_member_activity_filter_options\' action you should register your activity types using the function \'bp_activity_set_action\'', 'bp-nouveau' ),
),
'bp_group_activity_filter_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'Instead of using the \'bp_group_activity_filter_options\' action you should register your activity types using the function \'bp_activity_set_action\'', 'bp-nouveau' ),
),
'bp_groups_directory_order_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_groups_directory_order_options\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_groups_filters\' filter instead', 'bp-nouveau' ),
),
'bp_member_group_order_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_member_group_order_options\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_groups_filters\' filter instead', 'bp-nouveau' ),
),
'bp_member_blog_order_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_member_blog_order_options\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_blogs_filters\' filter instead', 'bp-nouveau' ),
),
'bp_blogs_directory_order_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_blogs_directory_order_options\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_blogs_filters\' filter instead', 'bp-nouveau' ),
),
'bp_activity_entry_meta' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_activity_entry_meta\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_activity_entry_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_member_header_actions' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_member_header_actions\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_members_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_directory_members_actions' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_directory_members_actions\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_members_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_group_members_list_item_action' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_group_members_list_item_action\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_members_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_friend_requests_item_action' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_friend_requests_item_action\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_members_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_group_header_meta' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_group_header_meta\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_group_meta\' filter instead', 'bp-nouveau' ),
),
'bp_directory_members_item' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_directory_members_item\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_member_meta\' filter instead', 'bp-nouveau' ),
),
'bp_profile_header_meta' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_profile_header_meta\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_member_meta\' filter instead', 'bp-nouveau' ),
),
'bp_group_header_actions' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_group_header_actions\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_groups_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_directory_groups_actions' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_directory_groups_actions\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_groups_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_group_invites_item_action' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_group_invites_item_action\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_groups_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_group_membership_requests_admin_item_action' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_group_membership_requests_admin_item_action\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_groups_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_group_manage_members_admin_item' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_group_manage_members_admin_item\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_groups_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_directory_blogs_actions' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_directory_blogs_actions\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_blogs_buttons\' filter instead', 'bp-nouveau' ),
),
'bp_activity_comment_options' => array(
'hook_type' => 'action',
'message_type' => 'warning',
'message' => __( 'The \'bp_activity_comment_options\' action will soon be deprecated in the BP Nouveau template pack, we recommend you now use the \'bp_nouveau_get_activity_comment_buttons\' filter instead', 'bp-nouveau' ),
),
'groups_custom_group_fields_editable' => array(
'hook_type' => 'action',
'message_type' => 'error',
'message' => __( 'The \'groups_custom_group_fields_editable\' action is deprecated in the BP Nouveau template pack, please use \'bp_after_group_details_creation_step\' or \'bp_after_group_details_admin\' instead', 'bp-nouveau' ),
),
);

/**
* Add warning messages for people using dynamic filters the BP Nouveau Nav Loop
* won't take in account unlike bp_get_displayed_user_nav() & bp_get_options_nav().
*/
$nav_items = array();
if ( bp_is_user() ) {
$nav_items = buddypress()->members->nav->get_item_nav();
} elseif ( bp_is_group() && ! bp_is_group_create() ) {
$nav_items = buddypress()->groups->nav->get_secondary( array( 'parent_slug' => bp_get_current_group_slug() ), false );
}

if ( $nav_items ) {

// Set the common parts
$common = array(
'hook_type' => 'filter',
'message_type' => 'error',
);

// And the warning message
$message = __( 'The \'%s\' filter is not used in the BP Nouveau template pack, please use one of the filters of the BP Nouveau Navigation Loop instead', 'bp-nouveau' );

foreach ( $nav_items as $nav_item ) {
if ( ! isset( $nav_item->children ) ) {
$filter = 'bp_get_options_nav_' . $nav_item->css_id;
$forsaken_hooks[ $filter ] = array_merge( $common, array(
'message' => sprintf( $message, $filter ),
) );
} else {
$filter = 'bp_get_displayed_user_nav_' . $nav_item->css_id;
$forsaken_hooks[ $filter ] = array_merge( $common, array(
'message' => sprintf( $message, $filter ),
) );

foreach ( $nav_item->children as $child ) {
$filter = 'bp_get_options_nav_' . $child->css_id;
$forsaken_hooks[ $filter ] = array_merge( $common, array(
'message' => sprintf( $message, $filter ),
) );
}
}
}
}

return $forsaken_hooks;
}

/**
* Inform developers about the Legacy hooks we are not using.
*
* This will be output as warnings inside the Browser console to avoid
* messing with the page display.
*
* @since 1.0.0
*
* @param array $retval Current JS properties.
* @return array
*/
add_filter( 'bp_core_get_js_strings', function( $retval ) {
// Get The forsaken hooks.
$forsaken_hooks = bp_nouveau_get_forsaken_hooks();

$notices = array();

// Loop to check if deprecated hooks are used.
foreach ( $forsaken_hooks as $hook => $feedback ) {
if ( 'action' === $feedback['hook_type'] ) {
if ( ! has_action( $hook ) ) {
continue;
}

} elseif ( 'filter' === $feedback['hook_type'] ) {
if ( ! has_filter( $hook ) ) {
continue;
}
}

$notices[] = $feedback['message'];
}

$retval['warnings'] = $notices;
return $retval;
} );
Loading