Enable/disable post revisions programmatically

To keep posts updated, I am working with WordPress 4.4 and to enable/disable post revisions programmatically use: remove_action( ‘post_updated’, ‘wp_save_post_revision’ ); $post_id = wp_update_post( $arg ); add_action( ‘post_updated’, ‘wp_save_post_revision’ );

How do I make my function add variables/values to the $post object?

Like any other php object, you can add items to the $post object like so: $post->my_new_val_name=”my new value”; I don’t know exactly what you’re trying to do, but inside a function hooked to the_post, you can assign new values and return the object. function my_func($post) { $post->my_new_val_name=”my new value”; return $post; } add_action( ‘the_post’, ‘my_func’ … Read more

Add Useragent to the body class?

something like this maybe: function my_class_names($classes) { $useragent = $_SERVER[‘HTTP_USER_AGENT’]; if(strchr($useragent,’Safari’)) $classes[] = ‘Safari’; // etc.. return $classes; } add_filter(‘body_class’,’my_class_names’); Edit – as per Chip’s suggestion, here’s the function using the WordPress useragents checks: function my_class_names($classes) { global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone; if($is_lynx) $classes[] = ‘lynx’; elseif($is_gecko) $classes[] = ‘gecko’; elseif($is_winIE) … Read more

Add extra field to users

your function never defines a value for that field so when you check if its equal to 1 you never get true. try this: add_action( ‘show_user_profile’, ‘module_user_profile_fields’ ); add_action( ‘edit_user_profile’, ‘module_user_profile_fields’ ); function module_user_profile_fields( $user ) { ?> <h3>Module Options</h3> <table class=”form-table”> <tr> <th><label for=”module_activation”>Module Activation</label></th> <td> <input id=”module_activation” name=”module_activation” type=”checkbox” value=”1″ <?php if ( … Read more

Using WP_Query – how to display something IF there are no results

So, let’s say $query is your WP_Query object. I.e. $query = new WP_Query($some_query_args ); Then you can set up ‘the loop’, by $query->get_posts(); Then to check if there are actually any returned results: if ( $query->have_posts() ) : //Use a While loop to show the results else: //No results, let’s show a message instead. //This … Read more

How to add some custom HTML to the edit posts page

As found here: http://codex.wordpress.org/Function_Reference/add_meta_box /** * Calls the class on the post edit screen */ function call_someClass() { return new someClass(); } if ( is_admin() ) add_action( ‘load-post.php’, ‘call_someClass’ ); /** * The Class */ class someClass { const LANG = ‘some_textdomain’; public function __construct() { add_action( ‘add_meta_boxes’, array( &$this, ‘add_some_meta_box’ ) ); } /** … Read more

Is it possible to disable a function of a parent theme?

Only under some circumstances. If the parent theme’s functions are wrapped in function_exists conditionals then you should be able to replace them. For example: // Parent if (!function_exists(‘p_wpse_95799’)) { function p_wpse_95799() { // } } If the child theme defines a function named p_wpse_95799 then the parent function will not be used. If this is … Read more