Comments (12)
Hi @szepeviktor,
cool, thanks a lot for all these suggestions! :-)
That class_alias()
thing really cost me some nerves when I first added that. I had checked so many things, but must have missed that @var TablePress_*_Controller
line... I have now made that more precise in fbe75c5 so that the class_alias()
is no longer needed :-)
(That $controller
class property could have other types in previous versions of TablePress, but since TablePress 2.0, it's only TablePress_Frontend_Controller
.)
Your other suggestions are also very intriguing, but they will need careful review and a lot of testing.
For that class-string
idea with load_class()
, that @template
would probably need to be made more complex, as load_class()
does not just load TablePress_Controller
s.
And I totally agree that autoloading would be very cool to have in the future, but I'm not sure if that can be changed that easily, without breaking backward-compatibility. For example, the load_controller()
, load_class()
, load_file()
, etc. methods all have WordPress filter hooks that are used in e.g. the premium version, TablePress Extensions, and other plugins. So, this would need careful investigation.
Could you maybe expand on that load_admin_page_*
suggestion a little bit? I'm not sure that I fully understand where you want to change what here. While that long switch/case is indeed a bit ugly, its advantage is that the $data
can then be filtered (which is also done in various plugins).
Thanks a lot for your great contributions here!
Best wishes,
Tobias
from tablepress.
Ah, now I see what you mean. This approach will only work if TablePress is displayed in a top-level menu entry (which is not always the case, it can be moved e.g. via the setting on the "Plugin Options" screen). Also, there are views that don't correspond to an admin menu entry, which would need separate handling.
But I understand the general idea now, and yes, that all looks very reasonable! I'll investigate that more closely! :-)
from tablepress.
PHP generics comes to the rescue π¨
And there is a special type in PHPStan: class-string
/**
* @template TClass of TablePress_Controller
* @phpstan-param class-string<TClass> $class_name
* @phpstan-return TClass
*/
public static function load_class(
from tablepress.
Please consider using spl_autoload_register
instead of the load_class
method.
Then you could instantiate a class anywhere in the code.
$view = new TablePress_Export_View();
$view->do_anything();
I would use Composer's "classmap" autoloader.
{
"autoload": {
"classmap": ["classes/", "controllers/", "models/", "views/"]
}
}
composer dump-autoload --optimize
Later on you could leave legacy technologies behind and keep all classes in PSR-4 format in src/
and tame libraries with https://github.com/BrianHenryIE/strauss
from tablepress.
I would have as many load_admin_page_*
methods as there are views.
Then you wouldn't need that array in init_view_actions
and the long switch/case in load_admin_page
.
from tablepress.
Could you maybe expand on that
load_admin_page_*
suggestion a little bit?
I would have a load_admin_page_list
etc. method for each $action
. One can argues that it will cause code duplications but explicit is better than implicit, and repeated things can be abstracted to new methods.
Each one would have an apply_filters()
call.
That is all.
from tablepress.
Ah, then then call these dynamically (e.g. with call_user_func()
) inside the existing load_admin_page()
?
(That function would still be needed, as there's just one add_action( "load-{$page_hook}", array( $this, 'load_admin_page' ) );
where the load_admin_page_*()
functions could hook into.)
Yes, this could indeed be a nice way to get rid of that switch
in favor of individual functions, and their output could still be passed through the tablepress_view_data
filter hook.
from tablepress.
there's just one
add_action( "load-{$page_hook}", array( $this, 'load_admin_page' ) );
Have many of this also! With explicit values. It will be so nice.
from tablepress.
It will be hard. WordPress has no routing/views/template engine.
(many agencies fill these holes before they start a new project)
from tablepress.
will only work if TablePress is displayed in a top-level menu entry
You could insert a layer that takes this dynamic list of menu entries and calls concrete methods.
And add a comment (from WordPress core)
// Pretend you didn't see this
from tablepress.
π Yes, that part of the WordPress code is a nightmare ;-)
Having a layered approach will indeed be the most reasonable approach here.
All this with controllers/views was my idea of a "template engine" as you mention, but well, it's like 12 years old or so, so not "modern" or anything like that anymore :-)
from tablepress.
Even a dumb mustache-like template engine would make WordPress much-much better.
Support for template variables/if/for is enough.
(I am a Timber contributor)
ps. PHP started as a template engine, in 7.0 it changed direction to be a Java-like programming language
from tablepress.
Related Issues (20)
- Can't save Auto Import Tables config HOT 1
- Function WP_Block_Type_Registry::register was called incorrectly HOT 2
- tablepress_rest_api:missing_capability:tablepress_edit_table HOT 7
- Help with translation HOT 3
- Freemius integration is doing heavy damage to wp_sitemeta meta_key fs_accounts HOT 5
- aria-role="link" in previous/next-buttons is redundant HOT 4
- check if file exists before attempting to unlink HOT 2
- Freemius Performance issue after upgrading to 2.1.5 HOT 3
- Error: Function is_search was called incorrectly... HOT 4
- Change Default Table Features for Site Visitors HOT 1
- No obvious way to disable/revert inline CSS loading HOT 1
- Fatal error: Compatibility issue with FS Edd Migration plugin HOT 8
- Oops! That page canβt be found. HOT 3
- Question: Accent neutralise HOT 1
- Tablepress text gets white when add links HOT 5
- TablePress CSS Loads even without a Table on page HOT 2
- Deprecation error from Freemius HOT 5
- TablePress and Elementor conflict after recent updates, preventing Elementor editor to load HOT 1
- Import of CSV: separation character determination fails HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tablepress.