Ask your WordPress questions! Pay money and get answers fast! (more info)

Adding extra functionality to a plugin WordPress

  • SOLVED

Hello,

I would like to add functionality to an Event Manager Plugin.
Adding an extra checkbox for "Past" events.

For you to understand, I made a screenshot of the admin and front end.


Here is the code for the plugin

<?php
/*
Plugin Name: Event Manager
Description: c-om-p-o-s-i-t-e
Version: 1.0
*/

function pps_video_seo_metabox() {
global $post;

$ppsupload1 = get_post_meta( $post->ID, 'ppsupload1', true );
$ppsupload2 = get_post_meta( $post->ID, 'ppsupload2', true );
$ppsupload3 = get_post_meta( $post->ID, 'ppsupload3', true );
$ppsevent1 = get_post_meta( $post->ID, 'ppsevent1', true );
$ppsevent2 = get_post_meta( $post->ID, 'ppsevent2', true );
$ppstitle = get_post_meta( $post->ID, 'ppstitle', true );
$posttype = get_post_meta( $post->ID, 'posttype', true );


?>

<script>

jQuery(document).ready(function($) {

var formfield = null;

$('#upload_logo_button1').click(function() {

$('html').addClass('Image');

formfield = $(this).prev('input').attr('name');
formfield_id = $(this).prev('input').attr('id');

tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );

window.original_send_to_editor = window.send_to_editor;
window.send_to_editor = function( html ) {
var fileurl;

if(formfield != null) {
fileurl = $( 'img', html).attr('src');

$('#ppsupload1').val(fileurl);

tb_remove();

$('html').removeClass('Image');
formfield = null;
} else {
window.original_send_to_editor(html);
}
};
return false;

});

$('#upload_logo_button2').click(function() {

$('html').addClass('Image');

formfield = $(this).prev('input').attr('name');
formfield_id = $(this).prev('input').attr('id');

tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );

window.original_send_to_editor = window.send_to_editor;
window.send_to_editor = function( html ) {
var fileurl;

if(formfield != null) {
fileurl = $( 'img', html).attr('src');

$('#ppsupload2').val(fileurl);

tb_remove();

$('html').removeClass('Image');
formfield = null;
} else {
window.original_send_to_editor(html);
}
};
return false;

});

$('#upload_logo_button3').click(function() {

$('html').addClass('Image');

formfield = $(this).prev('input').attr('name');
formfield_id = $(this).prev('input').attr('id');

tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );

window.original_send_to_editor = window.send_to_editor;
window.send_to_editor = function( html ) {
var fileurl;

if(formfield != null) {
fileurl = $( 'img', html).attr('src');

$('#ppsupload3').val(fileurl);

tb_remove();

$('html').removeClass('Image');
formfield = null;
} else {
window.original_send_to_editor(html);
}
};
return false;

});

});
</script>

<table class="widefat">
<form id= "myform" action="" method="POST">

<tr><td><label for="ppsevent"><font size="02"> <?php echo __('Period of time for the event ','ppsseo'); ?> </font>: </td>
</td><td><input id="ppsevent1" name="ppsevent1" type="date" size="60" value="<?php if ($ppsevent1) {echo $ppsevent1;}?>" ></input></label>
<?php echo __('to',''); ?><input id="ppsevent2" name="ppsevent2" type="date" size="60" value="<?php if ($ppsevent2) {echo $ppsevent2;} ?>" ></input></label></p></td>

</tr>

<tr><td><label for="ppstitle"><font size="02"> <?php echo __('Exhibition Title ','ppsseo'); ?> </font>: </td>
</td><td><input id="ppstitle" name="ppstitle" type="text" size="60" value="<?php if ($ppstitle) {echo $ppstitle;} ?>" ></input></label></p></td>

</tr>

<tr>
<td>
<font size="02"> <?php echo __('Post Type','wepguest'); ?></font>
</td>
<td>
<label for="posttype"></label>
<input type="radio" name="posttype" id="posttype" value="01" <?php if ($posttype == 01) {echo "checked";} ?>/>
<?php echo __('UPCOMING','wepguest'); ?>
&emsp;

