Child theme, how to cut the functions.php file into several classes?
Child theme, how to cut the functions.php file into several classes?
Child theme, how to cut the functions.php file into several classes?
After looking at the wp_list_comments() and Walker_Comment sources I would assume the callback is what the Walker uses to render single comments. And the callback recieves three parameters $comment, $args, $depth when the Walker calls it. Based on this, I assume you should be able to just push custom key-value pairs to your $args array … Read more
functions won’t fire after I converted my code from procedural code to OOP
When developing WordPress plugin, is it a good idea to create my class object by hooking to existing class constructor?
pluginprefix_setup_post_type() is a method inside the SoaneNews class, not a function, but inside your activate() method you’ve called a function with that name: function activate(){ pluginprefix_setup_post_type(); flush_rewrite_rules(); } To call the pluginprefix_setup_post_type() method from within the class, you need to do it like this: $this->pluginprefix_setup_post_type();
Some custom post types did not return an object
I ended up using the the_post hook to add the definitions as the posts are setup. This of course costs another trip to the database for every post but dealing with the duplicate entries proved too difficult. function add_definitions( $post ) { if ( ‘word’ != $post->post_type ) ) return; global $wpdb; $query = “SELECT … Read more
If you have defined the class MyCart directly in functions.php with your hooks. I’d expect for the following to work: // add action $cart = new MyCart(); function emdr_add_to_cart(){ $items = $cartClass->get_users_cart_contents(); // process items } add_action( ‘woocommerce_add_to_cart’, ’emdr_add_to_cart’); I might also add that duplicating the “state” of the users cart in 2 places is … Read more
WordPress hooks only work with global functions ( or public function inside a class ) – private or protected methods are not available due to their visibility level, so not available to the way WP calls actions or filters. What you are trying to do is tidy up your code using a class to contain … Read more
I noticed something in your ajax call. $.ajax({ type: ‘POST’, url: ajaxurl, data: data, Shouldn’t it be ajax_object.ajaxurl instead of just ajaxurl ?