Created
December 5, 2012 11:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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