dir($algo_remote_folder); if(!$algo_wp->exists()) { $algo_wp->create(Algorithmia\ACL::ANYONE); //so that the ObjRecognizer algo can analyze the file (note: NOT public/anonymous available) } //put the file into the folder $file = $algo_wp->putFile($image_path); //check to see if everything went ok! if($file->response->getStatusCode() !== 200 ) { //something went wrong throw new Exception("There was a problem sending this file to Algorithmia."); } //get the remote data url that the object detection algorithm can use to load the file // this will be an algorithmia path like "data://.my/algo_wp/myfile.png" $input = $file->getDataUrl(); } else { //otherwise just use the url (doesn't work for localhost because algo can't access the file via the url) $input = get_post( $in_post_id )->guid; //url to the file on our server } //now run the algorithm and do the magic! $algo = $client->algo($object_recognition_algorithm); //the results come back as a PHP object. handy! $result = $algo->pipe($input)->result; $labels = []; //what objects did the algorithm find? it labels each object and returns the labels in an array called boxes. // each algorithm responds their own way. see the algorithm documentation to determine what you may need to use the results. foreach($result->boxes as $item) { if(!in_array($item->label, $labels)) $labels[]=$item->label; } //now return our labels as a string for our alt-text! return implode(" ",$labels); } //admin section for this algorithm that appears on the settings page function algo_upload_auto_tag_settings_init() { // register a new section in the "algo" page add_settings_section( 'algo_section_uat', //id 'Feature: Auto-tag Uploads', //title 'algo_section_uat_cb', //callback 'algo' //page (menu-slug) ); add_settings_field( 'algo_field_uat_enabled', //id 'Enable this feature', //title 'algo_field_checkbox_cb', //callback for text fields 'algo', //page (menu-slug) 'algo_section_uat', //section [ //args 'label_for' => 'algo_field_uat_enabled', 'class' => 'algo_row', 'algo_custom_data' => 'custom', 'default' => false ] ); add_settings_field( 'algo_field_uat_algo', //id 'Object Detection Algorithm', //title 'algo_field_text_cb', //callback for text fields 'algo', //page (menu-slug) 'algo_section_uat', //section [ //args 'label_for' => 'algo_field_uat_algo', 'class' => 'algo_row', 'algo_custom_data' => 'custom', 'default' => "deeplearning/ObjectDetectionCOCO/0.2.1" ] ); add_settings_field( 'algo_field_uat_remote_folder', //id 'Remote Folder (if Upload to Algorithmia is selected)', //title 'algo_field_text_cb', //callback for text fields 'algo', //page (menu-slug) 'algo_section_uat', //section [ //args 'label_for' => 'algo_field_uat_remote_folder', 'class' => 'algo_row', 'algo_custom_data' => 'custom', 'default' => "data://.my/algo_wp" ] ); } //callback for the section header created above. function algo_section_uat_cb( $args ) { ?>