WordPress Multisite: Programmatically Activate / Deactivate a Plugin of a Specific Blog

Use a combination of switch_to_blog(), activate_plugins(), and deactivate_plugins(). You can put this in functions.php, but you’ll want to remove it once it runs: // hook to admin init add_action(‘admin_init’, ‘wpse_swap_plugins’); function wpse_swap_plugins() { // set blog ID per your needs $blog_id = 3; // switch to the site where you want to activate/deactivate plugins switch_to_blog($blog_id); … Read more

Submit Form data to another page via Ajax (WordPress Way)

Modify the following code I have added action in it. $(‘#btnDoCalculation’).click(function(e){ var formData = $(‘#interest_calculator’).serialize(); $.ajax({ type: ‘POST’, url: ‘<?php echo admin_url(‘admin-ajax.php’);?>’, data:formData, dataType: ‘json’, action:calculate_investor_interest encode:true, }).done(function(data){ if(data.success){ console.log(data); var results = data.calc_results; var newData = results.reduce(function(collection, element){ var rowData = {}; //create a new empty row element.reduce(function(collection, element){ //put the elements into the … Read more

Add Password Generator on password protected page

It is not possible to modify the post submit meta boxes with a filter. But you can do that with JavaScript. This script will generate 10-12 random alphanumeric string and put it in the password field (if it is empty) when you click the Password protected radio button. $(‘#visibility-radio-password’).click(function () { // If there is … Read more

esc_html__() and __() not working within arrays

I created simple widget to find out why you have such a problem. Everything is working fine. Below I give you my code as an example. /** * Register widget */ function wpse_287570_register_widget() { register_widget(‘WPSE_287570_Widget’); } add_action(‘widgets_init’, ‘wpse_287570_register_widget’); /** * Create widget */ class WPSE_287570_Widget extends WP_Widget { public function __construct() { $op = array( … Read more