Skip to content

Instantly share code, notes, and snippets.

View waylay's full-sized avatar
🏠
Working from home

Cristian Ionel waylay

🏠
Working from home
  • WCD
  • Brno, Czech Republic
  • X @waylay
View GitHub Profile
@waylay
waylay / customizer.php
Last active August 28, 2016 18:57
Add Logo Upload field in WordPress Customizer
<?php
/**
* Create Logo Setting and Upload Control
* Namespaced for Sage Usage
*/
function add_header_logo_settings($wp_customize) {
// add a setting for the site logo
$wp_customize->add_setting('header_logo');
// Add a control to upload the logo
$wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'header_logo',
@waylay
waylay / debug.php
Created November 1, 2016 15:03
Quick Debug
<?php
if (!function_exists('dd')) {
function dd()
{
$args = func_get_args();
echo "<script>";
echo "console.log(".json_encode($args).")";
echo "</script>";
}
}
@waylay
waylay / social-sharing.php
Created January 19, 2017 08:26
Social sharing without JS
<div class="social-sharing">
<?php
$link = urlencode(get_permalink());
?>
<ul>
<li>Share this on...</li>
<li class="twitter"><a href="https://twitter.com/intent/tweet?url=<?php echo $link; ?>" target="_blank">Twitter</a></li>
<li class="facebook"><a href="https://facebook.com/sharer.php?u=<?php echo $link; ?>" target="_blank">Facebook</a></li>
<li class="google-plus"><a href="https://plus.google.com/share?url=<?php echo $link; ?>" target="_blank">Google+</a></li>
<li class="linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo $link; ?>" target="_blank">LinkedIn</a></li>
// assets/scripts/customizer.js
(function($) {
// Primary colour
wp.customize('primary_colour', function(value) {
value.bind(function(to) {
$('head').append('<style>.Primary-bg-c{background-color:'+ to +' !important;}</style>');
$('head').append('<style>.Primary-c{color:'+ to +' !important;}</style>');
$('head').append('<style>.Primary-c--hover:hover{color:'+ to +' !important;}</style>');
@waylay
waylay / new-user-db.sql
Created February 15, 2017 14:46
MySQL create new db/user
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE newdatabase;
GRANT ALL PRIVILEGES ON newdatabase.* TO 'newuser'@'localhost';
@waylay
waylay / add-domain.txt
Last active February 15, 2017 15:04
Add new domain or subdomain on DO
1. Networking / Add Domain or Create new A record for subdomain;
2. cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
3. vi /etc/apache2/sites-available/example.com.conf
-----------
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/example.com
ServerName example.com
@waylay
waylay / replace_shortcode_with_output.php
Created July 4, 2017 12:03
Replace shortcode with its output in all posts
function get_replaced_sourcecode_sc( $post ) {
if ( empty($post) ) global $post;
if ( empty($post) || ! isset($post->post_content) ) return false;
$content = $post->post_content;
if (
preg_match_all( '/'. get_shortcode_regex() .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches ) && in_array( 'purehtml', $matches[2] )
) {
foreach ( $matches[2] as $i => $sc ) {
if ( $sc == 'purehtml' )
@waylay
waylay / magento_attachments.php
Created September 25, 2017 21:22
Map Magento attachment file to WooCommerce product file
<?php
//SQL
$mydb = new wpdb('root','root','magento','localhost');
$rows = $mydb->get_results("
select p.entity_id, p.sku, f.title, f.uploaded_file
from pml_uni_fileuploader f
inner join pml_catalog_product_entity p
on find_in_set(p.entity_id, f.product_ids)
order by p.entity_id
@waylay
waylay / search_and_replace.html
Created August 17, 2016 19:24
Search & Replace SQL Generator for changing WordPress URLs
<div>Old Url:</div> http://<input id="old_url" name="old_url" type="text" value="old_url" onchange="replaceMyText()" onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();"/>
<div>New Url:</div> http://<input id="new_url" name="new_url" type="text" value="new_url" onchange="replaceMyText()" onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();"/>
<div id="haystack">
UPDATE wp_options SET option_value = replace(option_value, 'http://old_url', 'http://new_url') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://old_url','http://new_url');
UPDATE wp_posts SET post_content = replace(post_content, 'http://old_url', 'http://new_url');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://old_url','http://new_url');
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old_url', 'http://new_url') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = repl
@waylay
waylay / .htaccess
Created August 22, 2018 15:42
.htaccess HTTPS redirect
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]