Skip to content

Commit 95d0c87

Browse files
committed
Re-enable saving post metadata
* Adjust `save()` as minimally as necessary to support new function names and the dual-`width/maxwidth` presence * Add note re: need for new post_metadata key * Add note re: functions we should be able to remove once tested Affects #16
1 parent 00c0b07 commit 95d0c87

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

documentcloud.php

+31-21
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function __construct() {
5151
// add_shortcode('documentcloud', array(&$this, 'embed_shortcode'));
5252

5353
// Store metadata upon post save
54-
// add_action('save_post', array(&$this, 'save'));
54+
add_action('save_post', array(&$this, 'save'));
5555
}
5656

5757
function register_dc_oembed_provider() {
@@ -190,21 +190,8 @@ function register_button($buttons) {
190190
return $buttons;
191191
}
192192

193-
function get_defaults() {
194-
// add admin options to adjust these defaults
195-
// storing js params as strings instead of real booleans
196-
return array(
197-
'url' => null,
198-
'id' => null,
199-
'height' => get_option('documentcloud_default_height', 600),
200-
'width' => get_option('documentcloud_default_width', 620),
201-
'format' => 'normal',
202-
'sidebar' => 'false',
203-
'text' => 'true',
204-
'pdf' => 'true'
205-
);
206-
}
207-
193+
// Setup settings for plugin
194+
208195
function add_options_page() {
209196
add_options_page('DocumentCloud', 'DocumentCloud', 'manage_options',
210197
'documentcloud', array(&$this, 'render_options_page'));
@@ -257,8 +244,6 @@ function full_width_field() {
257244

258245
function settings_section() {}
259246

260-
// Hopefully can remove from here down?
261-
262247
function save($post_id) {
263248
// tell the post if we're carrying a wide load
264249

@@ -270,7 +255,7 @@ function save($post_id) {
270255
))
271256
) { return; }
272257

273-
$defaults = $this->get_defaults();
258+
$defaults = $this->get_default_atts();
274259
$wide_assets = get_post_meta($post_id, 'wide_assets', true);
275260
$documents = get_post_meta($post_id, 'documentcloud', true);
276261
$matches = array();
@@ -283,14 +268,20 @@ function save($post_id) {
283268
$atts = shortcode_parse_atts($args[$i]);
284269
$atts = shortcode_atts($defaults, $atts);
285270

271+
// TODO: Reconsider using document ID as array key,
272+
// because we'll be using this same shortcode to
273+
// consume more than just documents in the future.
274+
// Perhaps we can use `url` as key?
275+
286276
// get a doc id to keep array keys consistent
287277
if (isset($atts['url']) && !isset($atts['id']) ) {
288278
$atts['id'] = $this->parse_id_from_url($atts['url']);
289279
}
290280

291281
// if no id, don't bother storing because it's wrong
292282
if ($atts['id'] != null) {
293-
if ($atts['format'] == "wide" || $atts['width'] > $defaults['width']) {
283+
$width = isset($atts['width']) ? $atts['width'] : $atts['maxwidth'];
284+
if ($atts['format'] == "wide" || $width > $defaults['maxwidth']) {
294285
$wide_assets[$atts['id']] = true;
295286
} else {
296287
$wide_assets[$atts['id']] = false;
@@ -303,7 +294,6 @@ function save($post_id) {
303294
}
304295
update_post_meta($post_id, 'documents', $documents);
305296
update_post_meta($post_id, 'wide_assets', $wide_assets);
306-
307297
}
308298

309299
function parse_id_from_url($url) {
@@ -316,6 +306,26 @@ function parse_id_from_url($url) {
316306
}
317307
}
318308

309+
// TODO: Remove this once we've ensured `handle_dc_shortcode()`
310+
// replicates all the functionality properly. Note that `save()`
311+
// has been adjusted to use `get_default_atts()`, but I left
312+
// `embed_shortcode()` using `get_defaults()` for inspection.
313+
314+
function get_defaults() {
315+
// add admin options to adjust these defaults
316+
// storing js params as strings instead of real booleans
317+
return array(
318+
'url' => null,
319+
'id' => null,
320+
'height' => get_option('documentcloud_default_height', 600),
321+
'width' => get_option('documentcloud_default_width', 620),
322+
'format' => 'normal',
323+
'sidebar' => 'false',
324+
'text' => 'true',
325+
'pdf' => 'true'
326+
);
327+
}
328+
319329
function embed_shortcode($atts, $content, $code) {
320330
global $post;
321331
$defaults = $this->get_defaults();

0 commit comments

Comments
 (0)