-
Notifications
You must be signed in to change notification settings - Fork 15
/
class-answers-simple.php
114 lines (99 loc) · 2 KB
/
class-answers-simple.php
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
<?php
// Exit if accessed directly
defined( 'ABSPATH' ) or die();
/**
* Decision Trees simple answers class
*
* @package Decision-Trees
* @subpackage Main
*/
class CFTP_DT_Answers_Simple {
/**
* Singleton stuff.
*
* @access @static
*
* @return void
*/
static public function init() {
static $instance = false;
if ( ! $instance ) {
$class = get_called_class();
$instance = new $class();
}
return $instance;
}
/**
* Hook into the CFTP_DT answer_providers filter
*
* @filter cftp_dt_answer_providers
*
* @access @static
*
* @return void
*/
static public function filter_answer_providers( $answers ) {
$answers['simple'] = self::init();
return $answers;
}
/**
* @TODO
*
* @access public
*
* @return void
**/
public function __construct() {
// Nothing
}
/**
* @TODO
*
* @access public
*
* @return string
**/
public function get_edit_form( $id, CFTP_DT_Answer $answer ) {
return sprintf( '<input type="text" class="regular-text" name="cftp_dt_edit[%s][simple][text]" placeholder="%s" value="%s" />',
$id,
__( 'Answer link text', 'cftp_dt' ),
esc_attr( $answer->get_answer_value() )
);
}
/**
* @TODO
*
* @access public
*
* @return string
**/
public function get_add_form() {
return sprintf( '<input type="text" class="regular-text" name="cftp_dt_new[simple][text]" placeholder="%s" />',
__( 'Answer link text', 'cftp_dt' )
);
}
/**
* @TODO
*
* @access public
*
* @return string
**/
public function get_answer( CFTP_DT_Answer $answer ) {
return sprintf( '<a class="cftp_dt_answer_link" href="%1$s">%2$s</a>',
get_permalink( $answer->get_post()->ID ),
$answer->get_answer_value()
);
}
/**
* @TODO
*
* @access public
*
* @return string
**/
public function get_edit_answer_url( CFTP_DT_Answer $answer ) {
return get_permalink( $answer->get_post()->post_parent );
}
}
add_filter( 'cftp_dt_answer_providers', 'CFTP_DT_Answers_Simple::filter_answer_providers', 0 );