53

Sharpen Resized Images (only jpg) This function sharpening resized jpg images. An example of difference: function ajx_sharpen_resized_files( $resized_file ) { $image = wp_load_image( $resized_file ); if ( !is_resource( $image ) ) return new WP_Error( 'error_loading_image', $image, $file ); $size = @getimagesize( $resized_file ); ...


21

There's actually a filter that you can use, see abstract-wc-email.php, line 214: return apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object ); you can put the following in your functions.php: add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2); ...


17

To disable user email notification, add this in a plugin or theme: add_filter( 'send_password_change_email', '__return_false' ); FYI wp_password_change_notification() controls admin email notification when a user changes their password


10

If you are building this for a single client, you should absolutely take advantage of mu-plugins. There are a lot of things in WordPress that you can't do in functions.php. Pluggable functions is one of them, but more obvious, a number of hooks (both actions and filters) fire before functions.php. In some cases, these hooks even fire before regular plugins, ...


9

Only show posts and media of the logged-in Author & fix the post/media counts on the filter bars. Tested on: Wordpress 3.4.1 By default, WordPress allows Authors to see the titles of other users posts, unpublished drafts, and all media, even though they cannot be edited. Use this code to only allow posts and media of the currently logged in Author to ...


9

And there is another filter that will give you access to the $header variable which can allow you to BCC your emails so that you get a carbon copy of every email that goes to your clients on Woocommerce. This is just as easy as the code above except your clients will not see your email address. Just like the solution above you would add the following code: ...


8

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


8

To disable Admin email notification when a user resets their own password, create a Plugin (or Must Use Plugin) using the following code snippet: /** * Disable Admin Notification of User Password Change * * @see pluggable.php */ if ( ! function_exists( 'wp_password_change_notification' ) ) { function wp_password_change_notification( $user ) { ...


7

Pre-populating post types Here is one for this collection. //////////////////////////////////////////////////////////////////////////////////// // This auto populates post types and posts. /////////////////////////////////////////////////////////////////////////////////// add_filter( 'default_content', 'my_editor_content' ); function my_editor_content( $...


6

Here are some nice shortcodes for you to use: 1. Easy to add twitter & facebook share button Shortcode function shreplz() { return ' <div class="sharebox"> <div class="twittme"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a><script type="text/javascript" src="//...


6

Wait for the action plugins_loaded before you create the class instance. The pluggable functions are loaded at this time. From wp-settings.php: /** * Fires once activated plugins have loaded. * * Pluggable functions are also available at this point in the loading order. * * @since 1.5.0 */ do_action( 'plugins_loaded' ); I would even wait for ...


6

Approach for WordPress 4.6+ Check out the patch in ticket #36009 that was merged into WordPress version 4.6. It adds the 'user' option for the $notify input parameter of wp_new_user_notification(), to skip sending those emails to the admin. How it works The register_new_user() function contains this part: do_action( 'register_new_user', $user_id ); The ...


5

In the context of a once-off project, it is absolutely appropriate to drop must-use code into mu-plugins. If "having it all in once place" is a concern, just make a symlink in the theme dir to the mu-plugins drop-in, so it'll show up when searching the theme directory.


5

You're on the right track with creating the plugin. All your assumptions are correct. To avoid errors on activation you'll want to wrap the functions that you are redefining in function_exists blocks, as on activation those functions will already be defined: if ( ! function_exists( 'wp_hash_password' ) ) : function wp_hash_password( $password ) { ...


5

Automatically create a new page upon activating a theme if (isset($_GET['activated']) && is_admin()){ $new_page_title = 'This is the page title'; $new_page_content = 'This is the page content'; $new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template. //don't edit under this line $...


5

Show template files being included Display inline comment with Template File and get_template_part files being included when rendering pages. Handy for troubleshooting multipart templates. add_action('all','template_snoop'); function template_snoop(){ $args = func_get_args(); if( !is_admin() and $args[0] ){ if( $args[0] == '...


5

Wrap your function in if( ! function_exists( 'wp_authenticate' ) ) to get rid of the error and successfully activate your plugin: if( ! function_exists( 'wp_authenticate' ) ){ function wp_authenticate(){} } This is necessary because in the context of activating a plugin, the function does already exist, only after it is activated will your plugin load ...


5

I have the same problem on WP 3.2.1. There was a filter conflict because a plugin (User Access Manager) calls manage_users_custom_column filter too. I change priority and it solved the problem : add_filter( 'manage_users_custom_column', 'custom_user_column_value', 15, 3 ); Hope that helps :)


5

You simply need to run your code on a higher priority than what the parent theme is, the default on add_action function is 10 so you can use: function s157343_unregister_widgets() { unregister_widget( 'Chocolat_Widget_New_Entrys' ); } add_action( 'widgets_init', 's157343_unregister_widgets', 20 ); This will unregister that widget. Of course, you can ...


5

You can't. While manipulation of JS and HTML is possible, it is not adviceable as a long term strategy unless it was explicitly document as "the right way" in the codex, code comment, or some other core document. In addition to the theoretical objection, right now it is hard or almost impossible to override specific JS core functions without resorting to ...


5

Generic Pluggable Approach for WordPress < 4.6 (See @birgire's Answer for > 4.6) Pluggable functions are one of the more depressing relics of WordPress's past and come with a slew of intricacies. That directly modifying the core file (which is entirely inadvisable, as @Jarmerson mentioned in the comments) did not work makes me suspect that another plugin ...


4

is_tree() conditional Function /* Adapted from csstricks with addition of ancestors .... use = if(is_tree($id)) { // do stuff } ... Returns true if the page is = $id OR any of it's children OR descendants */ function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath global $post; // load details about this page ...


4

Debug Bar Action Hooks plugin Displays a list of actions fired for the current request. Requires the debug bar plugin.


4

Display the users that have submitted the most comments without a plugin function top_comment_authors($amount = 5) { global $wpdb; $results = $wpdb->get_results(' SELECT COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url FROM '.$wpdb->comments.' WHERE comment_author_email != "" AND ...


4

Note: This is the merged version between my and @toscho answers. Explanation (by @toscho) Use add_meta_boxes_page as action hook. You can find the hook in wp-admin/edit-form-advanced.php and it displays as: do_action('add_meta_boxes_' . $post_type, $post); Solution(s) Try the following action, which is inside register_post_type() as well. function ...


4

I think that i figured it out. Gravatar default images need to be on a public url and not one blocked by htaccess. So i had this on my dev server and when i removed my htaccess file that was blocking access the images started to work. This seems to still be a new feature. Hope that this helps out someone in the future.


4

Remove the action: add_action('wp_footer', 'remove_upme_script', 0 ); function remove_upme_script() { remove_action('wp_footer', 'upme_custom_scripts'); }


3

Directly from source for pluggable.php: <?php /** * These functions can be replaced via plugins. If plugins do not redefine these * functions, then these will be used instead. * * @package WordPress */ ?> So, there's your answer, the functions in pluggable.php are intended to be overridden by Plugins. Re: load order: See this post by ...


3

The problem is that you're trying to load the code directly rather than with a WordPress hook. WordPress loads a bunch of code in a specific order (you can see the list of actions fired in a typical request in the Codex). By trying to fire your code directly, you're executing just before pluggable.php is loaded. And you should not try to include() this ...


3

Remove WordPress 3.3 Admin Bar Menu Items function dashboard_tweaks() { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('about'); $wp_admin_bar->remove_menu('wporg'); $wp_admin_bar->remove_menu('documentation'); $wp_admin_bar->remove_menu('support-forums'); $wp_admin_bar->...


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