default value. */ public static function get_defaults() { return array( // General. 'enable_humans_txt' => 0, 'enable_meta_tags' => 0, 'enable_footer_link' => 0, // humans.txt. 'humans_template' => 'freelancer', 'humans_custom_content' => '', // Freelancer template. 'freelancer_name' => '', 'freelancer_website' => '', 'freelancer_email' => '', 'freelancer_location' => '', 'freelancer_project' => '', 'freelancer_role' => '', 'freelancer_thanks_to' => '', // Agency template. 'agency_name' => '', 'agency_website' => '', 'agency_contact' => '', 'agency_location' => '', 'agency_project' => '', 'agency_design' => '', 'agency_development' => '', 'agency_seo' => '', 'agency_hosting' => '', 'agency_thanks' => '', // Meta tags. 'meta_author' => '', 'meta_designer' => '', 'meta_developer' => '', 'meta_copyright' => '', 'meta_owner' => '', 'meta_publisher' => '', 'meta_manage' => '', 'meta_power' => '', 'meta_acknowledgment' => '', // Footer link. 'footer_link_text' => 'Made by Acknowledgify', 'footer_link_url' => 'https://acknowledgify.com', 'footer_text_color' => '#000000', 'footer_bg_color' => '', // Empty means no background is emitted. 'footer_alignment' => 'inherit', // 'inherit' emits no text-align. 'footer_font_size' => '16px', 'footer_custom_class' => '', 'footer_placement_options' => 'auto_insert', 'footer_style_mode' => 'plugin', ); } /** * Permitted values for the fixed-choice settings. * * Anything outside these sets falls back to the default rather than being * stored. footer_font_size matters most: it is interpolated into an inline * style attribute by Footer_Link, so it must never accept free text. * * @return array Setting key => list of permitted values. */ public static function get_allowed_values() { return array( 'humans_template' => array( 'freelancer', 'agency', 'custom' ), 'footer_placement_options' => array( 'auto_insert', 'shortcode', 'php_snippet' ), 'footer_font_size' => array( '8px', '9px', '10px', '11px', '12px', '14px', '16px', '18px' ), 'footer_style_mode' => array( 'plugin', 'external' ), 'footer_alignment' => array( 'inherit', 'left', 'center', 'right' ), ); } /** * Default for a single setting. * * @param string $key The setting key. * @return mixed The default, or '' when the key is unknown. */ public static function get_default( $key ) { $defaults = self::get_defaults(); return array_key_exists( $key, $defaults ) ? $defaults[ $key ] : ''; } /** * Get a plugin setting from the database. * * @param string $key The setting key. * @param mixed $default The default value if the setting is not found. * Omit to use the registered default for the key. * @return mixed The setting value or default. */ public static function get_setting( $key, $default = null ) { if ( null === $default ) { $default = self::get_default( $key ); } $options = get_option( 'acknowledgify_settings', [] ); if ( ! is_array( $options ) ) { $options = []; } return ( isset( $options[$key] ) && ! empty( $options[$key] ) ) ? $options[$key] : $default; } /** * Normalise a value for inclusion in a plain-text response. * * humans.txt is served as text/plain, so HTML escaping is wrong there -- * there is no HTML context for entities to be decoded in, and "Smith & * Jones" would reach the reader as "Smith & Jones". The appropriate * protections for plain text are the Content-Type header, normalised line * endings and the removal of control characters. Values are already * sanitised on input. * * @param string $value Raw setting value. * @param bool $allow_newlines Whether line breaks may be preserved. * @return string */ public static function plain_text( $value, $allow_newlines = false ) { $value = (string) $value; // Normalise CRLF and lone CR to LF so output is consistent regardless // of where the value was authored. $value = str_replace( array( "\r\n", "\r" ), "\n", $value ); if ( $allow_newlines ) { // Strip control characters except newline and tab. return preg_replace( '/[^\P{C}\n\t]/u', '', $value ); } // Single-line field: fold any line breaks into spaces, then strip all // remaining control characters. $value = str_replace( "\n", ' ', $value ); return trim( preg_replace( '/[^\P{C}\t]/u', '', $value ) ); } /** * Check if a setting exists, then format it with a label. * * @param string $key The setting key (constant). * @param string $label The label to prepend. * @return string The formatted string or an empty string. */ public static function format_setting( $key, $label ) { $value = self::get_setting( $key, '' ); return !empty($value) ? "{$label}: " . self::plain_text($value) . "\n" : ''; } /** * Check if a setting exists, then generate a meta tag with the provided label. * * @param string $key The setting key (constant). * @param string $meta_name The meta name to be used in the meta tag. * @return string The formatted meta tag string or an empty string if the setting is empty. */ public static function generate_meta_tag($key, $meta_name) { $value = self::get_setting( $key, '' ); return !empty($value) ? '' . "\n" : ''; } }