add import service to tags and category
This commit is contained in:
@@ -32,6 +32,7 @@ function mvp_admin() {
|
|||||||
'author' => $_POST['author'],
|
'author' => $_POST['author'],
|
||||||
'author-byline' => $_POST['author-byline'],
|
'author-byline' => $_POST['author-byline'],
|
||||||
'display-copyright' => $_POST['display-copyright'],
|
'display-copyright' => $_POST['display-copyright'],
|
||||||
|
'subject-type' => $_POST['subject-type'],
|
||||||
'category' => $_POST['category'],
|
'category' => $_POST['category'],
|
||||||
);
|
);
|
||||||
update_option('mvp_settings', $settings);
|
update_option('mvp_settings', $settings);
|
||||||
@@ -47,6 +48,7 @@ function mvp_admin() {
|
|||||||
'author' => '',
|
'author' => '',
|
||||||
'author-byline' => '',
|
'author-byline' => '',
|
||||||
'display-copyright' => '',
|
'display-copyright' => '',
|
||||||
|
'subject-type' => '',
|
||||||
'category' => '',
|
'category' => '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -185,6 +187,30 @@ function mvp_admin() {
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">
|
||||||
|
Import Superdesk subjects as
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<fieldset>
|
||||||
|
<label for="tags">
|
||||||
|
<input type="radio" name="subject-type" id="tags" value="tags"<?php
|
||||||
|
if ($settings['subject-type'] == 'tags' || !$settings['subject-type'] || $settings['subject-type'] == null) {
|
||||||
|
echo(' checked');
|
||||||
|
}
|
||||||
|
?>> Wordpress tags
|
||||||
|
</label>
|
||||||
|
<br>
|
||||||
|
<label for="categories">
|
||||||
|
<input type="radio" name="subject-type" id="categories" value="categories"<?php
|
||||||
|
if ($settings['subject-type'] == 'categories') {
|
||||||
|
echo(' checked');
|
||||||
|
}
|
||||||
|
?>> Wordpress categories
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="category">Category</label>
|
<label for="category">Category</label>
|
||||||
|
|||||||
31
autoload.php
31
autoload.php
@@ -5,7 +5,8 @@ require_once '../../../wp-load.php';
|
|||||||
$json = file_get_contents('php://input');
|
$json = file_get_contents('php://input');
|
||||||
//$json = file_get_contents('log.txt');
|
//$json = file_get_contents('log.txt');
|
||||||
|
|
||||||
file_put_contents('log.txt', $json . "\n\n", FILE_APPEND);
|
//file_put_contents('log.txt', $json . "\n\n", FILE_APPEND);
|
||||||
|
//die();
|
||||||
$obj = json_decode($json, true);
|
$obj = json_decode($json, true);
|
||||||
|
|
||||||
if ($obj['type'] == 'composite') {
|
if ($obj['type'] == 'composite') {
|
||||||
@@ -57,6 +58,27 @@ if ($obj['type'] == 'composite') {
|
|||||||
$author_id = $settings['author'];
|
$author_id = $settings['author'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($obj['service'] as $service) {
|
||||||
|
if ($settings['subject-type'] == 'tags') {
|
||||||
|
$taxonomyTag[] = wp_strip_all_tags($service['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($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']),
|
||||||
@@ -64,11 +86,15 @@ if ($obj['type'] == 'composite') {
|
|||||||
'post_content_filtered' => $content,
|
'post_content_filtered' => $content,
|
||||||
'post_author' => (int) $author_id,
|
'post_author' => (int) $author_id,
|
||||||
'post_status' => $settings['status'],
|
'post_status' => $settings['status'],
|
||||||
'post_category' => $settings['category'],
|
'post_category' => $category,
|
||||||
);
|
);
|
||||||
|
|
||||||
$post_ID = wp_insert_post($postarr, true);
|
$post_ID = wp_insert_post($postarr, true);
|
||||||
|
|
||||||
|
if ($taxonomyTag && !empty($taxonomyTag)) {
|
||||||
|
wp_set_post_tags($post_ID, $taxonomyTag);
|
||||||
|
}
|
||||||
|
|
||||||
$table_name = $wpdb->prefix . DB_TABLE_SYNC_POST;
|
$table_name = $wpdb->prefix . DB_TABLE_SYNC_POST;
|
||||||
|
|
||||||
$wpdb->insert(
|
$wpdb->insert(
|
||||||
@@ -79,7 +105,6 @@ if ($obj['type'] == 'composite') {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if ($obj['associations']['featuremedia'] && $obj['associations']['featuremedia']['type'] == 'picture') {
|
if ($obj['associations']['featuremedia'] && $obj['associations']['featuremedia']['type'] == 'picture') {
|
||||||
/* save featured media */
|
/* save featured media */
|
||||||
$picture = $obj['associations']['featuremedia'];
|
$picture = $obj['associations']['featuremedia'];
|
||||||
|
|||||||
Reference in New Issue
Block a user