Skip to content

Commit

Permalink
Bug #18, Plugin - design review; add "Lorem_Filter_Plugin" [iet:75714…
Browse files Browse the repository at this point in the history
…70][iet:7690303]
  • Loading branch information
nfreear committed Jan 6, 2017
1 parent 0ab7248 commit c47ce02
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"jakub-onderka/php-parallel-lint": "^0.9.2",
"wp-coding-standards/wpcs": "^0.10"
},
"suggest": {
"vlucas/phpdotenv": "^2.4, phpdotenv",
"wpackagist-plugin/lorem-shortcode": "1.3.3; lorem-shortcode"
},
"scripts": {
"npm-install": "npm install eslint",
"eslint-config": [
Expand Down
72 changes: 72 additions & 0 deletions lorem-filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php namespace IET_OU\WP_Generic_Plugins;

/*
Plugin Name: Lorem Filter
Plugin URI:
Description: ...
Author: Nick Freear
Author URI: https://github.com/nfreear
Version: 1.0-alpha
@copyright © 2017 The Open University (UK).
@author Nick Freear, 04 January 2017.
@link https://en-gb.wordpress.org/plugins/lorem-shortcode/
@link https://wordpress.org/plugins/lorem-ipsum-dummy-article-shortcode
*/

#require_once __DIR__ . '/../../../vendor/autoload.php';

use Dotenv\Dotenv;
use SoderlindLorem as SoderlindLorem;

class Lorem_Filter_Plugin {

public function __construct() {
add_filter( 'the_content', [ &$this, 'filter_the_content' ]);
add_filter( 'lorem_small', [ &$this, 'filter_lorem_small' ]);
}

public function filter_lorem_small( $var_paras = null ) {
$var_paras = $var_paras > 1 ? $var_paras : 1;

if ( class_exists( 'SoderlindLorem' ) ) {

$soder_plugin = new SoderlindLorem();
return $soder_plugin->lorem( [
'p' => self::env( 'SM_PARAS', $var_paras ), # shortcode default: 5.
'l' => self::env( 'SM_LINES', 3 ), # " default: 3.
] );
}
return '';
}

public function filter_the_content( $content ) {

if ( ! $content && class_exists( 'SoderlindLorem' ) ) {

if ( class_exists( 'Dotenv\Dotenv' )) {
$dotenv = new Dotenv( __DIR__ . '/../../../' );
$dotenv->load();
}

$soder_plugin = new SoderlindLorem();
$lorem = $soder_plugin->lorem( [
'p' => self::env( 'PARAS', 5 ), # shortcode default: 5.
'l' => self::env( 'LINES', 6 ), # " default: 3.
] );

$lorem = preg_replace( '@<\/p>@', '</p> <h2> Lorem heading </h2> ', $lorem, self::env( 'LIMIT', 1 ) );
$lorem = preg_replace( '@,\.@', '.', $lorem );

return $lorem;
}

return $content;
}

protected static function env( $key, $default = null ) {
return getenv( "LOREM_$key" ) ? getenv( "LOREM_$key" ) : $default;
}

}
$plugin = new Lorem_Filter_Plugin();
7 changes: 6 additions & 1 deletion simple_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ protected function display_content( $sub_menu, $menu_id, $classes, $show_comment
<?php echo apply_filters('the_content', get_post_field( 'post_content', $it->object_id )) ?>
<?php self::display_comments( $it->object_id, $show_comments ) ?>
</div>
<div class="col-md-3 case-study"> Case study <!-- Tricky topics guide --></div>
<div class="col-md-3 case-study">
<h4 class="cs-title"> Case study </h4> <!-- Tricky topics guide -->
<p><img src="/wp-content/themes/tttt-guide/images/default-case-study.png" alt="" /></p>
<?php echo apply_filters( 'lorem_small', null ) ?>
<a href="#view-more" role="button" data-toggle="tooltip" title="View the case study.">View more</a>
</div>
</div>
<?php if ( $with_top_link ): ?>
<div class="row"><a href="#site-main" class="col-md-9 tttt-to-top">Return to top of page</a></div>
Expand Down

0 comments on commit c47ce02

Please sign in to comment.