Skip to content

Instantly share code, notes, and snippets.

@smartdeal
smartdeal / wp_cf7_form_change_pwd.php
Created May 25, 2018 17:18
[Wordpress custom form for change password] #WP #CF7
<?php
add_action("wpcf7_before_send_mail", "zz_wpcf7_change_pwd");
function zz_wpcf7_change_pwd($WPCF7_ContactForm) {
$wpcf7 = WPCF7_ContactForm::get_current();
if (3496 == $WPCF7_ContactForm->id()) {
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$data = $submission->get_posted_data();
@smartdeal
smartdeal / wp_cf7_skip_mail.php
Created May 25, 2018 09:16
[CF7 skip mail] #WP #CF7
<?php
add_filter('wpcf7_skip_mail', '__return_true');
@smartdeal
smartdeal / remove_default_image_sizes.php
Created May 13, 2018 16:06
[Remove default image sizes] #WP #WP_functions
/wp-admin/options.php
medium_large_size_w
function dco_remove_default_image_sizes( $sizes) {
return array_diff( $sizes, array(
'thumbnail',
'medium',
'medium_large',
'large',
@smartdeal
smartdeal / wp_enqueue_versioned_style.php
Created May 13, 2018 15:22
[Enqueues stylesheet with WordPress] #WP #WP_functions
/**
* Enqueues script with WordPress and adds version number that is a timestamp of the file modified date.
*
* @param string $handle Name of the script. Should be unique.
* @param string|bool $src Path to the script from the theme directory of WordPress. Example: '/js/myscript.js'.
* @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
* @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
* Default 'false'.
*/
function enqueue_versioned_script( $handle, $src = false, $deps = array(), $in_footer = false ) {
@smartdeal
smartdeal / remove_admin_color_scheme_picker.php
Last active May 9, 2018 12:24
[Remove admin color scheme picker] #Wordpress #WP_Admin
<?php
remove_action("admin_color_scheme_picker", "admin_color_scheme_picker");
@smartdeal
smartdeal / Wordpress_Menu_add_item.php
Last active May 8, 2018 15:53
[Add Custom Items to Specific WordPress Menus] #Wordpress #WP_Menu
<?php
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
}
@smartdeal
smartdeal / Remove_Dashboard_Access.php
Created May 8, 2018 14:56
[Remove Dashboard Access] #Wordpress
<?php
add_action('admin_init', 'no_mo_dashboard');
function no_mo_dashboard() {
if (!current_user_can('manage_options') && $_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php') {
wp_redirect(home_url()); exit;
}
}
?>
@smartdeal
smartdeal / lptracker-bicycle.php
Last active May 8, 2018 14:59
[LPtracker SDK my bicycle] #LPtracker
<?php
function ee($s) {
echo '<pre>';
print_r($s);
echo '</pre>';
}
function vd($s) {
echo '<pre>';
var_dump($s);
@smartdeal
smartdeal / wp_nav_menu_remove_current_link.php
Created February 17, 2018 12:49
[Remove currenk link from menu] #Wordpress
@smartdeal
smartdeal / debug2.php
Last active May 8, 2018 15:53
[Wordpress debug function] #Wordpress #WP_Debug
function (f_debug) {
if (is_admin()) {
define('WP_DEBUG', true )
} else {
define('WP_DEBUG', false )
}
}
add_action(init,f_debug);