Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Webhook;
use WP_Ultimo\Models\Webhook;
/**
* WP Multisite WaaS Webhook Edit/Add New Admin Page.
@ -92,17 +92,20 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
wp_register_script('wu-webhook-page', wu_get_asset('webhook-page.js', 'js'), array('jquery', 'wu-sweet-alert'));
wp_localize_script('wu-webhook-page', 'wu_webhook_page', array(
'i18n' => array(
'error_title' => __('Webhook Test', 'wp-ultimo'),
'error_message' => __('An error occurred when sending the test webhook, please try again.', 'wp-ultimo'),
'copied' => __('Copied!', 'wp-ultimo'),
),
));
wp_localize_script(
'wu-webhook-page',
'wu_webhook_page',
array(
'i18n' => array(
'error_title' => __('Webhook Test', 'wp-ultimo'),
'error_message' => __('An error occurred when sending the test webhook, please try again.', 'wp-ultimo'),
'copied' => __('Copied!', 'wp-ultimo'),
),
)
);
wp_enqueue_script('wu-webhook-page');
} // end register_scripts;
}
/**
* Register ajax forms that we use for webhook.
@ -114,11 +117,13 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
/*
* Delete Webhook - Confirmation modal
*/
add_filter('wu_data_json_success_delete_webhook_modal', fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-webhooks', array('deleted' => 1))
));
} // end register_forms;
add_filter(
'wu_data_json_success_delete_webhook_modal',
fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-webhooks', array('deleted' => 1)),
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -130,105 +135,117 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_widgets();
$this->add_fields_widget('domain-url', array(
'title' => __('Webhook URL', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
'webhook_url' => array(
'type' => 'url',
'title' => __('Webhook URL', 'wp-ultimo'),
'desc' => __('The URL where we will send the payload when the event triggers.', 'wp-ultimo'),
'placeholder' => __('https://example.com', 'wp-ultimo'),
'value' => $this->get_object()->get_webhook_url(),
),
'actions' => array(
'type' => 'actions',
'tooltip' => __('The event .', 'wp-ultimo'),
'actions' => array(
'send_test_event' => array(
'title' => __('Send Test Event', 'wp-ultimo'),
'action' => 'wu_send_test_event',
'object_id' => $this->get_object()->get_id(),
'loading_text' => 'Sending Test...',
$this->add_fields_widget(
'domain-url',
array(
'title' => __('Webhook URL', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
'webhook_url' => array(
'type' => 'url',
'title' => __('Webhook URL', 'wp-ultimo'),
'desc' => __('The URL where we will send the payload when the event triggers.', 'wp-ultimo'),
'placeholder' => __('https://example.com', 'wp-ultimo'),
'value' => $this->get_object()->get_webhook_url(),
),
'actions' => array(
'type' => 'actions',
'tooltip' => __('The event .', 'wp-ultimo'),
'actions' => array(
'send_test_event' => array(
'title' => __('Send Test Event', 'wp-ultimo'),
'action' => 'wu_send_test_event',
'object_id' => $this->get_object()->get_id(),
'loading_text' => 'Sending Test...',
),
),
'html_attr' => array(
'data-page' => 'edit',
),
'wrapper_classes' => 'wu-items-left wu-justify-start',
),
'html_attr' => array(
'data-page' => 'edit',
),
'wrapper_classes' => 'wu-items-left wu-justify-start',
),
),
));
)
);
add_meta_box('wp-ultimo-payload', __('Event Payload', 'wp-ultimo'), array($this, 'output_default_widget_payload'), get_current_screen()->id, 'normal');
$this->add_list_table_widget('events', array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
));
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
)
);
$event_list = array();
foreach (wu_get_event_types() as $key => $value) {
$event_list[ $key ] = $value['name'];
}
$event_list[$key] = $value['name'];
} // end foreach;
$this->add_save_widget('save', array(
'fields' => array(
'event' => array(
'type' => 'select',
'title' => __('Event', 'wp-ultimo'),
'desc' => __('The event that triggers this webhook.', 'wp-ultimo'),
'placeholder' => __('Select Event', 'wp-ultimo'),
'options' => $event_list,
'value' => $this->get_object()->get_event(),
$this->add_save_widget(
'save',
array(
'fields' => array(
'event' => array(
'type' => 'select',
'title' => __('Event', 'wp-ultimo'),
'desc' => __('The event that triggers this webhook.', 'wp-ultimo'),
'placeholder' => __('Select Event', 'wp-ultimo'),
'options' => $event_list,
'value' => $this->get_object()->get_event(),
),
),
),
));
)
);
$this->add_fields_widget('active', array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'tooltip' => __('Deactivate will end the event trigger for this webhook.', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this webhook.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
$this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'tooltip' => __('Deactivate will end the event trigger for this webhook.', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this webhook.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
),
),
),
));
)
);
$this->add_fields_widget('options', array(
'title' => __('Options', 'wp-ultimo'),
'fields' => array(
'integration' => array(
'edit' => true,
'title' => __('Integration', 'wp-ultimo'),
'type' => 'text-edit',
'placeholder' => 'manual',
'value' => $this->get_object()->get_integration(),
'display_value' => ucwords((string) $this->get_object()->get_integration()),
'tooltip' => __('Name of the service responsible for creating this webhook. If you are manually creating this webhook, use the value "manual".', 'wp-ultimo'),
$this->add_fields_widget(
'options',
array(
'title' => __('Options', 'wp-ultimo'),
'fields' => array(
'integration' => array(
'edit' => true,
'title' => __('Integration', 'wp-ultimo'),
'type' => 'text-edit',
'placeholder' => 'manual',
'value' => $this->get_object()->get_integration(),
'display_value' => ucwords((string) $this->get_object()->get_integration()),
'tooltip' => __('Name of the service responsible for creating this webhook. If you are manually creating this webhook, use the value "manual".', 'wp-ultimo'),
),
'event_count' => array(
'title' => __('Run Count', 'wp-ultimo'),
'type' => 'text-edit',
'min' => 0,
'placeholder' => 0,
'edit' => true,
'value' => $this->get_object()->get_event_count(),
// translators: %d is the number of times that this webhook was triggered.
'display_value' => sprintf(__('This webhook was triggered %d time(s).', 'wp-ultimo'), $this->get_object()->get_event_count()),
'tooltip' => __('The number of times that this webhook was triggered so far. It includes test runs.', 'wp-ultimo'),
),
),
'event_count' => array(
'title' => __('Run Count', 'wp-ultimo'),
'type' => 'text-edit',
'min' => 0,
'placeholder' => 0,
'edit' => true,
'value' => $this->get_object()->get_event_count(),
// translators: %d is the number of times that this webhook was triggered.
'display_value' => sprintf(__('This webhook was triggered %d time(s).', 'wp-ultimo'), $this->get_object()->get_event_count()),
'tooltip' => __('The number of times that this webhook was triggered so far. It includes test runs.', 'wp-ultimo'),
),
),
));
} // end register_widgets;
)
);
}
/**
* Outputs the markup for the payload widget.
@ -244,13 +261,15 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
$payload = isset($event['payload']) ? json_encode(wu_maybe_lazy_load_payload($event['payload']), JSON_PRETTY_PRINT) : '{}';
wu_get_template('events/widget-payload', array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => $payload,
));
} // end output_default_widget_payload;
wu_get_template(
'events/widget-payload',
array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => $payload,
)
);
}
/**
* Filters the list table to return only relevant events.
@ -268,8 +287,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Returns the title of the page.
@ -280,8 +298,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Webhook', 'wp-ultimo') : __('Add new Webhook', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -292,8 +309,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Webhook', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -304,8 +320,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -326,8 +341,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Webhook', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the object being edit at the moment.
@ -338,26 +352,21 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if (wu_request('id')) {
$query = new \WP_Ultimo\Database\Webhooks\Webhook_Query;
$query = new \WP_Ultimo\Database\Webhooks\Webhook_Query();
$item = $query->get_item_by('id', wu_request('id'));
if (!$item) {
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-webhooks'));
exit;
} // end if;
}
return $item;
}
} // end if;
return new Webhook;
} // end get_object;
return new Webhook();
}
/**
* Webhooks have titles.
*
@ -366,8 +375,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Handles the save of this form.
@ -382,33 +390,25 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
$object->attributes($_POST);
if (is_wp_error($object->save())) {
$errors = implode('<br>', $object->save()->get_error_messages());
WP_Ultimo()->notices->add($errors, 'error', 'network-admin');
return;
} else {
$array_params = array(
'updated' => 1,
);
if ($this->edit === false) {
$array_params['id'] = $object->get_id();
} // end if;
}
$url = add_query_arg($array_params);
wp_redirect($url);
exit;
} // end if;
} // end handle_save;
} // end class Webhook_Edit_Admin_Page;
}
}
}