Jetpack_Post_By_Email

The Jetpack by WordPress.com Jetpack Post By Email class.

Defined (1)

The class is defined in the following location(s).

/modules/post-by-email.php  
  1. class Jetpack_Post_By_Email { 
  2. public static function init() { 
  3. static $instance = NULL; 
  4.  
  5. if ( !$instance ) { 
  6. $instance = new Jetpack_Post_By_Email; 
  7.  
  8. return $instance; 
  9.  
  10. function __construct() { 
  11. add_action( 'init', array( &$this, 'action_init' ) ); 
  12.  
  13. static function module_toggle() { 
  14. $jetpack = Jetpack::init(); 
  15. $jetpack->sync->register( 'noop' ); 
  16.  
  17. static function configuration_redirect() { 
  18. wp_safe_redirect( get_edit_profile_url( get_current_user_id() ) . '#post-by-email' ); 
  19. exit; 
  20.  
  21. function action_init() { 
  22. if ( ! current_user_can( 'edit_posts' ) ) 
  23. return; 
  24.  
  25. add_action( 'profile_personal_options', array( &$this, 'user_profile' ) ); 
  26. add_action( 'admin_print_scripts-profile.php', array( &$this, 'profile_scripts' ) ); 
  27.  
  28. add_action( 'wp_ajax_jetpack_post_by_email_enable', array( &$this, 'create_post_by_email_address' ) ); 
  29. add_action( 'wp_ajax_jetpack_post_by_email_regenerate', array( &$this, 'regenerate_post_by_email_address' ) ); 
  30. add_action( 'wp_ajax_jetpack_post_by_email_disable', array( &$this, 'delete_post_by_email_address' ) ); 
  31.  
  32. function profile_scripts() { 
  33. wp_enqueue_script( 'post-by-email', plugins_url( 'post-by-email/post-by-email.js', __FILE__ ), array( 'jquery' ) ); 
  34. wp_enqueue_style( 'post-by-email', plugins_url( 'post-by-email/post-by-email.css', __FILE__ ) ); 
  35. wp_style_add_data( 'post-by-email', 'jetpack-inline', true ); 
  36. // Do we really need `admin_styles`? With the new admin UI, it's breaking some bits. 
  37. // Jetpack::init()->admin_styles(); 
  38.  
  39. function check_user_connection() { 
  40. $user_token = Jetpack_Data::get_access_token( get_current_user_id() ); 
  41. $is_user_connected = $user_token && !is_wp_error( $user_token ); 
  42.  
  43. // If the user is already connected via Jetpack, then we're good 
  44. if ( $is_user_connected ) 
  45. return true; 
  46.  
  47. return false; 
  48.  
  49. function user_profile() { 
  50. $blog_name = get_bloginfo( 'blogname' ); 
  51. if ( empty( $blog_name ) ) { 
  52. $blog_name = home_url( '/' ); 
  53.  
  54. ?> 
  55. <div id="post-by-email" class="jetpack-targetable"> 
  56. <h3><?php esc_html_e( 'Post by Email', 'jetpack' ); ?></h3> 
  57. <table class="form-table"> 
  58. <tr> 
  59. <th scope="row"><?php esc_html_e( 'Email Address', 'jetpack' ); ?><span id="jp-pbe-spinner" class="spinner"></span></th> 
  60. <td> 
  61. <div id="jp-pbe-error" class="jetpack-inline-error"></div> <?php 
  62.  
  63. if ( $this->check_user_connection() ) { 
  64. $email = $this->get_post_by_email_address(); 
  65.  
  66. if ( empty( $email ) ) { 
  67. $enable_hidden = ''; 
  68. $info_hidden = ' style="display: none;"'; 
  69. } else { 
  70. $enable_hidden = ' style="display: none;"'; 
  71. $info_hidden = ''; 
  72. } ?> 
  73.  
  74. <input type="button" name="jp-pbe-enable" id="jp-pbe-enable" class="button" value="<?php esc_attr_e( 'Enable Post By Email', 'jetpack' ); ?> "<?php echo $enable_hidden; ?> /> 
  75. <div id="jp-pbe-info"<?php echo $info_hidden; ?>> 
  76. <p id="jp-pbe-email-wrapper"> 
  77. <input type="text" id="jp-pbe-email" value="<?php echo esc_attr( $email ); ?>" readonly="readonly" class="regular-text" /> 
  78. <span class="description"><a target="_blank" href="http://jetpack.me/support/post-by-email/"><?php esc_html_e( 'More information', 'jetpack' ); ?></a></span> 
  79. </p> 
  80. <p> 
  81. <input type="button" name="jp-pbe-regenerate" id="jp-pbe-regenerate" class="button" value="<?php esc_attr_e( 'Regenerate Address', 'jetpack' ); ?> " /> 
  82. <input type="button" name="jp-pbe-disable" id="jp-pbe-disable" class="button" value="<?php esc_attr_e( 'Disable Post By Email', 'jetpack' ); ?> " /> 
  83. </p> 
  84. </div> <?php 
  85. } else { 
  86. $jetpack = Jetpack::init(); ?> 
  87.  
  88. <p class="jetpack-inline-message"> 
  89. <?php printf( 
  90. esc_html( wptexturize( __( 'To use Post By Email, you need to link your %s account to your WordPress.com account.', 'jetpack' ) ) ),  
  91. '<strong>' . esc_html( $blog_name ) . '</strong>' 
  92. ); ?><br /> 
  93. <?php echo esc_html( wptexturize( __( "If you don't have a WordPress.com account yet, you can sign up for free in just a few seconds.", 'jetpack' ) ) ); ?> 
  94. </p> 
  95. <p> 
  96. <a href="<?php echo $jetpack->build_connect_url( false, get_edit_profile_url( get_current_user_id() ) . '#post-by-email' ); ?>" class="button button-connector" id="wpcom-connect"><?php esc_html_e( 'Link account with WordPress.com', 'jetpack' ); ?></a> 
  97. </p> 
  98. <?php 
  99. } ?> 
  100. </td> 
  101. </tr> 
  102. </table> 
  103. </div> 
  104. <?php 
  105.  
  106. function get_post_by_email_address() { 
  107. Jetpack::load_xml_rpc_client(); 
  108. $xml = new Jetpack_IXR_Client( array( 
  109. 'user_id' => get_current_user_id(),  
  110. ) ); 
  111. $xml->query( 'jetpack.getPostByEmailAddress' ); 
  112.  
  113. if ( $xml->isError() ) 
  114. return NULL; 
  115.  
  116. $response = $xml->getResponse(); 
  117. if ( empty( $response ) ) 
  118. return NULL; 
  119.  
  120. return $response; 
  121.  
  122. function create_post_by_email_address() { 
  123. Jetpack::load_xml_rpc_client(); 
  124. $xml = new Jetpack_IXR_Client( array( 
  125. 'user_id' => get_current_user_id(),  
  126. ) ); 
  127. $xml->query( 'jetpack.createPostByEmailAddress' ); 
  128.  
  129. if ( $xml->isError() ) { 
  130. echo json_encode( array( 
  131. 'response' => 'error',  
  132. 'message' => __( 'Unable to create your Post By Email address. Please try again later.', 'jetpack' ) 
  133. ) ); 
  134. die(); 
  135.  
  136. $response = $xml->getResponse(); 
  137. if ( empty( $response ) ) { 
  138. echo json_encode( array( 
  139. 'response' => 'error',  
  140. 'message' => __( 'Unable to create your Post By Email address. Please try again later.', 'jetpack' ) 
  141. ) ); 
  142. die(); 
  143.  
  144. echo $response; 
  145. die(); 
  146.  
  147. function regenerate_post_by_email_address() { 
  148. Jetpack::load_xml_rpc_client(); 
  149. $xml = new Jetpack_IXR_Client( array( 
  150. 'user_id' => get_current_user_id(),  
  151. ) ); 
  152. $xml->query( 'jetpack.regeneratePostByEmailAddress' ); 
  153.  
  154. if ( $xml->isError() ) { 
  155. echo json_encode( array( 
  156. 'response' => 'error',  
  157. 'message' => __( 'Unable to regenerate your Post By Email address. Please try again later.', 'jetpack' ) 
  158. ) ); 
  159. die(); 
  160.  
  161. $response = $xml->getResponse(); 
  162. if ( empty( $response ) ) { 
  163. echo json_encode( array( 
  164. 'response' => 'error',  
  165. 'message' => __( 'Unable to regenerate your Post By Email address. Please try again later.', 'jetpack' ) 
  166. ) ); 
  167. die(); 
  168.  
  169. echo $response; 
  170. die(); 
  171.  
  172. function delete_post_by_email_address() { 
  173. Jetpack::load_xml_rpc_client(); 
  174. $xml = new Jetpack_IXR_Client( array( 
  175. 'user_id' => get_current_user_id(),  
  176. ) ); 
  177. $xml->query( 'jetpack.deletePostByEmailAddress' ); 
  178.  
  179. if ( $xml->isError() ) { 
  180. echo json_encode( array( 
  181. 'response' => 'error',  
  182. 'message' => __( 'Unable to disable your Post By Email address. Please try again later.', 'jetpack' ) 
  183. ) ); 
  184. die(); 
  185.  
  186. $response = $xml->getResponse(); 
  187. if ( empty( $response ) ) { 
  188. echo json_encode( array( 
  189. 'response' => 'error',  
  190. 'message' => __( 'Unable to disable your Post By Email address. Please try again later.', 'jetpack' ) 
  191. ) ); 
  192. die(); 
  193.  
  194. echo $response; 
  195. die();