Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / plugin-2.php
Last active January 1, 2023 23:00
How to create a Simple WordPress Language Switcher | https://www.ibenic.com/how-to-create-a-simple-wordpress-language-switcher/
<?php
// ... previous code
class SimpleWordPressLanguageSwitcher {
// ... previous code
/**
* Return the correct locale based on the $_GET parameter.
@igorbenic
igorbenic / installer-2.php
Last active February 21, 2024 21:34
Working with Custom Tables in WordPress – Installing and Updating | https://ibenic.com
<?php
/**
* Installer class
*/
namespace MyPlugin;
class Installer {
// ... previous code
@igorbenic
igorbenic / importer.php
Created June 4, 2021 12:44
Ignore Product Meta data from WooCommerce Importer
<?php
add_filter( 'woocommerce_product_import_process_item_data', 'wc_ignore_meta_in_import_if_non_value' );
/**
* Ignore the meta if value is empty
*
* @param array $data Data.
*
* @return array
@igorbenic
igorbenic / hide.php
Last active April 11, 2024 09:05
Shortcode Hide/Show Content
<?php
add_action( 'init', 'ibenic_register_hide_shortcode' );
function ibenic_register_hide_shortcode() {
add_shortcode( 'hide_content_if', 'ibenic_hide_content_if' );
}
function ibenic_hide_content_if( $atts, $content ) {
@igorbenic
igorbenic / shortcode.php
Created November 11, 2020 11:27
Conditional Enqueueing of scripts in WordPress
<?php
add_action('wp_enqueue_scripts', 'enqueue_if_shortcode');
function enqueue_if_shortcode(){
global $post;
if ( $post && has_shortcode( $post->post_content, 'your_shortcode_tag' ) {
// Enqueue
}
@igorbenic
igorbenic / form.php
Last active October 26, 2020 16:08
Programmatically Upload and Unpack ZIP files in WordPress | on https://www.ibenic.com/
<?php
/**
* Registering our shortcode
*/
function ibenic_register_upload_form() {
add_shortcode( 'zip_upload_form', 'ibenic_zip_upload_form' );
}
@igorbenic
igorbenic / add-cart-item.php
Last active February 21, 2024 21:34
Selling Simple Products as WooCommerce Subscriptions - Parts of code from tutorials | Selling Simple Products as WooCommerce Subscriptions - Admin | https://www.ibenic.com/selling-simple-products-woocommerce-subscriptions-front | https://www.ibenic.com/selling-simple-products-woocommerce-subscriptions-admin
<?php
namespace Simple_Product_Subscriptions;
class Cart {
/**
* Cart Hooks
@igorbenic
igorbenic / load_latest.php
Last active June 1, 2020 18:33
Loading Your Library only once between WordPress Plugins | https://www.ibenic.com/loading-library-once-wordpress-plugins/
<?php
class Library_Integration {
// previous code here ...
/**
* Load latest Library path
*/
public static function load_latest_path() {
<?php
/**
* Plugin Name: Simple Giveaways - Translating strings
* Description: This file can be saved under wp-content/plugins or just paste the code in your theme's functions.php.
* Version: 1.0.0
*/
if ( ! defined('ABSPATH') ) {
return;
@igorbenic
igorbenic / code.php
Created April 23, 2020 23:38
Pets and User Submitted Posts
<?php
function pets_usp_modify_post_type( $post_type ) {
return 'pets'; // edit post type as needed
}
add_filter( 'usp_post_type', 'pets_usp_modify_post_type' );