Add custom login / logout link in wordpress menu

Place below code in functions.php

<?php

add_filter(‘wp_nav_menu_items’, ‘add_login_logout_link’, 10, 2);
function add_login_logout_link($items, $args) {
ob_start();
wp_loginout(‘index.php’);
$loginoutlink = ob_get_contents();
ob_end_clean();
$items .= ‘<li>’. $loginoutlink .'</li>’;
return $items;
}

?>

Read files from directory and copy / move to another directory using php

<?php

/* For wordress */
$upload_dir = wp_upload_dir();
$dir = $upload_dir[‘basedir’].”/2015/11/”;
$dest_dir = $upload_dir[‘basedir’].”/developer/”;

/* For PHP */
$dir = “/source”;
$dest_dir = “/destination/”;

if (is_dir($dir)){
if ($dh = opendir($dir)){ $i=1; $cou = 0;
while (($file = readdir($dh)) !== false){
if (( $file != ‘.’ ) && ( $file != ‘..’ )) {
/* Copy files */
copy($dir . $file,$dest_dir . $file);
$i++;
/* Move files */
rename($dir . ‘/’ . $file, $dest_dir . ‘/’ . $file);
}

}
closedir($dh);
}
}
?>

Store string with quotes in MySQL using PHP new version

<?php

/* Database connect using mysqli */

$dbHost = ‘localhost’;
$dbUsername = ‘root’;
$dbPassword = ”;
$dbName = ‘test’;
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
if ($db->connect_errno) {
printf(“Connect failed: %s\n”, $db->connect_error);
exit();
}

/* Solve quotes issue using “addslashes” function in PHP. */ 

$str = “Is your name O’Reilly?”;

// Outputs: Is your name O\’Reilly?

$str = addslashes($str);

$query = “INSERT INTO table VALUES (‘$str’)”;
$sql = $db->query($query);
?>