How to remove parent section from attachment URL?

The attachment URL is created in wp-includes/link-template.php in function get_attachment_link(). And there is a filter for you, passing the WordPress URL and the post id for the attachment. You can hook into that filter and return the URL you need: add_filter( ‘attachment_link’, ‘wpse_56619_unprettify_attachment_url’, 10, 2 ); function wpse_56619_unprettify_attachment_url( $link, $id ) { return home_url( “/?attachment_id=$id” … Read more

media_sideload_image with rewritten urls?

You’re right, it’s because by default, wp_handle_sideload() requires a valid extension in the URI in order to continue processing the sideload. That is, unless your role has a capability called ‘unfiltered_upload‘, which by default is only given to admins. If it seems appropriate (and safe) for you to grant this capability to the user role … Read more

Adding width and height to wp_get_attachment_image_src

What is ‘two’ referring to? Is that a custom image size? Place the following var_dump(‘<pre>’,$image,'</pre>’); after your declared $image variable like so, $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘two’ ); var_dump(‘<pre>’,$image,'</pre>’); and provide the results so we can inspect the output. As per Codex the second argument in this function, wp_get_attachment_image_src( $attachment_id, $size, $icon ); … Read more

How to delete all post and attachments of a user when I delete it?

The hook you choose is appropriate, and here is how to use it to delete all posts of all types (posts, pages, links, attachments, etc) of the deleted user: add_action(‘delete_user’, ‘my_delete_user’); function my_delete_user($user_id) { $args = array ( ‘numberposts’ => -1, ‘post_type’ => ‘any’, ‘author’ => $user_id ); // get all posts by this user: … Read more

Show how many images are attached to a post/page on compose page

add_action( ‘add_meta_boxes’, ‘attached_images_meta’ ); function attached_images_meta() { $screens = array( ‘post’, ‘page’ ); //add more in here as you see fit foreach ($screens as $screen) { add_meta_box( ‘attached_images_meta_box’, //this is the id of the box ‘Attached Images’, //this is the title ‘attached_images_meta_box’, //the callback $screen, //the post type ‘side’ //the placement ); } } function … Read more

Set the default category of an attachment

To solve the problem 1, you could hook to add_attachment and edit_attachment hook. add_action(‘add_attachment’, ‘wpse_set_attachment_category’); add_action(‘edit_attachment’, ‘wpse_set_attachment_category’); function wpse_set_attachment_category( $post_ID ) { // if attachment already have categories, stop here if( wp_get_object_terms( $post_ID, ‘category’ ) ) return; // no, then get the default one $post_category = array( get_option(‘default_category’) ); // then set category if default … Read more

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