<input type="radio" name="posttype" id="posttype" value="02" <?php if ($posttype == 02) {echo "checked";} ?> />
<?php echo __('CURRENT','wepguest'); ?>
&emsp;

</td>
</tr>

<tr><td><label for="ppsupload1"><font size="02"><?php echo __('Press Release PDF FR URL','ppsseo'); ?> </font> :</td>
<td><input type="url" id="ppsupload1" name="ppsupload1" size="60" value="<?php if ($ppsupload1) {echo $ppsupload1; }?>" > <input id="upload_logo_button1" type="button" value="upload pdf" class="button-secondary" /></label></p></td>
</tr>
<tr><td><label for="ppsupload2"><font size="02"><?php echo __('Press Release PDF NL URL','ppsseo'); ?> </font> :</td>
<td><input type="url" id="ppsupload2" name="ppsupload2" size="60" value="<?php if ($ppsupload2) {echo $ppsupload2; }?>" > <input id="upload_logo_button2" type="button" value="upload pdf" class="button-secondary" /></label></p></td>
</tr>
<tr><td><label for="ppsupload3"><font size="02"><?php echo __('Press Release PDF ENG URL','ppsseo'); ?> </font> :</td>
<td><input type="url" id="ppsupload3" name="ppsupload3" size="60" value="<?php if ($ppsupload3) {echo $ppsupload3; }?>" > <input id="upload_logo_button3" type="button" value="upload pdf" class="button-secondary" /></label></p></td>
</tr>

</table>
<br />

<?php
}
/**
* Process the custom metabox fields
*/


function ppssave_custom_url10( $post_id ) {
global $post;

if( $_POST ) {

update_post_meta( $post->ID, 'ppsupload1', $_POST['ppsupload1'] );
update_post_meta( $post->ID, 'ppsupload2', $_POST['ppsupload2'] );
update_post_meta( $post->ID, 'ppsupload3', $_POST['ppsupload3'] );
update_post_meta( $post->ID, 'ppsevent1', $_POST['ppsevent1'] );
update_post_meta( $post->ID, 'ppsevent2', $_POST['ppsevent2'] );
update_post_meta( $post->ID, 'ppstitle', $_POST['ppstitle'] );
update_post_meta( $post->ID, 'posttype', $_POST['posttype'] );

}

}


add_action( 'save_post', 'ppssave_custom_url10',7 );
add_action( 'admin_init', 'pps_custom_metabox10',6 );

/**
* Add meta box
*/

function pps_custom_metabox10() {

add_meta_box( 'pps-metabox02', __( 'Event Manager ' ,'ppsseo'), 'pps_video_seo_metabox', 'post', 'normal', 'high' );

}

function dvp_add_content($content) {

if (is_single()) {
global $post;
$ppsupload1 = get_post_meta( $post->ID, 'ppsupload1', true );
$ppsupload2 = get_post_meta( $post->ID, 'ppsupload2', true );
$ppsupload3 = get_post_meta( $post->ID, 'ppsupload3', true );
$ppsevent1 = get_post_meta( $post->ID, 'ppsevent1', true );
$ppsevent2 = get_post_meta( $post->ID, 'ppsevent2', true );
$ppstitle = get_post_meta( $post->ID, 'ppstitle', true );
$posttype = get_post_meta( $post->ID, 'posttype', true );

$extra_content= $ppstitle.'<br /> <font size="02">'.$ppsevent1.'&emsp;> '.$ppsevent2.'</font>' ;
if ($ppsupload1) {$extra_content.='<br />PRESS RELEASE <a href="'.$ppsupload1.'" target="_new">FR</a>&emsp;';}
if ($ppsupload2) {$extra_content.='<a href="'.$ppsupload2.'" target="_new">NL</a>&emsp;';}
if ($ppsupload3) {$extra_content.='<a href="'.$ppsupload3.'" target="_new">ENG</a>';}

if ( ($ppsupload1) || ($ppsupload2) || ($ppsupload3) || ($ppsevent1) || ($ppsevent2) || ($ppstitle)) {
$extra_content .= $content; }

}

if ($extra_content) {
return $extra_content;
} else { return $content; }
}

