Get Admin Email Address From External PHP page

Basically what you’re looking to do is create a separate page within a WordPress site that (I’m sort of guessing here) you’re not creating within WordPress itself, but you want to pull WordPress data. There’s a “cheater” method and an officially sanctioned method to do what you want. The “cheater” method is to call wp-load.php … Read more

Prevent Data Resubmission On Page refresh

To prevent multiple button clicks, you can use JavaScript to disable the button. jQuery(‘#review_member_button’).on(‘click’, function(evt) { jQuery(this).attr(‘disabled’, ‘disabled’); }); On the WordPress end, you can set a unique key for the form every time it’s generated and check to see if a form with that key has been resubmitted. I would recommend setting a transient, … Read more

Choose To Display Post Views With An Options Panel

So this goes in your themes functions.php file. This adds a metabox on the right side of your editscreen within posts called “Enable Post Views on this Post”: // Hook into WordPress add_action( ‘admin_init’, ‘add_custom_metabox’ ); add_action( ‘save_post’, ‘wpse_16722_save_post_views_value’ ); /** * Add meta box */ function add_custom_metabox() { add_meta_box( ‘enable_post_views’, __( ‘Enable Post Views … Read more

Random Default Avatar Function

The function get_avatar‘s 3rd argument is the default image, which you can also pass a function’s return value to, so wherever you run get_avatar in your theme you can set a function that changes the default avatar as a 3rd argument. get_avatar( get_the_author_meta( ‘user_email’ ), 64, ‘http://example.com/path/to/image.jpg’ ); Or, with a function’s return value as … Read more

How do I attach a php file to an arbitrary slug and still have access to the wp-core functions?

I do this pretty regularly and have no issue with using functions in WordPress core. You can hook a bit earlier though and skip the 404 and header bits. In functions.php: function wpa88013_parse_query( $wp ){ if ( ‘nlm-admin-thumbnail’ == $wp->query_vars[‘pagename’] ) { include( dirname( __FILE__ ) . ‘/thumbnail.php’ ); exit; } } add_action( ‘parse_query’, ‘wpa88013_parse_query’ … Read more

WordPress excerpt not working

I actually solved it myself, it turns out there was this piece of code which I removed that solved my problem: function custom_excerpt_length( $length ) { return 0; } add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 ); Not sure what it does though, but it doesn’t seem like I need it.

Add user settings to specific roles

On the profile page exists a global variable $profileuser. The member $profileuser->roles is an array of all roles for that user. <?php # -*- coding: utf-8 -*- // Plugin Name: personal_options add_action( ‘personal_options’, ‘print_user_roles’); function print_user_roles() { global $profileuser; print ‘<pre>$profileuser->roles=” . htmlspecialchars( var_export( $profileuser->roles, TRUE ), ENT_QUOTES, “utf-8’, FALSE ) . ‘</pre>’; } Output: … Read more