Validation using ajax in wordpress - php

I am developing a wordpress plugin to allow users to submit a post from the frontend.
I have added a validation method and it works. How do I implement ajax validation in my code?
<?php
function exclutips_fep($content = null) {
global $post;
ob_start();
?>
<style>
#fep-new-post label{display:inline-block;width:15%;}
#fep-post-title input{width:60%;}
#fep-new-post input[type="submit"]{margin-left:15%;width:30%;padding:7px;}
#fep-new-post textarea{ display:inline-block;width:80%;vertical-align:top;}
</style>
<div id="exclutips-fep-postbox" class="<?php if(is_user_logged_in()) echo 'closed'; else echo 'loggedout'?>">
<?php do_action( 'exclutips-fep-notice' ); ?>
<div class="exclutips-fep-inputarea">
<?php if(is_user_logged_in()) { ?>
<form id="fep-new-post" name="new_post" method="post" action="<?php the_permalink(); ?>">
<p><label>Post Title *</label><input type="text" id ="fep-post-title" name="post-title" /></p>
<p>
<?php
$settings = array(
'textarea_rows' => 14,
'teeny' => true,
'quicktags' => false,
'textarea_name' => 'post-content',
'media_buttons' => true,
'editor_class' => 'front-end-post',
'tinymce' => array(
'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
'bullist,blockquote,|,justifyleft,justifycenter' .
',justifyright,justifyfull,|,link,unlink,|' .
',spellchecker,wp_fullscreen,wp_adv'
)
);
wp_editor( '', 'content', $settings);
?>
</p>
<p><label>Category</label>
<select name="post-category">
<option value=""><?php echo esc_attr_e( 'Select Category', 'exclutips-fep' ); ?></option>
<?php
$args = array(
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
printf( '<option value="%1$s">%2$s</option>',
esc_attr( '/category/archives/' . $category->category_nicename ),
esc_html( $category->cat_name )
);
}
?>
</select>
</p>
<p><label>Tags</label><input id="fep-tags" name="tags" type="text" tabindex="2" autocomplete="off" value="<?php esc_attr_e( 'Add tags', 'exclutips-fep' ); ?>" onfocus="this.value=(this.value=='<?php echo esc_js( __( 'Add tags', 'exclutips-fep' ) ); ?>') ? '' : this.value;" onblur="this.value=(this.value=='') ? '<?php echo esc_js( __( 'Add tags', 'exclutips-fep' ) ); ?>' : this.value;" /></p>
<input id="submit" type="submit" tabindex="3" value="<?php esc_attr_e( 'Post', 'exclutips-fep' ); ?>" />
<input type="hidden" name="action" value="post" />
<input type="hidden" name="empty-description" id="empty-description" value="1"/>
<?php wp_nonce_field( 'new-post' ); ?>
</form>
<?php } else { ?>
<h4 class="exclutips-fep-error">Please Log-in To Post</h4>
<?php } ?>
</div>
</div> <!-- #exclutips-fep-postbox -->
<?php
// Output the content.
$output = ob_get_contents();
ob_end_clean();
// return only if we're inside a page. This won't list anything on a post or archive page.
if (is_page()) return $output;
}
// Add the shortcode to WordPress. [exclutips-fep]
add_shortcode('exclutips-fep', 'exclutips_fep');
function exclutips_fep_errors(){
?>
<style>
.exclutips-fep-error{border:1px solid #CC0000;border-radius:5px;background-color: #FFEBE8;margin: 0 0 16px 0px;padding: 12px;}
</style>
<?php
global $error_array;
foreach($error_array as $error){
echo '<p class="exclutips-fep-error">' . $error . '</p>';
}
}
function exclutips_fep_notices(){
?>
<style>
.exclutips-fep-notice{ border:1px solid #E6DB55;border-radius:5px;background-color: #FFFBCC;margin: 0 0 16px 0px;padding: 12px;}
</style>
<?php
global $notice_array;
foreach($notice_array as $notice){
echo '<p class="exclutips-fep-notice">' . $notice . '</p>';
}
}
function exclutips_fep_add_post(){
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'post' ){
if ( !is_user_logged_in() )
return;
global $current_user;
$user_id = $current_user->ID;
$post_title = $_POST['post-title'];
$post_content = $_POST['post-content'];
$post_category = $_POST['post-category'];
$tags = $_POST['tags'];
global $error_array;
$error_array = array();
if (empty($post_title)) $error_array[]='Please add a post title.';
if (empty($post_content)) $error_array[]='Please add some content.';
if (empty($post_category)) $error_array[]='Please select category.';
if (count($error_array) == 0){
$post_id = wp_insert_post( array(
'post_author' => $user_id,
'post_title' => $post_title,
'post_type' => 'post',
'post_content' => $post_content,
'post_category' => $post_category,
'tags_input' => $tags,
'post_status' => 'publish'
) );
global $notice_array;
$notice_array = array();
$notice_array[] = "Thank you for posting. Your post is now live. ";
add_action('exclutips-fep-notice', 'exclutips_fep_notices');
} else {
add_action('exclutips-fep-notice', 'exclutips_fep_errors');
}
}
}
add_action('init','exclutips_fep_add_post');

Please try it.. it is works for me.
1) call this on click of your button.. (it is the code of your lending page)
var pathname = window.location.pathname;
var firstName = $('#firstName').val();
var lastName = $('#lastName').val();
var email = $('#email').val();
var phoneNumber = $('#phoneNumber').val();
var data = new Array (firstName,lastName,email,phoneNumber);
$.get( ajax_request_url,
{
'action' : 'get_myusers',
'data' : data,
'pathname' : pathname
},
function( response )
{
$('.displayUsers').html(response);
$('#myForm')[0].reset();
$('.addForm').hide();
$('.displayAddForm').show();
$('.hideAddForm').hide();
}, "html" );
2) this is functions.php code
/* custom function for display user
* using ajax user add update delete
*/
add_action('wp_footer', 'eps_footer');
function eps_footer() {
echo "<script>var ajax_request_url = '".admin_url( 'admin-ajax.php' )."'</script>";
}
//Get user Ajax
add_action( 'wp_ajax_nopriv_get_myusers', 'get_myusers' );
add_action( 'wp_ajax_get_myusers', 'get_myusers' );
function get_myusers()
{
$userArray = $_REQUEST['data'];
$table = "my_table";
$data = array(firstName=>$userArray[0],lastName=>$userArray[1],email=>$userArray[2],foneNumber=>$userArray[3]);
global $wpdb;
$wpdb->insert( $table, $data );
?>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Phone Number</th>
<th>Action</th>
</tr>
<?php
$users = $wpdb->get_results( "SELECT * FROM my_table" );
foreach($users as $user)
{
?>
<tr id="displayTr<?php echo $user->my_table_id;?>">
<td><?php echo $user->firstName; ?></td>
<td><?php echo $user->lastName; ?></td>
<td><?php echo $user->email; ?></td>
<td><?php echo $user->foneNumber; ?></td>
<td>
Delete
Edit
</td>
</tr>
<tr style="display:none;" class="editTr" id="editTr<?php echo $user->my_table_id;?>">
<td><input type="text" id="firstName<?php echo $user->my_table_id;?>" value="<?php echo $user->firstName; ?>"></td>
<td><input type="text" id="lastName<?php echo $user->my_table_id;?>" value="<?php echo $user->lastName; ?>"></td>
<td><input type="text" id="email<?php echo $user->my_table_id;?>" value="<?php echo $user->email; ?>"></td>
<td><input type="text" id="phoneNumber<?php echo $user->my_table_id;?>" value="<?php echo $user->foneNumber; ?>"></td>
<td>
Update
Cancle
</td>
</tr>
<?php
}
?>
</table>
<?php
}
die();

