-
AuthorPosts
-
November 22, 2015 at 18:13 #5752bebablubParticipant
Hello,
thank you for your great plugin.
Is there any possibility to import pictures from a given file system folder to a specific album automatically?
I know about the import from folder feature. I only need the possibility to trigger it (or such a Post Request) via let’s say something like a cron job. I already captured the request but it includes a nonce value which is not infinite usable. But probably there are other (simple) ways to get it to work? I would like to avoid making a dedicated script which scans a directory, copies files and alters db (because i have to modify it probably with every update).The idea of this features is that i would like to import photos uploaded from my mobile phone to my owncloud storage (on same machine) automatically.
Thank you very much!
November 29, 2015 at 22:29 #5761RattusKeymaster$skip_if_file_name_already_exists = true; $folder_path = 'PATH_TO_FOLDER_WITH_FILES'; // if you do not want to assign any album or tags $terms = array(); // else /* $terms = array( 'gmedia_album' => 'Album Name', 'gmedia_tag' => 'tags, separated, by comma' ); */ $files = glob($folder_path . '?*.?*', GLOB_NOSORT); if (! empty($files)) { global $gmCore; $allowed_ext = get_allowed_mime_types(); $allowed_ext = array_keys($allowed_ext); $allowed_ext = implode('|', $allowed_ext); $allowed_ext = explode('|', $allowed_ext); if ($skip_if_file_name_already_exists) { $exists = false; } else { $exists = 0; } foreach ($files as $i => $filepath) { $ext = pathinfo($filepath, PATHINFO_EXTENSION); if (! in_array(strtolower($ext), $allowed_ext)) { unset($files[$i]); } } $gmCore->gmedia_import_files($files, $terms, $move = false, $exists); }
November 30, 2015 at 00:46 #5785bebablubParticipantHello,
thank you for your reply. It gives me a brief idea on how to use gmedia functions.
But how is this code meant to be? Probably it sounds stupid but how and from where to call that code?
If i make a standalone php file out of it there are wordpress and gmedia gallery specific objects/methods are missing.I tried using it with the “insert php” wordpress plugin without success. If i add it to some gmedia button action, for example import it won’t give me the desired solution because the idea should be that a import should be initiated without activly logged in into admin panel (as mentions let’s say from a cron job with a call like “php -f import.php”)
Greats
November 30, 2015 at 00:58 #5787RattusKeymasterYou can add this code to your theme’s functions.php:
// create a scheduled event (if it does not exist already) function cronstarter_activation() { if( !wp_next_scheduled( 'mycronjob' ) ) { wp_schedule_event( time(), 'daily', 'mycronjob' ); } } // and make sure it's called whenever WordPress loads add_action('wp', 'cronstarter_activation'); // here's the function we'd like to call with our cron job function my_repeat_function() { // do here what needs to be done automatically as per your schedule } // hook that function onto our scheduled event: add_action ('mycronjob', 'my_repeat_function');
November 30, 2015 at 21:50 #5792bebablubParticipantThank you very much! Seems to work now :)
June 12, 2016 at 13:58 #7103AnonymousInactiveHi all,
I used this code in functions.php.
Works good.
When importing large amounts of pictures the plugin has a timeout. When importing again the plugin creates doubles or triples from some pictures.
I thought this line was to prevent doubles.
$skip_if_file_name_already_exists = true;
But even with this setting I get doubles.
What can I do to prevent doubles?
Thank you.
Sebastiaan.
-
AuthorPosts
- The forum ‘Requests and Feedback’ is closed to new topics and replies.