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 () { ?>

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 () { ?>

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 () { ?>

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 () { ?>

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 () { ?>

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 () { ?>

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 () { ?>

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 () { ?>

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 () { ?>

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 () { ?>

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/' ) ] ] ); } /** * 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 ); ?>

option_group ); ?>
do_settings_sections( $this->page_slug, false ); submit_button( __( 'Save', 'anycomment' ) ); ?>
'; $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 '
    '; echo ''; echo '
    '; $i ++; } } /** * Custom wrapper over original method. * * @global $wp_settings_fields Storage array of settings fields and their pages/sections * * @since 0.0.45 * * @param string $page Slug title of the admin page who's settings fields you want to show. * @param string $section Slug title of the settings section who's fields you want to show. */ private function do_settings_fields( $page, $section ) { global $wp_settings_fields; if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) { return; } foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) { $class = ''; if ( ! empty( $field['args']['class'] ) ) { $class = ' class="' . esc_attr( $field['args']['class'] ) . '"'; } echo ""; if ( ! empty( $field['args']['label_for'] ) ) { echo ''; } else { echo '' . $field['title'] . ''; } echo ''; call_user_func( $field['callback'], $field['args'] ); echo ''; echo ''; } } /** * Check whether social enabled by name. * * @param string $name Social network name. Will be lowercased. * * @return mixed|null */ public static function isEnabled( $name ) { return static::instance()->getOption( sprintf( 'social_%s_toggle_field', strtolower( $name ) ) ) !== null; } /** * Check if user enter at least some information about socials. * * @return bool */ public static function hasAnySocial() { return static::instance()->hasOptions(); } /** * Check whether VK social is on. * * @return bool */ public static function isVkOn() { return static::instance()->getOption( self::OPTION_VK_TOGGLE ) !== null; } /** * Get VK App ID. * * @return int|null */ public static function getVkAppId() { return static::instance()->getOption( self::OPTION_VK_APP_ID ); } /** * Get VK Secure key. * * @return string|null */ public static function getVkSecureKey() { return static::instance()->getOption( self::OPTION_VK_SECRET ); } /** * Check whether Yahoo social is on. * * @return bool */ public static function isYahooOn() { return static::instance()->getOption( self::OPTION_YAHOO_TOGGLE ) !== null; } /** * Get Yahoo App ID. * * @return int|null */ public static function getYahooAppId() { return static::instance()->getOption( self::OPTION_YAHOO_APP_ID ); } /** * Get Yahoo Secure key. * * @return string|null */ public static function getYahooClientSecret() { return static::instance()->getOption( self::OPTION_YAHOO_CLIENT_SECRET ); } /** * Check whether GitHub social is on. * * @return bool */ public static function isGithubOn() { return static::instance()->getOption( self::OPTION_GITHUB_TOGGLE ) !== null; } /** * Get GitHub client ID. * * @return int|null */ public static function getGithubClientId() { return static::instance()->getOption( self::OPTION_GITHUB_CLIENT_ID ); } /** * Get GitHub secret key. * * @return string|null */ public static function getGithubSecretKey() { return static::instance()->getOption( self::OPTION_GITHUB_SECRET ); } /** * Check whether Instagram social is on. * * @return bool */ public static function isInstagramOn() { return static::instance()->getOption( self::OPTION_INSTAGRAM_TOGGLE ) !== null; } /** * Get Instagram client ID. * * @return int|null */ public static function getInstagramClientId() { return static::instance()->getOption( self::OPTION_INSTAGRAM_CLIENT_ID ); } /** * Get Instagram secret key. * * @return string|null */ public static function getInstagramClientSecret() { return static::instance()->getOption( self::OPTION_INSTAGRAM_CLIENT_SECRET ); } /** * Check whether Twitch social is on. * * @return bool */ public static function isTwitchOn() { return static::instance()->getOption( self::OPTION_TWITCH_TOGGLE ) !== null; } /** * Get Twitch client ID. * * @return string|null */ public static function getTwitchClientId() { return static::instance()->getOption( self::OPTION_TWITCH_CLIENT_ID ); } /** * Get Twitch secret key. * * @return string|null */ public static function getTwitchClientSecret() { return static::instance()->getOption( self::OPTION_TWITCH_CLIENT_SECRET ); } /** * Check whether Dribbble social is on. * * @return bool */ public static function isDribbbleOn() { return static::instance()->getOption( self::OPTION_DRIBBBLE_TOGGLE ) !== null; } /** * Get Dribbble client ID. * * @return string|null */ public static function getDribbbleClientId() { return static::instance()->getOption( self::OPTION_DRIBBBLE_CLIENT_ID ); } /** * Get Dribbble secret key. * * @return string|null */ public static function getDribbbleClientSecret() { return static::instance()->getOption( self::OPTION_DRIBBBLE_CLIENT_SECRET ); } /** * Check whether Twitter is on. * * @return bool */ public static function isTwitterOn() { return static::instance()->getOption( self::OPTION_TWITTER_TOGGLE ) !== null; } /** * Get Twitter consumer key. * * @return string|null */ public static function getTwitterConsumerKey() { return static::instance()->getOption( self::OPTION_TWITTER_CONSUMER_KEY ); } /** * Get Twitter consumer secret. * * @return string|null */ public static function getTwitterConsumerSecret() { return static::instance()->getOption( self::OPTION_TWITTER_CONSUMER_SECRET ); } /** * Check whether Facebook social is on. * * @return bool */ public static function isFbOn() { return static::instance()->getOption( self::OPTION_FACEBOOK_TOGGLE ) !== null; } /** * Get Facebook App ID. * * @return int|null */ public static function getFbAppId() { return static::instance()->getOption( self::OPTION_FACEBOOK_APP_ID ); } /** * Get Facebook Secure key. * * @return string|null */ public static function getFbAppSecret() { return static::instance()->getOption( self::OPTION_FACEBOOK_APP_SECRET ); } /** * Check whether Google social is on. * * @return bool */ public static function isGoogleOn() { return static::instance()->getOption( self::OPTION_GOOGLE_TOGGLE ) !== null; } /** * Get Google Client ID. * * @return int|null */ public static function getGoogleClientId() { return static::instance()->getOption( self::OPTION_GOOGLE_CLIENT_ID ); } /** * Get Google secret key. * * @return string|null */ public static function getGoogleSecret() { return static::instance()->getOption( self::OPTION_GOOGLE_SECRET ); } /** * Check whether Odnoklassniki social is on. * * @return bool */ public static function isOkOn() { return static::instance()->getOption( self::OPTION_OK_TOGGLE ) !== null; } /** * Get Odnoklassniki app ID. * * @return int|null */ public static function getOkAppId() { return static::instance()->getOption( self::OPTION_OK_APP_ID ); } /** * Get Odnoklassniki app key. * * @return int|null */ public static function getOkAppKey() { return static::instance()->getOption( self::OPTION_OK_APP_KEY ); } /** * Get Odnoklassniki app secret key. * * @return string|null */ public static function getOkAppSecret() { return static::instance()->getOption( self::OPTION_OK_APP_SECRET ); } /** * Get guide. * * @param null $options Options. See list below. * - native (bool) Takes language from WordPress and trying to get guide for it. * - lang (string) Use this language to search for guide. * - social (string) Social name. Will be lowecased. * * @return null|string NULL when no guide exists for native or specified lang or social, otherwise string. */ public static function getGuide( $options = null ) { $isNative = isset( $options['native'] ); $lang = isset( $options['lang'] ) ? trim( $options['lang'] ) : null; $social = isset( $options['social'] ) ? trim( $options['social'] ) : null; if ( $social === null ) { return null; } $searchLang = null; if ( $isNative || $lang === null ) { $searchLang = get_locale(); if ( strlen( $searchLang ) > 2 ) { $searchLang = substr( $searchLang, 0, 2 ); } } $guides = static::getGuides(); // When there are guides for specified language if ( ! isset( $guides[ $searchLang ] ) ) { return null; } // When there are guides for language, but no for specific social if ( ! isset( $guides[ $searchLang ][ $social ] ) ) { return null; } return $guides[ $searchLang ][ $social ]; } /** * Get list of available guides. * * @return array */ public static function getGuides() { return [ 'ru' => [ AnyCommentSocialAuth::SOCIAL_VKONTAKTE => 'https://anycomment.io/ru/api-vkontakte/', AnyCommentSocialAuth::SOCIAL_TWITTER => 'https://anycomment.io/ru/api-twitter/', AnyCommentSocialAuth::SOCIAL_FACEBOOK => 'https://anycomment.io/ru/api-facebook/', AnyCommentSocialAuth::SOCIAL_GOOGLE => 'https://anycomment.io/ru/api-google/', AnyCommentSocialAuth::SOCIAL_ODNOKLASSNIKI => 'https://anycomment.io/ru/api-odnoklassniki/', AnyCommentSocialAuth::SOCIAL_GITHUB => 'https://anycomment.io/ru/api-github/', AnyCommentSocialAuth::SOCIAL_INSTAGRAM => 'https://anycomment.io/ru/api-instagram/', AnyCommentSocialAuth::SOCIAL_TWITCH => 'https://anycomment.io/ru/api-twitch/', ], 'en' => [ AnyCommentSocialAuth::SOCIAL_VKONTAKTE => 'https://anycomment.io/api-vkontakte/', AnyCommentSocialAuth::SOCIAL_TWITTER => 'https://anycomment.io/api-twitter/', AnyCommentSocialAuth::SOCIAL_FACEBOOK => 'https://anycomment.io/api-facebook/', AnyCommentSocialAuth::SOCIAL_GOOGLE => 'https://anycomment.io/api-google/', AnyCommentSocialAuth::SOCIAL_ODNOKLASSNIKI => 'https://anycomment.io/ru/api-odnoklassniki/', AnyCommentSocialAuth::SOCIAL_GITHUB => 'https://anycomment.io/api-github/', AnyCommentSocialAuth::SOCIAL_INSTAGRAM => 'https://anycomment.io/api-instagram/', AnyCommentSocialAuth::SOCIAL_TWITCH => 'https://anycomment.io/api-twitch/', AnyCommentSocialAuth::SOCIAL_DRIBBBLE => 'https://anycomment.io/api-dribbble/', ] ]; } } endif;