Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
bc8cc41349 | |||
a6a48dad58 | |||
d6ae2fe437 | |||
b29a2b169c | |||
fceea65dfb | |||
4635a47ca9 | |||
e5a76fc18c | |||
0979f070cf | |||
b237b731d5 | |||
1cc8869018 | |||
f662df3f11 | |||
f4f210f105 | |||
c05ee5b5ff | |||
9018d7bdca | |||
78ad69c897 | |||
5d9473eb3f | |||
8b0f89a847 | |||
ad8293fa3a | |||
a827536da7 | |||
d650ae08ee | |||
14ec07e423 | |||
e738da4f8f | |||
20401382b7 | |||
b1d42dadd8 | |||
fc957fd3b4 | |||
5f1e1a7879 | |||
ad245ebf43 |
@ -2,6 +2,7 @@
|
|||||||
/.github
|
/.github
|
||||||
/assets
|
/assets
|
||||||
/bin
|
/bin
|
||||||
|
/dist
|
||||||
/node_modules
|
/node_modules
|
||||||
/tests
|
/tests
|
||||||
/vendor
|
/vendor
|
||||||
|
1
.gitattributes
vendored
@ -11,6 +11,7 @@
|
|||||||
/composer.json export-ignore
|
/composer.json export-ignore
|
||||||
/composer.lock export-ignore
|
/composer.lock export-ignore
|
||||||
/CONTRIBUTING.md export-ignore
|
/CONTRIBUTING.md export-ignore
|
||||||
|
/dist export-ignore
|
||||||
/package.json export-ignore
|
/package.json export-ignore
|
||||||
/package-lock.json export-ignore
|
/package-lock.json export-ignore
|
||||||
/phpcs.xml export-ignore
|
/phpcs.xml export-ignore
|
||||||
|
2
.github/workflows/test.yml
vendored
@ -16,8 +16,6 @@ jobs:
|
|||||||
wordpress: '6.0'
|
wordpress: '6.0'
|
||||||
- php: '7.4'
|
- php: '7.4'
|
||||||
wordpress: '5.9'
|
wordpress: '5.9'
|
||||||
- php: '5.6'
|
|
||||||
wordpress: '4.7'
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
19
README.md
@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
# Liveticker (by stklcode)
|
# Liveticker (by stklcode)
|
||||||
|
|
||||||
* Contributors: Stefan Kalscheuer
|
* Contributors: stklcode
|
||||||
* Tags: liveticker, feed, rss
|
* Tags: liveticker, feed, rss
|
||||||
* Requires at least: 4.7
|
* Requires at least: 5.0
|
||||||
* Tested up to: 6.7
|
* Tested up to: 6.7
|
||||||
* Requires PHP: 5.6
|
* Requires PHP: 7.2
|
||||||
* Stable tag: 1.2.3
|
* Stable tag: 1.3.0
|
||||||
* License: GPLv2 or later
|
* License: GPLv2 or later
|
||||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
|
||||||
A simple ajaxified liveticker plugin for WordPress.
|
A simple ajaxified liveticker plugin for WordPress.
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ Alternatively you can also use _Copmposer_.
|
|||||||
|
|
||||||
### Requirements ###
|
### Requirements ###
|
||||||
|
|
||||||
* PHP 5.6 or above
|
* PHP 7.2 or above
|
||||||
* WordPress 4.7 or above
|
* WordPress 5.0 or above
|
||||||
|
|
||||||
## Frequently asked questions
|
## Frequently asked questions
|
||||||
|
|
||||||
@ -80,6 +80,11 @@ caching time of 12 hours obviously makes no sense.
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### 1.3.0 - 2025-03-10
|
||||||
|
|
||||||
|
* Requires at least PHP 7.2 and WordPress 5.0
|
||||||
|
* Sorting direction can now be changed for liveticker blocks
|
||||||
|
|
||||||
### 1.2.3 - 2025-02-04
|
### 1.2.3 - 2025-02-04
|
||||||
|
|
||||||
* Escape ticker ID in shortcode output
|
* Escape ticker ID in shortcode output
|
||||||
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 26 KiB |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "stklcode/stklcode-liveticker",
|
"name": "stklcode/stklcode-liveticker",
|
||||||
"version": "1.2.3",
|
"version": "1.3.0",
|
||||||
"description": "A simple Liveticker for Wordpress.",
|
"description": "A simple Liveticker for Wordpress.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"wordpress",
|
"wordpress",
|
||||||
@ -17,18 +17,17 @@
|
|||||||
],
|
],
|
||||||
"type": "wordpress-plugin",
|
"type": "wordpress-plugin",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.6",
|
"php": ">=7.2",
|
||||||
"composer/installers": "~1.12"
|
"composer/installers": "~v2.3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"dealerdirect/phpcodesniffer-composer-installer": "^v1.0",
|
"dealerdirect/phpcodesniffer-composer-installer": "^v1.0",
|
||||||
"matthiasmullie/minify": "^1.3",
|
"matthiasmullie/minify": "^1.3",
|
||||||
"phpcompatibility/phpcompatibility-wp": "^2.1",
|
"phpcompatibility/phpcompatibility-wp": "^2.1",
|
||||||
"phpunit/phpunit": "^5|^6|^7|^8|^9",
|
|
||||||
"slowprog/composer-copy-file": "~0.3",
|
"slowprog/composer-copy-file": "~0.3",
|
||||||
"squizlabs/php_codesniffer": "^3.9",
|
"squizlabs/php_codesniffer": "^3.11",
|
||||||
"wp-coding-standards/wpcs": "^3.0",
|
"wp-coding-standards/wpcs": "^3.1",
|
||||||
"yoast/phpunit-polyfills": "^2.0"
|
"yoast/wp-test-utils": "^1.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"post-install-cmd": [
|
"post-install-cmd": [
|
||||||
|
@ -23,7 +23,7 @@ class Admin extends SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function dashboard_right_now() {
|
public static function dashboard_right_now(): void {
|
||||||
$total_files = wp_count_posts( 'scliveticker_tick' );
|
$total_files = wp_count_posts( 'scliveticker_tick' );
|
||||||
|
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
@ -37,231 +37,24 @@ class Admin extends SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function register_settings_page() {
|
public static function register_settings_page(): void {
|
||||||
add_submenu_page(
|
add_submenu_page(
|
||||||
'edit.php?post_type=scliveticker_tick',
|
'edit.php?post_type=scliveticker_tick',
|
||||||
'Liveticker ' . __( 'Settings', 'stklcode-liveticker' ),
|
'Liveticker ' . __( 'Settings', 'stklcode-liveticker' ),
|
||||||
__( 'Settings', 'stklcode-liveticker' ),
|
__( 'Settings', 'stklcode-liveticker' ),
|
||||||
'manage_options',
|
'manage_options',
|
||||||
'scliveticker_settings',
|
'scliveticker_settings',
|
||||||
array(
|
array( Settings::class, 'render_settings_page' )
|
||||||
__CLASS__,
|
|
||||||
'settings_page',
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Register settings API
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function register_settings() {
|
|
||||||
register_setting(
|
|
||||||
'scliveticker_settings',
|
|
||||||
self::OPTION,
|
|
||||||
array( __CLASS__, 'validate_settings' )
|
|
||||||
);
|
|
||||||
|
|
||||||
// Form sections.
|
|
||||||
add_settings_section(
|
|
||||||
'scliveticker_settings_general',
|
|
||||||
__( 'General', 'stklcode-liveticker' ),
|
|
||||||
array( __CLASS__, 'settings_general_section' ),
|
|
||||||
'scliveticker-settings-page'
|
|
||||||
);
|
|
||||||
|
|
||||||
// Form fields.
|
|
||||||
add_settings_field(
|
|
||||||
'enable_ajax',
|
|
||||||
__( 'Use AJAX', 'stklcode-liveticker' ),
|
|
||||||
array( __CLASS__, 'settings_enable_ajax_field' ),
|
|
||||||
'scliveticker-settings-page',
|
|
||||||
'scliveticker_settings_general',
|
|
||||||
array( 'label_for' => esc_attr( self::OPTION ) . '-enable-ajax' )
|
|
||||||
);
|
|
||||||
|
|
||||||
add_settings_field(
|
|
||||||
'poll_interval',
|
|
||||||
__( 'AJAX poll interval', 'stklcode-liveticker' ),
|
|
||||||
array( __CLASS__, 'settings_poll_interval_field' ),
|
|
||||||
'scliveticker-settings-page',
|
|
||||||
'scliveticker_settings_general',
|
|
||||||
array( 'label_for' => esc_attr( self::OPTION ) . '-poll-interval' )
|
|
||||||
);
|
|
||||||
|
|
||||||
add_settings_field(
|
|
||||||
'enable_css',
|
|
||||||
__( 'Default CSS Styles', 'stklcode-liveticker' ),
|
|
||||||
array( __CLASS__, 'settings_enable_css_field' ),
|
|
||||||
'scliveticker-settings-page',
|
|
||||||
'scliveticker_settings_general',
|
|
||||||
array( 'label_for' => esc_attr( self::OPTION ) . '-enable-css' )
|
|
||||||
);
|
|
||||||
|
|
||||||
add_settings_field(
|
|
||||||
'show_feed',
|
|
||||||
__( 'Show RSS feed', 'stklcode-liveticker' ),
|
|
||||||
array( __CLASS__, 'settings_show_feed_field' ),
|
|
||||||
'scliveticker-settings-page',
|
|
||||||
'scliveticker_settings_general',
|
|
||||||
array( 'label_for' => esc_attr( self::OPTION ) . '-show-feed' )
|
|
||||||
);
|
|
||||||
|
|
||||||
add_settings_field(
|
|
||||||
'enable_shortcode',
|
|
||||||
__( 'Shortcode support', 'stklcode-liveticker' ),
|
|
||||||
array( __CLASS__, 'settings_enable_shortcode_field' ),
|
|
||||||
'scliveticker-settings-page',
|
|
||||||
'scliveticker_settings_general',
|
|
||||||
array( 'label_for' => esc_attr( self::OPTION ) . '-enable-shortcode' )
|
|
||||||
);
|
|
||||||
|
|
||||||
add_settings_field(
|
|
||||||
'embedded_script',
|
|
||||||
__( 'Embedded JavaScript', 'stklcode-liveticker' ),
|
|
||||||
array( __CLASS__, 'settings_embedded_script_field' ),
|
|
||||||
'scliveticker-settings-page',
|
|
||||||
'scliveticker_settings_general',
|
|
||||||
array( 'label_for' => esc_attr( self::OPTION ) . '-embedded-script' )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render general section.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function settings_general_section() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render uninstall section.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function settings_uninstall_section() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render enable AJAX field.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function settings_enable_ajax_field() {
|
|
||||||
$checked = self::$options['enable_ajax'];
|
|
||||||
|
|
||||||
echo '<input id="' . esc_attr( self::OPTION ) . '-enable-ajax" type="checkbox" name="' . esc_attr( self::OPTION ) . '[enable_ajax]" value="1" ' . checked( $checked, 1, false ) . '> ';
|
|
||||||
esc_html_e( 'Enable', 'stklcode-liveticker' );
|
|
||||||
echo '<p class="description">' . esc_html__( 'Disable this option to not use AJAX update. This means all liveticker widgets and shortcodes are only updated once on site load.', 'stklcode-liveticker' ) . '</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render AJAX poll interval field.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function settings_poll_interval_field() {
|
|
||||||
$poll_interval = self::$options['poll_interval'];
|
|
||||||
|
|
||||||
echo '<input id="' . esc_attr( self::OPTION ) . '-poll-interval" type="number" name="' . esc_attr( self::OPTION ) . '[poll_interval]" value="' . esc_attr( $poll_interval ) . '"> ';
|
|
||||||
esc_html_e( 'seconds', 'stklcode-liveticker' );
|
|
||||||
echo '<p class="description">' . esc_html__( 'Interval (in seconds) to update ticker if AJAX is enabled.', 'stklcode-liveticker' ) . '</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render enable css field.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function settings_enable_css_field() {
|
|
||||||
$checked = self::$options['enable_css'];
|
|
||||||
|
|
||||||
echo '<input id="' . esc_attr( self::OPTION ) . '-enable-css" type="checkbox" name="' . esc_attr( self::OPTION ) . '[enable_css]" value="1" ' . checked( $checked, 1, false ) . ' /> ';
|
|
||||||
esc_html_e( 'Enable', 'stklcode-liveticker' );
|
|
||||||
echo '<p class="description">' . esc_html__( 'Disable this option to remove the default styling CSS file.', 'stklcode-liveticker' ) . '</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render enable css field.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function settings_show_feed_field() {
|
|
||||||
$checked = self::$options['show_feed'];
|
|
||||||
|
|
||||||
echo '<input id="' . esc_attr( self::OPTION ) . '-show-feed" type="checkbox" name="' . esc_attr( self::OPTION ) . '[show_feed]" value="1" ' . checked( $checked, 1, false ) . ' /> ';
|
|
||||||
esc_html_e( 'Enable', 'stklcode-liveticker' );
|
|
||||||
echo '<p class="description">' . esc_html__( 'Can be overwritten in shortcode.', 'stklcode-liveticker' ) . '</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render enable shortcode field.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.2
|
|
||||||
*/
|
|
||||||
public static function settings_enable_shortcode_field() {
|
|
||||||
$checked = self::$options['enable_shortcode'];
|
|
||||||
|
|
||||||
echo '<input id="' . esc_attr( self::OPTION ) . '-enable-shortcode" type="checkbox" name="' . esc_attr( self::OPTION ) . '[enable_shortcode]" value="1" ' . checked( $checked, 1, false ) . ' /> ';
|
|
||||||
esc_html_e( 'Enable', 'stklcode-liveticker' );
|
|
||||||
echo '<p class="description">' . esc_html__( 'Enable shortcode processing in tick content.', 'stklcode-liveticker' ) . '</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render embedded script field.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.2
|
|
||||||
*/
|
|
||||||
public static function settings_embedded_script_field() {
|
|
||||||
$checked = self::$options['embedded_script'];
|
|
||||||
|
|
||||||
echo '<input id="' . esc_attr( self::OPTION ) . '-embedded-script" type="checkbox" name="' . esc_attr( self::OPTION ) . '[embedded_script]" value="1" ' . checked( $checked, 1, false ) . ' /> ';
|
|
||||||
esc_html_e( 'Enable', 'stklcode-liveticker' );
|
|
||||||
echo '<p class="description">' . esc_html__( 'Allow embedded script evaluation in tick contents. This might be useful for embedded content, e.g. social media integrations.', 'stklcode-liveticker' ) . '</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render the settings page.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function settings_page() {
|
|
||||||
include SCLIVETICKER_DIR . 'views/settings-page.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate settings callback.
|
|
||||||
*
|
|
||||||
* @param array $input Input arguments.
|
|
||||||
*
|
|
||||||
* @return array Parsed arguments.
|
|
||||||
*/
|
|
||||||
public static function validate_settings( $input ) {
|
|
||||||
$defaults = self::default_options();
|
|
||||||
|
|
||||||
$result['enable_ajax'] = isset( $input['enable_ajax'] ) ? intval( $input['enable_ajax'] ) : 0;
|
|
||||||
$result['poll_interval'] = isset( $input['poll_interval'] ) ? intval( $input['poll_interval'] ) : $defaults['poll_interval'];
|
|
||||||
$result['enable_css'] = isset( $input['enable_css'] ) ? intval( $input['enable_css'] ) : 0;
|
|
||||||
$result['show_feed'] = isset( $input['show_feed'] ) ? intval( $input['show_feed'] ) : 0;
|
|
||||||
$result['enable_shortcode'] = isset( $input['enable_shortcode'] ) ? intval( $input['enable_shortcode'] ) : 0;
|
|
||||||
$result['embedded_script'] = isset( $input['embedded_script'] ) ? intval( $input['embedded_script'] ) : 0;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register custom Gutenberg block type.
|
* Register custom Gutenberg block type.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
public static function register_block() {
|
public static function register_block(): void {
|
||||||
wp_register_script(
|
wp_register_script(
|
||||||
'scliveticker-editor',
|
'scliveticker-editor',
|
||||||
SCLIVETICKER_BASE . 'scripts/block.min.js',
|
SCLIVETICKER_BASE . 'scripts/block.min.js',
|
||||||
|
@ -15,6 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use WP_REST_Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Liveticker.
|
* Liveticker.
|
||||||
@ -27,7 +28,7 @@ class Api {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init(): void {
|
||||||
// Add rendered modification date to WP_Post object.
|
// Add rendered modification date to WP_Post object.
|
||||||
register_rest_field(
|
register_rest_field(
|
||||||
'scliveticker_tick',
|
'scliveticker_tick',
|
||||||
@ -48,11 +49,11 @@ class Api {
|
|||||||
* Filter tick queries by ticker slug and date.
|
* Filter tick queries by ticker slug and date.
|
||||||
*
|
*
|
||||||
* @param array $args Query vars.
|
* @param array $args Query vars.
|
||||||
* @param \WP_REST_Request $request The REST request.
|
* @param WP_REST_Request $request The REST request.
|
||||||
*
|
*
|
||||||
* @return array Filtered query values.
|
* @return array Filtered query values.
|
||||||
*/
|
*/
|
||||||
public static function tick_query_filter( $args, $request ) {
|
public static function tick_query_filter( array $args, WP_REST_Request $request ): array {
|
||||||
// Extract arguments.
|
// Extract arguments.
|
||||||
$ticker_slug = $request->get_param( 'ticker' );
|
$ticker_slug = $request->get_param( 'ticker' );
|
||||||
$limit = intval( $request->get_param( 'limit' ) );
|
$limit = intval( $request->get_param( 'limit' ) );
|
||||||
|
@ -26,7 +26,7 @@ class SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @var string OPTIONS
|
* @var string OPTIONS
|
||||||
*/
|
*/
|
||||||
const VERSION = '1.2.3';
|
const VERSION = '1.3.0';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options tag.
|
* Options tag.
|
||||||
@ -62,7 +62,7 @@ class SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init(): void {
|
||||||
// Skip on autosave.
|
// Skip on autosave.
|
||||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||||
return;
|
return;
|
||||||
@ -81,7 +81,7 @@ class SCLiveticker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load Textdomain.
|
// Load Textdomain.
|
||||||
load_plugin_textdomain( 'stklcode-liveticker', false );
|
load_plugin_textdomain( 'stklcode-liveticker' );
|
||||||
|
|
||||||
// Allow shortcodes in widgets.
|
// Allow shortcodes in widgets.
|
||||||
add_filter( 'widget_text', 'do_shortcode' );
|
add_filter( 'widget_text', 'do_shortcode' );
|
||||||
@ -104,7 +104,7 @@ class SCLiveticker {
|
|||||||
add_action( 'right_now_content_table_end', array( 'SCLiveticker\\Admin', 'dashboard_right_now' ) );
|
add_action( 'right_now_content_table_end', array( 'SCLiveticker\\Admin', 'dashboard_right_now' ) );
|
||||||
|
|
||||||
// Settings.
|
// Settings.
|
||||||
add_action( 'admin_init', array( 'SCLiveticker\\Admin', 'register_settings' ) );
|
add_action( 'admin_init', array( 'SCLiveticker\\Settings', 'register_settings' ) );
|
||||||
add_action( 'admin_menu', array( 'SCLiveticker\\Admin', 'register_settings_page' ) );
|
add_action( 'admin_menu', array( 'SCLiveticker\\Admin', 'register_settings_page' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ class SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function register_types() {
|
public static function register_types(): void {
|
||||||
// Add new taxonomy, make it hierarchical (like categories).
|
// Add new taxonomy, make it hierarchical (like categories).
|
||||||
$labels = array(
|
$labels = array(
|
||||||
'name' => _x( 'Ticker', 'taxonomy general name', 'stklcode-liveticker' ),
|
'name' => _x( 'Ticker', 'taxonomy general name', 'stklcode-liveticker' ),
|
||||||
@ -182,7 +182,7 @@ class SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function shortcode_ticker_show( $atts ) {
|
public static function shortcode_ticker_show( array $atts ): string {
|
||||||
// Indicate presence of shortcode (to enqueue styles/scripts later).
|
// Indicate presence of shortcode (to enqueue styles/scripts later).
|
||||||
self::$shortcode_present = true;
|
self::$shortcode_present = true;
|
||||||
|
|
||||||
@ -259,9 +259,9 @@ class SCLiveticker {
|
|||||||
* @return void
|
* @return void
|
||||||
* @since 1.1 Combined former methods "enqueue_styles" and "enqueue_scripts".
|
* @since 1.1 Combined former methods "enqueue_styles" and "enqueue_scripts".
|
||||||
*/
|
*/
|
||||||
public static function enqueue_resources() {
|
public static function enqueue_resources(): void {
|
||||||
// Only add if shortcode is present.
|
// Only add if shortcode is present.
|
||||||
if ( self::$shortcode_present || self::$widget_present || self::block_present() ) {
|
if ( self::$shortcode_present || self::$widget_present || has_block( 'scliveticker/ticker' ) ) {
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'scliveticker-js',
|
'scliveticker-js',
|
||||||
SCLIVETICKER_BASE . 'scripts/liveticker.min.js',
|
SCLIVETICKER_BASE . 'scripts/liveticker.min.js',
|
||||||
@ -289,8 +289,7 @@ class SCLiveticker {
|
|||||||
'sclt-css',
|
'sclt-css',
|
||||||
SCLIVETICKER_BASE . 'styles/liveticker.min.css',
|
SCLIVETICKER_BASE . 'styles/liveticker.min.css',
|
||||||
'',
|
'',
|
||||||
self::VERSION,
|
self::VERSION
|
||||||
'all'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,7 +300,7 @@ class SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function ajax_update() {
|
public static function ajax_update(): void {
|
||||||
// Verify AJAX nonce.
|
// Verify AJAX nonce.
|
||||||
check_ajax_referer( 'scliveticker_update-ticks' );
|
check_ajax_referer( 'scliveticker_update-ticks' );
|
||||||
|
|
||||||
@ -394,18 +393,19 @@ class SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function mark_widget_present() {
|
public static function mark_widget_present(): void {
|
||||||
self::$widget_present = true;
|
self::$widget_present = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update options.
|
* Update options.
|
||||||
*
|
*
|
||||||
* @param array $options Optional. New options to save.
|
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @since 1.3.0 removed unused parameter
|
||||||
*/
|
*/
|
||||||
protected static function update_options( $options = null ) {
|
protected static function update_options(): void {
|
||||||
self::$options = wp_parse_args(
|
self::$options = wp_parse_args(
|
||||||
get_option( self::OPTION ),
|
get_option( self::OPTION ),
|
||||||
self::default_options()
|
self::default_options()
|
||||||
@ -417,7 +417,7 @@ class SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return array The options array.
|
* @return array The options array.
|
||||||
*/
|
*/
|
||||||
protected static function default_options() {
|
protected static function default_options(): array {
|
||||||
return array(
|
return array(
|
||||||
'enable_ajax' => 1,
|
'enable_ajax' => 1,
|
||||||
'poll_interval' => 60,
|
'poll_interval' => 60,
|
||||||
@ -439,7 +439,7 @@ class SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return string HTML code of tick.
|
* @return string HTML code of tick.
|
||||||
*/
|
*/
|
||||||
private static function tick_html( $time, $title, $content, $id ) {
|
private static function tick_html( string $time, string $title, string $content, int $id ): string {
|
||||||
if ( self::$options['enable_shortcode'] ) {
|
if ( self::$options['enable_shortcode'] ) {
|
||||||
$content = do_shortcode( $content );
|
$content = do_shortcode( $content );
|
||||||
}
|
}
|
||||||
@ -460,7 +460,7 @@ class SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return string HTML code of widget tick.
|
* @return string HTML code of widget tick.
|
||||||
*/
|
*/
|
||||||
public static function tick_html_widget( $time, $title, $highlight, $id = 0 ) {
|
public static function tick_html_widget( string $time, string $title, bool $highlight, int $id = 0 ): string {
|
||||||
$out = '<li';
|
$out = '<li';
|
||||||
if ( $highlight ) {
|
if ( $highlight ) {
|
||||||
$out .= ' class="sclt-widget-new"';
|
$out .= ' class="sclt-widget-new"';
|
||||||
@ -473,15 +473,4 @@ class SCLiveticker {
|
|||||||
. '<span class="sclt-widget-title">' . $title . '</span>'
|
. '<span class="sclt-widget-title">' . $title . '</span>'
|
||||||
. '</li>';
|
. '</li>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the Gutenberg block is present in current post.
|
|
||||||
*
|
|
||||||
* @return boolean True, if Gutenberg block is present.
|
|
||||||
* @since 1.1
|
|
||||||
*/
|
|
||||||
private static function block_present() {
|
|
||||||
return function_exists( 'has_block' ) && // We are in WP 5.x environment.
|
|
||||||
has_block( 'scliveticker/ticker' ); // Specific block is present.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
305
includes/class-settings.php
Normal file
@ -0,0 +1,305 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Liveticker: Plugin settings class.
|
||||||
|
*
|
||||||
|
* This file contains the derived class for the plugin's settings.
|
||||||
|
*
|
||||||
|
* @package SCLiveticker
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace SCLiveticker;
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liveticker admin configuration.
|
||||||
|
*
|
||||||
|
* @since 1.3.0 extracted from {@link Admin} class
|
||||||
|
*/
|
||||||
|
class Settings extends SCLiveticker {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register settings API
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function register_settings(): void {
|
||||||
|
register_setting(
|
||||||
|
'scliveticker_settings',
|
||||||
|
self::OPTION,
|
||||||
|
array( __CLASS__, 'validate_settings' )
|
||||||
|
);
|
||||||
|
|
||||||
|
// Form sections.
|
||||||
|
add_settings_section(
|
||||||
|
'scliveticker_settings_general',
|
||||||
|
__( 'General', 'stklcode-liveticker' ),
|
||||||
|
array( __CLASS__, 'settings_general_section' ),
|
||||||
|
'scliveticker-settings-page'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Form fields.
|
||||||
|
add_settings_field(
|
||||||
|
'enable_ajax',
|
||||||
|
__( 'Use AJAX', 'stklcode-liveticker' ),
|
||||||
|
array( __CLASS__, 'settings_enable_ajax_field' ),
|
||||||
|
'scliveticker-settings-page',
|
||||||
|
'scliveticker_settings_general',
|
||||||
|
array( 'label_for' => esc_attr( self::OPTION ) . '-enable-ajax' )
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
'poll_interval',
|
||||||
|
__( 'AJAX poll interval', 'stklcode-liveticker' ),
|
||||||
|
array( __CLASS__, 'settings_poll_interval_field' ),
|
||||||
|
'scliveticker-settings-page',
|
||||||
|
'scliveticker_settings_general',
|
||||||
|
array( 'label_for' => esc_attr( self::OPTION ) . '-poll-interval' )
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
'enable_css',
|
||||||
|
__( 'Default CSS Styles', 'stklcode-liveticker' ),
|
||||||
|
array( __CLASS__, 'settings_enable_css_field' ),
|
||||||
|
'scliveticker-settings-page',
|
||||||
|
'scliveticker_settings_general',
|
||||||
|
array( 'label_for' => esc_attr( self::OPTION ) . '-enable-css' )
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
'show_feed',
|
||||||
|
__( 'Show RSS feed', 'stklcode-liveticker' ),
|
||||||
|
array( __CLASS__, 'settings_show_feed_field' ),
|
||||||
|
'scliveticker-settings-page',
|
||||||
|
'scliveticker_settings_general',
|
||||||
|
array( 'label_for' => esc_attr( self::OPTION ) . '-show-feed' )
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
'enable_shortcode',
|
||||||
|
__( 'Shortcode support', 'stklcode-liveticker' ),
|
||||||
|
array( __CLASS__, 'settings_enable_shortcode_field' ),
|
||||||
|
'scliveticker-settings-page',
|
||||||
|
'scliveticker_settings_general',
|
||||||
|
array( 'label_for' => esc_attr( self::OPTION ) . '-enable-shortcode' )
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
'embedded_script',
|
||||||
|
__( 'Embedded JavaScript', 'stklcode-liveticker' ),
|
||||||
|
array( __CLASS__, 'settings_embedded_script_field' ),
|
||||||
|
'scliveticker-settings-page',
|
||||||
|
'scliveticker_settings_general',
|
||||||
|
array( 'label_for' => esc_attr( self::OPTION ) . '-embedded-script' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the settings page.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function render_settings_page(): void {
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<div id="icon-options-general" class="icon32"><br></div>
|
||||||
|
<h2>Liveticker <?php esc_html_e( 'Settings', 'stklcode-liveticker' ); ?></h2>
|
||||||
|
<?php
|
||||||
|
if ( isset( $_GET['settings-updated'] ) ) { // phpcs:ignore
|
||||||
|
echo '<div class="updated"><p>' . esc_html__( 'Settings updated successfully.', 'stklcode-liveticker' ) . '</p></div>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<form action="options.php" method="post">
|
||||||
|
<?php
|
||||||
|
settings_fields( 'scliveticker_settings' );
|
||||||
|
do_settings_sections( 'scliveticker-settings-page' );
|
||||||
|
submit_button();
|
||||||
|
?>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render general section.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function settings_general_section(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render enable AJAX field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function settings_enable_ajax_field(): void {
|
||||||
|
self::render_checkbox(
|
||||||
|
'enable-ajax',
|
||||||
|
'[enable_ajax]',
|
||||||
|
self::$options['enable_ajax'],
|
||||||
|
__( 'Disable this option to not use AJAX update. This means all liveticker widgets and shortcodes are only updated once on site load.', 'stklcode-liveticker' ),
|
||||||
|
__( 'Enable AJAX updates', 'stklcode-liveticker' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render AJAX poll interval field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function settings_poll_interval_field(): void {
|
||||||
|
$poll_interval = self::$options['poll_interval'];
|
||||||
|
|
||||||
|
echo '<input id="' . esc_attr( self::OPTION ) . '-poll-interval" type="number" name="' . esc_attr( self::OPTION ) . '[poll_interval]" value="' . esc_attr( $poll_interval ) . '"> ';
|
||||||
|
esc_html_e( 'seconds', 'stklcode-liveticker' );
|
||||||
|
echo '<p class="description">' . esc_html__( 'Interval (in seconds) to update ticker if AJAX is enabled.', 'stklcode-liveticker' ) . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render enable css field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function settings_enable_css_field(): void {
|
||||||
|
self::render_checkbox(
|
||||||
|
'enable-css',
|
||||||
|
'[enable_css]',
|
||||||
|
self::$options['enable_css'],
|
||||||
|
__( 'Disable this option to remove the default styling CSS file.', 'stklcode-liveticker' ),
|
||||||
|
__( 'Enable default stylesheet', 'stklcode-liveticker' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render enable css field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function settings_show_feed_field(): void {
|
||||||
|
self::render_checkbox(
|
||||||
|
'show-feed',
|
||||||
|
'[show_feed]',
|
||||||
|
self::$options['show_feed'],
|
||||||
|
__( 'Can be overwritten in shortcode.', 'stklcode-liveticker' ),
|
||||||
|
__( 'Show RSS feed in shortcode', 'stklcode-liveticker' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render enable shortcode field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.2.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function settings_enable_shortcode_field(): void {
|
||||||
|
self::render_checkbox(
|
||||||
|
'enable-shortcode',
|
||||||
|
'[enable_shortcode]',
|
||||||
|
self::$options['enable_shortcode'],
|
||||||
|
__( 'Enable shortcode processing in tick content.', 'stklcode-liveticker' ),
|
||||||
|
__( 'Allow shortcodes in tick content', 'stklcode-liveticker' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render embedded script field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.2.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function settings_embedded_script_field(): void {
|
||||||
|
self::render_checkbox(
|
||||||
|
'embedded-script',
|
||||||
|
'[embedded_script]',
|
||||||
|
self::$options['embedded_script'],
|
||||||
|
__( 'Allow embedded script evaluation in tick contents. This might be useful for embedded content, e.g. social media integrations.', 'stklcode-liveticker' ) .
|
||||||
|
' ' .
|
||||||
|
__( 'Be aware that this feature potentially enables cross-site scripting, so make sure content is created by trusted people and only enable this if required.', 'stklcode-liveticker' ),
|
||||||
|
__( 'Allow JavaScript in tick content', 'stklcode-liveticker' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate settings callback.
|
||||||
|
*
|
||||||
|
* @param array $input Input arguments.
|
||||||
|
*
|
||||||
|
* @return array Parsed arguments.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @since 1.3.0 moved from Admin to Settings class
|
||||||
|
*/
|
||||||
|
public static function validate_settings( array $input ): array {
|
||||||
|
$defaults = self::default_options();
|
||||||
|
|
||||||
|
$result['enable_ajax'] = isset( $input['enable_ajax'] ) ? intval( $input['enable_ajax'] ) : 0;
|
||||||
|
$result['poll_interval'] = isset( $input['poll_interval'] ) ? intval( $input['poll_interval'] ) : $defaults['poll_interval'];
|
||||||
|
$result['enable_css'] = isset( $input['enable_css'] ) ? intval( $input['enable_css'] ) : 0;
|
||||||
|
$result['show_feed'] = isset( $input['show_feed'] ) ? intval( $input['show_feed'] ) : 0;
|
||||||
|
$result['enable_shortcode'] = isset( $input['enable_shortcode'] ) ? intval( $input['enable_shortcode'] ) : 0;
|
||||||
|
$result['embedded_script'] = isset( $input['embedded_script'] ) ? intval( $input['embedded_script'] ) : 0;
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render a checkbox field.
|
||||||
|
*
|
||||||
|
* @param string $id Field ID.
|
||||||
|
* @param string $name Option name.
|
||||||
|
* @param mixed $value Current value.
|
||||||
|
* @param string $description Description text.
|
||||||
|
* @param string $screen_reader_text Screen reader text.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function render_checkbox(
|
||||||
|
string $id,
|
||||||
|
string $name,
|
||||||
|
$value,
|
||||||
|
string $description,
|
||||||
|
string $screen_reader_text
|
||||||
|
) {
|
||||||
|
?>
|
||||||
|
<fieldset>
|
||||||
|
<legend class="screen-reader-text"><?php echo esc_html( $screen_reader_text ); ?></legend>
|
||||||
|
<label for="<?php echo esc_attr( self::OPTION . '-' . $id ); ?>">
|
||||||
|
<input id="<?php echo esc_attr( self::OPTION . '-' . $id ); ?>" name="<?php echo esc_attr( self::OPTION . $name ); ?>" type="checkbox" value="1" <?php checked( $value, 1 ); ?>>
|
||||||
|
<?php esc_html_e( 'Enable', 'stklcode-liveticker' ); ?>
|
||||||
|
</label>
|
||||||
|
<p class="description"><?php echo esc_html( $description ); ?></p>
|
||||||
|
</fieldset>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,7 @@ class System extends SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function activate() {
|
public static function activate(): void {
|
||||||
// Load current options.
|
// Load current options.
|
||||||
self::update_options();
|
self::update_options();
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ class System extends SCLiveticker {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function uninstall() {
|
public static function uninstall(): void {
|
||||||
// Delete all ticks.
|
// Delete all ticks.
|
||||||
$ticks = new WP_Query( array( 'post_type' => 'scliveticker_tick' ) );
|
$ticks = new WP_Query( array( 'post_type' => 'scliveticker_tick' ) );
|
||||||
foreach ( $ticks->get_posts() as $tick ) {
|
foreach ( $ticks->get_posts() as $tick ) {
|
||||||
|
@ -31,7 +31,7 @@ class Widget extends WP_Widget {
|
|||||||
/**
|
/**
|
||||||
* Register the widget.
|
* Register the widget.
|
||||||
*/
|
*/
|
||||||
public static function register() {
|
public static function register(): void {
|
||||||
register_widget( __CLASS__ );
|
register_widget( __CLASS__ );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,10 +49,10 @@ class Widget extends WP_Widget {
|
|||||||
SCLiveticker::mark_widget_present();
|
SCLiveticker::mark_widget_present();
|
||||||
|
|
||||||
$instance = self::fill_options_with_defaults( $instance );
|
$instance = self::fill_options_with_defaults( $instance );
|
||||||
$before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
|
$before_widget = $args['before_widget'] ?? '';
|
||||||
$after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
|
$after_widget = $args['after_widget'] ?? '';
|
||||||
$before_title = isset( $args['before_title'] ) ? $args['before_title'] : '';
|
$before_title = $args['before_title'] ?? '';
|
||||||
$after_title = isset( $args['after_title'] ) ? $args['after_title'] : '';
|
$after_title = $args['after_title'] ?? '';
|
||||||
$title = apply_filters( 'scliveticker_catlit', $instance['title'] );
|
$title = apply_filters( 'scliveticker_catlit', $instance['title'] );
|
||||||
$category = apply_filters( 'scliveticker_catlit', $instance['category'] );
|
$category = apply_filters( 'scliveticker_catlit', $instance['category'] );
|
||||||
$count = apply_filters( 'scliveticker_catlit', $instance['count'] );
|
$count = apply_filters( 'scliveticker_catlit', $instance['count'] );
|
||||||
@ -164,7 +164,7 @@ class Widget extends WP_Widget {
|
|||||||
*
|
*
|
||||||
* @return array Complete instance configuration.
|
* @return array Complete instance configuration.
|
||||||
*/
|
*/
|
||||||
private static function fill_options_with_defaults( $instance ) {
|
private static function fill_options_with_defaults( array $instance ): array {
|
||||||
$default = array(
|
$default = array(
|
||||||
'title' => '',
|
'title' => '',
|
||||||
'category' => '',
|
'category' => '',
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "stklcode-liveticker",
|
"name": "stklcode-liveticker",
|
||||||
"version": "1.2.3",
|
"version": "1.3.0",
|
||||||
"description": "A simple Liveticker for Wordpress.",
|
"description": "A simple Liveticker for Wordpress.",
|
||||||
"author": "Stefan Kalscheuer",
|
"author": "Stefan Kalscheuer",
|
||||||
"license": "GPL-2.0+",
|
"license": "GPL-2.0+",
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<file>views</file>
|
<file>views</file>
|
||||||
|
|
||||||
<!-- Compliance with WordPress Coding Standard -->
|
<!-- Compliance with WordPress Coding Standard -->
|
||||||
<config name="minimum_supported_wp_version" value="4.7"/>
|
<config name="minimum_supported_wp_version" value="5.0"/>
|
||||||
<rule ref="WordPress">
|
<rule ref="WordPress">
|
||||||
<exclude name="WordPress.DB.SlowDBQuery.slow_db_query_tax_query"/>
|
<exclude name="WordPress.DB.SlowDBQuery.slow_db_query_tax_query"/>
|
||||||
</rule>
|
</rule>
|
||||||
@ -25,6 +25,6 @@
|
|||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<!-- PHP compatibility level -->
|
<!-- PHP compatibility level -->
|
||||||
<config name="testVersion" value="5.6-"/>
|
<config name="testVersion" value="7.2-"/>
|
||||||
<rule ref="PHPCompatibilityWP"/>
|
<rule ref="PHPCompatibilityWP"/>
|
||||||
</ruleset>
|
</ruleset>
|
||||||
|
@ -86,6 +86,10 @@
|
|||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
sort: {
|
||||||
|
type: 'string',
|
||||||
|
// implicit default: 'desc', left empty here for backwards compatibility of the block
|
||||||
|
},
|
||||||
},
|
},
|
||||||
edit: withSelect( function( select ) {
|
edit: withSelect( function( select ) {
|
||||||
return {
|
return {
|
||||||
@ -166,6 +170,26 @@
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
el(
|
||||||
|
wp.components.SelectControl,
|
||||||
|
{
|
||||||
|
label: __( 'Output direction', 'stklcode-liveticker' ),
|
||||||
|
value: props.attributes.sort,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
value: 'desc',
|
||||||
|
label: __( 'newest first', 'stklcode-liveticker' ),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'asc',
|
||||||
|
label: __( 'oldest first', 'stklcode-liveticker' ),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
onChange: function( val ) {
|
||||||
|
props.setAttributes( { sort: val } );
|
||||||
|
},
|
||||||
|
}
|
||||||
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,6 +207,7 @@
|
|||||||
'data-sclt-ticker': props.attributes.ticker,
|
'data-sclt-ticker': props.attributes.ticker,
|
||||||
'data-sclt-limit': props.attributes.unlimited ? 0 : props.attributes.limit,
|
'data-sclt-limit': props.attributes.unlimited ? 0 : props.attributes.limit,
|
||||||
'data-sclt-last': 0,
|
'data-sclt-last': 0,
|
||||||
|
'data-sclt-sort': props.attributes.sort,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Contructor of the scLiveticker object.
|
* Constructor of the scLiveticker object.
|
||||||
*
|
*
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
@ -73,6 +73,7 @@
|
|||||||
var parseElement = function( elem, widget, n ) {
|
var parseElement = function( elem, widget, n ) {
|
||||||
var list = elem.querySelector( 'ul' );
|
var list = elem.querySelector( 'ul' );
|
||||||
var last = elem.getAttribute( 'data-sclt-last' );
|
var last = elem.getAttribute( 'data-sclt-last' );
|
||||||
|
var sort = elem.getAttribute( 'data-sclt-sort' );
|
||||||
|
|
||||||
elem.id = 'sclt-' + n;
|
elem.id = 'sclt-' + n;
|
||||||
|
|
||||||
@ -92,11 +93,16 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( 'asc' !== sort && 'desc' !== 'sort' ) {
|
||||||
|
sort = 'desc';
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: n,
|
id: n,
|
||||||
ticker: elem.getAttribute( 'data-sclt-ticker' ),
|
ticker: elem.getAttribute( 'data-sclt-ticker' ),
|
||||||
limit: elem.getAttribute( 'data-sclt-limit' ),
|
limit: elem.getAttribute( 'data-sclt-limit' ),
|
||||||
lastPoll: last,
|
lastPoll: last,
|
||||||
|
sort: sort,
|
||||||
ticks: list,
|
ticks: list,
|
||||||
isWidget: widget,
|
isWidget: widget,
|
||||||
updating: false,
|
updating: false,
|
||||||
@ -210,8 +216,11 @@
|
|||||||
if ( old ) {
|
if ( old ) {
|
||||||
// Replace entry, if it already exists (i.e. has been updated).
|
// Replace entry, if it already exists (i.e. has been updated).
|
||||||
t.ticks.replaceChild( li, old );
|
t.ticks.replaceChild( li, old );
|
||||||
|
} else if ( 'asc' === t.sort ) {
|
||||||
|
// Append new tick as last element to container.
|
||||||
|
t.ticks.appendChild( li );
|
||||||
} else {
|
} else {
|
||||||
// Prepend new tick to container.
|
// Prepend new tick as fist element to container.
|
||||||
t.ticks.insertBefore( li, t.ticks.firstChild );
|
t.ticks.insertBefore( li, t.ticks.firstChild );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,8 +229,13 @@
|
|||||||
t.ticks.parentNode.setAttribute( 'data-sclt-last', u.date_gmt );
|
t.ticks.parentNode.setAttribute( 'data-sclt-last', u.date_gmt );
|
||||||
|
|
||||||
// Remove tail, if limit is set.
|
// Remove tail, if limit is set.
|
||||||
if ( 0 < t.limit ) {
|
if ( 0 < t.limit && t.limit < t.ticks.children.length ) {
|
||||||
[].slice.call( t.ticks.getElementsByTagName( 'li' ), t.limit ).forEach(
|
if ( 'asc' === t.sort ) {
|
||||||
|
old = [].slice.call( t.ticks.children, 0, -t.limit );
|
||||||
|
} else {
|
||||||
|
old = [].slice.call( t.ticks.children, t.limit );
|
||||||
|
}
|
||||||
|
old.forEach(
|
||||||
function( l ) {
|
function( l ) {
|
||||||
l.remove();
|
l.remove();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* @wordpress-plugin
|
* @wordpress-plugin
|
||||||
* Plugin Name: Liveticker (by stklcode)
|
* Plugin Name: Liveticker (by stklcode)
|
||||||
* Description: A simple Liveticker for WordPress.
|
* Description: A simple Liveticker for WordPress.
|
||||||
* Version: 1.2.3
|
* Version: 1.3.0
|
||||||
* Author: Stefan Kalscheuer
|
* Author: Stefan Kalscheuer
|
||||||
* Author URI: https://www.stklcode.de
|
* Author URI: https://www.stklcode.de
|
||||||
* Text Domain: stklcode-liveticker
|
* Text Domain: stklcode-liveticker
|
||||||
@ -26,7 +26,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with Liveticker (by stklcode). If not, see http://www.gnu.org/licenses/gpl-2.0.html.
|
* along with Liveticker (by stklcode). If not, see https://www.gnu.org/licenses/gpl-2.0.html.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Exit if accessed directly.
|
// Exit if accessed directly.
|
||||||
@ -68,11 +68,12 @@ spl_autoload_register( 'scliveticker_autoload' );
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function scliveticker_autoload( $class_name ) {
|
function scliveticker_autoload( string $class_name ): void {
|
||||||
$plugin_classes = array(
|
$plugin_classes = array(
|
||||||
'SCLiveticker\\SCLiveticker',
|
'SCLiveticker\\SCLiveticker',
|
||||||
'SCLiveticker\\Admin',
|
'SCLiveticker\\Admin',
|
||||||
'SCLiveticker\\Api',
|
'SCLiveticker\\Api',
|
||||||
|
'SCLiveticker\\Settings',
|
||||||
'SCLiveticker\\System',
|
'SCLiveticker\\System',
|
||||||
'SCLiveticker\\Widget',
|
'SCLiveticker\\Widget',
|
||||||
);
|
);
|
||||||
|
@ -5,34 +5,25 @@
|
|||||||
* @package SCLiveticker
|
* @package SCLiveticker
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$_tests_dir = getenv( 'WP_TESTS_DIR' );
|
use Yoast\WPTestUtils\WPIntegration;
|
||||||
|
|
||||||
if ( ! $_tests_dir ) {
|
require_once dirname( __DIR__ ) . '/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php';
|
||||||
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
|
|
||||||
|
$_tests_dir = WPIntegration\get_path_to_wp_test_dir();
|
||||||
|
|
||||||
|
// Get access to tests_add_filter() function.
|
||||||
|
require_once $_tests_dir . 'includes/functions.php';
|
||||||
|
|
||||||
|
// Add plugin to active mu-plugins to make sure it gets loaded.
|
||||||
|
tests_add_filter(
|
||||||
|
'muplugins_loaded',
|
||||||
|
function() {
|
||||||
|
require dirname( __DIR__ ) . '/stklcode-liveticker.php';
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Forward custom PHPUnit Polyfills configuration to PHPUnit bootstrap file.
|
/*
|
||||||
$_phpunit_polyfills_path = getenv( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' );
|
* Bootstrap WordPress. This will also load the Composer autoload file, the PHPUnit Polyfills
|
||||||
if ( false !== $_phpunit_polyfills_path ) {
|
* and the custom autoloader for the TestCase and the mock object classes.
|
||||||
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
|
|
||||||
echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
||||||
exit( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Give access to tests_add_filter() function.
|
|
||||||
require_once "{$_tests_dir}/includes/functions.php";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manually load the plugin being tested.
|
|
||||||
*/
|
*/
|
||||||
function _manually_load_plugin() {
|
WPIntegration\bootstrap_it();
|
||||||
require dirname( dirname( __FILE__ ) ) . '/stklcode-liveticker.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
|
|
||||||
|
|
||||||
// Start up the WP testing environment.
|
|
||||||
require "{$_tests_dir}/includes/bootstrap.php";
|
|
||||||
|
@ -13,18 +13,18 @@ use DateInterval;
|
|||||||
use DateTime;
|
use DateTime;
|
||||||
use WP_REST_Request;
|
use WP_REST_Request;
|
||||||
use WP_REST_Server;
|
use WP_REST_Server;
|
||||||
use WP_UnitTestCase;
|
use Yoast\WPTestUtils\WPIntegration\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Test_API.
|
* Class Test_API.
|
||||||
*/
|
*/
|
||||||
class Test_API extends WP_UnitTestCase {
|
class Test_API extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Initialize WP REST API for tests.
|
* Initialize WP REST API for tests.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function set_up() {
|
public function set_up(): void {
|
||||||
parent::set_up();
|
parent::set_up();
|
||||||
global $wp_rest_server;
|
global $wp_rest_server;
|
||||||
$wp_rest_server = new WP_REST_Server();
|
$wp_rest_server = new WP_REST_Server();
|
||||||
@ -36,7 +36,7 @@ class Test_API extends WP_UnitTestCase {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function test_register_route() {
|
public function test_register_route(): void {
|
||||||
global $wp_rest_server;
|
global $wp_rest_server;
|
||||||
|
|
||||||
$routes = $wp_rest_server->get_routes();
|
$routes = $wp_rest_server->get_routes();
|
||||||
@ -52,7 +52,7 @@ class Test_API extends WP_UnitTestCase {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function test_get_ticks() {
|
public function test_get_ticks(): void {
|
||||||
global $wp_rest_server;
|
global $wp_rest_server;
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'GET', '/wp/v2/scliveticker_tick' );
|
$request = new WP_REST_Request( 'GET', '/wp/v2/scliveticker_tick' );
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Liveticker: Settings page.
|
|
||||||
*
|
|
||||||
* This file contains the view model for the Plugin settings oage.
|
|
||||||
*
|
|
||||||
* @package Liveticker
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<div class="wrap">
|
|
||||||
<div id="icon-options-general" class="icon32"><br></div>
|
|
||||||
<h2>Liveticker <?php esc_html_e( 'Settings', 'stklcode-liveticker' ); ?></h2>
|
|
||||||
<?php
|
|
||||||
if ( isset( $_GET['settings-updated'] ) ) { // phpcs:ignore
|
|
||||||
echo '<div class="updated"><p>' . esc_html__( 'Settings updated successfully.', 'stklcode-liveticker' ) . '</p></div>';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<form action="options.php" method="post">
|
|
||||||
<?php
|
|
||||||
settings_fields( 'scliveticker_settings' );
|
|
||||||
do_settings_sections( 'scliveticker-settings-page' );
|
|
||||||
submit_button();
|
|
||||||
?>
|
|
||||||
</form>
|
|
||||||
</div>
|
|