Call to undefined function add_action() - plugins

I am developing a plugin for custom registration form.I have first file customapplicationform.php file , other files in side registration and shortcode folder.
So, My Plugin Directory structure like this :
--->customapplicationform
|--js
|--ajax-registration.js
|--registration
|--registration.php
|--regsubmit.php
|--scripts.php
|--shortcode
|--display.php
|--shortcodes.php
--customapplicatioform.php
It's give error :
Fatal error: Call to undefined function add_action() in E:\xampp\htdocs\aism\wp-content\plugins\customapplicationform\registration\scripts.php on line 17
Please , Tell me what is the problem with this ? and if there any better way than suggest me. Thanks in advance.
1) This is my customapplicationform.php file.
require_once(ABSPATH.'wp-admin/includes/plugin.php');
ob_start();
global $app_db_version;
$app_db_version = '1.0';
function app_install() {
global $wpdb;
global $app_db_version;
$table_name = $wpdb->prefix .'registeration';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
regid mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
fname varchar(50) NOT NULL,
lname varchar(50) NOT NULL,
email varchar(50) NOT NULL,
phno int(12) NOT NULL,
PRIMARY KEY(regid)
) ";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
add_option( 'app_db_version', $app_db_version );
}
register_activation_hook( __FILE__, 'app_install');
include_once('/shortcode/shortcodes.php');
2) This is my shortcodes.php file.
function shortcode_function( $atts ) {
$plugin_dir_path = dirname(__FILE__);
include_once('display.php');
$data = ob_get_clean();
return $data;
}
add_shortcode( 'custom-application', 'shortcode_function' );
3) This is my display.php file.
include_once(''.dirname(dirname(__FILE__)).'/registration/registration.php');
4) This is my registration.php file.
<form action="<?php echo plugins_url();>/customapplicationform/registration/regsubmit.php" method="Post">
<label>First Name:</label>
<input type="text" name="appfname" id="appfname" />
<label>Last Name :</label>
<input type="text" name="applname" id="applname" />
<label>Email :</label>
<input type="email" name="appemail" id="appemail" />
<label>Phone :</label>
<input type="tel" name="appphone" id="appphone" />
<?php// wp_nonce_field('app_new_user','app_new_user_nonce', true, true ); ?>
<input type="Submit" value="Submit" id="btn-new-user">
</form>
5) This is my regsubmit.php file.
require_once('scripts.php');
// Verify nonce
if( ! wp_verify_nonce( $_POST['app_new_user_nonce'], 'app_new_user' ) )
{
die( 'Ooops, something went wrong, please try again later.' );
}
else {
if(isset($_POST['appemail'])) {
// Post values
echo $fname = $_POST['appfname'];
echo $lname = $_POST['applname'];
echo $email = $_POST['appemail'];
echo $phone = $_POST['appphone'];
$userdata = array(
'fname' => $fname,
'lname' => $lname,
'email' => $email,
'phno' => $phone,
);
$user_id = wp_insert_user( $userdata ) ;
// Return
if( !is_wp_error($user_id) ) {
echo '1';
} else {
echo $user_id->get_error_message();
}
}
}
6) This is my scripts.php file .
function app_register_user_scripts() {
// Enqueue script
wp_register_script('app_reg_script', dirname(__FILE__). '/js/ajax- registration.js', array('jquery'), null, false);
wp_enqueue_script('app_reg_script');
wp_localize_script( 'app_reg_script', 'app_reg_vars', array('app_ajax_url' => admin_url( 'admin-ajax.php' )));
}
add_action('wp_enqueue_scripts', 'app_register_user_scripts');

It's a core function and available if your code is activated trough WordPress and accessed trough WordPress. If you try to call your plugin file outside the WordPress scope (for example you approach the file from the browser, directly) then add_action is not available unless you require wp-load.php at the top of your file from the WordPress root.

Since we're calling core functions before $wp->init; we need to include pluggable.php
require_once(ABSPATH .'wp-includes/pluggable.php');

Related

this plugin works only on page

