Skip to content

Instantly share code, notes, and snippets.

Avatar

Igor Benić igorbenic

View GitHub Profile
@igorbenic
igorbenic / load_latest.php
Last active Jun 1, 2020
Loading Your Library only once between WordPress Plugins | https://www.ibenic.com/loading-library-once-wordpress-plugins/
View load_latest.php
<?php
class Library_Integration {
// previous code here ...
/**
* Load latest Library path
*/
public static function load_latest_path() {
View sg-translate.php
<?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 Apr 23, 2020
Pets and User Submitted Posts
View code.php
<?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' );
@igorbenic
igorbenic / field.php
Last active Mar 19, 2020
How to use the WooCommerce Postcode Validator | https://www.ibenic.com/woocommerce-postcode-validator
View field.php
<?php
/**
* Shipping method id: rp_table_rate
* You can use any ID here and replace rp_table_rate to add this field to your shipping method settings page.
*/
add_filter( 'woocommerce_settings_api_form_fields_rp_table_rate', 'ibenic_add_postcodes_field_a_shipping_method' );
/**
* Add Postcodes field to the Table Rate
View validator.php
<?php
/**
* Used by shipping zones and taxes to compare a given $postcode to stored
* postcodes to find matches for numerical ranges, and wildcards.
*
* @since 2.6.0
* @param string $postcode Postcode you want to match against stored postcodes.
* @param array $objects Array of postcode objects from Database.
* @param string $object_id_key DB column name for the ID.
@igorbenic
igorbenic / remove-terms.php
Created Mar 12, 2020
Simple Sponsorships - Code Snippets
View remove-terms.php
<?php
/**
* Remove Terms and Conditions Field
*/
add_filter( 'ss_form_sponsors_fields', 'ss_remove_terms_and_conditions' );
/**
* Filtering out the terms and conditions field
@igorbenic
igorbenic / disable-theme-comments.php
Last active May 14, 2020
Simple Feature Requests & GeneratePress snippets
View disable-theme-comments.php
<?php
add_action( 'jck_sfr_after_single_loop', 'jck_disable_theme_comments');
/**
* Disable the default theme comments form by disabling comments after the plugin comments form is rendered.
*/
function jck_disable_theme_comments() {
add_filter( 'comments_open', function( $open, $post_id ) {
if ( 'cpt_feature_requests' === get_post_type( $post_id ) ) {
@igorbenic
igorbenic / elementor-widget.php
Last active May 3, 2020
Ultimate Guide for JavaScript in Elementor Widgets
View elementor-widget.php
<?php
/**
* Plugin Name: Elementor Widget
* Text Domain: elementor-widget
* Domain Path: /languages
* Version: 0.1.0
*
* @package Elementor_Widget
*/
@igorbenic
igorbenic / App-1.js
Last active Jan 24, 2020
Headless WordPress: Displaying single articles | https://ibenic.com/headless-wordpress-displaying-articles
View App-1.js
function App() {
const [loading, setLoading] = useState(false);
const [articles, setArticles] = useState([]);
const [notFoundSlugs, setNotFoundSlugs] = useState([]); // Adding not found slugs
// ... other code
}
View App-1.js
// Adding the React Router
import React, { useState, useEffect } from 'react';
import './App.scss';
import {
BrowserRouter as Router,
Switch,
Route,
Link,
useParams
} from "react-router-dom";
You can’t perform that action at this time.