add_filter('the_content','dvp_add_content');

?>


And here the php page (http://www.c-o-m-p-o-s-i-t-e.com/programme/)


<?php

/*

Template Name: Event manager

*/

?>

<?php

get_header();
?>

<div id="primary" class="site-content">
<div id="content" role="main">
<div class="readable-content">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'page hentry clearfix' ); ?>>
<div class="entry-content">
<?php
the_content();
?>

<?php

wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'read' ), 'after' => '</div>' ) );

?>
<div class="post-list archives-list last-30-posts">

<ul>
<li class="<?php echo $linkclass; ?>">
<span class="date">13/03/2014 > 12/04/2014</span><br /><span class="grey">Kato Six - Re-located into Silence</span>
</li>
<?php

$args_homepage = array( 'post_type' => 'post', 'posts_per_page' => 30 );

$loop_homepage = new WP_Query( $args_homepage );


if ( $loop_homepage->have_posts() ) :

while ( $loop_homepage->have_posts() ) : $loop_homepage->the_post();

global $post;

$ppsupload1 = get_post_meta( $post->ID, 'ppsupload1', true );
$ppsupload2 = get_post_meta( $post->ID, 'ppsupload2', true );
$ppsupload3 = get_post_meta( $post->ID, 'ppsupload3', true );
$ppsevent1 = get_post_meta( $post->ID, 'ppsevent1', true );
$ppsevent2 = get_post_meta( $post->ID, 'ppsevent2', true );
$ppstitle = get_post_meta( $post->ID, 'ppstitle', true );
$posttype = get_post_meta( $post->ID, 'posttype', true );

switch($posttype) {
case 01:
$linkclass="upcomingclass";
break;

case 02:
$linkclass="currentclass";
break;

default:
$linkclass="defaultclass";
}

$format = get_post_format();



if ( $format == false )

{

?>
<style>
.upcomingclass {
color: black;
}
.upcomingclass a {
color: black;
}
.currentclass {
color: #999 !important;
}
.currentclass a {
color: #999 !important;
}

.defaultclass {
background:none;
//css code in case no class is selected
}
</style>

<li class="<?php echo $linkclass; ?>">
<span class="dateblk"><?php echo $ppsevent1; ?>
> <?php echo $ppsevent2; ?></span>
<br /><a href="<?php the_permalink(); ?>"><h1 class="entry-title"><?php the_title(); ?> - <?php echo $ppstitle; ?></h1></a>
</li>

<?php

}

// end if

endwhile;
endif;
wp_reset_query();

?>
</ul>
</div>
<!-- end Last 30 posts -->
</div>
<!-- end .entry-content -->
</article>
<!-- end .hentry -->
<?php
endwhile;
endif;
wp_reset_query();
?>
<?php
comments_template( "", true );
?>
</div>
<!-- end .readable-content -->
</div>
<!-- end #content -->
</div>
<!-- end #primary -->

<?php
get_footer();
?>

Answers (2)

2014-03-04

Arnav Joy answers:

please check this code , it will add new radio button "PAST" in admin

<?php

/*

Plugin Name: Event Manager

Description: c-om-p-o-s-i-t-e

Version: 1.0

*/



