WSP-29 WP author byline by
This commit is contained in:
@@ -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() {
|
||||
<label for="author">Author</label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="author" id="author">
|
||||
<select name="author" id="author" <?php echo ($settings['author-byline']) ? 'disabled="true"' : ""; ?>>
|
||||
<?php
|
||||
foreach ($authors as $key => $value) {
|
||||
?>
|
||||
@@ -151,6 +153,10 @@ function mvp_admin() {
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br /><br />
|
||||
<label>
|
||||
<input type="checkbox" name="author-byline" <?php echo ($settings['author-byline']) ? "checked" : ""; ?> onclick="setAuthor()"> Show byline in posts
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -180,5 +186,10 @@ function mvp_admin() {
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
function setAuthor() {
|
||||
console.log('zavolano');
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
25
autoload.php
25
autoload.php
@@ -30,12 +30,35 @@ if ($obj['type'] == 'composite') {
|
||||
|
||||
wp_update_post($edit_post);
|
||||
} else {
|
||||
|
||||
if ($settings['author-byline'] && $settings['author-byline'] == 'on') {
|
||||
$author_name = str_replace("By ", "", $obj['byline']);
|
||||
|
||||
$authorExist = $wpdb->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'],
|
||||
);
|
||||
|
||||
12
mvp.php
12
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');
|
||||
|
||||
Reference in New Issue
Block a user