BuddyDev

Search

Replies

  • Participant
    Level: Initiated
    Posts: 20
    karamveer on in reply to: Pragmatically create mediapress Gallery! #49678

    Thanks, Brajesh, Let me try your suggested way and asap will get back to you with the results.

  • Participant
    Level: Initiated
    Posts: 20
    karamveer on in reply to: Pragmatically create mediapress Gallery! #49676

    Hi Brajesh,

    Thanks for your reply but sorry to say not getting much of what you’re suggested.

    What I understand MediaPress- is not suitable for MultiSite/Network, please correct me.

    Regards,
    Karamveer Singh

  • Participant
    Level: Initiated
    Posts: 20
    karamveer on in reply to: Pragmatically create mediapress Gallery! #49671

    Hi Brajesh,

    Thank you for your continued support. About your queries kindly look underneath my comments and let me know if there is any further information required.

    1. Is it a normal multisite with BuddyPress network active or do you have BuddyPress in Multi Network mode(BuddyPress behaves to be available on all sites and directory/profile is available from all of the sites).
    Answer: Yes our website is running on multisite with BuddyPress in Multi Network mode.Our both plugins(MediaPRess/BuddyPress) are configured from Network Admin.

    2. Or is BuddyPress just active on a single blog/site on the network?
    Answer: No, It’s being activated by the Network admin and enabled under all sites.

    3. On which blog BuddyPress and MediaPress are active?
    Answer: We have 2 blogs(sites) and in both buddypress/mediapress plugin is activated.

    4. Is MediaPress network active or just active on a single site of the network?
    Answer: MediaPress is network active.

    5. Is the gallery and the media you want to add to the gallery available on same site?
    Answer:: Yes, the gallery and the media we want to add, are available on the same site.

    6. If the answer to the previous question is no, What is the source of media? Do you want to import an existing attachment to gallery or do you want to import a media from somewhere on the web to the gallery?
    Answer: Answer to all above question is Yes, We uploaded the media in uploads(see next reply for exact path) via FTP and with API trying to attach it to WordPress Media and Media press gallery.

    7. or is there any chance that you have some way to upload your media and you want to add it to gallery after you have handled the upload on you own?
    Answer: Yes right, we already have media and placed there inside the site folders which we’re mapping by the API to WP. Both 2 sites’ media folders path look like this – \wp-content\uploads\sites\2 , \wp-content\uploads\sites\3

  • Participant
    Level: Initiated
    Posts: 20
    karamveer on in reply to: Pragmatically create mediapress Gallery! #49658

    Hi Brajesh,

    Thank you for your quick response—I really appreciate you getting back to me so soon. About your suggestion already tried same in my logic, see below the complete snippet of the function.

    
    function imagecreateprogram(){
    	switch_to_blog(3);
    	$gallery_id = 5;
    	
    	mpp_import_attachment('10',$gallery_id);
    	
    		require_once ABSPATH . 'wp-admin/includes/image.php';
    		
    		$storage = mpp_local_storage();
    		// destination.
    		$uploads = $storage->get_upload_dir( array(
    			'component'    => 'sitewide',
    			'component_id' => 1/* $gallery->component_id */,
    			'gallery_id'   => $gallery_id,
    		) );
    		
    		$imagename = 'karamveer.jpg';
    		
    		$image_url = $uploads['url'] . '/'.$imagename;
    
    		//$image_data = file_get_contents( $image_url );
    		
    		$filename = basename( $image_url );
    
    		// if destination directory does not exists, try creating it.
    		if ( ! file_exists( $uploads['path'] ) ) {
    			wp_mkdir_p( $uploads['path'] );
    		}
    
    		if ( file_exists( $uploads['path'] ) ) {
    			  $file = $uploads['path'] . '/' . $filename;
    		} else {
    			  $file = $uploads['basedir'] . '/' . $filename;
    		}
    
    	
    	$wp_filetype = wp_check_filetype( $filename, null );
    	
    
    	$wp_gallery_id = $gallery_id;
    	$photoTitle = 'Test Title';
    	$customerID = 1;
    	$photoDesc = 'Photo Description';
    	$attachment = array(
    		'post_mime_type' => $wp_filetype['type'],
    		'post_title'	 => $photoTitle,
    		/* 'post_date'		 => $createdDate, */
    		'post_parent'	 => $wp_gallery_id,
    		'post_author'	 => $customerID,
    		'post_content'	 => $photoDesc,
    		'post_status' 	 => 'inherit',
    	);
    			
    	$attachment = sanitize_post( $attachment, 'db' );
    	
    	 $image_subdir_path = $uploads['subdir'] . '/' . $filename;
    	
    	
    	$attach_id = wp_insert_attachment( $attachment, ltrim($image_subdir_path, '/'),$gallery_id );
    	require_once( ABSPATH . 'wp-admin/includes/image.php' );
    	$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    	wp_update_attachment_metadata( $attach_id, $attach_data );
    	
    	mpp_update_media_meta( $attach_id, '_mpp_is_mpp_media', 1 );
    	mpp_update_media_meta( $attach_id, '_mpp_component_id', 1 );
    	mpp_update_media_meta( $attach_id, '_wp_attached_file', $filename );
    	mpp_import_attachment($attach_id,$gallery_id); // not working
    	return rest_ensure_response($attach_id);
    
    }
    
    • This reply was modified 1 year, 6 months ago by karamveer.
    • This reply was modified 1 year, 6 months ago by karamveer.