Skip to content

Instantly share code, notes, and snippets.

View tripflex's full-sized avatar
🦋
in the zone

Myles tripflex

🦋
in the zone
View GitHub Profile
@tripflex
tripflex / functions.php
Last active May 27, 2025 14:35
Programmatically create a WooCommerce Subscription and associated WooCommerce Order
<?php
public function give_user_subscription( $product, $user_id, $note = '' ){
// First make sure all required functions and classes exist
if( ! function_exists( 'wc_create_order' ) || ! function_exists( 'wcs_create_subscription' ) || ! class_exists( 'WC_Subscriptions_Product' ) ){
return false;
}
$order = wc_create_order( array( 'customer_id' => $user_id ) );
@tripflex
tripflex / functions.php
Last active April 29, 2025 14:57
How to add additional email addresses when email is sent to WordPress admin_email option value
<?php
/**
*
* WARNING: this only checks if the email is being sent to the same email as admin_email option.
* If for some reason another email is sent to that same email address, but it's not meant as an "admin email"
* this filter will still add those additional emails, just something to keep in mind.
*/
add_filter( 'wp_mail', 'my_custom_to_admin_emails' );
@tripflex
tripflex / functions.php
Last active March 19, 2025 11:59
WordPress Remove Filter (remove_filter converted to remove_class_filter) to remove Filter/Action without Class Object access. Works with WordPress 1.2+ (4.7+ support added 9-19-2016)
<?php
/**
* Make sure the function does not exist before defining it
*/
if( ! function_exists( 'remove_class_filter' ) ){
/**
* Remove Class Filter Without Access to Class Object
*
* In order to use the core WordPress remove_filter() on a filter added with the callback
@tripflex
tripflex / functions.php
Last active January 31, 2025 22:39
Change default Company Logo in WP Job Manager
<?php
// ^ there should only be one of these at the top of your child theme's functions.php file
add_filter( 'job_manager_default_company_logo', 'smyles_custom_job_manager_logo' );
function smyles_custom_job_manager_logo( $logo_url ){
// Change the value below to match the filename of the custom logo you want to use
// Place the file in a /images/ directory in your child theme's root directory.
// The example provided assumes "/images/custom_logo.png" exists in your child theme
@tripflex
tripflex / functions.php
Created January 31, 2025 20:47
Prevent WP Job Manager Resumes from Translating the resume slug in the URL
<?php
add_filter('register_post_type_resume', 'modify_resume_rewrite_slug', 99, 1);
function modify_resume_rewrite_slug($args) {
// don't translate the value
$args['rewrite']['slug'] = 'resume';
return $args;
}
@tripflex
tripflex / functions.php
Last active January 26, 2025 09:22
How to remove default company fields from WP Job Manager (this example for Listify)
<?php
// Add your own function to filter the fields
add_filter( 'submit_job_form_fields', 'remove_listify_submit_job_form_fields', 9999999999 );
// This is your function which takes the fields, modifies them, and returns them
// You can see the fields which can be changed here: https://github.com/mikejolley/WP-Job-Manager/blob/master/includes/forms/class-wp-job-manager-form-submit-job.php
function remove_listify_submit_job_form_fields( $fields ) {
if( ! isset( $fields['company'] ) ) return $fields;
@tripflex
tripflex / functions.php
Created January 9, 2025 22:28
Make sure job_location translation is handled correctly (as core WPJM pulls directly from database)
<?php
add_filter( 'the_job_location', 'smyles_the_job_location_translatable', 99, 2 );
function smyles_the_job_location_translatable( $job_location, $post ){
// We don't want to override the auto generated geolocation address information
if ( get_option( 'job_manager_display_location_address' ) === '1' ) {
return $job_location;
}
return get_job_field('job_location', $post->ID );
@tripflex
tripflex / functions.php
Last active December 3, 2024 16:13
Customize WP Job Manager wp_editor arguments
<?php
add_filter( 'submit_job_form_wp_editor_args', 'smyles_submit_job_form_wp_editor_args' );
function smyles_submit_job_form_wp_editor_args( $args ){
// @see https://github.com/Automattic/WP-Job-Manager/blob/master/templates/form-fields/wp-editor-field.php#L2
// change quicktags to true
$args['quicktags'] = true;
// change rows to 10 (default is 8)
@tripflex
tripflex / functions.php
Created November 26, 2024 23:13
Job URL apply type custom URL for not logged in users (when using WP Job Manager Packages 1.3.5+)
<?php
add_filter( 'job_manager_packages_job_application_url_type_packages_permalink_not_logged_in', function( $url ) {
return 'https://domain.com/please-register'; // Replace with your desired URL
});
@tripflex
tripflex / functions.php
Created November 26, 2024 21:23
[candidate_photo] shortcode to output candidate photo (as thumbnail, etc)
<?php
function display_candidate_photo_shortcode($atts) {
// Check if the function exists before calling it
if (function_exists('the_candidate_photo')) {
ob_start();
// Options are full, thumbnail, medium, large
the_candidate_photo( 'thumbnail' );
return ob_get_clean();
} else {
return 'Candidate photo function not available.';