WordPress – Reffffference https://ivan.reallusiondesign.com For my personal reference purposes Thu, 05 Jul 2018 20:21:23 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 106465655 Mount directory into the RAM https://ivan.reallusiondesign.com/mount-directory-into-the-ram/ https://ivan.reallusiondesign.com/mount-directory-into-the-ram/#disqus_thread Thu, 05 Jul 2018 20:20:44 +0000 https://ivan.reallusiondesign.com/?p=875 Needed to mount WordPress cache folder into the RAM of one VPS, to get that little bit of extra speed.
To mount it temporary and see how it works for you, you can use:

mount -t tmpfs -o size=64M tmpfs /absolute/path/to/your/folder/

To make it permanent you need to add this in the /etc/fstab file:

tmpfs /absolute/path/to/your/folder tmpfs defaults,size=64M 0 0
]]>
https://ivan.reallusiondesign.com/mount-directory-into-the-ram/feed/ 0 875
WordPress white page with Nginx and php-fpm https://ivan.reallusiondesign.com/wordpress-white-page-with-nginx-and-php-fpm/ https://ivan.reallusiondesign.com/wordpress-white-page-with-nginx-and-php-fpm/#disqus_thread Tue, 23 May 2017 23:14:48 +0000 https://ivan.reallusiondesign.com/?p=795 One of the reasons for this and nothing in the logs might be newer version of Nginx which and you will have to replace in your configuration

include fastcgi_params;

with

include fastcgi.conf;

Another problem is that you might need to add

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

in /etc/nginx/fastcgi_params , might be called also /etc/nginx/fastcgi.conf
It can also be added where your php setting block in Nginx is.

Might expand the post in the future with other possible reasons.

]]>
https://ivan.reallusiondesign.com/wordpress-white-page-with-nginx-and-php-fpm/feed/ 0 795
Hide WordPress plugin from the plugin list. https://ivan.reallusiondesign.com/hide-wordpress-plugin-from-the-plugin-list/ https://ivan.reallusiondesign.com/hide-wordpress-plugin-from-the-plugin-list/#disqus_thread Wed, 16 Mar 2016 17:46:06 +0000 https://ivan.reallusiondesign.com/?p=677 If you want to hide a plugin name from the WordPress backend for whatever reason, you can use this piece of code in the functions file on your active theme:

	function hide_plugin_reallusion() {
	  global $wp_list_table;
	  $hidearr = array('plugin-folder/plugin.php');
	  $myplugins = $wp_list_table->items;
	  foreach ($myplugins as $key => $val) {
		if (in_array($key,$hidearr)) {
		  unset($wp_list_table->items[$key]);
		}
	  }
	}
	 
	add_action('hide_plugin_backend', 'hide_plugin_reallusion');

Or make this into plugin? Why not – plugins for everyone, let’s get covered in plugins.

]]>
https://ivan.reallusiondesign.com/hide-wordpress-plugin-from-the-plugin-list/feed/ 0 677
WPML Translate get_theme_mod https://ivan.reallusiondesign.com/wpml-translate-get_theme_mod/ https://ivan.reallusiondesign.com/wpml-translate-get_theme_mod/#disqus_thread Mon, 21 Sep 2015 07:19:56 +0000 https://ivan.reallusiondesign.com/?p=635 If you are using WPML and you have a theme which customize strings are not detected you can use the fallowing code, you might need to modify it for your use case:

if (function_exists ( 'icl_register_string' )) {
    echo icl_translate('Theme Mod', 'text_in_wpml', get_theme_mod( 'theme_mod_name' ));
}

This basically register the string as it echo it.

And yeah – this will require you to have the strings translation plugin.

]]>
https://ivan.reallusiondesign.com/wpml-translate-get_theme_mod/feed/ 0 635
Get featured image clean URL https://ivan.reallusiondesign.com/get-featured-image-clean-url/ https://ivan.reallusiondesign.com/get-featured-image-clean-url/#disqus_thread Thu, 30 Jul 2015 22:34:02 +0000 https://ivan.reallusiondesign.com/?p=598 $fimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full', false ); echo $fimage[0]; // the url ]]> https://ivan.reallusiondesign.com/get-featured-image-clean-url/feed/ 0 598 Enable WP_DEBUG to file https://ivan.reallusiondesign.com/enable-wp_debug-to-file/ https://ivan.reallusiondesign.com/enable-wp_debug-to-file/#disqus_thread Wed, 08 Apr 2015 19:53:04 +0000 https://ivan.reallusiondesign.com/?p=567 In your wp-config.php replace:

define('WP_DEBUG', false);

with:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

That will output any errors to file called debug.log in your wp-content directory.
It is far better to save errors to a file, otherwise they will be shown in your site.

]]>
https://ivan.reallusiondesign.com/enable-wp_debug-to-file/feed/ 0 567
Apply coupon if user bought a specific product https://ivan.reallusiondesign.com/apply-coupon-if-user-bought-a-specific-product/ https://ivan.reallusiondesign.com/apply-coupon-if-user-bought-a-specific-product/#disqus_thread Mon, 23 Mar 2015 16:27:53 +0000 https://ivan.reallusiondesign.com/?p=557 Recently I had to do discount in WooCommerce if a user is bought a specific product – in this case “Membership” product.
The fallowing code will check if a user is bought a product with given id, and if so it will apply specified coupon code.

