This', 'highlight-and-share' ); } $social_defaults[ $slug ] = array( 'enabled' => $enabled, 'locked' => $locked, 'label' => $label, ); if ( $enabled ) { $network_order[] = $slug; } } // Append remaining text-sharing networks to network_order. foreach ( $networks as $slug => $network ) { if ( empty( $network['allows_text_sharing'] ) ) { continue; } if ( ! in_array( $slug, $network_order, true ) ) { $network_order[] = $slug; } } // Make sure copy is first in the array. if ( in_array( 'copy', $network_order, true ) ) { $network_order = array_merge( array( 'copy' ), array_diff( $network_order, array( 'copy' ) ) ); } $defaults = array( 'enable_headlines' => false, 'auto_generate_ids' => false, 'truncate_anchor_chars' => false, 'enabled_heading_levels' => array( 'h2', 'h3', 'h4' ), 'supported_post_types' => array( 'post' => true ), 'exclusion_selectors' => '', 'social_defaults' => $social_defaults, 'network_order' => $network_order, 'link_icon_always_visible' => false, 'display_mode' => 'rows', /* can be rows (default) or grid */ 'theme' => 'light', /* can be light (default) or dark */ 'headline_placement' => 'before', /* can be before (default) or after */ 'headline_position' => 'inline', /* can be absolute or inline */ ); return $defaults; } /** * Get the headlines options. * * @param bool $force Force a refresh of the options. * * @return array Headlines options. */ public static function get_headlines_options( $force = false ) { if ( false === self::$options_headlines || $force ) { $settings = get_option( 'highlight-and-share-headline-options' ); } else { $settings = self::$options_headlines; } $defaults = self::get_headlines_defaults(); if ( false === $settings || ! is_array( $settings ) ) { update_option( 'highlight-and-share-headline-options', $defaults ); return $defaults; } // Get settings, but replace excluded heading levels over defaults if set. $exluded_heading_levels = isset( $settings['enabled_heading_levels'] ) ? $settings['enabled_heading_levels'] : array(); $settings = array_replace_recursive( $defaults, $settings ); $settings['enabled_heading_levels'] = $exluded_heading_levels; $settings['network_order'] = array_unique( (array) ( $settings['network_order'] ?? array() ) ); // Restore social_defaults from defaults if empty (e.g. corrupted/migrated data). if ( empty( $settings['social_defaults'] ) || ! is_array( $settings['social_defaults'] ) ) { $settings['social_defaults'] = $defaults['social_defaults']; $settings['network_order'] = $defaults['network_order']; } // Sort social_defaults by slug. ksort( $settings['social_defaults'] ); self::$options_headlines = $settings; return $settings; } /** * Get default options. */ public static function get_defaults() { $defaults = array( 'options_version' => 0, 'js_content' => '', 'element_content' => '', 'id_content' => '', 'wrapper_classes' => '', 'twitter' => '', 'show_twitter' => true, 'show_facebook' => true, 'show_linkedin' => false, 'show_ok' => false, 'show_vk' => false, 'enable_emails' => false, 'show_copy' => false, 'show_whats_app' => false, 'show_xing' => false, 'enable_mobile' => true, 'show_reddit' => false, 'show_telegram' => false, 'show_tumblr' => false, 'show_signal' => false, 'show_webshare' => false, 'show_mastodon' => false, 'show_threads' => false, 'show_bluesky' => false, 'enable_webshare_inline_highlight' => false, 'enable_webshare_click_to_share' => false, 'enable_content' => true, 'enable_excerpt' => true, 'enable_hashtags' => true, 'shortlinks' => false, 'icons' => false, 'enable_comments' => false, 'theme' => 'default', 'sharing_prefix' => '', 'sharing_suffix' => '', 'excluded_post_types' => array(), 'whatsapp_api_endpoint' => 'app', // Can also we 'web'. 'whatsapp_can_share_url' => true, 'twitter_label' => _x( 'Share This', 'X social network formerly Twitter', 'highlight-and-share' ), 'twitter_tooltip' => _x( 'Share on X', 'X social network formerly Twitter', 'highlight-and-share' ), 'facebook_label' => __( 'Facebook', 'highlight-and-share' ), 'facebook_tooltip' => __( 'Share on Facebook', 'highlight-and-share' ), 'linkedin_label' => __( 'LinkedIn', 'highlight-and-share' ), 'linkedin_tooltip' => __( 'Share on LinkedIn', 'highlight-and-share' ), 'ok_label' => __( 'OK', 'highlight-and-share' ), 'ok_tooltip' => __( 'Share on OK', 'highlight-and-share' ), 'vk_label' => __( 'VK', 'highlight-and-share' ), 'vk_tooltip' => __( 'Share on VK', 'highlight-and-share' ), 'whatsapp_label' => __( 'WhatsApp', 'highlight-and-share' ), 'whatsapp_tooltip' => __( 'Share on WhatsApp', 'highlight-and-share' ), 'threads_label' => __( 'Threads', 'highlight-and-share' ), 'threads_tooltip' => __( 'Share on Threads', 'highlight-and-share' ), 'bluesky_label' => __( 'BlueSky', 'highlight-and-share' ), 'bluesky_tooltip' => __( 'Share on BlueSky', 'highlight-and-share' ), 'reddit_label' => __( 'Reddit', 'highlight-and-share' ), 'reddit_tooltip' => __( 'Share on Reddit', 'highlight-and-share' ), 'telegram_label' => __( 'Telegram', 'highlight-and-share' ), 'telegram_tooltip' => __( 'Share on Telegram', 'highlight-and-share' ), 'signal_label' => __( 'Signal', 'highlight-and-share' ), 'signal_tooltip' => __( 'Share on Signal', 'highlight-and-share' ), 'xing_label' => __( 'Xing', 'highlight-and-share' ), 'xing_tooltip' => __( 'Share on Xing', 'highlight-and-share' ), 'copy_label' => __( 'Copy', 'highlight-and-share' ), 'copy_tooltip' => __( 'Copy Selection', 'highlight-and-share' ), 'email_label' => __( 'Email', 'highlight-and-share' ), 'email_tooltip' => __( 'Share via email', 'highlight-and-share' ), 'tumblr_label' => __( 'Tumblr', 'highlight-and-share' ), 'tumblr_tooltip' => __( 'Share on Tumblr', 'highlight-and-share' ), 'webshare_label' => __( 'Share', 'highlight-and-share' ), 'webshare_tooltip' => __( 'Share This', 'highlight-and-share' ), 'mastodon_label' => __( 'Mastodon', 'highlight-and-share' ), 'mastodon_tooltip' => __( 'Share on Mastodon', 'highlight-and-share' ), ); $theme_defaults = self::get_theme_defaults(); $block_editor_defaults = self::get_block_editor_defaults(); return array_merge( $defaults, $theme_defaults, $block_editor_defaults ); } /** * Initialize and return plugin options. * * Return an array of plugin options. * * @since 1.0.0 * @access public * * @see init * * @param bool $force Force a refresh of the options. * * @return array Plugin options */ public static function get_plugin_options( $force = false ) { if ( false === self::$options || $force ) { $settings = get_option( 'highlight-and-share', array() ); } else { $settings = self::$options; } // Port old settings to new settings. if ( ! isset( $settings['show_whats_app'] ) ) { $settings['show_whats_app'] = $settings['show_whatsapp'] ?? false; } if ( ! isset( $settings['enable_emails'] ) ) { $settings['enable_emails'] = $settings['show_email'] ?? false; } $defaults = self::get_defaults(); if ( false === $settings || ! is_array( $settings ) ) { update_option( 'highlight-and-share', $defaults ); return $defaults; } $settings = array_replace_recursive( $defaults, $settings ); // Force network_order key to be unique. $settings['network_order'] = array_unique( $settings['network_order'] ); $options_version = HIGHLIGHT_AND_SHARE_OPTIONS_VERSION; if ( $options_version !== $settings['options_version'] ) { /** * Filter to migrate plugin options. * * @param array $settings The plugin options. * @param string $options_version The current options version. * @param string $settings_version The stored or default settings version. * @return array The migrated plugin options. */ $settings = apply_filters( 'has_migrate_plugin_options', $settings, $options_version, $settings['options_version'] ); $settings['options_version'] = sanitize_text_field( $options_version ); update_option( 'highlight-and-share', $settings ); } self::$options = $settings; return $settings; } /** * Initialize and return email options. * * Return an array of email options. * * @since 1.0.0 * @access public * * @see init * * @param bool $force Force a refresh of the options. * * @return array Plugin options */ public static function get_email_options( $force = false ) { if ( false === self::$options_emails || $force ) { $settings = get_option( 'highlight-and-share-email-settings' ); } else { $settings = self::$options_emails; } $defaults = self::get_email_settings_defaults(); if ( false === $settings || ! is_array( $settings ) ) { update_option( 'highlight-and-share-email-settings', $defaults ); return $defaults; } $settings = wp_parse_args( $settings, $defaults ); self::$options_emails = $settings; return $settings; } /** * Get enabled state for a network from main options. * * @param string $network_slug Network slug. * @param array $network_def Network definition from registry. * @return bool Whether network is enabled. */ private static function get_network_enabled_state( $network_slug, $network_def ) { $plugin_options = self::get_plugin_options(); $option_key = $network_def['enabled_option_key'] ?? "show_{$network_slug}"; // Handle special cases. if ( 'email' === $network_slug ) { $option_key = 'enable_emails'; } $enabled = $plugin_options[ $option_key ] ?? false; // Apply filter. $filter_name = 'has_show_' . $network_slug; return (bool) apply_filters( $filter_name, $enabled ); } /** * Return the social network options. * * @since 3.0.0 * @access public * * @see init * * @param bool $force Force a refresh of the options. * * @return array Plugin options */ public static function get_plugin_options_social_networks( $force = false ) { if ( false === self::$options_social_networks || $force ) { $settings = get_option( 'highlight-and-share-social-networks', array() ); } else { $settings = self::$options_social_networks; } $defaults = self::get_social_network_defaults(); if ( false === $settings || ! is_array( $settings ) ) { update_option( 'highlight-and-share-social-networks', $defaults ); } // Merge two multi-dimensional arrays (defaults, and from settings). $settings = array_replace_recursive( $defaults, $settings ); // Ensure labels remain the same as the defaults. foreach ( $defaults as $network_slug => $network_def ) { $settings[ $network_slug ]['label'] = $network_def['label']; } // Loop through networks and set enabled state. foreach ( $settings as $network_slug => &$network_def ) { $network_def['enabled'] = self::get_network_enabled_state( $network_slug, $network_def ); } unset( $network_def ); // Break reference. // Now sort the arrays based on order. array_multisort( array_column( $settings, 'order' ), SORT_ASC, $settings ); self::$options_social_networks = $settings; return $settings; } /** * Return the social network options. * * @since 3.0.0 * @access public * * @see init * * @param bool $force Force a refresh of the options. * * @return array Plugin options */ public static function get_theme_options( $force = false ) { if ( false === self::$options_theme || $force ) { $settings = get_option( 'highlight-and-share-theme-options' ); } else { $settings = self::$options_theme; } $defaults = self::get_theme_defaults(); if ( false === $settings || ! is_array( $settings ) ) { $settings = $defaults; } // Merge two multi-dimensional arrays (defaults, and from settings). $settings = array_replace_recursive( $defaults, $settings ); self::$options_theme = $settings; return $settings; } /** * Return the social network options. * * @since 3.0.0 * @access public * * @see init * * @param bool $force Force a refresh of the options. * * @return array Plugin options */ public static function get_block_editor_options( $force = false ) { if ( false === self::$options_block_editor || $force ) { $settings = get_option( 'highlight-and-share-block-editor-options' ); } else { $settings = self::$options_block_editor; } $defaults = self::get_block_editor_defaults(); if ( false === $settings || ! is_array( $settings ) ) { $settings = $defaults; } // Merge two multi-dimensional arrays (defaults, and from settings). $settings = array_replace_recursive( $defaults, $settings ); self::$options_block_editor = $settings; return $settings; } }