sync->register( 'noop' ); } static function configuration_redirect() { wp_safe_redirect( get_edit_profile_url( get_current_user_id() ) . '#post-by-email' ); exit; } function action_init() { if ( ! current_user_can( 'edit_posts' ) ) return; add_action( 'profile_personal_options', array( &$this, 'user_profile' ) ); add_action( 'admin_print_scripts-profile.php', array( &$this, 'profile_scripts' ) ); add_action( 'wp_ajax_jetpack_post_by_email_enable', array( &$this, 'create_post_by_email_address' ) ); add_action( 'wp_ajax_jetpack_post_by_email_regenerate', array( &$this, 'regenerate_post_by_email_address' ) ); add_action( 'wp_ajax_jetpack_post_by_email_disable', array( &$this, 'delete_post_by_email_address' ) ); } function profile_scripts() { wp_enqueue_script( 'post-by-email', plugins_url( 'post-by-email/post-by-email.js', __FILE__ ), array( 'jquery' ) ); wp_localize_script( 'post-by-email', 'pbeVars', array( 'nonces' => array( 'enable' => wp_create_nonce( 'jetpack.createPostByEmailAddress' ), 'regenerate' => wp_create_nonce( 'jetpack.regeneratePostByEmailAddress' ), 'disable' => wp_create_nonce( 'jetpack.deletePostByEmailAddress' ), ), )); wp_enqueue_style( 'post-by-email', plugins_url( 'post-by-email/post-by-email.css', __FILE__ ) ); wp_style_add_data( 'post-by-email', 'jetpack-inline', true ); // Do we really need `admin_styles`? With the new admin UI, it's breaking some bits. // Jetpack::init()->admin_styles(); } function check_user_connection() { $user_token = Jetpack_Data::get_access_token( get_current_user_id() ); $is_user_connected = $user_token && !is_wp_error( $user_token ); // If the user is already connected via Jetpack, then we're good if ( $is_user_connected ) return true; return false; } function user_profile() { $blog_name = get_bloginfo( 'blogname' ); if ( empty( $blog_name ) ) { $blog_name = home_url( '/' ); } ?>

check_user_connection() ) { $email = $this->get_post_by_email_address(); if ( empty( $email ) ) { $enable_hidden = ''; $info_hidden = ' style="display: none;"'; } else { $enable_hidden = ' style="display: none;"'; $info_hidden = ''; } ?> />
>

' . esc_html( $blog_name ) . '' ); ?>

get_current_user_id(), ) ); $xml->query( 'jetpack.getPostByEmailAddress' ); if ( $xml->isError() ) return NULL; $response = $xml->getResponse(); if ( empty( $response ) ) return NULL; return $response; } function create_post_by_email_address() { self::__process_ajax_proxy_request( 'jetpack.createPostByEmailAddress', __( 'Unable to create your Post By Email address. Please try again later.', 'jetpack' ) ); } function regenerate_post_by_email_address() { self::__process_ajax_proxy_request( 'jetpack.regeneratePostByEmailAddress', __( 'Unable to regenerate your Post By Email address. Please try again later.', 'jetpack' ) ); } function delete_post_by_email_address() { self::__process_ajax_proxy_request( 'jetpack.deletePostByEmailAddress', __( 'Unable to disable your Post By Email address. Please try again later.', 'jetpack' ) ); } /** * Backend function to abstract the xmlrpc function calls to wpcom. * * @param $endpoint * @param $error_message */ function __process_ajax_proxy_request( $endpoint, $error_message ) { if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error( $error_message ); } if ( empty( $_REQUEST['pbe_nonce'] ) || ! wp_verify_nonce( $_REQUEST['pbe_nonce'], $endpoint ) ) { wp_send_json_error( $error_message ); } Jetpack::load_xml_rpc_client(); $xml = new Jetpack_IXR_Client( array( 'user_id' => get_current_user_id(), ) ); $xml->query( $endpoint ); if ( $xml->isError() ) { wp_send_json_error( $error_message ); } $response = $xml->getResponse(); if ( empty( $response ) ) { wp_send_json_error( $error_message ); } wp_send_json_success( $response ); } }