Set company details via the admin panel? (6 posts)

  1. Joey
    Posted 3 years ago #

    I'm looking to create a simple admin menu item titled "Company Information" that would take you to an admin panel where an administrator could fill out the following details via a form:

    Company Name
    Company Address

    Once set, each item could then be used as a shortcode, within the loop. Eg. [companyname], [companyaddress] etc.

    Can anyone provide a good starting point?

  2. widelegger
    Posted 3 years ago #

    You might find what you want in the WordPress.org plugin repository:

    What you describe is very specific yet basic, so you might consider simply writing the plugin yourself:

  3. Joey
    Posted 3 years ago #

    Thanks. I browsed through the plugins and found something that would do the trick but it's really overkill for my needs.

    All that said, my plan was to create a custom admin menu using this as a starting point:

    add_action('admin_menu', 'company_information_menu');
    function my_plugin_menu() {
    	add_options_page('Company Information Options', Company Information', 'manage_options', 'company-information', 'company_information_options');
    function company_information_options() {
    	if (!current_user_can('manage_options'))  {
    		wp_die( __('You do not have sufficient permissions to access this page.') );
    	echo 'My fields would go here but I don't know how to set them up';

    Problem is, I can't find any documentation for hooking in the form to capture data for the fields.

  4. widelegger
    Posted 3 years ago #

    You are on the right track. You'll want to use the "WordPress Settings API" to store your plugin's settings in your database. WordPress has some documentation on the API and there are some tutorials on the internet too.


  5. Joey
    Posted 3 years ago #

    Thanks for the link. I was able to build the admin panel page and it accepts and records my entries. However I'm stumped as to how I can display the content of these entries within the loop using short codes.

    If it's helpful here's my function to register the settings:

    function contactinfo_init_fn(){
    	register_setting('plugin_options', 'plugin_options', 'plugin_options_validate' );
    	add_settings_section('contact_details', 'contact Details', 'section_text_fn', __FILE__);
    	add_settings_field('contact_information_name', 'contact Name', 'setting_name_fn', __FILE__, 'contact_details');
    	add_settings_field('contact_information_address1', 'Address', 'setting_address1_fn', __FILE__, 'contact_details');
    	add_settings_field('contact_information_address2', 'Address Line 2', 'setting_address2_fn', __FILE__, 'contact_details');
    	add_settings_field('contact_information_city', 'City', 'setting_city_fn', __FILE__, 'contact_details');
    	add_settings_field('contact_information_state', 'State', 'setting_state_fn', __FILE__, 'contact_details');
    	add_settings_field('contact_information_zip', 'Zip Code', 'setting_zip_fn', __FILE__, 'contact_details');
    	add_settings_field('contact_information_phone', 'Phone Number', 'setting_fax_fn', __FILE__, 'contact_details');
    	add_settings_field('contact_information_fax', 'Fax', 'setting_fax_fn', __FILE__, 'contact_details');
    	add_settings_field('contact_information_email', 'Email', 'setting_email_fn', __FILE__, 'contact_details');
    	add_settings_field('plugin_chk1', 'Restore Defaults Upon Reactivation?', 'setting_chk1_fn', __FILE__, 'main_section');

    I'd like to be able to call up the value of each of these settings using a shortcode such as [email] or [fax] or [phone]. Any further advice? :-)

  6. Joey
    Posted 3 years ago #

    Not sure if this is correct, but I registered the following shortcode and it appears to return the value of the "name" option:

    function contactname_func($atts) {
    $options = get_option('plugin_options');
    return "{$options['name_string']}";
    add_shortcode('contact_name', 'contactname_func');

    Likewise I can use the shortcode contact_name to return the proper value. I guess my question then is my shortcode function properly formatted? I've actually never set a shortcode before. I'm new to this stuff. :-)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.