synchronize category, rename value form

This commit is contained in:
Filip Penkava
2017-02-17 15:22:31 +01:00
parent d5e3b3be6b
commit 84c1b53b5d
2 changed files with 39 additions and 38 deletions

View File

@@ -145,7 +145,7 @@ function mvp_admin() {
</tr> </tr>
<tr> <tr>
<th scope="row"> <th scope="row">
<label for="author">Author</label> <label for="author">Default author</label>
</th> </th>
<td> <td>
<select name="author" id="author"> <select name="author" id="author">
@@ -217,7 +217,7 @@ function mvp_admin() {
</tr> </tr>
<tr> <tr>
<th scope="row"> <th scope="row">
Convert services as Category Import Superdesk categories as Wordpress categories
</th> </th>
<td> <td>
<fieldset> <fieldset>
@@ -265,7 +265,7 @@ function mvp_admin() {
</tr> </tr>
<tr> <tr>
<th scope="row"> <th scope="row">
<label for="category">Category</label> <label for="category">Default category</label>
</th> </th>
<td> <td>
<select name="category[]" id="category" multiple> <select name="category[]" id="category" multiple>

View File

@@ -26,6 +26,40 @@ if ($obj['type'] == 'text') {
$guid = wp_strip_all_tags($obj['guid']); $guid = wp_strip_all_tags($obj['guid']);
} }
foreach ($obj['subject'] as $subject) {
if ($settings['subject-type'] == 'tags') {
$taxonomyTag[] = wp_strip_all_tags($subject['name']);
} elseif ($settings['subject-type'] == 'categories') {
$categoryExist = $wpdb->get_row("SELECT terms.term_id, term_taxonomy.term_taxonomy_id FROM " . $wpdb->prefix . "terms terms JOIN " . $wpdb->prefix . "term_taxonomy term_taxonomy ON term_taxonomy.term_id = terms.term_id WHERE term_taxonomy.taxonomy = 'category' AND terms.name = '" . wp_strip_all_tags($subject['name']) . "'");
if ($categoryExist) {
$taxonomyCategory[] = $categoryExist->term_taxonomy_id;
} else {
$category_id = wp_insert_term(wp_strip_all_tags($subject['name']), 'category');
$taxonomyCategory[] = $category_id['term_taxonomy_id'];
}
}
}
if ($settings['convert-services'] == 'on') {
foreach ($obj['service'] as $service) {
$categoryExist = $wpdb->get_row("SELECT terms.term_id, term_taxonomy.term_taxonomy_id FROM " . $wpdb->prefix . "terms terms JOIN " . $wpdb->prefix . "term_taxonomy term_taxonomy ON term_taxonomy.term_id = terms.term_id WHERE term_taxonomy.taxonomy = 'category' AND terms.name = '" . wp_strip_all_tags($service['name']) . "'");
if ($categoryExist) {
$taxonomyCategory[] = $categoryExist->term_taxonomy_id;
} else {
$category_id = wp_insert_term(wp_strip_all_tags($service['name']), 'category');
$taxonomyCategory[] = $category_id['term_taxonomy_id'];
}
}
}
if ($taxonomyCategory && !empty($taxonomyCategory)) {
$category = $taxonomyCategory;
} else {
$category = $settings['category'];
}
$sync = $wpdb->get_row("SELECT post_id FROM " . $wpdb->prefix . DB_TABLE_SYNC_POST . " WHERE guid = '" . $guid . "'"); $sync = $wpdb->get_row("SELECT post_id FROM " . $wpdb->prefix . DB_TABLE_SYNC_POST . " WHERE guid = '" . $guid . "'");
if ($sync) { if ($sync) {
@@ -35,7 +69,8 @@ if ($obj['type'] == 'text') {
'post_title' => wp_strip_all_tags($obj['headline']), 'post_title' => wp_strip_all_tags($obj['headline']),
'post_name' => wp_strip_all_tags($obj['headline']), 'post_name' => wp_strip_all_tags($obj['headline']),
'post_content' => $content, 'post_content' => $content,
'post_content_filtered' => $content 'post_content_filtered' => $content,
'post_category' => $category
); );
wp_update_post($edit_post); wp_update_post($edit_post);
@@ -81,40 +116,6 @@ if ($obj['type'] == 'text') {
} }
foreach ($obj['subject'] as $subject) {
if ($settings['subject-type'] == 'tags') {
$taxonomyTag[] = wp_strip_all_tags($subject['name']);
} elseif ($settings['subject-type'] == 'categories') {
$categoryExist = $wpdb->get_row("SELECT terms.term_id, term_taxonomy.term_taxonomy_id FROM " . $wpdb->prefix . "terms terms JOIN " . $wpdb->prefix . "term_taxonomy term_taxonomy ON term_taxonomy.term_id = terms.term_id WHERE term_taxonomy.taxonomy = 'category' AND terms.name = '" . wp_strip_all_tags($subject['name']) . "'");
if ($categoryExist) {
$taxonomyCategory[] = $categoryExist->term_taxonomy_id;
} else {
$category_id = wp_insert_term(wp_strip_all_tags($subject['name']), 'category');
$taxonomyCategory[] = $category_id['term_taxonomy_id'];
}
}
}
if ($settings['convert-services'] == 'on') {
foreach ($obj['service'] as $service) {
$categoryExist = $wpdb->get_row("SELECT terms.term_id, term_taxonomy.term_taxonomy_id FROM " . $wpdb->prefix . "terms terms JOIN " . $wpdb->prefix . "term_taxonomy term_taxonomy ON term_taxonomy.term_id = terms.term_id WHERE term_taxonomy.taxonomy = 'category' AND terms.name = '" . wp_strip_all_tags($service['name']) . "'");
if ($categoryExist) {
$taxonomyCategory[] = $categoryExist->term_taxonomy_id;
} else {
$category_id = wp_insert_term(wp_strip_all_tags($service['name']), 'category');
$taxonomyCategory[] = $category_id['term_taxonomy_id'];
}
}
}
if ($taxonomyCategory && !empty($taxonomyCategory)) {
$category = $taxonomyCategory;
} else {
$category = $settings['category'];
}
$postarr = array( $postarr = array(
'post_title' => wp_strip_all_tags($obj['headline']), 'post_title' => wp_strip_all_tags($obj['headline']),
'post_name' => wp_strip_all_tags($obj['headline']), 'post_name' => wp_strip_all_tags($obj['headline']),