Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / example_false.php
Last active April 19, 2024 13:40
Handle WordPress Remote Requests with OOP | ibenic.com
<?php
$remote_request = new WordPressRemoteJSON( 'https://leanpub.com/wpb3/coupons.json', array( 'body' => array("coupon_code" => "coupon-code-123456" ) ), "post" );
$remote_request->run(); //False
@igorbenic
igorbenic / elementor-widget.php
Last active April 11, 2024 09:12
Ultimate Guide for JavaScript in Elementor Widgets
<?php
/**
* Plugin Name: Elementor Widget
* Text Domain: elementor-widget
* Domain Path: /languages
* Version: 0.1.0
*
* @package Elementor_Widget
*/
@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 / acf.js
Created June 3, 2022 15:19
ACF Repeater Fields - Filter by Price
(function($){
$(function(){
$(document.body).on( 'change', '#min_price, #max_price', function(){
var minPrice = parseFloat( $('#min_price').val() );
var maxPrice = parseFloat( $('#max_price').val() );
$('.item-list li').each(function(){
var price = parseFloat( $(this).attr('data-price') );
@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 / App-1.js
Last active April 11, 2024 09:05
Headless WordPress: Displaying single articles | https://ibenic.com/headless-wordpress-displaying-articles
function App() {
const [loading, setLoading] = useState(false);
const [articles, setArticles] = useState([]);
const [notFoundSlugs, setNotFoundSlugs] = useState([]); // Adding not found slugs
// ... other code
}
@igorbenic
igorbenic / App-1.js
Last active April 11, 2024 09:05
Headless WordPress: React Router Pagination | https://ibenic.com/headless-wordpress-react-router-pagination
// 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";
@igorbenic
igorbenic / live.php
Created November 23, 2022 22:17
A simple shortcode to display results from World Cup 2022 using api-football.com APIs
<?php
/**
* Plugin Name: Live API
*/
add_action( 'init', function(){
add_shortcode( 'live_api', 'live_api_shortcode' );
});
function live_api_shortcode() {
@igorbenic
igorbenic / add_metabox.php
Last active February 21, 2024 21:36
How to use the WordPress Code Editor in your Plugins or Themes | https://www.ibenic.com/wordpress-code-editor
<?php
add_action( 'add_meta_boxes', 'add_page_scripts' );
/**
* Register the metabox
*/
function add_page_scripts() {
add_meta_box( 'page-scripts', __( 'Page Scripts & Styles', 'textdomain' ), 'add_page_metabox_scripts_html', 'page', 'advanced' );
}
@igorbenic
igorbenic / api.php
Last active February 21, 2024 21:36
How to use PHP Namespaces in WordPress Plugins | https://www.ibenic.com/php-namespaces-wordpress-plugins
<?php
namespace My_Plugin\API;
/**
* API Functions
*/
if( ! defined( 'ABSPATH' ) ) {
return;
}