What’s so special about Premise WP?

Aside form being Open Source, Premise WP is maintained by a group of developers that build beautiful things for the web every day leveraging the power of WordPress. Put quite literally, it helps us build s**t faster and we thought we should share it.

Full disclosure – There is no user interface. When you install Premise WP on your WordPress site you will not see
a UI, settings page, or any sort of GUI.
That’s because Premise WP has no settings, it is merely a library of functions and classes that make your live easier as a developer. Below are some examples on when Premise WP is a big timesaver.

Saving data and retrieving it

This is probably the biggest time saver for us when we build our own projects. Premise comes with two functions you should know premise_field() and premise_get_value(). These two functions alone will save you tons of time! Lets see how..

When building options in the backend of WordPress we need to output field elements to save our options, duh! That’s exactly what premise_field() does – it outputs form elements for us but in doing so it takes care of a lot of the logic that goes on when retrieving the data saved, setting defaults, or adding advanced fields like to upload media. Here are some different use cases for premise_field().

<?php 
/**
 * media field that takes mutliple images and shows preview of them
 */
premise_field( 'wp_media', array(
	'multiple' => true,
	'preview' => true,
	'name' => 'premise_options[media]',
) );

/**
 * text field used on a post
 */
premise_field( 'text', array(
	'name' => 'premise_options[text]',
	'default' => 'Insert default value',
	'context' => 'post', 
) );

/**
 * select field used in a user profile
 */
premise_field( 'select', array(
	'name' => 'premise_options[text]',
	'options' => array(
		'Text for option1' => ' Value for option1',
		'Text for option2' => ' Value for option2',
		'Text for option3' => ' Value for option3',
	),
	'context' => 'user', 
) );
?>

To learn more about how to use premise_field() take a look at this article.

When retrieving these options from the front end of our theme or plugin we use premise_get_value(). This function is basically a wrapper function to get_option(), get_post_meta(), and/or get_user_meta(). it used by premise_field() when retrieving the value for each of your fields. If you save your data serialized under one option (which you should always do when possible IMO) this function will come in handy! You can pass the name attribute of the field that you want to retreive and premise_get_value() will look through your serialized and retrieve only the value you need.

So for example if I want to get the value of a field with the name attribute name="premise_options[level1][level2][key]", premise_get_value() will return the value of key out your serialized data by simply calling it like this premise_get_value( 'premise_options[level1][level2][key]' ).

My alternative with WordPress built in function would be something like this:

<?php 
$key = '';
$my_serialized_data = get_option( 'premise_options' );
if ( $my_serialized_data &&; is_array( $my_serialized_data ) ) {
    $key = isset( $my_serialized_data['level1']['level2']['key'] ) ? $my_serialized_data['level1']['level2']['key'] : '';
}
?>