lesterchan / wp-sweep

WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It also optimizes your database tables.
https://wordpress.org/plugins/wp-sweep/
153 stars 22 forks source link

Move main class to a separate file #68

Closed szepeviktor closed 1 year ago

szepeviktor commented 1 year ago

@lesterchan 👋🏻

kép

lesterchan commented 1 year ago

@szepeviktor this breaks admin.php

szepeviktor commented 1 year ago

I'm sorry. What is the error?

szepeviktor commented 1 year ago

I see. The REST class and the CLI class instantiate new WPSweep() without the plugin main file's path.

szepeviktor commented 1 year ago

Should I replace those new-s with WPSweep::get_instance()?

lesterchan commented 1 year ago

https://wordpress.org/support/topic/fatal-error-in-the-wp-sweep-version-1-1-6/

I make the arguments optional and it works =)

lesterchan commented 1 year ago

Not sure is there a better way of not passing in FILE to the class.

szepeviktor commented 1 year ago

I think WPSweep should be instantiated (new WPSweep()) only once in the get_instance method.

szepeviktor commented 1 year ago

Multiple instantiations cause really bad side-effects. For example multiple hooking.

szepeviktor commented 1 year ago

Not sure is there a better way of not passing in __FILE__ to the class.

Please do not tell anyone about it. I will deny it.

Put __FILE__ into a global constant.

define( 'WP_SWEEP_MAIN_FILE', __FILE__ );
lesterchan commented 1 year ago

@szepeviktor LOL I let you figure it out and send a PR to change to new WPSweep() But the reason I use a singleton is that I need to access the functions outside.