-
Notifications
You must be signed in to change notification settings - Fork 0
/
description2caption.php
executable file
·150 lines (137 loc) · 4.89 KB
/
description2caption.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/*
Plugin Name: Description 2 Caption
Description: This plugin copies the value of description to caption in the media editor, after the media attachment has been uploaded. I created this plugin to fix the annoying feature of Wordpress, when by uploading images it copies the IPTC caption to description and leaves the caption field empty.
Version: 1.0
Author: Peter Hudec
Author URI: http://peterhudec.com
Plugin URI: http://peterhudec.com/programming/description2caption
License: GPL2
*/
/**
* Main plugin class
* the long name is intentional to avoid collisions in global namespace
*/
class Description_2_Caption_Plugin {
/**
* Constructor
*/
function __construct() {
// hooks
register_activation_hook( __FILE__, array( $this, 'register' ) );
// filters
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
// actions
add_action( 'add_attachment', array( $this, 'add_attachment' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_init', array( $this, 'init' ) );
}
/**
* Default settings
*/
public function register() {
add_option( 'description_2_caption_move', 0 );
}
/**
* Plugin action links
*/
public function plugin_action_links( $links, $file ) {
static $this_plugin;
if ( ! $this_plugin ) {
$this_plugin = plugin_basename( __FILE__ );
}
if ( $file == $this_plugin ) {
$settings_link = '<a href="' . get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=d2c-options">Settings</a>';
array_unshift( $links, $settings_link );
}
return $links;
}
/**
* Trigered after user uploads attachment and before the attachment form gets displayed
*/
public function add_attachment( $post_ID )
{
$post = get_post( $post_ID );
$post->post_excerpt = $post->post_content;
if ( get_option( 'description_2_caption_move') ) {
$post->post_content = null;
}
wp_update_post( $post );
}
/**
* Adds plugin entry in the admin menu
*/
public function admin_menu() {
add_plugins_page(
'Description 2 Caption',
'Description 2 Caption',
'administrator',
'd2c-options',
array( $this, 'options_cb' )
);
}
/**
* Called upon plugin initialization
*/
public function init()
{
register_setting(
'description_2_caption_move',
'description_2_caption_move'
);
add_settings_section(
'd2c_section',
'',
array( $this, 'section_cb' ),
'd2c-options'
);
add_settings_field(
'description_2_caption_move',
'Copy or move caption to description?',
array( $this, 'move_cb' ),
'd2c-options',
'd2c_section'
);
}
/**
* Empty section callback
*/
public function section_cb() {}
/**
* Options callback
*/
public function options_cb() { ?>
<div class="wrap">
<h2>Description 2 Caption options</h2>
<?php settings_errors(); ?>
<form action="options.php" method="post">
<?php settings_fields( 'description_2_caption_move' ); ?>
<?php do_settings_sections( 'd2c-options' ); ?>
<?php submit_button(); ?>
</form>
<p>
Created by <a href="http://peterhudec.com" target="_blank">peterhudec.com</a>.<br />
This plugin is and allways will be free but if you still want to pay for it you can. Just click the button below <strong>:-)</strong><br />
</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="GB4S3N2XJMRCN">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
<?php }
/**
* Move setting callback
*/
public function move_cb() { ?>
<input type="radio" id="description_2_caption_copy" name="description_2_caption_move" value="0" <?php checked( 0, get_option( 'description_2_caption_move' ) ); ?> />
<label for="d2c_copy">Copy</label>
<br />
<input type="radio" id="description_2_caption_move" name="description_2_caption_move" value="1" <?php checked( 1, get_option( 'description_2_caption_move' ) ); ?> />
<label for="description_2_caption_move">Move</label>
<?php }
}
// instantiate plugin with long name to avoid collisions with other plugins
$description_2_caption_plugin = new Description_2_Caption_Plugin();
?>