Archived topic
PHP Warning: Trying to access array offset on value of type bool
10 replies · Started by Stew on February 22, 2023
I use WP CLI to install/setup WordPress and install plugins/themes, and I've noticed that when I do a fresh setup with GP Premium installed, I see the following PHP warning at the top of the Dashboard after logging in (but it disappears on subsequent page loads):
Warning: Trying to access array offset on value of type bool in S:\Local Sites\test\app\public\wp-content\plugins\gp-premium\hooks\functions\functions.php on line 450
That line reads:
if ( 'true' == $generate_hooks['updated'] ) {
So I'm guessing the fix might be to change it to something like:
if ( isset($generate_hooks['updated']) && 'true' == $generate_hooks['updated'] ) {
Hi there,
thanks for reporting ill get this added to our issues to be fixed.
Much appreciated!
No worries, thanks David!
Its on our list now.
Thanks again!!
Just a heads up - not sure how you're activating the modules, but the Hook module has been deprecated for a few years now. No need to have it activated at all.
Ah, thanks Tom. I was indeed using some instructions you wrote a few years back (and added a couple of options): https://generatepress.com/forums/topic/how-to-activate-addons-with-the-wp-cli/#post-305962
wp option update generate_package_backgrounds 'activated'
wp option update generate_package_blog 'activated'
wp option update generate_package_colors 'activated'
wp option update generate_package_copyright 'activated'
wp option update generate_package_disable_elements 'activated'
wp option update generate_package_elements 'activated'
# wp option update generate_package_hooks 'activated'
wp option update generate_package_import_export 'activated'
wp option update generate_package_menu_plus 'activated'
wp option update generate_package_page_header 'activated'
wp option update generate_package_secondary_nav 'activated'
wp option update generate_package_sections 'activated'
wp option update generate_package_site_library 'activated'
wp option update generate_package_spacing 'activated'
wp option update generate_package_typography 'activated'
Commenting-out the hooks option as I have above stops that warning from appearing, thanks.
On the topic of activation, I'm also using the following to set the license keys, but I still need to click a button to actually activate them -- is there a better/automatic way of setting/activating?
// GeneratePress Premium
add_filter('pre_option_gen_premium_license_key', fn ($pre) => 'xxxxx');
// GenerateBlocks Pro
update_option('generateblocks_pro_licensing', [
'key' => 'xxxxx'
]);
From memory I think I found these either via the forum or trawling through the plugin code and coming up with my own hacky guess.
I would say this is the most recent:
wp option update generate_package_backgrounds 'activated'
wp option update generate_package_blog 'activated'
wp option update generate_package_copyright 'activated'
wp option update generate_package_disable_elements 'activated'
wp option update generate_package_elements 'activated'
wp option update generate_package_menu_plus 'activated'
wp option update generate_package_secondary_nav 'activated'
wp option update generate_package_site_library 'activated'
wp option update generate_package_spacing 'activated'
You can add your license key to the database like that, but you'll likely hit an "Unauthorized" error when trying to update. To fix that, you'll need to do this: https://docs.generatepress.com/article/authorizing-site-urls/
Thanks for that info Tom.
Re setting the license key for Generate Blocks, the License Key field is populated on the Settings page (/wp-admin/admin.php?page=generateblocks-settings) however I still have to manually click "Save", as I couldn't work out a scriptable way to automate this.
Basically you need to do this:
wp_remote_post(
'https://generateblocks.com',
array(
'timeout' => 15,
'sslverify' => false,
'body' => array(
'edd_action' => 'activate_license',
'license' => 'YOUR LICENSE KEY',
'item_name' => rawurlencode( 'GenerateBlocks Pro' ),
'url' => home_url(),
),
)
);
Hope this helps!
You're a gentleman and a scholar Tom, that is a great idea, thank you!
You're welcome :)