Skip to content

Instantly share code, notes, and snippets.

@Dianakc
Dianakc / convert_address_lat_lon.php
Last active December 15, 2015 06:49
Convert an address into latitude, longitude values
<?php
/ * Convert an address into latitude longitude */
function getLatLong($address){
$_url = sprintf('http://maps.google.com/maps?output=js&q=%s',rawurlencode($address));
$_result = false;
if($_result = file_get_contents($_url)) {
if(strpos($_result,'errortips') > 1 || strpos($_result,'Did you mean:') !== false) return false;
preg_match('!center:\s*{lat:\s*(-?\d+\.\d+),lng:\s*(-?\d+\.\d+)}!U', $_result, $_match);
<?php
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
@Dianakc
Dianakc / add_css_adminpanels.php
Last active December 15, 2015 16:09
Add custom CSS in admin panel.
<?php
function dkc_add_css_on_pages() {
echo '
#csp-dialog-msgid[style], #csp-dialog-msgid-plural[style] {font-size:14px!important; font-family:"Lucida Console"!important; color:#333; padding:10px;background:#D8E8F5;border:none;line-height:18px!important }
#csp-dialog-msgstr[style], #csp-dialog-msgstr-0[style], #csp-dialog-msgstr-1[style] {font-size:14px!important; font-family:"Lucida Console"!important; color:#000; background:#FAFCFE;border:none;padding:10px;line-height:18px!important }
#csp-dialog-msgstr[style]:focus, #csp-dialog-msgstr-0[style]:focus, #csp-dialog-msgstr-1[style]:focus {font-size:14px!important;-webkit-box-shadow: 0px 1px 0px 2px #A6BFD3; box-shadow: 0px 1px 0px 2px #A6BFD3;: 0px 0px 10px 2px #A6BFD3;background:#f7f7f7}
#csp-dialog-body strong {color:#85B7E0}
@Dianakc
Dianakc / Conver_hex_to_rgb.php
Last active December 15, 2015 16:19
Converte cor hexadecimal em rgb
<?php
function hex2rgb($hex) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
<?php
// Shortcode implementation
function magic_stuff($atts) {
// turn on output buffering to capture script output
ob_start();
// include file (contents will get saved in output buffer)
include(TEMPLATEPATH.'/wp-content/prugins/magic-plugin/magic-code.php');
@Dianakc
Dianakc / dynamic_sidebar_shortcode.php
Last active December 16, 2015 02:09
Permite usar dynamic_sidebar em shortcodes, para isso seu conteúdo deve ser atribuido a uma variável
<?php
function shortcoding_for_sidebar( $atts ) {
ob_start();
dynamic_sidebar('sidecode');
$html = ob_get_contents();
ob_end_clean();
//return $html;
}
@Dianakc
Dianakc / hash_for_uploads.php
Last active December 16, 2015 06:19
Adiciona um hash e/outras coisas no arquivo enviado
<?php
function make_filename_hash($filename) {
$nomedosite = get_bloginfo('name');
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$name = basename($filename, $ext);
return $nomedosite.'_'.md5($name) . $ext;
}
add_filter('sanitize_file_name', 'make_filename_hash', 10);
@Dianakc
Dianakc / order_posts_in_alpha.php
Last active December 16, 2015 06:19
Modifica a ordem dos posts na listagem
<?php
function sort_categories_by_title($x) {
if (is_category()) { //can set specific ones
$x->query_vars['orderby'] = 'title';
$x->query_vars['order'] = 'ASC';
}
}
add_action('pre_get_posts', 'sort_categories_by_title');
@Dianakc
Dianakc / get_ID_by_slug.php
Last active December 17, 2015 07:59
Obtém ID da página por slyg
<?php
function get_ID_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}
}
;?>
@Dianakc
Dianakc / add_class_first_post.php
Last active December 17, 2015 19:19
Adiciona uma classe especial para o primeiro post em um loop
<?php
function mark_first_post( $classes )
{
remove_filter( current_filter(), __FUNCTION__ );
$classes[] = 'first-post';
return $classes;
}
add_filter( 'post_class', 'mark_first_post' );