Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Cristian Ionel waylay

🏠
Working from home
Block or report user

Report or block waylay

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@waylay
waylay / functions.php
Last active Sep 1, 2019
Add Login/Username/Logout(as submenu) to main navigation
View functions.php
function add_login_logout_to_menu( $items, $args ) {
if ( $args->theme_location != 'primary' ) {
return $items;
}
if ( !is_user_logged_in() ) {
$items .= '<li><a href="'.wp_login_url().'" title="Login">Login</a></li>';
} else {
$current_user = wp_get_current_user();
$items .= '<li class="menu-item-has-children"><a href="#">'. $current_user->display_name .'</a><ul class="sub-menu">';
@waylay
waylay / login.php
Created Aug 29, 2019
WordPress PHP login
View login.php
<?php
if($_SERVER['REMOTE_ADDR'] == 'x.x.x.x') {
$user_id = 1;
$user = get_user_by( 'id', $user_id );
if( $user && !is_user_logged_in()) {
wp_set_current_user( $user_id, $user->user_login );
wp_set_auth_cookie( $user_id );
do_action( 'wp_login', $user->user_login, $user );
}
}
@waylay
waylay / .htaccess
Created Aug 22, 2018
.htaccess HTTPS redirect
View .htaccess
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@waylay
waylay / magento_attachments.php
Created Sep 25, 2017
Map Magento attachment file to WooCommerce product file
View magento_attachments.php
<?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 / replace_shortcode_with_output.php
Created Jul 4, 2017
Replace shortcode with its output in all posts
View replace_shortcode_with_output.php
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 / new-user-db.sql
Created Feb 15, 2017
MySQL create new db/user
View new-user-db.sql
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 Feb 15, 2017
Add new domain or subdomain on DO
View add-domain.txt
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
View customizer.js
// 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 / social-sharing.php
Created Jan 19, 2017
Social sharing without JS
View social-sharing.php
<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>
View debug.php
<?php
if (!function_exists('dd')) {
function dd()
{
$args = func_get_args();
echo "<script>";
echo "console.log(".json_encode($args).")";
echo "</script>";
}
}
You can’t perform that action at this time.