Files

583 lines
27 KiB
PHP

<?php
if ( ! defined( 'ABSPATH' ) )
exit;
class ACUI_Homepage{
function __construct(){
}
function hooks(){
add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ), 10, 1 );
add_action( 'wp_ajax_acui_delete_users_assign_posts_data', array( $this, 'delete_users_assign_posts_data' ) );
}
function load_scripts( $hook ){
if( $hook != 'tools_page_acui' )
return;
wp_enqueue_style( 'select2-css', '//cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css' );
wp_enqueue_script( 'select2-js', '//cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js' );
}
static function admin_gui(){
$settings = new ACUI_Settings( 'import_backend' );
$settings->maybe_migrate_old_options( 'import_backend' );
$upload_dir = wp_upload_dir();
$sample_path = $upload_dir["path"] . '/test.csv';
$sample_url = plugin_dir_url( dirname( __FILE__ ) ) . 'test.csv';
if( ctype_digit( $settings->get( 'delete_users_assign_posts' ) ) ){
$delete_users_assign_posts_user_id = $settings->get( 'delete_users_assign_posts' );
$delete_users_assign_posts_user = get_user_by( 'id', $delete_users_assign_posts_user_id );
if( $delete_users_assign_posts_user ) {
$delete_users_assign_posts_options = array( $delete_users_assign_posts_user_id => $delete_users_assign_posts_user->display_name);
} else {
$delete_users_assign_posts_options = array();
}
$delete_users_assign_posts_option_selected = $delete_users_assign_posts_user_id;
}
else{
$delete_users_assign_posts_options = array( 0 => __( 'No user selected', 'import-users-from-csv-with-meta' ) );
$delete_users_assign_posts_option_selected = 0;
}
?>
<div class="wrap acui">
<style>
#acui_import_results{
display: none;
background-color: #f0f0f1;
padding: 20px;
margin-top: 20px;
margin-bottom: 20px;
border-radius: 6px;
border: 1px solid #c3c4c7;
}
.user-importer-progress-wrapper{
padding: 20px;
background-color: white;
width: 100%;
margin: 0 0 20px 0;
text-align: center;
border-radius: 9px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
box-sizing: border-box;
display: none;
}
.user-importer-progress{
width: 100%;
height: 42px;
border: 0;
border-radius: 9px;
}
.user-importer-progress::-webkit-progress-bar {
background-color: #f3f3f3;
border-radius: 9px;
}
.user-importer-progress::-webkit-progress-value {
background: #2271b1;
border-radius: 9px;
}
.user-importer-progress::-moz-progress-bar {
background: #2271b1;
border-radius: 9px;
}
.acui-importing .acui-import-options,
.acui-importing .sidebar,
.acui-importing .header,
.acui-importing .acui-message{
display: none !important;
}
.acui-importing .user-importer-progress-wrapper{
display: block !important;
}
</style>
<?php do_action( 'acui_homepage_start' ); ?>
<div class="row">
<div class="main_bar">
<form method="POST" id="acui_form" enctype="multipart/form-data" action="" accept-charset="utf-8">
<div class="user-importer-progress-wrapper">
<progress class="user-importer-progress" value="0" max="100"></progress>
<div style="margin-top: 10px; font-weight: bold;">
<span class="user-importer-progress-value">0%</span>
</div>
<div class="user-importer-controls" style="margin-top: 20px;">
<button type="button" id="acui_pause_btn" class="button button-secondary"><?php _e( 'Pause', 'import-users-from-csv-with-meta' ); ?></button>
<button type="button" id="acui_stop_btn" class="button button-link-delete" style="color: #d63638;"><?php _e( 'Stop', 'import-users-from-csv-with-meta' ); ?></button>
</div>
</div>
<div class="acui-import-options">
<div class="acui-accordion">
<details id="acui_file_header" open>
<summary><span class="acui-summary-label"><?php _e( 'File', 'import-users-from-csv-with-meta'); ?></span><span class="acui-summary-chevron">▼</span></summary>
<table id="acui_file_wrapper" class="form-table">
<tbody>
<?php do_action( 'acui_homepage_before_file_rows' ); ?>
<tr class="form-field form-required">
<th scope="row"><label for="uploadfile"><?php _e( 'CSV file <span class="description">(required)</span></label>', 'import-users-from-csv-with-meta' ); ?></th>
<td>
<div id="upload_file">
<input type="file" name="uploadfile" id="uploadfile" size="35" class="uploadfile" />
<?php _e( '<em>or you can choose directly a file from your host or from an external URL', 'import-users-from-csv-with-meta' ) ?> <a href="#" class="toggle_upload_path"><?php _e( 'click here', 'import-users-from-csv-with-meta' ) ?></a>.</em>
</div>
<div id="introduce_path" style="display:none;">
<input placeholder="<?php printf( __( 'You have to enter the URL or the path to the file, i.e.: %s or %s' ,'import-users-from-csv-with-meta' ), $sample_path, $sample_url ); ?>" type="text" name="path_to_file" id="path_to_file" value="<?php echo $settings->get( 'path_to_file' ); ?>" style="width:70%;" />
<em><?php _e( 'or you can upload it directly from your computer', 'import-users-from-csv-with-meta' ); ?>, <a href="#" class="toggle_upload_path"><?php _e( 'click here', 'import-users-from-csv-with-meta' ); ?></a>.</em>
</div>
<?php if( !is_plugin_active( 'import-export-users-customers-file-formats/import-export-users-customers-file-formats.php' ) ): ?>
<p class="description"><?php printf( __( 'You can also import <strong>XLSX, XLS or ODS</strong> files with the <a href="%s" target="_blank">File Formats addon</a>.', 'import-users-from-csv-with-meta' ), 'https://import-wp.com/plugins/file-formats-addon/' ); ?></p>
<?php endif; ?>
</td>
</tr>
<?php do_action( 'acui_homepage_after_file_rows' ); ?>
</tbody>
</table>
</details>
<details id="acui_roles_header" open>
<summary><span class="acui-summary-label"><?php _e( 'Roles', 'import-users-from-csv-with-meta'); ?></span><span class="acui-summary-chevron">▼</span></summary>
<table id="acui_roles_wrapper" class="form-table">
<tbody>
<?php do_action( 'acui_homepage_before_roles_rows' ); ?>
<tr class="form-field">
<th scope="row"><label for="role"><?php _e( 'Default role', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<?php ACUIHTML()->select( array(
'options' => ACUI_Helper::get_editable_roles(),
'name' => 'role[]',
'show_option_all' => false,
'show_option_none' => true,
'multiple' => true,
'selected' => is_array( $settings->get( 'role' ) ) ? $settings->get( 'role' ) : array( $settings->get( 'role' ) ),
'style' => 'width:100%;'
)); ?>
<p class="description"><?php _e( 'You can also import roles from a CSV column. Please read the Documentation tab to see how this can be done. WordPress core allows assigning multiple roles to a user; however, the default interface only displays one role, although some plugins solve this limitation.', 'import-users-from-csv-with-meta' ); ?></p>
</td>
</tr>
<?php do_action( 'acui_homepage_after_roles_rows' ); ?>
</tbody>
</table>
</details>
<details id="acui_options_header">
<summary><span class="acui-summary-label"><?php _e( 'Options', 'import-users-from-csv-with-meta'); ?></span><span class="acui-summary-chevron">▼</span></summary>
<table id="acui_options_wrapper" class="form-table">
<tbody>
<?php do_action( 'acui_homepage_before_options_rows' ); ?>
<tr id="acui_empty_cell_wrapper" class="form-field form-required">
<th scope="row"><label for="empty_cell_action"><?php _e( 'What should the plugin do with empty cells?', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<?php ACUIHTML()->select( array(
'options' => array( 'leave' => __( 'Leave the old value for this metadata', 'import-users-from-csv-with-meta' ), 'delete' => __( 'Delete the metadata', 'import-users-from-csv-with-meta' ) ),
'name' => 'empty_cell_action',
'show_option_all' => false,
'show_option_none' => false,
'selected' => $settings->get( 'empty_cell_action' ),
)); ?>
</td>
</tr>
<tr id="acui_send_email_wrapper" class="form-field">
<th scope="row"><label for="user_login"><?php _e( 'Send email', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<p id="sends_email_wrapper">
<?php ACUIHTML()->checkbox( array( 'name' => 'sends_email', 'label' => sprintf( __( 'Do you wish to send an email from this plugin with credentials and other data? <a href="%s">(email template found here)</a>', 'import-users-from-csv-with-meta' ), admin_url( 'tools.php?page=acui&tab=mail-options' ) ), 'current' => 'yes', 'compare_value' => $settings->get( 'sends_email' ) ) ); ?>
</p>
<p id="send_email_updated_wrapper">
<?php ACUIHTML()->checkbox( array( 'name' => 'send_email_updated', 'label' => __( 'Do you wish to send this mail also to users that are being updated? (not just to the one which are being created)', 'import-users-from-csv-with-meta' ), 'current' => 'yes', 'compare_value' => $settings->get( 'send_email_updated' ) ) ); ?>
</p>
</td>
</tr>
<tr class="form-field form-required">
<th scope="row"><label for=""><?php _e( 'Force users to reset their passwords?', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<?php ACUIHTML()->checkbox( array( 'name' => 'force_user_reset_password', 'label' => __( 'If a password is set to a user and you activate this option, the user will be forced to reset their password at their first login', 'import-users-from-csv-with-meta' ), 'current' => 'yes', 'compare_value' => $settings->get( 'force_user_reset_password' ) ) ); ?>
<p class="description"><?php echo sprintf( __( 'Please, <a href="%s">read the documentation</a> before activating this option', 'import-users-from-csv-with-meta' ), admin_url( 'tools.php?page=acui&tab=doc#force_user_reset_password' ) ); ?></p>
</td>
</tr>
<?php do_action( 'acui_homepage_after_options_rows' ); ?>
</tbody>
</table>
</details>
<details id="acui_update_users_header">
<summary><span class="acui-summary-label"><?php _e( 'Update users', 'import-users-from-csv-with-meta'); ?></span><span class="acui-summary-chevron">▼</span></summary>
<table id="acui_update_users_wrapper" class="form-table">
<tbody>
<?php do_action( 'acui_homepage_before_update_users_rows' ); ?>
<tr id="acui_update_existing_users_wrapper" class="form-field form-required">
<th scope="row"><label for="update_existing_users"><?php _e( 'Update existing users?', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<?php ACUIHTML()->select( array(
'options' => array( 'no' => __( 'No', 'import-users-from-csv-with-meta' ), 'yes' => __( 'Yes', 'import-users-from-csv-with-meta' ), ),
'name' => 'update_existing_users',
'show_option_all' => false,
'show_option_none' => false,
'selected' => $settings->get( 'update_existing_users' ),
)); ?>
</td>
</tr>
<tr id="acui_update_emails_existing_users_wrapper" class="form-field form-required">
<th scope="row"><label for="update_emails_existing_users"><?php _e( 'Update emails?', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<?php ACUIHTML()->select( array(
'options' => array( 'no' => __( 'No', 'import-users-from-csv-with-meta' ), 'create' => __( 'No, but create a new user with a prefix in the username', 'import-users-from-csv-with-meta' ), 'yes' => __( 'Yes', 'import-users-from-csv-with-meta' ) ),
'name' => 'update_emails_existing_users',
'show_option_all' => false,
'show_option_none' => false,
'selected' => $settings->get( 'update_emails_existing_users' ),
)); ?>
<p class="description"><?php _e( 'What the plugin should do if the plugin find a user, identified by their username, with a different email', 'import-users-from-csv-with-meta' ); ?></p>
</td>
</tr>
<tr id="acui_update_roles_existing_users_wrapper" class="form-field form-required">
<th scope="row"><label for="update_roles_existing_users"><?php _e( 'Update roles for existing users?', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<?php ACUIHTML()->select( array(
'options' => array( 'no' => __( 'No', 'import-users-from-csv-with-meta' ), 'yes' => __( 'Yes, update and override existing roles', 'import-users-from-csv-with-meta' ), 'yes_no_override' => __( 'Yes, add new roles and do not override existing ones', 'import-users-from-csv-with-meta' ) ),
'name' => 'update_roles_existing_users',
'show_option_all' => false,
'show_option_none' => false,
'selected' => $settings->get( 'update_roles_existing_users' ),
)); ?>
</td>
</tr>
<tr id="acui_update_allow_update_passwords_wrapper" class="form-field form-required">
<th scope="row"><label for="update_allow_update_passwords"><?php _e( 'Update passwords for existing users?', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<?php ACUIHTML()->select( array(
'options' => array( 'no' => __( 'No, never update passwords for existing users', 'import-users-from-csv-with-meta' ), 'yes' => __( 'Yes, update passwords as described in documentation', 'import-users-from-csv-with-meta' ) ),
'name' => 'update_allow_update_passwords',
'show_option_all' => false,
'show_option_none' => false,
'selected' => $settings->get( 'update_allow_update_passwords' ),
)); ?>
</td>
</tr>
<?php do_action( 'acui_homepage_after_update_users_rows' ); ?>
</tbody>
</table>
</details>
<details id="acui_users_not_present_header">
<summary><span class="acui-summary-label"><?php _e( 'Users not present in CSV file', 'import-users-from-csv-with-meta'); ?></span><span class="acui-summary-chevron">▼</span></summary>
<table id="acui_users_not_present_wrapper" class="form-table">
<tbody>
<?php do_action( 'acui_homepage_before_users_not_present_rows' ); ?>
<tr id="acui_delete_users_wrapper" class="form-field form-required">
<th scope="row"><label for="delete_users_not_present"><?php _e( 'Delete users that are not present in the CSV?', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<div style="float:left; margin-top: 10px;">
<?php ACUIHTML()->checkbox( array( 'name' => 'delete_users_not_present', 'current' => 'yes', 'compare_value' => $settings->get( 'delete_users_not_present' ) ) ); ?>
</div>
<div style="margin-left:25px;">
<?php ACUIHTML()->select( array(
'options' => $delete_users_assign_posts_options,
'name' => 'delete_users_assign_posts',
'show_option_all' => false,
'show_option_none' => __( 'Delete posts of deleted users without assigning them to another user, or type to search for a user to assign the posts to', 'import-users-from-csv-with-meta' ),
'selected' => $delete_users_assign_posts_option_selected,
)); ?>
<p class="description"><?php _e( 'Administrators will not be deleted anyway. After deleting users, you can choose if you want to assign their posts to another user. If you do not choose a user, their content will be deleted.', 'import-users-from-csv-with-meta' ); ?></p>
</div>
</td>
</tr>
<tr id="acui_not_present_wrapper" class="form-field form-required">
<th scope="row"><label for="change_role_not_present"><?php _e( 'Change role of users that are not present in the CSV?', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<div style="float:left; margin-top: 10px;">
<?php ACUIHTML()->checkbox( array( 'name' => 'change_role_not_present', 'current' => 'yes', 'compare_value' => $settings->get( 'change_role_not_present' ) ) ); ?>
</div>
<div style="margin-left:25px;">
<?php ACUIHTML()->select( array(
'options' => ACUI_Helper::get_editable_roles(),
'name' => 'change_role_not_present_role',
'show_option_all' => false,
'show_option_none' => false,
'selected' => $settings->get( 'change_role_not_present_role' ),
)); ?>
<p class="description"><?php _e( 'After importing users from a CSV, users not present in the CSV can have their roles changed to a different role.', 'import-users-from-csv-with-meta' ); ?></p>
</div>
</td>
</tr>
<tr id="acui_not_present_same_role" class="form-field form-required">
<th scope="row"><label for="not_present_same_role"><?php _e( 'Apply only to users with the same role as imported users', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<?php ACUIHTML()->select( array(
'options' => array(
'no' => __( 'No, apply to all users regardless of their role', 'import-users-from-csv-with-meta' ),
'yes' => __( 'Yes, only users who have the role(s) of the imported users', 'import-users-from-csv-with-meta' ),
),
'name' => 'not_present_same_role',
'show_option_all' => false,
'show_option_none' => false,
'selected' => $settings->get( 'not_present_same_role' ),
)); ?>
<p class="description"><?php _e( 'Sometimes, you may want only the users of the imported users\' role to be affected and not the rest of the system user.', 'import-users-from-csv-with-meta' ); ?></p>
</td>
</tr>
<tr id="acui_not_present_only_imported_wrapper" class="form-field form-required">
<th scope="row"><label for="not_present_only_imported"><?php _e( 'Apply only to users previously imported by this plugin?', 'import-users-from-csv-with-meta' ); ?></label></th>
<td>
<?php ACUIHTML()->select( array(
'options' => array(
'no' => __( 'No, apply to all existing users', 'import-users-from-csv-with-meta' ),
'yes' => __( 'Yes, only affect users that were imported by this plugin', 'import-users-from-csv-with-meta' ),
),
'name' => 'not_present_only_imported',
'show_option_all' => false,
'show_option_none' => false,
'selected' => $settings->get( 'not_present_only_imported' ),
)); ?>
<p class="description"><?php _e( 'Users created manually in WordPress will not be affected.', 'import-users-from-csv-with-meta' ); ?></p>
</td>
</tr>
<?php do_action( 'acui_homepage_after_users_not_present_rows' ); ?>
</tbody>
</table>
</details>
</div><?php /* .acui-accordion */ ?>
<?php do_action( 'acui_tab_import_before_import_button' ); ?>
</div>
<?php wp_nonce_field( 'codection-security', 'security' ); ?>
</form>
<div id="acui_import_log" style="margin-top: 20px;"></div>
<div id="acui_import_results">
<h3><?php _e( 'Results', 'import-users-from-csv-with-meta' ); ?></h3>
<table id="acui_import_summary" class="form-table">
<tbody>
<tr>
<th><?php _e( 'Users processed', 'import-users-from-csv-with-meta' ); ?></th>
<td><span id="acui_result_processed">0</span></td>
</tr>
<tr>
<th><?php _e( 'Users created', 'import-users-from-csv-with-meta' ); ?></th>
<td><span id="acui_result_created">0</span></td>
</tr>
<tr>
<th><?php _e( 'Users updated', 'import-users-from-csv-with-meta' ); ?></th>
<td><span id="acui_result_updated">0</span></td>
</tr>
<tr>
<th><?php _e( 'Users deleted', 'import-users-from-csv-with-meta' ); ?></th>
<td><span id="acui_result_deleted">0</span></td>
</tr>
<tr>
<th><?php _e( 'Errors, warnings and notices found', 'import-users-from-csv-with-meta' ); ?></th>
<td><span id="acui_result_errors">0</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sidebar" style="position:sticky;top:32px;align-self:flex-start;">
<div class="sidebar_section" style="background:#fff;border:1px solid #c3c4c7;border-radius:4px;box-shadow:0 1px 3px rgba(0,0,0,.07);overflow:hidden;padding:0;margin-bottom:16px;">
<h3 style="margin:0;padding:12px 16px;font-size:13px;font-weight:600;border-bottom:1px solid #c3c4c7;background:#f6f7f7;"><?php _e( 'Actions', 'import-users-from-csv-with-meta' ); ?></h3>
<div style="padding:12px 16px;display:flex;flex-direction:column;gap:8px;">
<button type="submit" name="uploadfile" id="uploadfile_btn" form="acui_form" class="button button-primary" style="width:100%;">
<?php _e( 'Start importing', 'import-users-from-csv-with-meta' ); ?>
</button>
<button type="submit" name="save_options" form="acui_form" class="button button-secondary" style="width:100%;">
<?php _e( 'Save Settings', 'import-users-from-csv-with-meta' ); ?>
</button>
</div>
</div>
<div class="sidebar_section sidebar-info">
<p><?php printf( __( 'The CSV must have at least <strong>2 columns: username and email</strong>, in that order. Extra columns are matched by their header name. Both fields are required unless you use <a href="%s">the Allow No Email addon</a>.', 'import-users-from-csv-with-meta' ), 'https://import-wp.com/allow-no-email-addon/' ); ?></p>
<p><?php _e( 'Read the documentation on how <strong>passwords are managed</strong>. This plugin is <strong>case sensitive</strong>.', 'import-users-from-csv-with-meta' ); ?></p>
</div>
<div class="sidebar_section premium_addons">
<a class="premium-addons" color="primary" type="button" name="premium-addons" data-tag="premium-addons" href="https://www.import-wp.com/" role="button" target="_blank">
<div><span><?php _e( 'Premium Addons', 'import-users-from-csv-with-meta'); ?></span></div>
</a>
</div>
<div class="sidebar_section">
<h3><?php _e( 'Having issues?', 'import-users-from-csv-with-meta'); ?></h3>
<ul>
<li><label><?php _e( 'You can create a ticket', 'import-users-from-csv-with-meta'); ?></label> <a target="_blank" href="http://wordpress.org/support/plugin/import-users-from-csv-with-meta"><label><?php _e( 'WordPress support forum', 'import-users-from-csv-with-meta'); ?></label></a></li>
<li><label><?php _e( 'You can ask for premium support', 'import-users-from-csv-with-meta'); ?></label> <a target="_blank" href="mailto:contacto@codection.com"><label>contacto@codection.com</label></a></li>
</ul>
<p style="margin-top:10px; font-size:11px;">
<a target="_blank" href="https://ko-fi.com/codection"><?php _e( '☕ Buy me a coffee', 'import-users-from-csv-with-meta'); ?></a>
&nbsp;·&nbsp;
<a target="_blank" href="https://www.patreon.com/carazo"><?php _e( 'Become a patron', 'import-users-from-csv-with-meta'); ?></a>
</p>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery( document ).ready( function( $ ){
document.querySelectorAll( '.acui-accordion details' ).forEach( function( el ){
var key = 'acui_acc_' + el.id;
var stored = localStorage.getItem( key );
if( stored === 'open' ) el.open = true;
if( stored === 'closed' ) el.open = false;
el.addEventListener( 'toggle', function(){
localStorage.setItem( key, el.open ? 'open' : 'closed' );
} );
} );
check_delete_users_checked();
$( '#uploadfile_btn,#uploadfile_btn_up' ).click( function(){
if( $( '#uploadfile' ).val() == "" && $( '#upload_file' ).is( ':visible' ) ) {
alert("<?php _e( 'Please choose a file', 'import-users-from-csv-with-meta' ); ?>");
return false;
}
if( $( '#path_to_file' ).val() == "" && $( '#introduce_path' ).is( ':visible' ) ) {
alert("<?php _e( 'Please enter a path to the file', 'import-users-from-csv-with-meta' ); ?>");
return false;
}
} );
$( '.acui-checkbox.roles[value="no_role"]' ).click( function(){
var checked = $( this ).is(':checked');
if( checked ) {
if( !confirm( '<?php _e( 'Are you sure you want to disables roles from these users?', 'import-users-from-csv-with-meta' ); ?>' ) ){
$( this ).removeAttr( 'checked' );
return;
}
else{
$( '.acui-checkbox.roles' ).not( '.acui-checkbox.roles[value="no_role"]' ).each( function(){
$( this ).removeAttr( 'checked' );
} )
}
}
} );
$( '.acui-checkbox.roles' ).click( function(){
if( $( this ).val() != 'no_role' && $( this ).val() != '' )
$( '.acui-checkbox.roles[value="no_role"]' ).removeAttr( 'checked' );
} );
$( '#delete_users_not_present' ).on( 'click', function() {
check_delete_users_checked();
});
$( '.toggle_upload_path' ).click( function( e ){
e.preventDefault();
$( '#upload_file,#introduce_path' ).toggle();
} );
$( '#vote_us' ).click( function(){
var win=window.open( 'http://wordpress.org/support/view/plugin-reviews/import-users-from-csv-with-meta?free-counter?rate=5#postform', '_blank');
win.focus();
} );
$( '#role' ).select2({ width: '80%' });
$( '#change_role_not_present_role' ).select2({ width: '80%' });
$( '#delete_users_assign_posts' ).select2({
allowClear: true,
placeholder: '<?php _e( 'Delete posts of deleted users without assigning to any user', 'import-users-from-csv-with-meta' ) ?>',
width: '80%',
ajax: {
url: '<?php echo admin_url( 'admin-ajax.php' ) ?>',
cache: true,
dataType: 'json',
minimumInputLength: 3,
data: function( params ) {
var query = {
search: params.term,
_wpnonce: '<?php echo wp_create_nonce( 'codection-security' ); ?>',
action: 'acui_delete_users_assign_posts_data',
}
return query;
}
},
});
function check_delete_users_checked(){
if( $( '#delete_users_not_present' ).is( ':checked' ) ){
$( '#delete_users_assign_posts' ).prop( 'disabled', false );
$( '#change_role_not_present' ).prop( 'disabled', true );
$( '#change_role_not_present_role' ).prop( 'disabled', true );
} else {
$( '#delete_users_assign_posts' ).prop( 'disabled', true );
$( '#change_role_not_present' ).prop( 'disabled', false );
$( '#change_role_not_present_role' ).prop( 'disabled', false );
}
}
} );
</script>
<?php
}
function delete_users_assign_posts_data(){
check_ajax_referer( 'codection-security', 'security' );
if( ! current_user_can( apply_filters( 'acui_capability', 'create_users' ) ) )
wp_die( __( 'Only users who are allowed to create users can manage this option.', 'import-users-from-csv-with-meta' ) );
$results = array( array( 'id' => '', 'value' => __( 'Delete posts of deleted users without assigning to any user', 'import-users-from-csv-with-meta' ) ) );
$search = sanitize_text_field( $_GET['search'] );
if( strlen( $search ) >= 3 ){
$blogusers = get_users( array( 'fields' => array( 'ID', 'display_name' ), 'search' => '*' . $search . '*' ) );
foreach ( $blogusers as $bloguser ) {
$results[] = array( 'id' => $bloguser->ID, 'text' => $bloguser->display_name );
}
}
echo json_encode( array( 'results' => $results, 'more' => 'false' ) );
wp_die();
}
}
$acui_homepage = new ACUI_Homepage();
$acui_homepage->hooks();