= 0) { $opts = Gogs_API_Plugin::get_api_supported(); if (isset($opts[$idx]) && $opts[$idx]["path"] == $apiv[1]) return $opts[$idx]["path"]; } } add_settings_error( "gawpp_messages", "gawpp_message", esc_html( sprintf(__("The api version selected \"%s\" is not supported", GAWPP_TEXT_DOMAIN), join(":", $apiv)) ), "error" ); return false; }); register_setting("gawpp", "gawpp_usr", function(string $user){ if (empty(trim($user))) return false; if (preg_match("/[a-z0-9\\_\\-i\\.]+$/i", $user)) return $user; add_settings_error( "gawpp_messages", "gawpp_message", esc_html( __("The username must be valid alpha or numeric or dash(-_) or dot characters", GAWPP_TEXT_DOMAIN) ), "error" ); }); register_setting("gawpp", "gawpp_credit", function(string $opt){ if (empty(trim($opt))) return "yes"; if (in_array($opt, array("yes", "no"))) return $opt; return "yes"; }); add_settings_section( "gawpp_config", __("Required", GAWPP_TEXT_DOMAIN), function(array $args) { echo sprintf( '

%s

', esc_attr($args["id"]), esc_html__( "Information about your Gogs-site that Gogs API WPPlugin need to know to make queries. It's recommended to fill in these fields first, to ensure you have entered the required fields correctly before filling out the optional fields.", GAWPP_TEXT_DOMAIN ) ); }, "gawpp" ); $field = function(array $args) { $options = get_option("gawpp_" . $args["id"]); echo sprintf( '', esc_attr($args["label_for"]), esc_attr($args["class"]), (isset($args["placeholder"]) && !empty($args["placeholder"]) ? sprintf(' placeholder="%s"', esc_attr($args["placeholder"])) : null ), (isset($args["data"]) && !empty($args["data"]) ? sprintf(' data-custom="%s"', esc_attr($args["data"])) : null ), (($value = Gogs_API_Plugin::get_option($args["label_for"])) != false ? sprintf(' value="%s"', $value) : null ) ); }; add_settings_field( "gawpp_url", __("Gogs URL", GAWPP_TEXT_DOMAIN), $field, "gawpp", "gawpp_config", array( 'label_for' => "url", 'class' => "regular-text code", 'data' => "", 'placeholder' => 'https://git.domain.tld' ), trim(GAWPP_GOGS_LOGO) ); add_settings_field( "gawpp_token", __("Application token", GAWPP_TEXT_DOMAIN), $field, "gawpp", "gawpp_config", array( 'label_for' => "token", 'class' => "regular-text code", 'data' => "", 'placeholder' => 'e.g c7397d798d241d6462ac992680fa6648d83132ab' ) ); add_settings_field( "gawpp_apiv", __("API version", GAWPP_TEXT_DOMAIN), function (array $args) { $selected = Gogs_API_Plugin::get_api_path(); echo sprintf('', $args["label_for"], $args["class"], (function() use ($args, $selected) { $opts = array(); foreach(Gogs_API_Plugin::get_api_supported() as $key => $opt) $opts[] = sprintf('