Skip to content

Instantly share code, notes, and snippets.

View matthijs166's full-sized avatar

Matthijs Knigge matthijs166

View GitHub Profile
@matthijs166
matthijs166 / Sanitizes string
Created January 6, 2018 20:38
Sanitizes a string from user input or from the database.
sanitize_text_field( string $str )
@matthijs166
matthijs166 / add style to wigiy editor
Created January 5, 2018 21:44
add font and style to wigiy editor
//add font to wigiy editor
add_editor_style( '/css/editor.css' );
add_filter( 'tiny_mce_before_init', 'wpex_mce_google_fonts_array' );
function wpex_mce_google_fonts_array( $initArray ) {
$theme_advanced_fonts = 'futura=futura;';
$theme_advanced_fonts .= 'futura_b=futura_b;';
$theme_advanced_fonts .= 'avenir_Bold=avenir_b;';
$theme_advanced_fonts .= 'avenir_Regular=avenir_r';
$initArray['font_formats'] = $theme_advanced_fonts;
return $initArray;
@matthijs166
matthijs166 / run wp cron job
Created January 4, 2018 18:11
run a wordpress cron job exicute do cron job
wp_schedule_single_event( time() - 1, 'mailchimp_user_sync_run' );
spawn_cron();
@matthijs166
matthijs166 / scroll lock
Created January 2, 2018 18:27
disable and enable scroll lock scroll enz
// scroll tools
var keys = {37: 1, 38: 1, 39: 1, 40: 1};
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
}
function preventDefaultForScrollKeys(e) {
if (keys[e.keyCode]) {
@matthijs166
matthijs166 / selelct template
Created December 28, 2017 16:37
Select custom template woocommerce
add_filter( 'template_include', 'so_25789472_template_include' );
function so_25789472_template_include( $template ) {
if ( is_singular('product') && (has_term( 'mock', 'product_cat')) ) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-mock.php';
}
return $template;
}
@matthijs166
matthijs166 / regsiter post type
Last active December 28, 2017 12:31
create post types regsiter multiple post types
function codex_custom_init() {
register_post_type(
'testimonials', array(
'labels' => array('name' => __( 'Books' ), 'singular_name' => __( 'Book' ) ),
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-cart',
'supports' => array('title', 'editor', 'thumbnail')
)
@matthijs166
matthijs166 / add wp admin menu
Created December 22, 2017 10:36
wordpress admin page add of custom menu item in wp admin
//tournament setting page
function brackets_settings_page(){
echo "<h1>Bracket Admin Pannle</h1>";
}
function add_theme_menu_item(){
add_menu_page("Brackets", "Brackets", "manage_options", "theme-panel", "brackets_settings_page", null, 99);
}
add_action("admin_menu", "add_theme_menu_item");
@matthijs166
matthijs166 / get menu items by slug
Created December 21, 2017 12:31
Wordpress get all nav items and sub nav item by registerd slug in the code uing register_nav_menu
//get menu items by code registerd slug
function get_menu_items_by_registered_slug($menu_slug) {
$menu_items = array();
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_slug ] ) ) {
$menu = get_term( $locations[ $menu_slug ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
}
return $menu_items;
}
//enable catogries and tags for pages
function myplugin_settings() {
// Add tag metabox to page
register_taxonomy_for_object_type('post_tag', 'page');
// Add category metabox to page
register_taxonomy_for_object_type('category', 'page');
}
// Add to the admin_init hook of your theme functions.php file
add_action( 'init', 'myplugin_settings' );
@matthijs166
matthijs166 / send wocommerce emal
Created December 2, 2017 16:39
resend or send wocommerce emal
$wc_emails = WC()->mailer()->get_emails();
foreach ( $wc_emails as $wc_mail )
if ( $wc_mail->id == "wc_notifi_live" )
$wc_mail->trigger( 1191 );