GithubHelp home page GithubHelp logo

Comments (17)

szepeviktor avatar szepeviktor commented on July 3, 2024 1

you can't use only core constants.

You mean using only core functions?

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 3, 2024 1

Done.

https://github.com/php-stubs/wordpress-globals

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 3, 2024

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.

szepeviktor avatar szepeviktor commented on July 3, 2024

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.

danieleperilli avatar danieleperilli commented on July 3, 2024

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.

szepeviktor avatar szepeviktor commented on July 3, 2024

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.

szepeviktor avatar szepeviktor commented on July 3, 2024

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.

danieleperilli avatar danieleperilli commented on July 3, 2024

Please consider that sometimes you have to use core constants.

from wordpress-stubs.

danieleperilli avatar danieleperilli commented on July 3, 2024

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.

szepeviktor avatar szepeviktor commented on July 3, 2024

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.

danieleperilli avatar danieleperilli commented on July 3, 2024

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.

szepeviktor avatar szepeviktor commented on July 3, 2024

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.

danieleperilli avatar danieleperilli commented on July 3, 2024

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.

szepeviktor avatar szepeviktor commented on July 3, 2024

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.

szepeviktor avatar szepeviktor commented on July 3, 2024

@danieleperilli You know what!
I would gladly publish php-stubs/wordpress-globals with any global or constant.
What do you think?

from wordpress-stubs.

danieleperilli avatar danieleperilli commented on July 3, 2024

Great!

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.