Tag Info

Hot answers tagged

11

There's little difference between the files. When you view a WordPress page, the first file called is index.php. And it is, essentially, your "Method 1:" define('WP_USE_THEMES', true); /** Loads the WordPress Environment and Template */ require ('./wp-blog-header.php'); The blog header file (that queues up the rest of WordPress) loads wp-load.php ...


10

I came up with following solution. The script have to start with the following code. <?php if( php_sapi_name() !== 'cli' ) { die("Meant to be run from command line"); } function find_wordpress_base_path() { $dir = dirname(__FILE__); do { //it is possible to check for other files here if( ...


5

muplugins_loaded is the very earliest. 1) WordPress Codex - Action Reference List 2) Hooks Run List


4

Yeah $wpdb2 = new wpdb('dbuser', 'dbpassword', 'dbname', 'dbhost'); // get 10 posts, assuming the other WordPress db table prefix is "wp_" $query = "SELECT post_title, guid FROM wp_posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC LIMIT 10"; $someposts = $wpdb2->get_results($query, ...


3

We also needed to do this in WP-CLI. In order to properly handle all the edge cases, such as incorrect database credentials, we ended up rolling our own version of the wp-settings.php file: https://github.com/wp-cli/wp-cli/blob/master/php/wp-settings-cli.php The good news is that you don't have to deal with the messy process of loading WordPress, if you ...


3

Use the defines to make it pick the site you want it to pick. You can define these four to setup the $current_site values properly: DOMAIN_CURRENT_SITE, PATH_CURRENT_SITE, SITE_ID_CURRENT_SITE, BLOG_ID_CURRENT_SITE. If you check the wpmu_current_site() function in ms-load.php, you'll see that it uses those to create the $current_site global. You may or ...


3

Christ, once again I was fighting with something for a few days straight and found a solution 20 minutes after asking on StackExchange. WHY? require_once('../../../wp-load.php');


3

consider including wp-load.php instead of wp-blog-header.php You can also "force" a 200 response using status_header(200); although, depending on how you code your site, this could interfere with sending legitimate 404s.


3

Instead of cooking up your own PHP file and trying to bring in WordPress functionality, put the functionality inside of WordPress using the AJAX hooks that are designed to do that sort of thing. More info here: http://codex.wordpress.org/AJAX_in_Plugins


3

Turn your external file into a WordPress plugin. That way you'll have full access to WP core functions.


3

If you are going to enqueue a stylesheet you should be using wp_enqueue_scripts not wp_print_styles, but you are in a bit of a gray zone between doing things "WordPress-ie" and doing things correctly for performance. The "WordPress-ie" way is to enqueue a stylesheet, but from a performance standpoint you are loading an additional resource and in your case ...


3

What your asking is if Wordpress is modular. Almost like many plugins making up the core and you could use one of those plugins. There are some files with classes you can call on their own but even then some of the methods use even the smallest of core WP functions. I wouldn't worry about load time. Maybe 5 years ago but if your site needs a CMS driving it ...


3

Add a rewrite endpoint to give your plugin a public URL- function wpa_my_endpoint(){ add_rewrite_endpoint( 'my_api', EP_ROOT ); } add_action( 'init', 'wpa_my_endpoint' ); After you flush rewrite rules, you'll have the URL available for the scheduler to ping. http://example.com/my_api/do/something/ Then catch those requests on the parse_query ...


3

Method 2, wp-load.php is the access to all functions of WP, that's all. The first line you can remove, not necessarily.


2

You should be using admin-ajax.php for your AJAX requests and WordPress has pretty good wrappers and actions to help you do that. In terms of performance, 3-4s is pretty harsh. WordPress will typically serve a non-cached request in about 300ms out of the box, so some other theme or plugin is adding to that time, probably by doing something silly and ...


2

The problem in this solution is, that the location of this file are different. WordPress allow the definition of the folder of plugins and themes, different to your static path check for the wp-load.php. Example for custom paths //* // Custom content directory define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' ); define( 'WP_CONTENT_URL', ...


2

The function is called the_post() (no plural s).


2

The reason this is happening is actually not because of anything in the code you've posted, per se, but because of how you have PHPUnit configured. The shortcode callbacks are stored in a global ($shortcode_tags). When you load WP, the shortcode is registered and added to the global. You call shortcode_exists(), it checks $shortcode_tags, and returns true. ...


2

You see a lot of code out there which includes wp-load.php or wp-blog-header.php to use the WordPress API within a php page loaded outside the context of WordPress. There's often a better way to accomplish this. It's also worth noting that any plugin which does that will get rejected from the WordPress.org plugin repository, with good reason- it's prone to ...


2

You get as much control as any other plugin. if you need some code to be executed before any other you can't just include it in the theme and you will need the user to manually install it. Those files are reffered to "dropin plugins" and that is the best documentation I could find http://wpengineer.com/2500/wordpress-dropins/ (shame on the codex for not ...


2

I'm not sure why it does't work for you, but the following works in the file wp-content/test.php: <?php // doesn't make difference to have this or not, for the rest to work define( 'WP_USE_THEMES', false ); require( $_SERVER['DOCUMENT_ROOT'] .'/wp-load.php' ); function my_function() { return 'hello world'; } $value = my_function(); update_option( ...


2

The simplest way is include wp-load.php file. This file will loads all WP core, so you can use WP functions such as get_option in your PHP file: include 'path/to/wp-load.php'; echo get_option( 'option_name' );


2

EDIT Forget my answer below. You could simply use wp_register_style and wp_enqueue_style described in this answer. You could do it with an additional query variable. Add a new variable to the $query_vars array with the query_vars filter On the template_redirect action, make sure your custom.php-css file is included, if the query variable is set. // ...


2

Look at the answers of these questions: How do I add CSS options to my plugin without using inline styles? Best way of adding CSS which can be manipulated by the user via theme option panels? Best practices for a Style/CSS based theme options page?


2

You could give a try to Wordpress Mu Domain Mapping plugin. Update Actually, it better fits on your request to include wp-blog-header.php in the top of your php file of your subdomain, so you can load also the template functions. include(dirname(__FILE__) . "/../path_to_my_blog/wp-blog-header.php"); Or you can do a wp_redirect after the include of ...


2

First of all, search this site. This questions has been answered many times in the past: http://wordpress.stackexchange.com/search?q=clean+wp_head and http://wordpress.stackexchange.com/search?q=security+obscurity Secondly, there is a difference in what WP loads and what a theme and a plugin will load. Look in the theme functions file to see what the theme ...


2

In the generic case, there is no performant solution other than to check every file and folder that is publicly accessible, and then all the parent folders. Since this is not a feasible or excusable operation to perform on every page load or request, you're left with two other options: Define the location manually, which is not an unreasonable request ...


2

Hi @RodeoRamsey: I think your question is very similar to this question: Getting post-thumbnails from another WP site Basically you just need to created the $wpdb using the security credentials for your other site. Take a look at my answer on that question and let me know if it does or does not answer your question, and if not why so I might be able to ...


1

I am not sure if that is cause of your issue, but you do not load WordPress in correct way. Please see Integrating WordPress with Your Website in Codex for details.


1

This error has nothing to do with wp-load.php. You are declaring the 'some_plugin_function' function twice within your plugin file. The error message tells you exactly where to look. You don't need to call class-frontend.php from your stand-alone PHP file to get the error. It's in a plugin, so as long as that plugin is active, it will be parsed.



Only top voted, non community-wiki answers of a minimum length are eligible