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 / 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 / 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 / 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 / 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 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 / 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 / wp_reset.php
Created January 21, 2014 07:15
WordPress reset Install
<?php
// HOW TO USE:
// Simply type in the url in the text box to reset the WordPress site url.
// WARNING:
// This file can be a HUGE security risk and has the potential to seriously
// mess up your site's database. Please use with caution and DELETE THIS FILE when you
// are done resetting your website.
@stefanbc
stefanbc / remove_slug.php
Created September 19, 2013 07:32
These functions remove the slug from a permalink for a custom post type. These should be placed in functions.php in your theme and the permalink structure should be /%postname%/
<?php
add_filter('post_type_link','custom_post_type_link',10,3);
function custom_post_type_link($permalink, $post, $leavename) {
$url_components = parse_url($permalink);
$post_path = $url_components['path'];
$post_name = end(explode('/', trim($post_path, '/')));
if(!empty($post_name)) {
@stefanbc
stefanbc / getCoordinates.php
Created June 13, 2013 22:06
Get coordinates for a specified address
<?php
// Get coordinates for a specified address
function getCoordinates($address){
$address = str_replace(" ", "+", $address); // replcae all the white space with "+" sign to match with google search pattern
$url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=$address";
$response = file_get_contents($url);
@stefanbc
stefanbc / svn_client.bat
Created June 13, 2013 17:35
SVN bat file
@echo off
title SVN Client v1.0
echo ####################################
echo ## ##
echo ## Welcome to the SVN Client v1.0 ##
echo ## ##
echo ####################################
cd C:\Program Files\SlikSvn\bin\