I have a large amount of password-protected posts, all of which are hidden from the average viewer. I’d like a single password entry page to unlock the visibility of all the protected content, as well as a custom landing page after the successful password entry. This plugin seems to do what i’m looking for but only with Pages
can it also work on post and woocomerce products?
i added 'post' in 119 line, but not works
thanks
<?php
/*
define( 'SECONDS_TO_STORE_PW', 864000); // 864000 = 10 Days
class smartPWPages {
function smartpwpages_shortcode( $atts ) {
global $post;
extract( shortcode_atts( array(
'label' => __( 'Enter', 'smartpwpages' ),
'ID' => 'smartPWLogin',
'parent' => $post->ID,
), $atts ) );
$result = '<form ID="' . esc_attr( $ID ) . '" method="post" action="' . esc_url( get_permalink() ) . '" >' . PHP_EOL;
if ( isset( $_GET['wrongpw'] ) ) $result .= '<p id="smartPWError">' . __( 'You\'ve entered an invalid password.</p>', 'smartpwpages' ) . PHP_EOL;
$result .= ' <input class="requiredField" type="password" name="smartPassword" id="smartPassword" value=""/>' . PHP_EOL;
$result .= ' <input type="hidden" name="smartParent" value="' . (int) $parent . '" />' . PHP_EOL;
$result .= ' <input type="hidden" name="smartPWPage_nonce" value="' . wp_create_nonce( 'smartPWPage' ).'" />' . PHP_EOL;
$result .= ' <input type="submit" value="' . esc_attr( $label ). '" />' . PHP_EOL;
$result .= '</form>' . PHP_EOL;
return $result;
}
/**
* Password Redirect
* Decodes the password, stores it in a cookie and redirects the visitor to that page.
*/
function pw_redirect( $perma, $password ) {
global $wp_version, $wp_hasher;
// Version 3.6 introduces a new function
if ( function_exists( 'wp_unslash' ) ) {
$cookiePW = wp_unslash( $password );
} else {
$cookiePW = stripslashes( $password );
}
// Version 3.4 and higher has better security on the pw pages
if ( version_compare( $wp_version, '3.4', '>=' ) ) {
if ( empty( $wp_hasher ) ) {
// By default, use the portable hash from phpass
require_once( ABSPATH . 'wp-includes/class-phpass.php');
$wp_hasher = new PasswordHash( 8, true );
}
// Potentially using a custom hasher, hash the pw
$cookiePW = $wp_hasher->HashPassword( $cookiePW );
}
$secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
// Store password for the length in the constant
setcookie( 'wp-postpass_' . COOKIEHASH, $cookiePW, time() + SECONDS_TO_STORE_PW, COOKIEPATH, COOKIE_DOMAIN, $secure );
wp_safe_redirect( $perma );
exit();
}
/**
* Process Form
* Decodes the password submitted on a form, find a page that uses it and redirects the visitor to that page.
*/
function process_form() {
global $wp_version, $wp_hasher;
if ( isset( $_POST[ 'smartPassword' ] ) && isset( $_POST[ 'smartParent' ] ) && wp_verify_nonce( $_POST[ 'smartPWPage_nonce' ], 'smartPWPage' ) ) {
$parentForm = (int) $_POST[ 'smartParent' ] ;
$password = $_POST[ 'smartPassword' ];
if ( function_exists( 'wp_unslash' ) ) {
$postPassword = wp_unslash( $password );
} else {
$postPassword = stripslashes( $password );
}
$args = array(
'sort_order' => 'DESC',
'sort_column' => 'post_date',
'hierarchical' => 1,
'post_type' => 'page','post',
'post_status' => 'publish'
);
if ( function_exists( 'pause_exclude_pages' ) ) pause_exclude_pages();
$myPages = get_pages( $args );
if ( function_exists( 'resume_exclude_pages' ) ) resume_exclude_pages();
// Version 3.4 and higher has better security on the pw pages
if ( version_compare( $wp_version, '3.4', '>=' ) ) {
if ( empty( $wp_hasher ) ) {
// By default, use the portable hash from phpass
require_once( ABSPATH . 'wp-includes/class-phpass.php' );
$wp_hasher = new PasswordHash( 8, true );
}
}
foreach( $myPages as $page ) {
if ( ( $page->post_password == $postPassword ) || ( !empty( $wp_hasher ) &&
$wp_hasher->CheckPassword( $page->post_password, $postPassword ) ) ) {
$permalink = get_permalink( $page->ID );
$this->pw_redirect( $permalink, $postPassword );
}
}
// Nothing more to do here. If we reached here, we've submitted a pw but no match was found.
// Allow the page to continue loading, but hack $_GET to indicate the status
$_GET[ 'wrongpw' ] = TRUE;
}
}
}
) );
thanks to everyone can help me

