I have a Wordpress website hosted on 20i. I'm almost certain that everything worked fine until I pointed the a records to get the website off its test domain and onto the actual one, this might be unrelated but I figured I'd mention it incase. Anyway for some reason my Ajax function works fine on desktop but not on mobile. When I look at it on mobile none of the posts are visible and if I select a filter nothing happens. Does anyone know what this could be? I've looked around for answers but I can't seem to find the solution.
Here's my code;
jQuery
// submit form function
jQuery('#form').on('submit', function(e){
e.preventDefault();
var $ = jQuery;
var filter = $('#form');
var form_data = $('#form').serializeArray();
$('#load_more').data('page', 1);
$.ajax({
url: ajax_url,
type: 'post',
data: form_data,
dataType: 'json',
error : function(response){
console.log(response);
},
success : function(response){
$('#loop').empty();
for( var i = 0; i < response.post_cont.length; i++ ){
var html =''+
'<div class="col-12 col-md-4 column">'+
'<a href="'+ response.post_cont[i].permalink +'">'+
'<div class="card" style="width: 100%;">'+
'<div class="post_image" style="background-image: url('+ response.post_cont[i].image +');"></div>'+
'<div class="card-body">'+
'<h5 class="card-title">'+ response.post_cont[i].title +'</h5>'+
'</div>'+
'</div>'+
'</a>'+
'</div>';
$('#loop').append(html);
}
}
});
});
php AJAX function
<?php
add_action('wp_ajax_nopriv_filter', 'filter');
add_action('wp_ajax_filter', 'filter');
// this function runs after it is called inside our_work_ajax.js
function filter(){
if( $_POST['type'] && !empty($_POST['type']) ){
$category = $_POST['type'];
}else{
$category = array( 'Assisted Needs/Residential', 'Commercial/Educational', 'Private Housing', 'Social-Housing' );
}
$args = array(
'post_type' => 'our_work',
'posts_per_page' => 9,
'orderby' => 'date',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $category
)
)
);
$query = new WP_Query( $args );
$no_of_posts = $query->found_posts;
if( $query->have_posts() ):
while( $query->have_posts() ): $query->the_post();
$main_field = get_field('Images');
$first_row = $main_field[0];
$img = $first_row['Image'];
$imgsize = $img['sizes']['large'];
// creating an array of content needed from array
$post_cont[] = array(
"permalink" => get_the_permalink(),
"image" => $imgsize,
"title" => get_the_title(),
);
endwhile;
endif;
// array getting the total number of posts
$max_posts[] = array(
"no_of_posts" => $no_of_posts
);
// converting arrays into json and submitting it to the ajax_url for the .js file
echo json_encode(array( "post_cont" => $post_cont, "max_posts" => $max_posts));
wp_reset_postdata();
die();
}
?>
HTML
<form action="" method="POST" id="form">
<div id="filters">
<div class="option">
<p>Assisted Needs/Residential</p>
<input type="checkbox" name="type[]" value="Assisted Needs/Residential">
</div>
<div class="option">
<p>Commercial/Educational</p>
<input type="checkbox" name="type[]" value="Commercial/Educational">
</div>
<div class="option">
<p>Private Housing</p>
<input type="checkbox" name="type[]" value="Private Housing">
</div>
<div class="option">
<p>Social Housing</p>
<input type="checkbox" name="type[]" value="Social Housing">
</div>
</div>
<input type="hidden" name="action" value="filter">
</form>
<div id="loop" class="row">
</div>
<script>
jQuery(document).ready(function($){
var inputs = $('#form .option input');
inputs.each(function(){
if( $(this).is(':checked') ){
$(this).parent().addClass('active');
}
});
$('#form').submit();
});
</script>
AJAX url inside functions.php
wp_localize_script( 'all_js', 'ajax_url', admin_url('admin-ajax.php') );
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");
}
i want to changes query_posts by clicking a link witch ajax and load new result in to my div
i use this code in single.php
By using the $_GET function at the top
if( !empty($_GET['key']) )
$meta_key=$_GET['key'];
else $meta_key= ''; // default
dropdown list
<form action="" method="get">
<select name="key" id="fromchange" class="style-select"onchange="if(this.value != 0) { this.form.submit(); }">
<option value="">""</option>
<option value="artist_artist" <?php if ($key == "artist_artist") { echo 'style="color:gray" selected'; } ?>> ACTOR</option>
<option value="artist_director" <?php if ($key == "artist_director") { echo 'style="color:gray" selected'; } ?>> DIRECTOR</option>
</select>
</form>
phpcode and div for new result is :
<div id="result">
<?php // ACTORS
$title1='>'. get_the_title() .'</a> ('.get_field('date').')';
$title2='>'. get_the_title() . ' ('.get_field('date').')';
$args_actor=array(
'post_type'=> 'post',
'cat' => '5',
'posts_per_page'=> -1,
'orderby' => 'title',
'order' => 'ASC',
);
$crew_query = null;
$crew_query = new WP_Query(array($args_actor,
'meta_query'=> array('relation' => 'OR',
array('key'=>$meta_key,'value'=> $title1,'compare'=>'LIKE'),
array('key'=>$meta_key,'value'=> $title2,'compare' => 'LIKE'))
));
if( $crew_query->have_posts() ) {
echo'<ul class="mpanel">';
while ($crew_query->have_posts()) : $crew_query->the_post();
include (TEMPLATEPATH . '/single-movie/content-list-movie-crew.php');
endwhile;echo '</ul>';}
else{
echo'<ul class="mpanel">';
include (TEMPLATEPATH . '/single-movie/movie-crew-else.php');
echo '</ul>';
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
</div>
how to run this code and change query by click with ajax in div ?
I have a custom taxonomy and I've added a category dropdown to the archive page to allow users to quickly switch between categories. I have the following code, which works in redirecting users to the new category that they choose. However, the dropdown always defaults to the first option in the <select>. How can I pass the selected <option> through and set it as the default value when a user switches categories?
<?php
$args = array(
'taxonomy' => 'custom_taxonomy',
'orderby' => 'name',
'show_count' => 1,
'hierarchical' => 1,
'title_li' => 'title'
);
<form id="categoriesform" action="<?php bloginfo('url'); ?>" method="post">
<div>
<?php $cats = get_categories($args); ?>
<select id="categories" name="custom_taxonomy">
<option value="allCategories">All Categories</option>
<?php foreach ($cats as $cat) : ?>
<option value="<?php echo get_term_link($cat, $cat->taxonomy) ?>">
<?php echo $cat->name ?></option>
<?php endforeach; ?>
</select>
</div>
</form>
<script>
jQuery(document).ready(function() {
jQuery('#categories').change(function() {
if (jQuery(this).val() == 'allCategories') {
window.location = 'http://example.com/all-categories';
} else {
window.location = jQuery(this).val();
}
});
});
</script>
First you need to get current category id via get_queried_object()->term_id; then you check and add selected in option.
<?php
$current=get_queried_object()->term_id;
$args = array(
'taxonomy' => 'custom_taxonomy',
'orderby' => 'name',
'show_count' => 1,
'hierarchical' => 1,
'title_li' => 'title'
);
<form id="categoriesform" action="<?php bloginfo('url'); ?>" method="post">
<div>
<?php $cats = get_categories($args); ?>
<select id="categories" name="custom_taxonomy">
<option value="allCategories">All Categories</option>
<?php foreach ($cats as $cat) : ?>
<option <?php echo ($current == $cat->term_id ? 'selected' : ''); ?> value="<?php echo get_term_link($cat, $cat->taxonomy) ?>">
<?php echo $cat->name ?></option>
<?php endforeach; ?>
</select>
</div>
</form>
<script>
jQuery(document).ready(function() {
jQuery('#categories').change(function() {
if (jQuery(this).val() == 'allCategories') {
window.location = 'http://example.com/all-categories';
} else {
window.location = jQuery(this).val();
}
});
});
</script>
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