How to create a custom table using custom code in WordPress? 


global $wpdb;
    global $charset_collate;
    $table_name = $wpdb->prefix . 'custom_table';
	$sql = "CREATE TABLE IF NOT EXISTS $table_name (
		`ID` int(20) NOT NULL AUTO_INCREMENT,
		`name` varchar(200)  NOT NULL,
		`mobile_number` varchar(200) NOT NULL,
		`email` varchar(20) NOT NULL,
		PRIMARY KEY (`ID`)
	)$charset_collate;";
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $sql );
Advertisement

Encryption & Decryption using PHP

<pre>
//Encryption
function encryption_function($string){
	// Storingthe cipher method 
	$ciphering = "AES-128-CTR";

	// Using OpenSSl Encryption method 
	$iv_length = openssl_cipher_iv_length($ciphering);
	$options   = 0;

	// Non-NULL Initialization Vector for encryption 
	$encryption_iv = '0000111122223333';

	// Storing the encryption key 
	$encryption_key = "aviweb";
	
	return openssl_encrypt($string, $ciphering, $encryption_key, $options, $encryption_iv);
}
//Decryption
function decryption_function($string){
	// Storingthe cipher method 
	$ciphering = "AES-128-CTR";

	// Using OpenSSl Encryption method 
	$iv_length = openssl_cipher_iv_length($ciphering);
	$options   = 0;

	// Non-NULL Initialization Vector for encryption 
	$decryption_iv = '0000111122223333';

	// Storing the decryption key 
	$decryption_key = "aviweb";
	
	return openssl_decrypt($string, $ciphering, $decryption_key, $options, $decryption_iv);
}
</pre>

Compare two dates in php

<pre>
	<?php 
	$date = "2021-12-25";
	$today = date("Y-m-d");
	$today_time = strtotime($today);
	$compare_date = strtotime($date);
	if($compare_date > $today_time){
		echo 'Future date';
	}else{
		echo 'Past Date';
	}
	?>
</pre>

Magento 2.4.1 admin page showing blank

1. Need to update code in Validator.php
2. Path: vendor\magento\framework\View\Element\Template\File
3. Replace line no 138 like below

$realPath = $this->fileDriver->getRealPath($path); replace with $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));

Run below commends.
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento indexer:reindex

Unable to apply data patch Magento\Theme\Setup\Patch\Data\RegisterThemes for module Magento_Theme. And Wrong file In Gd2.php in Magento 2.4.1

Add extra condition, please edit below function on line no 90 follow this- vendor\magento\framework\Image\Adapter\Gd2.php

private function validateURLScheme(string $filename) : bool
  {
      $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
      $url = parse_url($filename);
      if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) {
          return false;
      }

      return true;
  }

Remove admin menu from WordPress dashboard

 
add_action('admin_init', 'custom_remove_admin_page');

if(!function_exists('custom_remove_admin_page')) {
	function remove_admin_page($needle) {
		if(isset($GLOBALS[ 'menu' ]) && !empty($GLOBALS[ 'menu' ]) && !empty($needle)) {
			$needle = strtolower($needle);
			$needle = trim($needle);
			foreach($GLOBALS[ 'menu' ] as $position => $items) {
				foreach($items as $key => $item) {                   
					if(strtolower($item) == $needle) {
						remove_menu_page( $items[2] );
					}
				}
			}
		}
	}
}	

European countries list in php array

$eu_counries = array( 'AL' => 'Albania', 'AD' => 'Andorra', 'AM' => 'Armenia', 'AT' => 'Austria ', 'BY' => 'Belarus', 'BE' => 'Belgium', 'BA' => 'Bosnia and Herzegovina', 'BG' => 'Bulgaria', 'CH' => 'Switzerland', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 'DE' => 'Germany', 'DK' => 'Denmark', 'EE' => 'Estonia', 'ES' => 'Spain', 'FO' => 'Faeroe Islands', 'FI' => 'Finland', 'FR' => 'France', 'GB' => 'United Kingdom', 'GE' => 'Georgia', 'GI' => 'Gibraltar', 'GR' => 'Greece', 'HU' => 'Hungary', 'HR' => 'Croatia', 'IE' => 'Ireland', 'IS' => 'Iceland', 'IT' => 'Italy', 'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'LV' => 'Latvia', 'MC' => 'Monaco', 'MK' => 'Macedonia', 'MT' => 'Malta', 'NO' => 'Norway', 'NL' => 'Netherlands', 'PL' => 'Poland', 'PT' => 'Portugal', 'RO' => 'Romania', 'RU' => 'Russian Federation', 'SE' => 'Sweden', 'SI' => 'Slovenia', 'SK' => 'Slovakia', 'SM' => 'San Marino', 'TR' => 'Turkey', 'UA' => 'Ukraine', 'VA' => 'Vatican City State');