Hot answers tagged

21

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


14

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


6

muplugins_loaded is the earliest hook. Depending on your wordpress setup, you may not have any plugins in the MU_PLUGINS directory. In that case this hook may not fire. The next best hook to trigger is plugins_loaded. RESOURCES WordPress Codex - Action Reference List Q/A: How to get WordPress' hook run sequence? Q/A: Make sense of WP Load Core


5

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, OBJECT);...


5

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


5

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


4

Your analogy here is partially correct, but incomplete: I understand that when do_action is called wp looks for all registered listeners and invokes them according set priority. You need to consider what happens when you call add_action. WordPress never searches for the add_action statements, it has those in a list. When you call add_action, it ...


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

The shortest way is to load wp-load.php and abort the loading of the template engine (Note: You couldn't do that, if you'd be loading the header file, like you see it on many sites in the interweb). # No need for the template engine define( 'WP_USE_THEMES', false ); # Load WordPress Core // Assuming we're in a subdir: "~/wp-content/plugins/current_dir" ...


3

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' );


3

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


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

You can... Load the file into the file where you want to display the 'hey username' message: <?php include(TEMPLATEPATH .'/check-user-hello.php'); ?> . Then in that file "check-user-hello.php" You need to put this code <?php if ( is_user_logged_in() ) { global $current_user; get_currentuserinfo(); echo 'Hey ' . $current_user->display_name; ...


3

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?


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

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

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


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

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

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

You can use real cron to trigger WP cron - by fetching wp-cron.php file from root (snippet from quick google search). That will take care of environment and everything.


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

I don´t know if someone is still looking to resolve this, but this is how I did it: In the "load-posts.js" you have this line: $('.pbd-alp-placeholder-'+ pageNum).load(nextLink + ' .post', This looks for the class ".post" to load more. The custom post types doesn´t have this class. So simply change this line for something like: $('.pbd-alp-placeholder-'+...


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

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 function is called the_post() (no plural s).


2

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


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



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