supportedCountries = $supportedCountries; $this->supportedLanguages = $supportedLanguages; $this->supportedTextTypes = $supportedTextTypes; } /** * Add the menu entry */ public function addMenu() { $hook = add_options_page( __('Terms & Conditions Connector of IT-Recht Kanzlei', 'agb-connector'), 'AGB Connector', 'edit_pages', 'agb_connector_settings', [ $this, 'page', ] ); add_action('load-' . $hook, [$this, 'load']); } /** * Add settings link to plugin actions. * * @param array $links The links. * * @return array */ public function addActionLinks($links) { $addLinks = [ '' . __( '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 = $this->supportedTextTypes; $textAllocations = []; foreach ($postTextAllocation as $type => $allocations) { if (! array_key_exists($type, $supportedTextTypes)) { continue; } foreach ($allocations as $allocation) { if (! array_key_exists($allocation['country'], $this->supportedCountries)) { continue; } if (! array_key_exists($allocation['language'], $this->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']), 'savePdfFile' => $allocation['savePdfFile'], ]; } } 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) . '