Settings pages moved into separate view files

This commit is contained in:
Stefan Kalscheuer 2017-12-05 19:29:16 +01:00
parent 8b5c920c98
commit acb896e2f3
4 changed files with 162 additions and 107 deletions

View File

@ -21,7 +21,7 @@ class WPLiveticker2_Admin extends WPLiveticker2 {
*
* @return void
*/
function dashboard_right_now() {
public static function dashboard_right_now() {
$total_files = wp_count_posts( 'wplt2_tick' );
echo '<tr>';
@ -136,24 +136,7 @@ class WPLiveticker2_Admin extends WPLiveticker2 {
* @return void
*/
public static function settings_page() {
?>
<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
include '../views/settings-page.php';
}
/**

View File

@ -49,11 +49,13 @@ class WPLiveticker2_Widget extends WP_Widget {
?>
<?php
// @codingStandardsIgnoreLine
echo $before_widget;
?>
<?php
if ( $title ) {
// @codingStandardsIgnoreLine
echo $before_title . esc_html( $title ) . $after_title;
}
@ -73,7 +75,8 @@ class WPLiveticker2_Widget extends WP_Widget {
$wp_query = new WP_Query( $args );
$cnt = 0;
while ( $wp_query->have_posts() ) : $wp_query->the_post();
while ( $wp_query->have_posts() ) :
$wp_query->the_post();
?>
<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 ) ) {
@ -91,7 +94,7 @@ class WPLiveticker2_Widget extends WP_Widget {
if ( $link ) {
print '<p class="wplt_widget_link"><a href="' . esc_attr( $link ) . '">' . esc_html__( 'show all', 'wplt2' ) . '...</a></p>';
}
// @codingStandardsIgnoreLine
echo $after_widget;
?>
<?php
@ -125,93 +128,8 @@ class WPLiveticker2_Widget extends WP_Widget {
$highlight_time = isset( $instance['highlight_time'] ) ? esc_attr( $instance['highlight_time'] ) : '0';
$ajax = isset( $instance['ajax'] ) ? esc_attr( $instance['ajax'] ) : '0';
$categories = get_terms( 'wplt2_ticker', 'orderby=name&order=ASC' );
?>
<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>
<?php
include '../views/widget-form.php';
}
/**

29
views/settings-page.php Normal file
View 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
View 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>