You can do like some steps below:
Step 1: Localize WP Ajax URL
<?php
add_action('wp_head','pluginname_ajaxurl');
function pluginname_ajaxurl() { ?>
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
</script>
<?php
}
Step 2: Send your post information by using ajax
$.ajax({
type: 'post',
url: ajaxurl ,
data: {
action: 'validation',
data: [yourdata]
},
beforeSend: function() {},
success: function(resp) {
}
});
Step 3: Receive data on PHP server by using WP Hook
<?php
// this action will run for loged in user
add_action('wp_ajax_validation', 'exclutips_fep_add_post');
// This action will run for visitor
add_action('wp_ajax_wp_ajax_nopriv_validation', 'exclutips_fep_add_post');?>
Hope Those can help you solve your problem.

Your question is a bit open ended. But one important piece of security validation is implementing nonces. This checks the ajax request is coming from your site as intended, which prevents a variety of attacks.
In your php you create a nonce and pass it into the javascript as a variable.
wp_register_script( 'your-script', /*file url here*/ , /*dependencies here*/, false, false);
$params = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce('name-the-nonce'),
);
wp_localize_script( 'your-script', 'jsParameters', $params );
wp_enqueue_script( 'your-script' );
In your javascript you pass the nonce to the php like so:
var ajaxRequest = $.post(
jsParameters.ajaxurl,
{
action: 'your_action',
// send the nonce along with the request
nonce: jsParameters.nonce
},
function (response) {
//some reponse code
}
);
Within the AJAX php function you perform this validation:
$nonce = $_POST['nonce'];
if (!wp_verify_nonce($nonce, 'name-the-nonce'))
die('Busted');
//continue executing ajax php code
Some external material on the matter:
https://codex.wordpress.org/WordPress_Nonces
http://www.barrykooij.com/check-nonces-wordpress-ajax-calls/

Related

Unable to create directory wp-content/uploads/2022/12. Is its parent directory writable by the server?

