Support has been upgraded!
The Support Forum is closed. Not to worry! Providing the top quality support you expect and we're known for will continue! We're not ending support, just changing where you submit requests. This will provide you with the best experience possible.
Premium Support
Have you purchased an addon for Connections such as one of our premium templates or extensions with a valid license and you need help?
Please open a Support Ticket in your user account.
Free Support
Are you using the free Connections plugin? Don't worry, you are still very important to us! We are still providing you with the same high quality support that we're known for.
Please open a new support topic in the WordPress support forums for Connections.
Tagged: 8.28.5
- This topic has 16 replies, 2 voices, and was last updated 3 years, 2 months ago by
Steven Zahm.
-
AuthorPosts
-
02/04/2019 at 8:51 am #483479
Steven Zahm
Keymaster@ Joshua
Can you share what you’ve been writing? Is it up on Github?
02/19/2019 at 8:28 pm #485084Joshua Tempesta
ParticipantHey Steven,
Sorry for my delay i been juggling projects.
This is really horrible code but it gets the job done:In registration magic I just set the post submission url to: http://www.yoursite.com/wp-admin/admin-ajax.php
Feel free to do whatever you want with it. Figured it’d be nice to have a bridge between RM and your plugin.
Best wishes,
PS: can you tell me how to add images to an entry programmatically? I can’t figure it out you may see the commented out line i started.
02/19/2019 at 8:30 pm #485085Joshua Tempesta
Participant02/19/2019 at 8:30 pm #48508602/20/2019 at 9:14 am #485184Steven Zahm
Keymaster@ Joshua
Thanks!, I throw it up in my Github account for safekeeping.
https://github.com/Connections-Business-Directory/Registration-Magic-Connector
02/21/2019 at 9:24 am #485333Joshua Tempesta
ParticipantAwesome. Hopefully someone can benefit from it..
Is it hard to associate an existing media library item (or image url) with a business connections entry programmatically?
02/21/2019 at 10:02 am #485342Steven Zahm
Keymaster@ Joshua
RE: Is it hard to associate an existing media library item (or image url) with a business connections entry programmatically?
Sorry, but this will not be possible. Connections uses its own image “stash” for the lack of a better term. This is primarily for performance/usability reasons. WordPress stores all its image meta as a post type in the database. So when you access an image, you have to first hit the DB, then the image. Connections can also crop/scale on demand and cache’s them. With the Media Library, a new image size needs registered, then a plugin like Regenerate thumbnails needs to be run to create the new size for all images.
The best that could be done is “sideload” an image from the Media Library into the Connections cache.
Here’s a code snippet I have handy for sideloading an image added to an Connections Entry into the Media Library. This does not link the two images in any way. It just adds the image to the Media Library.
add_action( 'cn_post_process_add-entry', 'cn_insert_image_into_media_library' ); add_action( 'cn_post_process_update-entry', 'cn_insert_image_into_media_library' ); function cn_insert_image_into_media_library( $entry ) { $image = $entry->getimageMeta(); if ( ! is_wp_error( $image ) ) { // $file = array( // 'url' => $image['url'], // 'type' => $image['type'], // 'path' => $image['path'], // ); // $time = current_time( 'mysql' ); // $url = $file['url']; // $type = $file['type']; // $file = $file['path']; // $title = preg_replace('/\.[^.]+$/', '', basename( $file ) ); // $content = ''; // // Use image exif/iptc data for title and caption defaults if possible. // if ( $image_meta = @wp_read_image_metadata( $file ) ) { // if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { // $title = $image_meta['title']; // } // if ( trim( $image_meta['caption'] ) ) { // $content = $image_meta['caption']; // } // } // // Construct the attachment array. // $attachment = array_merge( // array( // 'post_mime_type' => $type, // 'guid' => $url, // 'post_parent' => 0, // 'post_title' => $title, // 'post_content' => $content, // ), // array() // ); // // This should never be set as it would then overwrite an existing attachment. // unset( $attachment['ID'] ); // // Save the attachment metadata // $id = wp_insert_attachment( $attachment, $file, 0 ); // if ( ! is_wp_error( $id ) ) { // wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); // } /* * Read the contents of the upload directory. We need the * path to copy the file and the URL for uploading the file. */ $uploads = wp_upload_dir(); $uploads_dir = $uploads['path']; $uploads_url = $uploads['url']; // Copy the file from the root directory to the uploads directory copy( $image['path'], trailingslashit( $uploads_dir ) . $image['name'] ); /* * Get the URL to the file and grab the file and load * it into WordPress (and the Media Library) */ $url = trailingslashit( $uploads_url ) . $image['name']; $result = media_sideload_image( $url, 0, $image['name'] ); // If there's an error, then we'll write it to the error log. if ( is_wp_error( $result ) ) { error_log( print_r( $result, true ) ); } } }
I do not have any code handy to sideload an image into an Entry from the Media Library. I do plan on writing a series on helper functions to make adding an logo/photo easy. I need these for the REST API for Connections I’ve been working on. But I’m not there yet.
You should be able to cobble something together from these lines of code:
And the code from this function:
You would need to tweak the to use an the absolute file path of an image from the Media Library instead of the files upload path.
Hope this helps!
-
AuthorPosts
You cannot reply to this support topic. Please open your own support topic.