來喔!一起來開發WP外掛吧!!

LINEで送る
[`evernote` not found]

大部分的人應該對WP都多多少少有點”恩 如果有個….的外掛就好了!”這樣的念頭
但往往都卡在沒有著力點無從下手而行人止步
不過有人開發出這樣的範例可以拿來開發:WordPress Plugin Templates

官網有提供範例的壓縮檔可以下載
說時遲那是快的第二版 檔案下載

裡面包含三個檔案:

main.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/*
Plugin Name: Your Plugin Title
Plugin URI: http://your-url.com/plugin-name/
Description: Your super awesome, catchy, and descriptive description
Version: 1.0.0
Author: You!
Author URI: http://your-url.com/
*/
 
/*
Change log
 
1.0.0
 - Achievement
 - Achievement
 
Beta 3
 - Achievement
 - Achievement
 - Achievement
 
Beta 2
 - Achievement
 - Achievement
 - Achievement
 - Achievement
 
Beta 1
 - Achievement
 - Achievement
 
Alpha 1
 - Used the plugin template from FS
 
*/
 
// Some Defaults
$var1				= '';
$var2				= '';
$var3				= array();
$var4				= '';
 
// Put our defaults in the "wp-options" table
add_option("***-var1", $var1);
add_option("***-var2", $var2);
add_option("***-var3", $var3);
add_option("***-var4", $var4);
 
// Start the plugin
if ( ! class_exists( 'Your_Plugin' ) ) {
 
	class Your_Plugin {
 
		// prep options page insertion
		function add_config_page() {
			global $wpdb;
			if ( function_exists('add_submenu_page') ) {
				add_options_page('Plugin Title', 'Plugin Name', 10, basename(__FILE__), array('Your_Plugin','config_page'));
				add_filter( 'plugin_action_links', array( 'Your_Plugin', 'filter_plugin_actions' ), 10, 2 );
				add_filter( 'ozh_adminmenu_icon', array( 'Your_Plugin', 'add_ozh_adminmenu_icon' ) );
			}
		}
 
		// Place in Settings Option List
		function filter_plugin_actions( $links, $file ){
			//Static so we don't call plugin_basename on every plugin row.
			static $this_plugin;
			if ( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
 
			if ( $file == $this_plugin ){
				$settings_link = '<a href="options-general.php?page=main.php">' . __('Settings') . '</a>';
				array_unshift( $links, $settings_link ); // before other links
			}
			return $links;
		}
 
		function config_page(){
			include('admin-page.php');
		}
	}
}
 
include('purpose.php');
 
// insert into admin panel
add_action('admin_menu', array('SBC_Admin','add_config_page'));
?>

admin-page.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
 
// Update Settings
if ( isset($_POST['submit']) ) {
	if (!current_user_can('manage_options')) die(__('You cannot edit the search-by-category options.'));
	check_admin_referer('your_plugin-updatesettings');
 
	// Get our new option values
	$var1					= $_POST['var1'];
	$var2					= $_POST['var2'];
	$var3					= $_POST['var3'];
	$var4					= $_POST['var4'];
 
	// Fix value of checkboxes
	if(empty($var3)) $var3 = '0';
 
	// Update the DB with the new option values
	update_option("***-var1", $var1);
	update_option("***-var2", $var2);
	update_option("***-var3", $var3);
	update_option("***-var4", $var4);
}
 
// Get Current DB Values
$var1					= get_option("***-var1");
$var2					= get_option("***-var2");
$var3					= get_option("***-var3");
$var4					= get_option("***-var4");	
 
?>
 
<div class="wrap">
	<h2>Your_Plugin</h2>
	<form action="" method="post" id="your_plugin-config">
		<table class="form-table">
			<?php if (function_exists('wp_nonce_field')) { wp_nonce_field('your_plugin-updatesettings'); } ?>
			<tr>
				<th scope="row" valign="top"><label for="var1">Display text for var1:</label></th>
				<td><input type="text" name="var1" id="var1" class="regular-text" value="<?php echo $var1; ?>"/></td>
			</tr>
			<tr>
				<th scope="row" valign="top"><label for="var2">Display text for var2:</label></th>
				<td><input type="text" name="var2" id="var2" class="regular-text" value="<?php echo $var2; ?>"/></td>
			</tr>
			<tr>
				<th scope="row" valign="top"><label for="var3">Display text for var3:</label></th>
				<td><input type="checkbox" name="var3" id="var3" value="1" <?php if ($var3 == '1') echo 'checked="checked"'; ?> /></td>
			</tr>
			<tr>
				<th scope="row" valign="top"><label for="var4">Display text for var4:</label></th>
				<td><input type="text" name="var4" id="var4" class="regulat-text" value="<?php echo $var4; ?>" /></td>
			</tr>
		</table>
		<br/>
		<span class="submit" style="border: 0;"><input type="submit" name="submit" value="Save Settings" /></span>
	</form>
</div>

purpose.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
// I suggest creating a new one of these for every major feature
 
function your_plugin_feature( ) {
	global $wp_query, $post;
 
	$var1		= get_option("***-var1");
	$var2		= get_option("***-var2");
	$var3		= get_option("***-var3");
	$var4		= get_option("***-var4");
 
	echo 'Hello World!';
}
 
?>

改天再來好好的仔細研究吧~

12 則迴響於《來喔!一起來開發WP外掛吧!!

回應已關閉。