Plugin Directory

Changeset 989738


Ignore:
Timestamp:
09/14/2014 10:01:52 PM (12 years ago)
Author:
ourvalley
Message:

Add ability for shortcode

Location:
health-progress
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • health-progress/trunk/health-progress.js

    r949106 r989738  
    11jQuery(document).ready(function($){
    22    $('#date').datepicker();
    3    
    4    
    53});
  • health-progress/trunk/health-progress.php

    r949850 r989738  
    33  Plugin Name: Health Progress
    44  Plugin URI: http://sandymcfadden.com/2014/07/16/health-progress-wordpress-plugin/
    5   Description: Creates a widget so you can display progress in healthy measurements.
     5  Description: Creates a widget / shortcode so you can display progress in healthy measurements.
    66  Author: Sandy McFadden
    7   Version: 1.2
     7  Version: 1.3
    88  Author URI: http://sandymcfadden.com
    99*/
     
    3333}
    3434
    35 function smhp_display($instance = null) {
     35function smhp_display_widget($instance = null) {
    3636  static $smhp_count = 1;
    3737 
     
    5959  $widget .= '  <td>'. __(@$options['field_'. $i . '_title'], 'smhp_widget_domain') .'</td>';
    6060  $widget .= '  <td>'. @$options['field_'. $i . '_start'] . __(@$options['field_'. $i . '_unit'], 'smhp_widget_domain') .'</td>';
    61   $widget .= '  <td>'. @$instance['field_' . $i . '_now'] . __(@$options['field_'. $i . '_unit'], 'smhp_widget_domain') .'</td>';
    62   $widget .= '  <td><strong>'. (@$options['field_'. $i . '_start'] - @$instance['field_' . $i . '_now']) . __(@$options['field_'. $i . '_unit'], 'smhp_widget_domain') .'</strong></td>';
     61  $widget .= '  <td>'. @$options['field_' . $i . '_now'] . __(@$options['field_'. $i . '_unit'], 'smhp_widget_domain') .'</td>';
     62  $widget .= '  <td><strong>'. (@$options['field_'. $i . '_start'] - @$options['field_' . $i . '_now']) . __(@$options['field_'. $i . '_unit'], 'smhp_widget_domain') .'</strong></td>';
    6363  $widget .= '</tr>';
    6464}
     
    9393      echo $args['before_title'] . $title . $args['after_title'];
    9494
    95     echo smhp_display($instance);
     95    echo smhp_display_widget($instance);
    9696    echo $args['after_widget'];
    9797}
     
    117117  </p>
    118118
     119
    119120<?php
    120 
    121   $num = intval($options['num']);
    122   for ($i = 1; $i <= $num; $i++) {
    123 ?>
    124  
    125  <p>
    126    <label for="<?php echo $this->get_field_id( 'field_' . $i . '_now' ); ?>">Current <?php echo __($options['field_'. $i . '_title'], 'smhp_widget_domain'); ?></label>
    127    <input class="widefat" id="<?php echo $this->get_field_id( 'field_' . $i . '_now' ); ?>" name="<?php echo $this->get_field_name( 'field_' . $i . '_now' ); ?>" type="text" value="<?php echo esc_attr( $instance['field_' . $i . '_now'] ); ?>"> <?php echo __($options['field_'. $i . '_unit'], 'smhp_widget_domain'); ?>
    128  </p>
    129  
    130 <?php
    131   }
    132 
    133121}
    134122
     
    137125    $instance = array();
    138126    $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
    139    
    140     foreach ($new_instance as $key => $value) {
    141       $instance[$key] = strip_tags( $value );
    142     }
     127
    143128    return $instance;
    144129  }
     
    154139
    155140
     141/**
     142* Display Shortcode
     143*/
     144
     145function smhp_display_shortcode($instance = null) {
     146  static $smhp_count = 1;
     147 
     148  $options = get_option('smhp_options', array() );
     149  if (empty($options)) {
     150    return '<p>You must input settings on the plugin settings page.</p>';
     151  }
     152 
     153  $start_date = $options['date'];
     154  $start_date = strtotime($start_date);
     155  $start_date = date("M/y", $start_date);
     156
     157  $shortcode = '  <div id="smhp_shortcode_'. $smhp_count .'" class="smhp_shortcode">
     158    <table id="smhp_shortcode_table_'. $smhp_count .'" class="smhp_shortcode_table">
     159      <tr>
     160        <th>&nbsp;</th>
     161        <th>'. $start_date .'</th>
     162        <th>'. __('Now', 'smhp_widget_domain') .'</th>
     163        <th>'. __('Lost', 'smhp_widget_domain') .'</th>
     164      </tr>';
     165     
     166$num = intval($options['num']);
     167for ($i = 1; $i <= $num; $i++) {
     168  $shortcode .= '<tr>';
     169  $shortcode .= '  <td>'. __(@$options['field_'. $i . '_title'], 'smhp_widget_domain') .'</td>';
     170  $shortcode .= '  <td>'. @$options['field_'. $i . '_start'] . __(@$options['field_'. $i . '_unit'], 'smhp_widget_domain') .'</td>';
     171  $shortcode .= '  <td>'. @$options['field_' . $i . '_now'] . __(@$options['field_'. $i . '_unit'], 'smhp_widget_domain') .'</td>';
     172  $shortcode .= '  <td><strong>'. (@$options['field_'. $i . '_start'] - @$options['field_' . $i . '_now']) . __(@$options['field_'. $i . '_unit'], 'smhp_widget_domain') .'</strong></td>';
     173  $shortcode .= '</tr>';
     174}
     175     
     176  $shortcode .= '
     177    </table>
     178   </div>';
     179
     180  $smhp_count++;
     181  return $shortcode;
     182}
    156183
    157184
     
    200227        $this->options = get_option( 'smhp_options' );
    201228
    202 
    203229        if (!isset($this->options['num']) || $this->options['num'] == '')
    204230          $this->options['num'] = 1;
    205231        ?>
    206232        <div class="wrap">
    207             <h2>Health Progress Settings</h2>           
    208             <form method="post" action="options.php">
     233            <h2>Health Progress Settings</h2>   
     234
     235            <form method="post" name="inital-settings" action="options.php">
     236              <input type="hidden" name="smhp_form" value="initial">
    209237            <?php
    210238                // This prints out all hidden setting fields
     
    292320            $new_input['field_'. $i .'_unit'] = sanitize_text_field($input['field_'. $i .'_unit']);
    293321            $new_input['field_'. $i .'_start'] = sanitize_text_field($input['field_'. $i .'_start']);
     322            $new_input['field_'. $i .'_now'] = sanitize_text_field($input['field_'. $i .'_now']);
    294323          }
    295324         
     
    324353        isset( $this->options['field_'. $field_num .'_unit'] ) ? esc_attr( $this->options['field_'. $field_num .'_unit']) : '' );
    325354      printf('<input type="text" id="field_'. $field_num .'_start" name="smhp_options[field_'. $field_num .'_start]" value="%s" placeholder="Starting Measurement (eg. 100)" />',
    326         isset( $this->options['field_'. $field_num .'_start'] ) ? esc_attr( $this->options['field_'. $field_num .'_start']) : '' );         
     355        isset( $this->options['field_'. $field_num .'_start'] ) ? esc_attr( $this->options['field_'. $field_num .'_start']) : '' );       
     356      printf('<input type="text" id="field_'. $field_num .'_now" name="smhp_options[field_'. $field_num .'_now]" value="%s" placeholder="Current Measurement (eg. 100)" />',
     357        isset( $this->options['field_'. $field_num .'_now'] ) ? esc_attr( $this->options['field_'. $field_num .'_now']) : '' );         
    327358    }
    328359   
     
    341372}
    342373
     374// Add shortcode
     375function get_sm_health_progress_shortcode($atts) {
     376  return smhp_display_shortcode();
     377}
     378
     379add_shortcode('sm_health_progress', 'get_sm_health_progress_shortcode');
     380
    343381if( is_admin() )
    344382    $smhp_settings_page = new smhp_settings_page();
  • health-progress/trunk/readme.txt

    r979984 r989738  
    1111Stable tag: 1.2
    1212
    13 Health Progress will add a widget to your site which will display your starting measurements and progress as you get healthy.
     13Health Progress will add a widget and shortcode to your site which will display your starting measurements and progress as you get healthy.
    1414
    1515== Description ==
     
    2828* You will then have that many fields available to you.
    2929* Set the date with the date picker for when these starting measurements were taken.
    30 * Input your fields and starting measurements.
    31 * For each measurement there are three fields. The title, the units, and the starting measurement.
    32 * The units can remain blank if you like and only digits should to in the starting measurement.
     30* Input your fields, starting measurements and current values.
     31* For each measurement there are four fields. The title, the units, the starting measurement and the current value.
     32* The units can remain blank if you like and only digits should to in the starting measurement and current value.
    3333* Submit the changes
    3434
    3535Next you can go to the Appearance then Widgets. You will see the widget availabe for you to add to your site.
    3636You can fill in the title you want to appear with this widget.
    37 Then you can fill out your current measurments for each that you are keeping track of.
     37
     38== Frequently Asked Questions ==
     39
     401. What shortcode do I use?
     41   **[sm_health_progress]**
    3842
    3943== Screenshots ==
    4044
    41 1. Enter settings and initial measurements
    42 2. Fill in the current measurements for the widget
    43 3. Example front end look
     451. Enter settings, initial measurements and current values
     462. Example front end look
    4447
    4548== Changelog ==
    4649
     50= 1.3 =
     51* Add shortcode of [sm_health_progress] to display progress.
     52* Move current values form from widget to settings page.
     53
    4754= 1.2 =
    4855* Updating readme.txt file with proper version and URI fields.
Note: See TracChangeset for help on using the changeset viewer.