1. I notice that when I chose between summary, Photo and Player in the post settings, it always reverts back to “Summary” after saving. It’s not clear if the setting is not updated or if it is and the drop-down just doesn’t show it.
2. When choosing a player card, there is a very obvious mistake where the default content of the iframe field spills over the field itself.
3. I don’t know if it’s because of these issues or others, but I can only get this to work for summary cards, not for photo.
]]>I activated WP Twitter Cards and updated my post with the right information, but when I checked the source, I didn’t see any twitter:* tags inside. ??
]]>Howdy,
It seems that twitter also requires a Width and Height meta tag to be set for “players” as well.
I also fixed a couple of bugs.
One was where the “twitter:player” value was being set to “1” (this was as side effect of doing the assignment AND a test for the card type.
Also fixed a bug with automatically setting the twitter type combo box.
PATCH BEGINS
diff wp-twitter-cards/twitter_cards.php wp-twitter-cards-patched/twitter_cards.php
82a83,84
> add_settings_field('twitter_cards_default_iframe_width', 'Default Player iFrame Width', array(__CLASS__, 'add_settings_input'), 'twitter_cards', 'twitter_cards_defaults', array('name' => 'default_iframe_width', 'type' => 'number', 'maxlength' => '20'));
> add_settings_field('twitter_cards_default_iframe_height', 'Default Player iFrame Height', array(__CLASS__, 'add_settings_input'), 'twitter_cards', 'twitter_cards_defaults', array('name' => 'default_iframe_height', 'type' => 'number', 'maxlength' => '20'));
132a135,138
> if( isset( $_POST['twitter_cards_post_iframe_width'] ) )
> update_post_meta($post_id, 'twitter_cards_post_iframe_width', $_POST['twitter_cards_post_iframe_width']);
> if( isset( $_POST['twitter_cards_post_iframe_height'] ) )
> update_post_meta($post_id, 'twitter_cards_post_iframe_height', $_POST['twitter_cards_post_iframe_height']);
182,185c188,205
< if ($stream = get_post_meta($id, 'twitter_cards_post_stream', true) && $type == 'player') {
< self::echo_meta('twitter:player:stream', $stream);
< } else if ($iframe = get_post_meta($id, 'twitter_cards_post_iframe', true) && $type == 'player') {
< self::echo_meta('twitter:player', $iframe);
---
>
> if ($type == 'player') {
> if ($stream = get_post_meta($id, 'twitter_cards_post_stream', true)) {
> self::echo_meta('twitter:player:stream', $stream);
> }
> if ($iframe = get_post_meta($id, 'twitter_cards_post_iframe', true)) {
> self::echo_meta('twitter:player', $iframe);
> }
> if ($iframe_width = get_post_meta($id, 'twitter_cards_post_iframe_width', true)) {
> self::echo_meta('twitter:player:width', $iframe_width);
> } else if ($iframe_width = $twitter_cards['default_iframe_width']) {
> self::echo_meta('twitter:player:width', $iframe_width);
> }
> if ($iframe_height = get_post_meta($id, 'twitter_cards_post_iframe_height', true)) {
> self::echo_meta('twitter:player:height', $iframe_height);
> } else if ($iframe_height = $twitter_cards['default_iframe_height']) {
> self::echo_meta('twitter:player:height', $iframe_height);
> }
diff wp-twitter-cards/twitter_cards_postbox.php wp-twitter-cards-patched/twitter_cards_postbox.php
1,57c1,153
< <?php
< $prev_desc = get_post_meta($post->ID, "twitter_cards_post_description", true);
< $prev_title = get_post_meta($post->ID, "twitter_cards_post_title", true);
< $prev_creator = get_post_meta($post->ID, "twitter_cards_post_creator_username", true);
< $prev_type = get_post_meta($post->ID, "twitter_cards_post_type", true);
< $prev_img = get_post_meta($post->ID, "twitter_cards_post_image", true);
< $prev_iframe = get_post_meta($post->ID, "twitter_cards_post_iframe", true);
< $prev_stream = get_post_meta($post->ID, "twitter_cards_post_stream", true);
< wp_nonce_field( 'twitter_cards_post_nonce', 'twitter_cards_post_nonce' );
< ?>
<
< <p><label for="twitter_cards_post_title"><b>Title</b></label></p>
< <p><input class="large-text" type="text" placeholder="Maximum 70 chars" maxlength="70" name="twitter_cards_post_title" value="<?php echo $prev_title; ?>"></p>
< <p><label for="twitter_cards_post_description"><b>Description</b></label></p>
< <p><textarea cols="4" rows="4" class="large-text" placeholder="Maximum 200 chars" maxlength="200" name="twitter_cards_post_description"><?php echo $prev_desc; ?></textarea></p>
< <p><label for="twitter_cards_post_image"><b>Image</b></label></p>
< <p><input class="large-text" value="<?php echo $prev_img; ?>" type="url" value="<?php echo $prev_img; ?>" name="twitter_cards_post_image"></p>
< <?php echo "<h4>" . __( 'Twitter Settings', 'twitter_cards_trdom' ) . "</h4>"; ?>
< <p><label for="twitter_cards_post_type"><b>Post Type</b></label></p>
< <p>
< <select class="large-text" name="twitter_cards_post_type" id="twitter_cards_post_type" onchange="wptc_hide()">
< <option value="summary" <?php selected( 0, $prev_type, true)?>>Summary</option>
< <option value="photo" <?php selected( 0, $prev_type, true)?>>Photo</option>
< <option value="player" <?php selected( 0, $prev_type, true)?>>Player</option>
< </select>
< </p>
< <p id="twitter_cards_iframe_label"><label for="twitter_cards_post_iframe"><b>iFrame</b></label></p>
< <p id="twitter_cards_iframe_input"><input class="large-text" placeholder="https url to an iFrame" value="<?php echo $prev_iframe; ?>" type="url" name="twitter_cards_post_iframe"></p>
< <p id="twitter_cards_stream_label"><label for="twitter_cards_post_stream"><b>Stream</b></label></p>
< <p id="twitter_cards_stream_input"><input class="large-text" placeholder="Driect link to media file" value="<?php echo $prev_stream; ?>" type="url" name="twitter_cards_post_stream"></p>
< <p><label for="twitter_cards_post_creator_username"><b>Username</b></label></p>
< <p><input class="large-text" type="text" placeholder="The @username of the creator" name="twitter_cards_post_creator_username" value="<?php echo $prev_creator; ?>"></p>
<
< <script type="text/javascript">
< var stream = document.getElementById('twitter_cards_stream_input');
< var stream_label = document.getElementById('twitter_cards_stream_label');
< var iframe = document.getElementById('twitter_cards_iframe_input');
< var iframe_label = document.getElementById('twitter_cards_iframe_label');
< wptc_hide();
<
< function wptc_hide () {
<
< stream.style.display="none";
< stream_label.style.display="none";
< iframe.style.display="none";
< iframe_label.style.display="none";
<
< var card_type = document.getElementById('twitter_cards_post_type');
< card_type = card_type.options[card_type.selectedIndex].value;
<
< if (card_type == 'player') {
< stream.style.display="block";
< stream_label.style.display="block";
< iframe.style.display="block";
< iframe_label.style.display="block";
< }
< }
---
> <?php
>
> $prev_desc = get_post_meta($post->ID, "twitter_cards_post_description", true);
>
> $prev_title = get_post_meta($post->ID, "twitter_cards_post_title", true);
>
> $prev_creator = get_post_meta($post->ID, "twitter_cards_post_creator_username", true);
>
> $prev_type = get_post_meta($post->ID, "twitter_cards_post_type", true);
>
> $prev_img = get_post_meta($post->ID, "twitter_cards_post_image", true);
>
> $prev_iframe = get_post_meta($post->ID, "twitter_cards_post_iframe", true);
>
> $prev_iframe_width = get_post_meta($post->ID, "twitter_cards_post_iframe_width", true);
>
> $prev_iframe_height = get_post_meta($post->ID, "twitter_cards_post_iframe_height", true);
>
> $prev_stream = get_post_meta($post->ID, "twitter_cards_post_stream", true);
>
> wp_nonce_field( 'twitter_cards_post_nonce', 'twitter_cards_post_nonce' );
>
> ?>
>
>
>
> <p><label for="twitter_cards_post_title"><b>Title</b></label></p>
>
> <p><input class="large-text" type="text" placeholder="Maximum 70 chars" maxlength="70" name="twitter_cards_post_title" value="<?php echo $prev_title; ?>"></p>
>
> <p><label for="twitter_cards_post_description"><b>Description</b></label></p>
>
> <p><textarea cols="4" rows="4" class="large-text" placeholder="Maximum 200 chars" maxlength="200" name="twitter_cards_post_description"><?php echo $prev_desc; ?></textarea></p>
>
> <p><label for="twitter_cards_post_image"><b>Image</b></label></p>
>
> <p><input class="large-text" value="<?php echo $prev_img; ?>" type="url" value="<?php echo $prev_img; ?>" name="twitter_cards_post_image"></p>
>
> <?php echo "<h4>" . __( 'Twitter Settings', 'twitter_cards_trdom' ) . "</h4>"; ?>
>
> <p><label for="twitter_cards_post_type"><b>Post Type</b></label></p>
>
> <p>
>
> <select class="large-text" name="twitter_cards_post_type" id="twitter_cards_post_type" onchange="wptc_hide()">
>
> <option value="summary" <?php selected( 'summary', $prev_type)?>>Summary</option>
>
> <option value="photo" <?php selected( 'photo', $prev_type)?>>Photo</option>
>
> <option value="player" <?php selected( 'player', $prev_type)?>>Player</option>
>
> </select>
>
> </p>
>
> <p id="twitter_cards_iframe_label"><label for="twitter_cards_post_iframe"><b>iFrame</b></label></p>
>
> <p id="twitter_cards_iframe_input"><input class="large-text" placeholder="https url to an iFrame" value="<?php echo $prev_iframe; ?>" type="url" name="twitter_cards_post_iframe"></p>
>
> <p id="twitter_cards_iframe_width_label">
> <span><label for="twitter_cards_post_iframe_width"><b>iFrame Width</b></label></span>:
> <span id="twitter_cards_iframe_width_input"><input class="small-text" placeholder="width" value="<?php echo $prev_iframe_width; ?>" type="number" name="twitter_cards_post_iframe_width"></span>
> </p>
>
> <p id="twitter_cards_iframe_height_label">
> <span><label for="twitter_cards_post_iframe_height"><b>iFrame Height</b></label></span>:
> <span id="twitter_cards_iframe_height_input"><input class="small-text" placeholder="height" value="<?php echo $prev_iframe_height; ?>" type="number" name="twitter_cards_post_iframe_height"></span>
> </p>
>
> <p id="twitter_cards_stream_label"><label for="twitter_cards_post_stream"><b>Stream</b></label></p>
>
> <p id="twitter_cards_stream_input"><input class="large-text" placeholder="Driect link to media file" value="<?php echo $prev_stream; ?>" type="url" name="twitter_cards_post_stream"></p>
>
> <p><label for="twitter_cards_post_creator_username"><b>Username</b></label></p>
>
> <p><input class="large-text" type="text" placeholder="The @username of the creator" name="twitter_cards_post_creator_username" value="<?php echo $prev_creator; ?>"></p>
>
>
>
> <script type="text/javascript">
>
> var stream = document.getElementById('twitter_cards_stream_input');
>
> var stream_label = document.getElementById('twitter_cards_stream_label');
>
> var iframe = document.getElementById('twitter_cards_iframe_input');
>
> var iframe_label = document.getElementById('twitter_cards_iframe_label');
>
> var iframe_width = document.getElementById('twitter_cards_iframe_width_input');
>
> var iframe_width_label = document.getElementById('twitter_cards_iframe_width_label');
>
> var iframe_height = document.getElementById('twitter_cards_iframe_height_input');
>
> var iframe_height_label = document.getElementById('twitter_cards_iframe_height_label');
>
> wptc_hide();
>
>
>
> function wptc_hide () {
>
>
>
> stream.style.display="none";
>
> stream_label.style.display="none";
>
> iframe.style.display="none";
>
> iframe_label.style.display="none";
>
> iframe.style.display="none";
>
> iframe_label.style.display="none";
>
> iframe_width.style.display="none";
>
> iframe_width_label.style.display="none";
>
> iframe_height.style.display="none";
>
> iframe_height_label.style.display="none";
>
> var card_type = document.getElementById('twitter_cards_post_type');
>
> card_type = card_type.options[card_type.selectedIndex].value;
>
>
> if (card_type == 'player') {
>
> stream.style.display="block";
>
> stream_label.style.display="block";
>
> iframe.style.display="block";
>
> iframe_label.style.display="block";
>
> iframe_width.style.display="block";
>
> iframe_width_label.style.display="block";
>
> iframe_height.style.display="block";
>
> iframe_height_label.style.display="block";
>
> }
>
> }
>
It looks like the formatting got somewhat kludged up on the postbox.php file. If you let me know what editor you are using, I can try formatting it better.
Anyways, thanks for the great plugin and let me know if you’d like me to email the patch to you.
Cheers,
Josh