Articles of hooks

Use has_filter on comment_post

I hook to comment form (on comment_form_logged_in_after if user is logged in and comment_form_before_fields if not) to add 2 fields (rating and title). These fields can be mandatory or comment will not save. These fields will not appear on comment reply or if review are not enabled for a certain post or page. If these […]

Remove word “Category” from WooCommerce product page

I’m trying to remove the word Category from the product page. As far as I know the code that displays that is woocommerce_template_single_meta located into content-single-product.php file: <?php /** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title – 5 * @hooked woocommerce_template_single_rating – 10 * @hooked woocommerce_template_single_price – 10 * @hooked woocommerce_template_single_excerpt – 20 * @hooked […]

Odd map_meta_cap $args on post edit — sometimes integer, sometimes string

I’ve been digging into the map_meta_cap filter since I need to extend the user’s capabilities based on context, in certain situations. This is working well but in my traces I noticed something odd about the way $args show up at the callback function. Here’s my filter registration (inside a class): add_filter( ‘map_meta_cap’, array(&$this, ‘post_map_meta_cap’), 10, […]

How to replace default comments with custom HTML?

I’m going to replace default list of comments and comment form with Facebook’s comment box. As far as I know there is function wp_list_comments(). How can I replace this function with my custom one? Update: I want completely ignore built-in WordPress comments. When I try to add my code to the end of content, it […]

How can I create a custom plugin that allows anonymous users to signup without registering?

I am very new to wordpress. I want to create a small Booking System as a plugin. I have 5 different pages for entering details step by step and Users can book as anonymous. Admin only need a mail with all those details. How can I allow access for anonymous users in these pages? What […]

Remove links from the_content when using filters wp_trim_excerpt

I’m using wp_trim_excerpt which is working perfectly but I want to strip the links contained in the the_excerpt (using get_the_content), I’ve looked online and tried many solutions to get the thing to work and hoping someone can help point me in the right direction. My working code looks like this: add_filter( ‘wp_trim_excerpt’, ‘my_custom_excerpt’, 10, 2 […]

How can I check user capability when a page loads (via functions.php)?

I need to restrict users without a specific capability from seeing a specific page. I can’t use shortcodes or anything like that, I just want to redirect them if they get to that page URL. I want to do this by adding something to my functions.php file… I would imagine the code would be something […]

Trying to get class to instantiate ONCE (or, “why do I keep punching myself in the head?”)

Here’s a very simple plugin, which I drop into mu_plugins in my multisite installation: <?php /* Plugin Name: Test */ class myclass { function __construct() { error_log(“I just punched myself in the head.”); } } // end of class definition /* start of plugin functions */ function run_plugin() { static $counter = 0; if (0 […]

hook filter after the_content on a specific page

I’ve made a function to hook after the_content. This is only working on certain pages/posts. It’s working on the default template but not on my custom one’s. function insertFootNote($content) { $content.= “<div>”; $content.=”additional content”; $content.= “</div>”; return $content; } add_filter (‘the_content’, ‘insertCpontent’); In my custom page template I haven the following code <?php if(have_posts()): ?> […]

AddFilter option_active_plugins is executed 6 times. Why?

I’ve put an adsense script in the mu-plugins folder, hooked it to the option_active_plugins but it happens to be executed 6 times. Is it an error?