Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:41:14+00:00 2026-06-03T12:41:14+00:00

I have run into a slight issue when creating a WordPress plugin. The plugin

  • 0

I have run into a slight issue when creating a WordPress plugin. The plugin is class based and the problem appears to be with the foreach call within a function. The foreach call is iterating through an array and adding options to WordPress using the options api. Any help getting this to work correctly would be appreciated.

The Array

$settings = array();
$settings['version'] = '0.1';
$settings['release'] = 'development';
$settings['license_accepted'] = 'false';

The Function

public function settings($action) {
        $supported_actions = array('install', 'update', 'uninstall');
        if (in_array($action, $supported_actions) == true) {
            foreach($settings as $setting => $value) {
                $current = 'plugin_'.$setting;
                if ($action == 'install') {
                    add_option($current, $value, null, true);
                }
                if ($action == 'update') {
                    update_option($current, $value, null, true);
                }
                if ($action == 'uninstall') {
                    delete_option($current);
                }
            }
        } else {
            return false;
        }
}

The Problem

Warning: Invalid argument supplied for foreach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:41:19+00:00Added an answer on June 3, 2026 at 12:41 pm

    You need to bring the $settings variable inside the function scope. You can do that by using a argument:

    $settings = array(...);
    $pluginClass->settings($action, $settings);
    

    Or use Dependency Injection (I prefer), but I think that is to difficult for you and the plugin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a Drupal setup and have run into a slight issue
We're writing an SDK for a CAD program and have run into a slight
I have run into a common, yet difficult problem. I do not use Photoshop
I have run into a bit of a tricky problem in some C++ code,
I have run into a problem trying to modify a form I myself have
I have run into a bit of a problem here: I had a problem-specific
I have run into a problem w/ my model for databinding in WPF. I
I have run into another problem with my current project. I have a form
I have run into this problem again and now really need to know how
I have run into a problem attempting to redispatch mouse events in ActionScript 3,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.