Skip to content

Commit

Permalink
Add inline documents
Browse files Browse the repository at this point in the history
  • Loading branch information
takayukister committed Aug 28, 2024
1 parent 5bf9360 commit 26c69b1
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions admin/includes/tag-generator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* The base class for form-tag generators management.
*/
class WPCF7_TagGenerator {

private static $instance;
Expand All @@ -8,6 +11,10 @@ class WPCF7_TagGenerator {

private function __construct() {}


/**
* Returns the singleton instance of this class.
*/
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
Expand All @@ -16,6 +23,10 @@ public static function get_instance() {
return self::$instance;
}


/**
* Adds a form-tag generator instance.
*/
public function add( $id, $title, $callback, $options = '' ) {
$id = trim( $id );

Expand Down Expand Up @@ -52,6 +63,10 @@ public function add( $id, $title, $callback, $options = '' ) {
return true;
}


/**
* Renders form-tag generator calling buttons.
*/
public function print_buttons() {
echo '<span id="tag-generator-list">';

Expand All @@ -75,6 +90,10 @@ public function print_buttons() {
echo '</span>';
}


/**
* Renders form-tag generator dialog panels (hidden until called).
*/
public function print_panels( WPCF7_ContactForm $contact_form ) {
foreach ( (array) $this->panels as $id => $panel ) {
$callback = $panel['callback'];
Expand Down Expand Up @@ -120,14 +139,25 @@ public function print_panels( WPCF7_ContactForm $contact_form ) {
}


/**
* Class helps to implement a form-tag generator content.
*/
class WPCF7_TagGeneratorGenerator {

private $key = '';


/**
* The constructor.
*/
public function __construct( $key ) {
$this->key = $key;
}


/**
* Returns a unique reference ID.
*/
public function ref( $suffix = '' ) {
$ref = sprintf( '%s-%s', $this->key, $suffix );
$ref = strtolower( $ref );
Expand All @@ -137,12 +167,20 @@ public function ref( $suffix = '' ) {
return $ref;
}


/**
* Calls one of the template methods.
*/
public function print( $part, $options = '' ) {
if ( is_callable( array( $this, $part ) ) ) {
call_user_func( array( $this, $part ), $options );
}
}


/**
* Template method for field type field.
*/
private function field_type( $options = '' ) {
$options = wp_parse_args( $options, array(
'with_required' => false,
Expand Down Expand Up @@ -178,6 +216,10 @@ private function field_type( $options = '' ) {
<?php
}


/**
* Template method for field name field.
*/
private function field_name( $options = '' ) {
$options = wp_parse_args( $options, array(
'ask_if' => '',
Expand Down Expand Up @@ -236,6 +278,10 @@ private function field_name( $options = '' ) {
<?php
}


/**
* Template method for ID attribute option field.
*/
private function id_attr( $options = '' ) {
?>
<fieldset>
Expand All @@ -247,6 +293,10 @@ private function id_attr( $options = '' ) {
<?php
}


/**
* Template method for class attribute option field.
*/
private function class_attr( $options = '' ) {
?>
<fieldset>
Expand All @@ -258,6 +308,10 @@ private function class_attr( $options = '' ) {
<?php
}


/**
* Template method for min/max options.
*/
private function min_max( $options = '' ) {
$options = wp_parse_args( $options, array(
'type' => 'number',
Expand Down Expand Up @@ -303,6 +357,10 @@ private function min_max( $options = '' ) {
<?php
}


/**
* Template method for default value field.
*/
private function default_value( $options = '' ) {
$options = wp_parse_args( $options, array(
'type' => 'text',
Expand Down Expand Up @@ -338,6 +396,10 @@ private function default_value( $options = '' ) {
<?php
}


/**
* Template method for selectable values useful for checkboxes or a menu.
*/
private function selectable_values( $options = '' ) {
$options = wp_parse_args( $options, array(
'first_as_label' => false,
Expand Down Expand Up @@ -408,6 +470,10 @@ private function selectable_values( $options = '' ) {
<?php
}


/**
* Template method for insert-box content including the result form-tag.
*/
private function insert_box_content( $options = '' ) {
?>
<div class="flex-container">
Expand All @@ -429,6 +495,10 @@ private function insert_box_content( $options = '' ) {
<?php
}


/**
* Template method for a tip message about mail-tag.
*/
private function mail_tag_tip( $options = '' ) {
$tip = sprintf(
/* translators: %s: mail-tag corresponding to the form-tag */
Expand All @@ -440,4 +510,5 @@ private function mail_tag_tip( $options = '' ) {
<p class="mail-tag-tip"><?php echo $tip; ?></p>
<?php
}

}

0 comments on commit 26c69b1

Please sign in to comment.