Abency Connector
';
if (! empty($_GET['abency_notice'])) {
echo ''
. esc_html(sanitize_text_field(wp_unslash($_GET['abency_notice'])))
. '
';
}
if (Abency_Settings::is_paired()) {
$this->render_pending();
} else {
$this->render_pairing_form();
}
echo '';
}
private function render_pairing_form() {
$action = admin_url('admin-post.php');
echo '' . esc_html__('Pair this WordPress site with Abency. Generate a code in Abency (Brand → Integrations → WordPress → Pair plugin) and paste it here.', 'abency-connector') . '
';
echo '';
}
private function render_pending() {
$brand = (int) Abency_Settings::get(Abency_Settings::OPT_BRAND_ID);
/* translators: %d: Abency brand identifier. */
echo '' . esc_html(sprintf(__('Paired with Abency (brand #%d).', 'abency-connector'), $brand)) . ' ';
$unpair = wp_nonce_url(admin_url('admin-post.php?action=abency_unpair'), 'abency_unpair');
echo '' . esc_html__('Unpair', 'abency-connector') . '
';
$pending = Abency_Proposals::pending();
echo '' . esc_html__('Changes pending approval', 'abency-connector') . '
';
if (empty($pending)) {
echo '' . esc_html__('No pending changes.', 'abency-connector') . '
';
return;
}
echo ''
. '| ' . esc_html__('Content', 'abency-connector') . ' | '
. '' . esc_html__('Changes', 'abency-connector') . ' | '
. '' . esc_html__('Received', 'abency-connector') . ' | '
. '' . esc_html__('Actions', 'abency-connector') . ' | '
. '
';
foreach ($pending as $p) {
$post_id = (int) $p['wp_post_id'];
$title = get_the_title($post_id);
$fields = is_array($p['fields']) ? array_keys($p['fields']) : array();
$preview = add_query_arg(array(
'abency_preview' => $p['id'],
'_wpnonce' => wp_create_nonce('abency_preview_' . $p['id']),
), get_permalink($post_id));
$approve = wp_nonce_url(admin_url('admin-post.php?action=abency_approve&id=' . $p['id']), 'abency_approve_' . $p['id']);
$reject = wp_nonce_url(admin_url('admin-post.php?action=abency_reject&id=' . $p['id']), 'abency_reject_' . $p['id']);
echo '';
/* translators: %d: WordPress post ID. */
echo '| ' . esc_html($title ?: sprintf(__('(#%d)', 'abency-connector'), $post_id)) . ' | ';
echo '' . esc_html(implode(', ', $fields)) . ' | ';
echo '' . esc_html($p['created_at']) . ' | ';
echo ''
. '' . esc_html__('Preview', 'abency-connector') . ' '
. '' . esc_html__('Approve', 'abency-connector') . ' '
. '' . esc_html__('Reject', 'abency-connector') . ''
. ' | ';
echo '
';
}
echo '
';
}
// ── Handlers ────────────────────────────────────────────────────────────
public function handle_pair() {
$this->guard('abency_pair');
$base = isset($_POST['abency_base']) ? esc_url_raw(wp_unslash($_POST['abency_base'])) : '';
$code = isset($_POST['abency_code']) ? sanitize_text_field(wp_unslash($_POST['abency_code'])) : '';
$result = Abency_Pairing::pair($base, $code);
if (! is_wp_error($result)) {
// Content created by Abency is attributed to whoever pairs the plugin.
Abency_Settings::set(Abency_Settings::OPT_AUTHOR_ID, get_current_user_id());
}
$this->redirect_with_notice(is_wp_error($result) ? $result->get_error_message() : __('Paired successfully.', 'abency-connector'));
}
public function handle_unpair() {
$this->guard('abency_unpair');
Abency_Settings::clear_pairing();
$this->redirect_with_notice(__('Unpaired.', 'abency-connector'));
}
public function handle_approve() {
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$this->guard('abency_approve_' . $id);
$result = Abency_Proposals::approve($id);
$this->redirect_with_notice(is_wp_error($result) ? $result->get_error_message() : __('Change approved and published.', 'abency-connector'));
}
public function handle_reject() {
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$this->guard('abency_reject_' . $id);
$result = Abency_Proposals::reject($id);
$this->redirect_with_notice(is_wp_error($result) ? $result->get_error_message() : __('Change rejected.', 'abency-connector'));
}
private function guard($nonce_action) {
if (! current_user_can(self::CAP)) {
wp_die(esc_html__('You do not have permission to perform this action.', 'abency-connector'));
}
$nonce = isset($_REQUEST['_wpnonce']) ? sanitize_text_field(wp_unslash($_REQUEST['_wpnonce'])) : '';
if (! wp_verify_nonce($nonce, $nonce_action)) {
wp_die(esc_html__('Invalid nonce.', 'abency-connector'));
}
}
private function redirect_with_notice($message) {
$url = add_query_arg(array(
'page' => self::SLUG,
'abency_notice' => rawurlencode($message),
), admin_url('admin.php'));
wp_safe_redirect($url);
exit;
}
}