Settings page restored, AJAX hook bundled in main class
This commit is contained in:
@ -68,6 +68,11 @@ class WPLiveticker2 {
|
||||
// Enqueue styles.
|
||||
add_action( 'wp_footer', array( 'WPLiveticker2', 'enqueue_styles' ) );
|
||||
|
||||
// Add AJAX hook if configured.
|
||||
if ( 1 === self::$_options['enable_ajax'] ) {
|
||||
add_action( 'wp_ajax_wplt2_update-ticks', array( 'WPLiveticker2', 'ajax_update' ) );
|
||||
}
|
||||
|
||||
// Admin only actions.
|
||||
if ( is_admin() ) {
|
||||
// Add dashboard "right now" functionality.
|
||||
@ -207,6 +212,50 @@ class WPLiveticker2 {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Ajax upload file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function ajax_update() {
|
||||
// TODO: re-enable security checks.
|
||||
// check_ajax_referer( 'wplt_ajax_get_new_ticks' );
|
||||
|
||||
// Timestamp for request.
|
||||
$slug = $_REQUEST['sl'];
|
||||
$time = $_REQUEST['ts'];
|
||||
|
||||
if ( $slug ) {
|
||||
// get new ticks from database
|
||||
$args = array(
|
||||
'post_type' => 'wplt_tick',
|
||||
'posts_per_page' => '-1',
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'wplt_ticker',
|
||||
'field' => 'slug',
|
||||
'terms' => $slug
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_query = new WP_Query( $args );
|
||||
$output = '';
|
||||
|
||||
while ( $wp_query->have_posts() ) {
|
||||
$wp_query->the_post();
|
||||
$output .= '<li class="wplt_tick">'
|
||||
. '<p><span class="wplt_tick_time">' . get_the_time( 'd.m.Y H.i' ) . '</span>'
|
||||
. '<span class="wplt_tick_title">' . get_the_title() . '</span></p>'
|
||||
. '<p class="wplt_tick_content">' . get_the_content() . '</p></li>';
|
||||
}
|
||||
|
||||
// Echo success response
|
||||
echo $output;
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update options.
|
||||
*
|
||||
|
Reference in New Issue
Block a user