Skip to content

Instantly share code, notes, and snippets.

View stefanbc's full-sized avatar
🖖
Do; or do not. There is no // TODO

Stefan Cosma stefanbc

🖖
Do; or do not. There is no // TODO
View GitHub Profile
@stefanbc
stefanbc / functions.php
Created February 20, 2014 07:06
Custom Functions for Contact Form 7
<?php
// Get date from Contact Form 7 before email send
add_action("wpcf7_before_send_mail", "wpcf7_save_data");
function wpcf7_save_data(&$wpcf7_data) {
// Here is the variable where the data are stored!
$user_nume = $wpcf7_data->posted_data['user_nume'];
$user_email = $wpcf7_data->posted_data['user_email'];
// Set the cookies
setcookie('os_username', $user_nume, time() + (10*365*24*60*60));
@stefanbc
stefanbc / functions.php
Created February 21, 2014 07:41
Custom database connection
<?php
// Create a new database connection
$customdb = new wpdb(USERNAME, PASSWORD, DATABASE, 'localhost');
$customdb->show_errors();
?>
@stefanbc
stefanbc / stringGen.php
Created February 21, 2014 07:44
Generate a random string
<?php
// Generate a random string with a given lenght and set special char on or off
function random_gen($length, $special_char) {
$random = "";
srand((double)microtime()*1000000);
$char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$char_list .= "abcdefghijklmnopqrstuvwxyz";
$char_list .= "1234567890";
@stefanbc
stefanbc / functions.php
Created February 26, 2014 08:58
Add Checkbox option to General Settings
<?php
$new_general_setting = new new_general_setting();
class new_general_setting {
function new_general_setting( ) {
add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
}
function register_fields() {
register_setting( 'general', 'OPTION_NAME', 'esc_attr' );
add_settings_field('OPTION_NAME', '<label for="OPTION_NAME">'.__('OPTION_LABEL_TEXT' , 'OPTION_NAME' ).'</label>' , array(&$this, 'fields_html') , 'general' );
@stefanbc
stefanbc / import.php
Created March 6, 2014 10:58
Import Ammap entries to WordPress posts
<?php
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once ($parse_uri[0] . 'wp-load.php');
require_once($parse_uri[0] . '/wp-admin/includes/taxonomy.php');
// Get coordinates for a specified address
function getCoordinates($address){
$address = str_replace("Str.", "Strada", $address);
@stefanbc
stefanbc / db.sql
Created April 24, 2014 21:21
Deactivate all plugins from the DB
UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';
@stefanbc
stefanbc / header.tpl
Created May 13, 2014 11:26
Login with Facebook using Login Radius in Prestashop
<!-- Requires dependencies https://github.com/carhartl/jquery-cookie -->
<script src="{$js_dir}jquery.cookie.js"></script>
{if $smarty.get.fb == 1 && $page_name == 'index'}
<script type="text/javascript">
$(document).ready(function(){
// console.log("BEFORE");
var cookie = $.cookie("loggedinFB");
@stefanbc
stefanbc / export.php
Last active March 28, 2017 09:45
Export CSV from osCommerce and import it in Prestashop.Instructions:* Place the script in your osC root folder* Call the script in your browser* Save the file* Import it in Prestashop* Map the fields* Import!* You're awesome! Note: Tested with osC 2.2 rc 2a and Ps 1.5.4.1
<?php
require('includes/application_top.php');
// Output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// Create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
@stefanbc
stefanbc / functions.php
Created July 23, 2014 12:54
Automatically add product to cart, on Woocommerce.
<?php
// Add item to cart on visit
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = THE_PRODUCT_ID;
$found = false;
//check if product already in cart
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
@stefanbc
stefanbc / size.sql
Created August 4, 2014 09:34
Find out database size using a query (usable in phpMyAdmin)
SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB"
FROM information_schema.TABLES GROUP BY table_schema ;