umchal
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Reliable way to Include files under the wp-admin directoryI had somebody to check on wordpress.com and
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
works as their path constants are
- ABSPATH: /wordpress/core/5.8/
- WP_CONTENT_DIR: /srv/htdocs/wp-content
Forum: Developing with WordPress
In reply to: Reliable way to Include files under the wp-admin directoryFor dbDelta and similar, ABSPATH . ‘wp-admin/includes/filename.php’ should be fine since /wp-admin/ is supposed to not be moved or renamed.
Are you certain that it works on wordpress.com as well? I’m not familiar with their platform. Just in case you or somebody else might know it.
Forum: Developing with WordPress
In reply to: Reliable way to Include files under the wp-admin directoryHello,
Other options?
https://developer.www.ads-software.com/reference/functions/admin_url/You shouldn’t use a url to include a PHP file. We need a PATH to the wp-admin directory.
Here’s a good thread:
https://wordpress.stackexchange.com/questions/119064/what-should-i-use-instead-of-wp-content-dir-and-wp-plugin-dirIt doesn’t mention the wp-admin path.
Forum: Developing with WordPress
In reply to: Reliable way to Include files under the wp-admin directoryHello,
If WP_CONTENT_DIR is being stored as a constant, then the dir path should be fine.
We are not taking about
WP_CONTENT_DIR
itself but thewp-admin
path. In many cases,dirname( WP_CONTENT_DIR ) . '/wp-admin'
would give the correct path for thewp-admin
directory. However, sites with a custom path set toWP_CONTENT_DIR
will have a problem with the code likerequire_once( dirname( WP_CONTENT_DIR ) . '/wp-admin/includes/class-wp-list-table.php' );
There are plugins / people etc, that choose to rename their /wp-admin directory tho.
Is that what you mean?
No. I’m not talking about cases that users manually edit core directory names.
Forum: Developing with WordPress
In reply to: Reliable way to Include files under the wp-admin directoryHello,
At first guess, I would say that the WP_CONTENT_DIR is being stored as a CONSTANT, so would render the right path whether it is custom or not.
It doesn’t mean
dirname( WP_CONTENT_DIR ) . '/wp-admin'
always gives the right path among sites with different path configurations.Forum: Developing with WordPress
In reply to: Reliable way to Include files under the wp-admin directoryHello,
Why are you trying to include files under the WordPress core?
If you want to use certain functions and classes such as
dbDelta()
andWP_List_Table
defined in the files under the wp-admin directory in your plugin, you need to include them first. See here for example.Thanks for the clarification!
Thank you for the very clear instruction. I get an impression that it’s quite complicated as it seems the best workaround at the moment though. Also, will those copied files remain after Matomo updates?
Wait, I was testing with the administrator privilege. When I test with the subscriber user roll, the query indeed is what you said.
So, it’s all done by default.
Thanks.
Ah,
When I test it with a logged-in user, actually the generated query is like this
SELECT SQL_CALC_FOUND_ROWS wptests_posts.ID FROM wptests_posts WHERE 1=1 AND wptests_posts.post_type = 'test' AND (wptests_posts.post_status = 'publish' OR wptests_posts.post_status = 'private') ORDER BY wptests_posts.post_date DESC LIMIT 0, 10
The part
AND (wptests_posts.post_status = 'publish' OR wptests_posts.post_status = 'private')
is indeed automatically added by default. Maybe this is what you mean.Still, the post author’s part is missing though.
Hi,
So do you mean you have to manually write a SQL query? It is what you mean by default? I might be missing something.
When you do this,
$q = new WP_Query( array( 'post_type' => 'test' ) ); $q->request
by default, the generated database query by WordPress is like this
SELECT SQL_CALC_FOUND_ROWS wptests_posts.ID FROM wptests_posts WHERE 1=1 AND wptests_posts.post_type = 'test' AND (wptests_posts.post_status = 'publish') ORDER BY wptests_posts.post_date DESC LIMIT 0, 10
It does not handle the asked conditions like the
private
post status andpost_author
.Wait,
Greenwich Mean Time
might mean the time without any offsets. In that case, it’s not a problem. I thought GMT time means a time with some GMT time-zone offsets.—-
By the way, I thought this forum section is for Fixing WordPress, meaning fixing the WordPress core issues. But when I read the description of the forum, it says,For any problems encountered after setting up WordPress.
There are lots of misleading titles out there.
Forum: Fixing WordPress
In reply to: Default sorting posts of custom post types with the `hierarchical`Ops, I said the opposite. You’re right: to list posts in the order that latest ones come first.
So we both agree with that point about what “normal” is.
Forum: Fixing WordPress
In reply to: Default sorting posts of custom post types with the `hierarchical`What is “normal”?
To list posts by the order they are created. Even pages are sorted in that manner.
I tested with manual coding and it seems that it’s not your plugin but the WordPress core behavior.
Sorry for bothering.