Plugin Directory

Changeset 1838366


Ignore:
Timestamp:
03/12/2018 04:41:12 AM (8 years ago)
Author:
ashuwp
Message:

Vision 1.2

Location:
ashuwp-invitaion-code/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ashuwp-invitaion-code/trunk/admin/admin.php

    r1775541 r1838366  
    3434 
    3535  function column_cb( $item ) {
    36     return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $item['id'] );
     36    return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', 'invitationcode', $item['id'] );
    3737  }
    3838 
     
    200200   
    201201    add_submenu_page('invitation_code', __('Add New', 'ashuwp'), __('Add New', 'ashuwp'), 'manage_options', 'invitation_code_add', array(&$this, 'invitation_code_add'));
     202   
     203    add_submenu_page('invitation_code', __('Options', 'ashuwp'), __('Options', 'ashuwp'), 'manage_options', 'invitation_code_options', array(&$this, 'invitation_code_options'));
    202204   
    203205    add_action( "load-$hook", array( $this, 'invitation_code_update' ) );
     
    385387    return $code_tem;
    386388  }
     389 
    387390  function invitation_code_add(){
    388391    $code_added = $this->invitation_code_generate();
     
    460463  <?php
    461464  }
     465 
     466  function invitation_code_options_update(){
     467    if ( isset( $_POST['ashuwp_invitation_code_options_field'] ) && wp_verify_nonce( $_POST['ashuwp_invitation_code_options_field'], 'ashuwp_invitation_code_options_action' )  ) {
     468     
     469      $new_options = $old_options = get_option('invitation_code');
     470      if( empty($new_options['show_help']) ){
     471        $new_options['show_help'] = '';
     472      }
     473      if( empty($new_options['help_content']) ){
     474        $new_options['help_content'] = '';
     475      }
     476     
     477      if( !empty($_POST['show_help']) ){
     478        $show_help = sanitize_text_field($_POST['show_help']);
     479        if( $new_options['show_help'] != $show_help ){
     480          $new_options['show_help'] = $show_help;
     481        }
     482      }
     483     
     484      if( !empty($_POST['help_content']) ){
     485        $v = trim( strip_tags($_POST['help_content'],'<a>') );
     486        $v = htmlspecialchars($v, ENT_COMPAT);
     487       
     488        if( $new_options['help_content'] != $v ){
     489          $new_options['help_content'] = $v;
     490        }
     491      }else{
     492        $new_options['help_content'] = '';
     493      }
     494     
     495      if( $new_options != $old_options ){
     496        update_option('invitation_code', $new_options);
     497       
     498        $return = array(
     499          'status' => true,
     500          'msg' => __('Options saved.','ashuwp'),
     501        );
     502      }
     503     
     504    }
     505   
     506    if(isset($return)){
     507      return $return;
     508    }else{
     509      return NULL;
     510    }
     511  }
     512  function invitation_code_options(){
     513    $return = $this->invitation_code_options_update();
     514   
     515    $invitation_code_options = get_option('invitation_code');
     516    $show_help = 0;
     517    if( !empty($invitation_code_options['show_help']) && $invitation_code_options['show_help']=='yes' ){
     518      $show_help = 1;
     519    }
     520   
     521    $help_content = '';
     522    if( !empty($invitation_code_options['help_content']) ){
     523      $help_content = stripslashes($invitation_code_options['help_content']);
     524      $help_content = htmlspecialchars_decode($help_content, ENT_QUOTES);
     525    }
     526  ?>
     527    <div class="wrap">
     528      <h1 class="wp-heading-inline"><?php _e('Options', 'ashuwp'); ?></h1>
     529      <hr class="wp-header-end">
     530      <?php
     531      if(!empty($return)){
     532        if($return['status']){
     533          $c = 'notice-success';
     534        }else{
     535          $c = 'notice-error';
     536        }
     537      ?>
     538      <div id="message" class="notice <?php echo $c; ?>">
     539        <p><?php echo $return['msg']; ?></p>
     540      </div>
     541      <?php
     542      }
     543      ?>
     544      <form action="" method="post">
     545        <table class="form-table">
     546          <tbody>
     547            <tr>
     548              <th><label for="code_prefix"><?php _e('Display help in register form.', 'ashuwp'); ?></label></th>
     549              <td>
     550                <p>
     551                  <label><input name="show_help" type="radio" value="yes" <?php if($show_help){ echo 'checked="checked"'; } ?>><?php _e('Display', 'ashuwp'); ?></label>
     552                  <br>
     553                  <label><input name="show_help" type="radio" value="no" <?php if(!$show_help){ echo 'checked="checked"'; } ?> ><?php _e('Not Display', 'ashuwp'); ?></label>
     554                </p>
     555              </td>
     556            </tr>
     557            <tr>
     558              <th><label for="code_length"><?php _e('Help content', 'ashuwp'); ?></label></th>
     559              <td>
     560                <p class="description"><?php _e('Only &lt;a&gt; allowed.', 'ashuwp'); ?></p>
     561                <textarea name="help_content" id="help_content" class="large-text code" rows="3"><?php echo $help_content; ?></textarea>
     562              </td>
     563            </tr>
     564          </tbody>
     565        </table>
     566        <p class="submit">
     567          <?php wp_nonce_field( 'ashuwp_invitation_code_options_action','ashuwp_invitation_code_options_field' ); ?>
     568          <input type="submit" name="submit" id="submit" class="button button-primary" value="Update">
     569        </p>
     570      </form>
     571    </div>
     572  <?php
     573  }
     574 
    462575  public static function get_instance() {
    463576    if ( ! isset( self::$instance ) ) {
  • ashuwp-invitaion-code/trunk/ashuwp_invitation_code.php

    r1715354 r1838366  
    33 * Plugin Name: Ashuwp invitaion code
    44 * Description: Ashuwp_Invitation_Code is a wordpress plugin, It helps adding invitation codes for your site.
    5  * Version: 1.1
     5 * Version: 1.2
    66 * Author: Ashuwp
    77 * Author URI: http://www.ashuwp.com/package/ashuwp_invitation_code
  • ashuwp-invitaion-code/trunk/includes/functions.php

    r1715291 r1838366  
    5454    return false;
    5555  }
     56}
     57
     58/**
     59* update a invite code status.
     60**/
     61function ashuwp_update_invitation_status( $id ){
     62  global $wpdb;
     63 
     64  if($id==''){
     65    return false;
     66  }
     67 
     68  $table_name = $wpdb->prefix . 'ashuwp_invitation_code';
     69  $sql = "select * from $table_name where id='$id'";
     70 
     71  $code = $wpdb->get_row($sql,'ARRAY_A');
     72  if(!empty($code)){
     73    $users = array();
     74    if(!empty($code['users'])){
     75      $users = code_users_string_to_array($code['users']);
     76    }
     77    $used = count($users);
     78     
     79    if( ($code['max']<=$used) && ($code['status']=='available') ){
     80      $code['status'] = 'finish';
     81      ashuwp_update_invitation_code( $code['id'], 'status', 'finish' );
     82    }
     83   
     84    $expiration = '';
     85    if( !empty( $code['expiration'] ) && $code['expiration']!='0000-00-00 00:00:00' ){
     86      $expiration = date_i18n( get_option( 'date_format' ).' '.get_option( 'time_format' ), strtotime($code['expiration']) );
     87       
     88      $now = time() + ( get_option( 'gmt_offset' ) * 3600 );
     89
     90      if( ($now >= strtotime($code['expiration'])) && ($code['status'] == 'available') ){
     91        $code['status'] = 'expired';
     92        ashuwp_update_invitation_code( $code['id'], 'status', 'expired' );
     93      }
     94    }
     95    return true;
     96   
     97  }else{
     98    return false;
     99  }
     100 
    56101}
    57102
  • ashuwp-invitaion-code/trunk/includes/invitation_code_login.php

    r1715291 r1838366  
    1010</p>
    1111<?php
     12  $invitation_code_options = get_option('invitation_code');
     13  if( !empty($invitation_code_options['show_help']) && $invitation_code_options['show_help']=='yes' ){
     14
     15  if( !empty($invitation_code_options['help_content']) ){
     16    $help_content = stripslashes($invitation_code_options['help_content']);
     17    $help_content = htmlspecialchars_decode($help_content, ENT_QUOTES);
     18    $help_content = str_replace(PHP_EOL, '<br>', $help_content);
     19    echo '<p style="margin:-16px 6px 16px 0;">'.$help_content.'</p>';
     20  }
     21  }
    1222}
    1323
     
    6575     
    6676      ashuwp_update_invitation_code( $code_id, 'users', $new_users );
     77      ashuwp_update_invitation_status( $code_id );
    6778      add_user_meta( $user_id, 'invitation_code', $result['code'], true );
    6879    }
     
    7990  <input type="text" name="invitation_code" id="invitation_code" value=""  />
    8091<?php
     92  $invitation_code_options = get_option('invitation_code');
     93  if( !empty($invitation_code_options['show_help']) && $invitation_code_options['show_help']=='yes' ){
     94
     95  if( !empty($invitation_code_options['help_content']) ){
     96    $help_content = stripslashes($invitation_code_options['help_content']);
     97    $help_content = htmlspecialchars_decode($help_content, ENT_QUOTES);
     98    $help_content = str_replace(PHP_EOL, '<br>', $help_content);
     99    echo $help_content;
     100  }
     101  }
    81102}
    82103
     
    131152    <p class="error"><?php echo $errmsg; ?></p>
    132153  <?php endif; ?>
    133   <input type="text" name="invitation_code" id="invitation_code" value=""  /><br />
     154  <input type="text" name="invitation_code" id="invitation_code" value=""  />
     155  <?php
     156  $invitation_code_options = get_option('invitation_code');
     157  if( !empty($invitation_code_options['show_help']) && $invitation_code_options['show_help']=='yes' ){
     158
     159  if( !empty($invitation_code_options['help_content']) ){
     160    $help_content = stripslashes($invitation_code_options['help_content']);
     161    $help_content = htmlspecialchars_decode($help_content, ENT_QUOTES);
     162    $help_content = str_replace(PHP_EOL, '<br>', $help_content);
     163    echo $help_content;
     164  }
     165  }
     166  ?>
     167  <br />
    134168  <?php
    135169  _e( '(Must be input.)', 'ashuwp' );
  • ashuwp-invitaion-code/trunk/readme.txt

    r1775541 r1838366  
    44Tags: Invitation code, Register
    55Requires at least: 4.5
    6 Tested up to: 4.8
    7 Stable tag:4.8
     6Tested up to: 4.9
     7Stable tag:4.9
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    4343Compatible with version less than php5.5
    4444
     45= 1.3 =
     46Add invitation options.
     47Fix some bugs.
     48
    4549== Upgrade Notice ==
    4650
     
    5357= 1.2 =
    5458Compatible with version less than php5.5
     59
     60= 1.3 =
     61Add invitation options.
     62Fix some bugs.
Note: See TracChangeset for help on using the changeset viewer.