Skip to content

Commit

Permalink
Allow to add custom preferences to config.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
mleroi committed Jun 8, 2018
1 parent 3c40550 commit 7fb8413
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions wp-appkit/lib/simulator/config-file.php
Expand Up @@ -444,6 +444,20 @@ protected static function get_icons_and_splashscreens_xml( $app_id, $app_platfor
return $app_icons_and_splashscreens_files;
}

protected static function get_custom_preferences( $app_id, $app_platform, $export_type ) {
/**
* 'wpak_config_xml_custom_preferences' filter.
* Allows to add custom preferences to config.xml file.
* (This filters only applies to non PWA exports).
*
* @param array custom preferences to add: array of [ 'name' => 'preferenceName', 'value' => 'preferenceValue' ]
* @param int $app_id Application ID.
* @param string $app_platform App platform (see WpakApps::get_platforms to get the list).
* @param string $export_type Export type.
*/
return apply_filters( 'wpak_config_xml_custom_preferences', [], $app_id, $app_platform, $export_type );
}

public static function get_config_xml( $app_id, $echo = false, $export_type = 'phonegap-build' ) {

$app_main_infos = WpakApps::get_app_main_infos( $app_id );
Expand All @@ -464,6 +478,9 @@ public static function get_config_xml( $app_id, $echo = false, $export_type = 'p
$whitelist_settings = self::get_whitelist_settings( $app_id, $app_platform, $export_type );
$splashscreen_settings = self::get_splashscreen_settings( $app_id, $app_platform, $export_type );

//Custom preferences (added via hook):
$custom_preferences = self::get_custom_preferences( $app_id, $app_platform, $export_type );

//Merge our default Phonegap Build plugins to those set in BO :
$app_phonegap_plugins = WpakApps::get_merged_phonegap_plugins_xml( $app_id, $export_type, $app_main_infos['phonegap_plugins'] );

Expand Down Expand Up @@ -518,6 +535,13 @@ public static function get_config_xml( $app_id, $echo = false, $export_type = 'p
<preference name="webviewbounce" value="false" />
<?php endif ?>

<!-- Custom preferences -->
<?php if( !empty( $custom_preferences ) ) : ?>
<?php foreach( $custom_preferences as $preference ): ?>
<preference name="<?php echo esc_attr( $preference['name'] ); ?>" value="<?php echo esc_attr( $preference['value'] ); ?>" />
<?php endforeach ?>
<?php endif ?>

<!-- PhoneGap plugin declaration -->
<?php if( !empty( $app_phonegap_plugins ) ): ?>
<?php echo str_replace( "\n", "\n\t", $app_phonegap_plugins ) ?>
Expand Down

0 comments on commit 7fb8413

Please sign in to comment.