did some sniff sniff

This commit is contained in:
2025-07-14 21:47:29 -07:00
parent c6bb1b7c7b
commit 0e9321b01a
44 changed files with 2557 additions and 2259 deletions

View File

@@ -11,158 +11,158 @@
class sophia_after_dark_Author_Info extends WP_widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
$widget_ops = array(
'classname' => 'sophia_after_dark_author_info',
'description' => __( 'Select the user to display the author info.', 'sophia-after-dark' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'sophia_after_dark_author_info', __( 'MT: Author Info', 'sophia-after-dark' ), $widget_ops );
}
* Register widget with WordPress.
*/
public function __construct() {
$widget_ops = array(
'classname' => 'sophia_after_dark_author_info',
'description' => __( 'Select the user to display the author info.', 'sophia-after-dark' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'sophia_after_dark_author_info', __( 'MT: Author Info', 'sophia-after-dark' ), $widget_ops );
}
/**
* Helper function that holds widget fields
* Array is used in update and form functions
*/
private function widget_fields() {
$fields = array(
/**
* Helper function that holds widget fields
* Array is used in update and form functions
*/
private function widget_fields() {
$fields = array(
'widget_title' => array(
'sophia_after_dark_widgets_name' => 'widget_title',
'sophia_after_dark_widgets_title' => __( 'Widget title', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'text'
),
'widget_title' => array(
'sophia_after_dark_widgets_name' => 'widget_title',
'sophia_after_dark_widgets_title' => __( 'Widget title', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'text',
),
'user_name' => array(
'sophia_after_dark_widgets_name' => 'user_name',
'sophia_after_dark_widgets_title' => __( 'User Name', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'text'
),
'user_name' => array(
'sophia_after_dark_widgets_name' => 'user_name',
'sophia_after_dark_widgets_title' => __( 'User Name', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'text',
),
'user_id' => array(
'sophia_after_dark_widgets_name' => 'user_id',
'sophia_after_dark_widgets_title' => __( 'Select Author', 'sophia-after-dark' ),
'sophia_after_dark_widgets_default' => '',
'sophia_after_dark_widgets_field_type' => 'user_dropdown'
),
'user_id' => array(
'sophia_after_dark_widgets_name' => 'user_id',
'sophia_after_dark_widgets_title' => __( 'Select Author', 'sophia-after-dark' ),
'sophia_after_dark_widgets_default' => '',
'sophia_after_dark_widgets_field_type' => 'user_dropdown',
),
'user_thumb' => array(
'sophia_after_dark_widgets_name' => 'user_thumb',
'sophia_after_dark_widgets_title' => __( 'Author Image', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'upload'
),
'user_thumb' => array(
'sophia_after_dark_widgets_name' => 'user_thumb',
'sophia_after_dark_widgets_title' => __( 'Author Image', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'upload',
),
);
return $fields;
}
);
return $fields;
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
extract( $args );
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
extract( $args );
if ( empty( $instance ) ) {
return ;
}
if ( empty( $instance ) ) {
return;
}
$sophia_after_dark_widget_title = empty( $instance['widget_title'] ) ? '' : $instance['widget_title'];
$sophia_after_dark_user_name = empty( $instance['user_name'] ) ? '' : $instance['user_name'];
$sophia_after_dark_user_id = empty( $instance['user_id'] ) ? '' : $instance['user_id'];
$sophia_after_dark_user_image = empty( $instance['user_thumb'] ) ? '' : $instance['user_thumb'];
$sophia_after_dark_widget_title = empty( $instance['widget_title'] ) ? '' : $instance['widget_title'];
$sophia_after_dark_user_name = empty( $instance['user_name'] ) ? '' : $instance['user_name'];
$sophia_after_dark_user_id = empty( $instance['user_id'] ) ? '' : $instance['user_id'];
$sophia_after_dark_user_image = empty( $instance['user_thumb'] ) ? '' : $instance['user_thumb'];
echo $before_widget;
?>
<div class="sad-author-info-wrapper">
<?php
if ( ! empty( $sophia_after_dark_widget_title ) ) {
echo $before_title . esc_html( $sophia_after_dark_widget_title ) . $after_title;
}
?>
<div class="author-bio-wrap">
<div class="author-avatar">
<?php
if ( ! empty( $sophia_after_dark_user_image ) ) {
echo '<img src="'. esc_url( $sophia_after_dark_user_image ) .'" />';
} else {
echo get_avatar( $sophia_after_dark_user_id, '132' );
}
?>
</div>
<h3 class="author-name">
<?php
if ( empty( $sophia_after_dark_user_name ) ) {
echo wp_kses_post( get_the_author_meta( 'nickname', $sophia_after_dark_user_id ) );
} else {
echo esc_html( $sophia_after_dark_user_name );
}
?>
</h3>
<div class="author-description"><?php echo wp_kses_post( wpautop( get_the_author_meta( 'description', $sophia_after_dark_user_id ) ) ); ?></div>
<div class="author-social">
<?php sophia_after_dark_social_media_content(); ?>
</div>
</div>
</div>
<?php
echo $after_widget;
}
echo $before_widget;
?>
<div class="sad-author-info-wrapper">
<?php
if ( ! empty( $sophia_after_dark_widget_title ) ) {
echo $before_title . esc_html( $sophia_after_dark_widget_title ) . $after_title;
}
?>
<div class="author-bio-wrap">
<div class="author-avatar">
<?php
if ( ! empty( $sophia_after_dark_user_image ) ) {
echo '<img src="' . esc_url( $sophia_after_dark_user_image ) . '" />';
} else {
echo get_avatar( $sophia_after_dark_user_id, '132' );
}
?>
</div>
<h3 class="author-name">
<?php
if ( empty( $sophia_after_dark_user_name ) ) {
echo wp_kses_post( get_the_author_meta( 'nickname', $sophia_after_dark_user_id ) );
} else {
echo esc_html( $sophia_after_dark_user_name );
}
?>
</h3>
<div class="author-description"><?php echo wp_kses_post( wpautop( get_the_author_meta( 'description', $sophia_after_dark_user_id ) ) ); ?></div>
<div class="author-social">
<?php sophia_after_dark_social_media_content(); ?>
</div>
</div>
</div>
<?php
echo $after_widget;
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_updated_field_value() defined in sad-widget-fields.php
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_updated_field_value() defined in sad-widget-fields.php
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$widget_fields = $this->widget_fields();
$widget_fields = $this->widget_fields();
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
extract( $widget_field );
extract( $widget_field );
// Use helper function to get updated field values
$instance[$sophia_after_dark_widgets_name] = sophia_after_dark_widgets_updated_field_value( $widget_field, $new_instance[$sophia_after_dark_widgets_name] );
}
// Use helper function to get updated field values
$instance[ $sophia_after_dark_widgets_name ] = sophia_after_dark_widgets_updated_field_value( $widget_field, $new_instance[ $sophia_after_dark_widgets_name ] );
}
return $instance;
}
return $instance;
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_show_widget_field() defined in sad-widget-fields.php
*/
public function form( $instance ) {
$widget_fields = $this->widget_fields();
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_show_widget_field() defined in sad-widget-fields.php
*/
public function form( $instance ) {
$widget_fields = $this->widget_fields();
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
// Make array elements available as variables
extract( $widget_field );
$sophia_after_dark_widgets_field_value = !empty( $instance[$sophia_after_dark_widgets_name] ) ? wp_kses_post( $instance[$sophia_after_dark_widgets_name] ) : '';
sophia_after_dark_widgets_show_widget_field( $this, $widget_field, $sophia_after_dark_widgets_field_value );
}
}
}
// Make array elements available as variables
extract( $widget_field );
$sophia_after_dark_widgets_field_value = ! empty( $instance[ $sophia_after_dark_widgets_name ] ) ? wp_kses_post( $instance[ $sophia_after_dark_widgets_name ] ) : '';
sophia_after_dark_widgets_show_widget_field( $this, $widget_field, $sophia_after_dark_widgets_field_value );
}
}
}

