How do I programatically empty trash?
You can use wp_delete_post. To get all posts with the “trash” status: $trash = get_posts(‘post_status=trash&numberposts=-1’); Then: foreach($trash as $post) wp_delete_post($post->ID, $bypass_trash = true);
You can use wp_delete_post. To get all posts with the “trash” status: $trash = get_posts(‘post_status=trash&numberposts=-1’); Then: foreach($trash as $post) wp_delete_post($post->ID, $bypass_trash = true);
So what’s the best practice here? I would say a combination of letting the theme handle it and providing a default with your plugin. You can use the single_template filter to switch out the template. In your callback, see if the theme provided a template for the post type, if it did, do nothing. <?php … Read more
There is no hook to do this. Copy the index.php to the child theme and make the single line change. Also, tell the parent theme’s author that they should make the same change in their theme, for flexibility.
localhost refers to the machine it’s running on. For example on my own site tomjn.com localhost is 127.0.0.1 as it always is. This doesn’t mean the hacker doesn’t know where to connect, it means the hacker replaces localhost with tomjn.com. Of course if I have a proxy sitting in front this won’t work, but keep … Read more
According to this test, you use set_current_screen() to navigate to one of these in the setUp method. Alas, none of this is apparent if you look at the tremendously-helpful reference page for get_current_screen()… Example: <?php class AxisSetupTest extends WP_UnitTestCase { /** * @covers AxisWP::__construct */ function test_constructor() { // Assert // Admin $this->assertInternalType(‘integer’, has_action( ‘admin_enqueue_scripts’, … Read more
<img src=”<?php echo get_template_directory_uri().’/images/sample.png’; ?>”> Try this. It should work. You have to concatenate the results from get_template_directory_uri() and your images directory in echo.
You can add a custom plugin, to WordPress and also the TinyMCE visual editor. The follow source is a example that simple works and add a string before and after all shortcode. Usage The shortcode will find via regex, relevant if you need it for different shortcodes and different mark on this. The script add … Read more
You can execute arbitrary SQL statements with wpdb::query(), including Data Definition Statements, e.g. function create_index () { global $wpdb ; $sql = “CREATE INDEX my_index ON {$wpdb->prefix}my_table (my_column)” ; $wpdb->query ($sql) ; return ; } Note: Because $wpdb->query() can execute arbitrary SQL, if the statement you pass to it contains ANY user input, then you … Read more
Yes, I’ve dealt with this before. You have to specify a NOBLOGREDIRECT in your wp-config.php file: define( ‘NOBLOGREDIRECT’, ‘http://www.fightify.com’ ); If there’s no site, WP has to redirect visitors somewhere. By default, that’s the signup page. Adding that constant tells it where to go.
To add to @EAMann’s answer, you need to wrap your wp_get_current_user() call (or any call that tries to access a function defined within pluggable.php) within the ‘plugins_loaded’ action. So, if you’re putting this inside your functions.php file, do it like this: add_action( ‘plugins_loaded’, ‘get_user_info’ ); function get_user_info(){ $current_user = wp_get_current_user(); if ( !($current_user instanceof WP_User) … Read more