wp_normalize_path( $basename ), 'dir' => wp_normalize_path( $dir ), 'uri' => $uri, ) ); } } // Framework set paths. $get_path = cs_get_path_locate(); if ( ! defined( 'CS_BASENAME' ) ) { define( 'CS_BASENAME', $get_path['basename'] ); } if ( ! defined( 'CS_DIR' ) ) { define( 'CS_DIR', $get_path['dir'] ); } if ( ! defined( 'CS_URI' ) ) { define( 'CS_URI', $get_path['uri'] ); } if ( ! function_exists( 'cs_locate_template' ) ) { /** * Framework locate template and override files. * * @param string $template_name Template path relative to the framework. * * @return string */ function cs_locate_template( $template_name ) { $located = ''; $override = apply_filters( 'cs_framework_override', 'cs-framework-override' ); $dir_plugin = WP_PLUGIN_DIR; $dir_theme = get_template_directory(); $dir_child = get_stylesheet_directory(); $dir_override = '/' . $override . '/' . $template_name; $dir_template = CS_BASENAME . '/' . $template_name; // Child theme override. $child_force_overide = $dir_child . $dir_override; $child_normal_override = $dir_child . $dir_template; // Theme override paths. $theme_force_override = $dir_theme . $dir_override; $theme_normal_override = $dir_theme . $dir_template; // Plugin override. $plugin_force_override = $dir_plugin . $dir_override; $plugin_normal_override = $dir_plugin . $dir_template; if ( file_exists( $child_force_overide ) ) { $located = $child_force_overide; } elseif ( file_exists( $child_normal_override ) ) { $located = $child_normal_override; } elseif ( file_exists( $theme_force_override ) ) { $located = $theme_force_override; } elseif ( file_exists( $theme_normal_override ) ) { $located = $theme_normal_override; } elseif ( file_exists( $plugin_force_override ) ) { $located = $plugin_force_override; } elseif ( file_exists( $plugin_normal_override ) ) { $located = $plugin_normal_override; } $located = apply_filters( 'cs_locate_template', $located, $template_name ); if ( ! empty( $located ) ) { load_template( $located, true ); } return $located; } } if ( ! function_exists( 'cs_get_option' ) ) { /** * Get option. * * @param string $option_name Option name. * @param mixed $default Default value. * * @return mixed */ function cs_get_option( $option_name = '', $default = '' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound -- Public API; renaming would break named-argument callers. $options = apply_filters( 'cs_get_option', get_option( CS_OPTION ), $option_name, $default ); if ( ! empty( $option_name ) && ! empty( $options[ $option_name ] ) ) { return $options[ $option_name ]; } else { return ( ! empty( $default ) ) ? $default : null; } } } if ( ! function_exists( 'cs_set_option' ) ) { /** * Set option. * * @param string $option_name Option name. * @param mixed $new_value New value. */ function cs_set_option( $option_name = '', $new_value = '' ) { $options = apply_filters( 'cs_set_option', get_option( CS_OPTION ), $option_name, $new_value ); if ( ! empty( $option_name ) ) { $options[ $option_name ] = $new_value; update_option( CS_OPTION, $options ); } } } if ( ! function_exists( 'cs_get_all_option' ) ) { /** * Get all option. * * @return mixed */ function cs_get_all_option() { return get_option( CS_OPTION ); } } if ( ! function_exists( 'cs_get_multilang_option' ) ) { /** * Multi language option. * * @param string $option_name Option name. * @param mixed $default Default value. * * @return mixed */ function cs_get_multilang_option( $option_name = '', $default = '' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound -- Public API; renaming would break named-argument callers. $value = cs_get_option( $option_name, $default ); $languages = cs_language_defaults(); $default = $languages['default']; $current = $languages['current']; if ( is_array( $value ) && is_array( $languages ) && isset( $value[ $current ] ) ) { return $value[ $current ]; } elseif ( $default != $current ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual -- Language codes may be null when no multilang plugin is active; keep original loose check. return ''; } return $value; } } if ( ! function_exists( 'cs_get_multilang_value' ) ) { /** * Multi language value. * * @param mixed $value Value. * @param mixed $default Default value. * * @return mixed */ function cs_get_multilang_value( $value = '', $default = '' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound -- Public API; renaming would break named-argument callers. $languages = cs_language_defaults(); $default = $languages['default']; $current = $languages['current']; if ( is_array( $value ) && is_array( $languages ) && isset( $value[ $current ] ) ) { return $value[ $current ]; } elseif ( $default != $current ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual -- Language codes may be null when no multilang plugin is active; keep original loose check. return ''; } return $value; } } if ( ! function_exists( 'cs_get_customize_option' ) ) { /** * Get customize option. * * @param string $option_name Option name. * @param mixed $default Default value. * * @return mixed */ function cs_get_customize_option( $option_name = '', $default = '' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound -- Public API; renaming would break named-argument callers. $options = apply_filters( 'cs_get_customize_option', get_option( CS_CUSTOMIZE ), $option_name, $default ); if ( ! empty( $option_name ) && ! empty( $options[ $option_name ] ) ) { return $options[ $option_name ]; } else { return ( ! empty( $default ) ) ? $default : null; } } } if ( ! function_exists( 'cs_set_customize_option' ) ) { /** * Set customize option. * * @param string $option_name Option name. * @param mixed $new_value New value. */ function cs_set_customize_option( $option_name = '', $new_value = '' ) { $options = apply_filters( 'cs_set_customize_option', get_option( CS_CUSTOMIZE ), $option_name, $new_value ); if ( ! empty( $option_name ) ) { $options[ $option_name ] = $new_value; update_option( CS_CUSTOMIZE, $options ); } } } if ( ! function_exists( 'cs_get_all_customize_option' ) ) { /** * Get all customize option. * * @return mixed */ function cs_get_all_customize_option() { return get_option( CS_CUSTOMIZE ); } } if ( ! function_exists( 'cs_is_wpml_activated' ) ) { /** * WPML plugin is activated. * * @return bool */ function cs_is_wpml_activated() { if ( class_exists( 'SitePress' ) ) { return true; } else { return false; } } } if ( ! function_exists( 'cs_is_qtranslate_activated' ) ) { /** * The qTranslate plugin is activated. * * @return bool */ function cs_is_qtranslate_activated() { if ( function_exists( 'qtrans_getSortedLanguages' ) ) { return true; } else { return false; } } } if ( ! function_exists( 'cs_is_polylang_activated' ) ) { /** * Polylang plugin is activated. * * @return bool */ function cs_is_polylang_activated() { if ( class_exists( 'Polylang' ) ) { return true; } else { return false; } } } if ( ! function_exists( 'cs_language_defaults' ) ) { /** * Get language defaults. * * @return array|false */ function cs_language_defaults() { $multilang = array(); if ( cs_is_wpml_activated() || cs_is_qtranslate_activated() || cs_is_polylang_activated() ) { if ( cs_is_wpml_activated() ) { global $sitepress; $multilang['default'] = $sitepress->get_default_language(); $multilang['current'] = $sitepress->get_current_language(); $multilang['languages'] = $sitepress->get_active_languages(); } elseif ( cs_is_polylang_activated() ) { global $polylang; $current = pll_current_language(); $default = pll_default_language(); $current = ( empty( $current ) ) ? $default : $current; $poly_langs = $polylang->model->get_languages_list(); $languages = array(); foreach ( $poly_langs as $p_lang ) { $languages[ $p_lang->slug ] = $p_lang->slug; } $multilang['default'] = $default; $multilang['current'] = $current; $multilang['languages'] = $languages; } elseif ( cs_is_qtranslate_activated() ) { global $q_config; $multilang['default'] = $q_config['default_language']; $multilang['current'] = $q_config['language']; $multilang['languages'] = array_flip( qtrans_getSortedLanguages() ); } } $multilang = apply_filters( 'cs_language_defaults', $multilang ); return ( ! empty( $multilang ) ) ? $multilang : false; } } if ( ! function_exists( 'cs_get_locale' ) ) { /** * Get locale for load textdomain. * * @return string */ function cs_get_locale() { global $locale, $wp_local_package; if ( isset( $locale ) ) { return apply_filters( 'locale', $locale ); } // This mirrors core get_locale() and intentionally sets the global $locale, as it always has. // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited if ( isset( $wp_local_package ) ) { $locale = $wp_local_package; } if ( defined( 'WPLANG' ) ) { $locale = WPLANG; } if ( is_multisite() ) { if ( defined( 'WP_INSTALLING' ) ) { $ms_locale = get_site_option( 'WPLANG' ); } else { $ms_locale = get_option( 'WPLANG' ); if ( false === $ms_locale ) { $ms_locale = get_site_option( 'WPLANG' ); } } if ( false !== $ms_locale ) { $locale = $ms_locale; } } else { $db_locale = get_option( 'WPLANG' ); if ( false !== $db_locale ) { $locale = $db_locale; } } if ( empty( $locale ) ) { $locale = 'en_US'; } // phpcs:enable WordPress.WP.GlobalVariablesOverride.Prohibited return apply_filters( 'locale', $locale ); } } // Framework load text domain. load_textdomain( 'cs-framework', CS_DIR . '/languages/' . cs_get_locale() . '.mo' );