Addons.php
4.91 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php if ( ! defined( 'ABSPATH' ) ) exit;
final class NF_Admin_Menus_Addons extends NF_Abstracts_Submenu
{
public $parent_slug = 'ninja-forms';
public $menu_slug = 'ninja-forms#apps';
public $position = 7;
public function __construct()
{
$disable_marketing = false;
if ( ! apply_filters( 'ninja_forms_disable_marketing', $disable_marketing ) ) {
parent::__construct();
}
add_action( 'admin_init', array( $this, 'nf_upgrade_redirect' ) );
}
/**
* If we have required updates, unregister the menu item
*/
public function nf_upgrade_redirect() {
global $pagenow;
if( "1" == get_option( 'ninja_forms_needs_updates' ) ) {
remove_submenu_page( $this->parent_slug, $this->menu_slug );
}
}
public function get_page_title()
{
$title = '<span style="color:#84cc1e">' . esc_html__( 'Add-Ons', 'ninja-forms' ) . '</span>';
return $title;
}
public function get_capability()
{
return apply_filters( 'ninja_forms_admin_extend_capabilities', $this->capability );
}
public function display()
{
// Fetch our marketing feed.
$saved = get_option( 'ninja_forms_addons_feed', false );
// If we got back nothing...
if ( ! $saved ) {
// Default to the in-app file.
$items = file_get_contents( Ninja_Forms::$dir . '/lib/Legacy/addons-feed.json' );
$items = json_decode( $items, true );
} // Otherwise... (We did get something from the db.)
else {
// Use the data we fetched.
$items = json_decode( $saved, true );
}
//shuffle( $items );
$notices = array();
foreach ($items as &$item) {
$plugin_data = array();
if( !empty( $item['plugin'] ) && file_exists( WP_PLUGIN_DIR.'/'.$item['plugin'] ) ){
$plugin_data = get_plugin_data( WP_PLUGIN_DIR.'/'.$item['plugin'], false, true );
}
if ( ! file_exists( Ninja_Forms::$dir . '/' . $item[ 'image' ] ) ) {
$item[ 'image' ] = 'assets/img/add-ons/placeholder.png';
}
$version = isset ( $plugin_data['Version'] ) ? $plugin_data['Version'] : '';
if ( ! empty ( $version ) && $version < $item['version'] ) {
$notices[] = array(
'title' => $item[ 'title' ],
'old_version' => $version,
'new_version' => $item[ 'version' ]
);
}
}
$groups = [
'popular' => [
'title' => __( 'You Can Build Smart, Beautiful WordPress Forms!', 'ninja-forms' ),
'items' => self::filterItemsByCategroy( $items, 'form-function-design' ),
],
'documents' => [
'title' => __( 'Better Document Sharing will Take Your Business Further', 'ninja-forms' ),
'items' => self::filterItemsByCategroy( $items, 'file-management' ),
],
'payments' => [
'title' => __( 'Accept Payments & Donations Without Breaking the Bank', 'ninja-forms' ),
'items' => self::filterItemsByCategroy( $items, 'payment-gateways' ),
],
'marketing' => [
'title' => __( 'Want to Attract More Subscribers to Your Mailing Lists?', 'ninja-forms' ),
'items' => self::filterItemsByCategroy( $items, 'email-marketing' ),
],
'website' => [
'title' => __( 'Let Your Users Do More, and Do More for Your Users', 'ninja-forms' ),
'items' => self::filterItemsByCategroy( $items, 'user-management' ),
],
'crm' => [
'title' => __( 'Generate More Leads Than You Ever Thought Possible', 'ninja-forms' ),
'items' => self::filterItemsByCategroy( $items, 'crm-integrations' ),
],
'notifications' => [
'title' => __( 'Never Miss an Important Submission or Lead Again!', 'ninja-forms' ),
'items' => self::filterItemsByCategroy( $items, 'notification-workflow' ),
],
'misc' => [
'title' => __( 'Don’t See Your Favorite Service Above? We Can Likely Still Help.', 'ninja-forms' ),
'items' => self::filterItemsByCategroy( $items, 'custom-integrations' ),
],
];
Ninja_Forms::template( 'admin-menu-addons.html.php', compact( 'items', 'notices', 'groups' ) );
}
public static function filterItemsByCategroy( $items, $category ) {
return array_filter( $items, function( $item ) use ($category) {
return array_filter( $item['categories'], function( $itemCategory ) use ($category){
return $category === $itemCategory['slug'];
});
});
}
} // End Class NF_Admin_Addons