Passing arguments into ‘init’ function

The one thing you are missing is the use of use (http://php.net/manual/en/functions.anonymous.php example #3) You code will look something like //define post type name $pt_name=”post”; //remove default wysiwyg editor add_action(‘init’, function() use ($pt_name) { $post_type = $pt_name; remove_post_type_support( $post_type, ‘editor’); }, 100); This will let PHP know what is the currect scope to use when … Read more

add_action customize_register not working

You always need to be sure that three things are defined (section, setting and control). If you are adding a control to an already defined section, i.e. title_tagline, then you don’t need to re-register it, but always define the setting and the control. //adding setting for copyright text add_action(‘customize_register’, ‘theme_copyright_customizer’); function theme_copyright_customizer($wp_customize) { //adding section … Read more

Why, Where, and When to use reference pointers in filters/hooks?

The example you give is used when you’re building a plugin/theme using a class. In normal use, your functions.php file would just have: function my_function_to_filter( $args ) { // … function stuff here return $args; } add_filter(‘some_wp_filter’, ‘my_function_to_filter’); If you’re using a class, though, things would look different. You’d likely have a my-class.php file containing: … Read more

When and Where to use wp_insert_post()

Use some type of conditional tag to check if those posts exist or not. If they do not exist, have them created with wp_insert_post. Do this logic inside the AddMyPages function and not around the add_action function. Example You want to add a page with a parent ID only if it does not exist, and … Read more

How can I remove the WP menu from the admin bar?

This menu is added in WP_Admin_Bar::add_menus() with an action: add_action( ‘admin_bar_menu’, ‘wp_admin_bar_wp_menu’, 10 ); To remove it take the same action – just one step later. The following code works as a mu plugin or as a regular plugin: <?php # -*- coding: utf-8 -*- /** * Plugin Name: Remove WP Menu From Tool Bar … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)