Checking post format during xmlrpc_publish_post

This is because of a variable mismatch. Your function accepts $post_ID, but you don’t actually use it. You’re instead trying to reference a global $post object and doing your post format check with $post->ID. With the XML-RPC request, this won’t work. Rewrite your function to use get_post() to fetch a post object from the passed-in … Read more

How to prevent double execution of do_action statements

To check if someone already hooked into myhook1 if( 0 >= did_action( ‘myhook1’ ) ) do_action( ‘myhook1’, ‘myfunction1′ ); If you want to check if the function myfunction1 was already called (maybe by a simple function call), you have to set a ‘marker’ function myfunction1 ( $some_args ) { // with a simple global define … Read more

Storing state between hook functions

Uing OOP for your plugin it’s very easy. class MyPlugin { static $flag; static function function_a() { self::$flag = ‘a value’; } static function function_b() { if ( ! is_null(self::$flag) ) echo self::$flag; // echo ‘A Value’; } } add_action(‘plugins_loaded’, array(‘MyPlugin’, ‘function_a’) ); add_action(‘init’, array(‘MyPlugin’, ‘function_b’) ); Not using OOP you can use global variables. … Read more

How to find a callback attached to a bbpress hook?

To find an attached callback, you normally can just do the following: printf( ‘<pre>%s</pre>’, var_export( $GLOBALS[‘wp_filter’][‘hook_name’], TRUE ) ); This should give you back an array of callbacks attached to a hook, ordered by priority (which serves as key).

How to hook in after user’s registration email has been sent?

I would use the registration_redirect filter. This allows you to set where the user is sent to, but leaves WordPress to perform the redirect (after everything has successfully processed). function wpse_139267_registration_redirect( $url ) { return site_url( ‘thank-you’ ); } add_filter( ‘registration_redirect’, ‘wpse_139267_registration_redirect’ );

Get log of function/method calls made by do_action() on WordPress initialization

I don’t believe there is a way to do this via a plugin (at least in a way that will get around 500 type errors, which is why I originally looked into this), but the section of code where the hook callback gets called is in wp-includes/plugin.php in the do_action function: https://github.com/WordPress/WordPress/blob/master/wp-includes/plugin.php#L453 This got updated … Read more

Add parameter (time) to oembed

No extra code needed. Simply include the timestamp parameter onto the YouTube link, with the format of hash t equals number m number s. Or in other words: #t=1m02s The numbers are minutes and seconds. Example of a rickroll pre-fast-forwarded to 1 minute in: http://www.youtube.com/watch?v=dQw4w9WgXcQ#t=1m0s YouTube’s oEmbed endpoint seems to handle this just fine and … Read more

add_action for unknown custom post types

The first one does not work because to use that format you need double quotes. add_action( “publish_{$custom_post_type}” , ‘run_new_post_code’ ); That will let the wrapped variable name be processed properly. To do something for all custom post types you probably just need to grab the list of custom post types and cycle through them adding … Read more

Help to change the text for new website notification (wpmu_welcome_notification)

Here’s an untested example, how you could modify the email body to your needs: add_filter( ‘update_welcome_email’, function( $welcome_email, $blog_id, $user_id, $password, $title, $meta ) { // Override the email body: $welcome_email = __( ‘Dear User, Your new SITE_NAME site has been successfully set up at: BLOG_URL You can log in to the administrator account with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)