μ°λ¦¬λ κ½€ ν° μ¬μ΄νΈ λ€νΈμν¬λ₯Ό κ°μ§κ³ μμ΅λλ€. λͺ¨λ μ μ ν μμ±μ μ 보λ₯Ό νμν΄μΌ ν©λλ€. νμ¬ Distributorλ λ°°ν¬λ κ²μλ¬Ό μμ±μλ₯Ό μΈμ¦λ μ¬μ©μ IDλ‘ μ€μ ν©λλ€. λλ μ΄κ²μ λ°κΎΈκ³ μΆμ΅λλ€(κ·Έλ¦¬κ³ κΈ°κΊΌμ΄ μ€μ€λ‘ μΌμ ν μν₯μ΄ μμ΅λλ€). λ€μμ λ κ°μ§ κ°λ₯ν μ루μ μ λλ€.
dt_item_mapping
λλ νΈμ νν°μ κ²½μ° dt_push_post_args
μ¬μ©). μ°λ¦¬λμ κ²μνκ³ μμ΅λλ€. μ΄λ₯Ό μν΄μλ μ΅μ’
μ¬μ©μκ° μΈλΆ μ¬μ΄νΈ μμ±μ IDμ λν νμ¬ μ¬μ΄νΈ μμ±μ IDμ 맡 ββλλ λ°μ΄ν°λ² μ΄μ€κ° μμ΄μΌ ν©λλ€. λ§μ κ΄λ¦¬μκ° κ΅¬μΆνλ κ²μ΄ μΈμμμ κ°μ₯ μ΄λ €μ΄ κ²μ μλμ§λ§ μ¬μ ν κ½€ λμ κΈ°μ€μ
λλ€. μ¬λλ€μ΄ μ΄κ²μ΄ μ΅μ μ λ°©λ²μ΄λΌκ³ μκ°νλ€λ©΄ λλ μλ§λ λ΄ μμ μ μ루μ
μ μμ±νκ³ README.md
μ λ¬Έμνν κ²μ
λλ€. κ²°κ΅ μ΄λ₯Ό κ΄λ¦¬νκΈ° μν΄ λ°°ν¬μμμ UIλ₯Ό λ§λ€ μ μμ΅λλ€.μ΄μ¨λ , μ΄λ€ κ²½λ‘λ‘ κ°μΌνλμ§ λλ μμ ν λ€λ₯Έ κ²½λ‘μ λν νΌλλ°±μ μ°Ύκ³ μμ΅λλ€. μ΅λν 빨리 μ΄ μμ μ μννλ €κ³ νλ©° λ¬Όλ‘ νλ¬κ·ΈμΈμ λν λ³κ²½ μ¬νμ λ€μ μ μΆν κ²μ λλ€.
μ°λ¦¬λ μ체 μ λμΌμ΄μ μ ν리μΌμ΄μ μ μμ±νκ³ μμ±μμ μ΄λ©μΌ μ£Όμλ₯Ό μ¬μ©νμ¬ μμ μ¬μ΄νΈμμ IDλ₯Ό μ‘°ννμ΅λλ€. μ΄κ²μ μμ±μκ° λ€νΈμν¬μ λͺ¨λ μ¬μ΄νΈμμ λμΌν μ΄λ©μΌ μ£Όμλ₯Ό μ¬μ©νλ€κ³ κ°μ ν©λλ€.
@dleeward ν κ°μ¬ν©λλ€. λ°©κΈ νΈμνλ λμ μμ±μλ₯Ό λκΈ°ννκΈ° μν΄ ν λ§ functions.phpμ μμ μ μλ μΌλΆ μ½λλ₯Ό ν¨κ» ν΄νΉνμ΅λλ€. μ λ¬λ μ΄λ©μΌ μ£Όμλ‘ μμ±μλ₯Ό μ°ΎμΌλ €κ³ μλν©λλ€. κΈ°μ‘΄ μ¬μ©μλ₯Ό μ°Ύμ μ μλ κ²½μ° νΈμ WPμ μμ±μΌλ‘ μ¬μ©μκ° μμ±λ©λλ€. μ΄κ²μ μμ§ μ ν μ€νΈλμ§ μμμΌλ©° μμ§ νλ‘λμ μμ μ¬μ©ν΄μλ μλ©λλ€.
if ( defined( 'DT_VERSION' ) ) {
function setup_distributor_replacements() {
$post_types = get_post_types(array('show_in_rest' => true));
foreach ( $post_types as $post_type ) {
add_action( "rest_insert_{$post_type}", 'process_original_author', 10, 3 );
}
}
function process_original_author( $post, $request, $update ) {
if ( empty( $post ) || is_wp_error( $post ) ) {
return;
}
if ( ! empty( $request['distributor_original_author'] ) ) {
$author_obj = $request['distributor_original_author'];
$new_author = get_user_by( 'email', $author_obj['email'] );
$author_id = 0;
if ( ! empty( $new_author ) && ! is_wp_error( $new_author ) ) {
$author_id = $new_author->ID;
} else {
$create_user = wp_insert_user(array(
'display_name' => $author_obj['display_name'],
'first_name' => $author_obj['first_name'],
'last_name' => $author_obj['last_name'],
'nickname' => $author_obj['nickname'],
'user_displayname' => $author_obj['user_displayname'],
'user_email' => $author_obj['user_email'],
'user_login' => $author_obj['user_login'],
'user_nicename' => $author_obj['user_nicename'],
'user_pass' => NULL
));
if ( is_wp_error( $create_user ) ) {
error_log("Error creating user during Distributor push ".$create_user->get_error_message());
return;
}
$author_id = $create_user;
}
wp_update_post( array( 'ID' => $post->ID, 'post_author' => $author_id ) );
}
}
add_action('init', 'setup_distributor_replacements');
function add_original_author($post_body, $post, $that) {
$post_author = get_user_by( 'id', $post->post_author );
$author_obj = array(
'display_name' => $post_author->display_name,
'first_name' => get_user_meta($post->post_author, 'first_name', true),
'first_name' => get_user_meta($post->post_author, 'first_name', true),
'last_name' => get_user_meta($post->post_author, 'last_name', true),
'user_email' => $post_author->user_email,
'user_login' => $post_author->user_login,
'user_nicename' => $post_author->user_nicename,
);
$post_body['distributor_original_author'] = $author_obj;
return $post_body;
}
add_filter('dt_push_post_args', 'add_original_author', 1, 3);
}
@robbiet480 μμ μμ user_loginκ³Ό user_nicenameμ΄ μ΄λ―Έ μ¬μ©λκ³ μμ§ μλ€κ³ κ°μ νλ©΄ μ λ©λλ€. ABC1519562843κ³Ό κ°μ 짧μ ν μ€νΈ λ¬Έμμ΄μ΄ μ λμ¬λ‘ λΆμ νμ¬ μ λμ€ μκ°μ μμ μ¬μ©μ μ΄λ¦μ λ§λλλ€. μ΄κ²μ μ΄λΉ ν λͺ μ΄μμ μ¬μ©μλ₯Ό μμ±νμ§ μλλ€κ³ κ°μ ν©λλ€. λ§μ΄ν¬λ‘νμμ μ¬μ©νκ±°λ λμ μμμ μ λ―Έμ¬λ₯Ό μΆκ°ν μ μμ΅λλ€.
μ°λ¦¬λ μ΄κ²μ λν΄ λ§μ΄ λ Όμνμ΅λλ€.
μΌλ°μ μΌλ‘ μΈμ¦λ μ¬μ©μλ‘ κ²μνλ κ²μ΄ λͺ¨λ μ¬λμκ² κ°μ₯ μμ ν κ°μ₯ νΈν κ°λ₯ν μ루μ μ΄λΌκ³ λ―Ώμ΅λλ€. κ²μμλ§λ€ μꡬ μ¬νμ΄ λ€λ₯Ό μ μμ΅λλ€. μ격 μ¬μ΄νΈμμ μ μ¬μ©μλ₯Ό λ§λ€λ©΄ λ§μ μ΄λ €μ΄ μ§λ¬Έμ΄ μκΉλλ€. μ μ¬μ©μ μν μ 무μμ λκΉ? μλ μμ±μκ° ν΄λΉ κ³μ μ μ‘μΈμ€ν μ μμ΄μΌ ν©λκΉ?
λ¬Όλ‘ μ΄κ²μ ν λ‘ μ μν΄ μ΄λ € μμΌλ©° λ€λ₯Έ μ견μ λ£κ³ μΆμ§λ§ νμ¬ λ‘μλ @robbiet480 μ΄ λ μ½κ² μνν μ μλλ‘ μΆκ° νν¬/νν°λ₯Ό μΆκ°νλ κ²μ΄ μ΅μ μ λλ€.
ν κ°μ§ μ μν μ μ λ§μ μΆνλ¬Όμ΄ μ½ν μΈ μ λν΄ μ¬λ¬ μμ±μλ₯Ό μ§μν΄μΌ νκ³ μ΄λ¬ν κ²½μ° "μ¬μ©μ"κ° μμ±μ <-> μ½ν μΈ κ΄κ³μ μ¬μ©λμ§ μλ κ²½μ°κ° λ§λ€λ κ²μ λλ€.
DFMμμ μ½ν μΈ μ λμΌμ΄μ μμ μ ν λ κ²μλ¬Όμ λ§μ μμ±μλ₯Ό μΆκ°νκΈ° μν νμ΄λΈλ¦¬λ κ²μλ¬Ό μ ν/λΆλ₯ μ루μ μΈ Co-Authors Plusλ₯Ό μ¬μ©νμ΅λλ€. κ·Έλμ μ°λ¦¬μ κ²½μ° μ€μ λ‘ μΈμ¦λ μ¬μ©μκ° λ€μκ³Ό κ°μ΄ κ²μλ¬Όμ μ°κ²°λκΈ°λ₯Ό _μνμ΅λλ€_. μ λμΌμ΄νΈλ μ½ν μΈ μ μμ±μμ΄λ―λ‘ μ΄λ€ μ¬μ©μκ° μ λμΌμ΄μ μ νΈλ¦¬κ±°νλμ§ μΆμ νκ³ μμ±μ<->μ½ν μΈ κ΄κ³λ₯Ό μ²λ¦¬νκΈ° μν΄ μΆκ° λ°μ΄ν°λ₯Ό μ λμΌμ΄νΈνμ΅λλ€(λ―Έλμ΄μ λν κ΄κ³κ° μ²λ¦¬λλ λ°©μκ³Ό λ€μ μ μ¬).
νΌλλ°±μ κ°μ¬λ립λλ€, μ μ΄μ¨!
κ·Έλμ μ λ μ΄κ²μ ν λ¨κ³ λ λ°μ μμΌ°κ³ μ€μ λ‘ νν¬λ₯Ό ν΅ν΄ Co-Authors Plusμ λν μ§μμ Distributorμ μΆκ°νμ΅λλ€. λ€μμ ν΅ν©μ κ΄μ¬μ΄ μλ λ€λ₯Έ μ¬λμ μν μ½λμ λλ€. λμ€νΈλ¦¬λ·°ν°μ ν¬ν¨λλ κ²μ λν΄ #131μ λ¬Έμνμ΅λλ€.
<?php
function handle_dt_process_distributor_attributes( $post, $request, $update ) {
if ( empty( $post ) || is_wp_error( $post ) ) {
return;
}
if ( is_plugin_active( 'co-authors-plus/co-authors-plus.php' ) && ! empty( $request['distributor_coauthors'] ) ) {
global $coauthors_plus;
$author_logins = array();
foreach ( $request['distributor_coauthors'] as $coauthor ) {
$existing_guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'user_login', $coauthor['user_login'] );
if ( ! $existing_guest_author ) {
$guest_author_id = $coauthors_plus->guest_authors->create( array(
'display_name' => $coauthor['display_name'],
'first_name' => $coauthor['first_name'],
'last_name' => $coauthor['last_name'],
'user_login' => $coauthor['user_login'],
'user_nicename' => $coauthor['user_nicename']
) );
if ( is_wp_error( $guest_author_id ) ) {
error_log("Error creating co-author during Distributor push ".$guest_author_id->get_error_message());
return;
}
if ( !$guest_author_id ) {
error_log( '-- Failed to create guest author.' );
}
if ( ! empty($coauthor['avatar_url']) ) {
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
$thumbnail_id = media_sideload_image($coauthor['avatar_url'], $guest_author_id, null, 'id');
set_post_thumbnail($guest_author_id, $thumbnail_id);
}
$guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'ID', $guest_author_id );
array_push($author_logins, $guest_author->user_login);
} else {
array_push($author_logins, $existing_guest_author->user_login);
}
}
clean_post_cache($post->ID);
$coauthors_plus->guest_authors->delete_guest_author_cache($author_logins[0]);
}
}
add_action( 'dt_process_distributor_attributes', 'handle_dt_process_distributor_attributes', 10, 3 );
if ( is_plugin_active( 'co-authors-plus/co-authors-plus.php' ) ) {
function distributor_coauthors_get_avatar_url( $coauthor ) {
global $coauthors_plus;
if ( ! is_object( $coauthor ) ) {
return '';
}
if ( isset( $coauthor->type ) && 'guest-author' == $coauthor->type ) {
if ( ! has_post_thumbnail( $coauthor->ID ) ) {
return '';
}
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $coauthor->ID ), 'large' );
return $large_image_url[0];
}
// Make sure we're dealing with an object for which we can retrieve an email
if ( isset( $coauthor->user_email ) ) {
return get_avatar( $coauthor->user_email, $size, $default, $alt );
}
// Nothing matched, an invalid object was passed.
return '';
}
}
function add_dt_push_post_args($post_body, $post, $that) {
if ( is_plugin_active( 'co-authors-plus/co-authors-plus.php' ) ) {
$post_body['distributor_coauthors'] = array();
foreach ( $coauthors as $coauthor ) {
if( array_key_exists("data", $coauthor) ) {
// Don't include real WP_Users
continue;
}
$coauthor_arr = (array) $coauthor;
$coauthor_arr['avatar_url'] = distributor_coauthors_get_avatar_url($coauthor);
array_push($post_body['distributor_coauthors'], $coauthor_arr);
}
}
return $post_body;
}
add_filter('dt_push_post_args', 'add_dt_push_post_args', 1, 3);
add_filter('dt_push_post_timeout', function($default_timeout, $post) {
return 30;
}, 1, 2);
Re: μ μμ ν¨κ» λ°°ν¬νλ κ²μ λν μλ 쿼리, λλ CAPκ° λ°°ν¬μκ° μ μ ν μ μκ° μΈμ λλλ‘ νλ μ’μ μ€ν± κ° μ루μ μ΄ λ μ μλ€κ³ λ§νκ³ μΆμ΅λλ€. @tlovett1 μ΄ μΈκΈν μλ‘μ΄ μν μ λν΄ κ±±μ νμ§ μμλ λ©λλ€. μ¬μ©μλ λ±μ΄ μμ΅λλ€. λν, μ΄μ μ°λ¦¬κ° μλ³Έ μ¬μ΄νΈ μ΄λ¦μ λ ΈμΆν μ μλ κ²μ²λΌ νλ‘ νΈμλμ μλ³Έ μμ±μμ κ°μ μ 보λ₯Ό λ ΈμΆνκΈ° μν΄ ν νλ¦Ώ νκ·Έλ₯Ό λ μΆκ°νλ κ²μ΄ ν©λ¦¬μ μ΄λΌκ³ μκ°ν©λλ€.
μ΄ λ¬Έμ λ #131μ κ²°μ μΌλ‘ μ°¨λ¨νκ³ μΆμ΅λλ€. λ°°ν¬μκ° νν¬/νν°λ³΄λ€ μΈλΆ νλ¬κ·ΈμΈμ λ λ§μ΄ μ§μν κ²μ΄λΌλ κ²°μ μ΄ λ΄λ €μ§λ©΄ Co-Authors Plusλ₯Ό ν΅ν΄ μ΄ νΉμ λ¬Έμ λ₯Ό κ³μ μ‘°μ¬ν μ μμΌλ©° λ°°ν¬μμ ν¨κ»/ν¨κ» λ°°ν¬νλ λ° κ°μ₯ μ ν©νκ² ν¬ν¨λ μ μμ΅λλ€. λ°°ν¬μκ° νν¬/νν° μ μ© μ κ·Ό λ°©μμ μ·¨νλ κ²½μ° μ΄ λ¬Έμ λ₯Ό μ’ λ£ν κ°λ₯μ±μ΄ λμ΅λλ€.