コード例 #1
0
ファイル: widget.php プロジェクト: joffcrabtree/don8
    /**
     * Fires on the backend, inside of the widget. Used for customizing the current widget's options.
     *
     * If your widget doesn't need any options, just delete this whoooole function.
     *
     * @param array $instance The current widget instance.
     *
     * @return string|void Generally nothing.
     */
    public function form($instance)
    {
        // Get options
        $title = isset($instance['title']) ? $instance['title'] : '';
        $email = isset($instance['email']) ? $instance['email'] : '';
        $cause = isset($instance['cause']) ? $instance['cause'] : '';
        $value = isset($instance['value']) ? $instance['value'] : '';
        $currency = isset($instance['currency']) ? $instance['currency'] : '';
        $image = isset($instance['image']) ? $instance['image'] : '';
        // Output the HTML
        // These can be confusing. Just copy/paste them as needed and be sure to change the txt where needed (like in
        // the first one, change "title" wherever it exists)
        ?>
		<!-- The widget title -->
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
">Title:</label>
			<input type="text" name="<?php 
        echo $this->get_field_name('title');
        ?>
" class="widefat"
			       id="<?php 
        echo $this->get_field_id('title');
        ?>
" value="<?php 
        echo esc_attr($title);
        ?>
"/>
		</p>
		<!-- The paypal email -->
		<p>
			<label for="<?php 
        echo $this->get_field_id('email');
        ?>
">Email:</label>
			<input type="text" name="<?php 
        echo $this->get_field_name('email');
        ?>
" class="widefat"
			       id="<?php 
        echo $this->get_field_id('email');
        ?>
" value="<?php 
        if (!empty($email)) {
            echo esc_attr($email);
        } else {
            echo get_option('don8_paypal_email');
        }
        ?>
"/>
		</p>
		<!-- The cause -->
		<p>
			<label for="<?php 
        echo $this->get_field_id('cause');
        ?>
">Cause:</label>
			<input type="text" name="<?php 
        echo $this->get_field_name('cause');
        ?>
" class="widefat"
			       id="<?php 
        echo $this->get_field_id('cause');
        ?>
" value="<?php 
        if (!empty($cause)) {
            echo esc_attr($cause);
        } else {
            echo get_option('don8_cause');
        }
        ?>
"/>
		</p>
		<!-- The currency code -->
		<p>
			<label for="<?php 
        echo $this->get_field_id('currency');
        ?>
">Currency:</label>
			<input type="text" name="<?php 
        echo $this->get_field_name('currency');
        ?>
" class="widefat"
			       id="<?php 
        echo $this->get_field_id('currency');
        ?>
" value="<?php 
        if (!empty($currency)) {
            echo esc_attr($currency);
        } else {
            echo get_option('don8_currency');
        }
        ?>
"/>
		</p>
		<!-- The amount -->
		<p>
			<label for="<?php 
        echo $this->get_field_id('value');
        ?>
">Amount:</label>
			<input type="text" name="<?php 
        echo $this->get_field_name('value');
        ?>
" class="widefat"
			       id="<?php 
        echo $this->get_field_id('value');
        ?>
" value="<?php 
        if (!empty($value)) {
            echo esc_attr($value);
        } else {
            echo get_option('don8_value');
        }
        ?>
"/>
		</p>

		<!-- An image uploader -->
		<p>
			<?php 
        don8_media_uploader($this->get_field_name('image'), $image);
        ?>
		</p>
	<?php 
    }
コード例 #2
0
ファイル: admin.php プロジェクト: joffcrabtree/don8
    public function body()
    {
        ?>
		<div class="wrap">
			<?php 
        screen_icon();
        ?>
			<h2>Don8 Options</h2>

			<form method="post" action="options.php">
				<?php 
        settings_fields('don8_settings');
        $email = get_option('don8_paypal_email');
        $currency = get_option('don8_currency');
        $button = get_option('don8_button');
        ?>
				<h3>Donation default values</h3>

				<p>Here you can set the default values for your donation button.</p>
				<table class="form-table">
					<tr valign="top">
						<th scope="row"><label for="don8_paypal_email">Paypal e-mail</label></th>
						<td><input type="text" id="don8_paypal_email" name="don8_paypal_email"
						           value="<?php 
        if (is_email($email)) {
            echo $email;
        } elseif (empty($email)) {
        } else {
            echo 'Not a valid email';
        }
        ?>
"/></td>
					</tr>
					<tr valign="top">
						<th scope="row"><label for="don8_cause">Cause</label></th>
						<td><input type="text" id="don8_cause" name="don8_cause"
						           value="<?php 
        echo get_option('don8_cause');
        ?>
"/></td>
					</tr>
					<tr valign="top">
						<th scope="row"><label for="don8_currency">Currency Code</label></th>
						<td><input type="text" id="don8_currency" name="don8_currency"
						           value="<?php 
        echo $currency;
        ?>
"/></td>
					</tr>
					<tr valign="top">
						<th scope="row"><label for="don8_value">Amount</label></th>
						<td><input type="text" id="don8_value" name="don8_value"
						           value="<?php 
        echo get_option('don8_value');
        ?>
"/></td>
					</tr>
					<tr valign="top">
						<th scope="row"><label for="don8_button">Button image</label></th>
						<td><?php 
        don8_media_uploader('don8_button', $button);
        ?>
</td>
					</tr>
				</table>
				<?php 
        submit_button();
        ?>
			</form>
		</div>
	<?php 
    }