Answers.Body: <p>You could create a <a href="http://buildwithcraft.com/docs/plugins/records" rel="nofollow" title="Record">Record</a> which will give you a custom table to store your twitter related settings and update them as needed but I think that your use case is still simple enough that you could leave them in the <code>settings array</code> and then use the <code>Plugins Service</code> to update those settings.</p>
  
  <p>This is how I would do it if I chose to use <code>defineSettings()</code></p>
  
  <hr>
  
  <pre class="lang-php prettyprint-override"><code>// MyPlugin.php
  public function defineSettings()
  {
     return array(
          // ...
          'twitterApiKey' =&gt; array(AttributeType::String, 'default' =&gt; '5omeRand0mstriNg'),
          'twitterUsername' =&gt; array(AttributeType::String, 'default' =&gt; 'someone'),
      );
  }
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>// MyService.php
  public function saveTwitterSettings(array $settings=array())
  {
      $plugin = craft()-&gt;plugins-&gt;getPlugin('myplugin');
      $savedSettings = $plugin-&gt;getSettings()-&gt;getAttributes();
      $newSettingsRow = array_merge($savedSettings, $settings);
  
      return craft()-&gt;plugins-&gt;savePluginSettings($plugin, $newSettingsRow);
  }
  </code></pre>
  
  <hr>
  
  <p>Feel free to follow up with questions/comments if you have any.</p>
  
  <p><a href="http://twitter.com/selvinortiz" rel="nofollow" title="Selvin Ortiz">@selvinortiz</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-20T13:19:50.230Z
Answers.Text: Thanks Selvin, Records was the piece of the puzzle I was missing. I do also want to keep a log of each run of the plugin, so I think in this instance a Record may make more sense. Your code will come in handy next time for instances where a Record is a little too much.
Answers.UserDisplayName: Steve Holland
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-20T13:33:28.243Z
Answers.Text: Thanks for adding the link to the docs for the record @Steve and yes, in that case you'll definitely need one. Craft makes it a joy to interact with the database via records and the query builder: )
Answers.UserDisplayName: Selvin Ortiz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-20T12:36:01.493Z
Answers.LastActivityDate: 2014-06-23T17:04:52.790Z
Answers.LastEditDate: 2014-06-23T17:04:52.790Z
Answers.UserDisplayName: Selvin Ortiz
Body: <p>For instance I'm writing a plugin which is going to be periodically pulling stuff from Twitter, so I'd like to keep a hold of when the plugin was last run and maybe some Ids relevant to Twitter that sort of thing. </p>
  
  <p>I know there is the settings array which you use for user defined values, should I also use it for other stuff that the user can't change, or is there a more sensible place to stick those?  </p>
  
Tags: <plugin-development>
Title: When developing plugins where should you store values that might not strictly be settings?
ThreadText: # When developing plugins where should you store values that might not strictly be settings?
  
  (Asked by: username_0 on 2014-06-20)
  
  For instance I'm writing a plugin which is going to be periodically pulling stuff from Twitter, so I'd like to keep a hold of when the plugin was last run and maybe some Ids relevant to Twitter that sort of thing.
  
  I know there is the settings array which you use for user defined values, should I also use it for other stuff that the user can't change, or is there a more sensible place to stick those?
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-20. Score: 7 | Accepted answer
  
  You could create a [Record](http://buildwithcraft.com/docs/plugins/records "Record") which will give you a custom table to store your twitter related settings and update them as needed but I think that your use case is still simple enough that you could leave them in the `settings array` and then use the `Plugins Service` to update those settings.
  
  This is how I would do it if I chose to use `defineSettings()`
  
  ---
  
  ```php
  // MyPlugin.php
  public function defineSettings()
  {
     return array(
          // ...
          'twitterApiKey' => array(AttributeType::String, 'default' => '5omeRand0mstriNg'),
          'twitterUsername' => array(AttributeType::String, 'default' => 'someone'),
      );
  }
  
  ```
  
  ```php
  // MyService.php
  public function saveTwitterSettings(array $settings=array())
  {
      $plugin = craft()->plugins->getPlugin('myplugin');
      $savedSettings = $plugin->getSettings()->getAttributes();
      $newSettingsRow = array_merge($savedSettings, $settings);
  
      return craft()->plugins->savePluginSettings($plugin, $newSettingsRow);
  }
  
  ```
  
  ---
  
  Feel free to follow up with questions/comments if you have any.
  
  [@username_1](http://twitter.com/username_1 "username_1")
  
  > **Comments:**
  > **username_0**: Thanks username_1, Records was the piece of the puzzle I was missing. I do also want to keep a log of each run of the plugin, so I think in this instance a Record may make more sense. Your code will come in handy next time for instances where a Record is a little too much.  
  > **username_1**: Thanks for adding the link to the docs for the record @username_0 and yes, in that case you'll definitely need one. Craft makes it a joy to interact with the database via records and the query builder: )  
  
  ---
  
  