Closed angusdowling closed 6 years ago
Hi!
This is a great suggestion and I really like your solution. I know WooCommerce does something similar for some classes but they use an array instead of instance variables. Would you prefer a solution with instance variables (like your proposed solution) or one with a single array (something like `AF()->classes['core_forms'])?
Thank you!
Good idea! an array sounds like a much cleaner implementation. I would be happy to go with that.
Wonderful! I've pushed a commit which implements your suggestions, 86c58ebd027c257c3c598b67e0f7c7db999a2dc9. All the classes should be available through AF()->classes
.
Hope this works! Thanks for your help.
Hi @Fabianlindfors , loving the plugin so far. Great alternative to the bigger names like CF7.
Summary
Several classes are being declared in external files, and then included in the AF class, under the initialize_plugin function.
Unfortunately, these classes are being instantiated without being assigned to any variables.
This means that it's impossible without a large amount of hacking WP global variables, to remove any default filters or actions that are applied by these classes.
These classes are:
AF_ACF_Additions
(advanced-forms/acf/acf-additions.php)AF_Admin_Emails
(advanced-forms/admin/admin-emails.php)AF_Admin_Entries
(advanced-forms/admin/admin-entries.php)AF_Admin_Forms
(advanced-forms/admin/admin-forms.php)AF_Admin_Restrictions
(advanced-forms/admin/admin-restrictions.php)AF_Core_Emails
(advanced-forms/core/core-emails.php)AF_Core_Entries
(advanced-forms/core/core-entries.php)AF_Core_Forms
(advanced-forms/core/core-forms.php)AF_Core_Restrictions
(advanced-forms/core/core-restrictions.php)Steps to Reproduce
Add to anywhere in functions.php
remove_action( 'init', array( 'AF_Core_Forms', 'pre_form' ), 10 );
Expected behavior
Action is removed.
Actual behavior
Action is not removed.
Fix
Whenever a class is instantiated,
return
it, like this:return new AF_Core_Forms();
Inside the AF class assign it to a variable, like this:
$this->core_forms = include( $this->path . 'core/core-forms.php' );
That way, you can remove an action like this:
remove_action('init', array(AF()->core_forms, 'pre_form'), 10);
I'm happy to create a pull request that reflects this.
Version: 1.3.5