-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiCLW.php
More file actions
103 lines (93 loc) · 4.1 KB
/
iCLW.php
File metadata and controls
103 lines (93 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/*
Plugin Name: Custom Link Widget
Plugin URI: http://ipankaj.net/custom-link-widget-plugin
Description: This Plugin Helps You To Insert Links As Widget. You Need To Insert Link and Link Name, It Will Convert Them To Hyperlink Automatically. After Installation & Activation, Navigate to Appearence -> Widgets, There Should A Widget Called "Link Widget By Pankaj Biswas", Drag And Add That.
Author: Pankaj Biswas
Author URI: http://ipankaj.net
Version: 1.2.0
*/
class iCLW extends WP_Widget {
function __construct(){
$options = array(
'description' => 'You can add links by entering the URL and LINK NAME, this widget will automatically transform them into hyperlinks.',
'name' => 'Link Widget By Pankaj Biswas'
);
parent::__construct('iCLW','',$options);
}
//Taking Input From User
public function form($instance){
extract($instance);
?>
<p>
<label for="<?php echo $this->get_field_id('title');?>">Title: </label>
<input class="widefat" style="background:#fff;" id="<?php echo $this->get_field_id('title');?>" name="<?php echo $this->get_field_name('title');?>" value="<?php if(isset($title)) echo esc_attr($title);?>"/>
</p>
<p>
<label for="<?php echo $this->get_field_id('hLinks');?>">How Many Links You Want To Display? </label>
<input type="number" min="1" max="20" class="widefat" style="background:#fff;width:40px;text-align:center;" id="<?php echo $this->get_field_id('numB');?>" name="<?php echo $this->get_field_name('numB');?>" value="<?php echo !empty($numB) ? $numB:1;?>"/>
<br><i>Hit Save After Changing The Number. <b>Do Not Decrease The Number of Links</b>, If Does So, It Will Remove Some Links From The End Of The Array Permanently.</i>
</p>
<?php
$externalLinl = 'externalLinl';
for($i=0;$i<$numB;$i++)
{
$count=$i+1;
$target = 'iT'.$count;
$link = 'iLink'.$count;
$name = 'iName'.$count;
?>
<h4>Details for Link <?php echo $count;?></h4>
<!-- New Window Opening Option -->
<p>
<label for="<?php echo $this->get_field_id($target);?>">Open Link In A New Window?</label>
<input type="checkbox" class="checkbox" <?php checked($instance[$target], true) ?> id="<?php echo $this->get_field_id($target);?>" name="<?php echo $this->get_field_name($target);?>" value="1"/>
</p>
<!-- /New Window Opening Option -->
<p>
<label for="<?php echo $this->get_field_id($link);?>">URL: (Please Add http://) </label>
<input class="widefat" style="background:#fff;" id="<?php echo $this->get_field_id($link);?>" name="<?php echo $this->get_field_name($link);?>" value="<?php if(isset($$link)) echo esc_attr($$link);?>"/>
</p>
<p>
<label for="<?php echo $this->get_field_id($name);?>">Link Title: </label>
<input class="widefat" style="background:#fff;" id="<?php echo $this->get_field_id($name);?>" name="<?php echo $this->get_field_name($name);?>" value="<?php if(isset($$name)) echo esc_attr($$name);?>"/>
</p>
<?php
}?>
<p>
<label for="<?php echo $this->get_field_id('allLink');?>">All View Link: </label>
<input class="widefat" style="background:#fff;" id="<?php echo $this->get_field_id('allLink');?>" name="<?php echo $this->get_field_name('allLink');?>" value="<?php if(isset($allLink)) echo esc_attr($allLink);?>"/>
</p>
<?php
}
//Displaying The Data To Widget
public function widget($args,$instance){
extract($args);
extract($instance);
$title = apply_filters('widget_title',$title);
echo $before_widget;
echo $before_title .'<div class="link-list-block block"><h4>'.$title.'</h4>'. $after_title;
echo '<ul>';
for($i=0;$i<$numB;$i++)
{
$count=$i+1;
$target = 'iT'.$count;
$link = 'iLink'.$count;
$name = 'iName'.$count;
if(empty($$name)) return false;
//Determining Whether To Open In New Window Or Not
if($$target == 1) {
$tar = 'target="_blank" ';
}else{
$tar = '';
}
echo '<li><a '.$tar.'href="'.esc_attr($$link).'">'.esc_attr($$name).'</a></li>';
}
echo '</ul><a href="'.$allLink.'" class="view-all">view all <span class="screen-reader-text sr-only">'.$title.'</span> ›</a></div>';
echo $after_widget;
}
}
add_action('widgets_init','register_iCLW');
function register_iCLW(){
register_widget('iCLW');
}