init_hooks();
}
}
/**
* Initiate hooks.
*/
private function init_hooks() {
add_action( 'admin_init', [ $this, 'init_settings' ] );
}
/**
* {@inheritdoc}
*/
public function init_settings() {
/**
* VK
*/
add_settings_section(
'section_vkontakte',
__( 'VK', "anycomment" ),
function () {
?>
= __( 'VK authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_vkontakte',
[
[
'id' => self::OPTION_VK_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => esc_html( __( 'Allow VK authorization', "anycomment" ) )
],
[
'id' => self::OPTION_VK_APP_ID,
'title' => __( 'Application ID', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter app id. Can be found in apps page', "anycomment" ), 'https://vk.com/apps?act=manage' )
],
[
'id' => self::OPTION_VK_SECRET,
'title' => __( 'Secure key', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter secure key. Can be found in apps page', "anycomment" ), 'https://vk.com/apps?act=manage' )
]
]
);
/**
* Twitter
*/
add_settings_section(
'section_twitter',
__( 'Twitter', "anycomment" ),
function () {
?>
= __( 'Twitter authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_twitter',
[
[
'id' => self::OPTION_TWITTER_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow Twitter authorization', "anycomment" )
],
[
'id' => self::OPTION_TWITTER_CONSUMER_KEY,
'title' => __( 'Consumer Key', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter consumer key. Can be found in the list of apps', "anycomment" ), 'https://apps.twitter.com/' )
],
[
'id' => self::OPTION_TWITTER_CONSUMER_SECRET,
'title' => __( 'Consumer Secret', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter consumer secret. Can be found in the list of apps', "anycomment" ), 'https://apps.twitter.com/' )
]
]
);
/**
* Facebook
*/
add_settings_section(
'section_facebook',
__( 'Facebook', "anycomment" ),
function () {
?>
= __( 'Facebook authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_facebook',
[
[
'id' => self::OPTION_FACEBOOK_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow Facebook authorization', "anycomment" )
],
[
'id' => self::OPTION_FACEBOOK_APP_ID,
'title' => __( 'App ID', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter app id. Can be found in the list of apps', "anycomment" ), 'https://developers.facebook.com/apps/' )
],
[
'id' => self::OPTION_FACEBOOK_APP_SECRET,
'title' => __( 'App Secret', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter app secret. Can be found in the list of apps', "anycomment" ), 'https://developers.facebook.com/apps/' )
]
]
);
/**
* Google
*/
add_settings_section(
'section_google',
__( 'Google', "anycomment" ),
function () {
?>
= __( 'Google authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_google',
[
[
'id' => self::OPTION_GOOGLE_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow Google authorization', "anycomment" )
],
[
'id' => self::OPTION_GOOGLE_CLIENT_ID,
'title' => __( 'Client ID', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client id. Can be found in the list of apps', "anycomment" ), 'https://console.developers.google.com/apis/credentials' )
],
[
'id' => self::OPTION_GOOGLE_SECRET,
'title' => __( 'Client Secret', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client secret. Can be found in the list of apps', "anycomment" ), 'https://console.developers.google.com/apis/credentials' )
]
]
);
/**
* GitHub
*/
add_settings_section(
'section_github',
__( 'Github', "anycomment" ),
function () {
?>
= __( 'Github authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_github',
[
[
'id' => self::OPTION_GITHUB_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow GitHub authorization', "anycomment" )
],
[
'id' => self::OPTION_GITHUB_CLIENT_ID,
'title' => __( 'Client ID', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client id. Can be found in the list of apps', "anycomment" ), 'https://github.com/settings/developers' )
],
[
'id' => self::OPTION_GITHUB_SECRET,
'title' => __( 'Client Secret', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client secret. Can be found in the list of apps', "anycomment" ), 'https://github.com/settings/developers' )
]
]
);
/**
* GitHub
*/
add_settings_section(
'section_odnoklassniki',
__( 'Odnoklassniki', "anycomment" ),
function () {
?>
= __( 'Odnoklassniki authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_odnoklassniki',
[
[
'id' => self::OPTION_OK_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow Odnoklassniki authorization', "anycomment" )
],
[
'id' => self::OPTION_OK_APP_ID,
'title' => __( 'App ID', "anycomment" ),
'callback' => 'input_text',
'description' => __( 'Enter app id. Can be found in the email sent to you by Odnoklassniki', "anycomment" ),
],
[
'id' => self::OPTION_OK_APP_KEY,
'title' => __( 'App Key', "anycomment" ),
'callback' => 'input_text',
'description' => __( 'Enter app key. Can be found in the email sent to you by Odnoklassniki', "anycomment" ),
],
[
'id' => self::OPTION_OK_APP_SECRET,
'title' => __( 'App Secret', "anycomment" ),
'callback' => 'input_text',
'description' => __( 'Enter client secret. Can be found in the email sent to you by Odnoklassniki', "anycomment" ),
]
]
);
/**
* Instagram
*/
add_settings_section(
'section_instagram',
__( 'Instagram', "anycomment" ),
function () {
?>
= __( 'Instagram authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_instagram',
[
[
'id' => self::OPTION_INSTAGRAM_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow Instagram authorization', "anycomment" )
],
[
'id' => self::OPTION_INSTAGRAM_CLIENT_ID,
'title' => __( 'Client ID', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client id. Can be found in Manage Clients', "anycomment" ), 'https://www.instagram.com/developer/clients/manage/' )
],
[
'id' => self::OPTION_INSTAGRAM_CLIENT_SECRET,
'title' => __( 'Client Secret', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client secret. Can be found in Manage Clients', "anycomment" ), 'https://www.instagram.com/developer/clients/manage/' )
]
]
);
/**
* Twitch
*/
add_settings_section(
'section_twitch',
__( 'Twitch', "anycomment" ),
function () {
?>
= __( 'Twitch authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_twitch',
[
[
'id' => self::OPTION_TWITCH_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow Twitch authorization', "anycomment" )
],
[
'id' => self::OPTION_TWITCH_CLIENT_ID,
'title' => __( 'Client ID', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client id. It can be found in the apps', "anycomment" ), 'https://glass.twitch.tv/console/apps' )
],
[
'id' => self::OPTION_TWITCH_CLIENT_SECRET,
'title' => __( 'Client Secret', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client secret. It can be found in the apps', "anycomment" ), 'https://glass.twitch.tv/console/apps' )
]
]
);
/**
* Dribble
*/
add_settings_section(
'section_dribbble',
__( 'Dribbble', "anycomment" ),
function () {
?>
= __( 'Dribbble authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_dribbble',
[
[
'id' => self::OPTION_DRIBBBLE_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow Dribbble authorization', "anycomment" )
],
[
'id' => self::OPTION_DRIBBBLE_CLIENT_ID,
'title' => __( 'Client ID', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client id. It can be found in the your applications', "anycomment" ), 'https://dribbble.com/account/applications' )
],
[
'id' => self::OPTION_DRIBBBLE_CLIENT_SECRET,
'title' => __( 'Client Secret', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client secret. It can be found in the your applications', "anycomment" ), 'https://dribbble.com/account/applications' )
]
]
);
/**
* Yahoo
*/
add_settings_section(
'section_yahoo',
__( 'Yahoo', "anycomment" ),
function () {
?>
= __( 'Yahoo authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug . time(),
'section_yahoo',
[
[
'id' => self::OPTION_YAHOO_TOGGLE,
'title' => __( 'Enable', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow Yahoo authorization', "anycomment" )
],
[
'id' => self::OPTION_YAHOO_APP_ID,
'title' => __( 'App ID', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter app id. It can be found in the my apps', "anycomment" ), 'https://developer.yahoo.com/apps/' )
],
[
'id' => self::OPTION_YAHOO_CLIENT_SECRET,
'title' => __( 'Client Secret', "anycomment" ),
'callback' => 'input_text',
'description' => sprintf( __( 'Enter client secret. It can be found in the my apps', "anycomment" ), 'https://developer.yahoo.com/apps/' )
]
]
);
/**
* WordPress
*/
add_settings_section(
'section_wordpress',
__( 'WordPress', "anycomment" ),
function () {
?>
= __( 'WordPress authorization settings.', "anycomment" ) ?>
page_slug
);
$this->render_fields(
$this->page_slug,
'section_wordpress',
[
[
'id' => self::OPTION_WORDPRESS_NATIVE_TOGGLE,
'title' => __( 'Enable Native', "anycomment" ),
'callback' => 'input_checkbox',
'description' => __( 'Allow WordPress native authorization', "anycomment" )
],
]
);
}
/**
* top level menu:
* callback functions
*
* @param bool $wrapper Whether to wrap for with header or not.
*/
public function page_html( $wrapper = true ) {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
if ( isset( $_GET['settings-updated'] ) ) {
add_settings_error( $this->alert_key, 'anycomment_message', __( 'Settings Saved', 'anycomment' ), 'updated' );
}
settings_errors( $this->alert_key );
?>
';
$i = 0;
foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
$liClasses = ( $i == 0 ? 'current' : '' );
$liClasses .= ' ' . ( static::isEnabled( str_replace( 'section_', '', $section['id'] ) ) ? 'toggled' : '' );
$path = sprintf( AnyComment()->plugin_url() . '/assets/img/icons/auth/%s.svg', str_replace( 'section_', 'social-', $section['id'] ) );
echo '
' . $section['title'] . '
';
$i ++;
}
echo '';
?>
{$section['title']}\n";
}
if ( $includeHeader && $section['callback'] ) {
call_user_func( $section['callback'], $section );
}
if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) {
continue;
}
$social = str_replace( 'section_', '', $section['id'] );
$guide_link = static::getGuide( [ 'social' => $social ] );
echo '
= __( 'Callback URL', 'anycomment' ) ?>
{$section['title']}
\n"; } if ( $includeHeader && $section['callback'] ) { call_user_func( $section['callback'], $section ); } if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) { continue; } echo '