# helper function

Some globally available "helper" PHP functions are included in Blessing Skin and used by Blessing Skin itself; you are free to use them in your plugins if you find it convenient.

[[toc]]

# json

Return a JSON response. Note that you need to manually return the return value of this function in the controller, that is, you need to return json(); in the controller method.

json(['a' => 1, 'b' => 2]);  // {"a":1,"b":2}

json('Hello.', 0, ['a' => 1]);  // {"code":0,"message":"Hello.","data":{"a":1}}

json('Success', 0);  // {"code":0,"message":"Success"}

json('Failed');  // {"code":1,"message":"Failed"}

# option

Returns or sets configuration items stored in the database.

$value = option( 'my_custom_option' ) ;  // Get the value of the option `my_custom_option` 

$value = option( 'my_custom_option' , 'default' ) ;  // If the option does not exist, return `'default'` as the default value 

option([ 'my_custom_option' => 'Yeah' ]) ;  // Set the value of the option `my_custom_option` to `'Yeah'`

# option_localized

function is the same as the optionfunction, but the returned value can be different according to the current locale. When using this function to set different languages to correspond to different values, you need to switch the page to the target language first.

// Assume that the `greeting` option is "你好" in the Chinese environment and "hello" in the English environment 

// en 
option_localized( 'greeting' ) ;  // hello 

// zh_CN 
option_localized( 'greeting' ) ;  // Hello

# plugin

Returns an instance of the specified plugin.

$plugin = plugin( 'example-plugin' ) ;

# plugin_assets

Returns the URL of the plugin resource file.

$url = plugin_assets( 'example-plugin' , 'assets/js/example1.js' ) ;