Comments (17)
you can't use only core constants.
You mean using only core functions?
from wordpress-stubs.
Done.
https://github.com/php-stubs/wordpress-globals
from wordpress-stubs.
Thank you very much for your report!
I think stubs should only contain classes and functions.
Beside GiacoCorsiglia/wordpress-stubs is not being updated this was the second reason to start this repo.
The problem of global constants are solved in my PHPStan extension
https://github.com/szepeviktor/phpstan-wordpress/blob/master/bootstrap.php
from wordpress-stubs.
Actually wpdb constants come from the class file
https://github.com/WordPress/WordPress/blob/3d623995a8d070e608f4ff297512799cf89bb2c0/wp-includes/wp-db.php#L17-L37
from wordpress-stubs.
I'd like to suggest these additions:
define( 'ARRAY_A', 'ARRAY_A');
define( 'ARRAY_N', 'ARRAY_N');
define( 'OBJECT', 'OBJECT');
define( 'OBJECT_K', 'OBJECT_K');
define( 'KB_IN_BYTES', 1024 );
define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
define( 'GB_IN_BYTES', 1024 * MB_IN_BYTES );
define( 'TB_IN_BYTES', 1024 * GB_IN_BYTES );
define( 'WP_START_TIMESTAMP', 0 );
define( 'WP_MEMORY_LIMIT', 512 );
define( 'WP_MAX_MEMORY_LIMIT', 512);
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_DISPLAY', true );
define( 'WP_DEBUG_LOG', false );
define( 'WP_CACHE', false );
define( 'SCRIPT_DEBUG', '');
define( 'MEDIA_TRASH', false );
define( 'SHORTINIT', false );
define( 'WP_FEATURE_BETTER_PASSWORDS', true );
define( 'MINUTE_IN_SECONDS', 60 );
define( 'HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS );
define( 'DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS );
define( 'WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS );
define( 'MONTH_IN_SECONDS', 30 * DAY_IN_SECONDS );
define( 'YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS );
define( 'ABSPATH', '/');
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
define( 'WP_CONTENT_URL', '/wp-content' );
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' );
define( 'PLUGINDIR', 'wp-content/plugins' );
define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' );
define( 'WPMU_PLUGIN_URL', WP_CONTENT_URL . '/mu-plugins' );
define( 'MUPLUGINDIR', 'wp-content/mu-plugins' );
define( 'COOKIEHASH', '' );
define( 'USER_COOKIE', 'wordpressuser_' . COOKIEHASH );
define( 'PASS_COOKIE', 'wordpresspass_' . COOKIEHASH );
define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
define( 'TEST_COOKIE', 'wordpress_test_cookie' );
define( 'COOKIEPATH', '');
define( 'SITECOOKIEPATH', '');
define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
define( 'PLUGINS_COOKIE_PATH', '' );
define( 'COOKIE_DOMAIN', false );
define( 'RECOVERY_MODE_COOKIE', 'wordpress_rec_' . COOKIEHASH );
define( 'FORCE_SSL_ADMIN', false );
define( 'AUTOSAVE_INTERVAL', 60 );
define( 'EMPTY_TRASH_DAYS', 30 );
define( 'WP_POST_REVISIONS', true );
define( 'WP_CRON_LOCK_TIMEOUT', 60 );
define( 'TEMPLATEPATH', '' );
define( 'STYLESHEETPATH', '' );
define( 'WP_DEFAULT_THEME', '' );
from wordpress-stubs.
As I've just stated above the "global world" of WordPress would pollute this project.
The repo description says: Up-to-date WordPress function and class declaration stubs
Please strive to use core functions instead of core constants and global variables.
from wordpress-stubs.
If you really need to use a core constant add it to your project/stubs/static analysis manually.
See https://github.com/szepeviktor/phpstan-wordpress/blob/master/bootstrap.php
Including anything other than function and class stubs would encourage developers to use them.
from wordpress-stubs.
Please consider that sometimes you have to use core constants.
from wordpress-stubs.
I mean that sometimes you have to use global constants like when you use wpdb->get_results() (https://developer.wordpress.org/reference/classes/wpdb/get_results/)
from wordpress-stubs.
You find $wpdb
at the end of the stubs file :)
https://github.com/php-stubs/wordpress-stubs/blob/master/generate.sh#L23-L24
from wordpress-stubs.
I know. The point is that when you call it, you could define an argument that could be only one of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants.
from wordpress-stubs.
Yes I know that.
By adding manually these global stuff to your project keeps telling you not to use them.
I've faced this while developing the PHPStan extension and added them to the bootstrap file.
from wordpress-stubs.
I use your stubs for the intellisense of VSCode with Intelephense, so I manually created a separate file with all the constants I reported before. Probably other people do the same and having that file would be useful. Just that.
from wordpress-stubs.
I see.
This seem to be a Collision of Worlds :) π
I'd like WordPress core to go in the OOP direction leaving PHP4/global things behind.
from wordpress-stubs.
@danieleperilli You know what!
I would gladly publish php-stubs/wordpress-globals with any global or constant.
What do you think?
from wordpress-stubs.
Great!
from wordpress-stubs.
I expect your contribution.
Please put constants and globals in the same path/file as they are in the core.
from wordpress-stubs.
Related Issues (20)
- Include `wp-includes/compat.php` HOT 10
- `wp_is_development_mode()` is missing from the stubs HOT 5
- wp_insert_attachment doesn't show WP_Error as possible return value HOT 5
- 6.4 new see tag HOT 9
- Tests for functionMap.php HOT 1
- Widget::widget() has never return type HOT 1
- stubs for wpdb::get_row() and wpdb::get_results() are wrong HOT 10
- Thanks HOT 1
- function wp_remote_retrieve_header expects array|WP_Error, httpReturnType given. HOT 3
- Issue with wp_get_global_stylesheet Function Not Recognized by Intelliphense HOT 2
- `add_submenu_page` parameter `$callback` should accept `''|callable` HOT 1
- function `wp_register_script` is missing `$in_footer` argument HOT 2
- The nice present: core phpstan tags vs. our phpstan tags in WordPress 6.5 HOT 10
- Update stubs to WordPress 6.5 HOT 1
- `block_template_part` parameter limited to `'header'|'footer'` when `string` should be accepted. HOT 8
- Check if function exists in wordpress-stubs.php HOT 7
- WordPress 6.2 in WordPress any more HOT 7
- functionMap.php wrong HOT 4
- `WP_Filesystem_Base::dirlist` returns an array<array> HOT 6
- OndΕej says: It doesn't make sense to combine void with something else in a union type. HOT 5
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 wordpress-stubs.