Core Functions Definitions€¦ · Core Functions Definitions Tanner Moushey, Web Engineer at...

Post on 07-Aug-2020

11 views 0 download

Transcript of Core Functions Definitions€¦ · Core Functions Definitions Tanner Moushey, Web Engineer at...

Core Functions Definitions

Tanner Moushey, Web Engineer at 10up@tannermoushey

Slides: http://wp.me/p2Py3c-2S

Core Functions Definitions

• The Codex

• The Core

Sample Project

Your client asks you to change the default “more...” link on each of the home page post’s teaser content to “Read more...”

What do you do?

Thank you codex!

The CodexThe codex is a great resource. Awesome for:• Quick reference• Code examples• Related functions

Your client was very pleased you turned that around so quickly and now has a more complicated request.... For links in the “Breaking News” category, can the link text say “Breaking! Read more...” and be bold?

Sample Project

function get_the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) { global $page, $more, $preview;

...

if ( count( $content ) > 1 ) { if ( $more ) { $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; } else { if ( ! empty( $more_link_text ) ) $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); $output = force_balance_tags( $output ); } }

if ( $preview ) // preview fix for javascript bug with foreign languages $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );

return $output;}

Core to the Rescue!

Core to the Rescue!

$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text

);

Solutionfunction my_more_link_filter( $link, $more_link_text ) { if ( ! in_category( 'breaking_news' ) ) return $link;

$more_link_text = 'Breaking! ' . $more_link_text;

$link = '<a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link breaking\">$more_link_text</a>";

return $link;}add_filter( 'the_content_more_link', 'my_more_link_filter', 10, 2 );

The Core

• Actions and Filters

• Sanitization and Escaping

• Coding standards

• Code forking

The Codex

• Quick reference

• Code examples

• Related functions

How to find core functions

• http://wpseek.com

• Ack ( http://beyondgrep.com/ )

• Use an IDE