Current File : /home/kelaby89/sergio-cuchi.tattoo/wp-content/themes/maori/includes/social-icons.php |
<?php
class maorisocial_Admin {
private $key = 'maorisocial_options';
private $metabox_id = 'maorisocial_option_metabox';
protected $title = '';
protected $options_page = '';
public function __construct() {
// Set our title
$this->title = esc_html__( 'Social Icons', 'maori' );
$this->menutitle = esc_html__( 'Social Icons', 'maori' );
}
public function hooks() {
add_action( 'admin_init', array( $this, 'init' ) );
add_action( 'admin_menu', array( $this, 'maori_add_social_page' ) );
add_action( 'cmb2_init', array( $this, 'maori_add_social_page_metabox' ) );
}
public function init() {
register_setting( $this->key, $this->key );
}
public function maori_add_social_page() {
$this->options_page = add_theme_page( $this->title, $this->menutitle, 'manage_options', $this->key, array( $this, 'maori_admin_social_display' ), 'dashicons-twitter' );
// Include CMB CSS in the head to avoid FOUT
add_action( "admin_print_styles-{$this->options_page}", array( 'CMB2_hookup', 'enqueue_cmb_css' ) );
}
public function maori_admin_social_display() {
?>
<div class="wrap cmb2-options-page <?php echo esc_html($this->key); ?>">
<div id="maori-social-wrapper">
<h1 class="maori-social-title"><span><span class="dashicons dashicons-twitter"></span> <?php echo esc_html( get_admin_page_title() ); ?></span></h1>
<p class="maori-social-subitle"><?php esc_html_e( 'These icons will be displayed in the sidebar.', 'maori' ); ?></p>
<?php cmb2_metabox_form( $this->metabox_id, $this->key ); ?>
<div id="maori-delete-social">
<form action="admin.php?page=maorisocial_options" method="post">
<input id="isg_delete_icons" name="isg_delete_icons" type="submit" onclick="return confirm('<?php esc_html_e( 'Are you sure you want to delete all icons?', 'maori') ?>')" class="button" value="<?php esc_html_e( 'Reset', 'maori') ?>" />
</form>
</div>
<?php
if (isset($_POST["isg_delete_icons"])) {
echo "<meta http-equiv='refresh' content='0'>";
delete_option("maorisocial_options");
}
?>
</div>
</div>
<?php
}
function maori_add_social_page_metabox() {
$prefix = 'maori';
$cmb = new_cmb2_box( array(
'id' => $this->metabox_id,
'hookup' => false,
'cmb_styles' => true,
'show_on' => array(
// These are important, don't remove
'key' => 'options-page',
'value' => array( $this->key, )
),
) );
$cmb->add_field(
array(
'desc' => esc_attr__( 'Open links in a new tab', 'maori'),
'id' => $prefix . 'socialiconstab',
'type' => 'checkbox'
)
);
$cmb->add_field(
array(
'id' => $prefix . 'socialicons',
'type' => 'group',
'options' => array(
'group_title' => esc_html__( 'Icon {#}', 'maori' ),
'add_button' => esc_html__( 'Add Another Icon', 'maori' ),
'remove_button' => esc_html__( 'Remove Icon', 'maori' ),
'sortable' => true,
'closed' => true,
),
'fields' => array(
array(
'name' => esc_html__( 'Select Icon:', 'maori'),
'id' => $prefix . 'iconimg',
'desc' => esc_html__( 'Select an icon.', 'maori'),
'type' => 'select',
'options' => array(
'facebook-f' => esc_html__( 'Facebook', 'maori' ),
'twitter' => esc_html__( 'Twitter', 'maori' ),
'google-plus' => esc_html__( 'Google +', 'maori' ),
'google' => esc_html__( 'Google', 'maori' ),
'linkedin' => esc_html__( 'Linkedin', 'maori' ),
'instagram' => esc_html__( 'Instagram', 'maori' ),
'vimeo' => esc_html__( 'Vimeo', 'maori' ),
'youtube' => esc_html__( 'You Tube', 'maori' ),
'apple' => esc_html__( 'Apple', 'maori' ),
'android' => esc_html__( 'Android', 'maori' ),
'dribbble' => esc_html__( 'Dribbble', 'maori' ),
'flickr' => esc_html__( 'Flickr', 'maori' ),
'pinterest' => esc_html__( 'Pinterest', 'maori' ),
'vk' => esc_html__( 'VK', 'maori' ),
'codepen' => esc_html__( 'Codepen', 'maori' ),
'snapchat-ghost' => esc_html__( 'Snapchat', 'maori' ),
'delicious' => esc_html__( 'Delicious', 'maori' ),
'github' => esc_html__( 'Github', 'maori' ),
'reddit-alien' => esc_html__( 'Reddit', 'maori' ),
'tumblr' => esc_html__( 'Tumblr', 'maori' ),
'twitch' => esc_html__( 'Twitch', 'maori' ),
'tripadvisor' => esc_html__( 'Trip Advisor', 'maori' ),
'vine' => esc_html__( 'Vine', 'maori' ),
'foursquare' => esc_html__( 'Foursquare', 'maori' ),
'lastfm' => esc_html__( 'Lastfm', 'maori' ),
'soundcloud' => esc_html__( 'Soundcloud', 'maori' ),
'deviantart' => esc_html__( 'Deviantart', 'maori' ),
'odnoklassniki' => esc_html__( 'Odnoklassniki', 'maori' ),
'spotify' => esc_html__( 'Spotify', 'maori' ),
'xing' => esc_html__( 'Xing', 'maori' ),
'amazon' => esc_html__( 'Amazon', 'maori' ),
'digg' => esc_html__( 'Digg', 'maori' ),
'etsy' => esc_html__( 'Etsy', 'maori' ),
'imdb' => esc_html__( 'Imdb', 'maori' ),
'behance' => esc_html__( 'Behance', 'maori' ),
'slack' => esc_html__( 'Slack', 'maori' ),
),
),
array(
'name' => esc_html__( 'Destination url:', 'maori'),
'desc' => esc_html__( 'Example; http://www.egemenerd.com', 'maori'),
'id' => $prefix . 'iconlink',
'type' => 'text_url'
),
),
));
}
public function __get( $field ) {
if ( in_array( $field, array( 'key', 'metabox_id', 'title', 'options_page' ), true ) ) {
return $this->{$field};
}
throw new Exception( 'Invalid property: ' . $field );
}
}
function maorisocial_admin() {
static $object = null;
if ( is_null( $object ) ) {
$object = new maorisocial_Admin();
$object->hooks();
}
return $object;
}
function maorisocial_get_option( $key = '' ) {
return cmb2_get_option( maorisocial_admin()->key, $key );
}
maorisocial_admin();
?>