How include the wordpress schedule feature in my own plugin? - php

My plugin includes a custom content textarea and I want add the same schedule feature that wordpress posts have.
Is there some easy procedure to do it?

HTML:
<div class="misc-pub-section curtime misc-pub-section-last">
<?php
$datef = __('M j, Y # G:i');
$stamp = __('Publish <b>immediately</b>');
$date = date_i18n($datef, strtotime(current_time('mysql')));
?>
<span id="timestamp"><?php printf($stamp, $date); ?></span>
<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a>
<div id="timestampdiv" class="hide-if-js"><?php touch_time(0, 0, 5); ?></div>
</div>
PHP:
add_action('admin_print_scripts', 'header_scripts');
function header_scripts()
{
wp_enqueue_script('nomikos_my_plugin_js_comment', site_url('wp-admin/js/comment.js'));
}

Related

page not updating when adding shortcode and it is rendering the shortcode content in wordpress dashboard also during wordpress plugin development

I am developing a wordpress plugin for event slider , but when i add shortcode to display the slider the wordpress page editor doesnot update and it is also rendering the content in admin dashboard.
the error i am getting is "Updating failed. Error message: The response is not a valid JSON response."
screenshot of updating failed error
event-plugin.php file
add_shortcode("myeventplugin","short_code_view");
function short_code_view(){
include PLUGIN_DIR_PATH.'views/shortcode-template.php';
}
shortcode-template.php
<?php
$allevents=display_events_from_db();
?>
<div class="main-eps">
<?php
if (count($allevents)>0){
foreach($allevents as $key=>$value){
?>
<div class="eps-event-cards">
<div class="img-cont">
<img src="<?php echo $value['thumb'] ?>" class="event-thumb">
</div>
<div class="textcont">
<p class="event-title"><?php echo $value['title'] ?></p>
<p class="event-desc">
<?php
$aa=$value['description'];
if (strlen($aa) >= 40) {
echo substr($aa, 0, 40)." ... ";
}
else {
echo $aa;
}
?>
</p>
<p class="event-date">
<?php
$newDate = date("l M, d, Y", strtotime($value['date']));
echo $newDate;
?>
</p>
</div>
</div>
<?php
}
}
?>
</div>
Change your shortcode to
add_shortcode("myeventplugin","short_code_view");
function short_code_view(){
ob_start();
include PLUGIN_DIR_PATH.'views/shortcode-template.php';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
You forget add return:
add_shortcode("myeventplugin","short_code_view");
function short_code_view(){
return include PLUGIN_DIR_PATH.'views/shortcode-template.php';
}
Hope help you.

Wordpress ACF: Showing Event Button if Event link exists and Date is in future

hope you can help.
I need to do the following, this is using Advanced Custom Fields in Wordpress 4.8
Display an Button if
A: The Event Date has not passed (i.e. the Event is finished)
AND
B: The Buy Ticket Link field has a value in it.
I have succeeded with A using the code below but I cannot work out how to combine this with B, using ACF.
I have looked at the ACF support post about hiding fields and the page is here: https://www.advancedcustomfields.com/resources/hiding-empty-fields/ but I don't have the skills to combine these two. I would hugely appreciate any help here please.
<?php
$eventDate = get_field('event_date', false, false);
$today = (date('Y-m-d'));
?>
<?php if ($eventDate >=$today) { ?>
<div class="tickets">
<a class="btn-primary" href="<?php echo the_field('buy_link') ?>" target="_blank">
Buy Tickets</a>
</div>
<?php
} else { ?>
<div class="tickets">
<div class="btn-primary" href="" target="_blank" style="color: white">
This is an old event. Tickets are no longer on sale.</div>
</div>
<?php } ?>
Don't overcomplicate it -
If you want to have an extra condition, you can specify it in your conditional statement.
<?php
$eventDate = get_field('event_date', false, false);
$today = (date('Y-m-d'));
$ticketLink = get_field('buy_link');
?>
<?php if ($eventDate >= $today && $ticketLink) { ?>
<div class="tickets">
<a class="btn-primary" href="<?php echo get_field('buy_link') ?>" target="_blank">
Buy Tickets</a>
</div>
<?php
} else { ?>
<div class="tickets">
<div class="btn-primary" href="#" style="color: white">
This is an old event. Tickets are no longer on sale.</div>
</div>
<?php } ?>
Read more about your logical operators here : Logical Operators

Wordpress: Generate a join group button in groups-loop

So this is what I have:
<ul id="popular">
<?php while ( bp_groups() ) : bp_the_group(); ?>
<li <?php bp_group_class(); ?>>
<div class="group-box">
<div class="group-box-image-container">
<a class="group-box-image" href="<?php bp_group_permalink() ?>"><?php bp_group_avatar( 'type=full' ) ?></a>
</div>
<div class="group-box-right">
<div class="group-box-title"><?php $grouptitle = bp_get_group_name(); $getlength = strlen($grouptitle); $thelength = 20; echo mb_substr($grouptitle, 0, $thelength, 'UTF-8'); if ($getlength > $thelength) echo "..."; ?></div>
<div class="group-box-details">
<div class="gb-a">Active <?php echo bp_get_group_last_active(); ?></div>
<div class="gb-m"><?php bp_group_member_count(); ?></div>
</div>
</div>
</div><!--group-box ends-->
</li>
<?php endwhile; ?>
</ul>
What I need: a link that allow every logged in member to join that group.
How can I do that? I have also the Invite anyone plugin activated...
Okay, I got it:
In the file groups-header.php of the legacy theme I found the code:
do_action( 'bp_group_header_actions' );
The code above did the magic. Funny how wordpress words those actions... Not quite obvious is it?
Anyway, now it works. For the folks who need it, now you know it :)

