This file contains 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 | |
echo 'Returning a specific post ID from a url: '.url_to_postid( 'https://smartwp.com/my-page-url' ); |
This file contains 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 | |
$post_details = get_page_by_title( 'My Post Title', '', 'post' ); | |
echo $post_details->ID; | |
$page_details = get_page_by_title( 'My Page Title', '', 'page' ); | |
echo $page_details->ID; |
This file contains 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 | |
$user_data = get_user_by('login', 'someguy'); | |
echo 'The user ID is '.$user_data->ID; |
This file contains 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 | |
$current_user = wp_get_current_user(); | |
echo 'Username: '.$current_user->user_login; | |
echo 'User ID: '.$current_user->ID; | |
echo 'User Email: '.$current_user->user_email; | |
echo 'User First Name: '.$current_user->user_firstname; | |
echo 'User Last Name: '.$current_user->user_lastname; | |
echo 'User Display Name: '.$current_user->display_name; |
This file contains 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 | |
@ini_set( 'upload_max_size' , '128M' ); | |
@ini_set( 'post_max_size', '128M'); | |
@ini_set( 'max_execution_time', '300' ); |
This file contains 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
//URLBOX | |
function urlbox_url_generate($url, $options){ | |
$options['url'] = $url; | |
$options['url'] = preg_replace("(^https?://)", "", $options['url'] ); | |
$format = isset($options['format']) ? $options['format'] : 'png'; | |
unset($options['format']); | |
$_parts = []; | |
foreach ($options as $key => $values) { | |
$values = is_array($values) ? $values : [$values]; | |
foreach ($values as $value) { |
This file contains 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 | |
//Record user's last login to custom meta | |
add_action( 'wp_login', 'smartwp_capture_login_time', 10, 2 ); | |
function smartwp_capture_login_time( $user_login, $user ) { | |
update_user_meta( $user->ID, 'last_login', time() ); | |
} | |
//Register new custom column with last login time | |
add_filter( 'manage_users_columns', 'smartwp_user_last_login_column' ); |
This file contains 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 smartwp_defer_js_parsing( $url ){ | |
if(is_admin()) return $url; //Skip admin JS files | |
if(is_user_logged_in()) return $url; //Skip if user is logged in | |
if(false === strpos($url, '.js')) return $url; //If it's not a JS file skip | |
if(strpos($url, 'jquery.js')) return $url; //Don't defer jQuery | |
return str_replace(' src', ' defer src', $url); //defer JS file | |
} | |
add_filter( 'script_loader_tag', 'smartwp_defer_js_parsing', 10 ); |
This file contains 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 wp_smartwp_scripts_method() { | |
wp_enqueue_script( 'my-custom-script', get_stylesheet_directory_uri() . '/js/your_custom_script.js', array( 'jquery' ), true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'wp_smartwp_scripts_method' ); |
This file contains 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 | |
//Disable automatic "Your Site Has Been Updated..." emails | |
add_filter( 'auto_core_update_send_email', 'smartwp_disable_core_update_emails', 10, 4 ); | |
function smartwp_disable_core_update_emails( $send, $type, $core_update, $result ) { | |
if ( !empty($type) && $type == 'success' ) { | |
return false; | |
} | |
return true; | |
} |