View File

@@ -11,169 +11,169 @@
class sophia_after_dark_Latest_Posts extends WP_widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
$widget_ops = array(
'classname' => 'sophia_after_dark_latest_posts',
'description' => __( 'A widget to display the latest posts with thumbnail.', 'sophia-after-dark' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'sophia_after_dark_latest_posts', __( 'MT: Latest Posts', 'sophia-after-dark' ), $widget_ops );
}
* Register widget with WordPress.
*/
public function __construct() {
$widget_ops = array(
'classname' => 'sophia_after_dark_latest_posts',
'description' => __( 'A widget to display the latest posts with thumbnail.', 'sophia-after-dark' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'sophia_after_dark_latest_posts', __( 'MT: Latest Posts', 'sophia-after-dark' ), $widget_ops );
}
/**
* Helper function that holds widget fields
* Array is used in update and form functions
*/
private function widget_fields() {
$fields = array(
/**
* Helper function that holds widget fields
* Array is used in update and form functions
*/
private function widget_fields() {
'widget_title' => array(
'sophia_after_dark_widgets_name' => 'widget_title',
'sophia_after_dark_widgets_title' => __( 'Widget title', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'text'
),
$fields = array(
'widget_post_order' => array(
'sophia_after_dark_widgets_name' => 'widget_post_order',
'sophia_after_dark_widgets_title' => __( 'Post Order', 'sophia-after-dark' ),
'sophia_after_dark_widgets_default' => 'default',
'sophia_after_dark_widgets_field_type' => 'select',
'sophia_after_dark_widgets_field_options' => array(
'default' => __( 'Default Order', 'sophia-after-dark' ),
'random' => __( 'Random Order', 'sophia-after-dark' ),
)
),
'widget_title' => array(
'sophia_after_dark_widgets_name' => 'widget_title',
'sophia_after_dark_widgets_title' => __( 'Widget title', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'text',
),
'widget_post_count' => array(
'sophia_after_dark_widgets_name' => 'widget_post_count',
'sophia_after_dark_widgets_title' => __( 'Post Count', 'sophia-after-dark' ),
'sophia_after_dark_widgets_default' => '5',
'sophia_after_dark_widgets_field_type' => 'number'
)
'widget_post_order' => array(
'sophia_after_dark_widgets_name' => 'widget_post_order',
'sophia_after_dark_widgets_title' => __( 'Post Order', 'sophia-after-dark' ),
'sophia_after_dark_widgets_default' => 'default',
'sophia_after_dark_widgets_field_type' => 'select',
'sophia_after_dark_widgets_field_options' => array(
'default' => __( 'Default Order', 'sophia-after-dark' ),
'random' => __( 'Random Order', 'sophia-after-dark' ),
),
),
);
return $fields;
}
'widget_post_count' => array(
'sophia_after_dark_widgets_name' => 'widget_post_count',
'sophia_after_dark_widgets_title' => __( 'Post Count', 'sophia-after-dark' ),
'sophia_after_dark_widgets_default' => '5',
'sophia_after_dark_widgets_field_type' => 'number',
),
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
extract( $args );
);
return $fields;
}
if ( empty( $instance ) ) {
return ;
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
extract( $args );
$sophia_after_dark_widget_title = empty( $instance['widget_title'] ) ? '' : $instance['widget_title'];
$sophia_after_dark_post_order = empty( $instance['widget_post_order'] ) ? 'default' : $instance['widget_post_order'];
$sophia_after_dark_post_count = empty( $instance['widget_post_count'] ) ? '5' : $instance['widget_post_count'];
if ( empty( $instance ) ) {
return;
}
echo $before_widget;
?>
<div class="sad-latest-posts-wrapper">
<?php
if ( !empty( $sophia_after_dark_widget_title ) ) {
echo $before_title . esc_html( $sophia_after_dark_widget_title ) . $after_title;
}
?>
<div class="sad-posts-content-wrapper">
<?php
$sophia_after_dark_posts_args = array(
'posts_per_page' => absint( $sophia_after_dark_post_count ),
'ignore_sticky_posts' => 1,
);
if ( 'random' === $sophia_after_dark_post_order ) {
$sophia_after_dark_posts_args['orderby'] = 'rand';
}
$sophia_after_dark_posts_query = new WP_Query( $sophia_after_dark_posts_args );
if ( $sophia_after_dark_posts_query->have_posts() ) {
while ( $sophia_after_dark_posts_query->have_posts() ) {
$sophia_after_dark_posts_query->the_post();
?>
<div class="sad-single-post-wrap">
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<figure><div class="sad-post-thumb"><?php the_post_thumbnail( 'thumbnail' ); ?></div></figure>
</a>
<?php } ?>
<div class="sad-post-content">
<h5 class="sad-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<div class="entry-cat">
<?php
sophia_after_dark_posted_on();
sophia_after_dark_posted_by();
?>
</div>
<?php sophia_after_dark_widget_entry_footer(); ?>
</div>
</div>
<?php
}
}
?>
</div>
</div>
<?php
echo $after_widget;
}
$sophia_after_dark_widget_title = empty( $instance['widget_title'] ) ? '' : $instance['widget_title'];
$sophia_after_dark_post_order = empty( $instance['widget_post_order'] ) ? 'default' : $instance['widget_post_order'];
$sophia_after_dark_post_count = empty( $instance['widget_post_count'] ) ? '5' : $instance['widget_post_count'];
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_updated_field_value() defined in sad-widget-fields.php
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
echo $before_widget;
?>
<div class="sad-latest-posts-wrapper">
<?php
if ( ! empty( $sophia_after_dark_widget_title ) ) {
echo $before_title . esc_html( $sophia_after_dark_widget_title ) . $after_title;
}
?>
<div class="sad-posts-content-wrapper">
<?php
$sophia_after_dark_posts_args = array(
'posts_per_page' => absint( $sophia_after_dark_post_count ),
'ignore_sticky_posts' => 1,
);
if ( 'random' === $sophia_after_dark_post_order ) {
$sophia_after_dark_posts_args['orderby'] = 'rand';
}
$sophia_after_dark_posts_query = new WP_Query( $sophia_after_dark_posts_args );
if ( $sophia_after_dark_posts_query->have_posts() ) {
while ( $sophia_after_dark_posts_query->have_posts() ) {
$sophia_after_dark_posts_query->the_post();
?>
<div class="sad-single-post-wrap">
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<figure><div class="sad-post-thumb"><?php the_post_thumbnail( 'thumbnail' ); ?></div></figure>
</a>
<?php } ?>
<div class="sad-post-content">
<h5 class="sad-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<div class="entry-cat">
<?php
sophia_after_dark_posted_on();
sophia_after_dark_posted_by();
?>
</div>
<?php sophia_after_dark_widget_entry_footer(); ?>
</div>
</div>
<?php
}
}
?>
</div>
</div>
<?php
echo $after_widget;
}
$widget_fields = $this->widget_fields();
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_updated_field_value() defined in sad-widget-fields.php
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
$widget_fields = $this->widget_fields();
extract( $widget_field );
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
// Use helper function to get updated field values
$instance[$sophia_after_dark_widgets_name] = sophia_after_dark_widgets_updated_field_value( $widget_field, $new_instance[$sophia_after_dark_widgets_name] );
}
extract( $widget_field );
return $instance;
}
// Use helper function to get updated field values
$instance[ $sophia_after_dark_widgets_name ] = sophia_after_dark_widgets_updated_field_value( $widget_field, $new_instance[ $sophia_after_dark_widgets_name ] );
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_show_widget_field() defined in sad-widget-fields.php
*/
public function form( $instance ) {
$widget_fields = $this->widget_fields();
return $instance;
}
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_show_widget_field() defined in sad-widget-fields.php
*/
public function form( $instance ) {
$widget_fields = $this->widget_fields();
// Make array elements available as variables
extract( $widget_field );
$sophia_after_dark_widgets_field_value = !empty( $instance[$sophia_after_dark_widgets_name] ) ? wp_kses_post( $instance[$sophia_after_dark_widgets_name] ) : '';
sophia_after_dark_widgets_show_widget_field( $this, $widget_field, $sophia_after_dark_widgets_field_value );
}
}
}
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
// Make array elements available as variables
extract( $widget_field );
$sophia_after_dark_widgets_field_value = ! empty( $instance[ $sophia_after_dark_widgets_name ] ) ? wp_kses_post( $instance[ $sophia_after_dark_widgets_name ] ) : '';
sophia_after_dark_widgets_show_widget_field( $this, $widget_field, $sophia_after_dark_widgets_field_value );
}
}
}

View File

@@ -11,118 +11,118 @@
class sophia_after_dark_Social_Media extends WP_widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
$widget_ops = array(
'classname' => 'sophia_after_dark_social_media',
'description' => __( 'A widget shows the social media icons.', 'sophia-after-dark' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'sophia_after_dark_social_media', __( 'MT: Social Media', 'sophia-after-dark' ), $widget_ops );
}
* Register widget with WordPress.
*/
public function __construct() {
$widget_ops = array(
'classname' => 'sophia_after_dark_social_media',
'description' => __( 'A widget shows the social media icons.', 'sophia-after-dark' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'sophia_after_dark_social_media', __( 'MT: Social Media', 'sophia-after-dark' ), $widget_ops );
}
/**
* Helper function that holds widget fields
* Array is used in update and form functions
*/
private function widget_fields() {
$fields = array(
/**
* Helper function that holds widget fields
* Array is used in update and form functions
*/
private function widget_fields() {
'widget_title' => array(
'sophia_after_dark_widgets_name' => 'widget_title',
'sophia_after_dark_widgets_title' => __( 'Widget title', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'text'
)
);
return $fields;
}
$fields = array(
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
extract( $args );
'widget_title' => array(
'sophia_after_dark_widgets_name' => 'widget_title',
'sophia_after_dark_widgets_title' => __( 'Widget title', 'sophia-after-dark' ),
'sophia_after_dark_widgets_field_type' => 'text',
),
);
return $fields;
}
if ( empty( $instance ) ) {
return ;
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
extract( $args );
$sophia_after_dark_widget_title = empty( $instance['widget_title'] ) ? '' : $instance['widget_title'];
if ( empty( $instance ) ) {
return;
}
$get_social_media_icons = get_theme_mod( 'social_media_icons', '' );
$get_decode_social_media = json_decode( $get_social_media_icons );
$sophia_after_dark_widget_title = empty( $instance['widget_title'] ) ? '' : $instance['widget_title'];
echo $before_widget;
?>
<div class="sad-aside-social-wrapper">
<?php
if ( ! empty( $sophia_after_dark_widget_title ) ) {
echo $before_title . esc_html( $sophia_after_dark_widget_title ) . $after_title;
}
?>
<div class="sad-social-icons-wrapper">
<?php sophia_after_dark_social_media_content(); ?>
</div>
</div>
<?php
echo $after_widget;
}
$get_social_media_icons = get_theme_mod( 'social_media_icons', '' );
$get_decode_social_media = json_decode( $get_social_media_icons );
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_updated_field_value() defined in sad-widget-fields.php
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
echo $before_widget;
?>
<div class="sad-aside-social-wrapper">
<?php
if ( ! empty( $sophia_after_dark_widget_title ) ) {
echo $before_title . esc_html( $sophia_after_dark_widget_title ) . $after_title;
}
?>
<div class="sad-social-icons-wrapper">
<?php sophia_after_dark_social_media_content(); ?>
</div>
</div>
<?php
echo $after_widget;
}
$widget_fields = $this->widget_fields();
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_updated_field_value() defined in sad-widget-fields.php
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
$widget_fields = $this->widget_fields();
extract( $widget_field );
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
// Use helper function to get updated field values
$instance[$sophia_after_dark_widgets_name] = sophia_after_dark_widgets_updated_field_value( $widget_field, $new_instance[$sophia_after_dark_widgets_name] );
}
extract( $widget_field );
return $instance;
}
// Use helper function to get updated field values
$instance[ $sophia_after_dark_widgets_name ] = sophia_after_dark_widgets_updated_field_value( $widget_field, $new_instance[ $sophia_after_dark_widgets_name ] );
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_show_widget_field() defined in sad-widget-fields.php
*/
public function form( $instance ) {
$widget_fields = $this->widget_fields();
return $instance;
}
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*
* @uses sophia_after_dark_widgets_show_widget_field() defined in sad-widget-fields.php
*/
public function form( $instance ) {
$widget_fields = $this->widget_fields();
// Make array elements available as variables
extract( $widget_field );
$sophia_after_dark_widgets_field_value = !empty( $instance[$sophia_after_dark_widgets_name] ) ? wp_kses_post( $instance[$sophia_after_dark_widgets_name] ) : '';
sophia_after_dark_widgets_show_widget_field( $this, $widget_field, $sophia_after_dark_widgets_field_value );
}
}
}
// Loop through fields
foreach ( $widget_fields as $widget_field ) {
// Make array elements available as variables
extract( $widget_field );
$sophia_after_dark_widgets_field_value = ! empty( $instance[ $sophia_after_dark_widgets_name ] ) ? wp_kses_post( $instance[ $sophia_after_dark_widgets_name ] ) : '';
sophia_after_dark_widgets_show_widget_field( $this, $widget_field, $sophia_after_dark_widgets_field_value );
}
}
}

View File

@@ -1,154 +1,155 @@
<?php
/**
* Define custom fields for widgets
*
*
* @package Sophia After Dark
* @since 1.0.0
*/
function sophia_after_dark_widgets_show_widget_field( $instance = '', $widget_field = '', $sophia_after_dark_widget_field_value = '' ) {
extract( $widget_field );
switch ( $sophia_after_dark_widgets_field_type ) {
extract( $widget_field );
/**
* text widget field
*/
case 'text'
?>
<p>
<span class="field-label"><label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?></label></span>
<input class="widefat" id="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>" name="<?php echo esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ); ?>" type="text" value="<?php echo esc_html( $sophia_after_dark_widget_field_value ); ?>" />
switch ( $sophia_after_dark_widgets_field_type ) {
<?php if ( isset( $sophia_after_dark_widgets_description ) ) { ?>
<br />
<em><?php echo wp_kses_post( $sophia_after_dark_widgets_description ); ?></em>
<?php } ?>
</p>
<?php
break;
/**
* text widget field
*/
case 'text'
?>
<p>
<span class="field-label"><label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?></label></span>
<input class="widefat" id="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>" name="<?php echo esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ); ?>" type="text" value="<?php echo esc_html( $sophia_after_dark_widget_field_value ); ?>" />
/**
* Select field
*/
case 'select' :
if ( empty( $sophia_after_dark_widget_field_value ) ) {
$sophia_after_dark_widget_field_value = $sophia_after_dark_widgets_default;
}
<?php if ( isset( $sophia_after_dark_widgets_description ) ) { ?>
<br />
<em><?php echo wp_kses_post( $sophia_after_dark_widgets_description ); ?></em>
<?php } ?>
</p>
<?php
break;
?>
<p>
<label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?>:</label>
<select name="<?php echo esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ); ?>" id="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>" class="widefat">
<?php foreach ( $sophia_after_dark_widgets_field_options as $select_option_name => $select_option_title ) { ?>
<option value="<?php echo esc_attr( $select_option_name ); ?>" id="<?php echo esc_attr( $instance->get_field_id( $select_option_name ) ); ?>" <?php selected( $select_option_name, $sophia_after_dark_widget_field_value ); ?>><?php echo esc_html( $select_option_title ); ?></option>
<?php } ?>
</select>
/**
* Select field
*/
case 'select':
if ( empty( $sophia_after_dark_widget_field_value ) ) {
$sophia_after_dark_widget_field_value = $sophia_after_dark_widgets_default;
}
<?php if ( isset( $sophia_after_dark_widgets_description ) ) { ?>
<br />
<small><?php echo esc_html( $sophia_after_dark_widgets_description ); ?></small>
<?php } ?>
</p>
<?php
break;
?>
<p>
<label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?>:</label>
<select name="<?php echo esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ); ?>" id="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>" class="widefat">
<?php foreach ( $sophia_after_dark_widgets_field_options as $select_option_name => $select_option_title ) { ?>
<option value="<?php echo esc_attr( $select_option_name ); ?>" id="<?php echo esc_attr( $instance->get_field_id( $select_option_name ) ); ?>" <?php selected( $select_option_name, $sophia_after_dark_widget_field_value ); ?>><?php echo esc_html( $select_option_title ); ?></option>
<?php } ?>
</select>
/**
* user dropdown widget field
*/
case 'user_dropdown' :
if ( empty( $sophia_after_dark_widget_field_value ) ) {
$sophia_after_dark_widget_field_value = $sophia_after_dark_widgets_default;
}
$select_field = 'name="'. esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ) .'" id="'. esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ) .'" class="widefat"';
?>
<p>
<label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?>:</label>
<?php
$dropdown_args = wp_parse_args( array(
'show_option_none' => __( '- - Select User - -', 'sophia-after-dark' ),
'selected' => esc_attr( $sophia_after_dark_widget_field_value ),
) );
<?php if ( isset( $sophia_after_dark_widgets_description ) ) { ?>
<br />
<small><?php echo esc_html( $sophia_after_dark_widgets_description ); ?></small>
<?php } ?>
</p>
<?php
break;
$dropdown_args['echo'] = false;
/**
* user dropdown widget field
*/
case 'user_dropdown':
if ( empty( $sophia_after_dark_widget_field_value ) ) {
$sophia_after_dark_widget_field_value = $sophia_after_dark_widgets_default;
}
$select_field = 'name="' . esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ) . '" id="' . esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ) . '" class="widefat"';
?>
<p>
<label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?>:</label>
<?php
$dropdown_args = wp_parse_args(
array(
'show_option_none' => __( '- - Select User - -', 'sophia-after-dark' ),
'selected' => esc_attr( $sophia_after_dark_widget_field_value ),
)
);
$dropdown = wp_dropdown_users( $dropdown_args );
$dropdown = str_replace( '<select', '<select ' . $select_field, $dropdown );
echo $dropdown;
?>
</p>
<?php
break;
/**
* number widget field
*/
case 'number' :
if ( empty( $sophia_after_dark_widget_field_value ) ) {
$sophia_after_dark_widget_field_value = $sophia_after_dark_widgets_default;
}
?>
<p>
<label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?></label>
<input name="<?php echo esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ); ?>" type="number" step="1" min="1" id="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>" value="<?php echo esc_html( $sophia_after_dark_widget_field_value ); ?>" class="small-text" />
$dropdown_args['echo'] = false;
<?php if ( isset( $sophia_after_dark_widgets_description ) ) { ?>
<br />
<em><?php echo wp_kses_post( $sophia_after_dark_widgets_description ); ?></em>
<?php } ?>
</p>
<?php
break;
$dropdown = wp_dropdown_users( $dropdown_args );
$dropdown = str_replace( '<select', '<select ' . $select_field, $dropdown );
echo $dropdown;
?>
</p>
<?php
break;
/**
* upload file field
*/
case 'upload':
$image = $image_class = "";
if ( $sophia_after_dark_widget_field_value ) {
$image = '<img src="'.esc_url( $sophia_after_dark_widget_field_value ).'" style="max-width:100%;"/>';
$image_class = ' hidden';
}
?>
<div class="attachment-media-view">
/**
* number widget field
*/
case 'number':
if ( empty( $sophia_after_dark_widget_field_value ) ) {
$sophia_after_dark_widget_field_value = $sophia_after_dark_widgets_default;
}
?>
<p>
<label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?></label>
<input name="<?php echo esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ); ?>" type="number" step="1" min="1" id="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>" value="<?php echo esc_html( $sophia_after_dark_widget_field_value ); ?>" class="small-text" />
<label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?>:</label><br />
<div class="placeholder<?php echo esc_attr( $image_class ); ?>">
<?php esc_html_e( 'No image selected', 'sophia-after-dark' ); ?>
</div>
<div class="thumbnail thumbnail-image">
<?php echo $image; ?>
</div>
<?php if ( isset( $sophia_after_dark_widgets_description ) ) { ?>
<br />
<em><?php echo wp_kses_post( $sophia_after_dark_widgets_description ); ?></em>
<?php } ?>
</p>
<?php
break;
<div class="actions sad-clearfix">
<button type="button" class="button sad-delete-button align-left"><?php esc_html_e( 'Remove', 'sophia-after-dark' ); ?></button>
<button type="button" class="button sad-upload-button alignright"><?php esc_html_e( 'Select Image', 'sophia-after-dark' ); ?></button>
<input name="<?php echo esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ); ?>" id="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>" class="upload-id" type="hidden" value="<?php echo esc_url( $sophia_after_dark_widget_field_value ) ?>"/>
</div>
/**
* upload file field
*/
case 'upload':
$image = $image_class = '';
if ( $sophia_after_dark_widget_field_value ) {
$image = '<img src="' . esc_url( $sophia_after_dark_widget_field_value ) . '" style="max-width:100%;"/>';
$image_class = ' hidden';
}
?>
<div class="attachment-media-view">
<?php if ( isset( $sophia_after_dark_widgets_description ) ) { ?>
<br />
<small><?php echo wp_kses_post( $sophia_after_dark_widgets_description ); ?></small>
<?php } ?>
<label for="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>"><?php echo esc_html( $sophia_after_dark_widgets_title ); ?>:</label><br />
<div class="placeholder<?php echo esc_attr( $image_class ); ?>">
<?php esc_html_e( 'No image selected', 'sophia-after-dark' ); ?>
</div>
<div class="thumbnail thumbnail-image">
<?php echo $image; ?>
</div>
</div>
<?php
break;
<div class="actions sad-clearfix">
<button type="button" class="button sad-delete-button align-left"><?php esc_html_e( 'Remove', 'sophia-after-dark' ); ?></button>
<button type="button" class="button sad-upload-button alignright"><?php esc_html_e( 'Select Image', 'sophia-after-dark' ); ?></button>
<input name="<?php echo esc_attr( $instance->get_field_name( $sophia_after_dark_widgets_name ) ); ?>" id="<?php echo esc_attr( $instance->get_field_id( $sophia_after_dark_widgets_name ) ); ?>" class="upload-id" type="hidden" value="<?php echo esc_url( $sophia_after_dark_widget_field_value ); ?>"/>
</div>
}
<?php if ( isset( $sophia_after_dark_widgets_description ) ) { ?>
<br />
<small><?php echo wp_kses_post( $sophia_after_dark_widgets_description ); ?></small>
<?php } ?>
</div>
<?php
break;
}
}
function sophia_after_dark_widgets_updated_field_value( $widget_field, $new_field_value ) {
extract( $widget_field );
if ( $sophia_after_dark_widgets_field_type == 'number') {
return absint( $new_field_value );
} elseif ( $sophia_after_dark_widgets_field_type == 'upload' ) {
return esc_url( $new_field_value );
} else {
return sanitize_text_field( $new_field_value );
}
}
extract( $widget_field );
if ( $sophia_after_dark_widgets_field_type == 'number' ) {
return absint( $new_field_value );
} elseif ( $sophia_after_dark_widgets_field_type == 'upload' ) {
return esc_url( $new_field_value );
} else {
return sanitize_text_field( $new_field_value );
}
}

View File

@@ -17,48 +17,55 @@ function sophia_after_dark_widgets_init() {
*
* @since 1.0.0
*/
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'sophia-after-dark' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'sophia-after-dark' ),
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'sophia-after-dark' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'sophia-after-dark' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
)
);
/**
* Register Header Ads Section
*
* @since 1.0.0
*/
register_sidebar( array(
'name' => esc_html__( 'Header Ads Section', 'sophia-after-dark' ),
'id' => 'header-ads-section',
'description' => esc_html__( 'Add MT: Ads Banner widgets here.', 'sophia-after-dark' ),
register_sidebar(
array(
'name' => esc_html__( 'Header Ads Section', 'sophia-after-dark' ),
'id' => 'header-ads-section',
'description' => esc_html__( 'Add MT: Ads Banner widgets here.', 'sophia-after-dark' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
)
);
/**
* Register 4 different footer area
* Register 4 different footer area
*
* @since 1.0.0
*/
register_sidebars( 4 , array(
'name' => esc_html__( 'Footer %d', 'sophia-after-dark' ),
'id' => 'footer-sidebar',
'description' => esc_html__( 'Added widgets are display at Footer Widget Area.', 'sophia-after-dark' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebars(
4,
array(
'name' => esc_html__( 'Footer %d', 'sophia-after-dark' ),
'id' => 'footer-sidebar',
'description' => esc_html__( 'Added widgets are display at Footer Widget Area.', 'sophia-after-dark' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
)
);
// Author Info
register_widget( 'sophia_after_dark_Author_Info' );
@@ -66,7 +73,7 @@ function sophia_after_dark_widgets_init() {
// Latest Posts
register_widget( 'sophia_after_dark_Latest_Posts' );
//Social Media
// Social Media
register_widget( 'sophia_after_dark_Social_Media' );
}
add_action( 'widgets_init', 'sophia_after_dark_widgets_init' );
@@ -80,4 +87,4 @@ add_action( 'widgets_init', 'sophia_after_dark_widgets_init' );
require get_template_directory() . '/inc/widgets/sad-widget-fields.php'; // Widget fields
require get_template_directory() . '/inc/widgets/sad-author-info.php'; // Author Info
require get_template_directory() . '/inc/widgets/sad-latest-posts.php'; // Latest Posts
require get_template_directory() . '/inc/widgets/sad-social-media.php'; // Social Media
require get_template_directory() . '/inc/widgets/sad-social-media.php'; // Social Media