Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / add_theme.php
Last active April 27, 2017 11:09
5 Ways to Make your Plugin Really Extensible | http://ibenic.com/5-ways-make-plugin-extensible
<?php
add_theme_support( 'my-plugin-style' );
<?php
$args = array(
'label' => '', // Text in Label
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post meta where id is the meta_key
'id' => '', // required
'name' => '', //name will set from id if empty
@igorbenic
igorbenic / class.php
Last active July 31, 2017 14:30
How to Create Featured Downloads for Easy Digital Downloads | http://www.ibenic.com/create-featured-downloads-for-edd
<?php
/**
* Adding the Featured Class
* @param array $classes
* @return array
*/
function ibenic_edd_featured_class( $classes ) {
global $post;
@igorbenic
igorbenic / refund_order.php
Last active November 5, 2021 00:32
How to Create WooCommerce Refunds Programmatically | ibenic.com/how-to-create-woocommerce-refunds-programmatically
<?php
/**
* Process Order Refund through Code
* @return WC_Order_Refund|WP_Error
*/
function ibenic_wc_refund_order( $order_id, $refund_reason = '' ) {
$order = wc_get_order( $order_id );
// IF it's something else such as a WC_Order_Refund, we don't want that.
@igorbenic
igorbenic / desc.php
Last active April 16, 2026 13:48
How to Programmatically Change Yoast SEO Open Graph Meta | http://www.ibenic.com/programmatically-change-yoast-seo-open-graph-meta
<?php
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_opengraph_desc', 'change_desc' );
}
function change_desc( $desc ) {
// This article is actually a landing page for an eBook
if( is_singular( 123 ) ) {
<?php
add_filter( 'edd_add_to_cart_item', 'dp_check_item_to_add' );
/**
* Check the item we want to add in cart (Step #7)
* @param array $item
* @return array|boolean
*/
function dp_check_item_to_add( $item ) {
<?php
//... Somewhere in a class that works with hooks
// Get the global Renderer
global $edd_points_render;
// Remove the Old Renderer Methods
remove_action( 'edd_before_purchase_form', array( $edd_points_render,'edd_points_guest_user_message' ) );
remove_action( 'edd_before_download_content', array( $edd_points_render,'edd_points_message_content' ) );
@igorbenic
igorbenic / function.php
Last active August 21, 2017 15:31
Using the WordPress Shortcode to Restrict the Content | http://www.ibenic.com/using-wordpress-shortcode-restrict-content
<?php
/**
* Function to decide if the user can view the content
* @return boolean
*/
function ibenic_can_user_view() {
$ret = false;
@igorbenic
igorbenic / admin_tab.php
Last active August 21, 2017 15:27
Display Members in BuddyPress by Roles
<?php
/**
* Add the Presenters tab to the Members Directory
* @return void
*/
function bp_my_administrators_tab() {
$button_args = array(
@igorbenic
igorbenic / regex.php
Last active August 21, 2017 15:27
How to Optimize the Divi Gallery Module | http://www.ibenic.com/optimize-divi-gallery-module
<?php
/**
* Replacing the original image source with a placeholder
* Placing the original source under attribute data-original
* @param array $img_match
* @return string
*/
function my_preg_lazyload($img_match) {