New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters #38

Closed
ryanburnette opened this Issue Jan 8, 2014 · 6 comments

Comments

Projects
None yet
2 participants
@ryanburnette

ryanburnette commented Jan 8, 2014

@stephenharris I hope creating an issue on your Github repo isn't too invasive, but I'm curious about a couple things and I haven't found an answer in your documentation. There are a couple things I'd like to do with Filters and WP-Markdown.

One is that I'd like to use the Markdown filter for text I store in custom fields. Is there a way to use apply_filters to process Markdown that I've stored on my own?

Also, I'd like to add processing to the filter which processes the Markdown. This is less important as I can filter using the the_content filter tag, but it might be cool to add additional processing using PHP that I keep in a separate plugin on certain projects.

Thanks in advance!

Ryan

@stephenharris

This comment has been minimized.

Owner

stephenharris commented Jan 8, 2014

Hi Ryan,

Not at all :).

The plug-in exposes two functions (see https://github.com/stephenharris/WP-MarkDown/blob/1.4/wp-markdown.php#L519). One for converting Markdown to HTML and the other doing the opposite. You can use those functions in any other plug-in.

As for filters when Markdown is run - there isn't, the plug-in uses WordPress' filters, so you can just use the same hooks (before/after wp-markdown's callback depending on whether you want the content in HTML or markdown when you perform your routine). I may add two filters in the above mentioned functions.

@ryanburnette

This comment has been minimized.

ryanburnette commented Jan 8, 2014

Thanks for getting back to me!

I'll definitely make use of this. It would be very WordPressy if these functions were WordPress filters, too.

@ryanburnette

This comment has been minimized.

ryanburnette commented May 6, 2014

I still think this would be a good addition to the plugin. If you want I can do a pull request. It's as easy as this.

function markdown_func($content) {
  if ( function_exists('wpmarkdown_markdown_to_html') ) {
    return wpmarkdown_markdown_to_html($content);
  }

  return $content;
}
add_filter('markdown','st_markdown_func');
@stephenharris

This comment has been minimized.

Owner

stephenharris commented May 7, 2014

Hi Ryan,

The above uses the filter markdown - this isn't a filter used by the plug-in or WordPress, so it's not clear to me what its filtering, or when its filtering it...

Or is it a case of:

$markdown = '...some text in markdown...';
$html = apply_filters( 'markdown', $markdown )

If so, I don't think a filter here is necessary, just call:

$html =  markdown_func( $markdown );
@ryanburnette

This comment has been minimized.

ryanburnette commented May 7, 2014

It's a WordPress plugin so my opinion is that offering a filter is cleaner. Same diff in the end. Closing.

@ryanburnette

This comment has been minimized.

ryanburnette commented May 7, 2014

But just in case anyone is like me and wants to utilize this functionality using filters, here's the code.

https://gist.github.com/ryanburnette/0fc9b9ab1eb41877ffd3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment