Include Class File in WordPress

Please clarify where you initiate the object $user in both ways (function.php and header.php). This is another thread on stack with similar kind of issue, have a look: Organizing Code in your WordPress Theme’s functions.php File? Thanks, Vee

Click loads template via ajax

So, you’re using wp_localize_script to inject the ajax url. But you didn’t use the localized var handle to access that value. Try this: /* … */ $.ajax({ url: ajaxStuff.ajaxurl, // NOTE use of ‘ajaxStuff’ object /* … */

How to display custom field on homepage

Try this: if ( ! function_exists( ‘customField’ ) ) : function customField($name, $id=false, $single=false){ global $post_type, $post; $name=trim($name); $prefix=”; // only if you need this $data=NULL; if($id!==false && !empty($id) && $id > 0) $getMeta=get_post_meta((int)$id, $prefix.$name, $single); else if(isset($post->ID) && $post->ID > 0) $getMeta=get_post_meta($post->ID,$prefix.$name, $single); else if(‘page’ == get_option( ‘show_on_front’ )) $getMeta=get_post_meta(get_option( ‘page_for_posts’ ),$prefix.$name, $single); else … Read more

Creating new menu item

Following code snippet replaces placeholder menu item from ‘your-menu’ menu. add_filter( ‘wp_nav_menu_items’, ‘add_item_to_menu’, 10, 2 ); function add_item_to_menu( $items, $args ) { if ( $args->theme_location == ‘your-menu’ ) { $link_text = “My Replaced Link Text”; $link_url = “my-replaced-link-url.com”; $items = str_replace( ‘lang_placeholder_text’, $link_text, $items); $items = str_replace( ‘lang_placeholder_url’, $link_url, $items); } return $items; }

Getting my head round WordPress filter

You are using the filter wrongly, that is why you might not get the desired result. Lets first look at the template_include filter which you can check out in wp-includes/template-loader.php (current version 4.3.1) 44 if ( defined(‘WP_USE_THEMES’) && WP_USE_THEMES ) : 45 $template = false; 46 if ( is_404() && $template = get_404_template() ) : … Read more

Notify WordPress Site I Have Linked To Them

The term you need to search for is “Pingbacks” (and maybe “Trackbacks”, but the former is better as it is less vulnerable to spam abuse). It is an XML-RPC request. You can find the specification here. Looking at github there seem to be some bare metal PHP implementations, but as I haven’t used any of … Read more

How to slow down server response

I don´t know why you would want to slow your website down, but PHP got sleep() which pauses a program for the amount of seconds you pass to it. You could then hook your function/plugin to init to halt your WordPress before it starts its output. That could probably do what you want. But why?

Issue with foreach on duplicate meta_key’s

Here is an example of getting the user IDs, looping through each, grabbing a meta_key as an array, adding new values to it and remove old values, saving the meta back, then grabbing it again to loop through each item in the array for output. Array is just an example of duplicate keys. $user_query = … Read more