Plugin Directory

Changeset 1544877


Ignore:
Timestamp:
12/02/2016 10:36:55 PM (9 years ago)
Author:
theode
Message:

capabilities added

Location:
traffic-lights
Files:
12 added
4 edited

Legend:

Unmodified
Added
Removed
  • traffic-lights/trunk/draw-traffic-lights.php

    r810729 r1544877  
    22
    33
    4 if( function_exists('user_begins_to_work')){
    5 $all_users=get_users();
    6 $somebody_is_green=false;
    7 $green=false;
    8 foreach($all_users as $user){
    94
    10 $the_user_id=$user->data->ID;
    11 $in_office=get_user_meta($the_user_id,"in_office", true);
    12 $in_pause=get_user_meta($the_user_id,"in_pause", true);
     5if
     6( function_exists('user_begins_to_work'))
     7{
     8    $all_users=get_users();
     9    $somebody_is_green=false;
     10    $green=false;
     11    foreach
     12    ($all_users as $user)
     13    {
     14        $the_user_id=$user->data->ID;
     15        $in_office=get_user_meta($the_user_id, "in_office", true);
     16        $in_pause=get_user_meta($the_user_id, "in_pause", true);
    1317
    14 if ($in_office=="yes" && $in_pause=="no")
    15 {
    16 update_option('ampel','gruen');
    17 $green=true;
    18 break;
    19 }else if($in_pause=="yes" && $green==false){
    20     update_option('ampel','gelb');
    21     break;
    22    
    23 }else{
    24     update_option('ampel','rot');
    25    
    26    
    27 }}
     18        if ($in_office=="yes" && $in_pause=="no")
     19        {
     20            update_option('ampel', 'gruen');
     21            $green=true;
     22            break;
     23        }else if
     24            ($in_pause=="yes" && $green==false)
     25            {
     26                update_option('ampel', 'gelb');
     27                break;
    2828
     29            }else
     30        {
     31            update_option('ampel', 'rot');
     32
     33        }}
    2934
    3035}
     36// Eine Funktion um eine Ampel anzuzeigen
     37function draw_traffic_light()
     38{
     39    echo "<div style=\"line-height:0px;padding:0;text-decoration:none;\">";
     40    $ampel_url=plugins_url( 'bilder/' , __FILE__ );
    3141
     42    if
     43    (isset($_GET['ampel']) && current_user_can( 'change_traffic_light',0 ) )
     44    {
     45        update_option('ampel', $_GET['ampel']);
     46    }
     47    $farbe=get_option('ampel');
    3248
    33 
    34 // Eine Funktion um eine Ampel anzuzeigen
    35 function draw_traffic_light(){
    36 echo "<div style=\"line-height:0px;padding:0;text-decoration:none;\">";
    37 $ampel_url=plugins_url( 'bilder/' , __FILE__ );
    38 
    39 if(isset($_GET['ampel']) && is_user_logged_in() ){
    40 update_option('ampel',$_GET['ampel']);
    41 }
    42 
    43 $farbe=get_option('ampel');
    44 
    45 if ($farbe=="rot"){
    46 echo "<img src=\"".$ampel_url."red.png\" /><br />";
    47 }else{
    48 if ( is_user_logged_in() ){echo "<a href=\"?ampel=rot\">";}else{}
    49 echo "<img src=\"".$ampel_url."red-off.png\" />";
    50 if ( is_user_logged_in() ){echo "</a>";}
    51 echo "<br />";
    52 }
    53 
    54 if ($farbe=="gelb"){
    55 echo "<img src=\"".$ampel_url."yellow.png\" /><br />";
    56 }else{
    57 if ( is_user_logged_in() ){echo "<a href=\"?ampel=gelb\">";}
    58 echo "<img src=\"".$ampel_url."yellow-off.png\" />";
    59 if ( is_user_logged_in() ){echo "</a>";}
    60 echo "<br />";
    61 }
    62 
    63 if ($farbe=="gruen"){
    64 echo "<img src=\"".$ampel_url."green.png\" /><br />";
    65 }else{
    66 if ( is_user_logged_in() ){echo "<a href=\"?ampel=gruen\">";}
    67 echo "<img src=\"".$ampel_url."green-off.png\" />";
    68 if ( is_user_logged_in() ){echo "</a>";}
    69 echo "<br />";
    70 }
    71 
    72 echo "</div>";
    73 
     49    if ($farbe=="rot")
     50    {
     51        echo "<img src=\"".$ampel_url."red.png\" /><br />";
     52    }else
     53    {
     54        if ( current_user_can( 'change_traffic_light',0 ) )
     55            {echo "<a href=\"?ampel=rot\">";
     56        }else
     57            {}
     58        echo "<img src=\"".$ampel_url."red-off.png\" />";
     59        if ( current_user_can( 'change_traffic_light',0 ) )
     60            {echo "</a>";
     61        }
     62        echo "<br />";
     63    }
     64    if ($farbe=="gelb")
     65    {
     66        echo "<img src=\"".$ampel_url."yellow.png\" /><br />";
     67    }else
     68    {
     69        if ( current_user_can( 'change_traffic_light',0 ) )
     70            {echo "<a href=\"?ampel=gelb\">";
     71        }
     72        echo "<img src=\"".$ampel_url."yellow-off.png\" />";
     73        if ( current_user_can( 'change_traffic_light',0 ) )
     74            {echo "</a>";
     75        }
     76        echo "<br />";
     77    }
     78    if ($farbe=="gruen")
     79    {
     80        echo "<img src=\"".$ampel_url."green.png\" /><br />";
     81    }else
     82    {
     83        if ( current_user_can( 'change_traffic_light',0 ) )
     84            {echo "<a href=\"?ampel=gruen\">";
     85        }
     86        echo "<img src=\"".$ampel_url."green-off.png\" />";
     87        if ( current_user_can( 'change_traffic_light',0 ) )
     88            {echo "</a>";
     89        }
     90        echo "<br />";
     91    }
     92    echo "</div>";
    7493
    7594}
  • traffic-lights/trunk/readme.txt

    r1302538 r1544877  
    44Tags: traffic,lights,status
    55Requires at least: 3.0
    6 Tested up to: 4.5
    7 Stable tag: 0.13
     6Tested up to: 4.7
     7Stable tag: 0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3939== Changelog ==
    4040
     41= 0.2 =  capabilities added
    4142= 0.1 =  Initial release
  • traffic-lights/trunk/traffic-lights-widget.php

    r809637 r1544877  
    11<?php
    2 
    32class traffic_light_Widget extends WP_Widget {
    4 
    53    /**
    64     * Register widget with WordPress.
    75     */
    8     function __construct() {
     6    function __construct()
     7    {
    98        parent::__construct(
    109            'traffic_light_Widget', // Base ID
     
    2221     * @param array $instance Saved values from database.
    2322     */
    24     public function widget( $args, $instance ) {
     23    public function widget( $args, $instance )
     24    {
    2525        $title = apply_filters( 'widget_title', $instance['title'] );
    2626
     
    3939     * @param array $instance Previously saved values from database.
    4040     */
    41     public function form( $instance ) {
    42         if ( isset( $instance[ 'title' ] ) ) {
     41    public function form( $instance )
     42    {
     43        if ( isset( $instance[ 'title' ] ) )
     44        {
    4345            $title = $instance[ 'title' ];
    4446        }
    45         else {
     47        else
     48        {
    4649            $title = __( 'New title', 'text_domain' );
    4750        }
    48         ?>
     51?>
    4952        <p>
    50         <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    51         <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
     53        <label for="<?php echo $this->get_field_id( 'title' );
     54        ?>"><?php _e( 'Title:' );
     55        ?></label>
     56        <input class="widefat" id="<?php echo $this->get_field_id( 'title' );
     57        ?>" name="<?php echo $this->get_field_name( 'title' );
     58        ?>" type="text" value="<?php echo esc_attr( $title );
     59        ?>" />
    5260        </p>
    53         <?php 
     61        <?php
    5462    }
    5563
     
    6472     * @return array Updated safe values to be saved.
    6573     */
    66     public function update( $new_instance, $old_instance ) {
     74    public function update( $new_instance, $old_instance )
     75    {
    6776        $instance = array();
    6877        $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
     
    7281
    7382} // class traffic_light_Widget
    74 
    75 
    76 
    7783?>
  • traffic-lights/trunk/traffic-lights.php

    r898144 r1544877  
    44Plugin URI: http://www.wp-plugin-dev.com
    55Description: A simple Traffic Light to show some state for visitor
    6 Version: 0.13
     6Version: 0.2
    77Author: wp-plugin-dev.com
    88Author URI: http://www.wp-plugin-dev.com
    99License: GPLv2 or later
    10 
    1110Graphic from http://www.openclipart.org/
    12 
    1311Dies ist eine einfache Ampel. Hauptsächlich ein Lernprojekt.
    1412Jedes WordPress Plugin hat die oben gemachten Angaben
    15 
    1613*/
    17 
    1814// um das Haupt Plugin File nicht so sehr mit Code voll zu machen
    1915// rufen wir nur die anderen Files auf.
     16// Das Dokument was die Ampel malt
     17include 'draw-traffic-lights.php';
     18include 'traffic-lights-widget.php';
    2019
    21 // Das Dokument was die Ampel malt
    22 include('draw-traffic-lights.php');
    23 include('traffic-lights-widget.php');
     20register_activation_hook( __FILE__, 'add_traffic_lights_caps' );
     21
     22function add_traffic_lights_caps() {
     23       
     24       $roles = array ('subscriber','author','editor','contributor','administrator');
     25       
     26    foreach ($roles as $role)
     27    {
     28        $role = get_role( $role );
     29        $role->add_cap( 'change_traffic_light' );
     30    }
     31}
     32
    2433
    2534// register traffic_light_Widget widget
    26 function register_traffic_light_Widget() {
    27     register_widget( 'traffic_light_Widget' );
     35function register_traffic_light_Widget()
     36{
     37    register_widget( 'traffic_light_Widget' );
    2838}
     39
    2940add_action( 'widgets_init', 'register_traffic_light_Widget' );
    3041
    3142// Function that outputs the contents of the dashboard widget
    32 function dashboard_widget_function_traffic_light() {
     43function dashboard_widget_function_traffic_light()
     44{
    3345    draw_traffic_light();
    3446}
    3547
    3648// Function used in the action hook
    37 function add_dashboard_widgets_tl() {
     49function add_dashboard_widgets_tl()
     50{
    3851    wp_add_dashboard_widget('dashboard_widget', 'Traffic Light Dashboard Widget', 'dashboard_widget_function_traffic_light');
    3952}
     
    4255add_action('wp_dashboard_setup', 'add_dashboard_widgets_tl' );
    4356
    44 add_shortcode("trafficlights","trafficlight_shorty");
     57add_shortcode("trafficlights", "trafficlight_shorty");
    4558
    46 function trafficlight_shorty(){
    47 ob_start();
    48 draw_traffic_light();
    49 return ob_get_clean();
     59function trafficlight_shorty()
     60{
     61    ob_start();
     62    draw_traffic_light();
     63    return ob_get_clean();
    5064}
    5165
Note: See TracChangeset for help on using the changeset viewer.