Skip to content
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

clean up, remove unused code #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 1 addition & 97 deletions class-newcity-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
*
* Defines custom TimberPost extensions
* Defines custom shortcodes
*
* @since 0.1.0
*
Expand All @@ -14,7 +14,6 @@ class NewCityShortcodes {

public function __construct() {
add_shortcode( 'newcity_blockquote', array( 'NewCityShortcodes', 'newcity_blockquote' ), 7 );
// add_filter( 'img_caption_shortcode', array( $this, 'update_caption_shortcode' ), 10, 3 );
add_filter( 'mce_external_plugins', array( 'NewCityShortcodes', 'add_blockquote_mce' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_jquery_ui' ) );
}
Expand Down Expand Up @@ -51,99 +50,4 @@ public static function newcity_blockquote( $attr, $content = '' ) {
<?php
return ob_get_clean();
}

function the_content_filter( $content ) {
// array of custom shortcodes requiring the fix
$block = join( '|',array( 'callout' ) );
// opening tag
$rep = preg_replace( "/(<p>)?\[($block)(\s[^\]]+)?\](<\/p>|<br \/>)?/",'[$2$3]',$content );
// closing tag
$rep = preg_replace( "/(<p>)?\[\/($block)](<\/p>|<br \/>)?/",'[/$2]',$rep );
// $rep = preg_replace("/\[\/($block)\][\S]*/","[/$2]",$rep);
// $rep = preg_replace( '/([\n\r][\s\t]*){3,}/', "\n\n", $rep );
return $rep;
}

function strip_breaks( $content ) {
$content = preg_replace( '/<br ?\/?>/', '', $content );

return $content;
}

public static function inline_callout( $atts, $content = null ) {
extract( shortcode_atts( array(), $atts ) );

$output = '<div class="callout callout--inline">' . trim( do_shortcode( $content ) ) . '</div>';

return $output;
}

public static function callout_header( $atts, $content = null, $tag = '' ) {

$atts = shortcode_atts(
[
'heading' => 'h3',
], $atts, $tag
);

return '<div class="callout__header"><' . $atts['heading'] . '>' . trim( $content ) . '</' . $atts['heading'] . '></div>';
}

public static function callout_body( $atts, $content = null ) {

extract( shortcode_atts( array(), $atts ) );

return '<div class="callout__body">' . trim( $content ) . '</div>';
}

function wrap_all_img_in_shortcode( $html, $id, $alt, $title, $align, $url, $size ) {
// $url = wp_get_attachment_url($id); // Grab the current image URL
$html = '[caption]' . $html . '[/caption]';
return $html;
}

function update_caption_shortcode( $val, $attr, $content = null ) {
$a = shortcode_atts(
array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => '',
), $attr
);

$image_id = '';
if ( 'attachment_' === substr( $a['id'], 0, 11 ) ) {
$image_id = substr( $a['id'], 11 );
}

if ( $image_id ) {
$image_acf = get_fields( $image_id );
}


$html_parent = new DOMDocument;
$html_parent->loadHTML( do_shortcode( $content ) );
$html_image = $html_parent->getElementsByTagName( 'img' );

$img_width = 640;
// $img_height = $html_image[0]->getAttribute( 'height' );
$img_alt = $html_image[0]->getAttribute( 'alt' );

return Timber::compile(
'figure.twig', array(
'image' => $image_id,
'caption' => $a['caption'],
'alt' => $img_alt,
'attribution' => $image_acf['attribution'],
'figure_modifier' => $a['align'],
'media_width' => $img_width,
// 'media_height' => $img_height,
'alt' => $img_alt,
'figure_modifier' => 'article-image',
'original_ratio' => true,
)
);
}

}
9 changes: 2 additions & 7 deletions newcity-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,5 @@
die;
}

require_once( dirname( __FILE__ ) . '/class-newcity-shortcodes.php');

function newcity_shortcodes_run() {
$newcity_shortcodes = new NewCityShortcodes();
}

newcity_shortcodes_run();
require_once( __DIR__ . '/class-newcity-shortcodes.php');
new NewCityShortcodes();