Skip to content

Instantly share code, notes, and snippets.

@trevoro
Last active February 2, 2019 19:55
Show Gist options
  • Save trevoro/29b437e7e13f1ed2100bd031e4b67dbc to your computer and use it in GitHub Desktop.
Save trevoro/29b437e7e13f1ed2100bd031e4b67dbc to your computer and use it in GitHub Desktop.
Get all plugins for wordpress multi-site installations
DELIMITER //
DROP PROCEDURE IF EXISTS site_plugins//
CREATE PROCEDURE site_plugins()
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
DECLARE option_val varchar(256);
DECLARE name_table varchar(256);
DECLARE cur_tables CURSOR FOR SELECT TABLE_NAME from information_schema.tables where TABLE_NAME like 'wp_%_options';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1;
DROP TABLE IF EXISTS temp_wp_options;
CREATE TEMPORARY TABLE temp_wp_options(option_value varchar(256), site_name varchar(256));
OPEN cur_tables;
LOOPROWS: LOOP
IF v_finished = 1 THEN
LEAVE LOOPROWS;
END IF;
FETCH cur_tables INTO name_table;
SET @query = concat('INSERT INTO temp_wp_options SELECT option_value, \'', name_table, '\' FROM ', name_table, ' WHERE option_name = \'active_plugins\'');
prepare stmt from @query;
execute stmt;
END LOOP;
CLOSE cur_tables;
SELECT * from temp_wp_options;
END//
DELIMITER ;
call site_plugins();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment