init commit

This commit is contained in:
2023-07-04 11:21:47 -07:00
commit ce48e96737
105 changed files with 28651 additions and 0 deletions

View File

@ -0,0 +1,168 @@
<?php
/**
* MT: Author Info
*
* Widget show the author information
*
* @package Sophia After Dark
* @since 1.0.0
*/
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 );
}
/**
* 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'
),
'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_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;
}
/**
* 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 ;
}
$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="mt-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><!-- .author-social -->
</div><!-- .author-bio-wrap -->
</div><!-- .mt-author-info-wrapper -->
<?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 mt-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();
// Loop through fields
foreach ( $widget_fields as $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] );
}
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 mt-widget-fields.php
*/
public function form( $instance ) {
$widget_fields = $this->widget_fields();
// 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

@ -0,0 +1,179 @@
<?php
/**
* MT: Latest Posts
*
* Widget show the latest post with thumbnail.
*
* @package Sophia After Dark
* @since 1.0.0
*/
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 );
}
/**
* 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_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_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'
)
);
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 );
if ( empty( $instance ) ) {
return ;
}
$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'];
echo $before_widget;
?>
<div class="mt-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="mt-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="mt-single-post-wrap">
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<figure><div class="mt-post-thumb"><?php the_post_thumbnail( 'thumbnail' ); ?></div></figure>
</a>
<?php } ?>
<div class="mt-post-content">
<h5 class="mt-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><!-- .mt-single-post-wrap -->
<?php
}
}
?>
</div><!-- .mt-posts-content-wrapper -->
</div><!-- .mt-latest-posts-wrapper -->
<?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 mt-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();
// Loop through fields
foreach ( $widget_fields as $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] );
}
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 mt-widget-fields.php
*/
public function form( $instance ) {
$widget_fields = $this->widget_fields();
// 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

@ -0,0 +1,128 @@
<?php
/**
* MT: Social Media
*
* Widget show the social media icons.
*
* @package Sophia After Dark
* @since 1.0.0
*/
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 );
}
/**
* 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'
)
);
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 );
if ( empty( $instance ) ) {
return ;
}
$sophia_after_dark_widget_title = empty( $instance['widget_title'] ) ? '' : $instance['widget_title'];
$get_social_media_icons = get_theme_mod( 'social_media_icons', '' );
$get_decode_social_media = json_decode( $get_social_media_icons );
echo $before_widget;
?>
<div class="mt-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="mt-social-icons-wrapper">
<?php sophia_after_dark_social_media_content(); ?>
</div><!-- .mt-social-icons-wrapper -->
</div><!-- .mt-aside-social-wrapper -->
<?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 mt-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();
// Loop through fields
foreach ( $widget_fields as $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] );
}
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 mt-widget-fields.php
*/
public function form( $instance ) {
$widget_fields = $this->widget_fields();
// 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

@ -0,0 +1,154 @@
<?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 ) {
/**
* 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 ); ?>" />
<?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;
/**
* Select field
*/
case 'select' :
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>
<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>
<?php if ( isset( $sophia_after_dark_widgets_description ) ) { ?>
<br />
<small><?php echo esc_html( $sophia_after_dark_widgets_description ); ?></small>
<?php } ?>
</p>
<?php
break;
/**
* 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_args['echo'] = false;
$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" />
<?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;
/**
* 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">
<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 class="actions mt-clearfix">
<button type="button" class="button mt-delete-button align-left"><?php esc_html_e( 'Remove', 'sophia-after-dark' ); ?></button>
<button type="button" class="button mt-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 );
}
}

View File

@ -0,0 +1,83 @@
<?php
/**
* custom function and work related to widgets.
*
* @package Sophia After Dark
* @since 1.0.0
*/
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function sophia_after_dark_widgets_init() {
/**
* Register default sidebar
*
* @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' ),
'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' ),
'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
*
* @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>',
) );
// Author Info
register_widget( 'sophia_after_dark_Author_Info' );
// Latest Posts
register_widget( 'sophia_after_dark_Latest_Posts' );
//Social Media
register_widget( 'sophia_after_dark_Social_Media' );
}
add_action( 'widgets_init', 'sophia_after_dark_widgets_init' );
/*-----------------------------------------------------------------------------------------------------------------------*/
/**
* Load widget required files
*
* @since 1.0.0
*/
require get_template_directory() . '/inc/widgets/mt-widget-fields.php'; // Widget fields
require get_template_directory() . '/inc/widgets/mt-author-info.php'; // Author Info
require get_template_directory() . '/inc/widgets/mt-latest-posts.php'; // Latest Posts
require get_template_directory() . '/inc/widgets/mt-social-media.php'; // Social Media