Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/Features
File: FeaturesController.php
*/
[1000] Fix | Delete
private function feature_exists( string $feature_id ): bool {
[1001] Fix | Delete
$features = $this->get_feature_definitions();
[1002] Fix | Delete
[1003] Fix | Delete
return isset( $features[ $feature_id ] );
[1004] Fix | Delete
}
[1005] Fix | Delete
[1006] Fix | Delete
/**
[1007] Fix | Delete
* Get the ids of the features that a certain plugin has declared compatibility for.
[1008] Fix | Delete
*
[1009] Fix | Delete
* This method can't be called before the 'woocommerce_init' hook is fired.
[1010] Fix | Delete
*
[1011] Fix | Delete
* @param string $plugin_name Plugin name, in the form 'directory/file.php'.
[1012] Fix | Delete
* @param bool $enabled_features_only True to return only names of enabled plugins.
[1013] Fix | Delete
* @param bool $resolve_uncertain True to resolve the uncertain features to compatible or incompatible.
[1014] Fix | Delete
* @return array An array having a 'compatible' and an 'incompatible' key, each holding an array of feature ids.
[1015] Fix | Delete
*/
[1016] Fix | Delete
public function get_compatible_features_for_plugin( string $plugin_name, bool $enabled_features_only = false, bool $resolve_uncertain = false ): array {
[1017] Fix | Delete
$this->process_pending_declarations();
[1018] Fix | Delete
$this->verify_did_woocommerce_init( __FUNCTION__ );
[1019] Fix | Delete
[1020] Fix | Delete
$features = $this->get_feature_definitions();
[1021] Fix | Delete
[1022] Fix | Delete
if ( $enabled_features_only ) {
[1023] Fix | Delete
$features = array_filter(
[1024] Fix | Delete
$features,
[1025] Fix | Delete
array( $this, 'feature_is_enabled' ),
[1026] Fix | Delete
ARRAY_FILTER_USE_KEY
[1027] Fix | Delete
);
[1028] Fix | Delete
}
[1029] Fix | Delete
[1030] Fix | Delete
if ( ! isset( $this->compatibility_info_by_plugin[ $plugin_name ] ) ) {
[1031] Fix | Delete
return array(
[1032] Fix | Delete
FeaturePluginCompatibility::COMPATIBLE => array(),
[1033] Fix | Delete
FeaturePluginCompatibility::INCOMPATIBLE => array(),
[1034] Fix | Delete
FeaturePluginCompatibility::UNCERTAIN => array_keys( $features ),
[1035] Fix | Delete
);
[1036] Fix | Delete
}
[1037] Fix | Delete
[1038] Fix | Delete
$info = $this->compatibility_info_by_plugin[ $plugin_name ];
[1039] Fix | Delete
$info[ FeaturePluginCompatibility::COMPATIBLE ] = array_values( array_intersect( array_keys( $features ), $info[ FeaturePluginCompatibility::COMPATIBLE ] ) );
[1040] Fix | Delete
$info[ FeaturePluginCompatibility::INCOMPATIBLE ] = array_values( array_intersect( array_keys( $features ), $info[ FeaturePluginCompatibility::INCOMPATIBLE ] ) );
[1041] Fix | Delete
$info[ FeaturePluginCompatibility::UNCERTAIN ] = array_values( array_diff( array_keys( $features ), $info[ FeaturePluginCompatibility::COMPATIBLE ], $info[ FeaturePluginCompatibility::INCOMPATIBLE ] ) );
[1042] Fix | Delete
[1043] Fix | Delete
if ( $resolve_uncertain ) {
[1044] Fix | Delete
foreach ( $info[ FeaturePluginCompatibility::UNCERTAIN ] as $feature_id ) {
[1045] Fix | Delete
$key = $this->get_default_plugin_compatibility( $feature_id );
[1046] Fix | Delete
$info[ $key ][] = $feature_id;
[1047] Fix | Delete
}
[1048] Fix | Delete
[1049] Fix | Delete
$info[ FeaturePluginCompatibility::UNCERTAIN ] = array();
[1050] Fix | Delete
}
[1051] Fix | Delete
[1052] Fix | Delete
return $info;
[1053] Fix | Delete
}
[1054] Fix | Delete
[1055] Fix | Delete
/**
[1056] Fix | Delete
* Get the names of the plugins that have been declared compatible or incompatible with a given feature.
[1057] Fix | Delete
*
[1058] Fix | Delete
* @param string $feature_id Feature id.
[1059] Fix | Delete
* @param bool $active_only True to return only active plugins.
[1060] Fix | Delete
* @param bool $resolve_uncertain True to resolve the uncertain plugins to compatible or incompatible.
[1061] Fix | Delete
* @return array An array having a 'compatible', an 'incompatible' and an 'uncertain' key, each holding an array of plugin names.
[1062] Fix | Delete
*/
[1063] Fix | Delete
public function get_compatible_plugins_for_feature( string $feature_id, bool $active_only = false, bool $resolve_uncertain = false ): array {
[1064] Fix | Delete
$this->process_pending_declarations();
[1065] Fix | Delete
$this->verify_did_woocommerce_init( __FUNCTION__ );
[1066] Fix | Delete
[1067] Fix | Delete
$woo_aware_plugins = $this->plugin_util->get_woocommerce_aware_plugins( $active_only );
[1068] Fix | Delete
if ( ! $this->feature_exists( $feature_id ) ) {
[1069] Fix | Delete
return array(
[1070] Fix | Delete
FeaturePluginCompatibility::COMPATIBLE => array(),
[1071] Fix | Delete
FeaturePluginCompatibility::INCOMPATIBLE => array(),
[1072] Fix | Delete
FeaturePluginCompatibility::UNCERTAIN => $woo_aware_plugins,
[1073] Fix | Delete
);
[1074] Fix | Delete
}
[1075] Fix | Delete
[1076] Fix | Delete
$info = $this->compatibility_info_by_feature[ $feature_id ];
[1077] Fix | Delete
ArrayUtil::ensure_key_is_array( $info, FeaturePluginCompatibility::UNCERTAIN );
[1078] Fix | Delete
[1079] Fix | Delete
// Resolve uncertain plugin compatibility?
[1080] Fix | Delete
$uncertain_plugins = array_values( array_diff( $woo_aware_plugins, $info[ FeaturePluginCompatibility::COMPATIBLE ], $info[ FeaturePluginCompatibility::INCOMPATIBLE ] ) );
[1081] Fix | Delete
$key = $resolve_uncertain ? $this->get_default_plugin_compatibility( $feature_id ) : FeaturePluginCompatibility::UNCERTAIN;
[1082] Fix | Delete
$info[ $key ] = array_merge( $info[ $key ], $uncertain_plugins );
[1083] Fix | Delete
[1084] Fix | Delete
return $info;
[1085] Fix | Delete
}
[1086] Fix | Delete
[1087] Fix | Delete
/**
[1088] Fix | Delete
* Check if the 'woocommerce_init' has run or is running, do a 'wc_doing_it_wrong' if not.
[1089] Fix | Delete
*
[1090] Fix | Delete
* @param string|null $function_name Name of the invoking method, if not null, 'wc_doing_it_wrong' will be invoked if 'woocommerce_init' has not run and is not running.
[1091] Fix | Delete
*
[1092] Fix | Delete
* @return bool True if 'woocommerce_init' has run or is running, false otherwise.
[1093] Fix | Delete
*/
[1094] Fix | Delete
private function verify_did_woocommerce_init( ?string $function_name = null ): bool {
[1095] Fix | Delete
if ( ! $this->proxy->call_function( 'did_action', 'woocommerce_init' ) &&
[1096] Fix | Delete
! $this->proxy->call_function( 'doing_action', 'woocommerce_init' ) ) {
[1097] Fix | Delete
if ( ! is_null( $function_name ) ) {
[1098] Fix | Delete
$class_and_method = ( new \ReflectionClass( $this ) )->getShortName() . '::' . $function_name;
[1099] Fix | Delete
/* translators: 1: class::method 2: plugins_loaded */
[1100] Fix | Delete
$this->proxy->call_function( 'wc_doing_it_wrong', $class_and_method, sprintf( __( '%1$s should not be called before the %2$s action.', 'woocommerce' ), $class_and_method, 'woocommerce_init' ), '7.0' );
[1101] Fix | Delete
}
[1102] Fix | Delete
return false;
[1103] Fix | Delete
}
[1104] Fix | Delete
[1105] Fix | Delete
return true;
[1106] Fix | Delete
}
[1107] Fix | Delete
[1108] Fix | Delete
/**
[1109] Fix | Delete
* Get the name of the option that enables/disables a given feature.
[1110] Fix | Delete
*
[1111] Fix | Delete
* Note that it doesn't check if the feature actually exists. Instead it
[1112] Fix | Delete
* defaults to "woocommerce_feature_{$feature_id}_enabled" if a different
[1113] Fix | Delete
* name isn't specified in the feature registration.
[1114] Fix | Delete
*
[1115] Fix | Delete
* @param string $feature_id The id of the feature.
[1116] Fix | Delete
* @return string The option that enables or disables the feature.
[1117] Fix | Delete
*/
[1118] Fix | Delete
public function feature_enable_option_name( string $feature_id ): string {
[1119] Fix | Delete
$features = $this->get_feature_definitions();
[1120] Fix | Delete
[1121] Fix | Delete
if ( ! empty( $features[ $feature_id ]['option_key'] ) ) {
[1122] Fix | Delete
return $features[ $feature_id ]['option_key'];
[1123] Fix | Delete
}
[1124] Fix | Delete
[1125] Fix | Delete
return "woocommerce_feature_{$feature_id}_enabled";
[1126] Fix | Delete
}
[1127] Fix | Delete
[1128] Fix | Delete
/**
[1129] Fix | Delete
* Check if the compatibility checks should be skipped for a given feature.
[1130] Fix | Delete
*
[1131] Fix | Delete
* @since 10.3.0
[1132] Fix | Delete
*
[1133] Fix | Delete
* @param string $feature_id The feature id to check.
[1134] Fix | Delete
* @return bool TRUE if the compatibility checks should be skipped.
[1135] Fix | Delete
*/
[1136] Fix | Delete
public function should_skip_compatibility_checks( string $feature_id ): bool {
[1137] Fix | Delete
$features = $this->get_feature_definitions();
[1138] Fix | Delete
[1139] Fix | Delete
return ! empty( $features[ $feature_id ]['skip_compatibility_checks'] );
[1140] Fix | Delete
}
[1141] Fix | Delete
[1142] Fix | Delete
/**
[1143] Fix | Delete
* Sets a flag indicating that it's allowed to enable features for which incompatible plugins are active
[1144] Fix | Delete
* from the WooCommerce feature settings page.
[1145] Fix | Delete
*/
[1146] Fix | Delete
public function allow_enabling_features_with_incompatible_plugins(): void {
[1147] Fix | Delete
$this->force_allow_enabling_features = true;
[1148] Fix | Delete
}
[1149] Fix | Delete
[1150] Fix | Delete
/**
[1151] Fix | Delete
* Sets a flag indicating that it's allowed to activate plugins for which incompatible features are enabled
[1152] Fix | Delete
* from the WordPress plugins page.
[1153] Fix | Delete
*/
[1154] Fix | Delete
public function allow_activating_plugins_with_incompatible_features(): void {
[1155] Fix | Delete
$this->force_allow_enabling_plugins = true;
[1156] Fix | Delete
}
[1157] Fix | Delete
[1158] Fix | Delete
/**
[1159] Fix | Delete
* Adds our callbacks for the `updated_option` and `added_option` filter hooks.
[1160] Fix | Delete
*
[1161] Fix | Delete
* We delay adding these hooks until `init`, because both callbacks need to load our list of feature definitions,
[1162] Fix | Delete
* and building that list requires translating various strings (which should not be done earlier than `init`).
[1163] Fix | Delete
*
[1164] Fix | Delete
* @return void
[1165] Fix | Delete
*
[1166] Fix | Delete
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
[1167] Fix | Delete
*/
[1168] Fix | Delete
public function start_listening_for_option_changes(): void {
[1169] Fix | Delete
add_filter( 'updated_option', array( $this, 'process_updated_option' ), 999, 3 );
[1170] Fix | Delete
add_filter( 'added_option', array( $this, 'process_added_option' ), 999, 3 );
[1171] Fix | Delete
}
[1172] Fix | Delete
[1173] Fix | Delete
/**
[1174] Fix | Delete
* Handler for the 'added_option' hook.
[1175] Fix | Delete
*
[1176] Fix | Delete
* It fires FEATURE_ENABLED_CHANGED_ACTION when a feature is enabled or disabled.
[1177] Fix | Delete
*
[1178] Fix | Delete
* @param string $option The option that has been created.
[1179] Fix | Delete
* @param mixed $value The value of the option.
[1180] Fix | Delete
*
[1181] Fix | Delete
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
[1182] Fix | Delete
*/
[1183] Fix | Delete
public function process_added_option( string $option, $value ) {
[1184] Fix | Delete
$this->process_updated_option( $option, false, $value );
[1185] Fix | Delete
}
[1186] Fix | Delete
[1187] Fix | Delete
/**
[1188] Fix | Delete
* Handler for the 'updated_option' hook.
[1189] Fix | Delete
*
[1190] Fix | Delete
* It fires FEATURE_ENABLED_CHANGED_ACTION when a feature is enabled or disabled.
[1191] Fix | Delete
*
[1192] Fix | Delete
* @param string $option The option that has been modified.
[1193] Fix | Delete
* @param mixed $old_value The old value of the option.
[1194] Fix | Delete
* @param mixed $value The new value of the option.
[1195] Fix | Delete
*
[1196] Fix | Delete
* @return void
[1197] Fix | Delete
*
[1198] Fix | Delete
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
[1199] Fix | Delete
*/
[1200] Fix | Delete
public function process_updated_option( string $option, $old_value, $value ) {
[1201] Fix | Delete
$matches = array();
[1202] Fix | Delete
$is_default_key = preg_match( '/^woocommerce_feature_([a-zA-Z0-9_]+)_enabled$/', $option, $matches );
[1203] Fix | Delete
$features_with_custom_keys = array_filter(
[1204] Fix | Delete
$this->get_feature_definitions(),
[1205] Fix | Delete
function ( $feature ) {
[1206] Fix | Delete
return ! empty( $feature['option_key'] );
[1207] Fix | Delete
}
[1208] Fix | Delete
);
[1209] Fix | Delete
$custom_keys = wp_list_pluck( $features_with_custom_keys, 'option_key' );
[1210] Fix | Delete
[1211] Fix | Delete
if ( ! $is_default_key && ! in_array( $option, $custom_keys, true ) ) {
[1212] Fix | Delete
return;
[1213] Fix | Delete
}
[1214] Fix | Delete
[1215] Fix | Delete
if ( $value === $old_value ) {
[1216] Fix | Delete
return;
[1217] Fix | Delete
}
[1218] Fix | Delete
[1219] Fix | Delete
$feature_id = '';
[1220] Fix | Delete
if ( $is_default_key ) {
[1221] Fix | Delete
$feature_id = $matches[1];
[1222] Fix | Delete
} elseif ( in_array( $option, $custom_keys, true ) ) {
[1223] Fix | Delete
$feature_id = array_search( $option, $custom_keys, true );
[1224] Fix | Delete
}
[1225] Fix | Delete
[1226] Fix | Delete
if ( ! $feature_id ) {
[1227] Fix | Delete
return;
[1228] Fix | Delete
}
[1229] Fix | Delete
[1230] Fix | Delete
WC_Tracks::record_event(
[1231] Fix | Delete
self::FEATURE_ENABLED_CHANGED_ACTION,
[1232] Fix | Delete
array(
[1233] Fix | Delete
'feature_id' => $feature_id,
[1234] Fix | Delete
'enabled' => $value,
[1235] Fix | Delete
)
[1236] Fix | Delete
);
[1237] Fix | Delete
[1238] Fix | Delete
/**
[1239] Fix | Delete
* Action triggered when a feature is enabled or disabled (the value of the corresponding setting option is changed).
[1240] Fix | Delete
*
[1241] Fix | Delete
* @param string $feature_id The id of the feature.
[1242] Fix | Delete
* @param bool $enabled True if the feature has been enabled, false if it has been disabled.
[1243] Fix | Delete
*
[1244] Fix | Delete
* @since 7.0.0
[1245] Fix | Delete
*/
[1246] Fix | Delete
do_action( self::FEATURE_ENABLED_CHANGED_ACTION, $feature_id, 'yes' === $value );
[1247] Fix | Delete
}
[1248] Fix | Delete
[1249] Fix | Delete
/**
[1250] Fix | Delete
* Handler for the 'woocommerce_get_sections_advanced' hook,
[1251] Fix | Delete
* it adds the "Features" section to the advanced settings page.
[1252] Fix | Delete
*
[1253] Fix | Delete
* @param array $sections The original sections array.
[1254] Fix | Delete
* @return array The updated sections array.
[1255] Fix | Delete
*
[1256] Fix | Delete
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
[1257] Fix | Delete
*/
[1258] Fix | Delete
public function add_features_section( $sections ) {
[1259] Fix | Delete
if ( ! isset( $sections['features'] ) ) {
[1260] Fix | Delete
$sections['features'] = __( 'Features', 'woocommerce' );
[1261] Fix | Delete
}
[1262] Fix | Delete
return $sections;
[1263] Fix | Delete
}
[1264] Fix | Delete
[1265] Fix | Delete
/**
[1266] Fix | Delete
* Handler for the 'woocommerce_get_settings_advanced' hook,
[1267] Fix | Delete
* it adds the settings UI for all the existing features.
[1268] Fix | Delete
*
[1269] Fix | Delete
* Note that the settings added via the 'woocommerce_settings_features' hook will be
[1270] Fix | Delete
* displayed in the non-experimental features section.
[1271] Fix | Delete
*
[1272] Fix | Delete
* @param array $settings The existing settings for the corresponding settings section.
[1273] Fix | Delete
* @param string $current_section The section to get the settings for.
[1274] Fix | Delete
* @return array The updated settings array.
[1275] Fix | Delete
*
[1276] Fix | Delete
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
[1277] Fix | Delete
*/
[1278] Fix | Delete
public function add_feature_settings( $settings, $current_section ): array {
[1279] Fix | Delete
if ( 'features' !== $current_section ) {
[1280] Fix | Delete
return $settings;
[1281] Fix | Delete
}
[1282] Fix | Delete
[1283] Fix | Delete
$feature_settings = array(
[1284] Fix | Delete
array(
[1285] Fix | Delete
'title' => __( 'Features', 'woocommerce' ),
[1286] Fix | Delete
'type' => 'title',
[1287] Fix | Delete
'desc' => __( 'Start using new features that are being progressively rolled out to improve the store management experience.', 'woocommerce' ),
[1288] Fix | Delete
'id' => 'features_options',
[1289] Fix | Delete
),
[1290] Fix | Delete
);
[1291] Fix | Delete
[1292] Fix | Delete
$features = $this->get_features( true );
[1293] Fix | Delete
[1294] Fix | Delete
$feature_ids = array_keys( $features );
[1295] Fix | Delete
usort(
[1296] Fix | Delete
$feature_ids,
[1297] Fix | Delete
function ( $feature_id_a, $feature_id_b ) use ( $features ) {
[1298] Fix | Delete
return ( $features[ $feature_id_b ]['order'] ?? 0 ) <=> ( $features[ $feature_id_a ]['order'] ?? 0 );
[1299] Fix | Delete
}
[1300] Fix | Delete
);
[1301] Fix | Delete
$experimental_feature_ids = array_filter(
[1302] Fix | Delete
$feature_ids,
[1303] Fix | Delete
function ( $feature_id ) use ( $features ) {
[1304] Fix | Delete
return $features[ $feature_id ]['is_experimental'] ?? false;
[1305] Fix | Delete
}
[1306] Fix | Delete
);
[1307] Fix | Delete
$mature_feature_ids = array_diff( $feature_ids, $experimental_feature_ids );
[1308] Fix | Delete
$feature_ids = array_merge( $mature_feature_ids, array( 'mature_features_end' ), $experimental_feature_ids );
[1309] Fix | Delete
[1310] Fix | Delete
foreach ( $feature_ids as $id ) {
[1311] Fix | Delete
if ( 'mature_features_end' === $id ) {
[1312] Fix | Delete
// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
[1313] Fix | Delete
/**
[1314] Fix | Delete
* Filter allowing to add additional settings to the WooCommerce Advanced - Features settings page.
[1315] Fix | Delete
*
[1316] Fix | Delete
* @param bool $disabled False.
[1317] Fix | Delete
*/
[1318] Fix | Delete
$feature_settings = apply_filters( 'woocommerce_settings_features', $feature_settings );
[1319] Fix | Delete
// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment
[1320] Fix | Delete
[1321] Fix | Delete
if ( ! empty( $experimental_feature_ids ) ) {
[1322] Fix | Delete
$feature_settings[] = array(
[1323] Fix | Delete
'type' => 'sectionend',
[1324] Fix | Delete
'id' => 'features_options',
[1325] Fix | Delete
);
[1326] Fix | Delete
[1327] Fix | Delete
$feature_settings[] = array(
[1328] Fix | Delete
'title' => __( 'Experimental features', 'woocommerce' ),
[1329] Fix | Delete
'type' => 'title',
[1330] Fix | Delete
'desc' => __( 'These features are either experimental or incomplete, enable them at your own risk!', 'woocommerce' ),
[1331] Fix | Delete
'id' => 'experimental_features_options',
[1332] Fix | Delete
);
[1333] Fix | Delete
}
[1334] Fix | Delete
continue;
[1335] Fix | Delete
}
[1336] Fix | Delete
[1337] Fix | Delete
if ( 'new_navigation' === $id && 'yes' !== get_option( $this->feature_enable_option_name( $id ), 'no' ) ) {
[1338] Fix | Delete
continue;
[1339] Fix | Delete
}
[1340] Fix | Delete
[1341] Fix | Delete
if ( isset( $features[ $id ]['disable_ui'] ) && $features[ $id ]['disable_ui'] ) {
[1342] Fix | Delete
continue;
[1343] Fix | Delete
}
[1344] Fix | Delete
[1345] Fix | Delete
$feature_settings[] = $this->get_setting_for_feature( $id, $features[ $id ] );
[1346] Fix | Delete
[1347] Fix | Delete
$additional_settings = $features[ $id ]['additional_settings'] ?? array();
[1348] Fix | Delete
if ( count( $additional_settings ) > 0 ) {
[1349] Fix | Delete
$feature_settings = array_merge( $feature_settings, $additional_settings );
[1350] Fix | Delete
}
[1351] Fix | Delete
}
[1352] Fix | Delete
[1353] Fix | Delete
$feature_settings[] = array(
[1354] Fix | Delete
'type' => 'sectionend',
[1355] Fix | Delete
'id' => empty( $experimental_feature_ids ) ? 'features_options' : 'experimental_features_options',
[1356] Fix | Delete
);
[1357] Fix | Delete
[1358] Fix | Delete
if ( $this->verify_did_woocommerce_init() ) {
[1359] Fix | Delete
// Allow feature setting properties to be determined dynamically just before being rendered.
[1360] Fix | Delete
$feature_settings = array_map(
[1361] Fix | Delete
function ( $feature_setting ) {
[1362] Fix | Delete
foreach ( $feature_setting as $prop => $value ) {
[1363] Fix | Delete
if ( is_callable( $value ) ) {
[1364] Fix | Delete
$feature_setting[ $prop ] = call_user_func( $value );
[1365] Fix | Delete
}
[1366] Fix | Delete
}
[1367] Fix | Delete
[1368] Fix | Delete
return $feature_setting;
[1369] Fix | Delete
},
[1370] Fix | Delete
$feature_settings
[1371] Fix | Delete
);
[1372] Fix | Delete
}
[1373] Fix | Delete
[1374] Fix | Delete
return $feature_settings;
[1375] Fix | Delete
}
[1376] Fix | Delete
[1377] Fix | Delete
/**
[1378] Fix | Delete
* Get the parameters to display the setting enable/disable UI for a given feature.
[1379] Fix | Delete
*
[1380] Fix | Delete
* @param string $feature_id The feature id.
[1381] Fix | Delete
* @param array $feature The feature parameters, as returned by get_features.
[1382] Fix | Delete
* @return array The parameters to add to the settings array.
[1383] Fix | Delete
*/
[1384] Fix | Delete
private function get_setting_for_feature( string $feature_id, array $feature ): array {
[1385] Fix | Delete
$description = $feature['description'] ?? '';
[1386] Fix | Delete
$disabled = false;
[1387] Fix | Delete
$desc_tip = '';
[1388] Fix | Delete
$tooltip = $feature['tooltip'] ?? '';
[1389] Fix | Delete
$type = $feature['type'] ?? 'checkbox';
[1390] Fix | Delete
$setting_definition = $feature['setting'] ?? array();
[1391] Fix | Delete
[1392] Fix | Delete
// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
[1393] Fix | Delete
/**
[1394] Fix | Delete
* Filter allowing WooCommerce Admin to be disabled.
[1395] Fix | Delete
*
[1396] Fix | Delete
* @param bool $disabled False.
[1397] Fix | Delete
*/
[1398] Fix | Delete
$admin_features_disabled = apply_filters( 'woocommerce_admin_disabled', false );
[1399] Fix | Delete
// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment
[1400] Fix | Delete
[1401] Fix | Delete
if ( ( 'analytics' === $feature_id || 'new_navigation' === $feature_id ) && $admin_features_disabled ) {
[1402] Fix | Delete
$disabled = true;
[1403] Fix | Delete
$desc_tip = __( 'WooCommerce Admin has been disabled', 'woocommerce' );
[1404] Fix | Delete
} elseif ( 'new_navigation' === $feature_id ) {
[1405] Fix | Delete
$update_text = sprintf(
[1406] Fix | Delete
// translators: 1: line break tag.
[1407] Fix | Delete
__(
[1408] Fix | Delete
'%1$s This navigation will soon become unavailable while we make necessary improvements.
[1409] Fix | Delete
If you turn it off now, you will not be able to turn it back on.',
[1410] Fix | Delete
'woocommerce'
[1411] Fix | Delete
),
[1412] Fix | Delete
'<br/>'
[1413] Fix | Delete
);
[1414] Fix | Delete
[1415] Fix | Delete
$needs_update = version_compare( get_bloginfo( 'version' ), '5.6', '<' );
[1416] Fix | Delete
if ( $needs_update && current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
[1417] Fix | Delete
$update_text = sprintf(
[1418] Fix | Delete
// translators: 1: line break tag, 2: open link to WordPress update link, 3: close link tag.
[1419] Fix | Delete
__( '%1$s %2$sUpdate WordPress to enable the new navigation%3$s', 'woocommerce' ),
[1420] Fix | Delete
'<br/>',
[1421] Fix | Delete
'<a href="' . self_admin_url( 'update-core.php' ) . '" target="_blank">',
[1422] Fix | Delete
'</a>'
[1423] Fix | Delete
);
[1424] Fix | Delete
$disabled = true;
[1425] Fix | Delete
}
[1426] Fix | Delete
[1427] Fix | Delete
if ( ! empty( $update_text ) ) {
[1428] Fix | Delete
$description .= $update_text;
[1429] Fix | Delete
}
[1430] Fix | Delete
}
[1431] Fix | Delete
[1432] Fix | Delete
if ( ! $this->should_skip_compatibility_checks( $feature_id ) && ! $disabled && $this->verify_did_woocommerce_init() ) {
[1433] Fix | Delete
$plugin_info_for_feature = $this->get_compatible_plugins_for_feature( $feature_id, true );
[1434] Fix | Delete
$desc_tip = $this->plugin_util->generate_incompatible_plugin_feature_warning( $feature_id, $plugin_info_for_feature );
[1435] Fix | Delete
}
[1436] Fix | Delete
[1437] Fix | Delete
/**
[1438] Fix | Delete
* Filter to customize the description tip that appears under the description of each feature in the features settings page.
[1439] Fix | Delete
*
[1440] Fix | Delete
* @since 7.1.0
[1441] Fix | Delete
*
[1442] Fix | Delete
* @param string $desc_tip The original description tip.
[1443] Fix | Delete
* @param string $feature_id The id of the feature for which the description tip is being customized.
[1444] Fix | Delete
* @param bool $disabled True if the UI currently prevents changing the enable/disable status of the feature.
[1445] Fix | Delete
* @return string The new description tip to use.
[1446] Fix | Delete
*/
[1447] Fix | Delete
$desc_tip = apply_filters( 'woocommerce_feature_description_tip', $desc_tip, $feature_id, $disabled );
[1448] Fix | Delete
[1449] Fix | Delete
$feature_setting_defaults = array(
[1450] Fix | Delete
'title' => $feature['name'],
[1451] Fix | Delete
'desc' => $description,
[1452] Fix | Delete
'type' => $type,
[1453] Fix | Delete
'id' => $this->feature_enable_option_name( $feature_id ),
[1454] Fix | Delete
'disabled' => $disabled && ! $this->force_allow_enabling_features,
[1455] Fix | Delete
'desc_tip' => $desc_tip,
[1456] Fix | Delete
'tooltip' => $tooltip,
[1457] Fix | Delete
'default' => $this->feature_is_enabled_by_default( $feature_id ) ? 'yes' : 'no',
[1458] Fix | Delete
);
[1459] Fix | Delete
[1460] Fix | Delete
$feature_setting = wp_parse_args( $setting_definition, $feature_setting_defaults );
[1461] Fix | Delete
[1462] Fix | Delete
if ( ! empty( $feature['learn_more_url'] ) ) {
[1463] Fix | Delete
$feature_setting['desc'] .= sprintf(
[1464] Fix | Delete
'<span class="learn-more-link"><a href="%s" target="_blank">%s</a></span>',
[1465] Fix | Delete
esc_attr( $feature['learn_more_url'] ),
[1466] Fix | Delete
esc_html__( 'Learn more', 'woocommerce' )
[1467] Fix | Delete
);
[1468] Fix | Delete
}
[1469] Fix | Delete
[1470] Fix | Delete
/**
[1471] Fix | Delete
* Allows to modify feature setting that will be used to render in the feature page.
[1472] Fix | Delete
*
[1473] Fix | Delete
* @param array $feature_setting The feature setting. Describes the feature:
[1474] Fix | Delete
* - title: The title of the feature.
[1475] Fix | Delete
* - desc: The description of the feature. Will be displayed under the title.
[1476] Fix | Delete
* - type: The type of the feature. Could be any of supported settings types from `WC_Admin_Settings::output_fields`, but if it's anything other than checkbox or radio, it will need custom handling.
[1477] Fix | Delete
* - id: The id of the feature. Will be used as the name of the setting.
[1478] Fix | Delete
* - disabled: Whether the feature is disabled or not.
[1479] Fix | Delete
* - desc_tip: The description tip of the feature. Will be displayed as a tooltip next to the description.
[1480] Fix | Delete
* - tooltip: The tooltip of the feature. Will be displayed as a tooltip next to the name.
[1481] Fix | Delete
* - default: The default value of the feature.
[1482] Fix | Delete
* @param string $feature_id The id of the feature.
[1483] Fix | Delete
* @since 8.0.0
[1484] Fix | Delete
*/
[1485] Fix | Delete
return apply_filters( 'woocommerce_feature_setting', $feature_setting, $feature_id );
[1486] Fix | Delete
}
[1487] Fix | Delete
[1488] Fix | Delete
/**
[1489] Fix | Delete
* Handle the plugin deactivation hook.
[1490] Fix | Delete
*
[1491] Fix | Delete
* @param string $plugin_name Name of the plugin that has been deactivated.
[1492] Fix | Delete
*
[1493] Fix | Delete
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
[1494] Fix | Delete
*/
[1495] Fix | Delete
public function handle_plugin_deactivation( $plugin_name ): void {
[1496] Fix | Delete
unset( $this->compatibility_info_by_plugin[ $plugin_name ] );
[1497] Fix | Delete
[1498] Fix | Delete
foreach ( array_keys( $this->compatibility_info_by_feature ) as $feature ) {
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function