Skip to content

Commit 7fd7013

Browse files
committed
Used Singleton where possible.
1 parent 2f3ffac commit 7fd7013

File tree

10 files changed

+73
-30
lines changed

10 files changed

+73
-30
lines changed

framework/Admin/Theme_Settings.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
<?php
22
namespace JustCoded\WP\Framework\Admin;
33

4+
use JustCoded\WP\Framework\Objects\Singleton;
5+
46
/**
57
* Theme Settings base class
68
* Contain few methods to work with Titan framework
79
*/
810
abstract class Theme_Settings {
11+
use Singleton;
12+
913
/**
1014
* Unique framework instance to be used
1115
*
1216
* @var \TitanFramework
1317
*/
14-
protected static $tf;
18+
protected static $titan_instance;
1519

1620
/**
1721
* Theme Settings constructor
1822
* init framework hook
1923
*/
20-
public function __construct() {
24+
protected function __construct() {
2125
add_action( 'tf_create_options', array( $this, 'init' ) );
2226
}
2327

28+
/**
29+
* Check and create titan framework instance if needed
30+
*
31+
* @return \TitanFramework
32+
*/
33+
public static function titan_instance() {
34+
if ( ! static::$titan_instance ) {
35+
static::$titan_instance = \TitanFramework::getInstance( 'just_theme_options' );
36+
}
37+
return static::$titan_instance;
38+
}
39+
2440
/**
2541
* Check and init framework instance if needed
42+
*
43+
* @deprecated from 2.1.2, use titan_instance() method.
2644
*/
2745
public static function check_instance() {
28-
if ( ! self::$tf ) {
29-
self::$tf = \TitanFramework::getInstance( 'just_theme_options' );
30-
}
46+
return static::titan_instance();
3147
}
3248

3349
/**
@@ -38,9 +54,7 @@ public static function check_instance() {
3854
* @return mixed
3955
*/
4056
public static function get( $option_name ) {
41-
self::check_instance();
42-
43-
return self::$tf->getOption( $option_name );
57+
return static::titan_instance()->getOption( $option_name );
4458
}
4559

4660
/**
@@ -50,6 +64,7 @@ public static function get( $option_name ) {
5064
* @param \TitanFrameworkAdminPage $panel Titan framework panel object.
5165
* @param array $tabs Tabs init callbacks to be executed.
5266
*
67+
* @deprecated from 1.1.2
5368
* @throws \Exception Missing method to execute.
5469
*/
5570
public function add_panel_tabs( $panel, $tabs ) {

framework/Page_Builder/v25/Page_Builder_Loader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace JustCoded\WP\Framework\Page_Builder\v25;
33

4+
use JustCoded\WP\Framework\Objects\Singleton;
45
use JustCoded\WP\Framework\Page_Builder\v25\Traits\Html_Cleanup;
56
use JustCoded\WP\Framework\Page_Builder\v25\Traits\Row_Layouts_Loader;
67
use JustCoded\WP\Framework\Page_Builder\v25\Traits\Widget_Layouts_Loader;
@@ -12,6 +13,7 @@
1213
* @package JustCoded\WP\Framework\SOPanels
1314
*/
1415
class Page_Builder_Loader {
16+
use Singleton;
1517
use Html_Cleanup, Row_Layouts_Loader, Widget_Layouts_Loader;
1618

1719
/**
@@ -90,7 +92,7 @@ class Page_Builder_Loader {
9092
* Main class constructor
9193
* Set WordPress actions and filters
9294
*/
93-
public function __construct() {
95+
protected function __construct() {
9496
$this->html_cleanup();
9597
$this->row_layouts_loader();
9698
$this->widget_layouts_loader();

framework/Supports/Autoptimize.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22
namespace JustCoded\WP\Framework\Supports;
33

4+
use JustCoded\WP\Framework\Objects\Singleton;
5+
46
/**
57
* Class AutoOptimize
68
* AutoOptimize plugin extention which allows to add advanced configuration of this plugin.
79
* Also add patches for multisite and "/cms" folder installation
810
*/
911
class Autoptimize {
12+
use Singleton;
13+
1014
/**
1115
* Domains to be added as <link prefetch>
1216
*
@@ -33,7 +37,7 @@ class Autoptimize {
3337
/**
3438
* AutoOptimize constructor.
3539
*/
36-
public function __construct() {
40+
protected function __construct() {
3741
// autooptimize patches.
3842
add_filter( 'autoptimize_filter_js_unmovable', array( $this, 'js_is_unmovable' ) );
3943
add_filter( 'autoptimize_filter_js_domove', array( $this, 'js_move_first' ) );

framework/Supports/Contact_Form7.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class Contact_Form7 extends Post_Type {
4141

4242
/**
4343
* FormRequest constructor.
44-
* Define Wordpress hooks
44+
* define WordPress hooks
4545
*/
46-
public function __construct() {
46+
protected function __construct() {
4747
parent::__construct();
4848
add_action( 'wpcf7_before_send_mail', array( $this, 'save_form_request' ) );
4949

framework/Supports/Just_Custom_Fields.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace JustCoded\WP\Framework\Supports;
44
use jcf\models\Settings;
5+
use JustCoded\WP\Framework\Objects\Singleton;
56

67
/**
78
* Class Just_Custom_Fields
@@ -11,11 +12,13 @@
1112
* @package JustCoded\WP\Framework\Supports
1213
*/
1314
class Just_Custom_Fields {
15+
use Singleton;
16+
1417
/**
1518
* Just_Custom_Fields constructor.
1619
* Register jcf hooks
1720
*/
18-
public function __construct() {
21+
protected function __construct() {
1922
add_filter( 'jcf_config_filepath', array( $this, 'jcf_config_filepath' ), 10, 2 );
2023
}
2124

framework/Supports/Just_Load_More.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99

1010
namespace JustCoded\WP\Framework\Supports;
1111

12+
use JustCoded\WP\Framework\Objects\Singleton;
13+
1214
/**
1315
* Class Just_Load_More
1416
*
1517
* @package JustCoded\WP\Framework\Supports
1618
*/
1719
class Just_Load_More {
20+
use Singleton;
21+
1822
/**
1923
* Just_Load_More constructor.
2024
*
2125
* Register plugin hooks.
2226
*/
23-
function __construct() {
27+
protected function __construct() {
2428
add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ) );
2529
if ( isset( $_POST['jtf_load_more'] ) && ! defined( 'JTF_LOAD_MORE_AJAX' ) ) {
2630
define( 'JTF_LOAD_MORE_AJAX', true );
@@ -31,30 +35,32 @@ function __construct() {
3135
}
3236

3337
/**
34-
* disable autooptimaze if using load more
38+
* Disable autooptimaze if using load more
3539
*/
3640
public function disable_autoptimize() {
3741
return true;
3842
}
3943

4044
/**
41-
* registered scripts
45+
* Register load more scripts
4246
*/
4347
public function register_assets() {
44-
wp_enqueue_script( '_jtf-load_more', jtf_plugin_url( 'assets/js/load_more.js' ), [ 'jquery' ] );
48+
if ( ! is_admin() ) {
49+
wp_enqueue_script( '_jtf-load_more', jtf_plugin_url( 'assets/js/load_more.js' ), [ 'jquery' ] );
50+
}
4551
}
4652

4753
/**
48-
* callback for loadmore script
54+
* Callback for loadmore script
4955
*
50-
* @param $html buffer output
56+
* @param string $html buffer output.
5157
*
5258
* @return string
5359
*/
5460
public function ob_get_clean( $html ) {
5561
$text = '';
56-
if ( isset( $_POST['jtf_selector'] ) ) {
57-
$selector = trim( $_POST['jtf_selector'] );
62+
if ( isset( $_POST[ 'jtf_selector' ] ) ) {
63+
$selector = trim( $_POST[ 'jtf_selector' ] );
5864
$attribute = substr( $selector, 0, 1 );
5965
if ( $attribute == '.' || $attribute == '#' ) {
6066
$selector = substr( $selector, 1 );

framework/Supports/Just_Post_Preview.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace JustCoded\WP\Framework\Supports;
33

4+
use JustCoded\WP\Framework\Objects\Singleton;
5+
46
/**
57
* Class Just_Post_Preview
68
*
@@ -9,13 +11,14 @@
911
* @package JustCoded\WP\Framework\Supports
1012
*/
1113
class Just_Post_Preview {
14+
use Singleton;
1215

1316
/**
1417
* Just_Post_Preview constructor.
1518
*
1619
* Register plugin hooks.
1720
*/
18-
public function __construct() {
21+
protected function __construct() {
1922
add_filter( 'jpp_post_preview_template', array( $this, 'jpp_post_preview_template' ) );
2023
}
2124

framework/Supports/Just_Responsive_Images.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace JustCoded\WP\Framework\Supports;
33

4+
use JustCoded\WP\Framework\Objects\Singleton;
5+
46
/**
57
* Class Just_Responsive_Images
68
*
@@ -9,13 +11,14 @@
911
* @package JustCoded\WP\Framework\Supports
1012
*/
1113
class Just_Responsive_Images {
14+
use Singleton;
1215

1316
/**
1417
* Just_Responsive_Images constructor.
1518
*
1619
* Register plugin hooks.
1720
*/
18-
public function __construct() {
21+
protected function __construct() {
1922
add_filter( 'rwd_image_sizes', array( $this, 'rmd_image_sizes' ) );
2023
}
2124

framework/Supports/Just_Tinymce.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace JustCoded\WP\Framework\Supports;
33

4+
use JustCoded\WP\Framework\Objects\Singleton;
5+
46
/**
57
* Class Just_Tinymce
68
*
@@ -9,12 +11,14 @@
911
* @package JustCoded\WP\Framework\Supports
1012
*/
1113
class Just_Tinymce {
14+
use Singleton;
15+
1216
/**
1317
* Just_Tinymce constructor.
1418
*
1519
* Register plugin hooks
1620
*/
17-
public function __construct() {
21+
protected function __construct() {
1822
add_filter( 'jtmce_config_file_path', array( $this, 'jtmce_config_file_path' ) );
1923
}
2024

framework/Theme.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace JustCoded\WP\Framework;
44

5+
use JustCoded\WP\Framework\Objects\Singleton;
56
use JustCoded\WP\Framework\Supports\Autoptimize;
67
use JustCoded\WP\Framework\Supports\Just_Custom_Fields;
78
use JustCoded\WP\Framework\Supports\Just_Post_Preview;
@@ -16,6 +17,8 @@
1617
* Init main path rewrite operations and activate / register hooks
1718
*/
1819
abstract class Theme {
20+
use Singleton;
21+
1922
/**
2023
* Theme version
2124
*
@@ -113,7 +116,7 @@ abstract class Theme {
113116
/**
114117
* Init actions and hooks
115118
*/
116-
public function __construct() {
119+
protected function __construct() {
117120
$this->register_post_types();
118121
$this->register_taxonomies();
119122
$this->init_views_templates();
@@ -383,11 +386,11 @@ public function register_taxonomies() {
383386
* Adds loading of custom features provided by 3d-party plugins.
384387
*/
385388
public function support_plugins() {
386-
new Just_Load_More();
387-
new Just_Responsive_Images();
388-
new Just_Custom_Fields();
389-
new Just_Post_Preview();
390-
new Just_Tinymce();
389+
Just_Load_More::instance();
390+
Just_Responsive_Images::instance();
391+
Just_Custom_Fields::instance();
392+
Just_Post_Preview::instance();
393+
Just_Tinymce::instance();
391394
}
392395

393396
/**

0 commit comments

Comments
 (0)