$data ) { if ( isset( $saved_widgets[ $slug ] ) ) { if ( 'disabled' === $saved_widgets[ $slug ] ) { $widgets[ $slug ]['is_activate'] = false; } else { $widgets[ $slug ]['is_activate'] = true; } } else { $widgets[ $slug ]['is_activate'] = ( isset( $data['default'] ) ) ? $data['default'] : false; } } } self::$widget_options = $widgets; } return apply_filters( 'hfe_enabled_widgets', self::$widget_options ); } /** * Updates an option from the admin settings page. * * @param string $key The option key. * @param mixed $value The value to update. * @param bool $network Whether to allow the network admin setting to be overridden on subsites. * @return mixed */ public static function update_admin_settings_option( $key, $value, $network = false ) { // Update the site-wide option since we're in the network admin. if ( $network && is_multisite() ) { update_site_option( $key, $value ); } else { update_option( $key, $value ); } } /** * Returns an option from the database for * the admin settings page. * * @param string $key The option key. * @param mixed $default Option default value if option is not available. * @param boolean $network_override Whether to allow the network admin setting to be overridden on subsites. * @return string Return the option value */ public static function get_admin_settings_option( $key, $default = false, $network_override = false ) { // Get the site-wide option if we're in the network admin. if ( $network_override && is_multisite() ) { $value = get_site_option( $key, $default ); } else { $value = get_option( $key, $default ); } return $value; } /** * Widget Active. * * @param string $slug Module slug. * @return string * @since 0.0.1 */ public static function is_widget_active( $slug = '' ) { $widgets = self::get_widget_options(); $is_activate = false; if ( isset( $widgets[ $slug ] ) ) { $is_activate = $widgets[ $slug ]['is_activate']; } return $is_activate; } /** * Get Rollback versions. * * @since 1.23.0 * @return array * @access public */ public static function get_rollback_versions_options() { $rollback_versions = self::get_rollback_versions(); $rollback_versions_options = []; foreach ( $rollback_versions as $version ) { $version = [ 'label' => $version, 'value' => $version, ]; $rollback_versions_options[] = $version; } return $rollback_versions_options; } /** * Get Rollback versions. * * @since 2.2.1 * @return array * @access public */ public static function get_rollback_versions() { $rollback_versions = get_transient( 'hfe_rollback_versions_' . HFE_VER ); if ( empty( $rollback_versions ) ) { $max_versions = 10; require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $plugin_information = plugins_api( 'plugin_information', [ 'slug' => 'header-footer-elementor', ] ); if ( empty( $plugin_information->versions ) || ! is_array( $plugin_information->versions ) ) { return []; } krsort( $plugin_information->versions ); $rollback_versions = []; foreach ( $plugin_information->versions as $version => $download_link ) { $lowercase_version = strtolower( $version ); $is_valid_rollback_version = ! preg_match( '/(trunk|beta|rc|dev)/i', $lowercase_version ); if ( ! $is_valid_rollback_version ) { continue; } if ( version_compare( $version, HFE_VER, '>=' ) ) { continue; } $rollback_versions[] = $version; } usort( $rollback_versions, function( $prev, $next ) { if ( version_compare( $prev, $next, '==' ) ) { return 0; } if ( version_compare( $prev, $next, '>' ) ) { return -1; } return 1; } ); $rollback_versions = array_slice( $rollback_versions, 0, $max_versions, true ); set_transient( 'hfe_rollback_versions_' . HFE_VER, $rollback_versions, WEEK_IN_SECONDS ); } return $rollback_versions; } /** * Get Unused Widgets. * * @since 2.4.2 * @return array * @access public */ public static function get_used_widget() { /** @var Usage_Module $usage_module */ $usage_module = Usage_Module::instance(); $usage_module->recalc_usage(); $widgets_usage = []; foreach ( $usage_module->get_formatted_usage( 'raw' ) as $data ) { foreach ( $data['elements'] as $element => $count ) { $widgets_usage[ $element ] = isset( $widgets_usage[ $element ] ) ? $widgets_usage[ $element ] + $count : $count; } } $allowed_widgets = [ 'hfe-breadcrumbs-widget', 'hfe-cart', 'copyright', 'navigation-menu', 'page-title', 'post-info-widget', 'retina', 'hfe-search-button', 'site-logo', 'hfe-site-tagline', 'hfe-site-title', 'hfe-infocard', 'hfe-woo-product-grid', 'hfe-basic-posts', 'hfe-counter', ]; // Filter widgets usage to include only allowed widgets $filtered_widgets_usage = array_filter( $widgets_usage, function ( $key ) use ( $allowed_widgets ) { return in_array( $key, $allowed_widgets, true ); }, ARRAY_FILTER_USE_KEY ); return $filtered_widgets_usage; } /** * Get widget help URL * * Retrieve the help URL for a specific widget. * * @since 2.4.3 * @access public * * @param string $widget_name Widget name. * @return string Widget help URL. */ public static function get_widget_help_url( $widget_name = '' ) { if ( empty( $widget_name ) ) { return ''; } if ( ! isset( self::$widget_list ) ) { self::$widget_list = self::get_widget_list(); } // Convert widget name to config key format $widget_key = ''; foreach ( self::$widget_list as $key => $widget_data ) { if ( isset( $widget_data['slug'] ) && $widget_data['slug'] === $widget_name ) { $widget_key = $key; break; } } if ( empty( $widget_key ) || ! isset( self::$widget_list[ $widget_key ]['doc_url'] ) ) { return ''; } $help_url = self::$widget_list[ $widget_key ]['doc_url']; // Ensure we have a valid URL $help_url = empty( $help_url ) ? '' : $help_url; return apply_filters( 'hfe_widget_help_url', $help_url, $widget_name ); } }