Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Vishal Gelani gelanivishal

🎯
Focusing
View GitHub Profile
@gelanivishal
gelanivishal / DatabaseManager.php
Last active Jun 13, 2017
A mysql database wrapper
View DatabaseManager.php
<?php
// Database
define('DB_HOST', 'localhost');
define('DB_DB', 'db_name');
define('DB_USER', 'db_user');
define('DB_PASS', 'db_password');
define('DB_ERROR', '/path/to/db_error.log');
@gelanivishal
gelanivishal / wordpress.sh
Created Jun 13, 2017
Wordpress file permissions
View wordpress.sh
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
WS_GROUP=www-data # <-- webserver group
# reset to safe defaults
find ${WP_ROOT} -exec chown ${WP_OWNER}:${WP_GROUP} {} \;
find ${WP_ROOT} -type d -exec chmod 755 {} \;
find ${WP_ROOT} -type f -exec chmod 644 {} \;
@gelanivishal
gelanivishal / is_admin_logged_in.php
Created Jun 13, 2017
M1 - Check admin logged in
View is_admin_logged_in.php
<?php
function isAdminLogin(){
$userId = 0;
$switchSessionName = 'adminhtml';
$currentSessionId = Mage::getSingleton('core/session')->getSessionId();
$currentSessionName = Mage::getSingleton('core/session')->getSessionName();
//if ($currentSessionId && $currentSessionName && isset($_COOKIE[$currentSessionName])) {
if(isset($_COOKIE[$switchSessionName])){
$switchSessionId = $_COOKIE[$switchSessionName];
$this->_switchSession($switchSessionName, $switchSessionId);
@gelanivishal
gelanivishal / custom_log_magento2.php
Created Jun 13, 2017
Create custom log file in magento2
View custom_log_magento2.php
<?php
// Create custom log file in var/log/...
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/XYZ.log'); // Whatever name you want
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Amazon Request'); // Set simple text in log file
$logger->info(print_r($array_of_content, true)); // array you want to log file
@gelanivishal
gelanivishal / create-admin.php
Created Jun 13, 2017
Create Admin user programmatically in Wordpress
View create-admin.php
<?php
define('WP_USE_THEMES', true);
// Load the WordPress library.
require_once( dirname(__FILE__) . '/wp-load.php' );
// Set up the WordPress query.
wp();
$username = 'developer';
$password = 'developer123';
@gelanivishal
gelanivishal / mysql_reset_user_password.md
Last active Jun 13, 2017
Reset MySQL user password
View mysql_reset_user_password.md
  • Turn off MySQL
  • Reset the root password through safe mode

sudo mysqld_safe --skip-grant-tables //Start up safe mode mysql -u root //Log into MySQL as root: use mysql; update user set password=PASSWORD("the new password you want to use") where User='root'; flush privileges; exit

@gelanivishal
gelanivishal / db_backup.php
Created Apr 28, 2017
Magento Database Backup Without phpmyadmin access
View db_backup.php
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
ini_set('memory_limit', '512M');
// Get Magento Application
require_once 'app/Mage.php';
Mage::app('default');
@gelanivishal
gelanivishal / mailchimp-subscribe.php
Last active Apr 26, 2017
Mailchimp API add subscriber to list without confirmation
View mailchimp-subscribe.php
<?php
$data = [
'email' => 'john@exmple.com',
'status' => 'subscribed',
'firstname' => 'john',
'lastname' => 'doe'
];
syncMailchimp($data);
@gelanivishal
gelanivishal / snippet.md
Created Mar 17, 2017
Magento 1 & 2 Useful links
@gelanivishal
gelanivishal / function.php
Created Mar 10, 2017
Add image to product programmatically
View function.php
<?php
// Add three image sizes to media gallery
$mediaArray = array(
'thumbnail' => $putPathHere,
'small_image' => $putPathHere,
'image' => $putPathHere,
);
// Remove unset images, add image to gallery if exists
$importDir = Mage::getBaseDir('media') . DS . 'import/';