'checkbox', 'helptext' => __( 'Display AppPresser in mobile browsers such as Safari and Chrome, instead of your normal theme.', 'apppresser' ) ) );
}
self::add_setting( 'admin_theme_switch', __( 'Load AppPresser for Admins Only', 'apppresser' ), array( 'type' => 'checkbox', 'helptext' => __( 'Check this if you want to test your AppPresser app without loading it for visitors to your site.', 'apppresser' ), 'description' => __( '(for testing purposes)', 'apppresser' ) ) );
self::add_setting( 'appp_theme', __( 'App only theme', 'apppresser' ), array( 'type' => 'select', 'options' => $this->themes, 'helptext' => __( 'Select which theme you want to be loaded inside the app, such as the AppPresser theme.', 'apppresser' ), 'description' => __( 'must be enabled above', 'apppresser' ) ) );
self::add_setting( 'appp_home_page', __( 'Use a unique homepage for your app.', 'apppresser' ), array( 'helptext' => __( 'Allows you to specify which page users will see first when they load up you AppPresser app.', 'apppresser' ), 'description' => __( 'Start typing to search for a page', 'apppresser' ) ) );
$menus = array( 'option-none' => __( '-- select --', 'apppresser' ) );
foreach ( (array) $this->nav_menus as $menu ) {
$menus[ $menu->term_id ] = $menu->name;
}
// Register main menu setting
self::add_setting( 'menu', __( 'Main App Menu', 'apppresser' ), array( 'type' => 'select', 'options' => $menus, 'helptext' => __( 'Use a custom main menu inside your app, different from your main site.', '' ) ) );
// Register secondary menu setting
self::add_setting( 'secondary_menu', __( 'Secondary App Menu', 'apppresser' ), array( 'type' => 'select', 'options' => $menus, 'helptext' => __( 'Use a custom secondary menu inside your app (the top right dropdown in the header).', 'apppresser' ) ) );
add_action( 'apppresser_tab_buttons_general', array( $this, 'help_link' ) );
}
/**
* Add a link to the help page in the main settings tab
* @since 1.0.0
*/
public function help_link() {
echo ''. __( 'Help/Support', 'apppresser' ) .'';
}
/**
* Add ajax spinner/results container to homepage selector field
* @since 1.0.0
* @param string $html Input html
* @param string $key Option field key
* @return string Modified input html
*/
public function ajax_container( $html, $key ) {
if ( $key === 'appp_home_page' ) {
$html .= '
', $class, $notice );
break;
case 'h3':
break;
default:
// Filter allows devs to add their own field types
$field .= sprintf( ''."\n", $key, $key, self::settings( $key ) );
break;
}
if ( trim( $args['description'] ) && ! in_array( $type, array( 'h3', 'checkbox' ) ) ) {
$field .= '
'. trim( $args['description'] ) .'
';
}
// Filter allows devs to add their own field types
$field = apply_filters( "apppresser_field_markup_$type", $field, $key, self::settings( $key ), $args, self::run() );
if ( $type !== 'h3' )
$field .= '
';
$_field = $_field . $field .'
';
if ( $args['echo'] ) {
echo $_field;
self::$all_fields['echoed'][ $key ] = $_field;
} else {
self::$all_fields[ $args['tab'] ][ $key ] = $_field;
}
return $_field;
}
/**
* Add a settings tab to the AppPresser Settings Page
* @since 1.0.0
* @param string $label Tab label
* @param string $slug Tab slug (optional)
*/
public static function add_setting_tab( $label, $slug = '' ) {
self::$admin_tabs[ $slug ? $slug : sanitize_html_class( $label ) ] = $label;
}
/**
* Adds a setting section title to AppPresser's settings.
* @since 1.0.0
* @param string $label Title
* @param array $options Array of possible options
*/
public static function add_setting_label( $title, $args = array() ) {
self::add_setting( sanitize_title( $title ), $title, wp_parse_args( $args, array( 'type' => 'h3' ) ) );
}
public static function license_keys() {
if ( empty( self::$license_keys ) )
self::$license_keys = apply_filters( 'apppresser_license_keys_to_check', self::$license_keys, self::run() );
return self::$license_keys;
}
/**
* Handles our ajax page search
* @since 1.0.0
*/
public function ajax_post_results() {
// verify our nonce
if ( ! ( isset( $_REQUEST['nonce'], $_REQUEST['page_title'] ) && wp_verify_nonce( $_REQUEST['nonce'], 'appp_settings_group-options' ) ) )
wp_send_json_error( '
'. __( 'security check failed', 'apppresser' ) .'
' );
// sanitize our search string
$search_string = sanitize_text_field( $_REQUEST['page_title'] );
// if there is no search string, bail here
if ( empty( $search_string ) )
wp_send_json_error( '
'. __( 'Please Try Again', 'apppresser' ) .'
' );
global $wpdb;
// Search posts by title wildcard and get IDs
$results = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title LIKE '%%%s%%' AND post_status = 'publish' AND post_type = 'page' LIMIT 10", $search_string ) );
if ( empty( $results ) )
wp_send_json_error( '
'. __('No Results Found', 'apppresser' ) .'
' );
// loop found ids and concatenate post links
$return = '';
foreach ( $results as $post_id ) {
$return .= '