how to integrate the mailchimp with core php

I need to integrate the mail chimp api with core php I tried more type of codes but not working. Finally, I found the below code. I have created an api key with mailchimp, likewise campaigns, template and list in the mailchimp.
<script src="jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$('#subscribe').submit(function() {
if (!valid_email_address($("#email").val()))
{
$(".message").html('The email address you entered was invalid. Please make sure you enter a valid email address to subscribe.');
}
else
{
$(".message").html("<span style='color:green;'>Adding your email address...</span>");
$.ajax({
url: 'subscribe.php',
data: $('#subscribe').serialize(),
type: 'POST',
success: function(msg) {
if(msg=="success")
{
$("#email").val("");
$(".message").html('<span style="color:green;">You have successfully subscribed to our mailing list.</span>');
}
else
{
$(".message").html('The email address you entered was invalid. Please make sure you enter a valid email address to subscribe.');
}
}
});
}
return false;
});
});
function valid_email_address(email)
{
var pattern = new RegExp(/^[+a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
return pattern.test(email);
}
</script>
<?php
$api_key = "key";
$list_id = "id";
require('inc/MAPI.class.php');
$Mailchimp = #new Mailchimp( $api_key );
echo bool($Mailchimp);
//$Mailchimp_Lists = #new Mailchimp_Lists( $Mailchimp );
//$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['email']) ) );
if ( ! empty( $subscriber['leid'] ) ) {
echo "success";
}
else
{
echo "fail";
}
?>
<div class="message"></div>
<form role="form" method="post" id="subscribe">
<input type="email" id="email" name="email" placeholder="you#yourself.com" value="">
<button type="submit">SUBSCRIBE</button>
</form>
This is my code, but it's not returning, errors only. Please help me.

Isotope with Fancybox filtering

I implemented Isotope.js into my WordPress site. I use it to display gallery with Easy Fancybox plugin to add zooming functionality for images. Problem is with Isotope filtering. I added rel attribute to my images but when I filter categories Fancybox still cycles through all images.
I need to add rel attribute dynamically based on category I'm filtering. I'm struggling with this problem for 3 days now. I've read bunch of post, tried view things but still can't make it work.
Most of posts give solution with data-fancybox-group attribute but I can't use it I must use rel attribute (it doesn't work for me anyway).
Here's my WP code:
<ul id="filters">
<li>All</li>
<?php
$terms = get_terms("polygraphy-categories");
$count = count($terms);
if ( $count > 0 ){
foreach ( $terms as $term ) {
echo "<li><a class='filterbutton' href='#' data-filter='.".$term->slug."'>" . $term->name . "</a></li>\n";
}
}
?>
</ul>
<?php $the_query = new WP_Query( 'post_type=polygraphy' ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<div id="isotope-list">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
$termsArray = get_the_terms( $post->ID, "polygraphy-categories" );
$termsString = "";
foreach ( $termsArray as $term ) {
$termsString .= $term->slug.' ';
}
?>
<div class="<?php echo $termsString; ?> poli">
<?php
if ( has_post_thumbnail()) {
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo '<a class="fancybox" href="' . $full_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
the_post_thumbnail('thumbnail');
echo '</a>';
}
?>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
And JS code:
jQuery(function ($) {
$(window).load(function(){
var $container = $('#isotope-list');
$container.isotope({
itemSelector : '.poli',
layoutMode : 'masonry'
});
var $optionSets = $('#filters'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('#filters');
$optionSets.find('.selected').removeClass('selected');
$this.addClass('selected');
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
});
});
I was told that this code should work but it doesn't:
$('.filterbutton').on("click", function(){
var selector = $(this).attr('data-filter');
if(selector == "*"){
$(".fancybox").attr("rel", "gallery");
} else{
$(selector).find(".fancybox").attr("rel", selector);
}
return false;
});

Form text diappears and comeing ab up again

How do I do that in symfony?
http://dorward.me.uk/tmp/label-work/example.html
When I click into the input field username. The text disappears. If I don't enter nothing and click somewhere else the text is comeing up again. How do I do that in symofny in lib/forms/.
Thanks for an advice!
Craphunter
This isnt symfony - its javascript ... just take a look at the source (uses jQuery)
HTML:
<div class="slim-control">
<label for="username"> Username </label>
<input name="username" id="username">
</div>
<div class="slim-control">
<label for="password"> Password </label>
<input name="password" id="password" type="password">
</div>
JavaScript:
(function () {
var nonEmpty = "non-empty";
var inputs = jQuery('.slim-control input');
var setLabelStyle = function setLabelStyle () {
var label = jQuery(this);
if (label.val().length) {
label.addClass(nonEmpty);
} else {
label.removeClass(nonEmpty);
}
};
inputs.focus(function () {
jQuery(this).addClass(nonEmpty);
});
inputs.blur(setLabelStyle);
inputs.each(setLabelStyle);
}());
So if you want to do this - you would need to add the javascript to the template (indexSuccess.php) for example - you would probably need to modify the ids / classes to meet your local needs
Updated
You could create the following form - this would match the above form (untested):
$this->form = new sfForm();
$this->form->setWidgets(array(
'username' => new sfWidgetFormInputText(),
'password' => new sfWidgetFormInputPassword()
));
Creating forms (indeed all of Symfony) is very well documented here -> http://www.symfony-project.org/gentle-introduction/1_4/en/10-Forms
'input' => new sfWidgetFormInputText(array(), array('size' => '100', 'maxlength' => '255', 'value' => 'Some text', 'onblur' =>"if(this.value == '') { this.value='Some text'}", 'onfocus' =>"if (this.value == 'Some text') {this.value=''}")),
This is much shorter! Be careful that "Some text" is identical!
If you need to pass more, take a look to SetWidgetsHtml in Symfony form: (slide down)
http://www.symfony-project.org/forms/1_4/en/01-Form-Creation

zend-form select optgroup, how to specify id

Hello i am using Zend Framework Form and have tried to get this example to work http://framework.zend.com/issues/browse/ZF-8252, but it fails xD
this is my code
$options = Array
(
[] => Qualsiasi Agente
[agenti_attivi] => Array
(
[4] => Giovanni Abc
[10] => Luigi Abc
[13] => Michela Abc
)
);
$agenti->addMultiOptions($options);
and the generated code is :
<select name="agente_id" id="agente_id" tabindex="6">
<option value="" label="Qualsiasi Agente" selected="selected">Qualsiasi Agente</option>
<optgroup id="agente_id-optgroup-Agenti attivi: " label="Agenti attivi: ">
<option value="4" label="Giovanni Abc">Giovanni Abc</option>
<option value="10" label="Luigi Capoarea">Luigi Abc</option>
<option value="13" label="Michela Abc">Michela Abc</option>
</optgroup>
</select>
where id="agente_id-optgroup-Agenti attivi: " is not xhtml valid Line 724, Column 44: value of attribute "id" must be a single token
i am using zend 1.11.10
thanks
Create a custom view helper FormSelect that extends the core FormSelect and then modify the code.
Include the path to your view helpers in the bootstrap file
protected function _initHelpers()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->addHelperPath('My/View/Helper', 'My_View_Helper');
}
The custom view helper. It's a copy of Zend_View_Helper_FormSelect but with small modification.
class My_View_Helper_FormSelect extends Zend_View_Helper_FormSelect
{
public function formSelect($name, $value = null, $attribs = null,
$options = null, $listsep = "<br />\n")
{
$info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
extract($info); // name, id, value, attribs, options, listsep, disable
// force $value to array so we can compare multiple values to multiple
// options; also ensure it's a string for comparison purposes.
$value = array_map('strval', (array) $value);
// check if element may have multiple values
$multiple = '';
if (substr($name, -2) == '[]') {
// multiple implied by the name
$multiple = ' multiple="multiple"';
}
if (isset($attribs['multiple'])) {
// Attribute set
if ($attribs['multiple']) {
// True attribute; set multiple attribute
$multiple = ' multiple="multiple"';
// Make sure name indicates multiple values are allowed
if (!empty($multiple) && (substr($name, -2) != '[]')) {
$name .= '[]';
}
} else {
// False attribute; ensure attribute not set
$multiple = '';
}
unset($attribs['multiple']);
}
// now start building the XHTML.
$disabled = '';
if (true === $disable) {
$disabled = ' disabled="disabled"';
}
// Build the surrounding select element first.
$xhtml = '<select'
. ' name="' . $this->view->escape($name) . '"'
. ' id="' . $this->view->escape($id) . '"'
. $multiple
. $disabled
. $this->_htmlAttribs($attribs)
. ">\n ";
// build the list of options
$list = array();
$translator = $this->getTranslator();
foreach ((array) $options as $opt_value => $opt_label) {
if (is_array($opt_label)) {
$opt_disable = '';
if (is_array($disable) && in_array($opt_value, $disable)) {
$opt_disable = ' disabled="disabled"';
}
if (null !== $translator) {
$opt_value = $translator->translate($opt_value);
}
$opt_id = ' id="' . $this->formatElementId($id . '-optgroup-' . $opt_value) . '"';
$list[] = '<optgroup'
. $opt_disable
. $opt_id
. ' label="' . $this->view->escape($opt_value) .'">';
foreach ($opt_label as $val => $lab) {
$list[] = $this->_build($val, $lab, $value, $disable);
}
$list[] = '</optgroup>';
} else {
$list[] = $this->_build($opt_value, $opt_label, $value, $disable);
}
}
// add the options to the xhtml and close the select
$xhtml .= implode("\n ", $list) . "\n</select>";
return $xhtml;
}
private function formatElementId($id)
{
// in here put whatever filter you want for the id value
$id = trim(strtr($id, array('[' => '-', ']' => '', ' ' => '', ':' => '')), '-');
$id = strtolower($id);
return $id;
}
}
Done. Create multi select element with a valid id.
<?php
$this->addElement('multiSelect', 'agente_id', array(
'label' => 'Label Name:',
'multiOptions' => array(
'' => 'Qualsiasi Agente',
'Agenti attivi: ' => array(
4 => 'Giovanni Verdi',
10 => 'Luigi Capoarea',
13 => 'Michela Passarin',
)
)
));
try this, it's works for me:
$select = new Zend_Form_Element_Select('select');
$options = Array(
'' => 'Qualsiasi Agente',
'agenti_attivi' => Array(
4 => 'Giovanni Verdi',
10 => 'Luigi Capoarea',
13 => 'Michela Passarin'
)
);
$this->addElements(array($xxxx,$select,$yyyy)); // $this : the form instance
and the result is:
<select id="select" name="select">
<option label="Qualsiasi Agente" value="">Qualsiasi Agente</option>
<optgroup label="agenti_attivi">
<option label="Giovanni Verdi" value="4">Giovanni Verdi</option>
<option label="Luigi Capoarea" value="10">Luigi Capoarea</option>
<option label="Michela Passarin" value="13">Michela Passarin</option>
</optgroup>
</select>
the problem is that the id attribute does not accept spaces and special special characters:
id="agente_id-optgroup-Agenti attivi: "
Zend is usually pretty good about rendering the proper html, given a doctype.
Try setting your doctype like this if you aren't already.
<?php
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->initView();
$viewRenderer->view->doctype('XHTML1_STRICT');
AND
<?php echo $this->doctype(); ?>
at the top of your layout
I don't have a install of ZF i can mess with easy, if this doesn't work ill setup a test environment.