, Ruben Garcia * @since 1.0.0 */ // Exit if accessed directly if( !defined( 'ABSPATH' ) ) exit; /** * Shortcut function to get plugin options * * @since 1.0.0 * * @param string $option_name * @param bool $default * * @return mixed */ function automatorwp_zoom_get_option( $option_name, $default = false ) { $prefix = 'automatorwp_zoom_'; return automatorwp_get_option( $prefix . $option_name, $default ); } /** * Register plugin settings sections * * @since 1.0.0 * * @return array */ function automatorwp_zoom_settings_sections( $automatorwp_settings_sections ) { $automatorwp_settings_sections['zoom'] = array( 'title' => __( 'Zoom', 'automatorwp' ), 'icon' => 'dashicons-video-alt2', ); return $automatorwp_settings_sections; } add_filter( 'automatorwp_settings_sections', 'automatorwp_zoom_settings_sections' ); /** * Register plugin settings meta boxes * * @since 1.0.0 * * @return array */ function automatorwp_zoom_settings_meta_boxes( $meta_boxes ) { $prefix = 'automatorwp_zoom_'; $meta_boxes['automatorwp-zoom-meetings-settings'] = array( 'title' => automatorwp_dashicon( 'groups' ) . __( 'Zoom Meetings', 'automatorwp' ), 'fields' => apply_filters( 'automatorwp_zoom_meetings_settings_fields', array( $prefix . 'meetings_client_id' => array( 'name' => __( 'Client ID:', 'automatorwp' ), 'desc' => __( 'Your Zoom app client ID.', 'automatorwp' ), 'type' => 'text', ), $prefix . 'meetings_client_secret' => array( 'name' => __( 'Client Secret:', 'automatorwp' ), 'desc' => __( 'Your Zoom app client secret.', 'automatorwp' ), 'type' => 'text', ), $prefix . 'meetings_redirect_url' => array( 'type' => 'text', 'render_row_cb' => 'automatorwp_zoom_redirect_url_display_cb', ), $prefix . 'meetings_authorize' => array( 'type' => 'text', 'render_row_cb' => 'automatorwp_zoom_authorize_display_cb', ), ) ), ); return $meta_boxes; } add_filter( "automatorwp_settings_zoom_meta_boxes", 'automatorwp_zoom_settings_meta_boxes' ); /** * Display callback for the authorize setting * * @since 1.0.0 * * @param array $field_args Array of field arguments. * @param CMB2_Field $field The field object */ function automatorwp_zoom_redirect_url_display_cb( $field_args, $field ) { $admin_url = str_replace( 'http://', 'https://', get_admin_url() ) . 'admin.php?page=automatorwp_settings&tab=opt-tab-zoom'; ?>

array( 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8', 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $client_secret ), 'Accept' => 'application/json', ), 'body' => array( 'grant_type' => 'authorization_code', 'redirect_uri' => str_replace( 'http://', 'https://', get_admin_url() ) . 'admin.php?page=automatorwp_settings&tab=opt-tab-zoom', 'code' => $_GET['code'] ) ); $response = wp_remote_post( 'https://zoom.us/oauth/token', $params ); // Bail if can't contact with the server if ( is_wp_error( $response ) ) { return; } $body = json_decode( wp_remote_retrieve_body( $response ) ); // Bail on receive an error if( isset( $body->error ) ) { return; } $auth = array( 'access_token' => $body->access_token, 'refresh_token' => $body->refresh_token, 'token_type' => $body->token_type, 'expires_in' => $body->expires_in, 'scope' => $body->scope, ); // Update the access and refresh tokens update_option( 'automatorwp_zoom_' . $platform . '_auth', $auth ); // Redirect to settings again wp_redirect( get_admin_url() . 'admin.php?page=automatorwp_settings&tab=opt-tab-zoom' ); exit; } } add_action( 'admin_init', 'automatorwp_zoom_maybe_authorize_complete' );