diff --git a/admin/admin.php b/admin/admin.php
index 2bf9f5f..a8bd078 100644
--- a/admin/admin.php
+++ b/admin/admin.php
@@ -30,6 +30,7 @@ function mvp_admin() {
'client_id' => $_POST['client_id'],
'status' => $_POST['status'],
'author' => $_POST['author'],
+ 'author-byline' => $_POST['author-byline'],
'category' => $_POST['category'],
);
update_option('mvp_settings', $settings);
@@ -43,6 +44,7 @@ function mvp_admin() {
'password' => '',
'status' => 'publish',
'author' => '',
+ 'author-byline' => '',
'category' => '',
);
}
@@ -138,7 +140,7 @@ function mvp_admin() {
- |
@@ -180,5 +186,10 @@ function mvp_admin() {
+
get_row("SELECT ID user_id FROM " . $wpdb->prefix . DB_TABLE_USERS . " WHERE display_name = '" . wp_strip_all_tags($author_name) . "'");
+
+ if (!$authorExist) {
+ $table_name = $wpdb->prefix . DB_TABLE_USERS;
+
+ $userArray = array(
+ 'user_login' => strtolower(str_replace(" ", "-", $author_name)),
+ 'user_pass' => generatePassword(),
+ 'display_name' => wp_strip_all_tags($author_name)
+ );
+
+ $author_id = wp_insert_user($userArray);
+ } else {
+ $author_id = $authorExist->user_id;
+ }
+ } else {
+ $author_id = $settings['author'];
+ }
+
$postarr = array(
'post_title' => wp_strip_all_tags($obj['headline']),
'post_name' => wp_strip_all_tags($obj['headline']),
'post_content' => $content,
'post_content_filtered' => $content,
- 'post_author' => (int) $settings['author'],
+ 'post_author' => (int) $author_id,
'post_status' => $settings['status'],
'post_category' => $settings['category'],
);
diff --git a/mvp.php b/mvp.php
index f859f6b..3e63fb6 100644
--- a/mvp.php
+++ b/mvp.php
@@ -26,6 +26,7 @@ define('MVP_PLUGIN_URL', untrailingslashit(plugins_url('', MVP_PLUGIN)));
define('MVP_DATABASE_VERSION', '2');
define('DB_TABLE_SYNC_POST', 'sync_posts');
+define('DB_TABLE_USERS', 'users');
require_once MVP_PLUGIN_DIR . '/settings.php';
@@ -69,5 +70,16 @@ function saveFile($from, $to) {
fclose($fp);
}
+function generatePassword() {
+ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%./\@';
+ $charactersLength = strlen($characters);
+ $password = '';
+ for ($i = 0; $i < 8; $i++) {
+ $password .= $characters[rand(0, $charactersLength - 1)];
+ }
+ $password = $password . strtotime("now");
+ return $password;
+}
+
register_activation_hook(__FILE__, 'mvp_database_install');
add_action('plugins_loaded', 'mvp_database_update');