register_activation_hook isn’t adding table to DB

Note that the $file in register_activation_hook( $file, $callback ), should be equal to path to the main plugin file, but when you have it in a sub file as __FILE__ then it’s not the same! That means your callback is never called. I would also recommend prefixing the function’s name to avoid possible name collision … Read more

When did wordpress switched requirements to php7?

The currently required minimal PHP version is still 5.2.4+. The recommended version is 7. According to archive.org since December 2, 2016. Note that many plugins and themes need at least PHP 5.4 or newer nowadays, and that PHP versions below 5.6 do not get security updates anymore and are therefore probably not safe for production. … Read more

PHPCS: Strings should have translatable content

There are several things wrong with your code The is no need for translation there. The message should have been translated before it is being passed to that function. At that function there is actually no context at all to create any different translation than %s Escaping should happen at the output. You should escape … Read more

How do I add HTML to a PHP function [closed]

You can use ‘echo’ (or ‘print’) to enclose HTML, but sometimes that gets a bit messy with complex HTML, not to mention having to escape quote/double-quote character. So try something like this: function myfunction() { // after this next, plain HTML ?> <div class=”myclass”><h1 align=”center”>This is a heading</h1></div> <!– more HTML code here –> <?php … Read more

How to change / delete product short description in Woocommerce

Th function wp_set_object_terms() will not work to set post object properties. To add/update/delete product short description there is mainly 2 ways: 1) the WordPress way from a post ID using wp_update_post() function this way: $product_id = $post->ID; // or get_the_id() or $product->get_id() (when $product is available); // The product short description (for testing) $new_short_description = … Read more

Style every second widget?

Use the dynamic_sidebar_params filter. The following code adds classes to say whether the widget is odd or even, what index it is in the sidebar, and what sidebar it’s in. Note: the str_replace(“class=\””, “class=\”$class “, $before_widget); code below depends on your before_widget using double quotes — it probably should be done with a regular expression … Read more

PHP if Condition not working

You should be using the “AND” operator, not “OR” <?php if (!is_page(‘about-us’) && !is_page(‘news-articles’)) {wp_head();}?> Because you want to display the WP head only if both conditions are true.

How to break down importing of feeds

You can try using wp cron functions, programing a feed import every 10 minutes or so, until you have nothing left in queue. Example code: <?php register_activation_hook( __FILE__, ‘wp1903_schedule_cron’ ); function wp1903_schedule_cron() { $counter = 0; $feeds = array( ‘http://example.com/feed1’, ‘http://example.com/feed2’, ‘http://example.com/feed3’, ‘http://example.com/feed4’ ); foreach ($feeds as $feed) { $counter++; // schedule every 10 mins … Read more

Highlight Current Tag in wp_tag_cloud

When you are in a tag template, a body class is added with term-{termID}, so you can hook in “wp_generate_tag_cloud_data” to check if class is present and add custom class to the tag 😉 function tribalpixel_tag_cloud_class_active($tags_data) { $body_class = get_body_class(); foreach ($tags_data as $key => $tag) { if(in_array(‘term-‘.$tag[‘id’], $body_class)) { $tags_data[$key][‘class’] = $tags_data[$key][‘class’] .” active-tag”; … Read more

WordPress get pagination on wpdb get_results

You say “However, I know this is not a good way to do this” in your self answer. One thing I could add answering your question and using your answer is, you can use SQL_CALC_FOUND_ROWS with $wpdb $result = $wpdb->get_results( “SELECT SQL_CALC_FOUND_ROWS * FROM `wp_table` WHERE 1 LIMIT 10;” ); $total_count = $wpdb->get_var( “SELECT FOUND_ROWS();” … Read more