actions();
}
/**
*
*/
public function actions() {
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_menu', array( $this, 'register_settings_page' ) );
}
/**
* Register settings
*/
public function register_settings() {
$this->settings_api = new WeDevs_Settings_API();
//set sections and fields
$this->settings_api->set_sections( $this->get_settings_sections() );
$this->settings_api->set_fields( $this->get_settings_fields() );
//initialize them
$this->settings_api->admin_init();
}
/**
*
*/
public function register_settings_page() {
add_options_page( __( 'StockPack', 'stockpack' ), __( 'StockPack', 'stockpack' ), 'delete_posts', 'stockpack',
array( $this, 'plugin_page' )
);
}
/**
*
*/
public function plugin_page() {
echo '
';
$this->settings_api->show_navigation();
$this->settings_api->show_forms();
$link_text = esc_textarea( __( 'Get your license key', 'stockpack' ) );
echo '
' . $link_text . '';
echo '
';
}
public function get_license_state() {
return $this->get_option( 'license_state', 'stockpack_basics' );
}
public function get_safe_search() {
return $this->get_option( 'safe_search', 'stockpack_basics' );
}
/**
* @return mixed
*/
public function get_api_key() {
return $this->get_option( 'auth_token', 'stockpack_basics' );
}
/**
* @return mixed
*/
public function set_api_key( $token ) {
return $this->set_option( 'auth_token', 'stockpack_basics', $token );
}
/**
* @return array
*/
private function get_settings_sections() {
return array(
array(
'id' => 'stockpack_basics',
'title' => __( 'StockPack', 'stockpack' ),
),
);
}
/**
* @return array
*/
private function get_settings_fields() {
return array(
'stockpack_basics' => array(
array(
'name' => 'auth_token',
'label' => __( 'License key', 'stockpack' ),
'desc' => __( 'This is the license key that is used for authentication', 'stockpack' ),
'type' => 'text',
'default' => '',
'size' => 'validate-stockpack-key regular' //small hack to add class
),
array(
'name' => 'license_state',
'label' => __( 'Search with authorization', 'stockpack' ),
'desc' => __( 'Providers that support oauth can get the license state for all images directly. You see it in the sidebar. The downside is that the searches are slower', 'stockpack' ),
'options' => array(
'yes' => __( 'Yes', 'stockpack' ),
'no' => __( 'No', 'stockpack' )
),
'type' => 'radio',
'default' => 'no',
),
array(
'name' => 'safe_search',
'label' => __( 'Apply safe search', 'stockpack' ),
'desc' => __( 'Some providers support this mode to prevent nude images to show up in the search', 'stockpack' ),
'options' => array(
'yes' => __( 'Yes', 'stockpack' ),
'no' => __( 'No', 'stockpack' )
),
'type' => 'radio',
'default' => 'yes',
),
),
);
}
/**
* Get the value of a settings field
*
* @param string $option settings field name
* @param string $section the section name this field belongs to
* @param string $default default text if it's not found
*
* @return mixed
*/
private function get_option( $option, $section, $default = '' ) {
$options = get_option( $section, array() );
if ( isset( $options[ $option ] ) ) {
return $options[ $option ];
}
return $default;
}
/**
* Set the value of a settings field
*
* @param string $option settings field name
* @param string $section the section name this field belongs to
* @param string $value
*
* @return mixed
*/
private function set_option( $option, $section, $value ) {
$options = get_option( $section, array() );
if ( ! is_array( $options ) ) {
$options = array();
}
$options[ $option ] = $value;
update_option( $section, $options );
}
}