settings_key_general, array(
'name' => 'Bacon',
'start-with' => 'Bacon ipsum dolor amet',
'querystring-all-custom' => 'all-custom',
'querystring-custom-and-filler' => 'custom-and-filler',
'button-text' => 'Give Me Bacon',
'all-custom-text' => 'All Meat',
'custom-and-filler-text' => 'Meat and Filler',
), '', $autoload = 'no' );
add_option( $this->settings_key_api, array(
'api-enabled' => '0',
'api-endpoint' => 'ipsum-api',
), '', $autoload = 'no' );
add_option( $this->settings_key_api, array(
'oembed-enabled' => '0',
'oembed-endpoint' => 'ipsum-oembed',
), '', $autoload = 'no' );
$custom = '';
$filler = '';
if (class_exists('WPAnyIpsumGenerator')) {
$WPAnyIpsumGenerator = new WPAnyIpsumGenerator();
$custom = implode( "\n", $WPAnyIpsumGenerator->default_custom() );
$filler = implode( "\n", $WPAnyIpsumGenerator->default_filler() );
}
add_option( $this->settings_key_filler, array('custom-words' => $custom, 'filler-words' => $filler), '', $autoload = 'no' );
// add an option so we can show the activated admin notice
add_option( 'anyipsum-plugin-activated', '1' );
}
function activation_admin_notice() {
if ( '1' === get_option( 'anyipsum-plugin-activated' ) ) {
?>
Any Ipsum activated! Please visit the Any Ipsum Settings page to customize your ipsum generator.', 'any-ispum' ), admin_url( 'options-general.php?page=anyipsum-settings' ) );
?>
register_general_settings();
$this->register_filler_settings();
$this->register_api_settings();
$this->register_oembed_settings();
$this->register_help_tab();
}
function register_general_settings() {
$key = $this->settings_key_general;
$this->plugin_settings_tabs[$key] = __('General', 'any-ipsum');
register_setting( $key, $key );
$section = 'general';
add_settings_section( $section, '', array( $this, 'section_header' ), $key );
add_settings_field( 'name', __('Your Ipsum Name', 'any-ipsum'), array( $this, 'settings_input' ), $key, $section,
array('key' => $key, 'name' => 'name', 'size' => 20, 'maxlength' => 50, 'after' => 'Example: Bacon, Hipster, Cupcake, etc'));
add_settings_field( 'all-custom-text', __('All Custom Text', 'any-ipsum'), array( $this, 'settings_input' ), $key, $section,
array('key' => $key, 'name' => 'all-custom-text', 'size' => 20, 'maxlength' => 50, 'after' => 'Example: All Meat, Hipster neat'));
add_settings_field( 'custom-and-filler-text', __('Custom and Filler Text', 'any-ipsum'), array( $this, 'settings_input' ), $key, $section,
array('key' => $key, 'name' => 'custom-and-filler-text', 'size' => 20, 'maxlength' => 50, 'after' => 'Example: Meat and Filler, Hipster with a shot of Latin'));
add_settings_field( 'start-with', __('Start With Text', 'any-ipsum'), array( $this, 'settings_input' ), $key, $section,
array('key' => $key, 'name' => 'start-with', 'size' => 50, 'maxlength' => 50, 'after' => 'Example: Bacon ipsum dolor sit amet'));
add_settings_field( 'button-text', __('Button Text', 'any-ipsum'), array( $this, 'settings_input' ), $key, $section,
array('key' => $key, 'name' => 'button-text', 'size' => 50, 'maxlength' => 50, 'after' => 'Example: Give me bacon, Beer me!, etc.'));
add_settings_field( 'querystring-all-custom', __('Querystring for All Custom', 'any-ipsum'), array( $this, 'settings_input' ), $key, $section,
array('key' => $key, 'name' => 'querystring-all-custom', 'size' => 50, 'maxlength' => 50, 'after' => 'In case you want something different (like all-meat, hipster-centric, etc.)'));
add_settings_field( 'querystring-custom-and-filler', __('Querystring for Custom and Filler', 'any-ipsum'), array( $this, 'settings_input' ), $key, $section,
array('key' => $key, 'name' => 'querystring-custom-and-filler', 'size' => 50, 'maxlength' => 50, 'after' => 'In case you want something different (like meat-and-filler, hipster-latin, etc.)'));
}
function register_filler_settings() {
$key = $this->settings_key_filler;
$this->plugin_settings_tabs[$key] = __('Custom and Filler', 'any-ipsum');
register_setting( $key, $key );
$section = 'custom-and-filler';
add_settings_section( $section, '', array( $this, 'section_header' ), $key );
add_settings_field( 'custom-words', __('Custom Words', 'any-ipsum'), array( $this, 'settings_textarea' ), $key, $section,
array('key' => $key, 'name' => 'custom-words', 'rows' => 10, 'cols' => 40, 'after' => 'One word, phrase, or sentence per line'));
add_settings_field( 'filler-words', __('Filler Words', 'any-ipsum'), array( $this, 'settings_textarea' ), $key, $section,
array('key' => $key, 'name' => 'filler-words', 'rows' => 10, 'cols' => 40, 'after' => 'One word/phrase per line'));
add_settings_field( 'sentence-mode', __('Sentence Mode', 'any-ipsum'), array( $this, 'settings_yes_no' ), $key, $section,
array('key' => $key, 'name' => 'sentence-mode', 'after' => __('The custom words above are sentences instead of words. Disables automatic punctuation.') ));
}
function register_api_settings() {
$key = $this->settings_key_api;
$this->plugin_settings_tabs[$key] = __('API', 'any-ipsum');
register_setting( $key, $key );
$section = 'api';
add_settings_section( $section, '', array( $this, 'section_header' ), $key );
add_settings_field( 'api-enabled', __('Enabled', 'any-ipsum'), array( $this, 'settings_yes_no' ), $key, $section,
array('key' => $key, 'name' => 'api-enabled'));
$permalink_structure = get_option( 'permalink_structure' );
$permalink_warning = empty($permalink_structure) ? ' (please anable any non-default Permalink structure)' : '';
add_settings_field( 'api-endpoint', __('Endpoint Page Name', 'any-ipsum'), array( $this, 'settings_input' ), $key, $section,
array('key' => $key, 'name' => 'api-endpoint', 'size' => 20, 'maxlength' => 50, 'after' => 'Example: api, ipsum-api, etc' . $permalink_warning));
}
function register_oembed_settings() {
$key = $this->settings_key_oembed;
$this->plugin_settings_tabs[$key] = __('oEmbed', 'any-ipsum');
register_setting( $key, $key );
$section = 'oembed';
add_settings_section( $section, '', array( $this, 'section_header' ), $key );
add_settings_field( 'oembed-enabled', __('Enabled', 'any-ipsum'), array( $this, 'settings_yes_no' ), $key, $section,
array('key' => $key, 'name' => 'oembed-enabled'));
$permalink_structure = get_option( 'permalink_structure' );
$permalink_warning = empty($permalink_structure) ? ' (please anable any non-default Permalink structure)' : '';
add_settings_field( 'oembed-endpoint', __('oEmbed Page Name', 'any-ipsum'), array( $this, 'settings_input' ), $key, $section,
array('key' => $key, 'name' => 'oembed-endpoint', 'size' => 20, 'maxlength' => 50, 'after' => 'Example: oembed, ipsum-oembed' . $permalink_warning));
}
function register_help_tab() {
$key = $this->settings_key_help;
$this->plugin_settings_tabs[$key] = __('Help', 'any-ipsum');
register_setting( $key, $key );
$section = 'help';
add_settings_section( $section, '', array( $this, 'section_header' ), $key );
}
function setting_is_enabled($enabled, $key, $setting) {
return '1' === $this->setting_get('0', $key, $setting);
}
function setting_get($value, $key, $setting) {
$args = wp_parse_args( get_option($key),
array(
$setting => $value,
)
);
return $args[$setting];
}
function settings_input($args) {
$args = wp_parse_args( $args,
array(
'name' => '',
'key' => '',
'maxlength' => 50,
'size' => 30,
'after' => '',
)
);
$name = $args['name'];
$key = $args['key'];
$size = $args['size'];
$maxlength = $args['maxlength'];
$option = get_option($key);
$value = isset($option[$name]) ? esc_attr($option[$name]) : '';
echo "
";
if (!empty($args['after']))
echo '' . __($args['after'], 'any-ipsum') . '
';
}
function settings_textarea($args) {
$args = wp_parse_args( $args,
array(
'name' => '',
'key' => '',
'rows' => 10,
'cols' => 40,
'after' => '',
)
);
$name = $args['name'];
$key = $args['key'];
$rows = $args['rows'];
$cols = $args['cols'];
$option = get_option($key);
$value = isset($option[$name]) ? esc_attr($option[$name]) : '';
echo "
";
if (!empty($args['after']))
echo '' . $args['after'] . '
';
}
function settings_yes_no($args) {
$args = wp_parse_args( $args,
array(
'name' => '',
'key' => '',
'after' => '',
)
);
$name = $args['name'];
$key = $args['key'];
$option = get_option($key);
$value = isset($option[$name]) ? esc_attr($option[$name]) : '';
if (empty($value))
$value = '0';
echo '';
echo " " . __('Yes', 'any-ipsum') . " ";
echo " " . __('No', 'any-ipsum') . " ";
echo '
';
if (!empty($args['after']))
echo '' . __($args['after'], 'any-ipsum') . '
';
}
function admin_menu() {
add_options_page( __('Any Ipsum Settings', 'any-ipsum'), __('Any Ipsum', 'any-ipsum'), 'manage_options', $this->settings_page, array($this, 'options_page' ), 30);
}
function options_page() {
$tab = !empty( $_GET['tab'] ) ? $_GET['tab'] : $this->settings_key_general;
?>
plugin_options_tabs(); ?>
settings_key_general;
echo '' . __('Any Ipsum Settings', 'any-ipsum') . ' ';
foreach ( $this->plugin_settings_tabs as $tab_key => $tab_caption ) {
$active = $current_tab == $tab_key ? 'nav-tab-active' : '';
echo '' . $tab_caption . ' ';
}
echo ' ';
}
function section_header($args) {
switch ($args['id']) {
case 'help';
include_once 'admin-help.php';
break;
case 'api':
$output = __('Allows for a JSON API to your custom ipsum.', 'any-ipsum');
$endpoint = $this->setting_get( '', $this->settings_key_api, 'api-endpoint' );
if (!empty($endpoint)) {
$output .= ' ' . __('Example', 'any-ipsum') . ': ';
$url = home_url( $endpoint ) . '?type=' . esc_attr( apply_filters( 'anyipsum-setting-get', '', 'anyipsum-settings-general', 'querystring-all-custom' ) ) . '¶s=3&start-with-lorem=1';
$output .= '' . $url . ' ';
}
break;
}
if (!empty($output))
echo '';
}
}
}