Within wordpress and using ACF Pro, I'm merging multiple Songkick XML feeds with PHP, attaching an artist name to them (annoyingly each feed doesn't include the artist name), and ordering them by the event date.
I've managed to put this all together (with help from different questions on here) using separate steps, but the page is loading very slowly, so I wondered if there was a way of streamlining or merging some of the steps?
With the code below I am:
Fetching multiple XML feeds (sing an ACF fields from other pages on the site)
Attaching an artist name to each feed
Merging the feeds (whilst removing some of the data to try and speed
up the processing time)
Outputting the information into a table while ordering by date
My code below:
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => 'artists'
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) : $artistFeedCount = 0; while ( $parent->have_posts() ) : $parent->the_post(); if( get_page_template_slug() == 'template-artist.php' && 'publish' === get_post_status() ) {
$singleArtistName = get_the_title();
$singleArtistSongkickRSS = 'https://api.songkick.com/api/3.0/artists/' . get_field('artist_songkick_id') . '/calendar.xml?apikey=XXXXXXXXXXXXXXXX';
$SongkickEvents[]=$singleArtistName;
$SongkickEvents[$singleArtistSongkickRSS] = $SongkickEvents[$artistFeedCount];
unset($SongkickEvents[$artistFeedCount]);
$artistFeedCount++;
?>
<?php }; endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
<?php
$eventsDom = new DOMDocument();
$eventsDom->appendChild($eventsDom->createElement('events'));
foreach ($SongkickEvents as $artist_dates => $artist_name ) {
$eventsAddDom = new DOMDocument();
$eventsAddDom->load($artist_dates);
$events = $eventsAddDom->getElementsByTagName('event');
if ($eventsAddDom->documentElement) {
foreach ($events as $event) {
$eventsDom->documentElement->appendChild(
$eventsDom->importNode($event, TRUE)
);
$artistName = $eventsDom->createElement('mainartist', $artist_name);
foreach($eventsDom->getElementsByTagName('event') as $singleEvent) {
$singleEvent->appendChild($artistName);
}
foreach($eventsDom->getElementsByTagName('performance') as $singlePerformance) {
$singlePerformance->parentNode->removeChild($singlePerformance);
}
}
}
}
$newXML = $eventsDom->saveXml();
$LiveDates = simplexml_load_string($newXML);
$eventsArr=array();
foreach($LiveDates->event as $eventsArrSingle)
{
$eventsArr[]=$eventsArrSingle;
}
usort($eventsArr,function($dstart,$dend){
return strtotime($dstart->start['date'])-strtotime($dend->start['date']);
});
foreach($eventsArr as $eventsArrSingle) { ?>
<div class="event-row <?php $eventStatus = $eventsArrSingle['status']; if($eventStatus == 'cancelled' || $eventStatus == 'postponed'): echo 'cancelled'; endif; ?>">
<div class="event-block event-date">
<span><?php $eventDate=$eventsArrSingle->start['date']; echo date("d", strtotime($eventDate)); ?></span>
<?php echo date("M", strtotime($eventDate)); ?>
</div>
<div class="event-block event-info">
<span><?php echo $eventsArrSingle->mainartist; ?></span>
<?php if($eventsArrSingle->venue['displayName'] != 'Unknown venue'): echo $eventsArrSingle->venue['displayName'] . ', '; endif; ?><?php echo $eventsArrSingle->venue->metroArea['displayName']; ?>
</div>
<div class="event-block event-button">
<span><?php if($eventStatus == 'cancelled'): echo 'Cancelled'; elseif($eventStatus == 'postponed'): echo 'Postponed'; else: echo 'Tickets'; endif; ?></span> <i class="fas fa-arrow-right"></i>
</div>
</div>
<?php };?>
Any help would be greatly appreciated, I'm sure there's a way of merging everything in fewer steps!
For anyone coming across the same issue, this is the solution I used. Using the Transient API to store the feed for 3 hours at a time.
<?php
function eventsFunction() {
// Do we have this information in our transients already?
$eventTransient = get_transient( 'eventsTransientData' );
// Yep! Just return it and we're done.
if( ! empty( $eventTransient ) ) {
echo $eventTransient;
} else {
$single_artist_ids = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => 'artists'
);
$parent = new WP_Query( $single_artist_ids );
if ( $parent->have_posts() ) : $artistFeedCount = 0; while ( $parent->have_posts() ) : $parent->the_post(); if( get_page_template_slug() == 'template-artist.php' && 'publish' === get_post_status() ) {
$singleArtistName = get_the_title();
$singleArtistSongkickRSS = 'https://api.songkick.com/api/3.0/artists/' . get_field('artist_songkick_id') . '/calendar.xml?apikey= XXXXXXXXXXXXXXXX';
$SongkickEvents[]=$singleArtistName;
$SongkickEvents[$singleArtistSongkickRSS] = $SongkickEvents[$artistFeedCount];
unset($SongkickEvents[$artistFeedCount]);
$artistFeedCount++;
?>
<?php }; endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
<?php
$eventsDom = new DOMDocument();
$eventsDom->appendChild($eventsDom->createElement('events'));
foreach ($SongkickEvents as $artist_dates => $artist_name ) {
$eventsAddDom = new DOMDocument();
$eventsAddDom->load($artist_dates);
$events = $eventsAddDom->getElementsByTagName('event');
if ($eventsAddDom->documentElement) {
foreach ($events as $event) {
$eventsDom->documentElement->appendChild(
$eventsDom->importNode($event, TRUE)
);
$artistName = $eventsDom->createElement('mainartist', $artist_name);
foreach($eventsDom->getElementsByTagName('event') as $singleEvent) {
$singleEvent->appendChild($artistName);
}
foreach($eventsDom->getElementsByTagName('performance') as $singlePerformance) {
$singlePerformance->parentNode->removeChild($singlePerformance);
}
}
}
}
$eventsXML = $eventsDom->saveXml();
$LiveDates = simplexml_load_string($eventsXML);
$eventsArr=array();
foreach($LiveDates->event as $eventsArrSingle)
{
$eventsArr[]=$eventsArrSingle;
}
usort($eventsArr,function($dstart,$dend){
return strtotime($dstart->start['date'])-strtotime($dend->start['date']);
});
$eventsStored = '';
foreach($eventsArr as $eventsArrSingle) {
$eventsStored .= '<div class="event-row ';
$eventStatus = $eventsArrSingle['status']; if($eventStatus == 'cancelled' || $eventStatus == 'postponed'): $eventsStored .= 'cancelled'; endif;
$eventsStored .= '">
<div class="event-block event-date">
<span>';
$eventDate=$eventsArrSingle->start['date']; $eventsStored .= date("d", strtotime($eventDate));
$eventsStored .= '</span>';
$eventsStored .= date("M", strtotime($eventDate));
$eventsStored .= '</div>
<div class="event-block event-info">
<span>';
$eventsStored .= $eventsArrSingle->mainartist;
$eventsStored .= '</span>';
if($eventsArrSingle->venue['displayName'] != 'Unknown venue'): $eventsStored .= $eventsArrSingle->venue['displayName'] . ', '; endif;
$eventsStored .= $eventsArrSingle->venue->metroArea['displayName'];
$eventsStored .= '</div>
<div class="event-block event-button">
<a href="' . $eventsArrSingle['uri'] . '" target="_blank"><span>';
if($eventStatus == 'cancelled'): $eventsStored .= 'Cancelled'; elseif($eventStatus == 'postponed'): $eventsStored .= 'Postponed'; else: $eventsStored .= 'Tickets'; endif;
$eventsStored .= '</span> <i class="fas fa-arrow-right"></i></a>
</div>
</div>';
};
set_transient( 'eventsTransientData', $eventsStored, 3*HOUR_IN_SECONDS );
echo $eventsStored;
}
}
eventsFunction();
?>
I am attempting to pull information from a custom post, feed it into a foreach loop and then echo it out into a function in repeating panel. At some point I'm guessing the function declaration is being redeclared (it is not in any other file, I'm 100% confident of this) as I keep getting a "Cannot redeclare output_member() previously declared in same file path php 43".
Any help is appreciated.
function output_team_members( $title, $id, $position ) {
$post_thumbnail = has_post_thumbnail( $id );
if ( $post_thumbnail == true ) {
$image = get_the_post_thumbnail_url( $id );
} else {
$image = get_stylesheet_directory_uri() . '/dist/assets/images/avatar.png';
}
$first = explode( ' ', $title, 2 );
$first_name = $first[0];
$position_title = get_field( 'person_title', $id );
$job_summary = get_field( 'job_summary', $id );
echo
"<li class='is-active orbit-slide'>
<figure class='orbit-figure'>
<div class='top'>
<h4>Meet $first_name</h4>
<p>$job_summary</p>
</div>
<div class='bottom'>
<img src=$image>
<h5>$title</h5>
<p>$position_title</p>
<button class='orbit-previous'></button>
<button class='orbit-next'></button>
</div>
</figure>
</li>";
}
$team_members = get_posts(
[
'post_type' => 'team-member',
'post_status' => 'publish',
'numberposts' => -1,
]
);
/** Grabs information about the post types team-member */
function output_member( $team_members ) {
foreach ( $team_members as $member ) {
output_team_members( $member->post_title, $member->ID, $member->post_content );
}
}
?>
<div class="orbit">
<div class="orbit-wrapper">
<div class="orbit-container">
<?php output_member( $team_members ); ?>
</div>
</div>
</div>
I ended up figuring it out. For future devs it was easier to remove the functions all together and just do this
$team_members = get_posts(
[
'post_type' => 'team-member',
'post_status' => 'publish',
'numberposts' => -1,
]
);
?>
<div class="orbit">
<div class="orbit-wrapper">
<div class="orbit-container" style="height: 500px;">
<?php
foreach ( $team_members as $member ) {
$title = $member->post_title;
$id = $member->ID;
$positon = $member->post_content;
$post_thumbnail = has_post_thumbnail( $id );
if ( true === $post_thumbnail ) {
$image = get_the_post_thumbnail_url( $id );
} else {
$image = get_stylesheet_directory_uri() . '/dist/assets/images/avatar.png';
}
$first = explode( ' ', $title, 2 );
$first_name = $first[0];
$position_title = get_field( 'person_title', $id );
$job_summary = get_field( 'job_summary', $id );
echo
"<li class='orbit-slide'>
<figure class='orbit-figure'>
<div class='top'>
<h4>Meet $first_name</h4>
<p>$job_summary</p>
</div>
<div class='bottom'>
<img src=$image>
<h5>$title</h5>
<p>$position_title</p>
</div>
</figure>
</li>";
}
?>
<button class='orbit-previous'></button>
<button class='orbit-next'></button>
</div>
</div>
hello I am new to programing. I am creating a simple RSS feed plugin for wordpress to upload some products to WooCommerce and need to upload the category to wordpress . In plugin the category is visible but they are not showing like the url link. I need the category to show like checkbox. Can anybody have any idea ?
File number 1
* Init feed with information from DB
private function load()
{
if ($this->id) {
$post = get_post( $this->id );
if (!$post) {
$this->id = null;
return;
}
$this->title = $post->post_title;
$this->id = $post->ID;
$meta = get_post_meta($post->ID);
foreach ($meta as $key=>$item) {
$newKey = substr($key, 1);
$this->properties[$newKey] = $item[0];
if ($newKey == 'post_category') {
$this->properties[$newKey] = unserialize($item[0]);
}
}
}
}
..................
$fields = array( 'post_category');
..................
// Create post
$post = array('post_category' => $this->post_category);
And the file number 2 have this
<div class="postbox">
<div class="handlediv" title="<?php esc_html_e('Click to toggle', 'rss-autopilot'); ?>"><br></div>
<h3 class="hndle ui-sortable-handle"><span><?php esc_html_e('Categories', 'rss-autopilot'); ?></span></h3>
<div class="inside">
<ul class="rssap-categories-list">
<?php wp_category_checklist( 0, 0, $feed->post_category, false, null, true ); ?>
</ul>
<div class="clear"></div>
</div>
</div>
Here is your code.
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<ul class="product-cats">';
foreach ( $terms as $term ) {
echo '<li class="category">';
echo '<h2>';
echo '<input name="product_category[]" type="checkbox" value="'. $term->term_id.'"';
echo $term->name;
echo '</a>';
echo '</h2>';
echo '</li>';
}
echo '</ul>';
}
i have a problem, in first this is my code
$page_id = get_queried_object_id();
$post = get_post($page_id);
$filter_args = array(
'tax_query'=>array(),
'meta_query'=>array()
);
$posts_per_page = 5;
$args = array(
'posts_per_page' => $posts_per_page,
'post_type' => 'property',
'orderby' => 'date'
);
$args = array_merge($args, $filter_args);
$query = new WP_Query( $args );
$items = array();
if(count($query->posts) > 0){
$items = $query->posts;
}
$acf_fields = get_acf_fields(array('general_property_fields', 'property_price'));
foreach($items as $k=>$v){
$items[$k]->acf = get_acf_data($v->ID, $acf_fields);
$items[$k]->pc = sb_get_price($v->ID);
}
The get_acf_fields is a personal function, not worry in this question about that.
And this is my loop for get the values i want.
<?php foreach ($items as $v) {
$status = $v->acf['c_status'];
$status_name = get_term_by('id', $status, 'type');
?>
<?php if ($status_name) { ?>
<div class="sb-sidebar-featured-type">
<?php
$title_status = $status_name->name;
$status = explode(' ', $title_status);
?>
<div class="sidebar-featured-transaction"><?=($status_name) ? $status[0] : '';?></div>
</div>
<?php } ?>
All work fine, but the status give me all values from the taxonomy with name status, for example if i obtain "sold", "discount", "offer", i want to exlude the results with "sold" in the taxonomy but i dont know how make that, thanks :D
Will you please try like this:
<?php if ($status_name != 'sold') { ?>
<div class="sb-sidebar-featured-type">
<?php
$title_status = $status_name->name;
$status = explode(' ', $title_status);
?>
<div class="sidebar-featured-transaction"><?=($status_name) ? $status[0] : '';?></div>
</div>
<?php } ?>
Here is the code working for somelse
<?php foreach ($items as $v) {
$tax_type = $v->acf['c_type'];
$status = $v->acf['c_status'];
$type_name = get_term_by('id', $tax_type, 'type');
$status_name = get_term_by('id', $status, 'type');
if ($status_name) {
$check_status = trim($status_name->slug);
}
if ($check_status != 'sold' && $check_status != 'vendido') {
?>
<div class="sidebar-featured-cont">
<div class="sidebar-featured">
<a class="sidebar-featured-image" href="<?=get_permalink($v->ID)?>">
<img src="<?=$v->acf['c_gallery'][0]['sizes']['property-listing']?>" alt="" />
<?php if ($status_name) { ?>
<div class="sb-sidebar-featured-type">
<?php
$title_status = $status_name->name;
$status = explode(' ', $title_status);
?>
<div class="sidebar-featured-transaction"><?=($status_name) ? $status[0] : '';?></div>
</div>
<?php } ?>
</a>
<div class="sidebar-featured-title"><?=$v->post_title?></div>
<div class="sidebar-featured-price">$ <?=$v->pc?></div>
<div class="clearfix"></div>
</div>
</div>
<?php } ?>
<?php } ?>
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