/** * Process custom field settings against all image attachments * without saving the settings to the mla_option * * @since 1.10 * @uses $_REQUEST if passed a NULL parameter * * @param array | NULL specific custom_field_mapping values * @param integer offset for chunk mapping * @param integer length for chunk mapping * * @return array Message(s) reflecting the results of the operation */ private static function _process_custom_field_mapping($settings = NULL, $offset = 0, $length = 0) { global $wpdb; if (NULL == $settings) { $source = 'custom_fields'; $settings = isset($_REQUEST['custom_field_mapping']) ? stripslashes_deep($_REQUEST['custom_field_mapping']) : array(); if (isset($settings[MLAOptions::MLA_NEW_CUSTOM_FIELD])) { unset($settings[MLAOptions::MLA_NEW_CUSTOM_FIELD]); } if (isset($settings[MLAOptions::MLA_NEW_CUSTOM_RULE])) { unset($settings[MLAOptions::MLA_NEW_CUSTOM_RULE]); } } else { $source = 'custom_rule'; $settings = stripslashes_deep($settings); } if (empty($settings)) { return array('message' => __('ERROR', 'media-library-assistant') . ': ' . __('No custom field mapping rules to process.', 'media-library-assistant'), 'body' => ''); } if ($length > 0) { $limits = "LIMIT {$offset}, {$length}"; } else { $limits = ''; } $examine_count = 0; $update_count = 0; $post_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE `post_type` = 'attachment' {$limits}"); do_action('mla_begin_mapping', $source, NULL); foreach ($post_ids as $key => $post_id) { $updates = MLAOptions::mla_evaluate_custom_field_mapping((int) $post_id, 'custom_field_mapping', $settings); $examine_count += 1; if (!empty($updates) && isset($updates['custom_updates'])) { $results = MLAData::mla_update_item_postmeta((int) $post_id, $updates['custom_updates']); if (!empty($results)) { $update_count += 1; } } } // foreach post do_action('mla_end_mapping'); if ($update_count) { /* translators: 1: field type 2: examined count 3: updated count */ $message = sprintf(__('%1$s mapping completed; %2$d attachment(s) examined, %3$d updated.'), __('Custom field', 'media-library-assistant'), $examine_count, $update_count) . "\r\n"; } else { /* translators: 1: field type 2: examined count */ $message = sprintf(__('%1$s mapping completed; %2$d attachment(s) examined, no changes detected.'), __('Custom field', 'media-library-assistant'), $examine_count) . "\r\n"; } return array('message' => $message, 'body' => '', 'processed' => $examine_count, 'unchanged' => $examine_count - $update_count, 'success' => $update_count); }
/** * Process custom field settings against all image attachments * without saving the settings to the mla_option * * @since 1.10 * @uses $_REQUEST if passed a NULL parameter * * @param array | NULL specific custom_field_mapping values * * @return array Message(s) reflecting the results of the operation */ private static function _process_custom_field_mapping($settings = NULL) { global $wpdb; if (NULL == $settings) { $settings = isset($_REQUEST['custom_field_mapping']) ? $_REQUEST['custom_field_mapping'] : array(); if (isset($settings[MLAOptions::MLA_NEW_CUSTOM_FIELD])) { unset($settings[MLAOptions::MLA_NEW_CUSTOM_FIELD]); } if (isset($settings[MLAOptions::MLA_NEW_CUSTOM_RULE])) { unset($settings[MLAOptions::MLA_NEW_CUSTOM_RULE]); } } if (empty($settings)) { return array('message' => 'ERROR: No custom field mapping rules to process.', 'body' => ''); } $examine_count = 0; $update_count = 0; $post_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE `post_type` = 'attachment'"); foreach ($post_ids as $key => $post_id) { $updates = MLAOptions::mla_evaluate_custom_field_mapping((int) $post_id, 'custom_field_mapping', $settings); $examine_count += 1; if (!empty($updates)) { $results = MLAData::mla_update_item_postmeta((int) $post_id, $updates['custom_updates']); if (!empty($results)) { $update_count += 1; } } } // foreach post if ($update_count) { $message = "Custom field mapping completed; {$examine_count} attachment(s) examined, {$update_count} updated.\r\n"; } else { $message = "Custom field mapping completed; {$examine_count} attachment(s) examined, no changes detected.\r\n"; } return array('message' => $message, 'body' => ''); }