Skip to content

Instantly share code, notes, and snippets.

@cdmz
cdmz / wp-query-post-type-laco.php
Created July 16, 2015 16:30
wp-query post type laco
<?php
wp_reset_query();
$wp_query = new WP_Query();
$query = $wp_query->query("post_type=sms-categories");
while ($wp_query->have_posts())
{
$wp_query->the_post();
?>
//put your code here
<?php
@cdmz
cdmz / get-image-using-get_post_meta-by-id.php
Last active August 29, 2015 14:25
get image using get_post_meta by id
<?php
$logotipo = get_post_meta($post->ID,'logotipo',true);
if($logotipo > 0 AND $logotipo != ''){
$logotipo = wp_get_attachment_image_src( $logotipo );
if(is_array($logotipo) AND count($logotipo) > 0){
$logotipo = array_shift($logotipo);
}else{
$logotipo = '';
}
}else{
@cdmz
cdmz / hide-button-add-new-post-by-post-type-and-post-id.php
Created July 17, 2015 14:06
hide button add new post in submenu and list post type and page edit post
<?php
//hide button add new in submenu and list post types and edit posts
function disable_new_posts() {
// remove submenu
global $submenu;
unset($submenu['edit.php?post_type=sms-call'][10]);
unset($submenu['edit.php?post_type=sms-ajudar'][10]);
// hide button add new
if (
@cdmz
cdmz / auto_default_base_url.php
Last active August 29, 2015 14:25
Auto change siteurl wordpress
<?php
include 'wp-load.php';
$folder = $_GET['folder'];
$results = $wpdb->get_results( "SELECT option_id,option_name,option_value FROM wp_options WHERE option_name = 'home' OR option_name = 'siteurl'");
$rows = count($results);
if($rows > 0 AND is_array($results)){
$host = $_SERVER['HTTP_HOST'];
$site_url = $results[0]->option_value;
$home = $results[1]->option_value;
if(
@cdmz
cdmz / verify-if-table-exists-in-database-wordpress.php
Created July 21, 2015 18:10
verify if table exists in database wordpress
<?php
include '../../../../wp-load.php';
global $wpdb;
$table_name = "wp_posts";
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
//Your code here
}
@cdmz
cdmz / download-files.php
Created July 22, 2015 19:09
Download files with php
<?php
//Referencia do arquivo
$arquivo = $_GET["arquivo"];
//get file ...
$path = /*path file here*/
if(isset($path) && file_exists($path)){
// verifica se a extensão do arquivo é permitida para baixar
switch(strtolower(substr(strrchr(basename($path),"."),1))){
@cdmz
cdmz / generate-images-custom-dimensions-keeping-proportion-dinamic.php
Created July 28, 2015 20:39
Class that generates images in custom size keeping the aspect ratio. If the image does not exist, will be generated and saved in the folder mentioned and printed on the screen. If the image already exists in the reported dimensions, the image will be printed on the screen.
<?php
class image{
public function createthumb_estadio($id, $name, $new_w, $new_h) {
$border=false; $transparency=true; $base64=false;
$name_ = $name;
$name = "images/estadios/{$id}/{$name}";
$newname = "images/estadios/$id/".$new_w."_".$new_h.$name_;
if(file_exists($newname)){
switch (exif_imagetype($newname)) {
case IMAGETYPE_PNG:
@cdmz
cdmz / update-site-url-wordpress-SQL.sql
Last active September 12, 2015 04:50
Update siteurl wordpress SQL
UPDATE wp_options SET option_value = replace(option_value, 'http://homologa.info/sesc-bienal', 'http://localhost/bienal-danca') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://homologa.info/sesc-bienal','http://localhost/bienal-danca');
UPDATE wp_posts SET post_content = replace(post_content, 'http://homologa.info/sesc-bienal', 'http://localhost/bienal-danca');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://homologa.info/sesc-bienal', 'http://localhost/bienal-danca');
@cdmz
cdmz / mixin-gradiente-vertical-less.less
Created July 31, 2015 11:28
Mixin gradiente vertical LESS
.vertical(@startColor: #555, @endColor: #333) {
background-color: mix(@startColor, @endColor, 60%);
background-image: -moz-linear-gradient(top, @startColor, @endColor); // FF 3.6+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+
background-image: -webkit-linear-gradient(top, @startColor, @endColor); // Safari 5.1+, Chrome 10+
background-image: -o-linear-gradient(top, @startColor, @endColor); // Opera 11.10
background-image: linear-gradient(to bottom, @startColor, @endColor); // Standard, IE10
background-repeat: repeat-x;
filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",argb(@startColor),argb(@endColor))); // IE9 and down
}
@cdmz
cdmz / Get-extension-file-by-path-javascript.js
Created July 31, 2015 13:27
Get extension file by path javascript
var path = "http://localhost/project/temp/folder/file.mp4";
var array = path.split('/'); // split /
var ultimo = array.pop(); // get last index
var basename = ultimo.split('.'); // splt .
var extension = basename.pop(); // get last index
alert(extension);
// OR
var path ="http://localhost/project/temp/folder/file.mp4";