<?php
/*
Plugin Name: Rotate the logos!
Plugin URI: http://www.pagelines.com
Author: PageLines
Author URI: http://www.pagelines.com
Description: Rotates your logo!
PageLines: true
Version: 0.1
*/
class PageLinesRotate {
/**
* Construct, always run when class is initiated
*
*/
function __construct() {
if ( is_admin() )
$this->admin_setup();
else
add_action( 'init', array( $this, 'rotate_filter' ) );
}
function rotate_filter() {
$max = ploption( 'pagelines_rotates_max' );
if ( ! $max )
$max = 2;
$this->rand = rand( 1, $max );
add_filter( 'ploption_pagelines_custom_logo', array( $this, 'do_rotate_image' ), 10, 2 );
add_filter( 'ploption_pagelines_custom_logo_url', array( $this, 'do_rotate_image_url' ), 10, 2 );
}
function do_rotate_image_url( $key, $o ) {
$url = ploption( "pagelines_rotates_url_{$this->rand}" );
if ( $url ) { return $url;
}
return get_ploption( $key );
}
function do_rotate_image( $key, $o ) {
$img = ploption( "pagelines_rotates_img_{$this->rand}" );
if ( $img ) { return $img;
}
return get_ploption( $key );
}
function admin_setup() {
add_action( 'admin_init', array( &$this, 'admin_page' ) );
}
function admin_page() {
pl_add_options_page( array(
'name' => 'rotator',
'raw' => $this->rotate_intro(),
'title' => 'Rotator Instructions.'
) );
pl_global_option( array( 'menu' => 'rotator', 'options' => $this->rotate_options(), 'location' => 'bottom' ) );
}
function rotate_options() {
$rotates_max = ploption( 'pagelines_rotates_max' );
if ( ! $rotates_max )
$rotates_max = 2;
$options = array(
'pagelines_rotates_opts' => array(
'type' => 'multi_option',
'title' => 'Rotate options...',
'selectvalues' => array(
'pagelines_rotates_max' => array(
'default' => 2,
'inputlabel' => 'How many?',
'type' => 'count_select',
'count_start' => 2,
'count_number' => 100,
)
),
) );
for($i = 1; $i <= $rotates_max; $i++) {
$options['pagelines_rotates_opts']['selectvalues']["pagelines_rotates_img_{$i}"] = array(
'type' => 'image_upload',
'title' => sprintf( 'Image number %s', $i )
);
$options['pagelines_rotates_opts']['selectvalues']["pagelines_rotates_url_{$i}"] = array( 'type' => 'text',
'inputlabel' => sprintf( 'Url for Image number %s', $i )
);
}
return $options;
}
function rotate_intro() {
return '<p>Select how many random images below, then simply upload them and add a URL. Simples.</p>';
}
} // class end
// this starts the plugin code.
new PageLinesRotate;