Home › Forums › ACF PRO › Wysiwyg Editor – hooks for "Add Media" button? › Reply To: Wysiwyg Editor – hooks for "Add Media" button?
I was probably doing something wrong before, because I’ve tried again with the add_attachment action and this time I was successful.
function do_stuff_to_the_uploaded_attachment( $attachment_ID ) {
global $MY_ENDPOINT;
//$user_id = get_current_user_id();
if ( ! current_user_can( 'upload_files' ) ) {
return;
}
$args = array(
'ID' => $attachment_ID,
//'post_title' => 'My default title ...',
'post_excerpt' => 'My default caption ...',
'post_content' => $_SERVER[ 'HTTP_REFERER' ],
);
// Use the Title, Caption and Description,
// to output/diagnose the referer and other data.
wp_update_post( $args );
/**
* If the request came from the specific URL, then do stuff to the attachment.
*
* Note: Ideally we'd target the "Add Media" button itself,
* but since there doesn't seem to be anything identifiable about it,
* we're targeting the URL of its page.
*/
if ( strpos( $_SERVER[ 'HTTP_REFERER' ], $MY_ENDPOINT ) !== false ) {
// Do stuff to the attachment by using its ID i.e. $attachment_ID
}
}
add_action( 'add_attachment', 'do_stuff_to_the_uploaded_attachment', 10, 1 );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.