Skip to content

Instantly share code, notes, and snippets.

@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;
}
@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 / 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 / checkout-form-final.php
Last active February 21, 2024 21:34
How to Customize WooCommerce Checkout Pages like a Hero | https://www.ibenic.com/customize-woocommerce-checkout-pages
<?php
/**
* Checkout Form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@igorbenic
igorbenic / clauses.php
Last active February 21, 2024 21:34
Extending WP_Query with Custom Queries and Tables | https://www.ibenic.com/extending-wp-query-custom-queries-tables
<?php
add_filter( 'posts_clauses', 'filter_clauses', 10, 2 );
/**
* Filtering everything.
*
* @param array $clauses Array with all parts of the query.
* @param WP_Query $wp_query Object.
* @return string
@igorbenic
igorbenic / cron.php
Last active February 21, 2024 21:34
Automation on Post Publish | https://www.ibenic.com/automation-post-publish
<?php
add_action( 'publish_future_post', 'automation_on_publish', 20, 1 );
/**
* Create automate tasks on post publish.
*
* @param integer $post_id Post ID that is published.
*/
function automation_on_publish( $post_id ) {
@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;
}
@igorbenic
igorbenic / app-1.js
Last active February 21, 2024 21:34
Using React to Render Content from WP REST API | https://ibenic.com/react-render-content-wp-rest-api
class App extends React.Component {
render() {
return (
bla
)
}
}
const element = <App />
@igorbenic
igorbenic / add.php
Last active February 21, 2024 21:34
How to Hook in WordPress Metadata | http://www.ibenic.com/hook-wordpress-metadata
<?php
// Should this data be added?
apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
// Do something before we add the data
do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value );
// Do Something after the data has been added
do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );