Title: &quot;Call to undefined function get_option()&quot; from another plugin script
Last modified: August 20, 2016

---

# "Call to undefined function get_option()" from another plugin script

 *  [chris.foxy](https://wordpress.org/support/users/chrisfoxy/)
 * (@chrisfoxy)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/call-to-undefined-function-get_option-from-another-plugin-script/)
 * hello, i’m a newbie of developing WordPress plugin.
 * now i’ve got a fatal error.
 * that is “Call to undefined function get_option()” when i directelly browse the
   script url.
 * it looks like “[http://wordpress_url/wp-content/plugins/my_plugin/index.php?action=sync&#8221](http://wordpress_url/wp-content/plugins/my_plugin/index.php?action=sync&#8221);
 * here is my plugin structure and script code below.
 * sorry about my poor english 🙂
 * _/_
    　_wp-content_ 　　_plugins_ 　　　_my\_plugin_ 　　　　_css_ 　　　　　
   style.css 　　　　_images_ 　　　　　checked.png 　　　　　favicon.gif 　　　　　
   loading.gif 　　　　　toggle.png 　　　　　unchecked.png 　　　　_js_ 　　　　
   _php_ 　　　　　**functions.php** 　　　　　uploader.php 　　　　**index.php**
 * **index.php**
 *     ```
       <?php
       	# Plugin Name: my_plugin
       	# Plugin URI:  http://www.skiddie.me/
       	# Version:     β
       	# Author:      Chris
       	# Description: no more plugin information provided :-)
   
       	require_once('php/functions.php');
       	if (!(function_exists('add_action')))
       	{
       		header('HTTP/1.1 500 Internal Server Error');
       		header('Status: 500 Internal Server Error');
       		exit('Call to function: add_action() failed');
       	}
       	add_action('admin_menu', 'my_plugin_menu');
       	add_action('publish_post', 'my_plugin_post');
       	add_filter('the_content', 'my_plugin_content');
       	register_activation_hook(__FILE__, 'my_plugin_activation');
       	register_deactivation_hook(__FILE__, 'my_plugin_deactivation');
       ?>
       ```
   
 * **php/functions.php**
 *     ```
       <?php
       	define('email', my_plugin_option('get', 'email'));
       	define('password', my_plugin_option('get', 'password'));
       	define('folder', my_plugin_option('get', 'folder'));
       	define('identity', my_plugin_option('get', 'identity'));
   
       	function my_plugin_activation()
       	{
       		$my_plugin_options = array('email' => '',
       					   'password' => '',
       					   'folder' => 'Public',
       					   'identity' => '',
       					   'delete' => 'false');
       		my_plugin_option('set', $my_plugin_options);
       	}
   
       	function my_plugin_content($content)
       	{
       		# just do something for content.
       		return $content;
       	}
   
       	function my_plugin_deactivation()
       	{
       		delete_option('my_plugin_options');
       	}
   
       	function my_plugin_file($post_id = '')
       	{
       		# try to get the post attachment real path
       	}
   
       	function my_plugin_menu()
       	{
       		if (function_exists('add_menu_page'))
       		{
       			add_menu_page('my_pluginBox Setting',
       				      'my_pluginBox',
       				      'manage_options',
       				      'my_pluginbox',
       				      'my_plugin_setup',
       				      plugin_dir_url(__FILE__) . '../images/favicon.gif');
       		}
       	}
   
       	function my_plugin_notify($status, $prompt)
       	{
       		switch ($status)
       		{
       			case 'error':
       				printf("<div id=\"message\" class=\"error\"><p>%s<br /></p></div>", $prompt);
       				break;
       			case 'success':
       				printf("<div id=\"message\" class=\"updated\"><p>%s<br /></p></div>", $prompt);
       				break;
       			default:
       				break;
       		}
       	}
   
       	function my_plugin_option($method, $key = '')
       	{
       		switch ($method)
       		{
       			case 'get':
       				$options = get_option('my_plugin_options');
       				if (is_array($options))
       					if (empty($key))
       						return $options;
       					else
       						return $options[$key];
       				return $key;
       				break;
       			case 'set':
       				if (is_array($key))
       				{
       					if (update_option('my_plugin_options', $key))
       						return true;
       					else
       						return false;
       				}
       				break;
       			default:
       				break;
       		}
       	}
   
       	function my_plugin_post($post_ID)
       	{
       		# just do something for post.
       		return $post_ID;
       	}
   
       	function my_plugin_upload($file, $folder, $email, $password)
       	{
       		# upload the post attachment to somewhere.
       	}
   
       	function my_plugin_setup()
       	{
       		if (!(empty($_POST['action'])))
       		{
       			switch ($_POST['action'])
       			{
       				case 'setup':
       					if (!(empty($_POST['delete'])) && ($_POST['delete'] == 'true'))
       						$delete = 'true';
       					else
       						$delete = 'false';
       					$my_plugin_options = array('email' => $_POST['email'],
       								   'password' => $_POST['password'],
       								   'folder' => $_POST['folder'],
       								   'identity' => $_POST['identity'],
       								   'delete' => $delete);
       					if (my_plugin_option('set', $my_plugin_options))
       						my_plugin_notify('success', 'my_pluginBox updated.');
       					else
       						my_plugin_notify('error', 'an error occurred.');
       					break;
       				case 'sync':
       					$start_time = date('Y-m-d H:i:s');
       					$file = my_plugin_file();
       					foreach ($file as $value)
       						my_plugin_upload($value, folder, email, password);
       					$end_time = date('Y-m-d H:i:s');
       					break;
       				default:
       					break;
       			}
       		}
       ?>
       	<link href="<?php printf("%scss/style.css", plugin_dir_url(__FILE__) . '../'); ?>" media="screen" rel="stylesheet" type="text/css" />
       	<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
       	<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" type="text/javascript"></script>
       	<script type="text/javascript">
       		$(document).ready(function(){
       			jQuery.validator.addMethod("format", function(value, element){
       				return this.optional(element) || /^Public(?:(?:\/[-\w.:@&?#]+)*|$)$/.test(value);
       			});
       			$("#my_pluginbox_form").validate({
       				debug: false,
       				errorElement: "strong",
       				errorPlacement: function(error, element){error.appendTo(element.siblings("span"));},
       				event: "blur",
       				rules: {
       					email: {
       						email: true,
       						required: true},
       					password: "required",
       					folder: {
       						format: true,
       						required: true},
       					identity: {
       						number: true,
       						required: true},},
       				success: function(label){label.addClass("valid");}
       			});
       			$("#identity_prompt_link").click(function(){
       				$("#identity_prompt_text").fadeToggle(1000);
       				$("#toggle").toggleClass('toggle_down');
       			});
       			$("#delete").click(function(){
       				if ($(this).attr('checked'))
       				{
       					$(this).attr('checked', false);
       					$("#delete_prompt_text").fadeIn(1000);
       				}
       			});
       			$("#delete_confirm_link").click(function(){
       				$("#delete").attr('checked', true);
       				$("#delete_prompt_text").hide();
       			});
       			$("#sync_now").click(function(){
       				$.ajax({
       					beforeSend: function(){
       						$("#result").empty();
       						$("#loading").show();},
       					cache: false,
       					data: "action=sync"
       					dataType: "html",
       					success: function(response){
       						$("#loading").hide();
       						$('#result').html(response);},
       					type: "POST",
       					url: '<?php printf("%s/wp-content/plugins/my_plugin/index.php?action=sync", get_option('siteurl')); ?>',
       				});
       			});
       		});
       	</script>
       	<form action="" autocomplete="off" id="my_pluginbox_form" method="post">
       		<div class="wrap">
       			<div id="icon-options-general" class="icon32">
       				<br />
       			</div>
       			<h2>my_pluginBox Setting</h2>
       			<fieldset>
       				<table class="form-table">
       					<tr valign="top">
       						<td>
       							<label for="email">Email: </label>
       						</td>
       						<td>
       							<input id="email" name="email" size="32" title="email" type="text" value="<?php echo email; ?>" />
       							<span></span>
       						</td>
       					</tr>
       					<tr valign="top">
       						<td>
       							<label for="password">Password: </label>
       						</td>
       						<td>
   
       							<input id="password" name="password" size="32" title="password" type="password" value="<?php echo password; ?>" />
       							<span></span>
       						</td>
       					</tr>
       					<tr valign="top">
       						<td>
       							<label for="folder">Folder: </label>
       						</td>
       						<td>
       							<input id="folder" name="folder" size="32" title="folder" type="text" value="<?php echo folder; ?>" />
       							<span></span>
       						</td>
       					</tr>
       					<tr valign="top">
       						<td>
       							<label for="identity">Identity: </label>
       						</td>
       						<td>
       							<input id="identity" name="identity" size="32" title="identity" type="text" value="<?php echo identity; ?>" />
       							<span></span>
       						</td>
       					</tr>
       					<tr valign="top">
       						<td>
       						</td>
       						<td>
       							<strong>
       								<a id="identity_prompt_link" href="#">?</a>
       								<span id="toggle" class="toggle_up"></span>
       							</strong>
       							<div id="identity_prompt_text" style="display: none">
       								this is a help prompt area :)
       							</div>
       						</td>
       					</tr>
       					<tr valign="top">
       						<td>
       							<label for="delete">Delete: </label>
       						</td>
       						<td>
       							<input <?php checked(my_plugin_option('get', 'delete'), 'true'); ?> id="delete" name="delete" title="delete" type="checkbox" value="true" />
       							Auto delete the file ?
       						</td>
       					</tr>
       					<tr valign="top">
       						<td>
       						</td>
       						<td>
       							<div id="delete_prompt_text" style="display: none">
       								Are u sure ? <a href="#" id="delete_confirm_link">CLICK HERE</a>
       							</div>
       						</td>
       					</tr>
       					<tr valign="top">
       						<th scope="row">Sync: </th>
       						<td>
       							<input class="button-primary" id="sync_now" title="sync_now。" type="button" value="Sync" />
       						</td>
       					</tr>
       					<tr valign="top">
       						<th scope="row"></th>
       						<td>
       							<div id="result">
       							</div>
       							<div id="loading" style="display:none">
       								<img src="images/loading.gif"> Uploading now ..
       							</div>
       						</td>
       					</tr>
       				</table>
       				<input type="hidden" name="action" value="setup" />
       				<p class="submit">
       					<input class="button-primary" type="submit" value="<?php _e('Save Changes') ?>" />
       				</p>
       			</fieldset>
       		</div>
       	</form>
       <?php
       	}
       ?>
       ```
   

The topic ‘"Call to undefined function get_option()" from another plugin script’
is closed to new replies.

## Tags

 * [Get_Option](https://wordpress.org/support/topic-tag/get_option/)
 * [undefined function](https://wordpress.org/support/topic-tag/undefined-function/)

 * 0 replies
 * 1 participant
 * Last reply from: [chris.foxy](https://wordpress.org/support/users/chrisfoxy/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/call-to-undefined-function-get_option-from-another-plugin-script/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