function pps_video_seo_metabox() {

global $post;



$ppsupload1 = get_post_meta( $post->ID, 'ppsupload1', true );

$ppsupload2 = get_post_meta( $post->ID, 'ppsupload2', true );

$ppsupload3 = get_post_meta( $post->ID, 'ppsupload3', true );

$ppsevent1 = get_post_meta( $post->ID, 'ppsevent1', true );

$ppsevent2 = get_post_meta( $post->ID, 'ppsevent2', true );

$ppstitle = get_post_meta( $post->ID, 'ppstitle', true );

$posttype = get_post_meta( $post->ID, 'posttype', true );





?>



<script>



jQuery(document).ready(function($) {



var formfield = null;



$('#upload_logo_button1').click(function() {



$('html').addClass('Image');



formfield = $(this).prev('input').attr('name');

formfield_id = $(this).prev('input').attr('id');



tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );



window.original_send_to_editor = window.send_to_editor;

window.send_to_editor = function( html ) {

var fileurl;



if(formfield != null) {

fileurl = $( 'img', html).attr('src');



$('#ppsupload1').val(fileurl);



tb_remove();



$('html').removeClass('Image');

formfield = null;

} else {

window.original_send_to_editor(html);

}

};

return false;



});



$('#upload_logo_button2').click(function() {



$('html').addClass('Image');



formfield = $(this).prev('input').attr('name');

formfield_id = $(this).prev('input').attr('id');



tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );



window.original_send_to_editor = window.send_to_editor;

window.send_to_editor = function( html ) {

var fileurl;



if(formfield != null) {

fileurl = $( 'img', html).attr('src');



$('#ppsupload2').val(fileurl);



tb_remove();



$('html').removeClass('Image');

formfield = null;

} else {

window.original_send_to_editor(html);

}

};

return false;



});



$('#upload_logo_button3').click(function() {



$('html').addClass('Image');



formfield = $(this).prev('input').attr('name');

formfield_id = $(this).prev('input').attr('id');



tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );



window.original_send_to_editor = window.send_to_editor;

window.send_to_editor = function( html ) {

var fileurl;



if(formfield != null) {

fileurl = $( 'img', html).attr('src');



$('#ppsupload3').val(fileurl);



tb_remove();



$('html').removeClass('Image');

formfield = null;

} else {

window.original_send_to_editor(html);

}

};

return false;



});



});

</script>



<table class="widefat">

<form id= "myform" action="" method="POST">



<tr><td><label for="ppsevent"><font size="02"> <?php echo __('Period of time for the event ','ppsseo'); ?> </font>: </td>

</td><td><input id="ppsevent1" name="ppsevent1" type="date" size="60" value="<?php if ($ppsevent1) {echo $ppsevent1;}?>" ></input></label>

<?php echo __('to',''); ?><input id="ppsevent2" name="ppsevent2" type="date" size="60" value="<?php if ($ppsevent2) {echo $ppsevent2;} ?>" ></input></label></p></td>



</tr>



<tr><td><label for="ppstitle"><font size="02"> <?php echo __('Exhibition Title ','ppsseo'); ?> </font>: </td>

</td><td><input id="ppstitle" name="ppstitle" type="text" size="60" value="<?php if ($ppstitle) {echo $ppstitle;} ?>" ></input></label></p></td>



</tr>



<tr>

<td>

<font size="02"> <?php echo __('Post Type','wepguest'); ?></font>

</td>

<td>

<label for="posttype"></label>

<input type="radio" name="posttype" id="posttype" value="01" <?php if ($posttype == 01) {echo "checked";} ?>/>

<?php echo __('UPCOMING','wepguest'); ?>

&emsp;



<input type="radio" name="posttype" id="posttype" value="02" <?php if ($posttype == 02) {echo "checked";} ?> />

<?php echo __('CURRENT','wepguest'); ?>


&emsp;



<input type="radio" name="posttype" id="posttype" value="03" <?php if ($posttype == 03) {echo "checked";} ?> />

<?php echo __('PAST','wepguest'); ?>

&emsp;



</td>

</tr>



<tr><td><label for="ppsupload1"><font size="02"><?php echo __('Press Release PDF FR URL','ppsseo'); ?> </font> :</td>

<td><input type="url" id="ppsupload1" name="ppsupload1" size="60" value="<?php if ($ppsupload1) {echo $ppsupload1; }?>" > <input id="upload_logo_button1" type="button" value="upload pdf" class="button-secondary" /></label></p></td>

</tr>

<tr><td><label for="ppsupload2"><font size="02"><?php echo __('Press Release PDF NL URL','ppsseo'); ?> </font> :</td>

<td><input type="url" id="ppsupload2" name="ppsupload2" size="60" value="<?php if ($ppsupload2) {echo $ppsupload2; }?>" > <input id="upload_logo_button2" type="button" value="upload pdf" class="button-secondary" /></label></p></td>

