Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / abstract.php
Last active February 21, 2024 21:32
How to add custom WordPress Profile Fields
<?php
abstract class WordPressSettings {
/**
* ID of the settings
* @var string
*/
public $settings_id = '';
/**
* Tabs for the settings page
@igorbenic
igorbenic / code.php
Last active February 21, 2024 21:32
How to create WordPress Metaboxes with OOP
<?php
class IBenic_WordPress_Metabox extends WordPressSettings {
protected $title = '';
protected $slug = '';
protected $post_types = array();
<?php
add_filter( 'template_include', 'ibenic_checkout_template', 99 );
function ibenic_checkout_template( $template ) {
if ( is_page( 'checkout' ) ) {
$new_template = locate_template( array( 'checkout.php' ) );
if ( '' != $new_template ) {
return $new_template ;
@igorbenic
igorbenic / book_admin_enqueue.php
Last active February 21, 2024 21:34
Better WordPress Performance by Controlling Scripts | http://www.ibenic.com/better-wordpress-performance/
<?php
add_action( 'admin_enqueue_scripts', 'books_enqueue_scripts' );
function books_enqueue_scripts( $hook ){
$hook_scripts = false;
if( $hook_suffix == "post-new.php" && isset( $_GET["post_type"] ) && $_GET["post_type"] == "books" ){
$hook_scripts = true;
}
<?php
function ibenic_get_all_zones() {
if( class_exists( 'WC_Shipping_Zones' ) ) {
$all_zones = WC_Shipping_Zones::get_zones();
return $all_zones;
}
return false;
}
@igorbenic
igorbenic / cpt.php
Last active February 11, 2023 21:53
Simple WordPress Advertising Plugin: Introduction | http://www.ibenic.com/simple-wordpress-advertising-plugin-introduction
<?php
// ...
public function load_dependencies(){
/**
* Base functions
*/
<?php
array(
// Storing ads for top position
'top' => array(
0 => array(
//Ads parameters
)
),
<?php
//swa-functions.php
/**
* Click Ad registration
* @return void
*/
function swa_ad_click() {
$id = 0;
@igorbenic
igorbenic / include.php
Last active July 22, 2016 06:48
Simple WordPress Advertising Plugin: Widget and Shortcode | http://www.ibenic.com/simple-wordpress-advertising-plugin-widget-and-shortcode
<?pbp
class Simple_WP_Ads {
// ...
public function load_dependencies(){
// ...
require_once SWA_ROOT .'inc/swa-statuses.php';
@igorbenic
igorbenic / gateway.php
Last active February 21, 2024 21:32
How to create a custom WooCommerce Payment Gateway
<?php
// ...
function woo_payment_gateway() {
class Woo_PayPal_Gateway extends WC_Payment_Gateway {
}
}