WordPress.org

Make WordPress Core

Opened 6 weeks ago

Closed 6 weeks ago

#48235 closed defect (bug) (invalid)

get_option('activate_plugins') not return Array()

Reported by: khoipro Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords:
Focuses: template Cc:
PR Number:

Description (last modified by SergeyBiryukov)

Case

When switching a default theme (Twenty Nineteen) to a custom theme (made by me).

The Problem

The plugin advanced-custom-fields-pro isn't activated so it displays an error.

I tried to fix it without touching a database by adding activate_plugin() function.

<?php
if (!function_exists('get_field') ) {
  activate_plugin('advanced-custom-fields-pro/acf.php');
}

Following those documents:

https://developer.wordpress.org/reference/functions/activate_plugin/
https://developer.wordpress.org/reference/functions/get_option/

The error returns

<?php
Warning: in_array() expects parameter 2 to be array, string given in /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-admin/includes/plugin.php on line 630
Fatal error: Uncaught Error: [] operator not supported for strings in /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-admin/includes/plugin.php:681
Stack trace:
#0 /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-content/themes/caruso-retail/lib/class-theme-init.php(74): activate_plugin('advanced-custom...')
#1 /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-includes/class-wp-hook.php(286): Caruso_Retail_Theme->required_plugins('')
#2 /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
#3 /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-includes/plugin.php(465): WP_Hook->do_action(Array)
#4 /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-settings.php(525): do_action('init')
#5 /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-config.php(38): require_once('/srv/bindings/a...')
#6 /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-load.php(37): require_once('/srv/bindings/a...')
#7 /srv/bindings/abe0a5b9a447426d in /srv/bindings/abe0a5b9a447426da8fb4ba7cd7f9471/code/wp-admin/includes/plugin.php on line 681
?>

Debug

The debug returns get_field('activate_plugins') doesn't return an Array as it described there (https://codex.wordpress.org/Option_Reference). It returns string with i and s looks like a direct query from database row.

So I wish to know how exactly to activate a plugin correctly?

Change History (2)

#1 @knutsp
6 weeks ago

  • Keywords close added

There is no core option 'activate_plugins', the closest is 'active_plugins'. It will return an array unless the database options table is tampered with.

I see no core bug here, and as this Trac is for core bugs and enhancements, not support, I suggest asking in Support or Stack Exchange.

#2 @SergeyBiryukov
6 weeks ago

  • Description modified (diff)
  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

The debug returns get_field('activate_plugins') doesn't return an Array

get_field() is not a WordPress core function. As noted above, please try the support forums.

Note: See TracTickets for help on using tickets.