| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( class_exists('WP_Widget') ) : |
| 8 |
|
| 9 |
class FV_Player_Widget extends WP_Widget { |
| 10 |
|
| 11 |
public function __construct() { |
| 12 |
|
| 13 |
add_action('widgets_init', array($this, 'widget_init')); |
| 14 |
|
| 15 |
$widget_ops = array('classname' => 'widget_fvplayer', 'description' => __('FV Player widget.')); |
| 16 |
$control_ops = array('width' => 400, 'height' => 350); |
| 17 |
parent::__construct('widget_fvplayer', __('FV Player'), $widget_ops, $control_ops); |
| 18 |
} |
| 19 |
|
| 20 |
function widget_init() { |
| 21 |
register_widget('FV_Player_widget'); |
| 22 |
add_action('admin_footer', array($this, 'formFooter'), 0 ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Outputs the content for the current Text widget instance. |
| 27 |
* |
| 28 |
* @since 2.8.0 |
| 29 |
* @access public |
| 30 |
* |
| 31 |
* @param array $args Display arguments including 'before_title', 'after_title', |
| 32 |
* 'before_widget', and 'after_widget'. |
| 33 |
* @param array $instance Settings for the current Text widget instance. |
| 34 |
*/ |
| 35 |
public function widget($args, $instance) { |
| 36 |
|
| 37 |
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
| 38 |
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); |
| 39 |
|
| 40 |
$widget_text = !empty($instance['text']) ? $instance['text'] : ''; |
| 41 |
|
| 42 |
/** |
| 43 |
* Filter the content of the Text widget. |
| 44 |
* |
| 45 |
* @since 2.3.0 |
| 46 |
* @since 4.4.0 Added the `$this` parameter. |
| 47 |
* |
| 48 |
* @param string $widget_text The widget content. |
| 49 |
* @param array $instance Array of settings for the current widget. |
| 50 |
* @param WP_Widget_Text $this Current Text widget instance. |
| 51 |
*/ |
| 52 |
$text = apply_filters('widget_text', $widget_text, $instance, $this); |
| 53 |
|
| 54 |
echo $args['before_widget']; |
| 55 |
if (!empty($title)) { |
| 56 |
echo $args['before_title'] . $title . $args['after_title']; |
| 57 |
} |
| 58 |
?> |
| 59 |
<div class="textwidget"><?php echo!empty($instance['filter']) ? wpautop($text) : $text; ?></div> |
| 60 |
<?php |
| 61 |
echo $args['after_widget']; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Handles updating settings for the current Text widget instance. |
| 66 |
* |
| 67 |
* @since 2.8.0 |
| 68 |
* @access public |
| 69 |
* |
| 70 |
* @param array $new_instance New settings for this instance as input by the user via |
| 71 |
* WP_Widget::form(). |
| 72 |
* @param array $old_instance Old settings for this instance. |
| 73 |
* @return array Settings to save or bool false to cancel saving. |
| 74 |
*/ |
| 75 |
public function update($new_instance, $old_instance) { |
| 76 |
$instance = $old_instance; |
| 77 |
$instance['title'] = sanitize_text_field($new_instance['title']); |
| 78 |
if (current_user_can('unfiltered_html')) |
| 79 |
$instance['text'] = $new_instance['text']; |
| 80 |
else |
| 81 |
$instance['text'] = wp_kses_post(stripslashes($new_instance['text'])); |
| 82 |
$instance['filter'] = !empty($new_instance['filter']); |
| 83 |
return $instance; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Outputs the Text widget settings form. |
| 88 |
* |
| 89 |
* @since 2.8.0 |
| 90 |
* @access public |
| 91 |
* |
| 92 |
* @param array $instance Current settings. |
| 93 |
*/ |
| 94 |
public function form($instance) { |
| 95 |
add_action('admin_head', 'wp_enqueue_media'); |
| 96 |
|
| 97 |
$instance = wp_parse_args((array) $instance, array('title' => '', 'text' => '')); |
| 98 |
$filter = isset($instance['filter']) ? $instance['filter'] : 0; |
| 99 |
$title = sanitize_text_field($instance['title']); |
| 100 |
|
| 101 |
$number = intval( $this->number ); |
| 102 |
|
| 103 |
// When the widget loads for Elementor, it does not replace REPLACE_TO_ID instead of widget number |
| 104 |
if ( ! empty( $_POST['action'] ) && 'elementor_ajax' == $_POST['action'] ) { |
| 105 |
$number = 'REPLACE_TO_ID'; |
| 106 |
} |
| 107 |
?><p><label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php esc_html_e('Title:'); ?></label> |
| 108 |
|
| 109 |
<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); ?>" /></p> |
| 110 |
|
| 111 |
<p> |
| 112 |
<style> |
| 113 |
.wp-customizer .fv-wordpress-flowplayer-button { display: none; } |
| 114 |
</style> |
| 115 |
<label for="<?php echo esc_attr( $this->get_field_id('text') ); ?>"><?php esc_html_e('Player'); ?>:</label> |
| 116 |
<input type="button" id="widget-widget_fvplayer-<?php echo intval( $this->number ); ?>-savewidget" class="button button-primary left fv-wordpress-flowplayer-button" data-number="<?php echo $number ?>" value="<?php echo strlen( trim($instance['text']) ) ? 'Edit' : 'Add'; ?>"> |
| 117 |
|
| 118 |
<textarea class="widefat" rows="5" cols="5" id="<?php echo esc_attr( $this->get_field_id('text') ); ?>" name="<?php echo esc_attr( $this->get_field_name('text') ); ?>"><?php echo esc_textarea($instance['text']); ?></textarea> |
| 119 |
</p> |
| 120 |
<?php |
| 121 |
} |
| 122 |
|
| 123 |
function formFooter() { |
| 124 |
if( function_exists('get_current_screen') ) { |
| 125 |
$objScreen = get_current_screen(); |
| 126 |
if( $objScreen && $objScreen->base != 'widgets' ) return; |
| 127 |
} |
| 128 |
|
| 129 |
fv_wp_flowplayer_edit_form_after_editor(); |
| 130 |
fv_player_shortcode_editor_scripts_enqueue(); |
| 131 |
} |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
$FV_Player_Widget = new FV_Player_Widget(); |
| 136 |
|
| 137 |
endif; |
| 138 |
|