' . __( 'Settings', 'agb-connector' ) . '', ]; return array_merge($addLinks, $links); } /** * All things must done in load * * phpcs:disable Generic.Metrics.NestingLevel.TooHigh * phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong */ public function load() { wp_enqueue_style( 'agb-connector', plugins_url('/assets/css/style.css', __DIR__), [], Plugin::VERSION, 'all' ); wp_enqueue_script( 'agb-connector', plugins_url('/assets/js/settings.js', __DIR__), ['jquery'], Plugin::VERSION, true ); $getRegen = filter_input(INPUT_GET, 'regen', FILTER_SANITIZE_NUMBER_INT); if (null !== $getRegen) { check_admin_referer('agb-connector-settings-page-regen'); $userAuthToken = md5(wp_generate_password(32, true, true)); update_option(Plugin::OPTION_USER_AUTH_TOKEN, $userAuthToken); $this->message = __('New APT-Token generated.', 'agb-connector'); return; } $postTextAllocation = filter_input( INPUT_POST, 'text_allocation', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); if (!$postTextAllocation && ! is_array($postTextAllocation)) { return; } check_admin_referer('agb-connector-settings-page'); $supportedTextTypes = XmlApi::supportedTextTypes(); $textAllocations = []; foreach ($postTextAllocation as $type => $allocations) { if (! \array_key_exists($type, $supportedTextTypes)) { continue; } foreach ($allocations as $allocation) { if (! array_key_exists($allocation['country'], XmlApi::supportedCountries())) { continue; } if (! array_key_exists($allocation['language'], XmlApi::supportedLanguages())) { continue; } if ('create' === $allocation['page_id']) { $postArray = [ 'post_type' => 'page', 'post_title' => $supportedTextTypes[$type] . ' (' . $allocation['language'] . '_' . $allocation['country'] . ')', 'post_content' => '', 'comment_status' => 'closed', 'ping_status' => 'closed', ]; $allocation['page_id'] = \wp_insert_post($postArray); } if ($allocation['page_id'] <= 0 || ! get_post(absint($allocation['page_id']))) { continue; } $textAllocations[$type][] = [ 'country' => $allocation['country'], 'language' => $allocation['language'], 'pageId' => absint($allocation['page_id']), 'wcOrderEmailAttachment' => ! empty($allocation['wc_email']), ]; } } update_option(Plugin::OPTION_TEXT_ALLOCATIONS, $textAllocations); $this->message = __('settings updated.', 'agb-connector'); } /** * The settings page content * * phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong */ public function page() { $textAllocations = get_option(Plugin::OPTION_TEXT_ALLOCATIONS, []); ?>
' . esc_html($this->message) . '