Skip to content

Instantly share code, notes, and snippets.

View renventura's full-sized avatar

Ren Ventura renventura

View GitHub Profile
@renventura
renventura / remove-parent-link-from-submenu.php
Created April 3, 2020 14:22
This removes a parent menu link from its submenu in the WordPress admin.
@renventura
renventura / js-usd-format.js
Created April 26, 2024 11:23
Javascript code to format a number to USD currency
const formatUSD = (value) => {
return new Intl.NumberFormat(
'en-US',
{
style: 'currency',
currency: 'USD'
}
).format(value);
}
@renventura
renventura / woocommerce-settings-page.php
Created December 26, 2017 02:52
Implement a custom WooCommerce settings page, including page sections
<?php
/**
* WooCommerce settings page
*
* This code creates a full WooCommerce settings page by extending the WC_Settings_Page class.
* By extending the WC_Settings_Page class, we can control every part of the settings page.
*
* @author Ren Ventura <renventura.com>
*/
@renventura
renventura / manually-call-wp_maybe_auto_update.php
Created March 6, 2024 15:13
Avoid deactivated plugins when manually calling wp_maybe_auto_update() function
<?php
/**
* Manually calling wp_maybe_auto_update() results in plugins getting deactivated during the update process.
* WP assumes this function is run during cron, and it neither deactivates nor reactivates plugins during cron.
* When run outside of cron, it will deactivate plugins, but it assumes the browser will refresh and reactivate them.
* To prevent deactivated plugins when calling this function, we can trick the upgrader into thinking it's called during cron.
*
* @link https://stackoverflow.com/questions/41541968/plugins-are-getting-deactivated-after-automatic-plugin-update-in-wordpress
*/
@renventura
renventura / memberpress-custom-field-dynamic-tag.php
Created December 26, 2019 15:00
Creates a dynamic tag for using in MemberPress custom fields.
<?php
add_filter( 'mepr_fetch_options', 'mp_filter_custom_fields' );
/**
* Filter the MemberPress options to set a dynamic value for custom fields.
*
* @param object $options MeprOptions
*
* @return object MeprOptions
*/
@renventura
renventura / remove-logout-link-wp-comment-form.php
Created August 26, 2016 03:35
Remove the "Logged in as {username}. Log Out?" link from the WordPress comment form.
@renventura
renventura / wpforms-programmatically-create-entry.php
Created May 3, 2020 15:50
Snippet for programmatically creating entries in WPForms.
<?php
// Create entry.
$entry_id = wpforms()->entry->add( array(
'form_id' => absint( $form_id ),
'user_id' => absint( $user_id ),
'fields' => wp_json_encode( $fields ),
'ip_address' => sanitize_text_field( $user_ip ),
'user_agent' => sanitize_text_field( $user_agent ),
'date' => $date,
@renventura
renventura / wp-fa-menu-anchor-icons.php
Last active December 8, 2022 16:50
Add Font Awesome icons to WordPress menu anchor text
<?php //* Mind this opening PHP tag
/**
* Append Font Awesome icons to menu-item anchor text
* Requires the "fa" and "fa-{icon_key}" classes to be added to the menu item
*
* @author Ren Ventura <EngageWP.com>
* @link http://www.engagewp.com/add-font-awesome-icons-to-wordpress-menu-anchor-text/
*
* @param $item Menu-item object
@renventura
renventura / remove-divi-project-post-type.php
Last active November 27, 2022 02:07
Remove the Projects Post Type from Divi by Elegant Themes
<?php //* Mind this opening php tag
/**
* This will hide the Divi "Project" post type.
* Thanks to georgiee (https://gist.github.com/EngageWP/062edef103469b1177bc#gistcomment-1801080) for his improved solution.
*/
add_filter( 'et_project_posttype_args', 'mytheme_et_project_posttype_args', 10, 1 );
function mytheme_et_project_posttype_args( $args ) {
return array_merge( $args, array(
'public' => false,
@renventura
renventura / list-hooked-functions.php
Last active November 6, 2022 18:23
List All Currently Hooked WordPress Functions
<?php //* mind this opening php tag
/**
* This snippet returns a list of all currently hooked functions.
* It is set up to output this data on a specific page. Do not output this data publicly.
* Use this snippet for debugging/testing/development.
* Source: http://www.rarst.net/wordpress/debug-wordpress-hooks/
* Modified by Ren Ventura, EngageWP.com
**/