Settings.php 4.08 KB
<?php
namespace Tz\WordPress\Tools\AddThis\Settings;

use Tz\Common;
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\AddThis;

const OPTION_GROUP   = 'addthis_group';      // Grouping of options used for setting output by WP
const OPTION_SECTION = 'tz_addthis_main';
const ADMIN_PAGE     = 'tz-tools-addthis';   // URI of options page
const CAPABILITY     = 'manage_addthis_params';     // User & Roles capability name

    call_user_func(function() {
        $role = get_role('administrator');
        $role->add_cap(CAPABILITY);

        Tools\add_actions(__NAMESPACE__ . '\Actions');
    });

function displayPage() {
	require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views/Settings.php');
}

function validate($data) {
    return $data;
}

/**
 * @uses Tools\add_actions
 */
class Actions {
    /**
     * Creates a settings page for the WP admin
     */
    public static function admin_menu() {
        add_options_page('AddThis', 'AddThis', CAPABILITY, ADMIN_PAGE, __NAMESPACE__ . '\displayPage');
    }

    /**
     * Generates variables for the module's options
     */
    public static function admin_init() {
        register_setting(OPTION_GROUP, AddThis\OPTION_NAME, __NAMESPACE__ . '\validate');
        add_settings_section(OPTION_SECTION, 'AddThis Default Expanded Settings', function(){}, ADMIN_PAGE);

        Tools\add_settings_fields(__NAMESPACE__ . '\Fields', ADMIN_PAGE, OPTION_SECTION);
    }
}

/**
 * Each function is a variable stored in the WP_Option
 * @uses Tools\add_settings_fields
 */
class Fields {
	
	
	public static function use_32px_icons() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	
	public static function show_share_dropdown() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	public static function facebook() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	public static function twitter() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	public static function googlebuzz() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	public static function print_button() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	public static function email() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	public static function facebook_like() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	public static function myspace() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	public static function digg() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	
	public static function stumble_upon() {
		echo '<input type="checkbox" id="' . __FUNCTION__ . '" name="' . AddThis\OPTION_NAME . '[' . __FUNCTION__ . ']" value="1" ' . checked('1', AddThis\Vars::$options[__FUNCTION__], false) . ' />';
	}
	  
}



?>