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

Hooking in the main plugin file is highly unstructured #784

Closed
szepeviktor opened this issue Apr 5, 2020 · 5 comments
Closed

Hooking in the main plugin file is highly unstructured #784

szepeviktor opened this issue Apr 5, 2020 · 5 comments

Comments

@szepeviktor
Copy link
Contributor

May I come up with ideas what to do with adding filters and actions in WP_Auth0.php?

@szepeviktor szepeviktor changed the title Hooks in the main plugin file is highly unstructured Hooking in the main plugin file is highly unstructured Apr 5, 2020
@joshcanhelp
Copy link
Contributor

Sounds great! Thank you for the offer. Would probably be best to propose those in this thread before going ahead with a PR.

@szepeviktor
Copy link
Contributor Author

$ grep '^add_' WP_Auth0.php |sort
add_action( 'activated_plugin', 'wp_auth0_activated_plugin_redirect' );
add_action( 'admin_action_wpauth0_callback_step1', 'wp_auth0_setup_callback_step1' );
add_action( 'admin_action_wpauth0_callback_step3_social', 'wp_auth0_setup_callback_step3_social' );
add_action( 'admin_action_wpauth0_clear_error_log', 'wp_auth0_errorlog_clear_error_log' );
add_action( 'admin_action_wpauth0_export_settings', 'wp_auth0_export_settings_admin_action' );
add_action( 'admin_action_wpauth0_import_settings', 'wp_auth0_import_settings_admin_action' );
add_action( 'admin_enqueue_scripts', 'wp_auth0_admin_enqueue_scripts', 1 );
add_action( 'admin_enqueue_scripts', 'wp_auth0_profile_enqueue_scripts' );
add_action( 'admin_init', 'wp_auth0_init_admin' );
add_action( 'admin_menu', 'wp_auth0_init_admin_menu', 96, 0 );
add_action( 'admin_notices', 'wp_auth0_create_account_message' );
add_action( 'admin_notices', 'wp_auth0_settings_admin_action_error' );
add_action( 'admin_notices', 'wp_auth0_setup_error_admin_notices' );
add_action( 'edit_user_profile', 'wp_auth0_show_delete_identity' );
add_action( 'init', 'wp_auth0_init' );
add_action( 'init', 'wp_auth0_initial_setup_init', 1 );
add_action( 'login_enqueue_scripts', 'wp_auth0_login_enqueue_scripts' );
add_action( 'login_form', 'wp_auth0_filter_login_override_form', 100 );
add_action( 'login_init', 'wp_auth0_login_ulp_redirect' );
add_action( 'lostpassword_form', 'wp_auth0_filter_login_override_form', 100 );
add_action( 'parse_request', 'wp_auth0_custom_requests' );
add_action( 'plugins_loaded', 'wp_auth0_plugins_loaded' );
add_action( 'profile_update', 'wp_auth0_profile_change_email', 100, 2 );
add_action( 'show_user_profile', 'wp_auth0_show_delete_identity' );
add_action( 'template_redirect', 'wp_auth0_process_auth_callback' );
add_action( 'user_profile_update_errors', 'wp_auth0_validate_new_password', 10, 2 );
add_action( 'validate_password_reset', 'wp_auth0_validate_new_password', 10, 2 );
add_action( 'widgets_init', 'wp_auth0_register_widget' );
add_action( 'woocommerce_save_account_details_errors', 'wp_auth0_validate_new_password', 10, 2 );
add_action( 'wp_ajax_auth0_delete_cache_transient', 'wp_auth0_ajax_delete_cache_transient' );
add_action( 'wp_ajax_auth0_delete_data', 'wp_auth0_delete_user_data' );
add_action( 'wp_ajax_auth0_rotate_migration_token', 'wp_auth0_ajax_rotate_migration_token' );
add_action( 'wp_ajax_nopriv_resend_verification_email', 'wp_auth0_ajax_resend_verification_email' );
add_action( 'wp_enqueue_scripts', 'wp_auth0_enqueue_scripts' );
add_action( 'wp_logout', 'wp_auth0_process_logout' );
add_filter( 'allowed_redirect_hosts', 'wp_auth0_add_allowed_redirect_hosts' );
add_filter( 'body_class', 'wp_auth0_filter_body_class' );
add_filter( 'get_avatar', 'wp_auth0_filter_get_avatar', 1, 5 );
add_filter( 'login_body_class', 'wp_auth0_filter_body_class' );
add_filter( 'login_message', 'wp_auth0_render_lock_form', 5 );
add_filter( 'login_url', 'wp_auth0_filter_login_override_url', 100 );
add_filter( 'lostpassword_url', 'wp_auth0_filter_login_override_url', 100 );
add_filter( 'plugin_action_links_' . WPA0_PLUGIN_BASENAME, 'wp_auth0_plugin_action_links' );
add_filter( 'query_vars', 'wp_auth0_register_query_vars' );
add_filter( 'woocommerce_before_customer_login_form', 'wp_auth0_filter_woocommerce_before_customer_login_form' );
add_filter( 'woocommerce_checkout_login_message', 'wp_auth0_filter_woocommerce_checkout_login_message' );
add_filter( 'wp_redirect', 'wp_auth0_filter_wp_redirect_lostpassword', 100 );
add_shortcode( 'auth0', 'wp_auth0_shortcode' );

@szepeviktor
Copy link
Contributor Author

I have a note on this topic: https://github.com/szepeviktor/debian-server-tools/blob/master/webserver/wordpress/WordPress-hooks.md

As all of them are very cheap to add I am tempted to leave as it is.

Let's leave the essentials in the main plugin file:

  • plugins_loaded
  • register_de/activation_hook
  • register_un/install_hook

Move others into:

  • WP_Auth0_Hooks.php - always runs
  • WP_Auth0_Admin_Hooks.php - only on admin, not during wp_doing_ajax
  • WP_Auth0_Frontend_Hooks.php - frontend only
  • WP_Auth0_Login_Hooks.php - on login only
  • WP_Auth0_WooCommerce_Hooks.php - in WC only

What do you think?

@joshcanhelp
Copy link
Contributor

So ... one of the big changes in this latest major was to call hooks with functions, not class methods, to make it easier to unhook if needed. I definitely don't want to pack those back into classes for the sake of organization. Separate files like hooks-woocommerce.php and the like would make it more clear and keep the better DX afforded by global functions.

@stale
Copy link

stale bot commented Jul 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

@stale stale bot added the closed:stale label Jul 5, 2020
@stale stale bot closed this as completed Jul 12, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants