Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/meks-sma.../inc
File: class-author-widget.php
<?php
[0] Fix | Delete
/*-----------------------------------------------------------------------------------*/
[1] Fix | Delete
/* Author Widget Class
[2] Fix | Delete
/*-----------------------------------------------------------------------------------*/
[3] Fix | Delete
[4] Fix | Delete
class MKS_Author_Widget extends WP_Widget {
[5] Fix | Delete
[6] Fix | Delete
private $users_split_at = 200; //Do not run get_users() if there are more than 200 users on the website
[7] Fix | Delete
[8] Fix | Delete
public $defaults;
[9] Fix | Delete
[10] Fix | Delete
function __construct() {
[11] Fix | Delete
$widget_ops = array(
[12] Fix | Delete
'classname' => 'mks_author_widget',
[13] Fix | Delete
'description' => __('Use this widget to display author/user profile info', 'meks-smart-author-widget'),
[14] Fix | Delete
'customize_selective_refresh' => true,
[15] Fix | Delete
'show_instance_in_rest' => true,
[16] Fix | Delete
);
[17] Fix | Delete
$control_ops = array( 'id_base' => 'mks_author_widget' );
[18] Fix | Delete
parent::__construct( 'mks_author_widget', __('Meks Smart Author', 'meks-smart-author-widget'), $widget_ops, $control_ops );
[19] Fix | Delete
[20] Fix | Delete
[21] Fix | Delete
add_action( 'wp_enqueue_scripts', array($this,'enqueue_styles'));
[22] Fix | Delete
add_action( 'admin_enqueue_scripts', array($this,'enqueue_styles'));
[23] Fix | Delete
[24] Fix | Delete
//Allow themes or plugins to modify default parameters
[25] Fix | Delete
$defaults = apply_filters('mks_author_widget_modify_defaults',array(
[26] Fix | Delete
'title' => __('About Author', 'meks-smart-author-widget'),
[27] Fix | Delete
'author' => 0,
[28] Fix | Delete
'auto_detect' => 0,
[29] Fix | Delete
'display_name' => 1,
[30] Fix | Delete
'display_avatar' => 1,
[31] Fix | Delete
'display_desc' => 1,
[32] Fix | Delete
'display_all_posts' => 1,
[33] Fix | Delete
'avatar_size' => 64,
[34] Fix | Delete
'name_to_title' => 0,
[35] Fix | Delete
'link_to_name' => 0,
[36] Fix | Delete
'link_to_avatar' => 0,
[37] Fix | Delete
'link_text' => __('View all posts', 'meks-smart-author-widget'),
[38] Fix | Delete
'link_url' => '',
[39] Fix | Delete
'limit_chars' => ''
[40] Fix | Delete
));
[41] Fix | Delete
[42] Fix | Delete
$this->defaults = $defaults;
[43] Fix | Delete
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
[47] Fix | Delete
function enqueue_styles(){
[48] Fix | Delete
wp_register_style( 'meks-author-widget', MKS_AUTHOR_WIDGET_URL.'css/style.css', false, MKS_AUTHOR_WIDGET_VER );
[49] Fix | Delete
wp_enqueue_style( 'meks-author-widget' );
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
[53] Fix | Delete
function widget( $args, $instance ) {
[54] Fix | Delete
[55] Fix | Delete
extract( $args );
[56] Fix | Delete
[57] Fix | Delete
$instance = wp_parse_args( (array) $instance, $this->defaults );
[58] Fix | Delete
[59] Fix | Delete
if ( is_single() && $this->is_co_authors_active() && $instance['auto_detect'] ) {
[60] Fix | Delete
include( $this->meks_get_template('meks-smart-author-widget-co-authors-template.php') );
[61] Fix | Delete
} else {
[62] Fix | Delete
include( $this->meks_get_template('meks-smart-author-widget-template.php') );
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
function update( $new_instance, $old_instance ) {
[68] Fix | Delete
$instance = $old_instance;
[69] Fix | Delete
$instance['title'] = strip_tags( $new_instance['title'] );
[70] Fix | Delete
$instance['author'] = absint( $new_instance['author'] );
[71] Fix | Delete
$instance['auto_detect'] = !empty($new_instance['auto_detect']) ? 1 : 0;
[72] Fix | Delete
$instance['display_name'] = !empty($new_instance['display_name']) ? 1 : 0;
[73] Fix | Delete
$instance['display_avatar'] = !empty($new_instance['display_avatar']) ? 1 : 0;
[74] Fix | Delete
$instance['display_desc'] = !empty($new_instance['display_desc']) ? 1 : 0;
[75] Fix | Delete
$instance['display_all_posts'] = !empty($new_instance['display_all_posts']) ? 1 : 0;
[76] Fix | Delete
$instance['name_to_title'] = !empty($new_instance['name_to_title']) ? 1 : 0;
[77] Fix | Delete
$instance['link_to_name'] = !empty($new_instance['link_to_name']) ? 1 : 0;
[78] Fix | Delete
$instance['link_to_avatar'] = !empty($new_instance['link_to_avatar']) ? 1 : 0;
[79] Fix | Delete
$instance['link_text'] = strip_tags( $new_instance['link_text'] );
[80] Fix | Delete
$instance['link_url'] = !empty( $new_instance['link_url'] ) ? esc_url($new_instance['link_url']) : '';
[81] Fix | Delete
$instance['avatar_size'] = !empty($new_instance['avatar_size']) ? absint($new_instance['avatar_size']) : 64;
[82] Fix | Delete
$instance['limit_chars'] = !empty( $new_instance['limit_chars'] ) ? absint($new_instance['limit_chars']) : '';
[83] Fix | Delete
[84] Fix | Delete
[85] Fix | Delete
return $instance;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
function form( $instance ) {
[89] Fix | Delete
[90] Fix | Delete
$instance = wp_parse_args( (array) $instance, $this->defaults );?>
[91] Fix | Delete
[92] Fix | Delete
<p>
[93] Fix | Delete
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title', 'meks-smart-author-widget'); ?>:</label>
[94] Fix | Delete
<input id="<?php echo $this->get_field_id( 'title' ); ?>" type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" class="widefat" />
[95] Fix | Delete
</p>
[96] Fix | Delete
[97] Fix | Delete
<p>
[98] Fix | Delete
[99] Fix | Delete
<?php if( $this->count_users() <= $this->users_split_at ) : ?>
[100] Fix | Delete
[101] Fix | Delete
<?php $authors = get_users(); ?>
[102] Fix | Delete
<label for="<?php echo $this->get_field_id( 'author' ); ?>"><?php _e('Choose author/user', 'meks-smart-author-widget'); ?>:</label>
[103] Fix | Delete
<select name="<?php echo $this->get_field_name( 'author' ); ?>" id="<?php echo $this->get_field_id( 'author' ); ?>" class="widefat">
[104] Fix | Delete
<?php foreach($authors as $author) : ?>
[105] Fix | Delete
<option value="<?php echo $author->ID; ?>" <?php selected($author->ID, $instance['author']); ?>><?php echo $author->data->user_login; ?></option>
[106] Fix | Delete
<?php endforeach; ?>
[107] Fix | Delete
</select>
[108] Fix | Delete
[109] Fix | Delete
<?php else: ?>
[110] Fix | Delete
[111] Fix | Delete
<label for="<?php echo $this->get_field_id( 'author' ); ?>"><?php _e('Enter author/user ID', 'meks-smart-author-widget'); ?>:</label>
[112] Fix | Delete
<input id="<?php echo $this->get_field_id( 'author' ); ?>" type="text" name="<?php echo $this->get_field_name( 'author' ); ?>" value="<?php echo $instance['author']; ?>" class="small-text" />
[113] Fix | Delete
[114] Fix | Delete
<?php endif; ?>
[115] Fix | Delete
[116] Fix | Delete
</p>
[117] Fix | Delete
[118] Fix | Delete
<p>
[119] Fix | Delete
<input class="checkbox" id="<?php echo $this->get_field_id( 'auto_detect' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'auto_detect' ); ?>" <?php checked(1, $instance['auto_detect']); ?>/>
[120] Fix | Delete
<label for="<?php echo $this->get_field_id( 'auto_detect' ); ?>"><?php _e('Automatically detect author', 'meks-smart-author-widget'); ?></label>
[121] Fix | Delete
<small class="howto"><?php _e('Use this option to automatically detect author if this sidebar is used on single post template or author template', 'meks-smart-author-widget'); ?></small>
[122] Fix | Delete
</p>
[123] Fix | Delete
<h4><?php _e('Display Options', 'meks-smart-author-widget'); ?></h4>
[124] Fix | Delete
<ul>
[125] Fix | Delete
<li>
[126] Fix | Delete
<input class="checkbox" id="<?php echo $this->get_field_id( 'display_avatar' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'display_avatar' ); ?>" <?php checked(1, $instance['display_avatar']); ?>/>
[127] Fix | Delete
<label for="<?php echo $this->get_field_id( 'display_avatar' ); ?>"><?php _e('Display author avatar', 'meks-smart-author-widget'); ?></label>
[128] Fix | Delete
</li>
[129] Fix | Delete
<li class="meks-avatar-size-field">
[130] Fix | Delete
<label for="<?php echo $this->get_field_id( 'avatar_size' ); ?>"><?php _e('Avatar size:', 'meks-smart-author-widget'); ?></label>
[131] Fix | Delete
<input class="widefat" id="<?php echo $this->get_field_id( 'avatar_size' ); ?>" type="text" name="<?php echo $this->get_field_name( 'avatar_size' ); ?>" value="<?php echo $instance['avatar_size']; ?>" class="small-text"/>
[132] Fix | Delete
<small class="howto"><?php _e('Avatar size in pixels', 'meks-smart-author-widget'); ?></small>
[133] Fix | Delete
</li>
[134] Fix | Delete
</ul>
[135] Fix | Delete
[136] Fix | Delete
<ul>
[137] Fix | Delete
<li>
[138] Fix | Delete
<input class="checkbox" id="<?php echo $this->get_field_id( 'display_name' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'display_name' ); ?>" <?php checked(1, $instance['display_name']); ?>/>
[139] Fix | Delete
<label for="<?php echo $this->get_field_id( 'display_name' ); ?>"><?php _e('Display author name', 'meks-smart-author-widget'); ?></label>
[140] Fix | Delete
</li>
[141] Fix | Delete
<li>
[142] Fix | Delete
<input class="checkbox" id="<?php echo $this->get_field_id( 'name_to_title' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'name_to_title' ); ?>" <?php checked(1, $instance['name_to_title']); ?>/>
[143] Fix | Delete
<label for="<?php echo $this->get_field_id( 'name_to_title' ); ?>"><?php _e('Overwrite widget title with author name', 'meks-smart-author-widget'); ?></label>
[144] Fix | Delete
</li>
[145] Fix | Delete
</ul>
[146] Fix | Delete
[147] Fix | Delete
<ul>
[148] Fix | Delete
<li>
[149] Fix | Delete
<input class="checkbox" id="<?php echo $this->get_field_id( 'display_desc' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'display_desc' ); ?>" <?php checked(1, $instance['display_desc']); ?>/>
[150] Fix | Delete
<label for="<?php echo $this->get_field_id( 'display_desc' ); ?>"><?php _e('Display author description', 'meks-smart-author-widget'); ?></label>
[151] Fix | Delete
</li>
[152] Fix | Delete
<li>
[153] Fix | Delete
<label for="<?php echo $this->get_field_id( 'limit_chars' ); ?>"><?php _e('Limit description:', 'meks-smart-author-widget'); ?></label>
[154] Fix | Delete
<input id="<?php echo $this->get_field_id( 'limit_chars' ); ?>" type="number" name="<?php echo $this->get_field_name( 'limit_chars' ); ?>" value="<?php echo $instance['limit_chars']; ?>" class="widefat" />
[155] Fix | Delete
<small class="howto"><?php _e('Specify number of characters to limit author description length', 'meks-smart-author-widget'); ?></small>
[156] Fix | Delete
</li>
[157] Fix | Delete
</ul>
[158] Fix | Delete
[159] Fix | Delete
<ul>
[160] Fix | Delete
<li>
[161] Fix | Delete
<input class="checkbox" id="<?php echo $this->get_field_id( 'link_to_name' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'link_to_name' ); ?>" <?php checked(1, $instance['link_to_name']); ?>/>
[162] Fix | Delete
<label for="<?php echo $this->get_field_id( 'link_to_name' ); ?>"><?php _e('Link author name', 'meks-smart-author-widget'); ?></label>
[163] Fix | Delete
</li>
[164] Fix | Delete
<li>
[165] Fix | Delete
<input class="checkbox" id="<?php echo $this->get_field_id( 'link_to_avatar' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'link_to_avatar' ); ?>" <?php checked(1, $instance['link_to_avatar']); ?>/>
[166] Fix | Delete
<label for="<?php echo $this->get_field_id( 'link_to_avatar' ); ?>"><?php _e('Link author avatar', 'meks-smart-author-widget'); ?></label>
[167] Fix | Delete
</li>
[168] Fix | Delete
<li>
[169] Fix | Delete
<input class="checkbox" id="<?php echo $this->get_field_id( 'display_all_posts' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'display_all_posts' ); ?>" <?php checked(1, $instance['display_all_posts']); ?>/>
[170] Fix | Delete
<label for="<?php echo $this->get_field_id( 'display_all_posts' ); ?>"><?php _e('Display author "all posts" archive link', 'meks-smart-author-widget'); ?></label>
[171] Fix | Delete
</li>
[172] Fix | Delete
<li>
[173] Fix | Delete
<label for="<?php echo $this->get_field_id( 'link_text' ); ?>"><?php _e('Link text:', 'meks-smart-author-widget'); ?></label>
[174] Fix | Delete
<input id="<?php echo $this->get_field_id( 'link_text' ); ?>" type="text" name="<?php echo $this->get_field_name( 'link_text' ); ?>" value="<?php echo $instance['link_text']; ?>" class="widefat"/>
[175] Fix | Delete
<small class="howto"><?php _e('Specify text for "all posts" link if you want to show separate link', 'meks-smart-author-widget'); ?></small>
[176] Fix | Delete
</li>
[177] Fix | Delete
<li>
[178] Fix | Delete
<label for="<?php echo $this->get_field_id( 'link_url' ); ?>"><?php _e('Override author link URL:', 'meks-smart-author-widget'); ?></label>
[179] Fix | Delete
<input id="<?php echo $this->get_field_id( 'link_url' ); ?>" type="text" name="<?php echo $this->get_field_name( 'link_url' ); ?>" value="<?php echo $instance['link_url']; ?>" class="widefat"/>
[180] Fix | Delete
<small class="howto"><?php _e('Specify custom URL if you want to override default author archive link', 'meks-smart-author-widget'); ?></small>
[181] Fix | Delete
</li>
[182] Fix | Delete
</ul>
[183] Fix | Delete
[184] Fix | Delete
<?php do_action('mks_author_widget_add_opts',$this,$instance);?>
[185] Fix | Delete
[186] Fix | Delete
<?php
[187] Fix | Delete
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/* Check total number of users on the website */
[191] Fix | Delete
function count_users(){
[192] Fix | Delete
$user_count = count_users();
[193] Fix | Delete
if(isset($user_count['total_users']) && !empty($user_count['total_users'])){
[194] Fix | Delete
return $user_count['total_users'];
[195] Fix | Delete
}
[196] Fix | Delete
return 0;
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
private function meks_get_template($template)
[200] Fix | Delete
{
[201] Fix | Delete
$template_slug = rtrim($template, '.php');
[202] Fix | Delete
$template = $template_slug . '.php';
[203] Fix | Delete
[204] Fix | Delete
if ($theme_file = locate_template(array('/sections/widgets/'.$template)) ) :
[205] Fix | Delete
$file = $theme_file;
[206] Fix | Delete
else :
[207] Fix | Delete
$file = $template;
[208] Fix | Delete
endif;
[209] Fix | Delete
[210] Fix | Delete
return $file;
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Support for Co-Authors Plus Plugin
[215] Fix | Delete
* Check if plugin is active
[216] Fix | Delete
*/
[217] Fix | Delete
public function is_co_authors_active() {
[218] Fix | Delete
[219] Fix | Delete
if ( in_array( 'co-authors-plus/co-authors-plus.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
[220] Fix | Delete
return true;
[221] Fix | Delete
}
[222] Fix | Delete
return false;
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
[226] Fix | Delete
/**
[227] Fix | Delete
* Limit character description
[228] Fix | Delete
*
[229] Fix | Delete
* @param string $string Content to trim
[230] Fix | Delete
* @param int $limit Number of characters to limit
[231] Fix | Delete
* @param string $more Chars to append after trimmed string
[232] Fix | Delete
* @return string Trimmed part of the string
[233] Fix | Delete
*/
[234] Fix | Delete
public function trim_chars( $string, $limit, $more = '...' ) {
[235] Fix | Delete
[236] Fix | Delete
if ( !empty( $limit ) ) {
[237] Fix | Delete
[238] Fix | Delete
$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $string ), ' ' );
[239] Fix | Delete
preg_match_all( '/./u', $text, $chars );
[240] Fix | Delete
$chars = $chars[0];
[241] Fix | Delete
$count = count( $chars );
[242] Fix | Delete
[243] Fix | Delete
if ( $count > $limit ) {
[244] Fix | Delete
[245] Fix | Delete
$chars = array_slice( $chars, 0, $limit );
[246] Fix | Delete
[247] Fix | Delete
for ( $i = ( $limit -1 ); $i >= 0; $i-- ) {
[248] Fix | Delete
if ( in_array( $chars[$i], array( '.', ' ', '-', '?', '!' ) ) ) {
[249] Fix | Delete
break;
[250] Fix | Delete
}
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
$chars = array_slice( $chars, 0, $i );
[254] Fix | Delete
$string = implode( '', $chars );
[255] Fix | Delete
$string = rtrim( $string, ".,-?!" );
[256] Fix | Delete
$string.= $more;
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
return $string;
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
?>
[267] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function