WordPress.org

Plugin Directory

Changeset 600208


Ignore:
Timestamp:
09/17/12 19:12:00 (5 years ago)
Author:
mltsy
Message:

Added settings page for network settings, updated wuthor information, and marked as v0.3

Location:
flickr-header/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • flickr-header/trunk/flickr-header.php

    r598781 r600208  
    44    Plugin URI: http://wordpress.org/extend/plugins/flickr-header/ 
    55    Description: Lets you pick a Creative Commons picture (or pictures) from Flickr to use as your WordPress header image(s). 
    6     Version: 0.2 
    7     Author: Joe Marty 
    8     Author URI: https://github.com/mltsy 
     6    Version: 0.3 
     7    Author: OwnLocal 
     8    Author URI: http://www.ownlocal.com 
    99    License: GPLv2 or any later version 
    1010*/ 
    1111 
    12 /*  Copyright 2012  Joe Marty  (mltsy) 
     12/*  Copyright 2012  OwnLocal 
    1313 
    1414    This program is free software; you can redistribute it and/or modify 
     
    3737  var $page; 
    3838  private $flickr_api_key; 
     39  private $api_key_scope; 
    3940 
    4041  const MIN_HEADER_WIDTH = 1000; 
     
    4445    add_action('init', array($this, 'capture_search_requests'), 20); 
    4546    add_action('admin_menu', array($this, 'setup_admin_ui')); 
     47    add_action('network_admin_menu', array($this, 'setup_network_admin_ui')); 
     48    add_action('network_admin_edit_flickr_header_settings', array($this, 'save_network_settings')); 
    4649    add_action('custom_header_options', array($this, 'header_options_form')); 
    4750    add_action('wp_enqueue_scripts', array($this, 'add_stylesheet') ); 
     
    4952 
    5053  function init() { 
    51     $this->flickr_api_key = get_option('flickr-header-api-key'); 
     54    $this->api_key_scope = 'network'; 
     55    $this->flickr_api_key = get_site_option('flickr-header-api-key'); 
     56    if (!$this->flickr_api_key) { 
     57      $this->api_key_scope = 'blog'; 
     58      $this->flickr_api_key = get_option('flickr-header-api-key'); 
     59    } 
     60  } 
     61 
     62  function setup_network_admin_ui() { 
     63    add_submenu_page('settings.php', 'Flickr Header', 'Flickr Header', 'manage_network_options', 'flickr-header-settings', array($this, 'network_options_form')); 
     64  } 
     65 
     66  function network_options_form() { 
     67    if (!current_user_can('manage_network_options')) return false; 
     68    $api_key = get_site_option('flickr-header-api-key'); 
     69    echo "<h2>Flickr Header - Network Settings</h2>"; 
     70    echo "Use this page to set the API key across all sites in this network, to eliminate the ened for individual sites to enter an API key:<br/>\n"; 
     71    echo "(You can <a href='http://www.flickr.com/services/apps/create/apply' target='_blank'>get a Flickr API key here</a>)<br/><br/>\n"; 
     72    echo "<form action='edit.php?action=flickr_header_settings' method='post'>\n"; 
     73    wp_nonce_field('flickr-header-network-settings'); 
     74    echo "Network-wide API-key: <input type='text' name='flickr_header_api_key' value='$api_key'>\n"; 
     75    submit_button('Update Key'); 
     76    echo "</form>"; 
     77  } 
     78 
     79  function save_network_settings() { 
     80    // Verify authenticity 
     81    check_admin_referer('flickr-header-network-settings'); 
     82    if (!current_user_can('manage_network_options')) return false; 
     83 
     84    //Save the settings 
     85    $api_key = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['flickr_header_api_key']); //Strip out non alpha-numberic chars 
     86    update_site_option('flickr-header-api-key', $api_key); 
     87 
     88    //Redirect back to the settings page 
     89    wp_redirect(add_query_arg(array('page' => 'flickr-header-settings', 'updated' => 'true'), network_admin_url('settings.php'))); 
     90    exit(); 
    5291  } 
    5392 
     
    178217        </div></td> 
    179218      </tr> 
    180       <tr> 
    181         <th scope="row">API Key</th> 
    182         <td> 
    183           <form method="post" action="<?php echo esc_attr(add_query_arg('action', 'update-key')); ?>"> 
    184           <?php 
    185             $key = $this->flickr_api_key; 
    186             if (!empty($key)) {  
    187               $masked_key = substr($key,0,2)."**********".substr($key,-4); 
    188               echo "Current: <b>$masked_key</b><br/>"; 
    189             } 
    190           ?> 
    191           Update: <input type="text" name="flickrHeader[api_key]"> 
    192           <?php submit_button('Update API key', 'secondary'); ?> 
    193           </form> 
    194         </td> 
    195       </tr> 
     219      <?php if ('blog' == $this->api_key_scope) { ?> 
     220        <tr> 
     221          <th scope="row"> 
     222            API Key<br/> 
     223            (<a href='http://www.flickr.com/services/apps/create/apply' taget='_blank'>Get one here</a>)</th> 
     224          <td> 
     225            <form method="post" action="<?php echo esc_attr(add_query_arg('action', 'update-key')); ?>"> 
     226            <?php 
     227              $key = $this->flickr_api_key; 
     228              if (!empty($key)) {  
     229                $masked_key = substr($key,0,2)."**********".substr($key,-4); 
     230                echo "Current: <b>$masked_key</b><br/>"; 
     231              } 
     232            ?> 
     233            Update: <input type="text" name="flickrHeader[api_key]"> 
     234            <?php submit_button('Update API key', 'secondary'); ?> 
     235            </form> 
     236          </td> 
     237        </tr> 
     238      <?php } //end API key scope check ?> 
    196239      <tr> 
    197240        <th scope="row">Search For Images:</th> 
  • flickr-header/trunk/readme.txt

    r598784 r600208  
    11=== Flickr Header === 
    2 Contributors: mltsy 
     2Contributors: ownlocal, mltsy 
    33Tags: flickr, header, custom 
    44Tested up to: 3.4.1 
Note: See TracChangeset for help on using the changeset viewer.