class-affiliates-registration-widget.php
3.98 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* class-affiliates-registration-widget.php
*
* Copyright (c) 2010, 2011 "kento" Karim Rahimpur www.itthinx.com
*
* This code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This header and all notices must be kept intact.
*
* @author Karim Rahimpur
* @package affiliates
* @since affiliates 1.1.0
*/
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Affiliate registration form as a widget.
*
* @link http://codex.wordpress.org/Widgets_API#Developing_Widgets
*/
class Affiliates_Registration_Widget extends WP_Widget {
/**
* Creates an affiliate registration widget.
*/
function __construct() {
parent::__construct( false, $name = 'Affiliates Registration' );
}
/**
* Widget output
*
* @see WP_Widget::widget()
*/
function widget( $args, $instance ) {
if ( affiliates_user_is_affiliate() ) {
return;
}
extract( $args );
$title = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : '';
$widget_id = $args['widget_id'];
echo $before_widget;
if ( !empty( $title ) ) {
echo $before_title . $title . $after_title;
}
$ext = '-' . $widget_id;
$options = array(
'is_widget' => true
);
if ( isset( $instance['terms_post_id'] ) ) {
$options['terms_post_id'] = $instance['terms_post_id'];
}
echo Affiliates_Registration::render_form( $options, $widget_id );
echo $after_widget;
}
/**
* Save widget options
*
* @see WP_Widget::update()
*/
function update( $new_instance, $old_instance ) {
$settings = $old_instance;
if ( !empty( $new_instance['title'] ) ) {
$settings['title'] = strip_tags( $new_instance['title'] );
} else {
unset( $settings['title'] );
}
if ( !empty( $new_instance['terms_post_id'] ) ) {
$terms_post_id = $new_instance['terms_post_id'];
if ( $post = get_post( $terms_post_id ) ) {
$settings['terms_post_id'] = $post->ID;
} else if ( $post = Affiliates_Utility::get_post_by_title( $terms_post_id ) ) {
$settings['terms_post_id'] = $post->ID;
} else {
unset( $settings['terms_post_id'] );
}
}
return $settings;
}
/**
* Output admin widget options form
*
* @see WP_Widget::form()
*/
function form( $instance ) {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', AFFILIATES_PLUGIN_DOMAIN ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<?php
// terms_post_id
// post_id
$terms_post_id = isset( $instance['terms_post_id'] ) ? $instance['terms_post_id'] : '';
echo "<p>";
echo '<label class="title" title="' . __( "Terms and conditions", AFFILIATES_PLUGIN_DOMAIN ) . '" for="' .$this->get_field_id( 'terms_post_id' ) . '">' . __( 'Terms Page or Post ID', AFFILIATES_PLUGIN_DOMAIN ) . '</label>';
echo '<input class="widefat" id="' . $this->get_field_id( 'terms_post_id' ) . '" name="' . $this->get_field_name( 'terms_post_id' ) . '" type="text" value="' . esc_attr( $terms_post_id ) . '" />';
echo '<br/>';
echo '<span class="description">' . __( "Write part of the title or the post ID. If left empty, no terms disclaimer will be shown.", AFFILIATES_PLUGIN_DOMAIN ) . '</span>';
if ( !empty( $terms_post_id ) && ( $post_title = get_the_title( $terms_post_id ) ) ) {
echo '<br/>';
echo '<span class="description"> ' . sprintf( __( "Terms page: <em>%s</em>", AFFILIATES_PLUGIN_DOMAIN ) , '<a target="_blank" href="'. esc_url( get_permalink( $terms_post_id ) ) .'">' . $post_title . '</a>' ) . '</span>';
}
echo '</p>';
}
}// class Affiliates_Registration_Widget