WordPress.org

Forums

[resolved] Read content from custom fields for this plugin (2 posts)

  1. jetonr
    Member
    Posted 6 years ago #

    Hi, the plugin shown down, reads the tags [megavideo videoid] from post content and I need to read them from a custom field like this:
    custom_field: megavideo
    custom_field_value:[megavideo videoid]

    <?php
    /*
    *	Plugin Name: Megavideo Embed
    *   Plugin URI: http://www.jrwebstudio.com
    *   Description: Valid XHTML Embeding Megavideo to WordPress
    * 	Author: Jeton Ramadani
    * 	Author URI: http://www.jrwebstudio.com
    * 	Version: 1.0
    */
    
    define("MEGAVIDEO_WIDTH", 545); // default width
    define("MEGAVIDEO_HEIGHT", 440); // default height
    define("MEGAVIDEO_REGEXP", "/\[megavideo (:print:+)\]/");
    define("MEGAVIDEO_TARGET", "<object type=\"application/x-shockwave-flash\" data=\"http://www.megavideo.com/v/---URL---\" width=\"---WIDTH---\" height=\"---HEIGHT---\"><param name=\"movie\" value=\"http://www.megavideo.com/v/---URL---\" /><param name=\"allowFullScreen\" value=\"true\" /></object>");
    
    function megavideo_plugin_callback($match)
    {
    	$tag_parts = explode(" ", rtrim($match[0], "]"));
    	$output = MEGAVIDEO_TARGET;
    	$output = str_replace("---URL---", $tag_parts[1], $output);
    	if (count($tag_parts) > 2) {
    		if ($tag_parts[2] == 0) {
    			$output = str_replace("---WIDTH---", MEGAVIDEO_WIDTH, $output);
    		} else {
    			$output = str_replace("---WIDTH---", $tag_parts[2], $output);
    		}
    		if ($tag_parts[3] == 0) {
    			$output = str_replace("---HEIGHT---", MEGAVIDEO_HEIGHT, $output);
    		} else {
    			$output = str_replace("---HEIGHT---", $tag_parts[3], $output);
    		}
    	} else {
    		$output = str_replace("---WIDTH---", MEGAVIDEO_WIDTH, $output);
    		$output = str_replace("---HEIGHT---", MEGAVIDEO_HEIGHT, $output);
    	}
    	return ($output);
    }
    function megavideo_plugin($content)
    {
    	return (preg_replace_callback(MEGAVIDEO_REGEXP, 'megavideo_plugin_callback', $content));
    }
    
    add_filter('the_content', 'megavideo_plugin');
    add_filter('the_content_rss', 'megavideo_plugin');
    add_filter('comment_text', 'megavideo_plugin');
    ?>
  2. esmi
    Forum Moderator
    Posted 6 years ago #

    [megavideo videoid] isn't a tag. It's a shortcode. If you want to use custom fields, have a look at http://codex.wordpress.org/Using_Custom_Fields

Topic Closed

This topic has been closed to new replies.

About this Topic