Just place the fallowing at the end of your functions.php in your theme:

// Apply coupon programmatically if specific product is bought

add_action( 'woocommerce_before_cart', 'auto_add_coupon' );

function auto_add_coupon() {
    global $woocommerce;

    $coupon_code = 'membership-cc';

    if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;

    foreach ($woocommerce->cart->cart_contents as $key => $values ) {

    $target_product = array(5183);

		$current_user = wp_get_current_user();
		if (woocommerce_customer_bought_product($current_user->user_email, $current_user->ID, $target_product)){

        $woocommerce->cart->add_discount( $coupon_code );
        $woocommerce->show_messages();
    }
    }

}
]]>
https://ivan.reallusiondesign.com/apply-coupon-if-user-bought-a-specific-product/feed/ 0 557
WooCommerce can’t remove items from cart on Nginx https://ivan.reallusiondesign.com/woocommerce-cant-remove-items-from-cart-on-nginx/ https://ivan.reallusiondesign.com/woocommerce-cant-remove-items-from-cart-on-nginx/#disqus_thread Wed, 18 Mar 2015 22:46:58 +0000 https://ivan.reallusiondesign.com/?p=553 Just finished moving client site from Apache to Nginx, and upon testing I noticed when I try to remove some product from the cart, it wasn’t working . All is happening is to reload the page.

It turns out that the problem is in my Nginx config (as I suspected).

A really simple fix.

If you have section like this in your config file:

    location / {
                try_files $uri $uri/ /index.php;
        }

you will need to add ?$args after index.php, so it is going to look like this:

    location / {
                try_files $uri $uri/ /index.php?$args;
        }
]]>
https://ivan.reallusiondesign.com/woocommerce-cant-remove-items-from-cart-on-nginx/feed/ 0 553
WordPress subdomain rewrite rules for Zeus web server https://ivan.reallusiondesign.com/wordpress-subdomain-rewrite-rules-for-zeus-web-server/ https://ivan.reallusiondesign.com/wordpress-subdomain-rewrite-rules-for-zeus-web-server/#disqus_thread Wed, 04 Mar 2015 18:00:26 +0000 https://ivan.reallusiondesign.com/?p=539 If you have to deal with the Zeus web server, using WordPress subdomain, you most probably noticed that the “pretty” permalinks include “/index.php/” whatever you do.

You will need to create file named “rewrite.script” in the root directory where WordPress is installed – pretty much the equivalent to “.htaccess” in Apache.

Use this in your rewrite.sript and replace the domain URL with your own.



RULE_3_START:
insensitive match IN:Host into % with ^www.sub.domain.com
if  matched then goto RULE_2_END
RULE_3_END:

RULE_2_START:
insensitive  match IN:Host into % with ^(.*).sub.domain.com
if matched then match URL  into $ with ^/(.*)
if not matched then goto RULE_2_END
set URL =  /%1/$1
RULE_2_END:


RULE_0_START:
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}

# see if theres any queries in our URL
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
RULE_0_END:

RULE_1_START:
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}

# check to see if the file requested is an actual file or
# a directory with possibly an index. don?EUR(TM)t rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for dir at %{SCRATCH:REQUEST_FILENAME}
if not exists then
set URL = /index.php?q=%{SCRATCH:REQUEST_URI}
goto QSA_RULE_START
endif
endif

# if we made it here then its a file or dir and no rewrite
goto END
RULE_1_END:

QSA_RULE_START:
# append the query string if there was one originally
# the same as [QSA,L] for apache
match SCRATCH:ORIG_URL into % with \?(.*)$
if matched then
set URL = %{URL}&%{SCRATCH:QUERY_STRING}
endif
goto END
QSA_RULE_END:

After that you will need to go to the WordPress back-end and change your permalinks settings.

It might work with the main domain too – but I haven’t tested this.

]]>
https://ivan.reallusiondesign.com/wordpress-subdomain-rewrite-rules-for-zeus-web-server/feed/ 0 539
Taxonomy Breadcrumbs https://ivan.reallusiondesign.com/taxonomy-breadcrumbs/ https://ivan.reallusiondesign.com/taxonomy-breadcrumbs/#disqus_thread Thu, 26 Feb 2015 02:44:00 +0000 https://ivan.reallusiondesign.com/?p=534 Add this function to the functions.php file in your current theme:

/* Taxonomy Breadcrumb */
function id_taxonomy_breadcrumb() {
// Get the current term
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
// Create a list of all the term's parents
$parent = $term->parent;
while ($parent):
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
$parent = $new_parent->parent;
endwhile;
if(!empty($parents)):
$parents = array_reverse($parents);
// For each parent, create a breadcrumb item
foreach ($parents as $parent):
$item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
$url = get_bloginfo('url').'/'.$item->taxonomy.'/'.$item->slug;
echo '<a href="'.$url.'">'.$item->name.'</a> / ';
endforeach;
endif;
// Display the current term in the breadcrumb
echo $term->name;
}

And the call it in the temlate:

<?php id_taxonomy_breadcrumb(); ?>
]]>
https://ivan.reallusiondesign.com/taxonomy-breadcrumbs/feed/ 0 534