How to include core files into plugin

Most of the time, if you are doing things right you don’t have to include Core files. If you are doing things right they will already be loaded for you. In those case where they aren’t loaded, trying to load files with “directory traversal” paths is the wrong way. The Core constants ABSPATH and WPINC … Read more

Problems Including File

Yes, you can use a /wp-content/mu-plugins folder for single file autoloading plugins. The only thing you will have to do is to use a plugin header comment in this file: <?php /* Plugin Name: I am a MU-Plugin */ Then you will find a link on top of your /wp-admin/plugins.php page that says “Must-Use Plugins” … Read more

How to pass variables with get_template_part?

This is essentially scope visibility issue. include brings code into a current scope, function call creates new closed off scope. In get_template_part() only certain WordPress globals are being made available by load_template() call inside. While the basic answer is to declare your variables as globals, you might want to ponder your overall architecture a bit … Read more

Why does get_template_part() break variables?

A script loaded within a function call will only work within the immediate scope of where require or include was used. So really only variables present when load_template() is called will be accessible to the loaded script (unless you use global $myvar of course). The reason vars like $post and $wp_query are available to the … Read more

Get current user data from external PHP page

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; } else { echo ‘<a href=”‘. get_bloginfo(‘url’) .’/wp-admin” … Read more

ABSPATH not working! Any idea why?

If you just need that class included, and your script is located in the plugin directory, like /wp-content/plugins/pluginName/script.php, then you can do: require realpath(‘../../../wp-includes/class-phpass.php’);

What’s the correct way to include files in WordPress TwentyTen theme with it’s own jquery scripts and css?

You need to have the script in a separate file (normally it would be filename.js; I suppose filename.php would work?). Then, you need to register and enqueue that script file, using wp_register_script() and wp_enqueue_script() e.g.: function mytheme_register_custom_scripts() { if ( ! is_admin() ) { $scriptsrc = get_stylesheet_directory_uri() . ‘/scripts/filename.js’; wp_register_script( ‘mytheme_slider’, $scriptsrc ); } } … Read more

How to rename wp-includes folder?

Unfortunately not at the moment. If you look in wp-includes/default_constants.php, the WP_CONTENT_DIR and other constants all have a if ( ! defined(constant) ) check before them. WPINC (the wp-includes constant) does not. It’s defined in wp-settings.php, and has no if ( ! defined(WPINC) ) check, so defining it before hand (in your wp-config.php) would just … Read more