Jquery and calendar next and previous month buttons

I am using wordpress, a plugin called The Events Calendar (great plugin btw), and I'm trying to create a little widget with a small navigational element in it. The navigation would show the previous month, the current month, and the next month. For example, today the navigation would show "Apr May Jun".
What should happen is when you click "Jun" it should load the events that occur in June. I want to load these via jquery/ajax magic into a specified div.
I kinda have it working, but i have a bug and I'm not sure how to fix it. When i click one of the months that is displayed initial, it works. But then when i click another month, I'm losing my jquery function (probably due to the page not reloading completely.)
So, I'm wondering if there is a way to re-initialize the navigation so i can get more clicks.
On with the code:
My sidebar.php file contains the following code:
Some HTML
<div id="upcoming-events-box">
<div class="upcoming-events-block-inner">
<div class="upcoming-events-content">
<div id="EventLoader">
<?php get_template_part( 'content', 'the-events' ); ?>
</div>
</div>
</div>
</div>
And some Jquery:
<script type="text/javascript">
jQuery(function() {
jQuery('#upcoming-events-months li a').click(function() {
var toLoad = jQuery(this).attr('href')+' #EventLoader';
jQuery('#EventLoader').hide('fast',loadContent);
jQuery('#load').remove();
jQuery('.upcoming-events-content').append('<span id="load">LOADING...</span>');
jQuery('#load').fadeIn('normal');
function loadContent() {
jQuery('#EventLoader').load(toLoad,'',showNewContent);
}
function showNewContent() {
jQuery('#EventLoader').show('normal',hideLoader);
}
function hideLoader() {
jQuery('#load').fadeOut('normal');
}
return false;
});
});
</script>
content-the-events.php which is called into the sidebar contains the following code:
<div id="upcoming-events-months">
// Some php
global $post;
$current_page_URL = $_SERVER["SERVER_NAME"];
if (isset($_GET['setmonth'])) {
$current_month = $_GET['setmonth'];
} else {
$current_month = date('M'); // This gets the current month
}
$next_month = date('M', strtotime('+1 month', strtotime($current_month)));
$prev_month = date('M', strtotime('-1 month', strtotime($current_month)));
echo "<ul>";
echo "<li><a href='http://".$current_page_URL."?setmonth=".$prev_month."'
id='".$prev_month."'>".$prev_month."</a></li>";
echo "<li>".$current_month."</li>";
echo "<li><a href='http://".$current_page_URL."?setmonth=".$next_month."'
id='".$next_month."'>".$next_month."</a></li>";
echo "</ul>";
</div>
<div id="content"></div>
<div class="upcoming-event-scroller">
<?php
$all_events = tribe_get_events(array(
'eventDisplay'=>'all',
'posts_per_page'=>-1,
'start_date'=>'01 '.$current_month.' 2012',
'end_date'=>'31 '.$current_month.' 2012'
));
foreach($all_events as $post) {
setup_postdata($post);
?>
<div class="row <?php echo (++$j % 2 == 0) ? 'even' : 'odd'; ?>">
<p><?php the_title(); ?></p>
<p class="event-date"><?php echo tribe_get_start_date($post->ID, true, 'M j, Y'); ?> - <?php echo tribe_get_end_date($post->ID, true, 'M j, Y'); ?></p>
</div>
<?php } //endforeach ?>
<?php wp_reset_query(); ?>
</div>
Maybe I've just gotten myself really confused trying to figure this out. haha. Any help would be greatly appreciated.

Coding Wordpress/PHP Problem

Im having a bit of a problem with wordpress. On my site there is a bit that displays voucher now what i want is when that voucher expires i want the voucher details div not too show.
Here is the code from single.php
<?php if(have_posts()) : while (have_posts()) : the_post();
$image = get_post_meta($post->ID, 'image',true);
$writer = get_post_meta($post->ID, 'writer',true);
$code = get_post_meta($post->ID,'vcode',true);
$store = get_post_meta($post->ID,'store',true);
$expiry = strtotime(get_post_meta($post->ID,'expiry',true));
$desc = get_post_meta($post->ID,'description',true);
$datetoday = strtotime(date('Y/m/d'));
?>
this brings all the data from custom fields
heres the voucher div
<?php if($expiry > $datetoday){?>
<div class="voucherDetails">
<h2>Voucher Details</h2>
<div class="left">
<ul>
<li>Code: <?php echo $code;?></li>
<li>Expires: <?php echo $expiry;?></li>
<li><a class="more-link" href="<?php echo $store;?>" title="Visit Store">Visit Store!</a></li>
</ul>
</div>
<div class="desc right">
<h4>Description</h4>
<p><?php echo $desc;?></p>
</div>
</div>
<?php }?>
Now when i run this with the expiry with any value the voucher doesn't show The value in store is DD/MM/YYYY
Can't work it out, all help appreciated,
Thanks
Joe
Change
$datetoday = strtotime(date('d/m/Y'));
to be
$datetoday = strtotime(date('Y/m/d'));
Try run the following as an example of how it differs:
$datetoday = strtotime(date('d/m/Y'));
var_dump($datetoday);
var_dump(date("F j, Y, g:i a", $datetoday));
$datetoday = strtotime(date('Y/m/d'));
var_dump($datetoday);
var_dump(date("F j, Y, g:i a", $datetoday));
Edit: Alternatively use strtotime("now") if you want the precise timestamp to the very minute

Categories