run(); } run_agnoplay_wordpress(); function agno_load_my_own_textdomain( $mofile, $domain ) { if ( 'agnoplay-wordpress' === $domain && false !== strpos( $mofile, WP_LANG_DIR . '/plugins/' ) ) { $locale = apply_filters( 'plugin_locale', determine_locale(), $domain ); $mofile = WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) . '/languages/' . $domain . '-' . $locale . '.mo'; } return $mofile; } add_filter( 'load_textdomain_mofile', 'agno_load_my_own_textdomain', 10, 2 ); /** * Settings page */ // Add menu item function agno_add_admin_menu( ) { add_options_page( __( 'Agnoplay settings', 'agnoplay-wordpress' ), __( 'Agnoplay settings', 'agnoplay-wordpress' ), 'manage_options', 'agnoplay_wordpress', 'agno_options_page' ); } add_action( 'admin_menu', 'agno_add_admin_menu' ); // Register settings function agno_settings_init( ) { register_setting( 'pluginPage', 'agno_settings', array( 'sanitize_callback' => 'agno_validate_settings' ) ); // Register a settings section for each player type add_settings_section( 'agno_video_section', 'Video', '', 'pluginPage' ); add_settings_section( 'agno_live_section', 'Live', '', 'pluginPage' ); add_settings_section( 'agno_audio_section', 'Audio', '', 'pluginPage' ); add_settings_section( 'agno_environment_section', 'Environment', '', 'pluginPage' ); // Add settings fields for brand ID and license keys to each settings section add_settings_field( 'aagno_video_brand', __( 'Brand ID', 'agnoplay-wordpress' ), 'agno_video_brand_render', 'pluginPage', 'agno_video_section' ); add_settings_field( 'agno_video_license', __( 'License key', 'agnoplay-wordpress' ), 'agno_video_license_render', 'pluginPage', 'agno_video_section' ); add_settings_field( 'agno_live_brand', __( 'Brand ID', 'agnoplay-wordpress' ), 'agno_live_brand_render', 'pluginPage', 'agno_live_section' ); add_settings_field( 'agno_live_license', __( 'License key', 'agnoplay-wordpress' ), 'agno_live_license_render', 'pluginPage', 'agno_live_section' ); add_settings_field( 'agno_brand', __( 'Brand ID', 'agnoplay-wordpress' ), 'agno_audio_brand_render', 'pluginPage', 'agno_audio_section' ); add_settings_field( 'agno_audio_license', __( 'License key', 'agnoplay-wordpress' ), 'agno_audio_license_render', 'pluginPage', 'agno_audio_section' ); add_settings_field( 'agno_environment', __( 'Environment', 'agnoplay-wordpress' ), 'agno_environment_render', 'pluginPage', 'agno_environment_section' ); } add_action( 'admin_init', 'agno_settings_init' ); function agno_get_option($key) { $options = get_option( 'agno_settings' ); if ($options) { if ($options[$key]) { return $options[$key]; } } return ''; } function agno_video_brand_render( ) { echo ''; } function agno_video_license_render( ) { echo ''; } function agno_live_brand_render( ) { echo ''; } function agno_live_license_render( ) { echo ''; } function agno_audio_brand_render( ) { echo ''; } function agno_audio_license_render( ) { echo ''; } function agno_environment_render( ) { $options = get_option( 'agno_settings' ); ?>

$brand, 'licenseKey' => $license ); $postBody = wp_json_encode($postBody); $args = array( 'headers' => array( 'Content-Type' => 'application/json', 'x-agnoplay-platform' => 'web' ), 'body' => $postBody ); $response = wp_remote_post($url, $args); if (is_wp_error($response)) { return "HTTP Error #:" . $response->get_error_message(); } else { $body = wp_remote_retrieve_body($response); $result = json_decode($body); // If request was succesful, but the validation failed if ( !property_exists( $result, 'success') || !$result->success ) { return $result->message; // Validation succeeded } else { return true; } } } function agno_validate_settings($data) { $envChanged = false; if ($data['agno_environment'] != agno_get_option('agno_environment')) { $envChanged = true; } $hasError = false; if (!agno_validate_brand_license_settings($data, 'Video', 'agno_video_brand', 'agno_video_license')) { $data['agno_video_brand'] = agno_get_option('agno_video_brand'); $data['agno_video_license'] = agno_get_option('agno_video_license'); $data['agno_environment'] = agno_get_option('agno_environment'); $hasError = true; } if (!agno_validate_brand_license_settings($data, 'Audio', 'agno_audio_brand', 'agno_audio_license')) { $data['agno_audio_brand'] = agno_get_option('agno_audio_brand'); $data['agno_audio_license'] = agno_get_option('agno_audio_license'); $data['agno_environment'] = agno_get_option('agno_environment'); $hasError = true; } if (!agno_validate_brand_license_settings($data, 'Live', 'agno_live_brand', 'agno_live_license')) { $data['agno_live_brand'] = agno_get_option('agno_live_brand'); $data['agno_live_license'] = agno_get_option('agno_live_license'); $data['agno_environment'] = agno_get_option('agno_environment'); $hasError = true; } if ($hasError && $envChanged) { agno_show_custom_error('Environment', 'Due to errors environment has not been updated'); } return $data; } function agno_validate_brand_license_settings($data, $section, $brandOptionKey, $licenseOptionKey) { if (empty($data[$licenseOptionKey])) { // Don't validate if license is empty return true; } $result = agno_validate_license_key( $data[$brandOptionKey], $data[$licenseOptionKey], $data['agno_environment'] ); if ($result !== true) { agno_show_custom_error($section, $result); return false; } return true; } function agno_show_custom_error( $type, $message ) { add_settings_error( 'agno_settings', 'agno_' . $type . '_error', $type . ': ' . $message, 'error' ); }