self::OPTION_RECAPTCHA_THEME_LIGHT, self::OPTION_RECAPTCHA_USER => self::OPTION_RECAPTCHA_USER_GUEST, self::OPTION_RECAPTCHA_BADGE => self::OPTION_RECAPTCHA_BADGE_BOTTOM_RIGHT, ]; /** * AnyCommentAdminPages constructor. * * @param bool $init if required to init the modle. */ public function __construct( $init = true ) { parent::__construct(); if ( $init ) { $this->init_hooks(); } } /** * Initiate hooks. */ private function init_hooks() { add_action( 'admin_init', [ $this, 'init_options' ] ); } /** * Init options. * @return bool False on failure. */ public function init_options() { add_settings_section( 'section_integration', __( 'Generic', "anycomment" ), function () { ?>

page_slug ); $integrations = []; if ( is_plugin_active( 'akismet/akismet.php' ) ) { $integrations[] = [ 'id' => self::OPTION_AKISMET, 'title' => __( 'Akismet Anti-Spam', "anycomment" ), 'type' => 'checkbox', 'description' => sprintf( __( 'Filter all new comments through Akismet Anti-Spam plugin.', "anycomment" ), "https://wordpress.org/plugins/akismet/" ) ]; } if ( is_plugin_active( 'wp-user-avatar/wp-user-avatar.php' ) ) { $integrations[] = [ 'id' => self::OPTION_WP_USER_AVATAR, 'title' => __( 'WP User Avatar', "anycomment" ), 'type' => 'checkbox', 'description' => sprintf( __( 'Use WP User Avatar for handling avatars in the plugin.', "anycomment" ), "https://wordpress.org/plugins/wp-user-avatar/" ) ]; } /** * reCaptcha */ $integrations[] = [ 'id' => self::OPTION_RECAPTCHA_TOGGLE, 'title' => __( 'Enable reCAPTCHA', "anycomment" ), 'type' => 'checkbox', 'description' => __( 'Enable reCAPTCHA', "anycomment" ) ]; $integrations[] = [ 'id' => self::OPTION_RECAPTCHA_USER, 'title' => __( 'reCAPTCHA Users', "anycomment" ), 'type' => 'select', 'options' => [ self::OPTION_RECAPTCHA_USER_ALL => __( 'For all', 'anycomment' ), self::OPTION_RECAPTCHA_USER_GUEST => __( 'For guests only', 'anycomment' ), self::OPTION_RECAPTCHA_USER_AUTH => __( 'For logged in only', 'anycomment' ), ], 'description' => __( 'Users affected by reCAPTCHA', "anycomment" ) ]; $integrations[] = [ 'id' => self::OPTION_RECAPTCHA_SITE_KEY, 'title' => __( 'reCAPTCHA Site Key', "anycomment" ), 'type' => 'text', 'description' => sprintf( __( 'reCAPTCHA site key. Can be found here (register your website if does not exist)', "anycomment" ), "http://www.google.com/recaptcha/admin" ) ]; $integrations[] = [ 'id' => self::OPTION_RECAPTCHA_SITE_SECRET, 'title' => __( 'reCAPTCHA Site Secret', "anycomment" ), 'type' => 'text', 'description' => sprintf( __( 'reCAPTCHA site secret. Can be found here (register your website if does not exist)', "anycomment" ), "http://www.google.com/recaptcha/admin" ) ]; $integrations[] = [ 'id' => self::OPTION_RECAPTCHA_THEME, 'title' => __( 'reCAPTCHA Theme', "anycomment" ), 'type' => 'select', 'options' => [ self::OPTION_RECAPTCHA_THEME_LIGHT => __( 'Light', 'anycomment' ), self::OPTION_RECAPTCHA_THEME_DARK => __( 'Dark', 'anycomment' ), ], 'description' => __( 'Theme of reCAPTCHA', "anycomment" ) ]; $integrations[] = [ 'id' => self::OPTION_RECAPTCHA_BADGE, 'title' => __( 'reCAPTCHA Position', "anycomment" ), 'type' => 'select', 'args' => [ 'options' => [ self::OPTION_RECAPTCHA_BADGE_BOTTOM_RIGHT => __( 'Bottom right', 'anycomment' ), self::OPTION_RECAPTCHA_BADGE_BOTTOM_LEFT => __( 'Bottom left', 'anycomment' ), self::OPTION_RECAPTCHA_BADGE_BOTTOM_INLINE => __( 'Inline', 'anycomment' ), ] ], 'description' => __( 'Position of reCAPTCHA', "anycomment" ) ]; $this->render_fields( $this->page_slug, 'section_integration', $integrations ); return true; } /** * Check whether Akismet filtration enabled or not. * * @return bool */ public static function isAkismetOn() { return static::instance()->getOption( self::OPTION_AKISMET ) !== null; } /** * Check whether WP User Avatar is enabled or not. * * @since 0.0.3 * @return bool */ public static function isWPUserAvatarOn() { return static::instance()->getOption( self::OPTION_WP_USER_AVATAR ) !== null; } /** * Check whether reCAPTCHA is enabled or not. * * @since 0.0.56 * @return bool */ public static function isRecaptchaOn() { return static::instance()->getOption( self::OPTION_RECAPTCHA_TOGGLE ) !== null; } /** * Check whether reCAPTCHA should be shown to all users. * * @since 0.0.56 * @return bool */ public static function isRecaptchaUserAll() { return static::getRecaptchaUser() === self::OPTION_RECAPTCHA_USER_ALL; } /** * Check whether reCAPTCHA should be shown to guest users only. * * @since 0.0.56 * @return bool */ public static function isRecaptchaUserGuest() { return static::getRecaptchaUser() === self::OPTION_RECAPTCHA_USER_GUEST; } /** * Check whether reCAPTCHA should be shown to logged in users only. * * @since 0.0.56 * @return bool */ public static function isRecaptchaUserAuth() { return static::getRecaptchaUser() === self::OPTION_RECAPTCHA_USER_AUTH; } /** * Get reCAPTCHA user (for whom it will be shown). * * @since 0.0.56 * @return string|null */ public static function getRecaptchaUser() { $user = static::instance()->getOption( self::OPTION_RECAPTCHA_USER ); if ( $user !== self::OPTION_RECAPTCHA_USER_ALL && $user !== self::OPTION_RECAPTCHA_USER_AUTH && $user !== self::OPTION_RECAPTCHA_USER_GUEST ) { return self::OPTION_RECAPTCHA_USER_GUEST; } return $user; } /** * Get reCAPTCHA site key. * * @since 0.0.56 * @return string|null */ public static function getRecaptchaSiteKey() { return static::instance()->getOption( self::OPTION_RECAPTCHA_SITE_KEY ); } /** * Get reCAPTCHA site secret. * * @since 0.0.56 * @return string|null */ public static function getRecaptchaSiteSecret() { return static::instance()->getOption( self::OPTION_RECAPTCHA_SITE_SECRET ); } /** * Get reCAPTCHA theme. * * @since 0.0.56 * @return string|null */ public static function getRecaptchaTheme() { $theme = static::instance()->getOption( self::OPTION_RECAPTCHA_THEME ); if ( $theme !== self::OPTION_RECAPTCHA_THEME_LIGHT && $theme !== self::OPTION_RECAPTCHA_THEME_DARK ) { return self::OPTION_RECAPTCHA_THEME_LIGHT; } return $theme; } /** * Get reCAPTCHA badge (location of invisible captcha). * * @since 0.0.56 * @return string|null */ public static function getRecaptchaBadge() { $badge = static::instance()->getOption( self::OPTION_RECAPTCHA_BADGE ); if ( $badge !== self::OPTION_RECAPTCHA_BADGE_BOTTOM_RIGHT && $badge !== self::OPTION_RECAPTCHA_BADGE_BOTTOM_LEFT && $badge !== self::OPTION_RECAPTCHA_BADGE_BOTTOM_INLINE ) { return self::OPTION_RECAPTCHA_BADGE_BOTTOM_RIGHT; } return $badge; } } endif;