Generate ids for form locations
This commit is contained in:
@@ -47,8 +47,17 @@ abstract class Location {
|
|||||||
|
|
||||||
abstract public function activate():void;
|
abstract public function activate():void;
|
||||||
|
|
||||||
|
protected function get_widget_id(): string {
|
||||||
|
return sprintf(
|
||||||
|
'cap-%s',
|
||||||
|
$this->name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function render():void {
|
public function render():void {
|
||||||
Widget::render();
|
Widget::render([
|
||||||
|
'id' => $this->get_widget_id(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process(WP_Error|null $errors = null):void {
|
public function process(WP_Error|null $errors = null):void {
|
||||||
@@ -78,7 +87,12 @@ abstract class Location {
|
|||||||
public function footer():void {
|
public function footer():void {
|
||||||
if (!Settings::is_widget_floating()) return;
|
if (!Settings::is_widget_floating()) return;
|
||||||
$html = ob_get_clean();
|
$html = ob_get_clean();
|
||||||
$html = Widget::set_button_floating($html);
|
$html = Widget::set_button_floating(
|
||||||
|
$html,
|
||||||
|
[
|
||||||
|
'id' => $this->get_widget_id(),
|
||||||
|
]
|
||||||
|
);
|
||||||
echo $html;
|
echo $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ final class Widget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$attributes = [
|
$attributes = [
|
||||||
'data-cap-floating' => "#{$args['id']}",
|
'data-cap-floating' => '#' . $args['id'],
|
||||||
'data-cap-floating-position' => $args['position'],
|
'data-cap-floating-position' => $args['position'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -134,11 +134,25 @@ final class Addon extends GFAddOn {
|
|||||||
public function submit_button(string $button_input, array $form): string {
|
public function submit_button(string $button_input, array $form): string {
|
||||||
if (!Settings::is_connected() || !$this->is_enabled($form)) return $button_input;
|
if (!Settings::is_connected() || !$this->is_enabled($form)) return $button_input;
|
||||||
if ((is_admin() && !defined('DOING_AJAX')) || GFCommon::is_form_editor()) return $button_input;
|
if ((is_admin() && !defined('DOING_AJAX')) || GFCommon::is_form_editor()) return $button_input;
|
||||||
|
|
||||||
|
$id = sprintf(
|
||||||
|
'gform_cap_%d',
|
||||||
|
absint(rgar($form, 'id'))
|
||||||
|
);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
Widget::render();
|
Widget::render([
|
||||||
|
'id' => $id,
|
||||||
|
]);
|
||||||
$button_input = ob_get_clean() . $button_input;
|
$button_input = ob_get_clean() . $button_input;
|
||||||
if (Settings::is_widget_floating()) $button_input = Widget::set_button_floating($button_input);
|
if (Settings::is_widget_floating()) {
|
||||||
|
$button_input = Widget::set_button_floating(
|
||||||
|
$button_input,
|
||||||
|
[
|
||||||
|
'id' => $id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
return $button_input;
|
return $button_input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ final class LoginForm extends Location {
|
|||||||
$content .= ob_get_clean();
|
$content .= ob_get_clean();
|
||||||
|
|
||||||
if (Settings::is_widget_floating()) {
|
if (Settings::is_widget_floating()) {
|
||||||
Widget::add_dynamic_floating_attributes();
|
Widget::add_dynamic_floating_attributes([
|
||||||
|
'id' => $this->get_widget_id(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
|
|||||||
Reference in New Issue
Block a user