</tr>

<tr><td><label for="ppsupload3"><font size="02"><?php echo __('Press Release PDF ENG URL','ppsseo'); ?> </font> :</td>

<td><input type="url" id="ppsupload3" name="ppsupload3" size="60" value="<?php if ($ppsupload3) {echo $ppsupload3; }?>" > <input id="upload_logo_button3" type="button" value="upload pdf" class="button-secondary" /></label></p></td>

</tr>



</table>

<br />



<?php

}

/**

* Process the custom metabox fields

*/





function ppssave_custom_url10( $post_id ) {

global $post;



if( $_POST ) {



update_post_meta( $post->ID, 'ppsupload1', $_POST['ppsupload1'] );

update_post_meta( $post->ID, 'ppsupload2', $_POST['ppsupload2'] );

update_post_meta( $post->ID, 'ppsupload3', $_POST['ppsupload3'] );

update_post_meta( $post->ID, 'ppsevent1', $_POST['ppsevent1'] );

update_post_meta( $post->ID, 'ppsevent2', $_POST['ppsevent2'] );

update_post_meta( $post->ID, 'ppstitle', $_POST['ppstitle'] );

update_post_meta( $post->ID, 'posttype', $_POST['posttype'] );



}



}





add_action( 'save_post', 'ppssave_custom_url10',7 );

add_action( 'admin_init', 'pps_custom_metabox10',6 );



/**

* Add meta box

*/



function pps_custom_metabox10() {



add_meta_box( 'pps-metabox02', __( 'Event Manager ' ,'ppsseo'), 'pps_video_seo_metabox', 'post', 'normal', 'high' );



}



function dvp_add_content($content) {



if (is_single()) {

global $post;

$ppsupload1 = get_post_meta( $post->ID, 'ppsupload1', true );

$ppsupload2 = get_post_meta( $post->ID, 'ppsupload2', true );

$ppsupload3 = get_post_meta( $post->ID, 'ppsupload3', true );

$ppsevent1 = get_post_meta( $post->ID, 'ppsevent1', true );

$ppsevent2 = get_post_meta( $post->ID, 'ppsevent2', true );

$ppstitle = get_post_meta( $post->ID, 'ppstitle', true );

$posttype = get_post_meta( $post->ID, 'posttype', true );



$extra_content= $ppstitle.'<br /> <font size="02">'.$ppsevent1.'&emsp;> '.$ppsevent2.'</font>' ;

if ($ppsupload1) {$extra_content.='<br />PRESS RELEASE <a href="'.$ppsupload1.'" target="_new">FR</a>&emsp;';}

if ($ppsupload2) {$extra_content.='<a href="'.$ppsupload2.'" target="_new">NL</a>&emsp;';}

if ($ppsupload3) {$extra_content.='<a href="'.$ppsupload3.'" target="_new">ENG</a>';}



if ( ($ppsupload1) || ($ppsupload2) || ($ppsupload3) || ($ppsevent1) || ($ppsevent2) || ($ppstitle)) {

$extra_content .= $content; }



}



if ($extra_content) {

return $extra_content;

} else { return $content; }

}



add_filter('the_content','dvp_add_content');



?>


Arnav Joy comments:

try this in template



<?php



/*



Template Name: Event manager



*/



?>



<?php



get_header();

?>



<div id="primary" class="site-content">

<div id="content" role="main">

<div class="readable-content">

<?php

if ( have_posts() ) :

while ( have_posts() ) : the_post();

?>

<article id="post-<?php the_ID(); ?>" <?php post_class( 'page hentry clearfix' ); ?>>

<div class="entry-content">

<?php

the_content();

?>



<?php



wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'read' ), 'after' => '</div>' ) );



?>

<div class="post-list archives-list last-30-posts">



<ul>

<li class="<?php echo $linkclass; ?>">

<span class="date">13/03/2014 > 12/04/2014</span><br /><span class="grey">Kato Six - Re-located into Silence</span>

</li>

<?php



$args_homepage = array( 'post_type' => 'post', 'posts_per_page' => 30 );



$loop_homepage = new WP_Query( $args_homepage );





