'' ); } $id = innreply_parse_input( $raw ); if ( '' === $id ) { add_settings_error( INNREPLY_OPTION, 'innreply_bad_id', __( 'That does not look like an InnReply line or account ID. Copy it from your InnReply install page and try again.', 'innreply' ), 'error' ); return is_array( $old ) ? $old : array( 'account_id' => '' ); } return array( 'account_id' => $id ); } /** * Registers the setting. */ function innreply_register_settings() { register_setting( 'innreply', INNREPLY_OPTION, array( 'type' => 'array', 'sanitize_callback' => 'innreply_sanitize_settings', 'default' => array( 'account_id' => '' ), ) ); } add_action( 'admin_init', 'innreply_register_settings' ); /** * Adds Settings, InnReply. */ function innreply_admin_menu() { add_options_page( __( 'InnReply Chat Box', 'innreply' ), __( 'InnReply', 'innreply' ), 'manage_options', 'innreply', 'innreply_render_settings_page' ); } add_action( 'admin_menu', 'innreply_admin_menu' ); /** * Adds a Settings link on the Plugins screen. * * @param array $links Action links. * @return array */ function innreply_action_links( $links ) { $url = admin_url( 'options-general.php?page=innreply' ); array_unshift( $links, '' . esc_html__( 'Settings', 'innreply' ) . '' ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'innreply_action_links' ); /** * Settings page. */ function innreply_render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $id = innreply_get_account_id(); ?>
true, 'strategy' => 'async', ) ); } add_action( 'wp_enqueue_scripts', 'innreply_enqueue_widget' ); /** * Adds the account ID (data-hotel) to the chat box script tag. * * @param string $tag Script tag. * @param string $handle Script handle. * @return string */ function innreply_script_tag( $tag, $handle ) { if ( 'innreply-widget' !== $handle ) { return $tag; } $id = innreply_get_account_id(); if ( '' === $id ) { return $tag; } return str_replace( ' src=', ' data-hotel="' . esc_attr( $id ) . '" src=', $tag ); } add_filter( 'script_loader_tag', 'innreply_script_tag', 10, 2 );