Skip to content

Instantly share code, notes, and snippets.

View gelanivishal's full-sized avatar
🎯
Focusing

Vishal Gelani gelanivishal

🎯
Focusing
View GitHub Profile
@gelanivishal
gelanivishal / DatabaseManager.php
Last active June 13, 2017 16:58
A mysql database wrapper
<?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 June 13, 2017 16:35
Wordpress file permissions
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 June 13, 2017 16:33
M1 - Check admin logged in
<?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 June 13, 2017 16:31
Create custom log file in magento2
<?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 June 13, 2017 16:30
Create Admin user programmatically in Wordpress
<?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 June 13, 2017 16:32
Reset MySQL user password
  • 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 April 28, 2017 06:08
Magento Database Backup Without phpmyadmin access
<?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 April 26, 2017 06:34
Mailchimp API add subscriber to list without confirmation
<?php
$data = [
'email' => 'john@exmple.com',
'status' => 'subscribed',
'firstname' => 'john',
'lastname' => 'doe'
];
syncMailchimp($data);
@gelanivishal
gelanivishal / snippet.md
Created March 17, 2017 02:43
Magento 1 & 2 Useful links
@gelanivishal
gelanivishal / function.php
Created March 10, 2017 01:17
Add image to product programmatically
<?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/';