1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* @file class-gravityview-field-post-content.php |
4
|
|
|
* @package GravityView |
5
|
|
|
* @subpackage includes\fields |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class GravityView_Field_Post_Content extends GravityView_Field { |
9
|
|
|
|
10
|
|
|
var $name = 'post_content'; |
|
|
|
|
11
|
|
|
|
12
|
|
|
var $search_operators = array( 'is', 'isnot', 'contains', 'starts_with', 'ends_with' ); |
|
|
|
|
13
|
|
|
|
14
|
|
|
var $_gf_field_class_name = 'GF_Field_Post_Content'; |
|
|
|
|
15
|
|
|
|
16
|
|
|
var $group = 'post'; |
|
|
|
|
17
|
|
|
|
18
|
|
|
public function __construct() { |
19
|
|
|
$this->label = esc_html__( 'Post Content', 'gravityview' ); |
20
|
|
|
parent::__construct(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
|
|
|
24
|
|
|
|
25
|
|
|
unset( $field_options['show_as_link'] ); |
26
|
|
|
|
27
|
|
|
if( 'edit' === $context ) { |
|
|
|
|
28
|
|
|
return $field_options; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$this->add_field_support('dynamic_data', $field_options ); |
|
|
|
|
32
|
|
|
|
33
|
|
|
return $field_options; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Returns the field inner markup. |
38
|
|
|
* |
39
|
|
|
* @param array $form The Form Object currently being processed. |
40
|
|
|
* @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission. |
41
|
|
|
* @param null|array $entry Null or the Entry Object currently being edited. |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function get_field_input( $form, $value = '', $entry = null, GF_Field_Post_Content $field ) { |
|
|
|
|
46
|
|
|
|
47
|
|
|
$id = (int) $field->id; |
48
|
|
|
$input_name = "input_{$id}"; |
49
|
|
|
$class = esc_attr( $field->size ); |
50
|
|
|
$tabindex = $field->get_tabindex(); |
51
|
|
|
|
52
|
|
|
$editor_settings = array( |
53
|
|
|
'editor_class' => "textarea {$class}", |
54
|
|
|
'textarea_name' => $input_name, |
55
|
|
|
'textarea_rows' => 15, |
56
|
|
|
'tabindex' => $tabindex, |
57
|
|
|
'media_buttons' => false, |
58
|
|
|
'quicktags' => false, |
59
|
|
|
'logic_event' => $field->get_conditional_logic_event( 'keyup' ), |
60
|
|
|
'placeholder' => $field->get_field_placeholder_attribute(), |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @filter `gravityview/edit_entry/post_content/wp_editor_settings` Modify the settings passed to the Post Content wp_editor() |
65
|
|
|
* @see wp_editor() For the options available |
66
|
|
|
* @since 1.7 |
67
|
|
|
* @param array $editor_settings Array of settings to be passed to wp_editor(). Note: there are also two additional values in the array: `logic_event` and `placehodler`, added to the textarea HTML by GravityView. |
68
|
|
|
*/ |
69
|
|
|
$editor_settings = apply_filters( 'gravityview/edit_entry/post_content/wp_editor_settings', $editor_settings ); |
70
|
|
|
|
71
|
|
|
ob_start(); |
72
|
|
|
wp_editor( $value, $input_name, $editor_settings ); |
73
|
|
|
$editor = ob_get_clean(); |
74
|
|
|
|
75
|
|
|
$logic_event = rgar( $editor_settings, 'logic_event' ); |
76
|
|
|
$placeholder = rgar( $editor_settings, 'placeholder' ); |
77
|
|
|
|
78
|
|
|
/** @internal Instead of using `add_filter('the_editor')` and doing the same thing, it's cleaner here. */ |
79
|
|
|
$editor = str_replace( '<textarea ', "<textarea {$logic_event} {$placeholder}", $editor ); |
80
|
|
|
|
81
|
|
|
return sprintf( "<div class='ginput_container ginput_container_post_content'>%s</div>", trim( $editor ) ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
new GravityView_Field_Post_Content; |
87
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.