Tag Info

Hot answers tagged

10

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 ...


9

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( ...


4

muplugins_loaded is the very earliest: http://codex.wordpress.org/Plugin_API/Action_Reference (via: http://stackoverflow.com/questions/2535994/sequential-order-of-wordpress-hooks)


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

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

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

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

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 ...


2

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 ...


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

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

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

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 ...


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

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

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


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 ...


1

url_to_postid(wp_get_referer()) will give you the ID of the referring page/post if you were referred from a page or a post. It won't work if referred from some other types of pages, like archives. You will then need to retrieve the categories for the ID to see if they match. I would strongly consider passing a parameter with the request though. You should ...


1

You mean: <?php include "http://www.sample.com/wp-load.php"; This setting is disabled/not allowed by default in most web servers (php.ini) so you can not use the include to include the files from a remote address for security reasons. If you still want to allow inclusion of remote files, the directive allow_url_include must be set toOn(or 1) inphp.ini`. ...


1

You can try this one: /** * Fires as an admin screen or script is being initialized. * * Note, this does not just run on user-facing admin screens. * It runs on admin-ajax.php and admin-post.php as well. * * This is roughly analgous to the more general 'init' hook, which fires earlier. * * @since 2.5.0 */ do_action( 'admin_init' ); if you need ...


1

I can't say I've ever tried including wp-load.php directly, but I've had success using: define("WP_USE_THEMES", false); include("wp-blog-header.php"); ... when trying to invoke Wordpress stack in a non-templated workflow. wp_blog_header.php does make the call out to wp-load.php but also wires up some other stuff (such as calling wp()).



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