• Skip to main content
  • Skip to primary sidebar

Code Inherit

Simple Programming Code Examples

Archives for September 2020

How to create MySQL user and database

23rd September 2020 by Site Admin Leave a Comment

CREATE DATABASE erlms_site1_db CHARACTER SET utf8 COLLATE utf8_general_ci
GRANT ALL privileges on erlms_site1_db.* to ‘benin_mysqladmin’@’localhost’ with grant option;
FLUSH PRIVILEGES;

Filed Under: MySQL, Uncategorised

How to change Linux and MySql user password

23rd September 2020 by Site Admin Leave a Comment

Change Linux Passord: passwd
Search text in files in Ubuntu: grep -r siglbenin_db *
Change MySql Password: ALTER USER ‘bdcovid19_mysqladmin’@’localhost’ IDENTIFIED BY ‘bGd60dbdu961a4’;
FLUSH PRIVILEGES;

Filed Under: Linux, MySQL

Create WordPress users by WP Ajax

23rd September 2020 by Site Admin Leave a Comment

Add the following code to function.php in child theme.

add_action('wp_ajax_create_my_users_action', 'create_my_users');
add_action('wp_ajax_nopriv_create_my_users_action', 'create_my_users');

function create_my_users(){
	
	if(!wp_verify_nonce($_POST['nonce_id'], 'create_my_users_action')){
		echo '<div class="alert alert_error">Error!</div>';
		wp_die(); 
	}
	
	$my_users = $_POST['my_users'];
	
	//var_dump($my_users);
		
	$user_ids = [];
	
	foreach($my_users as $u){
	
		$userdata = array(
			'user_login'	=> $u['user_login'],
			'user_pass'		=> $u['user_pass'],
			'user_email'	=> $u['user_email'],
			'first_name'    => $u['first_name'],
			'last_name'		=> $u['last_name'],
			'nickname'		=> $u['nickname']			
		);
		
		$user_id = wp_insert_user( $userdata );		
		
		//$result = add_user_meta($user_id, 'sw', $u['sw'], true);
		
		$result = update_user_meta( $user_id, 'account_status', $u['account_status'] );
		$result = update_user_meta( $user_id, 'um_multiple_roles', $u['um_multiple_roles'] );
		
		$user_ids[] = $user_id;
	}
	
	echo json_encode($user_ids);
	
	wp_die(); 
}
function create_my_users_shortcode() {
	
	$my_users = json_encode([[
			'user_login' => 'a11111111111',
			'user_pass' => '123456',
			'user_email' => 'a11111111111@gmail.com',
			'role' => 'subscriber',
			'first_name' => 'a11111111111',
			'last_name' => '',
			'sw' => '',
			'account_status' => 'approved',
			'um_multiple_roles' =>['um_data-entry-operator']
		  ],
		  [
			'user_login' => 'a22222222222',
			'user_pass' => '123456',
			'user_email' => 'a22222222222@gmail.com',
			'role' => 'subscriber',
			'first_name' => 'a22222222222',
			'last_name' => '',
			'sw' => '',
			'account_status' => 'approved',
			'um_multiple_roles' =>['um_data-entry-operator']
		  ]
		]);
	
	$html =	'<button nonce_id='.wp_create_nonce('create_my_users_action').' class="create_my_users">Test</button>
		<ul id="info_create_my_users"></ul>
		<script>
			jQuery(document).ready(function($) {
				
				$(".create_my_users").on("click", function() {
					
					var nonce_id = $(this).attr("nonce_id");
					
					$.ajax({
						url: "' . admin_url('admin-ajax.php') . '",						
						type: "POST",
						data: {
							action: "create_my_users_action",
							my_users: '.$my_users.',
							nonce_id: nonce_id
						},
						beforeSend: function(){
							$("#info_create_my_users").empty();
							$("#info_create_my_users").append("Creating users ...");
						},
						success: function(html) {
							$("#info_create_my_users").empty();
							$("#info_create_my_users").append(html);
						}
					});
					
				});
				
			});
		</script>';

	return $html;
	
}

add_shortcode('CreateMyUsersShortcode', 'create_my_users_shortcode');

You can place this short code anywhere in PHP code block like header, body, footer etc as follows.

<?php echo do_shortcode("[CreateMyUsersShortcode]"); ?>

You can place this short code into any post and page as follows.

[CreateMyUsersShortcode]

WordPress-users-by-WP-AjaxDownload

Filed Under: Wordpress, WP

Create zip file of folder by cron job

15th September 2020 by Site Admin Leave a Comment

zip -r “/home/softworks/folder1.zip” /home/softworks/public_html/folder1

Filed Under: Cron Job, Zip

Primary Sidebar

Recent Posts

  • Bijoy Converter
  • How to amend previous commit with current changes in git and github?
  • How to install PHP 8.1 alongside PHP 7.4 using HomeBrew in MacOs?
  • Create a shell script to switch 7.4 to 8.1 and vice versa
  • How to reflect PHP8.1 to Apache in MacOS?

Recent Comments

    Archives

    • October 2025
    • September 2024
    • January 2024
    • July 2023
    • October 2021
    • September 2021
    • February 2021
    • January 2021
    • October 2020
    • September 2020
    • August 2020
    • May 2020
    • March 2020
    • February 2020
    • January 2020
    • November 2019
    • May 2019

    Categories

    • Couchbase
    • Cron Job
    • dhis2
    • Linux, MySQL
    • MySQL
    • Oracle
    • Oracle Client
    • PHP
    • SSL
    • Subdomain
    • Uncategorised
    • Wordpress
    • WP
    • Zip

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org

    Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in