if ( $loop_homepage->have_posts() ) :



while ( $loop_homepage->have_posts() ) : $loop_homepage->the_post();



global $post;



$ppsupload1 = get_post_meta( $post->ID, 'ppsupload1', true );

$ppsupload2 = get_post_meta( $post->ID, 'ppsupload2', true );

$ppsupload3 = get_post_meta( $post->ID, 'ppsupload3', true );

$ppsevent1 = get_post_meta( $post->ID, 'ppsevent1', true );

$ppsevent2 = get_post_meta( $post->ID, 'ppsevent2', true );

$ppstitle = get_post_meta( $post->ID, 'ppstitle', true );

$posttype = get_post_meta( $post->ID, 'posttype', true );



switch($posttype) {

case 01:

$linkclass="upcomingclass";

break;



case 02:

$linkclass="currentclass";

break;


case 03:

$linkclass="pastclass";

break;



default:

$linkclass="defaultclass";

}



$format = get_post_format();







if ( $format == false )



{



?>

<style>

.upcomingclass {

color: black;

}

.upcomingclass a {

color: black;

}

.currentclass {

color: #999 !important;

}

.currentclass a {

color: #999 !important;

}



.defaultclass {

background:none;



}

</style>



<li class="<?php echo $linkclass; ?>">

<span class="dateblk"><?php echo $ppsevent1; ?>

> <?php echo $ppsevent2; ?></span>

<br /><a href="<?php the_permalink(); ?>"><h1 class="entry-title"><?php the_title(); ?> - <?php echo $ppstitle; ?></h1></a>

</li>



<?php



}



// end if



endwhile;

endif;

wp_reset_query();



?>

</ul>

</div>

<!-- end Last 30 posts -->

</div>

<!-- end .entry-content -->

</article>

<!-- end .hentry -->

<?php

endwhile;

endif;

wp_reset_query();

?>

<?php

comments_template( "", true );

?>

</div>

<!-- end .readable-content -->

</div>

<!-- end #content -->

</div>

<!-- end #primary -->



<?php

get_footer();

?>


guillaume guillaume comments:

Ok, I now have an extro checkbox on the admin page.
Can you go on with the rest ?


Arnav Joy comments:

For admin

http://pastebin.com/hdxMFCpu

For front end

http://pastebin.com/gYJpbKir


guillaume guillaume comments:

Thank you Arnav, but for the "upcoming" events I don't need the link to the article.


guillaume guillaume comments:

Please see the actual page, "Upcoming event" don't have link to article, the others event yes :

http://www.c-o-m-p-o-s-i-t-e.com/programme/


guillaume guillaume comments:

Can you get rid of the link below :

<li class="upcomingclass">

<span class="dateblk">30/01/2014 > 01/03/2014</span>

<br>

<a href="http://www.c-o-m-p-o-s-i-t-e.com/assunta-ruocco-3/">

<h1 class="entry-title"> Assunta Ruocco - A Record of Unaddressed Activity</h1>

</a>

</li>


And here the colors for the events :

Upcoming : #999
Current : #000
Past : #999


Arnav Joy comments:

here is the code with removed link


<li class="upcomingclass">



<span class="dateblk">30/01/2014 > 01/03/2014</span>



<br>







<h1 class="entry-title"> Assunta Ruocco - A Record of Unaddressed Activity</h1>







</li>


guillaume guillaume comments:

Ok but can you manage the template not ot have the link for "upcoming" ?


Arnav Joy comments:

paste this in style file


.currentclass , .currentclass a { color:#000000 !important;}

.upcomingclass , .upcomingclass a{ color: #999999!important;}

.pastclass , .pastclass a{ color: #999999!important;}


Arnav Joy comments:

HERE IS THE FINAL CODE

http://pastebin.com/sf6mmyc5


guillaume guillaume comments:

You got it !!!
Please let me see for any issue.


guillaume guillaume comments:

For now I miss an ">" between the debut and end date of the event :

30/01/2014 01/03/2014
should be
30/01/2014 > 01/03/2014


guillaume guillaume comments:

please see the original page