123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- /**
- * Custom widgets options.
- *
- * @package Pen
- */
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! function_exists( 'pen_widgets_color_scheme_option' ) ) {
- /**
- * Color scheme option for widgets.
- *
- * @global wp_registered_widgets $wp_registered_widgets
- * @global wp_registered_sidebars $wp_registered_sidebars
- *
- * @param WP_Widget $widget An instance of WP_Widget.
- * @param null $return Whether a field was added.
- * @param array $instance Widget settings.
- *
- * @since Pen 1.0.0
- * @return void
- */
- function pen_widgets_color_scheme_option( $widget, $return, $instance ) {
- $color_widget = isset( $instance['pen_theme_color_widget'] ) ? $instance['pen_theme_color_widget'] : '';
- $animation_widget = isset( $instance['pen_theme_animation_widget'] ) ? $instance['pen_theme_animation_widget'] : '';
- ?>
- <fieldset style="border:1px dashed #ccc;margin:0 0 1em;padding:0 1em">
- <legend style="font-weight:bold" title="<?php esc_attr_e( 'This is a part of the "Pen" theme so if you switch to another theme these settings will be no longer used. The rest of the settings that are here are either parts of the WordPress core or added via plugins and they are available with or without this theme.', 'pen' ); ?>">
- <?php
- esc_html_e( 'Pen', 'pen' );
- ?>
- </legend>
- <?php
- $field_id = $widget->get_field_id( 'pen_theme_animation_widget' );
- $field_name = $widget->get_field_name( 'pen_theme_animation_widget' );
- ?>
- <p>
- <label for="<?php echo esc_attr( $field_id ); ?>">
- <?php
- esc_html_e( 'Widget Animation', 'pen' );
- ?>
- </label>
- <select id="<?php echo esc_attr( $field_id ); ?>" name="<?php echo esc_attr( $field_name ); ?>">
- <?php
- $options = pen_animations();
- foreach ( $options as $key => $label ) {
- ?>
- <option value="<?php echo $key; /* phpcs:ignore */ ?>" <?php selected( $key, $animation_widget ); ?>>
- <?php
- echo esc_html( $label );
- ?>
- </option>
- <?php
- }
- ?>
- </select>
- </p>
- <?php
- $field_id = $widget->get_field_id( 'pen_theme_color_widget' );
- $field_name = $widget->get_field_name( 'pen_theme_color_widget' );
- ?>
- <p>
- <label for="<?php echo esc_attr( $field_id ); ?>">
- <?php
- esc_html_e( 'Widget Color Scheme:', 'pen' );
- ?>
- </label>
- <select id="<?php echo esc_attr( $field_id ); ?>" name="<?php echo esc_attr( $field_name ); ?>">
- <option value="transparent" <?php selected( 'transparent', $color_widget ); ?>>
- <?php
- esc_html_e( 'None', 'pen' );
- ?>
- </option>
- <?php
- $options = array(
- 'blue' => __( 'Blue', 'pen' ),
- 'dark' => __( 'Dark', 'pen' ),
- 'light' => __( 'Light', 'pen' ),
- 'orange' => __( 'Orange', 'pen' ),
- 'purple' => __( 'Purple', 'pen' ),
- 'red' => __( 'Red', 'pen' ),
- 'yellow' => __( 'Yellow', 'pen' ),
- );
- foreach ( $options as $key => $label ) {
- ?>
- <option value="<?php echo $key; /* phpcs:ignore */ ?>" <?php selected( $key, $color_widget ); ?>>
- <?php
- echo esc_html( $label );
- ?>
- </option>
- <?php
- }
- ?>
- </select>
- </p>
- </fieldset>
- <?php
- }
- add_filter( 'in_widget_form', 'pen_widgets_color_scheme_option', 10, 3 );
- }
- if ( ! function_exists( 'pen_widgets_save_color_scheme_option' ) ) {
- /**
- * Saves the widget color schemes.
- *
- * @param array $instance Widget settings.
- * @param array $new_instance The new widget settings.
- *
- * @since Pen 1.0.0
- * @return array
- */
- function pen_widgets_save_color_scheme_option( $instance, $new_instance ) {
- return $new_instance;
- }
- add_filter( 'widget_update_callback', 'pen_widgets_save_color_scheme_option', 10, 2 );
- }
- if ( ! function_exists( 'pen_widgets_custom_classes' ) ) {
- /**
- * Custom class names for widgets.
- *
- * @global wp_registered_widgets $wp_registered_widgets
- *
- * @param array $params Widget parameters.
- *
- * @since Pen 1.0.0
- * @return array
- */
- function pen_widgets_custom_classes( $params ) {
- global $wp_registered_widgets;
- $widget_id = $params[0]['widget_id'];
- $instance_id = $params[1]['number'];
- if ( ! is_object( $wp_registered_widgets[ $widget_id ]['callback'][0] ) ) {
- return;
- }
- $settings = $wp_registered_widgets[ $widget_id ]['callback'][0]->get_settings();
- $color_widget = 'transparent';
- $animation_widget = 'fadeIn';
- $class = 'class="';
- if ( isset( $settings[ $instance_id ]['title'] ) && '' !== trim( $settings[ $instance_id ]['title'] ) ) {
- $class .= 'pen_widget_has_title ';
- }
- if ( ! empty( $settings[ $instance_id ]['pen_theme_color_widget'] ) ) {
- $color_widget = $settings[ $instance_id ]['pen_theme_color_widget'];
- }
- $class .= 'pen_widget_' . $color_widget . ' ';
- if ( 'transparent' !== $color_widget ) {
- $class .= 'pen_widget_not_transparent ';
- }
- if ( ! empty( $settings[ $instance_id ]['pen_theme_animation_widget'] ) ) {
- $animation_widget = $settings[ $instance_id ]['pen_theme_animation_widget'];
- }
- if ( $animation_widget && 'none' !== $animation_widget ) {
- $class .= 'pen_animate_on_scroll pen_custom_animation_' . $animation_widget . ' ';
- }
- $params[0]['before_widget'] = str_ireplace( 'class="', $class, $params[0]['before_widget'] );
- return $params;
- }
- add_filter( 'dynamic_sidebar_params', 'pen_widgets_custom_classes' );
- }
|