Version Description
Download this release
Release Info
Developer | Otto42 |
Plugin | PHP Code Widget |
Version | 1.1 |
Comparing to | |
See all releases |
Version 1.1
- execphp.php +134 -0
- readme.txt +49 -0
- screenshot-1.png +0 -0
execphp.php
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Executable PHP widget
|
4 |
+
Description: Like the Text widget, but it will take PHP code as well. Heavily derived from the Text widget code in WordPress.
|
5 |
+
Author: Otto
|
6 |
+
Version: 1.1
|
7 |
+
Author URI: http://ottodestruct.com
|
8 |
+
Plugin URI: http://wordpress.org/extend/plugins/php-code-widget/
|
9 |
+
*/
|
10 |
+
/*
|
11 |
+
This program is free software; you can redistribute it and/or modify
|
12 |
+
it under the terms of the GNU General Public License version 2,
|
13 |
+
as published by the Free Software Foundation.
|
14 |
+
|
15 |
+
This program is distributed in the hope that it will be useful,
|
16 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
+
GNU General Public License for more details.
|
19 |
+
*/
|
20 |
+
|
21 |
+
function widget_execphp($args, $widget_args = 1) {
|
22 |
+
extract( $args, EXTR_SKIP );
|
23 |
+
if ( is_numeric($widget_args) )
|
24 |
+
$widget_args = array( 'number' => $widget_args );
|
25 |
+
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
|
26 |
+
extract( $widget_args, EXTR_SKIP );
|
27 |
+
|
28 |
+
$options = get_option('widget_execphp');
|
29 |
+
if ( !isset($options[$number]) )
|
30 |
+
return;
|
31 |
+
|
32 |
+
$title = $options[$number]['title'];
|
33 |
+
$text = apply_filters( 'widget_execphp', $options[$number]['text'] );
|
34 |
+
?>
|
35 |
+
<?php echo $before_widget; ?>
|
36 |
+
<?php if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
|
37 |
+
<div class="execphpwidget"><?php eval('?>'.$text); ?></div>
|
38 |
+
<?php echo $after_widget; ?>
|
39 |
+
<?php
|
40 |
+
}
|
41 |
+
|
42 |
+
function widget_execphp_control($widget_args) {
|
43 |
+
global $wp_registered_widgets;
|
44 |
+
static $updated = false;
|
45 |
+
|
46 |
+
if ( is_numeric($widget_args) )
|
47 |
+
$widget_args = array( 'number' => $widget_args );
|
48 |
+
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
|
49 |
+
extract( $widget_args, EXTR_SKIP );
|
50 |
+
|
51 |
+
$options = get_option('widget_execphp');
|
52 |
+
if ( !is_array($options) )
|
53 |
+
$options = array();
|
54 |
+
|
55 |
+
if ( !$updated && !empty($_POST['sidebar']) ) {
|
56 |
+
$sidebar = (string) $_POST['sidebar'];
|
57 |
+
|
58 |
+
$sidebars_widgets = wp_get_sidebars_widgets();
|
59 |
+
if ( isset($sidebars_widgets[$sidebar]) )
|
60 |
+
$this_sidebar =& $sidebars_widgets[$sidebar];
|
61 |
+
else
|
62 |
+
$this_sidebar = array();
|
63 |
+
|
64 |
+
foreach ( $this_sidebar as $_widget_id ) {
|
65 |
+
if ( 'widget_execphp' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
|
66 |
+
$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
|
67 |
+
unset($options[$widget_number]);
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
foreach ( (array) $_POST['widget-execphp'] as $widget_number => $widget_text ) {
|
72 |
+
$title = strip_tags(stripslashes($widget_text['title']));
|
73 |
+
if ( current_user_can('unfiltered_html') )
|
74 |
+
$text = stripslashes( $widget_text['text'] );
|
75 |
+
else
|
76 |
+
$text = stripslashes(wp_filter_post_kses( $widget_text['text'] ));
|
77 |
+
$options[$widget_number] = compact( 'title', 'text' );
|
78 |
+
}
|
79 |
+
|
80 |
+
update_option('widget_execphp', $options);
|
81 |
+
$updated = true;
|
82 |
+
}
|
83 |
+
|
84 |
+
if ( -1 == $number ) {
|
85 |
+
$title = '';
|
86 |
+
$text = '';
|
87 |
+
$number = '%i%';
|
88 |
+
} else {
|
89 |
+
$title = attribute_escape($options[$number]['title']);
|
90 |
+
$text = format_to_edit($options[$number]['text']);
|
91 |
+
}
|
92 |
+
?>
|
93 |
+
<p>
|
94 |
+
<input class="widefat" id="execphp-title-<?php echo $number; ?>" name="widget-execphp[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
|
95 |
+
<p>PHP Code (MUST be enclosed in <?php and ?> tags!):</p>
|
96 |
+
<textarea class="widefat" rows="16" cols="20" id="execphp-text-<?php echo $number; ?>" name="widget-execphp[<?php echo $number; ?>][text]"><?php echo $text; ?></textarea>
|
97 |
+
<input type="hidden" id="execphp-submit-<?php echo $number; ?>" name="execphp-submit-<?php echo $number; ?>" value="1" />
|
98 |
+
</p>
|
99 |
+
<?php
|
100 |
+
}
|
101 |
+
|
102 |
+
function widget_execphp_register() {
|
103 |
+
|
104 |
+
// Check for the required API functions
|
105 |
+
if ( !function_exists('wp_register_sidebar_widget') || !function_exists('wp_register_widget_control') )
|
106 |
+
return;
|
107 |
+
|
108 |
+
if ( !$options = get_option('widget_execphp') )
|
109 |
+
$options = array();
|
110 |
+
$widget_ops = array('classname' => 'widget_execphp', 'description' => __('Arbitrary text, HTML, or PHP code'));
|
111 |
+
$control_ops = array('width' => 460, 'height' => 350, 'id_base' => 'execphp');
|
112 |
+
$name = __('PHP Code');
|
113 |
+
|
114 |
+
$id = false;
|
115 |
+
foreach ( array_keys($options) as $o ) {
|
116 |
+
// Old widgets can have null values for some reason
|
117 |
+
if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) )
|
118 |
+
continue;
|
119 |
+
$id = "execphp-$o"; // Never never never translate an id
|
120 |
+
wp_register_sidebar_widget($id, $name, 'widget_execphp', $widget_ops, array( 'number' => $o ));
|
121 |
+
wp_register_widget_control($id, $name, 'widget_execphp_control', $control_ops, array( 'number' => $o ));
|
122 |
+
}
|
123 |
+
|
124 |
+
// If there are none, we register the widget's existance with a generic template
|
125 |
+
if ( !$id ) {
|
126 |
+
wp_register_sidebar_widget( 'execphp-1', $name, 'widget_execphp', $widget_ops, array( 'number' => -1 ) );
|
127 |
+
wp_register_widget_control( 'execphp-1', $name, 'widget_execphp_control', $control_ops, array( 'number' => -1 ) );
|
128 |
+
}
|
129 |
+
|
130 |
+
}
|
131 |
+
|
132 |
+
add_action( 'widgets_init', 'widget_execphp_register' );
|
133 |
+
|
134 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== PHP Code Widget ===
|
2 |
+
Contributors: Otto
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=otto%40ottodestruct%2ecom
|
4 |
+
Tags: php, widget, execphp
|
5 |
+
Requires at least: 2.5
|
6 |
+
Tested up to: 2.7
|
7 |
+
Stable tag: 1.1
|
8 |
+
|
9 |
+
Like the Text widget, but also allows working PHP code to be inserted.
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
The normal Text widget allows you to insert arbitrary Text and/or HTML code.
|
14 |
+
This allows that too, but also parses any inserted PHP code and executes it.
|
15 |
+
This makes it easier to migrate to a widget-based theme.
|
16 |
+
|
17 |
+
All PHP code must be enclosed in the standard <?php and ?> tags for it to be
|
18 |
+
recognized.
|
19 |
+
|
20 |
+
== Installation ==
|
21 |
+
|
22 |
+
1. Upload `execphp.php` to the `/wp-content/plugins/` directory
|
23 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
24 |
+
1. Use the widget like any other widget.
|
25 |
+
|
26 |
+
== Frequently Asked Questions ==
|
27 |
+
|
28 |
+
= There's some kind of error on line 27! =
|
29 |
+
|
30 |
+
That error means that your PHP code is incorrect or otherwise broken.
|
31 |
+
|
32 |
+
= No, my code is fine! =
|
33 |
+
|
34 |
+
No, it's not.
|
35 |
+
|
36 |
+
Really.
|
37 |
+
|
38 |
+
This widget has no bugs, it's about the simplest widget one can possibly
|
39 |
+
make. Any errors coming out of the "execphp,php" file are errors in code you
|
40 |
+
put into one of the widgets. The reason that it shows the error being in the
|
41 |
+
execphp.php file is because that is where your code is actually being run
|
42 |
+
from.
|
43 |
+
|
44 |
+
So, if it says that you have an error on line 27, I assure you, the problem
|
45 |
+
is yours. Please don't email me about that error.
|
46 |
+
|
47 |
+
== Screenshots ==
|
48 |
+
|
49 |
+
1. The widgets screen showing two PHP code widgets in use.
|
screenshot-1.png
ADDED
Binary file
|