This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Usage: Put in functions.php. Load site once. Remove code. Now login to admin | |
| // Change ID based on relevant user & put a more secure password! | |
| wp_update_user(array( | |
| 'ID' => 1, | |
| 'user_pass' =>'admin' | |
| )); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // In this example if trying to access /work/ it'll 302 redirect to the most recent post instead | |
| add_action('template_redirect','redirect_to_latest'); | |
| function redirect_to_latest() { | |
| if( is_post_type_archive('work') ) { | |
| $latest = get_posts( 'post_type=work&posts_per_page=1' ); | |
| if($latest) { | |
| wp_redirect( get_permalink( $latest[0]->ID ) ); | |
| exit; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Should almost be core, every client that embeds a YouTube video has always asked for them to be removed! | |
| function remove_youtube_controls($code){ | |
| if(strpos($code, 'youtu.be') !== false || strpos($code, 'youtube.com') !== false){ | |
| $return = preg_replace("@src=(['\"])?([^'\">\s]*)@", "src=$1$2&showinfo=0&rel=0", $code); | |
| return $return; | |
| } | |
| return $code; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Sometimes due to the design you get stuck putting the <h1> in header.php | |
| // This is a basic function I expand to output the relevant heading | |
| function page_heading() { | |
| if( is_page() ) { | |
| the_title(); | |
| } elseif( is_home() || is_single() || is_archive() ) { | |
| echo 'News'; | |
| } elseif( is_search() ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action( 'gform_user_registered', 'login_new_user', 10, 4 ); | |
| function login_new_user( $user_id, $config, $entry, $user_pass ) { | |
| wp_set_current_user( $user_id, $user_login ); | |
| wp_set_auth_cookie( $user_id ); | |
| do_action( 'wp_login', $user_login ); | |
| //do_action( 'tml_new_user_registered', $user_id, $user_pass ); IF USING THEME MY LOGIN, ELSE DELETE | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Usage: Put in functions.php. Load /wp-login.php once. Remove code. Can now login | |
| // Disable the admin notifications | |
| if ( ! function_exists( 'wp_new_user_notification' ) ) : | |
| function wp_new_user_notification( $user_id, $plaintext_pass = '' ) { | |
| return; | |
| } | |
| endif; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Perfect for testing. Setup "Cheque" as an option, put your user ID in below, now only you can do full checkouts without needing CC or paypal | |
| add_filter( 'woocommerce_available_payment_gateways', 'mr_filter_gateways' ); | |
| function mr_filter_gateways( $gateways ){ | |
| $current_user = wp_get_current_user(); | |
| if( 123 != $current_user->ID) { | |
| unset( $args['cheque'] ); | |
| } | |
| return $args; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Assuming you already have the user meta setup | |
| // In this example we unset Bank Transfer if the user doesn't have "pay via account" meta set to true | |
| add_filter( 'woocommerce_available_payment_gateways', 'mr_filter_gateways'); | |
| function mr_filter_gateways( $available_gateways ){ | |
| $pay_via_account = ( is_user_logged_in() ) ? get_user_meta( get_current_user_id(), '_pay_via_account', true ) : false; | |
| if( 1 != $pay_via_account ) { | |
| unset( $available_gateways['bacs'] ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function get_youtube_id($url) { | |
| preg_match('#(?<=(?:v|i)=)[a-zA-Z0-9-]+(?=&)|(?<=(?:v|i)\/)[^&\n]+|(?<=embed\/)[^"&\n]+|(?<=(?:v|i)=)[^&\n]+|(?<=youtu.be\/)[^&\n]+#',$url,$matches); | |
| $id = $matches[0]; | |
| $id = str_replace('?rel=0','',$id); | |
| if($id) return $id; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Sort items of all internal arrays by key | |
| function ksortRecursive($array) { | |
| foreach ($array as $key => $nestedArray) { | |
| if (is_array($nestedArray) && !empty($nestedArray)) { | |
| $array[$key] = ksortRecursive($nestedArray); | |
| } | |
| } | |
| ksort($array); |