Integrate wp_editor in admin page

21:25
we are implementing email template by using wp_editor. please follow below steps to achieve this functionality. Step 1: First We need to create a email-template folder in `wp-content/plugins/`. Step 2: Create new email-template.php file with the following php code in `wp-content/plugins/email-template/` folder. The following code is for your plugin details
<?php
/*
Plugin name: Email Template
Description: A simple plugin to create custom Email Template.
Author: Author Name
Version: 0.5
*/?>
Step 3: Please copy the following code and paste in your email-template.php
add_action( 'admin_menu', 'custom_admin_plugin_menu' );

function custom_admin_plugin_menu() {
 add_menu_page( 'Email Template', 'Email Template', 'manage_options', 'custom-menu-identifier', 'email_template_function' );
}

function email_template_function()
{
 $msg='';
 if(isset($_REQUEST['submit']))
 {
  $activation_email_content=$_REQUEST['activation_email_content'];
  $activation_email_subject=$_REQUEST['activation_email_subject'];
  
  update_option('activation_email_content',wp_kses_post( stripslashes($activation_email_content) ));
  update_option('activation_email_subject',$activation_email_subject);
  $msg='Successfully Updated';
 }

 //get email template
 $activation_email_content=get_option('activation_email_content');
 ?>
 <div class="search_categories">
 <div></div>
 <h2>Email Template</h2><span class="success"><?php _e($msg);?></span>
 <form name="f1" action="" method="post"> 
 <table>
  
  <tr>
   <td><b>Email Subject:</b></td>
   <td>
    <br/>
    <input type="text" name="activation_email_subject" value="<?php _e(get_option('activation_email_subject'));?>" style="width:500px;" />
   </td>
  </tr>
  <tr>
   <td><b>Email Template Content:</b></td>
   <td style="width:1000px;">
    <br/><br/>
    <?php
     
     $editor_id = 'activation_email_content';
     //wp_editor( $content, $editor_id );
     wp_editor(stripslashes($activation_email_content), $editor_id, array('textarea_rows' => 20, 'wpautop' => false, 'textarea_name' => "activation_email_content"));

    ?>
    <b>(Note: please use following shortcodes for dynamic data)</b><br/>
    <b>username - {{user_name}}, activation link - {{activation_link}}</b>
   </td>
  </tr>
  
  <tr>
   <td col="2"><br/><input type="submit" name="submit" value="Submit" class="button button-primary button-large" />
   </td>
  </tr>
 </table>
 </form>
 </div>
 
 <?php
}

No comments:

Powered by Blogger.