Skip to content

Instantly share code, notes, and snippets.

@dnaber-de
Created December 5, 2012 11:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnaber-de/4214994 to your computer and use it in GitHub Desktop.
Save dnaber-de/4214994 to your computer and use it in GitHub Desktop.
Worpress Plugin: Calls the action 'save_post' for Attachment Post Types. Requires PHP 5.3
<?php
/**
* Plugin Name: dna Save Attachment
* Plugin URI: https://gist.github.com/4214994
* Author: David Naber
* Author URI: http://dnaber.de/
* Version: 2014.08.24
* Description: Calls the action 'save_post' for Attachment Post Types vor WordPress versions prior 4.0. Requires PHP 5.3. The plugin will have no effect in WordPress 4.0 or higher. (Getting obsolete when <a href="http://core.trac.wordpress.org/ticket/21963">#21963</a> is fixed.)
*/
namespace DNA\SaveAttachment;
/**
* calls the action 'save_post'
* will be no longer neccessary when http://core.trac.wordpress.org/ticket/21963 gets solved.
*
* @wp-hook edit_attachment
* @wp-hook add_attachment
* @param int $post_ID
* @return void
*/
function do_save_post( $post_ID ) {
if ( ! version_compare( $GLOBALS[ 'wp_version' ], '4.0-beta', 'lt' ) )
return;
$post = get_post( $post_ID );
if ( ! $post )
return;
do_action( 'save_post', $post_ID, $post );
}
add_action( 'edit_attachment', __NAMESPACE__ . '\do_save_post', 5, 1 );
add_action( 'add_attachment', __NAMESPACE__ . '\do_save_post', 5, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment