File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/Settings.php.tar
www/vhosts/uyarreklam.com.tr/httpdocs/wp-content/plugins/woocommerce/src/Internal/Admin/Settings.php0000644 00000031114 15154472726 0030653 0 ustar 00 var <?php
/**
* WooCommerce Settings.
*/
namespace Automattic\WooCommerce\Internal\Admin;
use Automattic\WooCommerce\Admin\API\Plugins;
use Automattic\WooCommerce\Admin\PageController;
use Automattic\WooCommerce\Admin\API\Reports\Orders\DataStore as OrdersDataStore;
use Automattic\WooCommerce\Admin\PluginsHelper;
use Automattic\WooCommerce\Internal\Admin\WCPayPromotion\Init as WCPayPromotionInit;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
use WC_Marketplace_Suggestions;
/**
* Contains logic in regards to WooCommerce Admin Settings.
*/
class Settings {
/**
* Class instance.
*
* @var Settings instance
*/
protected static $instance = null;
/**
* Get class instance.
*/
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Hook into WooCommerce.
*/
public function __construct() {
// Old settings injection.
add_filter( 'woocommerce_components_settings', array( $this, 'add_component_settings' ) );
// New settings injection.
add_filter( 'woocommerce_admin_shared_settings', array( $this, 'add_component_settings' ) );
add_filter( 'woocommerce_settings_groups', array( $this, 'add_settings_group' ) );
add_filter( 'woocommerce_settings-wc_admin', array( $this, 'add_settings' ) );
}
/**
* Format order statuses by removing a leading 'wc-' if present.
*
* @param array $statuses Order statuses.
* @return array formatted statuses.
*/
public static function get_order_statuses( $statuses ) {
$formatted_statuses = array();
foreach ( $statuses as $key => $value ) {
$formatted_key = preg_replace( '/^wc-/', '', $key );
$formatted_statuses[ $formatted_key ] = $value;
}
return $formatted_statuses;
}
/**
* Get all order statuses present in analytics tables that aren't registered.
*
* @return array Unregistered order statuses.
*/
private function get_unregistered_order_statuses() {
$registered_statuses = wc_get_order_statuses();
$all_synced_statuses = OrdersDataStore::get_all_statuses();
$unregistered_statuses = array_diff( $all_synced_statuses, array_keys( $registered_statuses ) );
$formatted_status_keys = self::get_order_statuses( array_fill_keys( $unregistered_statuses, '' ) );
$formatted_statuses = array_keys( $formatted_status_keys );
return array_combine( $formatted_statuses, $formatted_statuses );
}
/**
* Return an object defining the currecy options for the site's current currency
*
* @return array Settings for the current currency {
* Array of settings.
*
* @type string $code Currency code.
* @type string $precision Number of decimals.
* @type string $symbol Symbol for currency.
* }
*/
public static function get_currency_settings() {
$code = get_woocommerce_currency();
//phpcs:ignore
return apply_filters(
'wc_currency_settings',
array(
'code' => $code,
'precision' => wc_get_price_decimals(),
'symbol' => html_entity_decode( get_woocommerce_currency_symbol( $code ) ),
'symbolPosition' => get_option( 'woocommerce_currency_pos' ),
'decimalSeparator' => wc_get_price_decimal_separator(),
'thousandSeparator' => wc_get_price_thousand_separator(),
'priceFormat' => html_entity_decode( get_woocommerce_price_format() ),
)
);
}
/**
* Hooks extra necessary data into the component settings array already set in WooCommerce core.
*
* @param array $settings Array of component settings.
* @return array Array of component settings.
*/
public function add_component_settings( $settings ) {
if ( ! is_admin() ) {
return $settings;
}
if ( ! function_exists( 'wc_blocks_container' ) ) {
global $wp_locale;
// inject data not available via older versions of wc_blocks/woo.
$settings['orderStatuses'] = self::get_order_statuses( wc_get_order_statuses() );
$settings['stockStatuses'] = self::get_order_statuses( wc_get_product_stock_status_options() );
$settings['currency'] = self::get_currency_settings();
$settings['locale'] = array(
'siteLocale' => isset( $settings['siteLocale'] )
? $settings['siteLocale']
: get_locale(),
'userLocale' => isset( $settings['l10n']['userLocale'] )
? $settings['l10n']['userLocale']
: get_user_locale(),
'weekdaysShort' => isset( $settings['l10n']['weekdaysShort'] )
? $settings['l10n']['weekdaysShort']
: array_values( $wp_locale->weekday_abbrev ),
);
}
//phpcs:ignore
$preload_data_endpoints = apply_filters( 'woocommerce_component_settings_preload_endpoints', array() );
if ( class_exists( 'Jetpack' ) ) {
$preload_data_endpoints['jetpackStatus'] = '/jetpack/v4/connection';
}
if ( ! empty( $preload_data_endpoints ) ) {
$preload_data = array_reduce(
array_values( $preload_data_endpoints ),
'rest_preload_api_request'
);
}
//phpcs:ignore
$preload_options = apply_filters( 'woocommerce_admin_preload_options', array() );
if ( ! empty( $preload_options ) ) {
foreach ( $preload_options as $option ) {
$settings['preloadOptions'][ $option ] = get_option( $option );
}
}
//phpcs:ignore
$preload_settings = apply_filters( 'woocommerce_admin_preload_settings', array() );
if ( ! empty( $preload_settings ) ) {
$setting_options = new \WC_REST_Setting_Options_V2_Controller();
foreach ( $preload_settings as $group ) {
$group_settings = $setting_options->get_group_settings( $group );
$preload_settings = array();
foreach ( $group_settings as $option ) {
if ( array_key_exists( 'id', $option ) && array_key_exists( 'value', $option ) ) {
$preload_settings[ $option['id'] ] = $option['value'];
}
}
$settings['preloadSettings'][ $group ] = $preload_settings;
}
}
$user_controller = new \WP_REST_Users_Controller();
$request = new \WP_REST_Request();
$request->set_query_params( array( 'context' => 'edit' ) );
$user_response = $user_controller->get_current_item( $request );
$current_user_data = is_wp_error( $user_response ) ? (object) array() : $user_response->get_data();
$settings['currentUserData'] = $current_user_data;
$settings['reviewsEnabled'] = get_option( 'woocommerce_enable_reviews' );
$settings['manageStock'] = get_option( 'woocommerce_manage_stock' );
$settings['commentModeration'] = get_option( 'comment_moderation' );
$settings['notifyLowStockAmount'] = get_option( 'woocommerce_notify_low_stock_amount' );
/**
* Deprecate wcAdminAssetUrl as we no longer need it after The Merge.
* Use wcAssetUrl instead.
*
* @deprecated 6.7.0
* @var string
*/
$settings['wcAdminAssetUrl'] = WC_ADMIN_IMAGES_FOLDER_URL;
$settings['wcVersion'] = WC_VERSION;
$settings['siteUrl'] = site_url();
$settings['shopUrl'] = get_permalink( wc_get_page_id( 'shop' ) );
$settings['homeUrl'] = home_url();
$settings['dateFormat'] = get_option( 'date_format' );
$settings['timeZone'] = wc_timezone_string();
$settings['plugins'] = array(
'installedPlugins' => PluginsHelper::get_installed_plugin_slugs(),
'activePlugins' => Plugins::get_active_plugins(),
);
// Plugins that depend on changing the translation work on the server but not the client -
// WooCommerce Branding is an example of this - so pass through the translation of
// 'WooCommerce' to wcSettings.
$settings['woocommerceTranslation'] = __( 'WooCommerce', 'woocommerce' );
// We may have synced orders with a now-unregistered status.
// E.g An extension that added statuses is now inactive or removed.
$settings['unregisteredOrderStatuses'] = $this->get_unregistered_order_statuses();
// The separator used for attributes found in Variation titles.
//phpcs:ignore
$settings['variationTitleAttributesSeparator'] = apply_filters( 'woocommerce_product_variation_title_attributes_separator', ' - ', new \WC_Product() );
if ( ! empty( $preload_data_endpoints ) ) {
$settings['dataEndpoints'] = isset( $settings['dataEndpoints'] )
? $settings['dataEndpoints']
: array();
foreach ( $preload_data_endpoints as $key => $endpoint ) {
// Handle error case: rest_do_request() doesn't guarantee success.
if ( empty( $preload_data[ $endpoint ] ) ) {
$settings['dataEndpoints'][ $key ] = array();
} else {
$settings['dataEndpoints'][ $key ] = $preload_data[ $endpoint ]['body'];
}
}
}
$settings = $this->get_custom_settings( $settings );
if ( PageController::is_embed_page() ) {
$settings['embedBreadcrumbs'] = wc_admin_get_breadcrumbs();
}
$settings['allowMarketplaceSuggestions'] = WC_Marketplace_Suggestions::allow_suggestions();
$settings['connectNonce'] = wp_create_nonce( 'connect' );
$settings['wcpay_welcome_page_connect_nonce'] = wp_create_nonce( 'wcpay-connect' );
$settings['features'] = $this->get_features();
$settings['isWooPayEligible'] = WCPayPromotionInit::is_woopay_eligible();
return $settings;
}
/**
* Removes non necesary feature properties for the client side.
*
* @return array
*/
public function get_features() {
$features = FeaturesUtil::get_features( true, true );
$new_features = array();
foreach ( array_keys( $features ) as $feature_id ) {
$new_features[ $feature_id ] = array(
'is_enabled' => $features[ $feature_id ]['is_enabled'],
'is_experimental' => $features[ $feature_id ]['is_experimental'] ?? false,
);
}
return $new_features;
}
/**
* Register the admin settings for use in the WC REST API
*
* @param array $groups Array of setting groups.
* @return array
*/
public function add_settings_group( $groups ) {
$groups[] = array(
'id' => 'wc_admin',
'label' => __( 'WooCommerce Admin', 'woocommerce' ),
'description' => __( 'Settings for WooCommerce admin reporting.', 'woocommerce' ),
);
return $groups;
}
/**
* Add WC Admin specific settings
*
* @param array $settings Array of settings in wc admin group.
* @return array
*/
public function add_settings( $settings ) {
$unregistered_statuses = $this->get_unregistered_order_statuses();
$registered_statuses = self::get_order_statuses( wc_get_order_statuses() );
$all_statuses = array_merge( $unregistered_statuses, $registered_statuses );
$settings[] = array(
'id' => 'woocommerce_excluded_report_order_statuses',
'option_key' => 'woocommerce_excluded_report_order_statuses',
'label' => __( 'Excluded report order statuses', 'woocommerce' ),
'description' => __( 'Statuses that should not be included when calculating report totals.', 'woocommerce' ),
'default' => array( 'pending', 'cancelled', 'failed' ),
'type' => 'multiselect',
'options' => $all_statuses,
);
$settings[] = array(
'id' => 'woocommerce_actionable_order_statuses',
'option_key' => 'woocommerce_actionable_order_statuses',
'label' => __( 'Actionable order statuses', 'woocommerce' ),
'description' => __( 'Statuses that require extra action on behalf of the store admin.', 'woocommerce' ),
'default' => array( 'processing', 'on-hold' ),
'type' => 'multiselect',
'options' => $all_statuses,
);
$settings[] = array(
'id' => 'woocommerce_default_date_range',
'option_key' => 'woocommerce_default_date_range',
'label' => __( 'Default Date Range', 'woocommerce' ),
'description' => __( 'Default Date Range', 'woocommerce' ),
'default' => 'period=month&compare=previous_year',
'type' => 'text',
);
$settings[] = array(
'id' => 'woocommerce_date_type',
'option_key' => 'woocommerce_date_type',
'label' => __( 'Date Type', 'woocommerce' ),
'description' => __( 'Database date field considered for Revenue and Orders reports', 'woocommerce' ),
'type' => 'select',
'options' => array(
'date_created' => 'date_created',
'date_paid' => 'date_paid',
'date_completed' => 'date_completed',
),
);
return $settings;
}
/**
* Gets custom settings used for WC Admin.
*
* @param array $settings Array of settings to merge into.
* @return array
*/
private function get_custom_settings( $settings ) {
$wc_rest_settings_options_controller = new \WC_REST_Setting_Options_Controller();
$wc_admin_group_settings = $wc_rest_settings_options_controller->get_group_settings( 'wc_admin' );
$settings['wcAdminSettings'] = array();
foreach ( $wc_admin_group_settings as $setting ) {
if ( ! empty( $setting['id'] ) ) {
$settings['wcAdminSettings'][ $setting['id'] ] = $setting['value'];
}
}
return $settings;
}
}
vhosts/uyarreklam.com.tr/httpdocs/wp-content/plugins/all-in-one-seo-pack/app/Common/Api/Settings.php0000644 00000057343 15154540651 0031122 0 ustar 00 var/www <?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
use AIOSEO\Plugin\Common\Migration;
/**
* Route class for the API.
*
* @since 4.0.0
*/
class Settings {
/**
* Contents to import.
*
* @since 4.7.2
*
* @var array
*/
public static $importFile = [];
/**
* Update the settings.
*
* @since 4.0.0
*
* @return \WP_REST_Response The response.
*/
public static function getOptions() {
return new \WP_REST_Response( [
'options' => aioseo()->options->all(),
'settings' => aioseo()->settings->all()
], 200 );
}
/**
* Toggles a card in the settings.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function toggleCard( $request ) {
$body = $request->get_json_params();
$card = ! empty( $body['card'] ) ? sanitize_text_field( $body['card'] ) : null;
$cards = aioseo()->settings->toggledCards;
if ( array_key_exists( $card, $cards ) ) {
$cards[ $card ] = ! $cards[ $card ];
aioseo()->settings->toggledCards = $cards;
}
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Toggles a radio in the settings.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function toggleRadio( $request ) {
$body = $request->get_json_params();
$radio = ! empty( $body['radio'] ) ? sanitize_text_field( $body['radio'] ) : null;
$value = ! empty( $body['value'] ) ? sanitize_text_field( $body['value'] ) : null;
$radios = aioseo()->settings->toggledRadio;
if ( array_key_exists( $radio, $radios ) ) {
$radios[ $radio ] = $value;
aioseo()->settings->toggledRadio = $radios;
}
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Dismisses an alert.
*
* @since 4.3.6
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function dismissAlert( $request ) {
$body = $request->get_json_params();
$alert = ! empty( $body['alert'] ) ? sanitize_text_field( $body['alert'] ) : null;
$alerts = aioseo()->settings->dismissedAlerts;
if ( array_key_exists( $alert, $alerts ) ) {
$alerts[ $alert ] = true;
aioseo()->settings->dismissedAlerts = $alerts;
}
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Toggles a table's items per page setting.
*
* @since 4.2.5
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function changeItemsPerPage( $request ) {
$body = $request->get_json_params();
$table = ! empty( $body['table'] ) ? sanitize_text_field( $body['table'] ) : null;
$value = ! empty( $body['value'] ) ? intval( $body['value'] ) : null;
$tables = aioseo()->settings->tablePagination;
if ( array_key_exists( $table, $tables ) ) {
$tables[ $table ] = $value;
aioseo()->settings->tablePagination = $tables;
}
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Dismisses the upgrade bar.
*
* @since 4.0.0
*
* @return \WP_REST_Response The response.
*/
public static function hideUpgradeBar() {
aioseo()->settings->showUpgradeBar = false;
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Hides the Setup Wizard CTA.
*
* @since 4.0.0
*
* @return \WP_REST_Response The response.
*/
public static function hideSetupWizard() {
aioseo()->settings->showSetupWizard = false;
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Save options from the front end.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function saveChanges( $request ) {
$body = $request->get_json_params();
$options = ! empty( $body['options'] ) ? $body['options'] : [];
$dynamicOptions = ! empty( $body['dynamicOptions'] ) ? $body['dynamicOptions'] : [];
$network = ! empty( $body['network'] ) ? (bool) $body['network'] : false;
$networkOptions = ! empty( $body['networkOptions'] ) ? $body['networkOptions'] : [];
// If this is the network admin, reset the options.
if ( $network ) {
aioseo()->networkOptions->sanitizeAndSave( $networkOptions );
} else {
aioseo()->options->sanitizeAndSave( $options );
aioseo()->dynamicOptions->sanitizeAndSave( $dynamicOptions );
}
// Re-initialize notices.
aioseo()->notices->init();
return new \WP_REST_Response( [
'success' => true,
'notifications' => Models\Notification::getNotifications()
], 200 );
}
/**
* Reset settings.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function resetSettings( $request ) {
$body = $request->get_json_params();
$settings = ! empty( $body['settings'] ) ? $body['settings'] : [];
$notAllowedOptions = aioseo()->access->getNotAllowedOptions();
foreach ( $settings as $setting ) {
$optionAccess = in_array( $setting, [ 'robots', 'blocker' ], true ) ? 'tools' : $setting;
if ( in_array( $optionAccess, $notAllowedOptions, true ) ) {
continue;
}
switch ( $setting ) {
case 'robots':
aioseo()->options->tools->robots->reset();
aioseo()->options->searchAppearance->advanced->unwantedBots->reset();
aioseo()->options->searchAppearance->advanced->searchCleanup->settings->preventCrawling = false;
break;
default:
if ( 'searchAppearance' === $setting ) {
aioseo()->robotsTxt->resetSearchAppearanceRules();
}
if ( aioseo()->options->has( $setting ) ) {
aioseo()->options->$setting->reset();
}
if ( aioseo()->dynamicOptions->has( $setting ) ) {
aioseo()->dynamicOptions->$setting->reset();
}
}
if ( 'access-control' === $setting ) {
aioseo()->access->addCapabilities();
}
}
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Import settings from external file.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request.
* @return \WP_REST_Response The response.
*/
public static function importSettings( $request ) {
$file = $request->get_file_params()['file'];
$isJSONFile = 'application/json' === $file['type'];
$isCSVFile = 'text/csv' === $file['type'];
$isOctetFile = 'application/octet-stream' === $file['type'];
if (
empty( $file['tmp_name'] ) ||
empty( $file['type'] ) ||
(
! $isJSONFile &&
! $isCSVFile &&
! $isOctetFile
)
) {
return new \WP_REST_Response( [
'success' => false
], 400 );
}
$contents = aioseo()->core->fs->getContents( $file['tmp_name'] );
if ( empty( $contents ) ) {
return new \WP_REST_Response( [
'success' => false
], 400 );
}
if ( $isJSONFile ) {
self::$importFile = json_decode( $contents, true );
}
if ( $isCSVFile ) {
// Transform the CSV content into the original JSON array.
self::$importFile = self::prepareCsvImport( $contents );
}
// If the file is invalid just return.
if ( empty( self::$importFile ) ) {
return new \WP_REST_Response( [
'success' => false
], 400 );
}
// Import settings.
if ( ! empty( self::$importFile['settings'] ) ) {
self::importSettingsFromFile( self::$importFile['settings'] );
}
// Import posts.
if ( ! empty( self::$importFile['postOptions'] ) ) {
self::importPostsFromFile( self::$importFile['postOptions'] );
}
// Import INI.
if ( $isOctetFile ) {
$response = aioseo()->importExport->importIniData( self::$importFile );
if ( ! $response ) {
return new \WP_REST_Response( [
'success' => false
], 400 );
}
}
return new \WP_REST_Response( [
'success' => true,
'options' => aioseo()->options->all()
], 200 );
}
/**
* Import settings from a file.
*
* @since 4.7.2
*
* @param array $settings The data to import.
*/
private static function importSettingsFromFile( $settings ) {
// Clean up the array removing options the user should not manage.
$notAllowedOptions = aioseo()->access->getNotAllowedOptions();
$settings = array_diff_key( $settings, $notAllowedOptions );
if ( ! empty( $settings['deprecated'] ) ) {
$settings['deprecated'] = array_diff_key( $settings['deprecated'], $notAllowedOptions );
}
// Remove any dynamic options and save them separately since this has been refactored.
$commonDynamic = [
'sitemap',
'searchAppearance',
'breadcrumbs',
'accessControl'
];
foreach ( $commonDynamic as $cd ) {
if ( ! empty( $settings[ $cd ]['dynamic'] ) ) {
$settings['dynamic'][ $cd ] = $settings[ $cd ]['dynamic'];
unset( $settings[ $cd ]['dynamic'] );
}
}
// These options have a very different structure so we'll do them separately.
if ( ! empty( $settings['social']['facebook']['general']['dynamic'] ) ) {
$settings['dynamic']['social']['facebook']['general'] = $settings['social']['facebook']['general']['dynamic'];
unset( $settings['social']['facebook']['general']['dynamic'] );
}
if ( ! empty( $settings['dynamic'] ) ) {
aioseo()->dynamicOptions->sanitizeAndSave( $settings['dynamic'] );
unset( $settings['dynamic'] );
}
if ( ! empty( $settings['tools']['robots']['rules'] ) ) {
$settings['tools']['robots']['rules'] = array_merge( aioseo()->robotsTxt->extractSearchAppearanceRules(), $settings['tools']['robots']['rules'] );
}
aioseo()->options->sanitizeAndSave( $settings );
}
/**
* Import posts from a file.
*
* @since 4.7.2
*
* @param array $postOptions The data to import.
*/
private static function importPostsFromFile( $postOptions ) {
$notAllowedFields = aioseo()->access->getNotAllowedPageFields();
foreach ( $postOptions as $postData ) {
if ( ! empty( $postData['posts'] ) ) {
foreach ( $postData['posts'] as $post ) {
unset( $post['id'] );
// Clean up the array removing fields the user should not manage.
$post = array_diff_key( $post, $notAllowedFields );
$thePost = Models\Post::getPost( $post['post_id'] );
// Remove primary term if the term is not attached to the post anymore.
if ( ! empty( $post['primary_term'] ) && aioseo()->helpers->isJsonString( $post['primary_term'] ) ) {
$primaryTerms = json_decode( $post['primary_term'], true );
foreach ( $primaryTerms as $tax => $termId ) {
$terms = wp_get_post_terms( $post['post_id'], $tax, [
'fields' => 'ids'
] );
if ( is_array( $terms ) && ! in_array( $termId, $terms, true ) ) {
unset( $primaryTerms[ $tax ] );
}
}
$post['primary_term'] = empty( $primaryTerms ) ? null : wp_json_encode( $primaryTerms );
}
// Remove FAQ Block schema if the block is not present in the post anymore.
if ( ! empty( $post['schema'] ) && aioseo()->helpers->isJsonString( $post['schema'] ) ) {
$schemas = json_decode( $post['schema'], true );
foreach ( $schemas['blockGraphs'] as $index => $block ) {
if ( 'aioseo/faq' !== $block['type'] ) {
continue;
}
$postBlocks = parse_blocks( get_the_content( null, false, $post['post_id'] ) );
$postFaqBlock = array_filter( $postBlocks, function( $block ) {
return 'aioseo/faq' === $block['blockName'];
} );
if ( empty( $postFaqBlock ) ) {
unset( $schemas['blockGraphs'][ $index ] );
}
}
$post['schema'] = wp_json_encode( $schemas );
}
$thePost->set( $post );
$thePost->save();
}
}
}
}
/**
* Prepare the content from CSV to the original JSON array to import.
*
* @since 4.7.2
*
* @param string $fileContent The Data to import.
* @return array The content.
*/
public static function prepareCSVImport( $fileContent ) {
$content = [];
$newContent = [
'postOptions' => null
];
$rows = str_getcsv( $fileContent, "\n" );
// Get the first row to check if the file has post_id or term_id.
$header = str_getcsv( $rows[0], ',' );
$header = aioseo()->helpers->sanitizeOption( $header );
// Check if the file has post_id or term_id.
$type = in_array( 'post_id', $header, true ) ? 'posts' : null;
$type = in_array( 'term_id', $header, true ) ? 'terms' : $type;
if ( ! $type ) {
return false;
}
// Remove header row.
unset( $rows[0] );
$jsonFields = [
'ai',
'keywords',
'keyphrases',
'page_analysis',
'primary_term',
'og_article_tags',
'schema',
'options',
'videos'
];
foreach ( $rows as $row ) {
$row = str_replace( '\\""', '\\"', $row );
$row = str_getcsv( $row, ',' );
foreach ( $row as $key => $value ) {
$key = aioseo()->helpers->sanitizeOption( $key );
if ( ! empty( $value ) && in_array( $header[ $key ], $jsonFields, true ) && ! aioseo()->helpers->isJsonString( $value ) ) {
continue;
} elseif ( '' === trim( $value ) ) {
$value = null;
}
$content[ $header [ $key ] ] = $value;
}
$newContent['postOptions']['content'][ $type ][] = $content;
}
return $newContent;
}
/**
* Export settings.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function exportSettings( $request ) {
$body = $request->get_json_params();
$settings = ! empty( $body['settings'] ) ? $body['settings'] : [];
$allSettings = [
'settings' => []
];
if ( empty( $settings ) ) {
return new \WP_REST_Response( [
'success' => false
], 400 );
}
$options = aioseo()->options->noConflict();
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
$notAllowedOptions = aioseo()->access->getNotAllowedOptions();
foreach ( $settings as $setting ) {
$optionAccess = in_array( $setting, [ 'robots', 'blocker' ], true ) ? 'tools' : $setting;
if ( in_array( $optionAccess, $notAllowedOptions, true ) ) {
continue;
}
switch ( $setting ) {
case 'robots':
$allSettings['settings']['tools']['robots'] = $options->tools->robots->all();
// Search Appearance settings that are also found in the robots settings.
if ( empty( $allSettings['settings']['searchAppearance']['advanced'] ) ) {
$allSettings['settings']['searchAppearance']['advanced'] = [
'unwantedBots' => $options->searchAppearance->advanced->unwantedBots->all(),
'searchCleanup' => [
'settings' => [
'preventCrawling' => $options->searchAppearance->advanced->searchCleanup->settings->preventCrawling
]
]
];
}
break;
default:
if ( $options->has( $setting ) ) {
$allSettings['settings'][ $setting ] = $options->$setting->all();
}
// If there are related dynamic settings, let's include them.
if ( $dynamicOptions->has( $setting ) ) {
$allSettings['settings']['dynamic'][ $setting ] = $dynamicOptions->$setting->all();
}
// It there is a related deprecated $setting, include it.
if ( $options->deprecated->has( $setting ) ) {
$allSettings['settings']['deprecated'][ $setting ] = $options->deprecated->$setting->all();
}
break;
}
}
return new \WP_REST_Response( [
'success' => true,
'settings' => $allSettings
], 200 );
}
/**
* Export post data.
*
* @since 4.7.2
*
* @param \WP_REST_Request $request The REST Request.
* @return \WP_REST_Response The response.
*/
public static function exportContent( $request ) {
$body = $request->get_json_params();
$postOptions = $body['postOptions'] ?? [];
$typeFile = $body['typeFile'] ?? false;
$siteId = (int) ( $body['siteId'] ?? get_current_blog_id() );
$contentPostType = null;
$return = true;
try {
aioseo()->helpers->switchToBlog( $siteId );
// Get settings from post types selected.
if ( ! empty( $postOptions ) ) {
$fieldsToExclude = [
'seo_score' => '',
'schema_type' => '',
'schema_type_options' => '',
'images' => '',
'image_scan_date' => '',
'videos' => '',
'video_thumbnail' => '',
'video_scan_date' => '',
'link_scan_date' => '',
'link_suggestions_scan_date' => '',
'local_seo' => '',
'options' => '',
'ai' => ''
];
$notAllowed = array_merge( aioseo()->access->getNotAllowedPageFields(), $fieldsToExclude );
$posts = self::getPostTypesData( $postOptions, $notAllowed );
// Generate content to CSV or JSON.
if ( ! empty( $posts ) ) {
// Change the order of keys so the post_title shows up at the beginning.
$data = [];
foreach ( $posts as $p ) {
$item = [
'id' => '',
'post_id' => '',
'post_title' => '',
'title' => ''
];
$p['title'] = aioseo()->helpers->decodeHtmlEntities( $p['title'] );
$p['post_title'] = aioseo()->helpers->decodeHtmlEntities( $p['post_title'] );
$data[] = array_merge( $item, $p );
}
if ( 'csv' === $typeFile ) {
$contentPostType = self::dataToCsv( $data );
}
if ( 'json' === $typeFile ) {
$contentPostType['postOptions']['content']['posts'] = $data;
}
}
}
} catch ( \Throwable $th ) {
$return = false;
}
return new \WP_REST_Response( [
'success' => $return,
'postTypeData' => $contentPostType
], 200 );
}
/**
* Returns the posts of specific post types.
*
* @since 4.7.2
*
* @param array $postOptions The post types to get data from.
* @param array $notAllowedFields An array of fields not allowed to be returned.
* @return array The posts.
*/
private static function getPostTypesData( $postOptions, $notAllowedFields = [] ) {
$posts = aioseo()->core->db->start( 'aioseo_posts as ap' )
->select( 'ap.*, p.post_title' )
->join( 'posts as p', 'ap.post_id = p.ID' )
->whereIn( 'p.post_type', $postOptions )
->orderBy( 'ap.id' )
->run()
->result();
if ( ! empty( $notAllowedFields ) ) {
foreach ( $posts as $key => &$p ) {
$p = array_diff_key( (array) $p, $notAllowedFields );
if ( count( $p ) <= 2 ) {
unset( $posts[ $key ] );
}
}
}
return $posts;
}
/**
* Returns a CSV string.
*
* @since 4.7.2
*
* @param array $data An array of data to transform into a CSV.
* @return string The CSV string.
*/
public static function dataToCsv( $data ) {
// Get the header row.
$csvString = implode( ',', array_keys( (array) $data[0] ) ) . "\r\n";
// Get the content rows.
foreach ( $data as $row ) {
$row = (array) $row;
foreach ( $row as &$value ) {
if ( aioseo()->helpers->isJsonString( $value ) ) {
$value = '"' . str_replace( '"', '""', $value ) . '"';
} elseif ( false !== strpos( (string) $value, ',' ) ) {
$value = '"' . $value . '"';
}
}
$csvString .= implode( ',', $row ) . "\r\n";
}
return $csvString;
}
/**
* Import other plugin settings.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function importPlugins( $request ) {
$body = $request->get_json_params();
$plugins = ! empty( $body['plugins'] ) ? $body['plugins'] : [];
foreach ( $plugins as $plugin ) {
aioseo()->importExport->startImport( $plugin['plugin'], $plugin['settings'] );
}
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Executes a given administrative task.
*
* @since 4.1.2
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function doTask( $request ) {
$body = $request->get_json_params();
$action = ! empty( $body['action'] ) ? $body['action'] : '';
$data = ! empty( $body['data'] ) ? $body['data'] : [];
$network = ! empty( $body['network'] ) ? boolval( $body['network'] ) : false;
$siteId = ! empty( $body['siteId'] ) ? intval( $body['siteId'] ) : false;
$siteOrNetwork = empty( $siteId ) ? aioseo()->helpers->getNetworkId() : $siteId; // If we don't have a siteId, we will use the networkId.
// When on network admin page and no siteId, it is supposed to perform on network level.
if ( $network && 'clear-cache' === $action && empty( $siteId ) ) {
aioseo()->core->networkCache->clear();
return new \WP_REST_Response( [
'success' => true
], 200 );
}
// Switch to the right blog before processing any task.
aioseo()->helpers->switchToBlog( $siteOrNetwork );
switch ( $action ) {
// General
case 'clear-cache':
aioseo()->core->cache->clear();
break;
case 'clear-plugin-updates-transient':
delete_site_transient( 'update_plugins' );
break;
case 'readd-capabilities':
aioseo()->access->addCapabilities();
break;
case 'reset-data':
aioseo()->uninstall->dropData( true );
aioseo()->internalOptions->database->installedTables = '';
aioseo()->internalOptions->internal->lastActiveVersion = '4.0.0';
aioseo()->internalOptions->save( true );
aioseo()->updates->addInitialCustomTablesForV4();
break;
// Sitemap
case 'clear-image-data':
aioseo()->sitemap->query->resetImages();
break;
// Migrations
case 'rerun-migrations':
aioseo()->internalOptions->database->installedTables = '';
aioseo()->internalOptions->internal->lastActiveVersion = '4.0.0';
aioseo()->internalOptions->save( true );
break;
case 'rerun-addon-migrations':
aioseo()->internalOptions->database->installedTables = '';
foreach ( $data as $sku ) {
$convertedSku = aioseo()->helpers->dashesToCamelCase( $sku );
if (
function_exists( $convertedSku ) &&
isset( $convertedSku()->internalOptions )
) {
$convertedSku()->internalOptions->internal->lastActiveVersion = '0.0';
}
}
break;
case 'restart-v3-migration':
Migration\Helpers::redoMigration();
break;
// Old Issues
case 'remove-duplicates':
aioseo()->updates->removeDuplicateRecords();
break;
case 'unescape-data':
aioseo()->admin->scheduleUnescapeData();
break;
// Deprecated Options
case 'deprecated-options':
// Check if the user is forcefully wanting to add a deprecated option.
$allDeprecatedOptions = aioseo()->internalOptions->getAllDeprecatedOptions() ?: [];
$enableOptions = array_keys( array_filter( $data ) );
$enabledDeprecated = array_intersect( $allDeprecatedOptions, $enableOptions );
aioseo()->internalOptions->internal->deprecatedOptions = array_values( $enabledDeprecated );
aioseo()->internalOptions->save( true );
break;
case 'aioseo-reset-seoboost-logins':
aioseo()->writingAssistant->seoBoost->resetLogins();
break;
default:
aioseo()->helpers->restoreCurrentBlog();
return new \WP_REST_Response( [
'success' => true,
'error' => 'The given action isn\'t defined.'
], 400 );
}
// Revert back to the current blog after processing to avoid conflict with other actions.
aioseo()->helpers->restoreCurrentBlog();
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Change Sem Rush Focus Keyphrase default country.
*
* @since 4.7.5
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function changeSemrushCountry( $request ) {
$body = $request->get_json_params();
$country = ! empty( $body['value'] ) ? sanitize_text_field( $body['value'] ) : 'US';
aioseo()->settings->semrushCountry = $country;
return new \WP_REST_Response( [
'success' => true
], 200 );
}
} vhosts/uyarreklam.com.tr/httpdocs/wp-content/plugins/google-listings-and-ads/src/Menu/Settings.php 0000644 00000001370 15154642552 0031044 0 ustar 00 var/www <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Menu;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Registerable;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service;
/**
* Class Settings
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Menu
*/
class Settings implements Service, Registerable {
/**
* Register a service.
*/
public function register(): void {
add_action(
'admin_menu',
function () {
wc_admin_register_page(
[
'title' => __( 'Settings', 'google-listings-and-ads' ),
'parent' => 'google-listings-and-ads-category',
'path' => '/google/settings',
'id' => 'google-settings',
]
);
}
);
}
}
httpdocs/wp-content/plugins/woocommerce/vendor/sabberworm/php-css-parser/src/Settings.php 0000644 00000003647 15155343274 0034364 0 ustar 00 var/www/vhosts/uyarreklam.com.tr <?php
namespace Sabberworm\CSS;
/**
* Parser settings class.
*
* Configure parser behaviour here.
*/
class Settings
{
/**
* Multi-byte string support.
* If true (mbstring extension must be enabled), will use (slower) `mb_strlen`, `mb_convert_case`, `mb_substr`
* and `mb_strpos` functions. Otherwise, the normal (ASCII-Only) functions will be used.
*
* @var bool
*/
public $bMultibyteSupport;
/**
* The default charset for the CSS if no `@charset` rule is found. Defaults to utf-8.
*
* @var string
*/
public $sDefaultCharset = 'utf-8';
/**
* Lenient parsing. When used (which is true by default), the parser will not choke
* on unexpected tokens but simply ignore them.
*
* @var bool
*/
public $bLenientParsing = true;
private function __construct()
{
$this->bMultibyteSupport = extension_loaded('mbstring');
}
/**
* @return self new instance
*/
public static function create()
{
return new Settings();
}
/**
* @param bool $bMultibyteSupport
*
* @return self fluent interface
*/
public function withMultibyteSupport($bMultibyteSupport = true)
{
$this->bMultibyteSupport = $bMultibyteSupport;
return $this;
}
/**
* @param string $sDefaultCharset
*
* @return self fluent interface
*/
public function withDefaultCharset($sDefaultCharset)
{
$this->sDefaultCharset = $sDefaultCharset;
return $this;
}
/**
* @param bool $bLenientParsing
*
* @return self fluent interface
*/
public function withLenientParsing($bLenientParsing = true)
{
$this->bLenientParsing = $bLenientParsing;
return $this;
}
/**
* @return self fluent interface
*/
public function beStrict()
{
return $this->withLenientParsing(false);
}
}
uyarreklam.com.tr/httpdocs/wp-content/plugins/google-listings-and-ads/src/API/Google/Settings.php 0000644 00000030004 15155351777 0031770 0 ustar 00 var/www/vhosts <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query\ShippingRateQuery;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query\ShippingTimeQuery;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\TargetAudience;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\WC;
use Automattic\WooCommerce\GoogleListingsAndAds\Shipping\CountryRatesCollection;
use Automattic\WooCommerce\GoogleListingsAndAds\Shipping\GoogleAdapter\DBShippingSettingsAdapter;
use Automattic\WooCommerce\GoogleListingsAndAds\Shipping\GoogleAdapter\WCShippingSettingsAdapter;
use Automattic\WooCommerce\GoogleListingsAndAds\Shipping\ShippingZone;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\AccountAddress;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\AccountTax;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\AccountTaxTaxRule as TaxRule;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\ShippingSettings;
defined( 'ABSPATH' ) || exit;
/**
* Class Settings
*
* Container used for:
* - OptionsInterface
* - ShippingRateQuery
* - ShippingTimeQuery
* - ShippingZone
* - ShoppingContent
* - TargetAudience
* - WC
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Google
*/
class Settings implements ContainerAwareInterface {
use ContainerAwareTrait;
use LocationIDTrait;
/**
* Return a set of formatted settings which can be used in tracking.
*
* @since 2.5.16
*
* @return array
*/
public function get_settings_for_tracking() {
$settings = $this->get_settings();
return [
'shipping_rate' => $settings['shipping_rate'] ?? '',
'offers_free_shipping' => (bool) ( $settings['offers_free_shipping'] ?? false ),
'free_shipping_threshold' => (float) ( $settings['free_shipping_threshold'] ?? 0 ),
'shipping_time' => $settings['shipping_time'] ?? '',
'tax_rate' => $settings['tax_rate'] ?? '',
'target_countries' => join( ',', $this->get_target_countries() ),
];
}
/**
* Sync the shipping settings with Google.
*/
public function sync_shipping() {
if ( ! $this->should_sync_shipping() ) {
return;
}
$settings = $this->generate_shipping_settings();
$this->get_shopping_service()->shippingsettings->update(
$this->get_merchant_id(),
$this->get_account_id(),
$settings
);
}
/**
* Whether we should synchronize settings with the Merchant Center
*
* @return bool
*/
protected function should_sync_shipping(): bool {
$shipping_rate = $this->get_settings()['shipping_rate'] ?? '';
$shipping_time = $this->get_settings()['shipping_time'] ?? '';
return in_array( $shipping_rate, [ 'flat', 'automatic' ], true ) && 'flat' === $shipping_time;
}
/**
* Whether we should get the shipping settings from the WooCommerce settings.
*
* @return bool
*
* @since 1.12.0
*/
public function should_get_shipping_rates_from_woocommerce(): bool {
return 'automatic' === ( $this->get_settings()['shipping_rate'] ?? '' );
}
/**
* Generate a ShippingSettings object for syncing the store shipping settings to Merchant Center.
*
* @return ShippingSettings
*
* @since 2.1.0
*/
protected function generate_shipping_settings(): ShippingSettings {
$times = $this->get_shipping_times();
/** @var WC $wc_proxy */
$wc_proxy = $this->container->get( WC::class );
$currency = $wc_proxy->get_woocommerce_currency();
if ( $this->should_get_shipping_rates_from_woocommerce() ) {
return new WCShippingSettingsAdapter(
[
'currency' => $currency,
'rates_collections' => $this->get_shipping_rates_collections_from_woocommerce(),
'delivery_times' => $times,
'accountId' => $this->get_account_id(),
]
);
}
return new DBShippingSettingsAdapter(
[
'currency' => $currency,
'db_rates' => $this->get_shipping_rates_from_database(),
'delivery_times' => $times,
'accountId' => $this->get_account_id(),
]
);
}
/**
* Get the current tax settings from the API.
*
* @return AccountTax
*/
public function get_taxes(): AccountTax {
return $this->get_shopping_service()->accounttax->get(
$this->get_merchant_id(),
$this->get_account_id()
);
}
/**
* Whether we should sync tax settings.
*
* This depends on the store being in the US
*
* @return bool
*/
protected function should_sync_taxes(): bool {
if ( 'US' !== $this->get_store_country() ) {
return false;
}
return 'destination' === ( $this->get_settings()['tax_rate'] ?? 'destination' );
}
/**
* Sync tax setting with Google.
*/
public function sync_taxes() {
if ( ! $this->should_sync_taxes() ) {
return;
}
$taxes = new AccountTax();
$taxes->setAccountId( $this->get_account_id() );
$tax_rule = new TaxRule();
$tax_rule->setUseGlobalRate( true );
$tax_rule->setLocationId( $this->get_state_id( $this->get_store_state() ) );
$tax_rule->setCountry( $this->get_store_country() );
$taxes->setRules( [ $tax_rule ] );
$this->get_shopping_service()->accounttax->update(
$this->get_merchant_id(),
$this->get_account_id(),
$taxes
);
}
/**
* Get shipping time data.
*
* @return array
*/
protected function get_shipping_times(): array {
static $times = null;
if ( null === $times ) {
$time_query = $this->container->get( ShippingTimeQuery::class );
$times = $time_query->get_all_shipping_times();
}
return $times;
}
/**
* Get shipping rate data.
*
* @return array
*/
protected function get_shipping_rates_from_database(): array {
$rate_query = $this->container->get( ShippingRateQuery::class );
return $rate_query->get_results();
}
/**
* Get shipping rate data from WooCommerce shipping settings.
*
* @return CountryRatesCollection[] Array of rates collections for each target country specified in settings.
*/
protected function get_shipping_rates_collections_from_woocommerce(): array {
/** @var TargetAudience $target_audience */
$target_audience = $this->container->get( TargetAudience::class );
$target_countries = $target_audience->get_target_countries();
/** @var ShippingZone $shipping_zone */
$shipping_zone = $this->container->get( ShippingZone::class );
$rates = [];
foreach ( $target_countries as $country ) {
$location_rates = $shipping_zone->get_shipping_rates_for_country( $country );
$rates[ $country ] = new CountryRatesCollection( $country, $location_rates );
}
return $rates;
}
/**
* @return OptionsInterface
*/
protected function get_options_object(): OptionsInterface {
return $this->container->get( OptionsInterface::class );
}
/**
* Get the Merchant ID
*
* @return int
*/
protected function get_merchant_id(): int {
return $this->get_options_object()->get( OptionsInterface::MERCHANT_ID );
}
/**
* Get the account ID.
*
* @return int
*/
protected function get_account_id(): int {
// todo: there are some cases where this might be different than the Merchant ID.
return $this->get_merchant_id();
}
/**
* Get the Shopping Service object.
*
* @return ShoppingContent
*/
protected function get_shopping_service(): ShoppingContent {
return $this->container->get( ShoppingContent::class );
}
/**
* Get the country for the store.
*
* @return string
*/
protected function get_store_country(): string {
return $this->container->get( WC::class )->get_base_country();
}
/**
* Get the state for the store.
*
* @return string
*/
protected function get_store_state(): string {
/** @var WC $wc */
$wc = $this->container->get( WC::class );
return $wc->get_wc_countries()->get_base_state();
}
/**
* Get the WooCommerce store physical address.
*
* @return AccountAddress
*
* @since 1.4.0
*/
public function get_store_address(): AccountAddress {
/** @var WC $wc */
$wc = $this->container->get( WC::class );
$countries = $wc->get_wc_countries();
$postal_code = ! empty( $countries->get_base_postcode() ) ? $countries->get_base_postcode() : null;
$locality = ! empty( $countries->get_base_city() ) ? $countries->get_base_city() : null;
$country = ! empty( $countries->get_base_country() ) ? $countries->get_base_country() : null;
$region = ! empty( $countries->get_base_state() ) ? $countries->get_base_state() : null;
$mc_address = new AccountAddress();
$mc_address->setPostalCode( $postal_code );
$mc_address->setLocality( $locality );
$mc_address->setCountry( $country );
if ( ! empty( $region ) && ! empty( $country ) ) {
$mc_address->setRegion( $this->maybe_get_state_name( $region, $country ) );
}
$address = ! empty( $countries->get_base_address() ) ? $countries->get_base_address() : null;
$address_2 = ! empty( $countries->get_base_address_2() ) ? $countries->get_base_address_2() : null;
$separator = ! empty( $address ) && ! empty( $address_2 ) ? "\n" : '';
$address = sprintf( '%s%s%s', $countries->get_base_address(), $separator, $countries->get_base_address_2() );
if ( ! empty( $address ) ) {
$mc_address->setStreetAddress( $address );
}
return $mc_address;
}
/**
* Check whether the address has errors
*
* @param AccountAddress $address to be validated.
*
* @return array
*/
public function wc_address_errors( AccountAddress $address ): array {
/** @var WC $wc */
$wc = $this->container->get( WC::class );
$countries = $wc->get_wc_countries();
$locale = $countries->get_country_locale();
$locale_settings = $locale[ $address->getCountry() ] ?? [];
$fields_to_validate = [
'address_1' => $address->getStreetAddress(),
'city' => $address->getLocality(),
'country' => $address->getCountry(),
'postcode' => $address->getPostalCode(),
];
return $this->validate_address( $fields_to_validate, $locale_settings );
}
/**
* Check whether the required address fields are empty
*
* @param array $address_fields to be validated.
* @param array $locale_settings locale settings
* @return array
*/
public function validate_address( array $address_fields, array $locale_settings ): array {
$errors = array_filter(
$address_fields,
function ( $field ) use ( $locale_settings, $address_fields ) {
$is_required = $locale_settings[ $field ]['required'] ?? true;
return $is_required && empty( $address_fields[ $field ] );
},
ARRAY_FILTER_USE_KEY
);
return array_keys( $errors );
}
/**
* Return a state name.
*
* @param string $state_code State code.
* @param string $country Country code.
*
* @return string
*
* @since 1.4.0
*/
protected function maybe_get_state_name( string $state_code, string $country ): string {
/** @var WC $wc */
$wc = $this->container->get( WC::class );
$states = $country ? array_filter( (array) $wc->get_wc_countries()->get_states( $country ) ) : [];
if ( ! empty( $states ) ) {
$state_code = wc_strtoupper( $state_code );
if ( isset( $states[ $state_code ] ) ) {
return $states[ $state_code ];
}
}
return $state_code;
}
/**
* Get the array of settings for the Merchant Center.
*
* @return array
*/
protected function get_settings(): array {
$settings = $this->get_options_object()->get( OptionsInterface::MERCHANT_CENTER );
return is_array( $settings ) ? $settings : [];
}
/**
* Return a list of target countries or all.
*
* @return array
*/
protected function get_target_countries(): array {
$target_audience = $this->get_options_object()->get( OptionsInterface::TARGET_AUDIENCE );
if ( isset( $target_audience['location'] ) && 'all' === $target_audience['location'] ) {
return [ 'all' ];
}
return $target_audience['countries'] ?? [];
}
}