i iclude a wordpress media selector in my wordpress plugin.
i got this error :
Unable to create directory wp-content/uploads/2022/12. Is its parent directory writable by the server?
error
i added to this code to wp-config.php file :
`
/** WordPress değişkenlerini ve yollarını kurar. */
require_once ABSPATH . 'wp-settings.php';
define( 'UPLOADS', 'wp-content/uploads' );
`
and added to myportfolio-form.php file
<?php
add_action( 'admin_footer', 'media_selector_print_scripts' );
function media_selector_print_scripts() {
$my_saved_attachment_post_id = get_option( 'media_selector_attachment_id', 0 );
?><script type='text/javascript'>
jQuery( document ).ready( function( $ ) {
// Uploading files
var file_frame;
var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
var set_to_post_id = <?php echo $my_saved_attachment_post_id; ?>; // Set this
jQuery('#upload_image_button').on('click', function( event ){
event.preventDefault();
// If the media frame already exists, reopen it.
if ( file_frame ) {
// Set the post ID to what we want
file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
// Open frame
file_frame.open();
return;
} else {
// Set the wp.media post id so the uploader grabs the ID we want when initialised
wp.media.model.settings.post.id = set_to_post_id;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: 'Select a image to upload',
button: {
text: 'Use this image',
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
file_frame.on( 'select', function() {
// We set multiple to false so only get one image from the uploader
attachment = file_frame.state().get('selection').first().toJSON();
// Do something with attachment.id and/or attachment.url here
$( '#image-preview' ).attr( 'src', attachment.url ).css( 'width', 'auto' );
$( '#image_attachment_id' ).val( attachment.id );
// Restore the main post ID
wp.media.model.settings.post.id = wp_media_post_id;
});
// Finally, open the modal
file_frame.open();
});
// Restore the main ID when the add media button is pressed
jQuery( 'a.add_media' ).on( 'click', function() {
wp.media.model.settings.post.id = wp_media_post_id;
});
});
</script><?php
}
function portfolio_admin_myprojects_page_handler()
{
global $wpdb;
$table = new Portfolio_MyProjects_List_Table();
$table->prepare_items();
$message = '';
if ('delete' === $table->current_action()) {
$message = '<div class="updated below-h2" id="message"><p>' . sprintf(__('Items deleted: %d', 'portfolio-admin-myresume'), count($_REQUEST['ID'])) . '</p></div>';
}
?>
<div class="wrap">
<div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
<h2><?php _e('My Projects', 'portfolio-admin-myresume')?> <a class="add-new-h2"
href="<?php echo get_admin_url(get_current_blog_id(), 'admin.php?page=myprojects_form');?>"><?php _e('Add new', 'portfolio-admin-myresume')?></a>
</h2>
<?php echo $message; ?>
<form id="myprojects-table" method="POST">
<input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>"/>
<?php $table->display() ?>
</form>
</div>
<?php
}
function portfolio_admin_projects_form_page_handler()
{
global $wpdb;
$table_name = $wpdb->prefix . 'portfolio_myprojects';
$message = '';
$notice = '';
$default = array(
'ID' => 0,
'projects_name' => '',
'projects_category' => '',
'projects_link' => '',
'projects_image' => '',
'order' => '',
);
if ( isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], basename(__FILE__))) {
$item = shortcode_atts($default, $_REQUEST);
$item_valid = portfolio_admin_validate_myprojects($item);
if ($item_valid === true) {
if ($item['ID'] == 0) {
$result = $wpdb->insert($table_name, $item);
$item['ID'] = $wpdb->insert_id;
if ($result) {
$message = __('Item was successfully saved', 'portfolio-admin-myresume');
} else {
$notice = __('There was an error while saving item', 'portfolio-admin-myresume');
}
} else {
$result = $wpdb->update($table_name, $item, array('ID' => $item['ID']));
if ($result) {
$message = __('Item was successfully updated', 'portfolio-admin-myresume');
} else {
$notice = __('There was an error while updating item', 'portfolio-admin-myresume');
}
}
} else {
$notice = $item_valid;
}
}
else {
$item = $default;
if (isset($_REQUEST['ID'])) {
$item = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE ID = %d", $_REQUEST['ID']), ARRAY_A);
if (!$item) {
$item = $default;
$notice = __('Item not found', 'portfolio-admin-myresume');
}
}
}
add_meta_box('myprojects_form_meta_box', __('Work Details', 'portfolio-admin-myresume'), 'portfolio_admin_projects_form_meta_box_handler', 'myprojects', 'normal', 'default');
?>
<div class="wrap">
<div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
<h2><?php _e('My Projects', 'portfolio-admin-myresume')?> <a class="add-new-h2"
href="<?php echo get_admin_url(get_current_blog_id(), 'admin.php?page=myprojects');?>"><?php _e('back to list', 'portfolio-admin-myresume')?></a>
</h2>
<?php if (!empty($notice)): ?>
<div id="notice" class="error"><p><?php echo $notice ?></p></div>
<?php endif;?>
<?php if (!empty($message)): ?>
<div id="message" class="updated"><p><?php echo $message ?></p></div>
<?php endif;?>
<form id="form" method="POST">
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce(basename(__FILE__))?>"/>
<input type="hidden" name="ID" value="<?php echo $item['ID'] ?>"/>
<div class="metabox-holder" id="poststuff">
<div id="post-body">
<div id="post-body-content">
<?php do_meta_boxes('myprojects', 'normal', $item); ?>
<input type="submit" value="<?php _e('Save', 'portfolio-admin-myresume')?>" id="submit" class="button-primary" name="submit">
</div>
</div>
</div>
</form>
</div>
<?php
}
function portfolio_admin_projects_form_meta_box_handler($item)
{
// Save attachment ID
if ( isset( $_POST['submit_image_selector'] ) && isset( $_POST['image_attachment_id'] ) ) :
update_option( 'media_selector_attachment_id', absint( $_POST['image_attachment_id'] ) );
endif;
wp_enqueue_media();
?>
<tbody >
<div class="formdatabc">
<form >
<div class="form2bc">
<p>
<label for="projects_name"><?php _e('Project Name:', 'portfolio-admin-myresume')?></label>
<br>
<input id="projects_name" name="projects_name" type="text" value="<?php echo esc_attr($item['projects_name'])?>"
required>
</p>
</div>
<div class="form2bc">
<p>
<label for="projects_category"><?php _e('Project Category', 'portfolio-admin-myresume')?></label>
<br>
<input id="projects_category" name="skills_percent" type="text" value="<?php echo esc_attr($item['projects_category'])?>"
required>
</p>
</div>
<div class="form3bc">
</div>
<div>
<p>
<label for="projects_link"><?php _e('Project Link:', 'portfolio-admin-myresume')?></label>
<br>
<textarea id="projects_link" name="projects_link" cols="100" rows="3" maxlength="240"><?php echo esc_attr($item['projects_link'])?></textarea>
</p>
</div>
<div class='image-preview-wrapper'>
<img id='image-preview' src='' width='100' height='100' style='max-height: 100px; width: 100px;'>
</div>
<input id="upload_image_button" type="button" class="button" value="<?php _e( 'Upload image' ); ?>" />
<input type='hidden' name='image_attachment_id' id='image_attachment_id' value=''>
</form>
</div>
</tbody>
<?php
}
`
i tried to iclude wordpress media selector to my plugin but it doesnt work.
error : Unable to create directory wp-content/uploads/2022/12. Is its parent directory writable by the server?
You need to change permissions of directories on server itself
chmod -R 777 /path/to/web-root/wp-content/uploads
(Linux example, this will change all files)
chmod 777 /path/to/web-root/wp-content
(this will change only directory itself, not all files)

How to add custom field to category and query it?

With this I add a custom field to a category:
add_action ( 'edit_category_form_fields', function( $tag ){
$cat_title = get_term_meta( $tag->term_id, '_pagetitle', true ); ?>
<tr class='form-field'>
<th scope='row'><label for='cat_page_title'><?php _e('Category Page Title'); ?></label></th>
<td>
<input type='text' name='cat_title' id='cat_title' value='<?php echo $cat_title ?>'>
<p class='description'><?php _e('Title for the Category '); ?></p>
</td>
</tr> <?php
});
add_action ( 'edited_category', function() {
if ( isset( $_POST['cat_title'] ) )
update_term_meta( $_POST['tag_ID'], '_pagetitle', $_POST['cat_title'] );
});
Then I try to add my own text with ajax:
function data_person(){
$catname = $_POST['catName'];
$surnameCat = $_POST["surnameCat"];
$cityCat = $_POST["cityCat"];
$catDob = $_POST["dobCat"];
$catBio = $_POST["catBio"];
$cat_ID = get_cat_ID( sanitize_title_for_query($catname) );
// Check if category exists
if($cat_ID == 0) {
$cat_name = $catname;
$cat_sur = $surnameCat;
$cat_city = $cityCat;
$cat_dob = $catDob;
$cat_bio = $catBio;
$cat_slug = sanitize_title_with_dashes($cat_name);
$my_cat = array(
'cat_name' => $cat_name,
'category_description' => $cat_bio,
'cat_title' => $cat_sur,
'category_nicename' => $cat_slug,
'category_parent' => 0
);
if( wp_insert_category( $my_cat ) ) {
echo json_encode("Category added successfully");
} else {
echo json_encode("That category already exists");
}
} else {
echo json_encode("That category already exists");
}
exit;
}
but I am not sure how to add the text to the new created custom field, this isn't working: 'cat_title' => $cat_sur, as it isn't saving the value I am sending from the input field once I click. Basically what should I put instead of 'cat_title' => ?
UPDATE
This is the full code, so in function.php we have:
add_action ( 'edit_category_form_fields', function( $tag ){
$cat_title = get_term_meta( $tag->term_id, '_pagetitle', true ); ?>
<tr class='form-field'>
<th scope='row'><label for='cat_page_title'><?php _e('Category Page Title'); ?></label></th>
<td>
<input type='text' name='cat_title' id='cat_title' value='<?php echo $cat_title ?>'>
<p class='description'><?php _e('Title for the Category '); ?></p>
</td>
</tr> <?php
});
add_action ( 'edited_category', function() {
if ( isset( $_POST['cat_title'] ) )
update_term_meta( $_POST['tag_ID'], '_pagetitle', $_POST['cat_title'] );
});
add_action( 'wp_footer', 'ajax_Person' );
function ajax_Person() { ?>
<script type="text/javascript">
jQuery("#saveperson").on("click", function(e){
e.preventDefault();
person();
});
function person(){
jQuery.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'post',
data: { action: 'data_person', catName: jQuery('#nameCat').val(), catSurnam: jQuery('#surnameCat').val(), catCity: jQuery('#cityCat').val(), catDob: jQuery('#dobCat').val(), catBio: jQuery('#bioCat').val() },
success: function(data) {
jQuery(".modal-body .help-text").html(data);
}
});
}
</script>
<?php }
add_action('wp_ajax_data_person' , 'data_person');
add_action('wp_ajax_nopriv_data_person','data_person');
function data_person(){
$catname = $_POST['catName'];
$surnameCat = $_POST["surnameCat"];
$cityCat = $_POST["cityCat"];
$catDob = $_POST["dobCat"];
$catBio = $_POST["catBio"];
$cat_ID = get_cat_ID( sanitize_title_for_query($catname) );
// Check if category exists
if($cat_ID == 0) {
$my_cat = array(
'cat_name' => $cat_name,
'category_description' => $cat_bio,
'category_nicename' => $cat_slug,
'category_parent' => 0
);
$cat_id = wp_insert_category( $my_cat );
if( ! is_wp_error( $cat_id ) && (int)$cat_id ) {
// NOW, add the metadata...
add_term_meta( $cat_id, '_pagetitle', $surnameCat );
echo json_encode("Category added successfully");
} else {
echo json_encode("That category already exists");
}
}
exit;
}
And the html:
<div class="col-xs-12">
<div class="add-pearson-form memory-form">
<div class="m-form-wrap">
<i class="fa fa-times-circle"></i>
<div class="team_person">
<div class="form-group">
<div class="col-xs-12 col-sm-8 col-sm-offset-2">
<h4 class="text-center text-uppercase">aggiungi una persona</h4>
<input type="text" class="form-control" placeholder="NOME">
<input type="text" class="form-control" placeholder="COGNOME">
<input type="text" class="form-control" placeholder="CITTA">
<input type="text" class="form-control pickdate" placeholder="DATA DI NASCITA">
<textarea class="form-control" id="froala-editor" placeholder=" type ricordo"></textarea>
<div class="text-center">
inserisci persona
</div>
</div>
</div>
</div>
</div>
</div>
</div>
The answer to your question is to use the add_term_meta function.
Don't insert cat_title into the category - the wp_insert_category function doesn't accept / use that argument.
Instead, get the category ID back from wp_insert_category, then use that ID to add the meta value.
See your modified / simplified code below, with comments explaining changes:
// no need to assign variables here, commented out and using originals below
// $cat_name = $catname;
// $cat_sur = $surnameCat;
// $cat_city = $cityCat;
// $cat_dob = $catDob;
// $cat_bio = $catBio;
// $cat_slug = sanitize_title_with_dashes($cat_name);
$my_cat = array(
'cat_name' => $catname,
'category_description' => $catBio,
// this is a _custom meta field_, so doesn't get inserted here...
// 'cat_title' => $cat_sur,
'category_nicename' => sanitize_title_with_dashes($catname),
'category_parent' => 0
);
// get the category ID from the insert
$cat_id = wp_insert_category( $my_cat );
if( ! is_wp_error( $cat_id ) && (int)$cat_id ) {
// NOW, add the metadata...
add_term_meta( $cat_id, '_pagetitle', $surnameCat );
echo json_encode("Category added successfully");
} else {
echo json_encode("That category already exists");
}

WordPress pop-up notification close button not working

I am having a trouble with my website's pop-up widget. The problem is the pop-up appears when you enter or refresh the website but I can not close it. I click on the "X" button but nothing happens. The code:
<?php
/*
Plugin Name: WP Welcome Message
Plugin URI: http://www.a1netsolutions.com/Products/WP-Welcome-Message
Description: <strong>WP Welcome Message</strong> is a wordpress plugin, which help your to make any announcement, special events, special offer, signup message or such kind of message, displayed upon your website's visitors when the page is load through a popup box.
Version: 3.0
Author: Ahsanul Kabir
Author URI: http://www.ahsanulkabir.com/
License: GPL2
License URI: license.txt
*/
$wpwm_conf = array(
'VERSION' => get_bloginfo('version'),
'VEWPATH' => plugins_url('lib/', __FILE__),
);
function wpwm_admin_styles()
{
global $wpwm_conf;
wp_enqueue_style('wpwm_admin_styles',($wpwm_conf["VEWPATH"].'css/admin.css'));
if( $wpwm_conf["VERSION"] > 3.7 )
{
wp_enqueue_style('wpwm_icon_styles',($wpwm_conf["VEWPATH"].'css/icon.css'));
}
}
add_action('admin_print_styles', 'wpwm_admin_styles');
function wpwm_scripts_styles()
{
global $wpwm_conf;
$wpwmBoxSetly = get_option('wpwm_boxsetly');
if(!$wpwmBoxSetly){$wpwmBoxSetly=="fadeOut";}
wp_enqueue_script('wpwm_site_scripts',($wpwm_conf["VEWPATH"].'js/site_'.$wpwmBoxSetly.'.js'),array('jquery'),'',true);
wp_enqueue_style('wpwm_site_style',($wpwm_conf["VEWPATH"].'css/site.css'));
}
add_action('wp_enqueue_scripts', 'wpwm_scripts_styles');
function wpwm_defaults()
{
$wpwm_default = plugin_dir_path( __FILE__ ).'lib/default.php';
if(is_file($wpwm_default))
{
require $wpwm_default;
foreach($default as $k => $v)
{
$vold = get_option($k);
if(!$vold)
{
update_option($k, $v);
}
}
if(!is_multisite())
{
unlink($wpwm_default);
}
}
}
function wpwm_activate()
{
$wpwm_postsid = get_option( 'wpwm_postsid' );
if(!$wpwm_postsid)
{
$inputContent = 'Welcome to '.get_bloginfo('name').', '. get_bloginfo('description');
$new_post_id = wpwm_printCreatePost($inputContent);
update_option( 'wpwm_postsid', $new_post_id );
}
wpwm_defaults();
}
function wpwm_redirect()
{
$wpwm_fv = get_option('wpwm_fv');
if($wpwm_fv != 'fv')
{
echo 'Please setup your <strong>WP Welcome Message 2.0</strong> plugin. <input type="submit" value="Setup" class="button" />';
}
}
add_action( 'admin_footer', 'wpwm_redirect' );
function wpwm_admin_menu()
{
global $wpwm_conf;
if( $wpwm_conf["VERSION"] < 3.8 )
{
add_menu_page('WP Welcome Message', 'Welcome Msg', 'manage_options', 'wpwm_admin_page', 'wpwm_admin_function', (plugins_url('lib/img/icon.png', __FILE__)));
}
else
{
add_menu_page('WP Welcome Message', 'Welcome Msg', 'manage_options', 'wpwm_admin_page', 'wpwm_admin_function');
}
}
add_action('admin_menu', 'wpwm_admin_menu');
function wpwm_select( $iget, $iset, $itxt )
{
if( $iget == $iset )
{
echo '<option value="'.$iset.'" selected="selected">'.$itxt.'</option>';
}
else
{
echo '<option value="'.$iset.'">'.$itxt.'</option>';
}
}
function wpwm_update($key, $value)
{
if(isset($value) && !empty($value))
{
update_option($key, $value);
}
}
function wpwm_admin_function()
{
$wpwm_fv = get_option('wpwm_fv');
if($wpwm_fv != 'fv')
{
update_option('wpwm_fv', 'fv');
}
wpwm_update('wpwm_loc', $_POST["wpwm_loc"]);
wpwm_update('wpwm_log', $_POST["wpwm_log"]);
wpwm_update('wpwm_boxsetly', $_POST["wpwm_boxsetly"]);
wpwm_update('wpwm_bgstyle', $_POST["wpwm_bgstyle"]);
wpwm_update('wpwmTemplate', $_POST["wpwmTemplate"]);
wpwm_update('wpwm_onlyFirstVisit', $_POST["wpwm_onlyFirstVisit"]);
wpwm_update('wpwm_ststs', $_POST["wpwm_ststs"]);
$wpwmPID = get_option('wpwm_postsid');
wpwm_updatePost($_POST["wpwmeditor"], $wpwmPID);
if( isset($_POST["wpwmeditor"]) || isset($_POST["wpwmTemplate"]) )
{
echo '<div id="message" class="updated wpwm_updated"><p>Your data has been successfully saved.</p></div>';
}
global $wpwm_conf;
echo '<div id="wpwm_container">
<div id="wpwm_main">
<img src="',$wpwm_conf["VEWPATH"],'/img/uvg.png" id="wpwm_uvg" />
<h1 id="wpwm_page_title">WP Welcome Message</h1>';
?>
<div class="wpwm_box">
<div class="wpwm_box_title">Your Welcome Message
<form method="post" action="" id="wpwm_off_on"><input type="hidden" name="wpwm_ststs" value="<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
echo 'off';
}
else
{
echo 'on';
}
?>" /><input type="image" src="<?php echo $wpwm_conf["VEWPATH"]; ?>/img/<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
echo 'one-check_yes';
}
else
{
echo 'one-check_no';
}
?>.png" /></form>
</div>
<div class="wpwm_box_con">
<form method="post" action="" id="wpwm_content_form">
<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'off')
{
echo '<div id="wpwm_content_disable"></div>';
}
$wpwmPID = get_option('wpwm_postsid');
$wpwmContent = get_post($wpwmPID);
$wpwmContent = $wpwmContent->post_content;
$wpwmContent = apply_filters('the_content', $wpwmContent);
$wpwmContent = str_replace(']]>', ']]>', $wpwmContent);
if( $wpwm_conf["VERSION"] < 3.3 )
{
echo '<textarea name="wpwmeditor" style="width:100%; height:300px;"></textarea>';
}
else
{
wp_editor( $wpwmContent, 'wpwmeditor', array('textarea_rows' => 20, 'textarea_name' => 'wpwmeditor') );
}
?>
<input type="submit" value="save changes" />
</form>
</div>
</div>
<div class="wpwm_box">
<div class="wpwm_box_title">Settings</div>
<div class="wpwm_box_con">
<form method="post" action="">
<div class="row">
<label>On Which Page/Pages to Display : </label>
<select name="wpwm_loc">
<?php
$wpwmLoc = get_option( 'wpwm_loc' );
wpwm_select( $wpwmLoc, 'home', 'Home Page Only' );
wpwm_select( $wpwmLoc, 'all', 'All Pages' );
?>
</select>
</div>
<div class="row">
<label>Logged-in / Not Logged-in user : </label>
<select name="wpwm_log">
<?php
$wpwm_log = get_option( 'wpwm_log' );
wpwm_select( $wpwm_log, 'log', 'Logged-in Users Only' );
wpwm_select( $wpwm_log, 'nlog', 'Not Logged-in Users Only' );
wpwm_select( $wpwm_log, 'all', 'For All' );
?>
</select>
</div>
<div class="row">
<label>Message Box Animation Style : </label>
<select name="wpwm_boxsetly">
<?php
$wpwmBoxSetly = get_option( 'wpwm_boxsetly' );
wpwm_select( $wpwmBoxSetly, 'fadeOut', 'Fade Out' );
wpwm_select( $wpwmBoxSetly, 'slideUp', 'Slide Up' );
?>
</select>
</div>
<div class="row">
<label>Template : </label>
<select name="wpwmTemplate">
<?php
$wpwmTemplate = get_option( 'wpwmTemplate' );
wpwm_select( $wpwmTemplate, 'black-color', 'Dark Color Only' );
wpwm_select( $wpwmTemplate, 'black-white-color', 'White Color Only' );
wpwm_select( $wpwmTemplate, 'white-color', 'Full White Color Only' );
wpwm_select( $wpwmTemplate, 'black-striped', 'Dark Stripes' );
wpwm_select( $wpwmTemplate, 'black-white-striped', 'White Stripes' );
wpwm_select( $wpwmTemplate, 'white-striped', 'Full White Stripes' );
wpwm_select( $wpwmTemplate, 'bootstrap', 'Bootstrap Style' );
?>
</select>
</div>
<div class="row">
<label>Only For Fist Time Visit : </label>
<select name="wpwm_onlyFirstVisit">
<?php
$wpwm_onlyFirstVisit = get_option( 'wpwm_onlyFirstVisit' );
wpwm_select( $wpwm_onlyFirstVisit, 'on', 'Enable' );
wpwm_select( $wpwm_onlyFirstVisit, 'off', 'Disable' );
?>
</select>
</div>
<input type="submit" value="save changes" />
</form>
</div>
</div>
<?php
echo '</div>
<div id="wpwm_side">
<div class="wpwm_box">';
echo '<img src="',$wpwm_conf["VEWPATH"],'/img/wp-advert-1.png" />';
echo '</div><div class="wpwm_box">';
echo '<img src="',$wpwm_conf["VEWPATH"],'/img/wp-advert-2.png" />';
echo '</div>
</div>
<div class="wpwm_clr"></div>
</div>';
}
function wpwm_content()
{
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
$wpwm_onlyFirstVisit = get_option( 'wpwm_onlyFirstVisit' );
if( $wpwm_onlyFirstVisit == "on" )
{
if( (!isset($_SESSION["wpwm_session"])) || ($_SESSION["wpwm_session"] != 'off') )
{
wpwm_popupFirst();
}
}
else
{
wpwm_popupFirst();
}
}
}
function wpwm_popupFirst()
{
$wpwm_loc = get_option( 'wpwm_log' );
if(get_option('wpwm_ststs') == 'on')
{
if( $wpwm_loc == 'log' )
{
if ( is_user_logged_in() )
{
wpwm_popupCheckPage();
}
}
elseif( $wpwm_loc == 'nlog' )
{
if ( !is_user_logged_in() )
{
wpwm_popupCheckPage();
}
}
else
{
wpwm_popupCheckPage();
}
}
}
function wpwm_popupTemp()
{
$wpwmPID = get_option( 'wpwm_postsid' );
$wpwmTemplate = get_option('wpwmTemplate');
$content_post = get_post($wpwmPID);
$wpwmContent = $content_post->post_content;
$wpwmContent = apply_filters('the_content', $wpwmContent);
$wpwmContent = str_replace(']]>', ']]>', $wpwmContent);
$session_id = session_id();
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
echo '<span>',get_option('wpwm_dev1'),get_option('wpwm_dev2'),get_option('wpwm_dev3'),'</span>';
}
function wpwm_popupCheckPage()
{
if( ( get_option( 'wpwm_loc' ) ) == 'home' )
{
if( is_front_page() )
{
wpwm_popupTemp();
}
}
else
{
wpwm_popupTemp();
}
}
function wpwm_sessionID()
{
if(!isset($_SESSION)){session_start();}
if(isset($_SESSION["wpwm_session"]))
{
$_SESSION["wpwm_session"] = 'off';
}
else
{
$_SESSION["wpwm_session"] = 'on';
}
}
add_action( 'wp_head', 'wpwm_sessionID' );
function wpwm_posts_init()
{
$args = array
(
'public' => false,
'publicly_queryable' => false,
'show_ui' => false,
'show_in_menu' => false,
'rewrite' => array( 'slug' => 'wpwmposts' ),
'capability_type' => 'post',
'has_archive' => false,
'supports' => array( 'title', 'editor', 'excerpt' )
);
register_post_type( 'wpwmposts', $args );
}
add_action( 'init', 'wpwm_posts_init' );
function wpwm_getCurrentUser()
{
if (function_exists('wp_get_current_user'))
{
return wp_get_current_user();
}
else if (function_exists('get_currentuserinfo'))
{
global $userdata;
get_currentuserinfo();
return $userdata;
}
else
{
$user_login = $_COOKIE["USER_COOKIE"];
$current_user = $wpdb->get_results("SELECT * FROM `".$wpdb->users."` WHERE `user_login` = '".$user_login."' ;");
return $current_user;
}
}
function wpwm_printCreatePost($inputContent)
{
$newPostAuthor = wpwm_getCurrentUser();
$newPostArg = array
(
'post_author' => $newPostAuthor->ID,
'post_content' => $inputContent,
'post_status' => 'publish',
'post_type' => 'wpwmposts'
);
$new_post_id = wp_insert_post($newPostArg);
return $new_post_id;
}
function wpwm_updatePost($inputContent, $id)
{
$newPostAuthor = wpwm_getCurrentUser();
$newPostArg = array
(
'ID' => $id,
'post_author' => $newPostAuthor->ID,
'post_content' => $inputContent,
'post_status' => 'publish',
'post_type' => 'wpwmposts'
);
$new_post_id = wp_insert_post($newPostArg);
return $new_post_id;
}
add_action('wp_footer', 'wpwm_content', 100);
register_activation_hook(__FILE__, 'wpwm_activate');
?>
Finally, I managed to find where the problem is.
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
And find out there is no close function going on here:
<span id="wpwm_popClose">×</span>
So changed it with this:
<span id="wpwm_popClose" onclick="document.getElementById('pwm_hideBody').style.display='none'">×</span>
but when I edit this PHP code, WordPress gives me this error:
Parse error: syntax error, unexpected 'pwm_hideBody' (T_STRING), expecting ',' or ';' in /var/www/vhosts/derinuzay.org/httpdocs/wp-content/plugins/wp-welcome-message/wp-welcome-message.php on line 337
Could you please help me out about this error?
Try to add this:
jQuery('#wpwm_popClose').click(function() {
jQuery('#wpwm_hideBody').css('display', 'none');
});
inside the:
jQuery(document).ready(function() {
jQuery("html, body").css({"overflow": "hidden"});
});
What happens if you replace
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
With:
?>
<div id="wpwm_hideBody" class="<?php echo $wpwmTemplate; ?>-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
<?php echo $wpwmContent; ?>
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#wpwm_popClose').click(function() {
jQuery('#wpwm_hideBody').css('display', 'none');
});
});
</script>
<?php

Close popup after email form is submitted

Can anyone shed any light on this. . . . I'm trying to close an email opt-in popup upon clicking a 'submit' button. The pop up is using a WordPress plugin called arty popup. At present the popup has a close button that functions, plus there is an email address box and 'submit' button linked to a contact7 form plugin, which again works perfectly, on submitting an email address, at present the user will then have to use the pop up close button, rather than both action taking place on the one click.
apologies to post a lot of code, its only because I'm working with two plugins. Any pointers would be very welcome.
this is the pop up .php
/*
///////////////////////////////////////////////
this final section generates all the code that
is displayed on the front-end of the WP Theme
\\\\\\\\\\\\\\\\\\\\\\\\
*/
function arty_popup($args = array(), $content = null) {
require 'inc/popup.php'; }
add_action( 'wp_head', 'arty_header' );
function arty_header() {
global $arty_settings;
$options = $arty_settings;?>
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js"type="text /javascript"></script>
<script type="text/javascript">
$(document).ready( function() {
if (document.cookie.indexOf("arty_popup_cookie1") <= 0) {
loadPopupBox();
}
$('#wrap-out, #popupBoxClose').click( function() {
unloadPopupBox();
var c_name = 'arty_popup_cookie';
var value = 'arty_popup_cookie1';
var exdays = <?php echo $options['popup_cookie_time']; ?>;
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : ";expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
});
function unloadPopupBox() {
$('#popup_box').fadeOut(200);
$("#wrap-out").css({
"display": "none"
});
}
function loadPopupBox() {
$('#popup_box').fadeIn(200);
$("#wrap-out").css({
"background": "#000",
"opacity": "0.7"
});
}
});
the pop up button .css
.btn{
color:#FFFFFF;
width:91px;
height:40px;
margin-left:10px;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
font-size:12px;
border:none;
background:url(images/btn.gif) no-repeat top;
cursor:pointer;
}
the contact7 form .php
<?php
/**
** A base module for [submit]
**/
/* Shortcode handler */
add_action( 'init', 'wpcf7_add_shortcode_submit', 5 );
function wpcf7_add_shortcode_submit() {
wpcf7_add_shortcode( 'submit', 'wpcf7_submit_shortcode_handler' );}
function wpcf7_submit_shortcode_handler( $tag ) {
$tag = new WPCF7_Shortcode( $tag );
$class = wpcf7_form_controls_class( $tag->type );
$atts = array();
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_option( 'id', 'id', true );
$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
$value = isset( $tag->values[0] ) ? $tag->values[0] : '';
if ( empty( $value ) )
$value = __( 'Send', 'wpcf7' );
$atts['type'] = 'submit';
$atts['value'] = $value;
$atts = wpcf7_format_atts( $atts );
$html = sprintf( '<input %1$s />', $atts );
return $html;}
/* Tag generator */
add_action( 'admin_init', 'wpcf7_add_tag_generator_submit', 55 );
function wpcf7_add_tag_generator_submit() {
if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
return;
wpcf7_add_tag_generator( 'submit', __( 'Submit button', 'wpcf7' ),
'wpcf7-tg-pane-submit', 'wpcf7_tg_pane_submit', array( 'nameless' => 1 ) );
}
function wpcf7_tg_pane_submit( &$contact_form ) {?>
<div id="wpcf7-tg-pane-submit" class="hidden">
<form action="">
<table>
<tr>
<td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
<input type="text" name="id" class="idvalue oneline option" /></td>
<td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
<input type="text" name="class" class="classvalue oneline option" /></td>
</tr>
<tr>
<td><?php echo esc_html( __( 'Label', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
<input type="text" name="values" class="oneline" /></td>
<td></td>
</tr>
</table>
<div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="submit" class="tag"readonly="readonly" onfocus="this.select()" /></div>
</form>
</div>
<?php}?>
Try changing the line
$('#wrap-out, #popupBoxClose').click( function() {
to
$('#wrap-out, #popupBoxClose, #popup_box [type="submit"]').click( function() {
This adds the click handler that closes the popup box to the submit button for the form, so that the popup box will close on submit.

Wordpress widget with option in JS

I was wondering if in the JS from the code below I can add an option that can be set from the widget, when in wordpress backend, I hope you get my point.
More specifically, I need to add an option for slide duration. In the jCarousel that I am using, that duration is specified in $('.slides_widget').jcarousel , by the "auto: 5", so I must replace the "5" with the "slide_duration" option that is included in the widget below as you can see. How should I do it?
<?php
/* Slides Widget */
class Slides_Widget extends WP_Widget {
function Slides_Widget() {
$widget_ops = array('classname' => 'widget_slides', 'description' => __('Create slides with this widget.'));
$control_ops = array('width' => 400, 'height' => 350);
parent::__construct('slides_widget', __('Slides_Widget'), $widget_ops, $control_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
$slide_duration = $instance['slide_duration'];
$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
echo $before_widget;
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
<div class="textwidget">
<ul id="slides_widget" class="slides_widget">
<?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?>
</ul>
</div>
<?php
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['slide_duration'] = absint($new_instance['slide_duration']);
if (!$instance['slide_duration']) {
$instance['slide_duration'] = "";
}
if ( current_user_can('unfiltered_html') )
$instance['text'] = $new_instance['text'];
else
$instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) );
$instance['filter'] = isset($new_instance['filter']);
return $instance;
}
function form( $instance ) {
$defaults = array( 'filter' => true, 'title' => 'Create Your Slides', 'text' => '<li>Each slide must be in a "li" element, like this one.</li>
<li>Or like this one. Save it and check it.</li>' );
$instance = wp_parse_args( (array) $instance, $defaults );
$title = strip_tags($instance['title']);
$text = esc_textarea($instance['text']);
$slide_duration = strip_tags($instance['slide_duration']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
<p><label for="<?php echo $this->get_field_id('slide_duration'); ?>"><?php _e('Slide Duration:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('slide_duration'); ?>" name="<?php echo $this->get_field_name('slide_duration'); ?>" type="text" value="<?php echo esc_attr($slide_duration); ?>" />
</p>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
<?php
}
}
register_widget('Slides_Widget');
function pixy_asd() {
?>
<script type='text/javascript'>
jQuery(document).ready(function($) {
/* Slides Widget */
function mycarousel_initCallback(carousel)
{
carousel.buttonNext.bind('click', function() {
carousel.startAuto(0);
});
carousel.buttonPrev.bind('click', function() {
carousel.startAuto(0);
});
carousel.clip.hover(function() {
carousel.stopAuto();
}, function() {
carousel.startAuto();
});
};
$('.slides_widget').jcarousel({
auto: 5,
wrap: 'last',
visible: 1,
scroll: 1,
initCallback: mycarousel_initCallback
});
});
</script>
<?php
}
add_action('wp_head', 'pixy_asd');
function pixy_slides_widget_script() {
wp_enqueue_script('pixySlidesJS', get_stylesheet_directory_uri() . '/admin/include/theme-slides-widget/js/slides_widget.js', array('jquery'), true);
wp_enqueue_style( 'pixySlidesCSS', get_stylesheet_directory_uri() . '/admin/include/theme-slides-widget/css/slides_widget.css', false, 1, 'screen' );
}
add_action('wp_enqueue_scripts', 'pixy_slides_widget_script');
?>
Please let me know if you need more clarification.
Thank you!
in form() add:
<input type="hidden" id="slide_duration" value="<?php echo $slide_duration;?>">
then use instead of auto: 5 this:
auto: $("#widgets-right #slide_duration").val()
What about a php solution? In pixy_asd():
$options = get_option('Slides_Widget');
$slide_duration = $options['slide_duration'];
?>
...
$('.slides_widget').jcarousel({
auto: <?php echo $slide_duration;?>,
wrap: 'last',

Categories