I am in the process of writing my first plugin and my call to the plugin_basename(__FILE__)
function results in a:
PHP Fatal error: Call to undefined function plugin_basename()
My plugin resides in a directory of its own under the standard wp-content/plugins/. I am also using wordpress 3.3.1 and have looked at the codex but cannot see anything wrong. The code block where it fails is shown below:
<?php
/*
Plugin Name: Send Invitation
Plugin URI: http://w3boutique.net
Description: Emails a the link of the current page to a friend
Author: Nandakumar Chandrasekhar
Version: 0.1wp-includes/plugin.php
Author URI: http://w3boutique.net/about-nanda.html
License: GPL2
*/
define( 'SEND_INVITATION_VERSION', '0.1' );
define( 'SEND_INVITATION_REQUIRED_WP_VERSION', '3.3.1' );
// Check if following are required
if ( ! defined( 'SEND_INVITATION_PLUGIN_BASENAME' ) ) {
define( 'SEND_INVITATION_PLUGIN_BASENAME', plugin_basename(__FILE__) );
}
if ( ! defined( 'SEND_INVITATION_PLUGIN_NAME' ) ) {
define( 'SEND_INVITATION_PLUGIN_NAME', trim( dirname( SEND_INVITATION_PLUGIN_BASENAME ), '/' ) );
}
if ( ! defined( 'SEND_INVITATION_PLUGIN_DIR' ) ) {
define( 'SEND_INVITATION_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . SEND_INVITATION_PLUGIN_NAME );
}
if ( ! defined( 'SEND_INVITATION_PLUGIN_URL' ) ) {
define( 'SEND_INVITATION_PLUGIN_URL', WP_PLUGIN_URL . '/' . SEND_INVITATION_PLUGIN_NAME );
}
// Version check
global $wp_version;
// Message to send if version is below the required version
$exit_msg = 'Send Invitation requires WordPress or newer' . SEND_INVITATION_REQUIRED_WP_VERSION . ' <a href="http://codex.wordpress.org/Upgrading_WordPress">Please update!</a>';
if ( version_compare( $wp_version, SEND_INVITATION_REQUIRED_WP_VERSION, "<" ) ) {
exit( $exit_msg );
}
function add_send_invitation_link() {
wp_enqueue_script('jquery');
wp_enqueue_script( 'show_form.js', SEND_INVITATION_PLUGIN_URL . '/js/show_form.js' );
wp_enqueue_style( 'send-invitation.css', SEND_INVITATION_PLUGIN_URL . '/css/send-invitation.css' );
# TODO Put this in another file and include it
$invitation_form = '
<h1><a href="#" onclick="show_form();">Send Invitation</a></h1>
<form id="invitation-form" method="post" action="javascript:void(0);">
<p>
Your Email Address<br />
<input type="text" name="email" />
</p>
<p>
' . "Friend's Email Address" . '<br />
<input type="text" name="email" />
</p>
<p>
Subject<br />
<input type="text" name="subject" />
</p>
<p>
Message<br/>
<textarea rows="10" cols="20"></textarea>
</p>
<p><input type="submit" name="submit" value="Send" /></p>
</form>
<script type="text/javascript">
jQuery("#invitation-form").submit(function(){
alert("got here");
var str = "this";
jQuery.ajax("' . SEND_INVITATION_PLUGIN_URL . '/form-processor.php?action=send_email", str, function(result){
alert(result);
});
alert("finished");
return(false);
});
</script>';
return $invitation_form;
}
function send_email() {
error_log("Inside send email", 0);
$subject = 'test';
$message = 'this is a test from send invitation';
$to = '[email protected]';
wp_mail($to, $subject, $message);
}
?>
I would appreciate any pointers you may have to what I might be doing wrong here.
Thanks in advance.