[wp-trac] [WordPress Trac] #48235: get_option('activate_plugins') not return Array()

WordPress Trac noreply at wordpress.org
Mon Oct 7 04:00:29 UTC 2019


#48235: get_option('activate_plugins') not return Array()
--------------------------------+-----------------------------
 Reporter:  khoipro             |      Owner:  (none)
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Options, Meta APIs  |    Version:
 Severity:  normal              |   Keywords:
  Focuses:  template            |
--------------------------------+-----------------------------
 **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
 <?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
 <?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?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48235>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list