Settings pages moved into separate view files
This commit is contained in:
parent
8b5c920c98
commit
acb896e2f3
@ -21,7 +21,7 @@ class WPLiveticker2_Admin extends WPLiveticker2 {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function dashboard_right_now() {
|
public static function dashboard_right_now() {
|
||||||
$total_files = wp_count_posts( 'wplt2_tick' );
|
$total_files = wp_count_posts( 'wplt2_tick' );
|
||||||
|
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
@ -136,24 +136,7 @@ class WPLiveticker2_Admin extends WPLiveticker2 {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function settings_page() {
|
public static function settings_page() {
|
||||||
?>
|
include '../views/settings-page.php';
|
||||||
<div class="wrap">
|
|
||||||
<div id="icon-options-general" class="icon32"><br></div>
|
|
||||||
<h2>Liveticker <?php esc_html_e( 'Settings', 'wplt2' ); ?></h2>
|
|
||||||
<?php if ( isset( $_GET['settings-updated'] ) ) {
|
|
||||||
echo '<div class="updated"><p>' . esc_html__( 'Settings updated successfully.', 'wplt2' ) . '</p></div>';
|
|
||||||
} ?>
|
|
||||||
<form action="options.php" method="post">
|
|
||||||
<?php
|
|
||||||
settings_fields( 'wplt2_settings' );
|
|
||||||
do_settings_sections( __FILE__ );
|
|
||||||
?>
|
|
||||||
<p class="submit">
|
|
||||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,11 +49,13 @@ class WPLiveticker2_Widget extends WP_Widget {
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
// @codingStandardsIgnoreLine
|
||||||
echo $before_widget;
|
echo $before_widget;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if ( $title ) {
|
if ( $title ) {
|
||||||
|
// @codingStandardsIgnoreLine
|
||||||
echo $before_title . esc_html( $title ) . $after_title;
|
echo $before_title . esc_html( $title ) . $after_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +75,8 @@ class WPLiveticker2_Widget extends WP_Widget {
|
|||||||
|
|
||||||
$wp_query = new WP_Query( $args );
|
$wp_query = new WP_Query( $args );
|
||||||
$cnt = 0;
|
$cnt = 0;
|
||||||
while ( $wp_query->have_posts() ) : $wp_query->the_post();
|
while ( $wp_query->have_posts() ) :
|
||||||
|
$wp_query->the_post();
|
||||||
?>
|
?>
|
||||||
<li>
|
<li>
|
||||||
<span class="wplt_widget_time"><?php echo esc_html( get_the_time( 'd.m.Y - H.i' ) ); ?></span><span class="wplt_widget_content<?php if ( '1' === $highlight && get_the_time( 'U' ) > ( time() - $highlight_time ) ) {
|
<span class="wplt_widget_time"><?php echo esc_html( get_the_time( 'd.m.Y - H.i' ) ); ?></span><span class="wplt_widget_content<?php if ( '1' === $highlight && get_the_time( 'U' ) > ( time() - $highlight_time ) ) {
|
||||||
@ -91,7 +94,7 @@ class WPLiveticker2_Widget extends WP_Widget {
|
|||||||
if ( $link ) {
|
if ( $link ) {
|
||||||
print '<p class="wplt_widget_link"><a href="' . esc_attr( $link ) . '">' . esc_html__( 'show all', 'wplt2' ) . '...</a></p>';
|
print '<p class="wplt_widget_link"><a href="' . esc_attr( $link ) . '">' . esc_html__( 'show all', 'wplt2' ) . '...</a></p>';
|
||||||
}
|
}
|
||||||
|
// @codingStandardsIgnoreLine
|
||||||
echo $after_widget;
|
echo $after_widget;
|
||||||
?>
|
?>
|
||||||
<?php
|
<?php
|
||||||
@ -125,93 +128,8 @@ class WPLiveticker2_Widget extends WP_Widget {
|
|||||||
$highlight_time = isset( $instance['highlight_time'] ) ? esc_attr( $instance['highlight_time'] ) : '0';
|
$highlight_time = isset( $instance['highlight_time'] ) ? esc_attr( $instance['highlight_time'] ) : '0';
|
||||||
$ajax = isset( $instance['ajax'] ) ? esc_attr( $instance['ajax'] ) : '0';
|
$ajax = isset( $instance['ajax'] ) ? esc_attr( $instance['ajax'] ) : '0';
|
||||||
$categories = get_terms( 'wplt2_ticker', 'orderby=name&order=ASC' );
|
$categories = get_terms( 'wplt2_ticker', 'orderby=name&order=ASC' );
|
||||||
?>
|
|
||||||
|
|
||||||
<table>
|
include '../views/widget-form.php';
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<label for="<?php echo esc_html( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:' ); ?></label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<label for="<?php echo esc_html( $this->get_field_id( 'category' ) ); ?>"><?php esc_html_e( 'Ticker:', 'wplt2' ); ?></label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select id="<?php echo esc_attr( $this->get_field_id( 'category' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'category' ) ); ?>">
|
|
||||||
<?php foreach ( $categories as $cat ) {
|
|
||||||
echo '<option value="' . esc_attr( $cat->slug ) . '"';
|
|
||||||
if ( $category === $cat->slug ) {
|
|
||||||
echo ' selected="selected"';
|
|
||||||
}
|
|
||||||
echo '>' . esc_html( $cat->name ) . '</option>';
|
|
||||||
} ?>
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"><?php esc_html_e( 'Number of Ticks:', 'wplt2' ); ?></label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>">
|
|
||||||
<option value="0"<?php if ( '0' === $count ) { echo ' selected="selected"'; } ?>><?php esc_html_e( 'all', 'wplt2' ); ?></option>
|
|
||||||
<option value="1"<?php if ( '1' === $count ) { echo ' selected="selected"'; } ?>>1</option>
|
|
||||||
<option value="2"<?php if ( '2' === $count ) { echo ' selected="selected"'; } ?>>2</option>
|
|
||||||
<option value="3"<?php if ( '3' === $count ) { echo ' selected="selected"'; } ?>>3</option>
|
|
||||||
<option value="4"<?php if ( '4' === $count ) { echo ' selected="selected"'; } ?>>4</option>
|
|
||||||
<option value="5"<?php if ( '5' === $count ) { echo ' selected="selected"'; } ?>>5</option>
|
|
||||||
<option value="6"<?php if ( '6' === $count ) { echo ' selected="selected"'; } ?>>6</option>
|
|
||||||
<option value="7"<?php if ( '7' === $count ) { echo ' selected="selected"'; } ?>>7</option>
|
|
||||||
<option value="8"<?php if ( '8' === $count ) { echo ' selected="selected"'; } ?>>8</option>
|
|
||||||
<option value="9"<?php if ( '9' === $count ) { echo ' selected="selected"'; } ?>>9</option>
|
|
||||||
<option value="10"<?php if ( '10' === $count ) { echo ' selected="selected"'; } ?>>10</option>
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<label for="<?php echo esc_attr( $this->get_field_id( 'link' ) ); ?>"><?php esc_html_e( 'Link (optional):', 'wplt2' ); ?></label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'link' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'link' ) ); ?>" type="text" value="<?php echo esc_attr( $link ); ?>" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<label for="<?php echo esc_attr( $this->get_field_id( 'highlight' ) ); ?>"><?php esc_html_e( 'Highlight new:', 'wplt2' ); ?></label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'highlight' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'highlight' ) ); ?>" type="checkbox" value="1" <?php if ( '1' === $highlight ) {
|
|
||||||
echo ' checked="checked"';
|
|
||||||
} ?> /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<label for="<?php echo esc_attr( $this->get_field_id( 'highlight_time' ) ); ?>"><?php esc_html_e( 'Highlight time [s]:', 'wplt2' ); ?></label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'highlight_time' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'highlight_time' ) ); ?>" type="text" value="<?php echo esc_html( $highlight_time ); ?>" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<label for="<?php echo esc_attr( $this->get_field_id( 'ajax' ) ); ?>"><?php esc_html_e( 'Auto refresh:', 'wplt2' ); ?></label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'ajax' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'ajax' ) ); ?>" type="checkbox" value="1"<?php if ( '1' === $ajax ) {
|
|
||||||
echo ' checked="checked"';
|
|
||||||
} ?> disabled="disabled" />
|
|
||||||
<small><?php esc_html_e( '(enables ajax)', 'wplt2' ); ?></small>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
<?php
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
29
views/settings-page.php
Normal file
29
views/settings-page.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* WP Liveticker 2: Settings page.
|
||||||
|
*
|
||||||
|
* This file contains the view model for the Plugin settings oage.
|
||||||
|
*
|
||||||
|
* @package WPLiveticker2
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<div id="icon-options-general" class="icon32"><br></div>
|
||||||
|
<h2>Liveticker <?php esc_html_e( 'Settings', 'wplt2' ); ?></h2>
|
||||||
|
<?php
|
||||||
|
if ( isset( $_GET['settings-updated'] ) ) {
|
||||||
|
echo '<div class="updated"><p>' . esc_html__( 'Settings updated successfully.', 'wplt2' ) . '</p></div>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<form action="options.php" method="post">
|
||||||
|
<?php
|
||||||
|
settings_fields( 'wplt2_settings' );
|
||||||
|
do_settings_sections( __FILE__ );
|
||||||
|
?>
|
||||||
|
<p class="submit">
|
||||||
|
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
125
views/widget-form.php
Normal file
125
views/widget-form.php
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* WP Liveticker 2: Widget form.
|
||||||
|
*
|
||||||
|
* This file contains the view model for the Widget settings form.
|
||||||
|
*
|
||||||
|
* @package WPLiveticker2
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
?>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="<?php echo esc_html( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:' ); ?></label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="<?php echo esc_html( $this->get_field_id( 'category' ) ); ?>"><?php esc_html_e( 'Ticker:', 'wplt2' ); ?></label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select id="<?php echo esc_attr( $this->get_field_id( 'category' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'category' ) ); ?>">
|
||||||
|
<?php foreach ( $categories as $cat ) {
|
||||||
|
echo '<option value="' . esc_attr( $cat->slug ) . '"';
|
||||||
|
if ( $category === $cat->slug ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
}
|
||||||
|
echo '>' . esc_html( $cat->name ) . '</option>';
|
||||||
|
} ?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"><?php esc_html_e( 'Number of Ticks:', 'wplt2' ); ?></label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>">
|
||||||
|
<option value="0"<?php if ( '0' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>><?php esc_html_e( 'all', 'wplt2' ); ?></option>
|
||||||
|
<option value="1"<?php if ( '1' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>1
|
||||||
|
</option>
|
||||||
|
<option value="2"<?php if ( '2' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>2
|
||||||
|
</option>
|
||||||
|
<option value="3"<?php if ( '3' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>3
|
||||||
|
</option>
|
||||||
|
<option value="4"<?php if ( '4' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>4
|
||||||
|
</option>
|
||||||
|
<option value="5"<?php if ( '5' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>5
|
||||||
|
</option>
|
||||||
|
<option value="6"<?php if ( '6' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>6
|
||||||
|
</option>
|
||||||
|
<option value="7"<?php if ( '7' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>7
|
||||||
|
</option>
|
||||||
|
<option value="8"<?php if ( '8' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>8
|
||||||
|
</option>
|
||||||
|
<option value="9"<?php if ( '9' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>9
|
||||||
|
</option>
|
||||||
|
<option value="10"<?php if ( '10' === $count ) {
|
||||||
|
echo ' selected="selected"';
|
||||||
|
} ?>>10
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="<?php echo esc_attr( $this->get_field_id( 'link' ) ); ?>"><?php esc_html_e( 'Link (optional):', 'wplt2' ); ?></label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'link' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'link' ) ); ?>" type="text" value="<?php echo esc_attr( $link ); ?>" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="<?php echo esc_attr( $this->get_field_id( 'highlight' ) ); ?>"><?php esc_html_e( 'Highlight new:', 'wplt2' ); ?></label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'highlight' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'highlight' ) ); ?>" type="checkbox" value="1" <?php if ( '1' === $highlight ) {
|
||||||
|
echo ' checked="checked"';
|
||||||
|
} ?> /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="<?php echo esc_attr( $this->get_field_id( 'highlight_time' ) ); ?>"><?php esc_html_e( 'Highlight time [s]:', 'wplt2' ); ?></label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'highlight_time' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'highlight_time' ) ); ?>" type="text" value="<?php echo esc_html( $highlight_time ); ?>" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="<?php echo esc_attr( $this->get_field_id( 'ajax' ) ); ?>"><?php esc_html_e( 'Auto refresh:', 'wplt2' ); ?></label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'ajax' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'ajax' ) ); ?>" type="checkbox" value="1"<?php if ( '1' === $ajax ) {
|
||||||
|
echo ' checked="checked"';
|
||||||
|
} ?> disabled="disabled" />
|
||||||
|
<small><?php esc_html_e( '(enables ajax)', 'wplt2' ); ?></small>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
Loading…
x
Reference in New Issue
Block a user