WPDK  1.5.0
WordPress Development Kit
 All Data Structures Files Functions Variables Pages
wpdk-preferences-view.php
Go to the documentation of this file.
1 <?php
13 
21  public $preferences;
22 
30  public $branch;
31 
39  private $branch_property;
40 
51  public function __construct( $preferences, $property )
52  {
53  parent::__construct( 'wpdk_preferences_view-' . $property );
54  $this->preferences = $preferences;
55  if ( !empty( $property ) && isset( $this->preferences->$property ) ) {
56  $this->branch_property = $property;
57  $this->branch = $this->preferences->$property;
58  }
59  }
60 
66  public function draw()
67  {
68  /* Create a nonce key. */
69  $nonce = md5( $this->id );
70  $input_hidden_nonce = new WPDKHTMLTagInput( '', $nonce, $nonce );
71  $input_hidden_nonce->type = WPDKHTMLTagInputType::HIDDEN;
72  $input_hidden_nonce->value = wp_create_nonce( $this->id );
73 
74  $input_hidden_class = new WPDKHTMLTagInput( '', 'wpdk_preferences_class' );
75  $input_hidden_class->type = WPDKHTMLTagInputType::HIDDEN;
76  $input_hidden_class->value = get_class( $this->preferences );
77 
78  $input_hidden_branch = new WPDKHTMLTagInput( '', 'wpdk_preferences_branch' );
79  $input_hidden_branch->type = WPDKHTMLTagInputType::HIDDEN;
80  $input_hidden_branch->value = $this->branch_property;
81 
82  $layout = new WPDKUIControlsLayout( $this->fields( $this->branch ) );
83  $form = new WPDKHTMLTagForm( $input_hidden_nonce->html() . $input_hidden_class->html() . $input_hidden_branch->html() . $layout->html() . $this->buttonsUpdateReset() );
84  $form->name = 'wpdk_preferences_view_form-' . $this->branch_property;
85  $form->id = $form->name;
86  $form->class[] = 'wpdk-form wpdk-preferences-view-' . $this->branch_property;
87  $form->method = 'post';
88  $form->action = '';
89 
90  do_action( 'wpdk_preferences_feedback-' . $this->branch_property );
91 
92  $form->display();
93  }
94 
104  public function fields( $branch )
105  {
106  die( __METHOD__ . ' must be override in your subclass' );
107  }
108 
117  public function buttonsUpdateReset()
118  {
119  $args = array(
120  'name' => 'update-preferences',
121  );
122  $button_update = WPDKUI::button( __( 'Update', WPDK_TEXTDOMAIN ), $args );
123 
124  $confirm = __( "Are you sure to reset this preferences to default values?\n\nThis operation is not reversible!", WPDK_TEXTDOMAIN );
125  $confirm = apply_filters( 'wpdk_preferences_reset_to_default_confirm_message', $confirm );
126 
127  $args = array(
128  'name' => 'reset-to-default-preferences',
129  'classes' => 'button-secondary',
130  'data' => array( 'confirm' => $confirm )
131  );
132  $button_reset = WPDKUI::button( __( 'Reset to default', WPDK_TEXTDOMAIN ), $args );
133 
134  return sprintf( '<p>%s%s</p>', $button_reset, $button_update );
135  }
136 
137 }