-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-feed-for-tiktok-boot.php
118 lines (96 loc) · 3.32 KB
/
custom-feed-for-tiktok-boot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
!defined('WPINC') && die;
define('CUSTOM_FEED_FOR_TIKTOK_VERSION', '1.0.0');
define('CUSTOM_FEED_FOR_TIKTOK', true);
define('CUSTOM_FEED_FOR_TIKTOK_URL', plugin_dir_url(__FILE__));
define('CUSTOM_FEED_FOR_TIKTOK_DIR', plugin_dir_path(__FILE__));
spl_autoload_register(function ($class){
$match = 'CustomFeedForTiktok';
if ( ! preg_match("/\b{$match}\b/", $class)) {
return;
}
$path = plugin_dir_path(__FILE__);
$file = str_replace(
['CustomFeedForTiktok', '\\', '/Application/'],
['', DIRECTORY_SEPARATOR, 'app/'],
$class
);
$filePath = (trailingslashit($path) . trim($file, '/') . '.php');
if (file_exists($filePath)) {
require $filePath;
}
});
class CustomFeedForTiktokDependency
{
public function init()
{
$this->injectDependency();
}
/**
* Notify the user about the WP Social Ninja dependency and instructs to install it.
*/
protected function injectDependency()
{
add_action('admin_notices', function () {
$pluginInfo = $this->getBasePluginInstallationDetails();
$class = 'notice notice-error';
$install_url_text = __('Click Here to Install the Plugin', 'custom-feed-for-tiktok');
if ($pluginInfo->action == 'activate') {
$install_url_text = __('Click Here to Activate the Plugin', 'custom-feed-for-tiktok');
}
$message = 'Custom Feed for TikTok Requires WP Social Ninja Base Plugin, <b><a href="' . $pluginInfo->url
. '">' . $install_url_text . '</a></b>';
// Allowed HTML for wp_kses
$allowed_html = array(
'a' => array(
'href' => array(),
'title' => array()
),
'b' => array(),
'br' => array(),
'em' => array(),
'strong' => array(),
);
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), wp_kses($message, $allowed_html));
});
}
/**
* Get the WP Social Ninja plugin installation information e.g. the URL to install.
*
* @return \stdClass $activation
*/
protected function getBasePluginInstallationDetails()
{
$activation = (object)[
'action' => 'install',
'url' => ''
];
$allPlugins = get_plugins();
$plugin_path = 'wp-social-reviews/wp-social-reviews.php';
if (isset($allPlugins[$plugin_path])) {
$url = wp_nonce_url(
self_admin_url('plugins.php?action=activate&plugin=' . $plugin_path . ''),
'activate-plugin_' . $plugin_path . ''
);
$activation->action = 'activate';
} else {
$api = (object)[
'slug' => 'wp-social-reviews'
];
$url = wp_nonce_url(
self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug),
'install-plugin_' . $api->slug
);
}
$activation->url = $url;
return $activation;
}
}
add_action('init', function ($app) {
if( !defined('WPSOCIALREVIEWS_VERSION') ){
(new CustomFeedForTiktokDependency())->init();
}
});