'; } echo $js; } function acobot_menu() { add_submenu_page( 'options-general.php', __( 'Acobot Settings', 'acobot' ), __( 'Acobot', 'acobot' ), 'manage_options', 'acobot', 'acobot_settings' ); } function acobot_register_settings() { register_setting( 'acobot', ACOBOT_SLUG . 'api' ); add_settings_section( 'acobot', __( 'Acobot API', 'acobot' ), 'acbobot_settings_section', 'acobot' ); add_settings_field( ACOBOT_SLUG . 'api', __( 'API Key', 'acobot' ), 'acbobot_settings_api', 'acobot', 'acobot' ); } function acbobot_settings_section() { echo '
' . __( 'Set the API credentials here', 'acobot' ) . '
'; } function acbobot_settings_api() { echo ''; $api = get_option( ACOBOT_SLUG . 'api' ); if ( empty( $api ) ) { echo '' . sprintf( __( 'Upgrade for more features. %1$sSign up%2$s for a key and paste it above.', 'acobot' ), '', '' ) . '
'; } } function acobot_get_domain() { return parse_url( get_site_url(), PHP_URL_HOST ); } function acobot_init_api() { $domain = get_option( ACOBOT_SLUG . 'domain' ); $now = acobot_get_domain(); if ( $domain === $now ) { return; } $body = wp_remote_retrieve_body( wp_remote_get( str_replace( '#', $now, ACOBOT_API_URL ) ) ); $json = json_decode( $body, true ); $success = false; if ( $json && ! empty( $json['js'] ) ) { update_option( ACOBOT_SLUG . 'js', $json['js'] ); update_option( ACOBOT_SLUG . 'domain', $now ); delete_option( ACOBOT_SLUG . 'api' ); } } function acobot_settings() { ?>