WP User Frontend – Membership, Profile, Registration & Post Submission Plugin for WordPress - Version 3.1.15

Version Description

Download this release

Release Info

Developer tareq1988
Plugin Icon 128x128 WP User Frontend – Membership, Profile, Registration & Post Submission Plugin for WordPress
Version 3.1.15
Comparing to
See all releases

Code changes from version 3.1.14 to 3.1.15

Files changed (116) hide show
  1. .php_cs.dist +148 -0
  2. admin/class-admin-settings.php +77 -79
  3. admin/class-admin-subscription.php +279 -255
  4. admin/class-admin-welcome.php +5 -5
  5. admin/class-tools.php +123 -113
  6. admin/form-builder/assets/js/components/builder-stage/template.php +3 -3
  7. admin/form-builder/assets/js/components/field-option-data/template.php +1 -1
  8. admin/form-builder/assets/js/components/field-visibility/template.php +12 -16
  9. admin/form-builder/assets/js/components/form-recaptcha/template.php +1 -1
  10. admin/form-builder/class-wpuf-admin-form-builder-ajax.php +23 -17
  11. admin/form-builder/class-wpuf-admin-form-builder.php +57 -62
  12. admin/form-builder/class-wpuf-form-builder-field-settings.php +1 -3
  13. admin/form-builder/views/form-builder.php +19 -19
  14. admin/form-handler.php +129 -104
  15. admin/form-template.php +39 -41
  16. admin/form.php +103 -117
  17. admin/html/form-settings-display.php +20 -20
  18. admin/html/form-settings-payment.php +16 -16
  19. admin/html/form-settings-post-edit.php +23 -23
  20. admin/html/form-settings-post.php +67 -55
  21. admin/html/form-submission-restriction.php +40 -40
  22. admin/html/modal.php +37 -35
  23. admin/html/support.php +177 -178
  24. admin/html/whats-new.php +292 -292
  25. admin/installer.php +46 -38
  26. admin/post-forms-list-table-view.php +6 -6
  27. admin/post-forms-list-table.php +71 -57
  28. admin/posting.php +109 -102
  29. admin/premium.php +75 -75
  30. admin/promotion.php +52 -38
  31. admin/settings-options.php +263 -261
  32. admin/subscribers.php +5 -5
  33. admin/template-post.php +70 -81
  34. admin/template.php +685 -713
  35. admin/tools.php +7 -5
  36. admin/transactions.php +1 -1
  37. admin/weforms.php +7 -7
  38. assets/css/admin.css +0 -0
  39. assets/css/chosen/chosen-sprite.png +0 -0
  40. assets/css/chosen/chosen-sprite@2x.png +0 -0
  41. assets/css/chosen/chosen.css +0 -0
  42. assets/css/frontend-forms.css +0 -0
  43. assets/css/images/ui-bg_diagonals-small_75_cccccc_40x40.png +0 -0
  44. assets/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  45. assets/css/images/ui-bg_flat_0_ffffff_40x100.png +0 -0
  46. assets/css/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  47. assets/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  48. assets/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  49. assets/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  50. assets/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  51. assets/css/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  52. assets/css/images/ui-icons_222222_256x240.png +0 -0
  53. assets/css/images/ui-icons_2e83ff_256x240.png +0 -0
  54. assets/css/images/ui-icons_454545_256x240.png +0 -0
  55. assets/css/images/ui-icons_888888_256x240.png +0 -0
  56. assets/css/images/ui-icons_cd0a0a_256x240.png +0 -0
  57. assets/css/jquery-ui-1.9.1.custom.css +0 -0
  58. assets/css/jquery.smallipop.css +0 -0
  59. assets/css/wpuf.css +0 -0
  60. assets/images/add.png +0 -0
  61. assets/images/arrow-move.png +0 -0
  62. assets/images/arrows.png +0 -0
  63. assets/images/completed.png +0 -0
  64. assets/images/cross.png +0 -0
  65. assets/images/del.png +0 -0
  66. assets/images/delete.png +0 -0
  67. assets/images/edit.png +0 -0
  68. assets/images/help.png +0 -0
  69. assets/images/help/bugs.svg +0 -0
  70. assets/images/help/customization.svg +0 -0
  71. assets/images/help/docs.svg +0 -0
  72. assets/images/help/like.svg +0 -0
  73. assets/images/help/support.svg +0 -0
  74. assets/images/icon-128x128.png +0 -0
  75. assets/images/no-image.png +0 -0
  76. assets/images/paypal.png +0 -0
  77. assets/images/processing.png +0 -0
  78. assets/images/remove.png +0 -0
  79. assets/images/tick.png +0 -0
  80. assets/images/wpspin_light.gif +0 -0
  81. assets/js-templates/form-components.php +16 -20
  82. assets/js/chosen.jquery.js +0 -0
  83. assets/js/conditional.js +0 -0
  84. assets/js/frontend-form.js +0 -0
  85. assets/js/frontend-form.min.js +0 -0
  86. assets/js/jquery-ui-timepicker-addon.js +0 -0
  87. assets/js/jquery.smallipop-0.4.0.min.js +0 -0
  88. assets/js/jquery.validate.min.js +0 -0
  89. assets/js/subscriptions.js +2 -1
  90. assets/js/upload.js +0 -0
  91. assets/js/upload.min.js +0 -0
  92. class/admin-asset-loader.php +34 -36
  93. class/asset-loader.php +29 -28
  94. class/frontend-account.php +93 -91
  95. class/frontend-dashboard.php +44 -43
  96. class/payment.php +142 -131
  97. class/post-form-template.php +23 -21
  98. class/post-form-templates/post.php +34 -34
  99. class/render-form.php +404 -431
  100. class/subscription.php +283 -262
  101. class/transactions-list-table.php +103 -96
  102. class/upload.php +83 -60
  103. includes/class-acf.php +45 -45
  104. includes/class-billing-address.php +117 -83
  105. includes/class-customizer.php +31 -33
  106. includes/class-dokan-integration.php +160 -167
  107. includes/class-field-manager.php +92 -134
  108. includes/class-form-manager.php +33 -34
  109. includes/class-form-preview.php +17 -20
  110. includes/class-form.php +68 -99
  111. includes/class-frontend-form-post.php +235 -217
  112. includes/class-frontend-render-form.php +263 -234
  113. includes/class-gutenblock.php +38 -37
  114. includes/class-installer.php +6 -7
  115. includes/class-list-table-subscribers.php +61 -46
  116. includes/class-login-widget.php +111 -354
.php_cs.dist ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $finder = PhpCsFixer\Finder::create()
4
+ ->exclude( 'node_modules' )
5
+ ->exclude( 'vendors' )
6
+ ->in( __DIR__ )
7
+ ;
8
+
9
+ $config = PhpCsFixer\Config::create()
10
+ ->setRiskyAllowed( true )
11
+ ->setUsingCache( false )
12
+ ->setRules( [
13
+ '@PSR2' => true,
14
+ 'align_multiline_comment' => true,
15
+ 'array_syntax' => ['syntax' => 'short'],
16
+ 'binary_operator_spaces' => [
17
+ 'align_double_arrow' => true,
18
+ 'align_equals' => true,
19
+ ],
20
+ 'blank_line_after_opening_tag' => true,
21
+ 'blank_line_before_statement' => [
22
+ 'statements' => ['return', 'try', 'if', 'while', 'for', 'foreach', 'do', 'case'],
23
+ ],
24
+ 'braces' => [
25
+ 'position_after_functions_and_oop_constructs' => 'same',
26
+ 'allow_single_line_closure' => false,
27
+ ],
28
+ 'cast_spaces' => ['space' => 'single'],
29
+ 'class_attributes_separation' => ['elements' => ['method', 'const', 'property']],
30
+ 'class_definition' => ['single_line' => true],
31
+ 'concat_space' => ['spacing' => 'one'],
32
+ 'constant_case' => ['case' => 'lower'],
33
+ 'dir_constant' => true,
34
+ 'elseif' => true,
35
+ 'full_opening_tag' => true,
36
+ 'fully_qualified_strict_types' => true,
37
+ 'function_declaration' => true,
38
+ 'space_inside_parenthesis' => true,
39
+ 'function_typehint_space' => true,
40
+ 'global_namespace_import' => ['import_classes' => true],
41
+ 'include' => true,
42
+ 'line_ending' => true,
43
+ 'list_syntax' => ['syntax' => 'long'],
44
+ 'lowercase_cast' => true,
45
+ 'lowercase_keywords' => true,
46
+ 'lowercase_static_reference' => true,
47
+ 'magic_constant_casing' => true,
48
+ 'magic_method_casing' => true,
49
+ 'method_argument_space' => true,
50
+ 'native_function_casing' => true,
51
+ 'method_chaining_indentation' => true,
52
+ 'native_function_type_declaration_casing' => true,
53
+ 'new_with_braces' => true,
54
+ 'no_alternative_syntax' => true,
55
+ 'no_blank_lines_before_namespace' => true,
56
+ 'no_blank_lines_after_class_opening' => false,
57
+ 'no_blank_lines_after_phpdoc' => true,
58
+ 'no_empty_comment' => true,
59
+ 'no_empty_phpdoc' => true,
60
+ 'no_empty_statement' => true,
61
+ 'no_extra_blank_lines' => ['tokens' => [
62
+ 'extra',
63
+ 'parenthesis_brace_block',
64
+ 'square_brace_block',
65
+ 'throw',
66
+ 'use',
67
+ ]],
68
+ 'no_leading_import_slash' => true,
69
+ 'no_leading_namespace_whitespace' => true,
70
+ 'no_mixed_echo_print' => true,
71
+ 'no_multiline_whitespace_around_double_arrow' => true,
72
+ 'no_short_bool_cast' => true,
73
+ 'no_short_echo_tag' => true,
74
+ 'no_singleline_whitespace_before_semicolons' => true,
75
+ 'no_spaces_around_offset' => ['positions' => ['outside']],
76
+ 'no_spaces_inside_parenthesis' => false,
77
+ 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'allow_unused_params' => true],
78
+ 'no_trailing_comma_in_list_call' => true,
79
+ 'no_trailing_comma_in_singleline_array' => true,
80
+ 'no_trailing_whitespace' => true,
81
+ 'no_unneeded_control_parentheses' => true,
82
+ 'no_unneeded_curly_braces' => true,
83
+ 'no_unneeded_final_method' => true,
84
+ 'no_unused_imports' => true,
85
+ 'no_whitespace_before_comma_in_array' => true,
86
+ 'no_whitespace_in_blank_line' => true,
87
+ 'normalize_index_brace' => true,
88
+ 'object_operator_without_whitespace' => true,
89
+ 'ordered_imports' => true,
90
+ 'php_unit_fqcn_annotation' => true,
91
+ 'phpdoc_align' => [
92
+ 'align' => 'vertical',
93
+ 'tags' => [
94
+ 'method',
95
+ 'param',
96
+ 'property',
97
+ 'return',
98
+ 'throws',
99
+ 'type',
100
+ 'var',
101
+ ],
102
+ ],
103
+ 'phpdoc_annotation_without_dot' => true,
104
+ 'phpdoc_indent' => true,
105
+ 'phpdoc_inline_tag' => true,
106
+ 'phpdoc_no_access' => true,
107
+ 'phpdoc_no_alias_tag' => true,
108
+ 'phpdoc_no_package' => true,
109
+ 'phpdoc_no_useless_inheritdoc' => true,
110
+ 'phpdoc_return_self_reference' => true,
111
+ 'phpdoc_scalar' => true,
112
+ 'phpdoc_separation' => true,
113
+ 'phpdoc_single_line_var_spacing' => true,
114
+ 'phpdoc_to_comment' => true,
115
+ 'phpdoc_trim' => true,
116
+ 'phpdoc_trim_consecutive_blank_line_separation' => true,
117
+ 'phpdoc_types' => true,
118
+ 'phpdoc_types_order' => [
119
+ 'null_adjustment' => 'always_last',
120
+ 'sort_algorithm' => 'none',
121
+ ],
122
+ 'phpdoc_var_without_name' => true,
123
+ 'return_type_declaration' => true,
124
+ 'semicolon_after_instruction' => true,
125
+ 'short_scalar_cast' => true,
126
+ 'single_class_element_per_statement' => true,
127
+ 'single_line_comment_style' => [
128
+ 'comment_types' => ['hash'],
129
+ ],
130
+ 'single_line_throw' => true,
131
+ 'single_quote' => true,
132
+ 'single_trait_insert_per_statement' => true,
133
+ 'space_after_semicolon' => [
134
+ 'remove_in_empty_for_expressions' => true,
135
+ ],
136
+ 'standardize_increment' => true,
137
+ 'standardize_not_equals' => true,
138
+ 'ternary_operator_spaces' => true,
139
+ 'trailing_comma_in_multiline_array' => true,
140
+ 'trim_array_spaces' => false,
141
+ 'unary_operator_spaces' => true,
142
+ 'whitespace_after_comma_in_array' => true,
143
+ // 'yoda_style' => true,
144
+ ] )
145
+ ->setFinder( $finder )
146
+ ;
147
+
148
+ return $config;
admin/class-admin-settings.php CHANGED
@@ -1,9 +1,7 @@
1
  <?php
2
 
3
  /**
4
- * WordPress settings API demo class
5
- *
6
- * @author Tareq Hasan
7
  */
8
  class WPUF_Admin_Settings {
9
 
@@ -35,24 +33,23 @@ class WPUF_Admin_Settings {
35
  *
36
  * @var array
37
  */
38
- private $menu_pages = array();
39
 
40
  public function __construct() {
41
-
42
- if ( ! class_exists( 'WeDevs_Settings_API' ) ) {
43
- require_once dirname( dirname( __FILE__ ) ) . '/lib/class.settings-api.php';
44
  }
45
 
46
  $this->settings_api = new WeDevs_Settings_API();
47
 
48
- add_action( 'admin_init', array($this, 'admin_init') );
49
- add_action( 'admin_menu', array($this, 'admin_menu') );
50
 
51
- add_filter( 'parent_file', array($this, 'fix_parent_menu' ) );
52
- add_filter( 'submenu_file', array($this, 'fix_submenu_file' ) );
53
 
54
- add_action( 'admin_init', array($this, 'handle_tools_action') );
55
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
56
  }
57
 
58
  public static function init() {
@@ -63,7 +60,7 @@ class WPUF_Admin_Settings {
63
  return self::$_instance;
64
  }
65
 
66
- function admin_init() {
67
 
68
  //set the settings
69
  $this->settings_api->set_sections( $this->get_settings_sections() );
@@ -78,54 +75,56 @@ class WPUF_Admin_Settings {
78
  *
79
  * @since 1.0
80
  */
81
- function admin_menu() {
82
  global $_registered_pages;
83
 
84
  $capability = wpuf_admin_role();
85
 
86
  // Translation issue: Hook name change due to translate menu title
87
- $this->menu_pages[] = add_menu_page( __( 'WP User Frontend', 'wp-user-frontend' ), __( 'User Frontend', '' ), $capability, 'wp-user-frontend', array($this, 'wpuf_post_forms_page'), 'data:image/svg+xml;base64,' . base64_encode( '<svg width="83px" height="76px" viewBox="0 0 83 76" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="wpuf-icon" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="ufp" fill-rule="nonzero" fill="#9EA3A8"><path d="M49.38,51.88 C49.503348,56.4604553 45.8999295,60.2784694 41.32,60.42 C36.7400705,60.2784694 33.136652,56.4604553 33.26,51.88 L33.26,40.23 L19,40.23 L19,51.88 C19,64.77 29,75.25 41.36,75.26 L41.36,75.26 C47.3622079,75.2559227 53.0954073,72.7693647 57.2,68.39 C61.4213559,63.9375842 63.7575868,58.0253435 63.72,51.89 L63.72,40.23 L49.38,40.23 L49.38,51.88 Z" id="Shape"></path><polygon id="Shape" points="32.96 0.59 0 0.59 3.77 16.68 32.96 16.68"></polygon><path d="M68,0 L49.75,0 L49.75,16.1 L68,16.1 C68.74,16.1 69.39,17.1 69.39,18.24 C69.39,19.38 68.74,20.38 68,20.38 L49.75,20.38 L49.75,36.5 L68,36.5 C76,36.5 82.5,28.31 82.5,18.25 C82.5,8.19 76,0 68,0 Z" id="Shape"></path><polygon id="Shape" points="32.96 20.41 5.31 20.41 9.07 36.5 32.96 36.5"></polygon></g></g></svg>' ), 55 );
88
 
89
- $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Post Forms', 'wp-user-frontend' ), __( 'Post Forms', 'wp-user-frontend' ), $capability, 'wpuf-post-forms', array( $this, 'wpuf_post_forms_page' ) );
90
  remove_submenu_page( 'wp-user-frontend', 'wp-user-frontend' );
91
 
92
- /**
93
  * @since 2.3
94
  */
95
  do_action( 'wpuf_admin_menu_top' );
96
 
97
  if ( !class_exists( 'WeForms' ) ) {
98
- $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'weForms', 'wp-user-frontend' ), __( 'Contact Form', 'wp-user-frontend' ), $capability, 'wpuf_weforms', array($this, 'weforms_page') );
99
  }
 
100
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
101
  $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Subscriptions', 'wp-user-frontend' ), __( 'Subscriptions', 'wp-user-frontend' ), $capability, 'edit.php?post_type=wpuf_subscription' );
102
  }
103
 
104
- do_action( 'wpuf_admin_menu' );
105
 
106
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
107
- $transactions_page = add_submenu_page( 'wp-user-frontend', __( 'Transactions', 'wp-user-frontend' ), __( 'Transactions', 'wp-user-frontend' ), $capability, 'wpuf_transaction', array($this, 'transactions_page') );
108
  }
109
 
110
- $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Tools', 'wp-user-frontend' ), __( 'Tools', 'wp-user-frontend' ), $capability, 'wpuf_tools', array($this, 'tools_page') );
111
 
112
  do_action( 'wpuf_admin_menu_bottom' );
113
 
114
  if ( !class_exists( 'WP_User_Frontend_Pro' ) ) {
115
- $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Premium', 'wp-user-frontend' ), __( 'Premium', 'wp-user-frontend' ), $capability, 'wpuf_premium', array($this, 'premium_page') );
116
  }
117
- $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Help', 'wp-user-frontend' ), __( '<span style="color:#f18500">Help</span>', 'wp-user-frontend' ), $capability, 'wpuf-support', array($this, 'support_page') );
118
- $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Settings', 'wp-user-frontend' ), __( 'Settings', 'wp-user-frontend' ), $capability, 'wpuf-settings', array($this, 'plugin_page') );
119
 
120
- $this->menu_pages[] = add_submenu_page( 'edit.php?post_type=wpuf_subscription', __( 'Subscribers', 'wp-user-frontend' ), __( 'Subscribers', 'wp-user-frontend' ), $capability, 'wpuf_subscribers', array($this, 'subscribers_page') );
121
  $_registered_pages['user-frontend_page_wpuf_subscribers'] = true; // hack to work the nested subscribers page
122
 
123
  // manually add subsription page
124
  $this->menu_pages[] = 'edit-wpuf_subscription';
125
  $this->menu_pages[] = 'wpuf_subscribers';
126
  $this->menu_pages[] = 'user-frontend_page_wpuf_transaction';
 
127
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
128
- add_action( "load-$transactions_page", array( $this, 'transactions_screen_option' ) );
129
  // add_action( "load-wpuf_subscribers", array( $this, 'subscribers_screen_option' ) );
130
  }
131
  }
@@ -134,9 +133,10 @@ class WPUF_Admin_Settings {
134
  * WPUF Settings sections
135
  *
136
  * @since 1.0
 
137
  * @return array
138
  */
139
- function get_settings_sections() {
140
  return wpuf_settings_sections();
141
  }
142
 
@@ -145,29 +145,28 @@ class WPUF_Admin_Settings {
145
  *
146
  * @return array settings fields
147
  */
148
- function get_settings_fields() {
149
  return wpuf_settings_fields();
150
  }
151
 
152
- function plugin_page() {
153
  ?>
154
  <div class="wrap">
155
 
156
- <h2 style="margin-bottom: 15px;"><?php _e( 'Settings', 'wp-user-frontend' ) ?></h2>
157
  <div class="wpuf-settings-wrap">
158
  <?php
159
  settings_errors();
160
 
161
  $this->settings_api->show_navigation();
162
- $this->settings_api->show_forms();
163
- ?>
164
  </div>
165
  </div>
166
  <?php
167
  }
168
 
169
- function transactions_page() {
170
- require_once dirname( dirname( __FILE__ ) ) . '/admin/transactions.php';
171
  }
172
 
173
  /**
@@ -177,8 +176,8 @@ class WPUF_Admin_Settings {
177
  *
178
  * @return void
179
  */
180
- function wpuf_post_forms_page() {
181
- $action = isset( $_GET['action'] ) ? $_GET['action'] : null;
182
  $add_new_page_url = admin_url( 'admin.php?page=wpuf-post-forms&action=add-new' );
183
 
184
  switch ( $action ) {
@@ -196,36 +195,36 @@ class WPUF_Admin_Settings {
196
  }
197
  }
198
 
199
- function subscription_page() {
200
- require_once dirname( dirname( __FILE__ ) ) . '/admin/subscription.php';
201
  }
202
 
203
- function subscribers_page($post_ID) {
204
- include dirname( dirname( __FILE__ ) ) . '/admin/subscribers.php';
205
  }
206
 
207
- function weforms_page() {
208
- require_once dirname( dirname( __FILE__ ) ) . '/admin/weforms.php';
209
  }
210
 
211
- function premium_page() {
212
- require_once dirname( dirname( __FILE__ ) ) . '/admin/premium.php';
213
  }
214
 
215
- function tools_page() {
216
- include dirname( dirname( __FILE__ ) ) . '/admin/tools.php';
217
  }
218
 
219
- function support_page() {
220
- require_once dirname( dirname( __FILE__ ) ) . '/admin/html/support.php';
221
  }
222
 
223
  /**
224
  * Check if the current page is a settings/menu page
225
  *
226
- * @param string $screen_id
227
  *
228
- * @return boolean
229
  */
230
  public function is_admin_menu_page( $screen ) {
231
  if ( $screen && in_array( $screen->id, $this->menu_pages ) ) {
@@ -238,7 +237,7 @@ class WPUF_Admin_Settings {
238
  /**
239
  * highlight the proper top level menu
240
  *
241
- * @link http://wordpress.org/support/topic/moving-taxonomy-ui-to-another-main-menu?replies=5#post-2432769
242
  *
243
  * @global obj $current_screen
244
  *
@@ -246,10 +245,10 @@ class WPUF_Admin_Settings {
246
  *
247
  * @return string
248
  */
249
- function fix_parent_menu( $parent_file ) {
250
  $current_screen = get_current_screen();
251
 
252
- $post_types = array( 'wpuf_forms', 'wpuf_profile', 'wpuf_subscription', 'wpuf_coupon');
253
 
254
  if ( in_array( $current_screen->post_type, $post_types ) ) {
255
  $parent_file = 'wp-user-frontend';
@@ -267,7 +266,7 @@ class WPUF_Admin_Settings {
267
  *
268
  * @since 2.6.0
269
  *
270
- * @param string $submenu_file
271
  *
272
  * @return string
273
  */
@@ -286,23 +285,23 @@ class WPUF_Admin_Settings {
286
  *
287
  * @return void
288
  */
289
- function handle_tools_action() {
290
- if ( ! isset( $_GET['wpuf_action'] ) ) {
291
  return;
292
  }
293
 
294
  check_admin_referer( 'wpuf-tools-action' );
295
 
296
- if ( ! current_user_can( 'manage_options' ) ) {
297
  return;
298
  }
299
 
300
  global $wpdb;
301
 
302
- $action = $_GET['wpuf_action'];
303
  $message = 'del_forms';
304
 
305
- switch ($action) {
306
  case 'clear_settings':
307
  delete_option( 'wpuf_general' );
308
  delete_option( 'wpuf_dashboard' );
@@ -330,37 +329,38 @@ class WPUF_Admin_Settings {
330
  break;
331
 
332
  case 'clear_transaction':
333
- $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}wpuf_transaction");
334
 
335
  $message = 'del_trans';
336
  break;
337
 
338
  default:
339
- # code...
340
  break;
341
  }
342
 
343
- wp_redirect( add_query_arg( array( 'msg' => $message ), admin_url( 'admin.php?page=wpuf_tools&action=tools' ) ) );
344
  exit;
345
  }
346
 
347
  /**
348
  * Delete all posts by a post type
349
  *
350
- * @param string $post_type
 
351
  * @return void
352
  */
353
- function delete_post_type( $post_type ) {
354
- $query = new WP_Query( array(
355
  'post_type' => $post_type,
356
  'posts_per_page' => -1,
357
- 'post_status' => array( 'publish', 'draft', 'pending', 'trash' )
358
- ) );
359
 
360
  $posts = $query->get_posts();
361
 
362
  if ( $posts ) {
363
- foreach ($posts as $item) {
364
  wp_delete_post( $item->ID, true );
365
  }
366
  }
@@ -373,15 +373,15 @@ class WPUF_Admin_Settings {
373
  */
374
  public function transactions_screen_option() {
375
  $option = 'per_page';
376
- $args = array(
377
  'label' => __( 'Number of items per page:', 'wp-user-frontend' ),
378
  'default' => 20,
379
- 'option' => 'transactions_per_page'
380
- );
381
 
382
  add_screen_option( $option, $args );
383
 
384
- if ( ! class_exists( 'WPUF_Transactions_List_Table' ) ) {
385
  require_once WPUF_ROOT . '/class/transactions-list-table.php';
386
  }
387
 
@@ -394,19 +394,17 @@ class WPUF_Admin_Settings {
394
  * @return void
395
  */
396
  public function enqueue_styles() {
397
-
398
- if ( ! $this->is_admin_menu_page( get_current_screen() ) && get_current_screen()->parent_base == 'edit' ) {
399
  return;
400
  }
401
 
402
  wp_enqueue_style( 'wpuf-admin', WPUF_ASSET_URI . '/css/admin.css', false, WPUF_VERSION );
403
- wp_enqueue_script( 'wpuf-admin-script', WPUF_ASSET_URI . '/js/wpuf-admin.js', array( 'jquery' ), false, WPUF_VERSION );
404
 
405
- wp_localize_script( 'wpuf-admin-script', 'wpuf_admin_script', array(
406
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
407
  'nonce' => wp_create_nonce( 'wpuf_nonce' ),
408
  'cleared_schedule_lock' => __( 'Post lock has been cleared', 'wp-user-frontend' ),
409
- ) );
410
  }
411
-
412
  }
1
  <?php
2
 
3
  /**
4
+ * WPUF settings
 
 
5
  */
6
  class WPUF_Admin_Settings {
7
 
33
  *
34
  * @var array
35
  */
36
+ private $menu_pages = [];
37
 
38
  public function __construct() {
39
+ if ( !class_exists( 'WeDevs_Settings_API' ) ) {
40
+ require_once dirname( __DIR__ ) . '/lib/class.settings-api.php';
 
41
  }
42
 
43
  $this->settings_api = new WeDevs_Settings_API();
44
 
45
+ add_action( 'admin_init', [$this, 'admin_init'] );
46
+ add_action( 'admin_menu', [$this, 'admin_menu'] );
47
 
48
+ add_filter( 'parent_file', [$this, 'fix_parent_menu' ] );
49
+ add_filter( 'submenu_file', [$this, 'fix_submenu_file' ] );
50
 
51
+ add_action( 'admin_init', [$this, 'handle_tools_action'] );
52
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] );
53
  }
54
 
55
  public static function init() {
60
  return self::$_instance;
61
  }
62
 
63
+ public function admin_init() {
64
 
65
  //set the settings
66
  $this->settings_api->set_sections( $this->get_settings_sections() );
75
  *
76
  * @since 1.0
77
  */
78
+ public function admin_menu() {
79
  global $_registered_pages;
80
 
81
  $capability = wpuf_admin_role();
82
 
83
  // Translation issue: Hook name change due to translate menu title
84
+ $this->menu_pages[] = add_menu_page( __( 'WP User Frontend', 'wp-user-frontend' ), __( 'User Frontend', '' ), $capability, 'wp-user-frontend', [$this, 'wpuf_post_forms_page'], 'data:image/svg+xml;base64,' . base64_encode( '<svg width="83px" height="76px" viewBox="0 0 83 76" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="wpuf-icon" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="ufp" fill-rule="nonzero" fill="#9EA3A8"><path d="M49.38,51.88 C49.503348,56.4604553 45.8999295,60.2784694 41.32,60.42 C36.7400705,60.2784694 33.136652,56.4604553 33.26,51.88 L33.26,40.23 L19,40.23 L19,51.88 C19,64.77 29,75.25 41.36,75.26 L41.36,75.26 C47.3622079,75.2559227 53.0954073,72.7693647 57.2,68.39 C61.4213559,63.9375842 63.7575868,58.0253435 63.72,51.89 L63.72,40.23 L49.38,40.23 L49.38,51.88 Z" id="Shape"></path><polygon id="Shape" points="32.96 0.59 0 0.59 3.77 16.68 32.96 16.68"></polygon><path d="M68,0 L49.75,0 L49.75,16.1 L68,16.1 C68.74,16.1 69.39,17.1 69.39,18.24 C69.39,19.38 68.74,20.38 68,20.38 L49.75,20.38 L49.75,36.5 L68,36.5 C76,36.5 82.5,28.31 82.5,18.25 C82.5,8.19 76,0 68,0 Z" id="Shape"></path><polygon id="Shape" points="32.96 20.41 5.31 20.41 9.07 36.5 32.96 36.5"></polygon></g></g></svg>' ), 55 );
85
 
86
+ $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Post Forms', 'wp-user-frontend' ), __( 'Post Forms', 'wp-user-frontend' ), $capability, 'wpuf-post-forms', [ $this, 'wpuf_post_forms_page' ] );
87
  remove_submenu_page( 'wp-user-frontend', 'wp-user-frontend' );
88
 
89
+ /*
90
  * @since 2.3
91
  */
92
  do_action( 'wpuf_admin_menu_top' );
93
 
94
  if ( !class_exists( 'WeForms' ) ) {
95
+ $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'weForms', 'wp-user-frontend' ), __( 'Contact Form', 'wp-user-frontend' ), $capability, 'wpuf_weforms', [$this, 'weforms_page'] );
96
  }
97
+
98
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
99
  $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Subscriptions', 'wp-user-frontend' ), __( 'Subscriptions', 'wp-user-frontend' ), $capability, 'edit.php?post_type=wpuf_subscription' );
100
  }
101
 
102
+ do_action( 'wpuf_admin_menu' );
103
 
104
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
105
+ $transactions_page = add_submenu_page( 'wp-user-frontend', __( 'Transactions', 'wp-user-frontend' ), __( 'Transactions', 'wp-user-frontend' ), $capability, 'wpuf_transaction', [$this, 'transactions_page'] );
106
  }
107
 
108
+ $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Tools', 'wp-user-frontend' ), __( 'Tools', 'wp-user-frontend' ), $capability, 'wpuf_tools', [$this, 'tools_page'] );
109
 
110
  do_action( 'wpuf_admin_menu_bottom' );
111
 
112
  if ( !class_exists( 'WP_User_Frontend_Pro' ) ) {
113
+ $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Premium', 'wp-user-frontend' ), __( 'Premium', 'wp-user-frontend' ), $capability, 'wpuf_premium', [$this, 'premium_page'] );
114
  }
115
+ $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Help', 'wp-user-frontend' ), __( '<span style="color:#f18500">Help</span>', 'wp-user-frontend' ), $capability, 'wpuf-support', [$this, 'support_page'] );
116
+ $this->menu_pages[] = add_submenu_page( 'wp-user-frontend', __( 'Settings', 'wp-user-frontend' ), __( 'Settings', 'wp-user-frontend' ), $capability, 'wpuf-settings', [$this, 'plugin_page'] );
117
 
118
+ $this->menu_pages[] = add_submenu_page( 'edit.php?post_type=wpuf_subscription', __( 'Subscribers', 'wp-user-frontend' ), __( 'Subscribers', 'wp-user-frontend' ), $capability, 'wpuf_subscribers', [$this, 'subscribers_page'] );
119
  $_registered_pages['user-frontend_page_wpuf_subscribers'] = true; // hack to work the nested subscribers page
120
 
121
  // manually add subsription page
122
  $this->menu_pages[] = 'edit-wpuf_subscription';
123
  $this->menu_pages[] = 'wpuf_subscribers';
124
  $this->menu_pages[] = 'user-frontend_page_wpuf_transaction';
125
+
126
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
127
+ add_action( "load-$transactions_page", [ $this, 'transactions_screen_option' ] );
128
  // add_action( "load-wpuf_subscribers", array( $this, 'subscribers_screen_option' ) );
129
  }
130
  }
133
  * WPUF Settings sections
134
  *
135
  * @since 1.0
136
+ *
137
  * @return array
138
  */
139
+ public function get_settings_sections() {
140
  return wpuf_settings_sections();
141
  }
142
 
145
  *
146
  * @return array settings fields
147
  */
148
+ public function get_settings_fields() {
149
  return wpuf_settings_fields();
150
  }
151
 
152
+ public function plugin_page() {
153
  ?>
154
  <div class="wrap">
155
 
156
+ <h2 style="margin-bottom: 15px;"><?php esc_html_e( 'Settings', 'wp-user-frontend' ); ?></h2>
157
  <div class="wpuf-settings-wrap">
158
  <?php
159
  settings_errors();
160
 
161
  $this->settings_api->show_navigation();
162
+ $this->settings_api->show_forms(); ?>
 
163
  </div>
164
  </div>
165
  <?php
166
  }
167
 
168
+ public function transactions_page() {
169
+ require_once dirname( __DIR__ ) . '/admin/transactions.php';
170
  }
171
 
172
  /**
176
  *
177
  * @return void
178
  */
179
+ public function wpuf_post_forms_page() {
180
+ $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : null;
181
  $add_new_page_url = admin_url( 'admin.php?page=wpuf-post-forms&action=add-new' );
182
 
183
  switch ( $action ) {
195
  }
196
  }
197
 
198
+ public function subscription_page() {
199
+ require_once dirname( __DIR__ ) . '/admin/subscription.php';
200
  }
201
 
202
+ public function subscribers_page( $post_ID ) {
203
+ include dirname( __DIR__ ) . '/admin/subscribers.php';
204
  }
205
 
206
+ public function weforms_page() {
207
+ require_once dirname( __DIR__ ) . '/admin/weforms.php';
208
  }
209
 
210
+ public function premium_page() {
211
+ require_once dirname( __DIR__ ) . '/admin/premium.php';
212
  }
213
 
214
+ public function tools_page() {
215
+ include dirname( __DIR__ ) . '/admin/tools.php';
216
  }
217
 
218
+ public function support_page() {
219
+ require_once dirname( __DIR__ ) . '/admin/html/support.php';
220
  }
221
 
222
  /**
223
  * Check if the current page is a settings/menu page
224
  *
225
+ * @param string $screen_id
226
  *
227
+ * @return bool
228
  */
229
  public function is_admin_menu_page( $screen ) {
230
  if ( $screen && in_array( $screen->id, $this->menu_pages ) ) {
237
  /**
238
  * highlight the proper top level menu
239
  *
240
+ * @see http://wordpress.org/support/topic/moving-taxonomy-ui-to-another-main-menu?replies=5#post-2432769
241
  *
242
  * @global obj $current_screen
243
  *
245
  *
246
  * @return string
247
  */
248
+ public function fix_parent_menu( $parent_file ) {
249
  $current_screen = get_current_screen();
250
 
251
+ $post_types = [ 'wpuf_forms', 'wpuf_profile', 'wpuf_subscription', 'wpuf_coupon'];
252
 
253
  if ( in_array( $current_screen->post_type, $post_types ) ) {
254
  $parent_file = 'wp-user-frontend';
266
  *
267
  * @since 2.6.0
268
  *
269
+ * @param string $submenu_file
270
  *
271
  * @return string
272
  */
285
  *
286
  * @return void
287
  */
288
+ public function handle_tools_action() {
289
+ if ( !isset( $_GET['wpuf_action'] ) ) {
290
  return;
291
  }
292
 
293
  check_admin_referer( 'wpuf-tools-action' );
294
 
295
+ if ( !current_user_can( 'manage_options' ) ) {
296
  return;
297
  }
298
 
299
  global $wpdb;
300
 
301
+ $action = isset( $_GET['wpuf_action'] ) ? sanitize_text_field( wp_unslash( $_GET['wpuf_action'] ) ) : '';
302
  $message = 'del_forms';
303
 
304
+ switch ( $action ) {
305
  case 'clear_settings':
306
  delete_option( 'wpuf_general' );
307
  delete_option( 'wpuf_dashboard' );
329
  break;
330
 
331
  case 'clear_transaction':
332
+ $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}wpuf_transaction" );
333
 
334
  $message = 'del_trans';
335
  break;
336
 
337
  default:
338
+ // code...
339
  break;
340
  }
341
 
342
+ wp_redirect( add_query_arg( [ 'msg' => $message ], admin_url( 'admin.php?page=wpuf_tools&action=tools' ) ) );
343
  exit;
344
  }
345
 
346
  /**
347
  * Delete all posts by a post type
348
  *
349
+ * @param string $post_type
350
+ *
351
  * @return void
352
  */
353
+ public function delete_post_type( $post_type ) {
354
+ $query = new WP_Query( [
355
  'post_type' => $post_type,
356
  'posts_per_page' => -1,
357
+ 'post_status' => [ 'publish', 'draft', 'pending', 'trash' ],
358
+ ] );
359
 
360
  $posts = $query->get_posts();
361
 
362
  if ( $posts ) {
363
+ foreach ( $posts as $item ) {
364
  wp_delete_post( $item->ID, true );
365
  }
366
  }
373
  */
374
  public function transactions_screen_option() {
375
  $option = 'per_page';
376
+ $args = [
377
  'label' => __( 'Number of items per page:', 'wp-user-frontend' ),
378
  'default' => 20,
379
+ 'option' => 'transactions_per_page',
380
+ ];
381
 
382
  add_screen_option( $option, $args );
383
 
384
+ if ( !class_exists( 'WPUF_Transactions_List_Table' ) ) {
385
  require_once WPUF_ROOT . '/class/transactions-list-table.php';
386
  }
387
 
394
  * @return void
395
  */
396
  public function enqueue_styles() {
397
+ if ( !$this->is_admin_menu_page( get_current_screen() ) && get_current_screen()->parent_base == 'edit' ) {
 
398
  return;
399
  }
400
 
401
  wp_enqueue_style( 'wpuf-admin', WPUF_ASSET_URI . '/css/admin.css', false, WPUF_VERSION );
402
+ wp_enqueue_script( 'wpuf-admin-script', WPUF_ASSET_URI . '/js/wpuf-admin.js', [ 'jquery' ], false, WPUF_VERSION );
403
 
404
+ wp_localize_script( 'wpuf-admin-script', 'wpuf_admin_script', [
405
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
406
  'nonce' => wp_create_nonce( 'wpuf_nonce' ),
407
  'cleared_schedule_lock' => __( 'Post lock has been cleared', 'wp-user-frontend' ),
408
+ ] );
409
  }
 
410
  }
admin/class-admin-subscription.php CHANGED
@@ -2,8 +2,6 @@
2
 
3
  /**
4
  * Manage Subscription packs
5
- *
6
- * @package WP User Frontend
7
  */
8
  class WPUF_Admin_Subscription {
9
 
@@ -18,26 +16,25 @@ class WPUF_Admin_Subscription {
18
  * The constructor
19
  */
20
  public function __construct() {
 
21
 
22
- add_filter( 'post_updated_messages', array($this, 'form_updated_message') );
 
 
 
 
23
 
24
- add_action( 'show_user_profile', array($this, 'profile_subscription_details'), 30 );
25
- add_action( 'edit_user_profile', array($this, 'profile_subscription_details'), 30 );
26
- add_action( 'personal_options_update', array($this, 'profile_subscription_update') );
27
- add_action( 'edit_user_profile_update', array($this, 'profile_subscription_update') );
28
- add_action( 'wp_ajax_wpuf_delete_user_package', array($this, 'delete_user_package') );
29
-
30
- add_filter( 'manage_wpuf_subscription_posts_columns', array( $this, 'subscription_columns_head') );
31
- add_action( 'manage_wpuf_subscription_posts_custom_column', array( $this, 'subscription_columns_content' ),10, 2 );
32
 
33
  // display help link to docs
34
- add_action( 'admin_notices', array( $this, 'add_help_link' ) );
35
 
36
  // new subscription metabox hooks
37
- add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
38
- add_action( 'admin_print_styles-post-new.php', array( $this, 'enqueue_scripts' ) );
39
- add_action( 'admin_print_styles-post.php', array( $this, 'enqueue_scripts' ) );
40
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_profile_script' ) );
41
  }
42
 
43
  /**
@@ -57,18 +54,19 @@ class WPUF_Admin_Subscription {
57
  * Add settings metaboxes
58
  */
59
  public function add_meta_boxes() {
60
- add_meta_box( 'wpuf-metabox-subscription', __( 'Pack Description', 'wp-user-frontend' ), array($this, 'pack_description_metabox'), 'wpuf_subscription', 'normal', 'high' );
61
- add_meta_box( 'wpuf_subs_metabox', 'Subscription Options', array( $this, 'subs_meta_box' ), 'wpuf_subscription' );
62
  }
63
 
64
  /**
65
  * Custom post update message
66
  *
67
- * @param array $messages
 
68
  * @return array
69
  */
70
- function form_updated_message( $messages ) {
71
- $message = array(
72
  0 => '',
73
  1 => __( 'Subscription pack updated.', 'wp-user-frontend' ),
74
  2 => __( 'Custom field updated.', 'wp-user-frontend' ),
@@ -80,7 +78,7 @@ class WPUF_Admin_Subscription {
80
  8 => __( 'Subscription pack submitted.', 'wp-user-frontend' ),
81
  9 => '',
82
  10 => __( 'Subscription pack draft updated.', 'wp-user-frontend' ),
83
- );
84
 
85
  $messages['wpuf_subscription'] = $message;
86
 
@@ -92,55 +90,66 @@ class WPUF_Admin_Subscription {
92
  *
93
  * @param int $user_id
94
  */
95
- function profile_subscription_update( $user_id ) {
96
  if ( !is_admin() && !current_user_can( 'edit_users' ) ) {
97
  return;
98
  }
 
 
 
 
 
99
 
100
  if ( !isset( $_POST['pack_id'] ) ) {
101
  return;
102
  }
103
 
104
  if ( isset( $_POST['wpuf_profile_mail_noti'] ) ) {
105
- update_user_meta( $user_id, '_pack_assign_notification', $_POST['wpuf_profile_mail_noti'] );
 
106
  }
107
 
108
- $pack_id = $_POST['pack_id'];
109
- $pack = WPUF_Subscription::get_subscription( $_POST['pack_id'] );
110
- $user_pack = WPUF_Subscription::get_user_pack( $_POST['user_id'] );
 
111
 
112
- if ( isset ( $user_pack['pack_id'] ) && $pack_id == $user_pack['pack_id'] ) {
113
  //updating number of posts
114
 
115
- if( isset( $user_pack['posts'] ) ) {
116
-
117
- foreach( $user_pack['posts'] as $post_type => $post_num ) {
118
- $user_pack['posts'][$post_type] = $_POST[$post_type];
119
  }
120
-
121
  }
122
 
123
  //post expiration enable or disable
124
 
125
- if( isset( $_POST['is_post_expiration_enabled'] ) ) {
126
- $user_pack['_enable_post_expiration'] = $_POST['is_post_expiration_enabled'];
127
  } else {
128
- unset($user_pack['_enable_post_expiration']);
129
  }
130
 
131
  //updating post time
132
- if( isset( $_POST['post_expiration_settings'] ) ) {
133
- echo $user_pack['_post_expiration_time'] = $_POST['post_expiration_settings']['expiration_time_value'].' '.$_POST['post_expiration_settings']['expiration_time_type'];
 
 
 
 
134
  }
 
135
  if ( isset( $user_pack['recurring'] ) && $user_pack['recurring'] == 'yes' ) {
136
  foreach ( $user_pack['posts'] as $type => $value ) {
137
- $user_pack['posts'][$type] = isset( $_POST[$type] ) ? $_POST[$type] : 0;
138
  }
139
  } else {
140
  foreach ( $user_pack['posts'] as $type => $value ) {
141
- $user_pack['posts'][$type] = isset( $_POST[$type] ) ? $_POST[$type] : 0;
142
  }
143
- $user_pack['expire'] = isset( $_POST['expire'] ) ? wpuf_date2mysql( $_POST['expire'] ) : $user_pack['expire'];
144
  }
145
  wpuf_get_user( $user_id )->subscription()->update_meta( $user_pack );
146
  } else {
@@ -153,7 +162,7 @@ class WPUF_Admin_Subscription {
153
  $billing_amount = apply_filters( 'wpuf_payment_amount', $cost );
154
  $tax_amount = $billing_amount - $cost;
155
 
156
- $data = array(
157
  'user_id' => $user_id,
158
  'status' => 'completed',
159
  'subtotal' => $cost,
@@ -169,7 +178,7 @@ class WPUF_Admin_Subscription {
169
  'transaction_id' => 0,
170
  'created' => current_time( 'mysql' ),
171
  'profile_id' => null,
172
- );
173
 
174
  $is_recurring = false;
175
 
@@ -184,12 +193,12 @@ class WPUF_Admin_Subscription {
184
  /**
185
  * Subscription column headings
186
  *
187
- * @param array $head
188
  *
189
  * @return array
190
  */
191
- function subscription_columns_head( $head ) {
192
- unset($head['date']);
193
  $head['title'] = __( 'Pack Name', 'wp-user-frontend' );
194
  $head['amount'] = __( 'Amount', 'wp-user-frontend' );
195
  $head['subscribers'] = __( 'Subscribers', 'wp-user-frontend' );
@@ -202,38 +211,40 @@ class WPUF_Admin_Subscription {
202
  /**
203
  * Susbcription lists column content
204
  *
205
- * @param string $column_name
206
- * @param integer $post_ID
207
  *
208
  * @return void
209
  */
210
- function subscription_columns_content( $column_name, $post_ID ) {
211
  switch ( $column_name ) {
212
  case 'amount':
213
 
214
  $amount = get_post_meta( $post_ID, '_billing_amount', true );
215
- if ( intval($amount) == 0 ) {
 
216
  $amount = __( 'Free', 'wp-user-frontend' );
217
  } else {
218
  $amount = wpuf_format_price( $amount );
219
  }
220
- echo $amount;
221
  break;
222
 
223
  case 'subscribers':
224
 
225
  $users = WPUF_Subscription::init()->subscription_pack_users( $post_ID );
226
 
227
- echo '<a href="'. admin_url( 'edit.php?post_type=wpuf_subscription&page=wpuf_subscribers&post_ID=' . $post_ID ) . '" />' . count( $users ) . '</a>';
228
  break;
229
 
230
  case 'recurring':
231
 
232
  $recurring = get_post_meta( $post_ID, '_recurring_pay', true );
 
233
  if ( $recurring == 'yes' ) {
234
- _e( 'Yes', 'wp-user-frontend' );
235
  } else {
236
- _e( 'No', 'wp-user-frontend' );
237
  }
238
  break;
239
 
@@ -244,20 +255,18 @@ class WPUF_Admin_Subscription {
244
  $cycle_period = get_post_meta( $post_ID, '_cycle_period', true );
245
 
246
  if ( $recurring_pay == 'yes' ) {
247
- echo $billing_cycle_number .' '. $cycle_period . '\'s (cycle)';
248
  } else {
249
  $expiration_number = get_post_meta( $post_ID, '_expiration_number', true );
250
  $expiration_period = get_post_meta( $post_ID, '_expiration_period', true );
251
- echo $expiration_number .' '. $expiration_period . '\'s';
252
  }
253
  break;
254
  }
255
-
256
  }
257
 
258
- function get_post_types( $post_types = null ) {
259
-
260
- if ( ! $post_types ) {
261
  $post_types = WPUF_Subscription::init()->get_all_post_type();
262
  }
263
 
@@ -265,12 +274,13 @@ class WPUF_Admin_Subscription {
265
 
266
  foreach ( $post_types as $key => $name ) {
267
  $post_type_object = get_post_type_object( $key );
 
268
  if ( $post_type_object ) { ?>
269
  <tr>
270
- <th><label for="wpuf-<?php echo esc_attr( $key ); ?>"><?php printf( 'Number of %s', $post_type_object->label ); ?></label></th>
271
  <td>
272
  <input type="text" size="20" style="" id="wpuf-<?php echo esc_attr( $key ); ?>" value="<?php echo intval( $name ); ?>" name="post_type_name[<?php echo esc_attr( $key ); ?>]" />
273
- <div><span class="description"><span><?php printf( 'How many %s the user can list with this pack? Enter <strong>-1</strong> for unlimited.', $key ); ?></span></span></div>
274
  </td>
275
  </tr>
276
  <?php
@@ -283,14 +293,14 @@ class WPUF_Admin_Subscription {
283
  /**
284
  * Replaces default post editor with a simiple rich editor
285
  *
286
- * @param integer $pack_id
287
  *
288
  * @return void
289
  */
290
- function pack_description_metabox( $pack_id = null ) {
291
  global $post;
292
 
293
- wp_editor( $post->post_content, 'post_content', array('editor_height' => 100, 'quicktags' => false, 'media_buttons' => false) );
294
  }
295
 
296
  /**
@@ -306,15 +316,14 @@ class WPUF_Admin_Subscription {
306
  $hidden_recurring_class = ( $sub_meta['recurring_pay'] != 'yes' ) ? 'none' : '';
307
  $hidden_trial_class = ( $sub_meta['trial_status'] != 'yes' ) ? 'none' : '';
308
  $hidden_expire = ( $sub_meta['recurring_pay'] == 'yes' ) ? 'none' : '';
309
- $is_post_exp_selected = isset($sub_meta['_enable_post_expiration']) && $sub_meta['_enable_post_expiration'] == 'on'?'checked':'';
310
- $_post_expiration_time = explode(' ',isset($sub_meta['_post_expiration_time'])?$sub_meta['_post_expiration_time']:' ');
311
- $time_value = isset($_post_expiration_time[0])?$_post_expiration_time[0]:1;
312
- $time_type = isset($_post_expiration_time[1])?$_post_expiration_time[1]:'day';
313
-
314
- $expired_post_status = isset($sub_meta['_expired_post_status'])?$sub_meta['_expired_post_status']:'';
315
- $is_enable_mail_after_expired = isset($sub_meta['_enable_mail_after_expired']) && $sub_meta['_enable_mail_after_expired'] == 'on'?'checked':'';
316
- $post_expiration_message = isset($sub_meta['_post_expiration_message'])?$sub_meta['_post_expiration_message']:'';;
317
- ?>
318
 
319
  <div class="wpuf-subscription-pack-settings">
320
  <nav class="subscription-nav-tab">
@@ -322,14 +331,14 @@ class WPUF_Admin_Subscription {
322
  <li class="tab-current">
323
  <a href="#wpuf-payment-settings">
324
  <span class="dashicons dashicons-cart"></span>
325
- <?php _e( 'Payment Settings', 'wp-user-frontend' ); ?>
326
  </a>
327
  </li>
328
 
329
  <li>
330
  <a href="#wpuf-post-restriction">
331
  <span class="dashicons dashicons-admin-post"></span>
332
- <?php _e( 'Posting Restriction', 'wp-user-frontend' ); ?>
333
  </a>
334
  </li>
335
 
@@ -343,21 +352,21 @@ class WPUF_Admin_Subscription {
343
  <tbody>
344
  <tr>
345
  <th><label for="wpuf-billing-amount">
346
- <span class="wpuf-biling-amount wpuf-subcription-expire" style="display: <?php echo $hidden_expire; ?>;"><?php _e( 'Billing amount:', 'wp-user-frontend' ); ?></span>
347
- <span class="wpuf-billing-cycle wpuf-recurring-child" style="display: <?php echo $hidden_recurring_class; ?>;"><?php _e( 'Billing amount each cycle:', 'wp-user-frontend' ); ?></span></label></th>
348
  <td>
349
- <?php echo wpuf_get_currency( 'symbol' ); ?>
350
  <input type="text" size="20" style="" id="wpuf-billing-amount" value="<?php echo esc_attr( $sub_meta['billing_amount'] ); ?>" name="billing_amount" />
351
  <div><span class="description"></span></div>
352
  </td>
353
  </tr>
354
- <tr class="wpuf-subcription-expire" style="display: <?php echo $hidden_expire; ?>;">
355
- <th><label for="wpuf-expiration-number"><?php _e( 'Expires In:', 'wp-user-frontend' ); ?></label></th>
356
  <td>
357
  <input type="text" size="20" style="" id="wpuf-expiration-number" value="<?php echo esc_attr( $sub_meta['expiration_number'] ); ?>" name="expiration_number" />
358
 
359
  <select id="expiration-period" name="expiration_period">
360
- <?php echo $this->option_field( $sub_meta['expiration_period'] ); ?>
361
  </select>
362
  <div><span class="description"></span></div>
363
  </td>
@@ -370,91 +379,110 @@ class WPUF_Admin_Subscription {
370
  <section id="wpuf-post-restriction">
371
  <table class="form-table">
372
  <tbody>
373
- <?php echo $this->get_post_types( $sub_meta['post_type_name'] ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  <?php
375
  // do_action( 'wpuf_admin_subscription_detail', $sub_meta, $hidden_recurring_class, $hidden_trial_class, $this );
376
  ?>
377
  <tr class="wpuf-metabox-post_expiration">
378
 
379
- <th><?php _e( 'Post Expiration', 'wp-user-frontend' ); ?></th>
380
 
381
  <td>
382
  <label>
383
- <input type="checkbox" id="wpuf-enable_post_expiration" name="post_expiration_settings[enable_post_expiration]" value="on" <?php echo $is_post_exp_selected;?> />
384
- <?php _e( 'Enable Post Expiration', 'wp-user-frontend' ); ?>
385
  </label>
386
  </td>
387
  </tr>
388
  <tr class="wpuf-metabox-post_expiration wpuf_subscription_expiration_field">
389
  <?php
390
- $timeType_array = array(
391
- 'year' => 100,
392
  'month' => 12,
393
- 'day' => 30
394
- );
395
- ?>
396
- <th class="wpuf-post-exp-time"> <?php _e( 'Post Expiration Time', 'wp-user-frontend' ); ?> </th>
397
  <td class="wpuf-post-exp-time">
398
  <select name="post_expiration_settings[expiration_time_value]" id="wpuf-expiration_time_value">
399
  <?php
400
- for($i = 1;$i <= $timeType_array[$time_type];$i++){
401
  ?>
402
- <option value="<?php echo $i; ?>" <?php echo $i == $time_value?'selected':''; ?>><?php echo $i;?></option>
403
  <?php
404
- }
405
- ?>
406
  </select>
407
  <select name="post_expiration_settings[expiration_time_type]" id="wpuf-expiration_time_type">
408
  <?php
409
- foreach($timeType_array as $each_time_type=>$each_time_type_val){
410
  ?>
411
- <option value="<?php echo $each_time_type;?>" <?php echo $each_time_type==$time_type?'selected':''; ?>><?php echo ucfirst($each_time_type);?></option>
412
  <?php
413
- }
414
- ?>
415
  </select>
416
  </td>
417
 
418
  </tr>
419
  <tr class="wpuf_subscription_expiration_field">
420
  <th>
421
- <?php _e( 'Post Status', 'wp-user-frontend' ); ?>
422
  </th>
423
  <td>
424
- <?php $post_statuses = get_post_statuses();
425
- ?>
426
  <select name="post_expiration_settings[expired_post_status]" id="wpuf-expired_post_status">
427
  <?php
428
- foreach($post_statuses as $post_status => $text){
429
  ?>
430
- <option value="<?php echo $post_status ?>" <?php echo ( $expired_post_status == $post_status )?'selected':''; ?>><?php echo $text;?></option>
431
  <?php
432
- }
433
- ?>
434
  </select>
435
- <p class="description"><?php _e('Status of post after post expiration time is over ', 'wp-user-frontend' );?></p>
436
  </td>
437
  </tr>
438
  <tr class="wpuf_subscription_expiration_field">
439
  <th>
440
- <?php _e( 'Expiration Mail', 'wp-user-frontend' ); ?>
441
  </th>
442
  <td>
443
  <label>
444
- <input type="checkbox" name="post_expiration_settings[enable_mail_after_expired]" value="on" <?php echo $is_enable_mail_after_expired;?> />
445
- <?php _e( 'Send Expiration Email to Post Author', 'wp-user-frontend' ); ?>
446
  </label>
447
 
448
  <p class="help">
449
- <?php _e( 'Send Mail to Author After Exceeding Post Expiration Time', 'wp-user-frontend' ); ?>
450
  </p>
451
  </td>
452
  </tr>
453
  <tr class="wpuf_subscription_expiration_field">
454
- <th><?php _e( 'Expiration Message', 'wp-user-frontend' ); ?></th>
455
  <td>
456
- <textarea name="post_expiration_settings[post_expiration_message]" id="wpuf-post_expiration_message" cols="50" rows="5"><?php echo $post_expiration_message;?></textarea>
457
- <p class="description"><strong><?php echo __( 'You may use: {post_author} {post_url} {blogname} {post_title} {post_status}', 'wp-user-frontend' ); ?></strong></p>
458
  </td>
459
  </tr>
460
 
@@ -462,8 +490,7 @@ class WPUF_Admin_Subscription {
462
  /**
463
  * @since 2.7.0
464
  */
465
- do_action( 'wpuf_admin_subscription_post_restriction', $sub_meta, $post, $this );
466
- ?>
467
  </tbody>
468
  </table>
469
  </section>
@@ -488,7 +515,7 @@ class WPUF_Admin_Subscription {
488
  return;
489
  }
490
 
491
- wp_enqueue_script( 'wpuf-metabox-tabs', WPUF_ASSET_URI . '/js/metabox-tabs.js' , array( 'jquery' ) );
492
  }
493
 
494
  /**
@@ -503,34 +530,35 @@ class WPUF_Admin_Subscription {
503
  return;
504
  }
505
 
506
- wp_enqueue_script( 'wpuf-admin-profile-subs', WPUF_ASSET_URI . '/js/admin-profile-subs.js' , array( 'jquery' ) );
507
  }
508
 
509
  /**
510
  * Option fields for date type
511
  *
512
- * @param string $selected
513
  *
514
  * @return void
515
  */
516
- function option_field( $selected ) {
517
  ?>
518
- <option value="day" <?php selected( $selected, 'day' ); ?> ><?php _e( 'Day(s)', 'wp-user-frontend' ); ?></option>
519
- <option value="week" <?php selected( $selected, 'week' ); ?> ><?php _e( 'Week(s)', 'wp-user-frontend' ); ?></option>
520
- <option value="month" <?php selected( $selected, 'month' ); ?> ><?php _e( 'Month(s)', 'wp-user-frontend'); ?></option>
521
- <option value="year" <?php selected( $selected, 'year' ); ?> ><?php _e( 'Year(s)', 'wp-user-frontend' ); ?></option>
522
  <?php
523
  }
524
 
525
- function packdropdown_without_recurring( $packs, $selected = '' ) {
526
- $packs = isset( $packs ) ? $packs : array();
527
- foreach( $packs as $key => $pack ) {
 
528
  $recurring = isset( $pack->meta_value['recurring_pay'] ) ? $pack->meta_value['recurring_pay'] : '';
529
- if( $recurring == 'yes' ) {
 
530
  continue;
531
- }
532
- ?>
533
- <option value="<?php echo $pack->ID; ?>" <?php selected( $selected, $pack->ID ); ?>><?php echo $pack->post_title; ?></option>
534
  <?php
535
  }
536
  }
@@ -540,15 +568,14 @@ class WPUF_Admin_Subscription {
540
  *
541
  * @param object $profileuser
542
  */
543
- function profile_subscription_details( $profileuser ) {
544
-
545
- if ( ! current_user_can( 'edit_users' ) ) {
546
  return;
547
  }
548
 
549
  $current_user = wpuf_get_user();
550
 
551
- if ( ! $current_user->subscription()->current_pack_id() ) {
552
  // return;
553
  }
554
 
@@ -556,15 +583,13 @@ class WPUF_Admin_Subscription {
556
 
557
  $packs = WPUF_Subscription::init()->get_subscriptions();
558
  $user_sub = WPUF_Subscription::get_user_pack( $userdata->ID );
559
- $pack_id = isset( $user_sub['pack_id'] ) ? $user_sub['pack_id'] : '';
560
- ?>
561
  <div class="wpuf-user-subscription" style="width: 640px;">
562
- <h3><?php _e( 'WPUF Subscription Information', 'wp-user-frontend' ); ?></h3>
563
 
564
  <?php
565
 
566
- if ( isset( $user_sub['pack_id'] ) ) :
567
-
568
  $pack = WPUF_Subscription::get_subscription( $user_sub['pack_id'] );
569
  $details_meta = WPUF_Subscription::init()->get_details_meta_value();
570
 
@@ -577,118 +602,109 @@ class WPUF_Admin_Subscription {
577
  $recurring_des = $recurring_des;
578
  } else {
579
  $recurring_des = '';
580
- }
581
-
582
- ?>
583
  <div class="wpuf-user-sub-info">
584
 
585
  <div class="wpuf-sub-summary">
586
  <div class="sub-name">
587
  <span class="label">
588
- <?php _e( 'Subcription Name', 'wp-user-frontend' ); ?>
589
  </span>
590
 
591
  <span class="value">
592
- <?php echo isset( $pack->post_title ) ? $pack->post_title : ''; ?>
593
  </span>
594
  </div>
595
 
596
  <div class="sub-price">
597
  <span class="label">
598
- <?php _e( 'Billing Info', 'wp-user-frontend' ); ?>
599
  </span>
600
 
601
  <span class="value">
602
- <?php echo $billing_amount; ?>
603
 
604
- <?php if ( $recurring_des ) : ?>
605
- <p><?php echo $recurring_des; ?></p>
606
- <?php endif; ?>
607
  </span>
608
  </div>
609
 
610
  <?php if ( isset( $user_sub['recurring'] ) && $user_sub['recurring'] == 'yes' ) { ?>
611
  <div class="info">
612
- <p><?php _e( 'This user is using recurring subscription pack', 'wp-user-frontend' ); ?></p>
613
  </div>
614
  <?php } ?>
615
  </div>
616
 
617
  <div class="wpuf-sub-section remaining-posts">
618
- <h4><?php _e( 'Remaining Posting Count', 'wp-user-frontend'); ?></h4>
619
 
620
  <table class="form-table">
621
 
622
  <?php foreach ( $user_sub['posts'] as $key => $value ) {
623
- $post_type_object = get_post_type_object( $key );
624
 
625
- if ( $post_type_object ) {
626
- ?>
627
  <tr>
628
- <th><label><?php echo $post_type_object->labels->name; ?></label></th>
629
- <td><input type="text" value="<?php echo $value; ?>" name="<?php echo $key; ?>" ></td>
630
  </tr>
631
  <?php
632
- }
633
- }
634
- ?>
635
  </table>
636
  </div>
637
 
638
  <div class="wpuf-sub-section post-expiration">
639
- <h4><?php _e( 'Subscription Expiration Info', 'wp-user-frontend' ); ?></h4>
640
 
641
  <table class="form-table">
642
  <?php
643
  if ( $user_sub['recurring'] != 'yes' ) {
644
  if ( !empty( $user_sub['expire'] ) ) {
645
- $expire = ( $user_sub['expire'] == 'unlimited' ) ? ucfirst( 'unlimited' ) : wpuf_get_date( wpuf_date2mysql( $user_sub['expire'] ));
646
- ?>
647
  <tr>
648
- <th><label><?php echo _e('Expire date:' , 'wp-user-frontend'); ?></label></th>
649
- <td><input type="text" class="wpuf-date-picker" name="expire" value="<?php echo $expire; ?>"></td>
650
  </tr>
651
  <?php
652
  }
653
-
654
  }
655
 
656
- $is_post_exp_selected = isset( $user_sub['_enable_post_expiration'] ) ? 'checked' : '';
657
- $_post_expiration_time = explode( ' ',isset($user_sub['_post_expiration_time']) ? $user_sub['_post_expiration_time'] : '' );
658
- $time_value = isset( $_post_expiration_time[0] ) && !empty( $_post_expiration_time[0] ) ? $_post_expiration_time[0] : '1';
659
- $time_type = isset( $_post_expiration_time[1] ) && !empty( $_post_expiration_time[1] ) ? $_post_expiration_time[1] : 'day';
660
- ?>
661
  <tr>
662
- <th><label><?php echo _e('Post Expiration Enabled', 'wp-user-frontend'); ?></label></th>
663
- <td><input type="checkbox" class="wpuf-post-exp-enabled" name="is_post_expiration_enabled" value="on" <?php echo $is_post_exp_selected;?>></td>
664
  </tr>
665
  <tr class="wpuf-post-exp-time">
666
  <?php
667
- $timeType_array = array(
668
  'year' => 100,
669
  'month' => 12,
670
- 'day' => 30
671
- );
672
- ?>
673
- <th><?php _e( 'Post Expiration Time', 'wp-user-frontend' ); ?></th>
674
  <td>
675
  <select name="post_expiration_settings[expiration_time_value]" id="wpuf-expiration_time_value">
676
  <?php
677
- for($i = 1;$i <= $timeType_array[$time_type];$i++){
678
  ?>
679
- <option value="<?php echo $i; ?>" <?php echo $i == $time_value?'selected':''; ?>><?php echo $i;?></option>
680
  <?php
681
- }
682
- ?>
683
  </select>
684
  <select name="post_expiration_settings[expiration_time_type]" id="wpuf-expiration_time_type">
685
  <?php
686
- foreach($timeType_array as $each_time_type=>$each_time_type_val){
687
  ?>
688
- <option value="<?php echo $each_time_type;?>" <?php echo $each_time_type==$time_type?'selected':''; ?>><?php echo ucfirst($each_time_type);?></option>
689
  <?php
690
- }
691
- ?>
692
  </select>
693
  </td>
694
  </tr>
@@ -696,113 +712,123 @@ class WPUF_Admin_Subscription {
696
  </div>
697
 
698
  <div class="wpuf-sub-section tax-restriction">
699
- <h4><?php _e( 'Allowed Taxonomy Terms', 'wp-user-frontend' ); ?></h4>
700
 
701
  <table class="form-table">
702
  <tr>
703
  <?php
704
- $allowed_tax_id_arr = array();
705
- $allowed_tax_id_arr = get_post_meta( $pack_id , '_sub_allowed_term_ids', true );
706
- if ( ! $allowed_tax_id_arr ) {
707
- $allowed_tax_id_arr = array();
708
- }
709
-
710
- $builtin_taxs = get_taxonomies( array(
711
- '_builtin' => true
712
- ), 'objects' );
713
-
714
- foreach ($builtin_taxs as $builtin_tax) {
715
- if ( is_taxonomy_hierarchical( $builtin_tax->name ) ) {
716
- $tax_terms = get_terms ( array(
717
- 'taxonomy' => $builtin_tax->name,
 
718
  'hide_empty' => false,
719
- ) );
720
- foreach ($tax_terms as $tax_term) {
721
- if ( in_array( $tax_term->term_id, $allowed_tax_id_arr ) ) {
722
- ?> <td> <?php echo $tax_term->name; ?> </td> <?php
723
- }
724
- }
725
- }
726
- }
727
-
728
- $custom_taxs = get_taxonomies(array('_builtin'=>false), 'objects');
729
- foreach ($custom_taxs as $custom_tax) {
730
- if ( is_taxonomy_hierarchical( $custom_tax->name ) ) {
731
- $tax_terms = get_terms ( array(
732
- 'taxonomy' => $custom_tax->name,
 
 
733
  'hide_empty' => false,
734
- ) );
735
-
736
- foreach ($tax_terms as $tax_term) {
737
- if ( in_array( $tax_term->term_id, $allowed_tax_id_arr ) ) {
738
- ?> <td> <?php echo $tax_term->name; ?> </td> <?php
739
- }
740
- }
741
- }
742
- }
743
- ?>
744
  </tr>
745
  </table>
746
  </div>
747
  </div>
748
- <?php endif;?>
 
749
 
750
- <?php if ( ! isset( $user_sub['recurring'] ) || $user_sub['recurring'] != 'yes' ): ?>
751
 
752
- <?php if ( empty( $user_sub ) ): ?>
753
  <div class="wpuf-sub-actions">
754
- <a class="btn button-secondary wpuf-assing-pack-btn wpuf-add-pack" href="#"><?php _e( 'Assign Package', 'wp-user-frontend' ); ?></a>
755
- <a class="btn button-secondary wpuf-assing-pack-btn wpuf-cancel-pack" style="display:none;" href="#"><?php _e( 'Cancel', 'wp-user-frontend' ); ?></a>
756
  </div>
757
- <?php endif ?>
758
 
759
  <table class="form-table wpuf-pack-dropdown" disabled="disabled" style="display: none;">
760
  <tr>
761
- <th><label for="wpuf_sub_pack"><?php _e( 'Select Package:', 'wp-user-frontend' ); ?> </label></th>
762
  <td>
763
  <select name="pack_id" id="wpuf_sub_pack">
764
- <option value="-1"><?php _e( '&mdash; Select &mdash;', 'wp-user-frontend' ); ?></option>
765
- <?php $this->packdropdown_without_recurring( $packs, $pack_id );//WPUF_Subscription::init()->packdropdown( $packs, $selected = '' ); ?>
766
  </select>
767
  <br>
768
- <span class="description"><?php _e( 'Only non-recurring pack can be assigned', 'wp-user-frontend' ); ?></span>
769
  </td>
770
  </tr>
771
  </table>
772
- <?php endif;?>
773
  <?php
774
- do_action( 'wpuf_admin_subscription_content', $userdata->ID ) ?>
775
- <?php if ( !empty( $user_sub ) ): ?>
 
776
  <div class="wpuf-sub-actions">
777
- <a class="btn button-secondary wpuf-delete-pack-btn" href="javascript:" data-userid="<?php echo $userdata->ID; ?>" data-packid="<?php echo isset( $user_sub['pack_id'] ) ? $user_sub['pack_id'] : ''; ?>"><?php _e( 'Delete Package', 'wp-user-frontend' ); ?></a>
778
  </div>
779
- <?php endif; ?>
780
  </div>
781
  <?php
782
-
783
  }
784
 
785
- function lenght_type_option( $selected ) {
786
-
787
- for ($i = 1; $i <= 30; $i++) {
788
  ?>
789
- <option value="<?php echo $i; ?>" <?php selected( $i, $selected ); ?>><?php echo $i; ?></option>
790
  <?php
791
  }
792
-
793
  }
794
 
795
  /**
796
  * Ajax function. Delete user package
 
797
  * @since 2.2.7
798
  */
799
- function delete_user_package(){
800
- echo delete_user_meta($_POST['userid'],'_wpuf_subscription_pack');
 
 
 
 
 
 
 
801
  $wpuf_paypal = new WPUF_Paypal();
802
- $wpuf_paypal->recurring_change_status( $_POST['userid'], 'Cancel' );
803
 
804
  if ( isset( $_POST['packid'] ) ) {
805
- WPUF_Subscription::subscriber_cancel( $_POST['userid'], $_POST['packid'] );
 
806
  }
807
  exit;
808
  }
@@ -817,13 +843,11 @@ class WPUF_Admin_Subscription {
817
 
818
  if ( 'edit-wpuf_subscription' != $screen->id ) {
819
  return;
820
- }
821
-
822
- ?>
823
  <div class="wpuf-footer-help">
824
  <span class="wpuf-footer-help-content">
825
  <span class="dashicons dashicons-editor-help"></span>
826
- <?php printf( __( 'Learn more about <a href="%s" target="_blank">Subscription</a>', 'wp-user-frontend' ), 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/?utm_source=wpuf-footer-help&utm_medium=text-link&utm_campaign=learn-more-subscription' ); ?>
827
  </span>
828
  </div>
829
 
2
 
3
  /**
4
  * Manage Subscription packs
 
 
5
  */
6
  class WPUF_Admin_Subscription {
7
 
16
  * The constructor
17
  */
18
  public function __construct() {
19
+ add_filter( 'post_updated_messages', [$this, 'form_updated_message'] );
20
 
21
+ add_action( 'show_user_profile', [$this, 'profile_subscription_details'], 30 );
22
+ add_action( 'edit_user_profile', [$this, 'profile_subscription_details'], 30 );
23
+ add_action( 'personal_options_update', [$this, 'profile_subscription_update'] );
24
+ add_action( 'edit_user_profile_update', [$this, 'profile_subscription_update'] );
25
+ add_action( 'wp_ajax_wpuf_delete_user_package', [$this, 'delete_user_package'] );
26
 
27
+ add_filter( 'manage_wpuf_subscription_posts_columns', [ $this, 'subscription_columns_head'] );
28
+ add_action( 'manage_wpuf_subscription_posts_custom_column', [ $this, 'subscription_columns_content' ], 10, 2 );
 
 
 
 
 
 
29
 
30
  // display help link to docs
31
+ add_action( 'admin_notices', [ $this, 'add_help_link' ] );
32
 
33
  // new subscription metabox hooks
34
+ add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] );
35
+ add_action( 'admin_print_styles-post-new.php', [ $this, 'enqueue_scripts' ] );
36
+ add_action( 'admin_print_styles-post.php', [ $this, 'enqueue_scripts' ] );
37
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_profile_script' ] );
38
  }
39
 
40
  /**
54
  * Add settings metaboxes
55
  */
56
  public function add_meta_boxes() {
57
+ add_meta_box( 'wpuf-metabox-subscription', __( 'Pack Description', 'wp-user-frontend' ), [$this, 'pack_description_metabox'], 'wpuf_subscription', 'normal', 'high' );
58
+ add_meta_box( 'wpuf_subs_metabox', 'Subscription Options', [ $this, 'subs_meta_box' ], 'wpuf_subscription' );
59
  }
60
 
61
  /**
62
  * Custom post update message
63
  *
64
+ * @param array $messages
65
+ *
66
  * @return array
67
  */
68
+ public function form_updated_message( $messages ) {
69
+ $message = [
70
  0 => '',
71
  1 => __( 'Subscription pack updated.', 'wp-user-frontend' ),
72
  2 => __( 'Custom field updated.', 'wp-user-frontend' ),
78
  8 => __( 'Subscription pack submitted.', 'wp-user-frontend' ),
79
  9 => '',
80
  10 => __( 'Subscription pack draft updated.', 'wp-user-frontend' ),
81
+ ];
82
 
83
  $messages['wpuf_subscription'] = $message;
84
 
90
  *
91
  * @param int $user_id
92
  */
93
+ public function profile_subscription_update( $user_id ) {
94
  if ( !is_admin() && !current_user_can( 'edit_users' ) ) {
95
  return;
96
  }
97
+ $nonce = isset( $_REQUEST['wpuf-subscription-nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['wpuf-subscription-nonce'] ) ) : '';
98
+
99
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'update-profile_' . $user_id ) ) {
100
+ return ;
101
+ }
102
 
103
  if ( !isset( $_POST['pack_id'] ) ) {
104
  return;
105
  }
106
 
107
  if ( isset( $_POST['wpuf_profile_mail_noti'] ) ) {
108
+ $wpuf_profile_mail_noti = sanitize_text_field( wp_unslash( $_POST['wpuf_profile_mail_noti'] ) );
109
+ update_user_meta( $user_id, '_pack_assign_notification', $wpuf_profile_mail_noti );
110
  }
111
 
112
+ $pack_id = isset( $_POST['pack_id'] ) ? intval( wp_unslash( $_POST['pack_id'] ) ) : '';
113
+ $u_id = isset( $_POST['user_id'] ) ? intval( wp_unslash( $_POST['user_id'] ) ) : '';
114
+ $pack = WPUF_Subscription::get_subscription( $pack_id );
115
+ $user_pack = WPUF_Subscription::get_user_pack( $u_id );
116
 
117
+ if ( isset( $user_pack['pack_id'] ) && $pack_id == $user_pack['pack_id'] ) {
118
  //updating number of posts
119
 
120
+ if ( isset( $user_pack['posts'] ) ) {
121
+ $p_type = isset( $_POST[$post_type] ) ? sanitize_text_field( wp_unslash( $_POST[$post_type] ) ) : '';
122
+ foreach ( $user_pack['posts'] as $post_type => $post_num ) {
123
+ $user_pack['posts'][$post_type] = $p_type;
124
  }
 
125
  }
126
 
127
  //post expiration enable or disable
128
 
129
+ if ( isset( $_POST['is_post_expiration_enabled'] ) ) {
130
+ $user_pack['_enable_post_expiration'] = sanitize_text_field( wp_unslash( $_POST['is_post_expiration_enabled'] ) );
131
  } else {
132
+ unset( $user_pack['_enable_post_expiration'] );
133
  }
134
 
135
  //updating post time
136
+ if ( isset( $_POST['post_expiration_settings'] ) ) {
137
+ $post_expiration_settings = array_map( 'sanitize_text_field', wp_unslash( $_POST['post_expiration_settings'] ) );
138
+
139
+ $user_pack['_post_expiration_time'] = post_expiration_settings['expiration_time_value'] . ' ' . post_expiration_settings['expiration_time_type'];
140
+
141
+ echo esc_html( $user_pack['_post_expiration_time'] );
142
  }
143
+
144
  if ( isset( $user_pack['recurring'] ) && $user_pack['recurring'] == 'yes' ) {
145
  foreach ( $user_pack['posts'] as $type => $value ) {
146
+ $user_pack['posts'][$type] = isset( $_POST[$type] ) ? sanitize_text_field( wp_unslash( $_POST[$type] ) ) : 0;
147
  }
148
  } else {
149
  foreach ( $user_pack['posts'] as $type => $value ) {
150
+ $user_pack['posts'][$type] = isset( $_POST[$type] ) ? sanitize_text_field( wp_unslash( $_POST[$type] ) ) : 0;
151
  }
152
+ $user_pack['expire'] = isset( $_POST['expire'] ) ? wpuf_date2mysql( sanitize_text_field( wp_unslash( $_POST['expire'] ) ) ) : $user_pack['expire'];
153
  }
154
  wpuf_get_user( $user_id )->subscription()->update_meta( $user_pack );
155
  } else {
162
  $billing_amount = apply_filters( 'wpuf_payment_amount', $cost );
163
  $tax_amount = $billing_amount - $cost;
164
 
165
+ $data = [
166
  'user_id' => $user_id,
167
  'status' => 'completed',
168
  'subtotal' => $cost,
178
  'transaction_id' => 0,
179
  'created' => current_time( 'mysql' ),
180
  'profile_id' => null,
181
+ ];
182
 
183
  $is_recurring = false;
184
 
193
  /**
194
  * Subscription column headings
195
  *
196
+ * @param array $head
197
  *
198
  * @return array
199
  */
200
+ public function subscription_columns_head( $head ) {
201
+ unset( $head['date'] );
202
  $head['title'] = __( 'Pack Name', 'wp-user-frontend' );
203
  $head['amount'] = __( 'Amount', 'wp-user-frontend' );
204
  $head['subscribers'] = __( 'Subscribers', 'wp-user-frontend' );
211
  /**
212
  * Susbcription lists column content
213
  *
214
+ * @param string $column_name
215
+ * @param int $post_ID
216
  *
217
  * @return void
218
  */
219
+ public function subscription_columns_content( $column_name, $post_ID ) {
220
  switch ( $column_name ) {
221
  case 'amount':
222
 
223
  $amount = get_post_meta( $post_ID, '_billing_amount', true );
224
+
225
+ if ( intval( $amount ) == 0 ) {
226
  $amount = __( 'Free', 'wp-user-frontend' );
227
  } else {
228
  $amount = wpuf_format_price( $amount );
229
  }
230
+ echo esc_html( $amount );
231
  break;
232
 
233
  case 'subscribers':
234
 
235
  $users = WPUF_Subscription::init()->subscription_pack_users( $post_ID );
236
 
237
+ echo wp_kses_post( '<a href="' . admin_url( 'edit.php?post_type=wpuf_subscription&page=wpuf_subscribers&post_ID=' . $post_ID ) . '" />' . count( $users ) . '</a>' );
238
  break;
239
 
240
  case 'recurring':
241
 
242
  $recurring = get_post_meta( $post_ID, '_recurring_pay', true );
243
+
244
  if ( $recurring == 'yes' ) {
245
+ esc_html_e( 'Yes', 'wp-user-frontend' );
246
  } else {
247
+ esc_html_e( 'No', 'wp-user-frontend' );
248
  }
249
  break;
250
 
255
  $cycle_period = get_post_meta( $post_ID, '_cycle_period', true );
256
 
257
  if ( $recurring_pay == 'yes' ) {
258
+ echo esc_attr( $billing_cycle_number . ' ' . $cycle_period ) . '\'s (cycle)';
259
  } else {
260
  $expiration_number = get_post_meta( $post_ID, '_expiration_number', true );
261
  $expiration_period = get_post_meta( $post_ID, '_expiration_period', true );
262
+ echo esc_attr( $expiration_number . ' ' . $expiration_period ) . '\'s';
263
  }
264
  break;
265
  }
 
266
  }
267
 
268
+ public function get_post_types( $post_types = null ) {
269
+ if ( !$post_types ) {
 
270
  $post_types = WPUF_Subscription::init()->get_all_post_type();
271
  }
272
 
274
 
275
  foreach ( $post_types as $key => $name ) {
276
  $post_type_object = get_post_type_object( $key );
277
+
278
  if ( $post_type_object ) { ?>
279
  <tr>
280
+ <th><label for="wpuf-<?php echo esc_attr( $key ); ?>"><?php printf( 'Number of %s', esc_html( $post_type_object->label ) ); ?></label></th>
281
  <td>
282
  <input type="text" size="20" style="" id="wpuf-<?php echo esc_attr( $key ); ?>" value="<?php echo intval( $name ); ?>" name="post_type_name[<?php echo esc_attr( $key ); ?>]" />
283
+ <div><span class="description"><span><?php printf( 'How many %s the user can list with this pack? Enter <strong>-1</strong> for unlimited.', esc_html( $key ) ); ?></span></span></div>
284
  </td>
285
  </tr>
286
  <?php
293
  /**
294
  * Replaces default post editor with a simiple rich editor
295
  *
296
+ * @param int $pack_id
297
  *
298
  * @return void
299
  */
300
+ public function pack_description_metabox( $pack_id = null ) {
301
  global $post;
302
 
303
+ wp_editor( $post->post_content, 'post_content', ['editor_height' => 100, 'quicktags' => false, 'media_buttons' => false] );
304
  }
305
 
306
  /**
316
  $hidden_recurring_class = ( $sub_meta['recurring_pay'] != 'yes' ) ? 'none' : '';
317
  $hidden_trial_class = ( $sub_meta['trial_status'] != 'yes' ) ? 'none' : '';
318
  $hidden_expire = ( $sub_meta['recurring_pay'] == 'yes' ) ? 'none' : '';
319
+ $is_post_exp_selected = isset( $sub_meta['_enable_post_expiration'] ) && $sub_meta['_enable_post_expiration'] == 'on' ? 'checked' : '';
320
+ $_post_expiration_time = explode( ' ', isset( $sub_meta['_post_expiration_time'] ) ? $sub_meta['_post_expiration_time'] : ' ' );
321
+ $time_value = isset( $_post_expiration_time[0] ) ? $_post_expiration_time[0] : 1;
322
+ $time_type = isset( $_post_expiration_time[1] ) ? $_post_expiration_time[1] : 'day';
323
+
324
+ $expired_post_status = isset( $sub_meta['_expired_post_status'] ) ? $sub_meta['_expired_post_status'] : '';
325
+ $is_enable_mail_after_expired = isset( $sub_meta['_enable_mail_after_expired'] ) && $sub_meta['_enable_mail_after_expired'] == 'on' ? 'checked' : '';
326
+ $post_expiration_message = isset( $sub_meta['_post_expiration_message'] ) ? $sub_meta['_post_expiration_message'] : ''; ?>
 
327
 
328
  <div class="wpuf-subscription-pack-settings">
329
  <nav class="subscription-nav-tab">
331
  <li class="tab-current">
332
  <a href="#wpuf-payment-settings">
333
  <span class="dashicons dashicons-cart"></span>
334
+ <?php esc_html_e( 'Payment Settings', 'wp-user-frontend' ); ?>
335
  </a>
336
  </li>
337
 
338
  <li>
339
  <a href="#wpuf-post-restriction">
340
  <span class="dashicons dashicons-admin-post"></span>
341
+ <?php esc_html_e( 'Posting Restriction', 'wp-user-frontend' ); ?>
342
  </a>
343
  </li>
344
 
352
  <tbody>
353
  <tr>
354
  <th><label for="wpuf-billing-amount">
355
+ <span class="wpuf-biling-amount wpuf-subcription-expire" style="display: <?php echo esc_attr( $hidden_expire ); ?>;"><?php esc_html_e( 'Billing amount:', 'wp-user-frontend' ); ?></span>
356
+ <span class="wpuf-billing-cycle wpuf-recurring-child" style="display: <?php echo esc_attr( $hidden_recurring_class ); ?>;"><?php esc_html_e( 'Billing amount each cycle:', 'wp-user-frontend' ); ?></span></label></th>
357
  <td>
358
+ <?php echo esc_attr( wpuf_get_currency( 'symbol' ) ); ?>
359
  <input type="text" size="20" style="" id="wpuf-billing-amount" value="<?php echo esc_attr( $sub_meta['billing_amount'] ); ?>" name="billing_amount" />
360
  <div><span class="description"></span></div>
361
  </td>
362
  </tr>
363
+ <tr class="wpuf-subcription-expire" style="display: <?php echo esc_attr( $hidden_expire ); ?>;">
364
+ <th><label for="wpuf-expiration-number"><?php esc_html_e( 'Expires In:', 'wp-user-frontend' ); ?></label></th>
365
  <td>
366
  <input type="text" size="20" style="" id="wpuf-expiration-number" value="<?php echo esc_attr( $sub_meta['expiration_number'] ); ?>" name="expiration_number" />
367
 
368
  <select id="expiration-period" name="expiration_period">
369
+ <?php echo esc_html( $this->option_field( $sub_meta['expiration_period'] ) ); ?>
370
  </select>
371
  <div><span class="description"></span></div>
372
  </td>
379
  <section id="wpuf-post-restriction">
380
  <table class="form-table">
381
  <tbody>
382
+ <?php
383
+ echo wp_kses( $this->get_post_types( $sub_meta['post_type_name'] ),
384
+ [
385
+ 'div' => [],
386
+ 'tr' => [],
387
+ 'td' => [],
388
+ 'th' => [],
389
+ 'label' => [
390
+ 'for' => []
391
+ ],
392
+ 'input' => [
393
+ 'type' => [],
394
+ 'size' => [],
395
+ 'style' => [],
396
+ 'id' => [],
397
+ 'value' => [],
398
+ 'name' => []
399
+ ],
400
+ 'span' => [
401
+ 'class' => []
402
+ ],
403
+ 'strong' => []
404
+ ]
405
+ );
406
+ ?>
407
  <?php
408
  // do_action( 'wpuf_admin_subscription_detail', $sub_meta, $hidden_recurring_class, $hidden_trial_class, $this );
409
  ?>
410
  <tr class="wpuf-metabox-post_expiration">
411
 
412
+ <th><?php esc_html_e( 'Post Expiration', 'wp-user-frontend' ); ?></th>
413
 
414
  <td>
415
  <label>
416
+ <input type="checkbox" id="wpuf-enable_post_expiration" name="post_expiration_settings[enable_post_expiration]" value="on" <?php echo esc_attr( $is_post_exp_selected ); ?> />
417
+ <?php esc_html_e( 'Enable Post Expiration', 'wp-user-frontend' ); ?>
418
  </label>
419
  </td>
420
  </tr>
421
  <tr class="wpuf-metabox-post_expiration wpuf_subscription_expiration_field">
422
  <?php
423
+ $timeType_array = [
424
+ 'year' => 100,
425
  'month' => 12,
426
+ 'day' => 30,
427
+ ]; ?>
428
+ <th class="wpuf-post-exp-time"> <?php esc_html_e( 'Post Expiration Time', 'wp-user-frontend' ); ?> </th>
 
429
  <td class="wpuf-post-exp-time">
430
  <select name="post_expiration_settings[expiration_time_value]" id="wpuf-expiration_time_value">
431
  <?php
432
+ for ( $i = 1; $i <= $timeType_array[$time_type]; $i++ ) {
433
  ?>
434
+ <option value="<?php echo esc_attr( $i ); ?>" <?php echo $i == $time_value ? 'selected' : ''; ?>><?php echo esc_attr( $i ); ?></option>
435
  <?php
436
+ } ?>
 
437
  </select>
438
  <select name="post_expiration_settings[expiration_time_type]" id="wpuf-expiration_time_type">
439
  <?php
440
+ foreach ( $timeType_array as $each_time_type=>$each_time_type_val ) {
441
  ?>
442
+ <option value="<?php echo esc_attr( $each_time_type ); ?>" <?php echo $each_time_type == $time_type ? 'selected' : ''; ?>><?php echo esc_html( ucfirst( $each_time_type ) ); ?></option>
443
  <?php
444
+ } ?>
 
445
  </select>
446
  </td>
447
 
448
  </tr>
449
  <tr class="wpuf_subscription_expiration_field">
450
  <th>
451
+ <?php esc_html_e( 'Post Status', 'wp-user-frontend' ); ?>
452
  </th>
453
  <td>
454
+ <?php $post_statuses = get_post_statuses(); ?>
 
455
  <select name="post_expiration_settings[expired_post_status]" id="wpuf-expired_post_status">
456
  <?php
457
+ foreach ( $post_statuses as $post_status => $text ) {
458
  ?>
459
+ <option value="<?php echo esc_attr( $post_status ); ?>" <?php echo ( $expired_post_status == $post_status ) ? 'selected' : ''; ?>><?php echo esc_html( $text ); ?></option>
460
  <?php
461
+ } ?>
 
462
  </select>
463
+ <p class="description"><?php esc_html_e( 'Status of post after post expiration time is over ', 'wp-user-frontend' ); ?></p>
464
  </td>
465
  </tr>
466
  <tr class="wpuf_subscription_expiration_field">
467
  <th>
468
+ <?php esc_html_e( 'Expiration Mail', 'wp-user-frontend' ); ?>
469
  </th>
470
  <td>
471
  <label>
472
+ <input type="checkbox" name="post_expiration_settings[enable_mail_after_expired]" value="on" <?php echo esc_attr( $is_enable_mail_after_expired ); ?> />
473
+ <?php esc_html_e( 'Send Expiration Email to Post Author', 'wp-user-frontend' ); ?>
474
  </label>
475
 
476
  <p class="help">
477
+ <?php esc_html_e( 'Send Mail to Author After Exceeding Post Expiration Time', 'wp-user-frontend' ); ?>
478
  </p>
479
  </td>
480
  </tr>
481
  <tr class="wpuf_subscription_expiration_field">
482
+ <th><?php esc_html_e( 'Expiration Message', 'wp-user-frontend' ); ?></th>
483
  <td>
484
+ <textarea name="post_expiration_settings[post_expiration_message]" id="wpuf-post_expiration_message" cols="50" rows="5"><?php echo esc_attr( $post_expiration_message ); ?></textarea>
485
+ <p class="description"><strong><?php echo esc_html( __( 'You may use: {post_author} {post_url} {blogname} {post_title} {post_status}', 'wp-user-frontend' ) ); ?></strong></p>
486
  </td>
487
  </tr>
488
 
490
  /**
491
  * @since 2.7.0
492
  */
493
+ do_action( 'wpuf_admin_subscription_post_restriction', $sub_meta, $post, $this ); ?>
 
494
  </tbody>
495
  </table>
496
  </section>
515
  return;
516
  }
517
 
518
+ wp_enqueue_script( 'wpuf-metabox-tabs', WPUF_ASSET_URI . '/js/metabox-tabs.js', [ 'jquery' ] );
519
  }
520
 
521
  /**
530
  return;
531
  }
532
 
533
+ wp_enqueue_script( 'wpuf-admin-profile-subs', WPUF_ASSET_URI . '/js/admin-profile-subs.js', [ 'jquery' ] );
534
  }
535
 
536
  /**
537
  * Option fields for date type
538
  *
539
+ * @param string $selected
540
  *
541
  * @return void
542
  */
543
+ public function option_field( $selected ) {
544
  ?>
545
+ <option value="day" <?php selected( $selected, 'day' ); ?> ><?php esc_html_e( 'Day(s)', 'wp-user-frontend' ); ?></option>
546
+ <option value="week" <?php selected( $selected, 'week' ); ?> ><?php esc_html_e( 'Week(s)', 'wp-user-frontend' ); ?></option>
547
+ <option value="month" <?php selected( $selected, 'month' ); ?> ><?php esc_html_e( 'Month(s)', 'wp-user-frontend' ); ?></option>
548
+ <option value="year" <?php selected( $selected, 'year' ); ?> ><?php esc_html_e( 'Year(s)', 'wp-user-frontend' ); ?></option>
549
  <?php
550
  }
551
 
552
+ public function packdropdown_without_recurring( $packs, $selected = '' ) {
553
+ $packs = isset( $packs ) ? $packs : [];
554
+
555
+ foreach ( $packs as $key => $pack ) {
556
  $recurring = isset( $pack->meta_value['recurring_pay'] ) ? $pack->meta_value['recurring_pay'] : '';
557
+
558
+ if ( $recurring == 'yes' ) {
559
  continue;
560
+ } ?>
561
+ <option value="<?php echo esc_attr( $pack->ID ); ?>" <?php selected( $selected, $pack->ID ); ?>><?php echo esc_attr( $pack->post_title ); ?></option>
 
562
  <?php
563
  }
564
  }
568
  *
569
  * @param object $profileuser
570
  */
571
+ public function profile_subscription_details( $profileuser ) {
572
+ if ( !current_user_can( 'edit_users' ) ) {
 
573
  return;
574
  }
575
 
576
  $current_user = wpuf_get_user();
577
 
578
+ if ( !$current_user->subscription()->current_pack_id() ) {
579
  // return;
580
  }
581
 
583
 
584
  $packs = WPUF_Subscription::init()->get_subscriptions();
585
  $user_sub = WPUF_Subscription::get_user_pack( $userdata->ID );
586
+ $pack_id = isset( $user_sub['pack_id'] ) ? $user_sub['pack_id'] : ''; ?>
 
587
  <div class="wpuf-user-subscription" style="width: 640px;">
588
+ <h3><?php esc_html_e( 'WPUF Subscription Information', 'wp-user-frontend' ); ?></h3>
589
 
590
  <?php
591
 
592
+ if ( isset( $user_sub['pack_id'] ) ) {
 
593
  $pack = WPUF_Subscription::get_subscription( $user_sub['pack_id'] );
594
  $details_meta = WPUF_Subscription::init()->get_details_meta_value();
595
 
602
  $recurring_des = $recurring_des;
603
  } else {
604
  $recurring_des = '';
605
+ } ?>
 
 
606
  <div class="wpuf-user-sub-info">
607
 
608
  <div class="wpuf-sub-summary">
609
  <div class="sub-name">
610
  <span class="label">
611
+ <?php esc_html_e( 'Subcription Name', 'wp-user-frontend' ); ?>
612
  </span>
613
 
614
  <span class="value">
615
+ <?php echo isset( $pack->post_title ) ? esc_html( $pack->post_title ) : ''; ?>
616
  </span>
617
  </div>
618
 
619
  <div class="sub-price">
620
  <span class="label">
621
+ <?php esc_html_e( 'Billing Info', 'wp-user-frontend' ); ?>
622
  </span>
623
 
624
  <span class="value">
625
+ <?php echo esc_html( $billing_amount ); ?>
626
 
627
+ <?php if ( $recurring_des ) { ?>
628
+ <p><?php echo esc_html( $recurring_des ); ?></p>
629
+ <?php } ?>
630
  </span>
631
  </div>
632
 
633
  <?php if ( isset( $user_sub['recurring'] ) && $user_sub['recurring'] == 'yes' ) { ?>
634
  <div class="info">
635
+ <p><?php esc_html_e( 'This user is using recurring subscription pack', 'wp-user-frontend' ); ?></p>
636
  </div>
637
  <?php } ?>
638
  </div>
639
 
640
  <div class="wpuf-sub-section remaining-posts">
641
+ <h4><?php esc_html_e( 'Remaining Posting Count', 'wp-user-frontend' ); ?></h4>
642
 
643
  <table class="form-table">
644
 
645
  <?php foreach ( $user_sub['posts'] as $key => $value ) {
646
+ $post_type_object = get_post_type_object( $key );
647
 
648
+ if ( $post_type_object ) {
649
+ ?>
650
  <tr>
651
+ <th><label><?php echo esc_html( $post_type_object->labels->name ); ?></label></th>
652
+ <td><input type="text" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $key ); ?>" ></td>
653
  </tr>
654
  <?php
655
+ }
656
+ } ?>
 
657
  </table>
658
  </div>
659
 
660
  <div class="wpuf-sub-section post-expiration">
661
+ <h4><?php esc_html_e( 'Subscription Expiration Info', 'wp-user-frontend' ); ?></h4>
662
 
663
  <table class="form-table">
664
  <?php
665
  if ( $user_sub['recurring'] != 'yes' ) {
666
  if ( !empty( $user_sub['expire'] ) ) {
667
+ $expire = ( $user_sub['expire'] == 'unlimited' ) ? ucfirst( 'unlimited' ) : wpuf_get_date( wpuf_date2mysql( $user_sub['expire'] ) ); ?>
 
668
  <tr>
669
+ <th><label><?php esc_html_e( 'Expire date:', 'wp-user-frontend' ); ?></label></th>
670
+ <td><input type="text" class="wpuf-date-picker" name="expire" value="<?php echo esc_html( $expire ); ?>"></td>
671
  </tr>
672
  <?php
673
  }
 
674
  }
675
 
676
+ $is_post_exp_selected = isset( $user_sub['_enable_post_expiration'] ) ? 'checked' : '';
677
+ $_post_expiration_time = explode( ' ', isset( $user_sub['_post_expiration_time'] ) ? $user_sub['_post_expiration_time'] : '' );
678
+ $time_value = isset( $_post_expiration_time[0] ) && !empty( $_post_expiration_time[0] ) ? $_post_expiration_time[0] : '1';
679
+ $time_type = isset( $_post_expiration_time[1] ) && !empty( $_post_expiration_time[1] ) ? $_post_expiration_time[1] : 'day'; ?>
 
680
  <tr>
681
+ <th><label><?php esc_html_e( 'Post Expiration Enabled', 'wp-user-frontend' ); ?></label></th>
682
+ <td><input type="checkbox" class="wpuf-post-exp-enabled" name="is_post_expiration_enabled" value="on" <?php echo esc_attr( $is_post_exp_selected ); ?>></td>
683
  </tr>
684
  <tr class="wpuf-post-exp-time">
685
  <?php
686
+ $timeType_array = [
687
  'year' => 100,
688
  'month' => 12,
689
+ 'day' => 30,
690
+ ]; ?>
691
+ <th><?php esc_html_e( 'Post Expiration Time', 'wp-user-frontend' ); ?></th>
 
692
  <td>
693
  <select name="post_expiration_settings[expiration_time_value]" id="wpuf-expiration_time_value">
694
  <?php
695
+ for ( $i = 1; $i <= $timeType_array[$time_type]; $i++ ) {
696
  ?>
697
+ <option value="<?php echo esc_attr( $i ); ?>" <?php echo $i == $time_value ? 'selected' : ''; ?>><?php echo esc_attr( $i ); ?></option>
698
  <?php
699
+ } ?>
 
700
  </select>
701
  <select name="post_expiration_settings[expiration_time_type]" id="wpuf-expiration_time_type">
702
  <?php
703
+ foreach ( $timeType_array as $each_time_type=>$each_time_type_val ) {
704
  ?>
705
+ <option value="<?php echo esc_attr( $each_time_type ); ?>" <?php echo $each_time_type == $time_type ? 'selected' : ''; ?>><?php echo esc_html( ucfirst( $each_time_type ) ); ?></option>
706
  <?php
707
+ } ?>
 
708
  </select>
709
  </td>
710
  </tr>
712
  </div>
713
 
714
  <div class="wpuf-sub-section tax-restriction">
715
+ <h4><?php esc_html_e( 'Allowed Taxonomy Terms', 'wp-user-frontend' ); ?></h4>
716
 
717
  <table class="form-table">
718
  <tr>
719
  <?php
720
+ $allowed_tax_id_arr = [];
721
+ $allowed_tax_id_arr = get_post_meta( $pack_id, '_sub_allowed_term_ids', true );
722
+
723
+ if ( !$allowed_tax_id_arr ) {
724
+ $allowed_tax_id_arr = [];
725
+ }
726
+
727
+ $builtin_taxs = get_taxonomies( [
728
+ '_builtin' => true,
729
+ ], 'objects' );
730
+
731
+ foreach ( $builtin_taxs as $builtin_tax ) {
732
+ if ( is_taxonomy_hierarchical( $builtin_tax->name ) ) {
733
+ $tax_terms = get_terms( [
734
+ 'taxonomy' => $builtin_tax->name,
735
  'hide_empty' => false,
736
+ ] );
737
+
738
+ foreach ( $tax_terms as $tax_term ) {
739
+ if ( in_array( $tax_term->term_id, $allowed_tax_id_arr ) ) {
740
+ ?> <td> <?php echo esc_html( $tax_term->name ); ?> </td> <?php
741
+ }
742
+ }
743
+ }
744
+ }
745
+
746
+ $custom_taxs = get_taxonomies( ['_builtin'=>false], 'objects' );
747
+
748
+ foreach ( $custom_taxs as $custom_tax ) {
749
+ if ( is_taxonomy_hierarchical( $custom_tax->name ) ) {
750
+ $tax_terms = get_terms( [
751
+ 'taxonomy' => $custom_tax->name,
752
  'hide_empty' => false,
753
+ ] );
754
+
755
+ foreach ( $tax_terms as $tax_term ) {
756
+ if ( in_array( $tax_term->term_id, $allowed_tax_id_arr ) ) {
757
+ ?> <td> <?php echo esc_html( $tax_term->name ); ?> </td> <?php
758
+ }
759
+ }
760
+ }
761
+ } ?>
 
762
  </tr>
763
  </table>
764
  </div>
765
  </div>
766
+ <?php
767
+ } ?>
768
 
769
+ <?php if ( !isset( $user_sub['recurring'] ) || $user_sub['recurring'] != 'yes' ) { ?>
770
 
771
+ <?php if ( empty( $user_sub ) ) { ?>
772
  <div class="wpuf-sub-actions">
773
+ <a class="btn button-secondary wpuf-assing-pack-btn wpuf-add-pack" href="#"><?php esc_html_e( 'Assign Package', 'wp-user-frontend' ); ?></a>
774
+ <a class="btn button-secondary wpuf-assing-pack-btn wpuf-cancel-pack" style="display:none;" href="#"><?php esc_html_e( 'Cancel', 'wp-user-frontend' ); ?></a>
775
  </div>
776
+ <?php } ?>
777
 
778
  <table class="form-table wpuf-pack-dropdown" disabled="disabled" style="display: none;">
779
  <tr>
780
+ <th><label for="wpuf_sub_pack"><?php esc_html_e( 'Select Package:', 'wp-user-frontend' ); ?> </label></th>
781
  <td>
782
  <select name="pack_id" id="wpuf_sub_pack">
783
+ <option value="-1"><?php esc_html_e( '&mdash; Select &mdash;', 'wp-user-frontend' ); ?></option>
784
+ <?php $this->packdropdown_without_recurring( $packs, $pack_id ); //WPUF_Subscription::init()->packdropdown( $packs, $selected = '' );?>
785
  </select>
786
  <br>
787
+ <span class="description"><?php esc_html_e( 'Only non-recurring pack can be assigned', 'wp-user-frontend' ); ?></span>
788
  </td>
789
  </tr>
790
  </table>
791
+ <?php } ?>
792
  <?php
793
+ wp_nonce_field( 'update-profile_' . $userdata->ID, 'wpuf-subscription-nonce' );
794
+ do_action( 'wpuf_admin_subscription_content', $userdata->ID ); ?>
795
+ <?php if ( !empty( $user_sub ) ) { ?>
796
  <div class="wpuf-sub-actions">
797
+ <a class="btn button-secondary wpuf-delete-pack-btn" href="javascript:" data-userid="<?php echo esc_attr( $userdata->ID ); ?>" data-packid="<?php echo isset( $user_sub['pack_id'] ) ? esc_attr( $user_sub['pack_id'] ) : ''; ?>"><?php esc_html_e( 'Delete Package', 'wp-user-frontend' ); ?></a>
798
  </div>
799
+ <?php } ?>
800
  </div>
801
  <?php
 
802
  }
803
 
804
+ public function lenght_type_option( $selected ) {
805
+ for ( $i = 1; $i <= 30; $i++ ) {
 
806
  ?>
807
+ <option value="<?php echo esc_attr( $i ); ?>" <?php selected( $i, $selected ); ?>><?php echo esc_html( $i ); ?></option>
808
  <?php
809
  }
 
810
  }
811
 
812
  /**
813
  * Ajax function. Delete user package
814
+ *
815
  * @since 2.2.7
816
  */
817
+ public function delete_user_package() {
818
+ $nonce = isset( $_REQUEST['wpuf_subscription_delete_nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['wpuf_subscription_delete_nonce'] ) ) : '';
819
+
820
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'wpuf-subscription-delete-nonce' ) ) {
821
+ return ;
822
+ }
823
+ $userid = isset( $_POST['userid'] ) ? intval( wp_unslash( $_POST['userid'] ) ) : 0;
824
+
825
+ echo esc_html( delete_user_meta( $userid, '_wpuf_subscription_pack' ) );
826
  $wpuf_paypal = new WPUF_Paypal();
827
+ $wpuf_paypal->recurring_change_status( $userid, 'Cancel' );
828
 
829
  if ( isset( $_POST['packid'] ) ) {
830
+ $pack_id = intval( wp_unslash( $_POST['packid'] ) );
831
+ WPUF_Subscription::subscriber_cancel( $userid, $pack_id );
832
  }
833
  exit;
834
  }
843
 
844
  if ( 'edit-wpuf_subscription' != $screen->id ) {
845
  return;
846
+ } ?>
 
 
847
  <div class="wpuf-footer-help">
848
  <span class="wpuf-footer-help-content">
849
  <span class="dashicons dashicons-editor-help"></span>
850
+ <?php printf( wp_kses_post( __( 'Learn more about <a href="%s" target="_blank">Subscription</a>', 'wp-user-frontend' ) ), 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/?utm_source=wpuf-footer-help&utm_medium=text-link&utm_campaign=learn-more-subscription' ); ?>
851
  </span>
852
  </div>
853
 
admin/class-admin-welcome.php CHANGED
@@ -7,9 +7,9 @@
7
  */
8
  class WPUF_Admin_Welcome {
9
 
10
- function __construct() {
11
- add_action( 'admin_menu', array( $this, 'register_menu' ) );
12
- add_action( 'admin_head', array( $this, 'hide_menu' ) );
13
  // add_action( 'admin_init', array( $this, 'redirect_to_page' ), 9999 );
14
  }
15
 
@@ -19,7 +19,7 @@ class WPUF_Admin_Welcome {
19
  * @return void
20
  */
21
  public function register_menu() {
22
- add_dashboard_page( __( 'Welcome to WP User Frontend', 'wp-user-frontend' ), __( 'Welcome to WP User Frontend', 'wp-user-frontend' ), 'manage_options', 'wpuf-welcome', array( $this, 'welcome_page' ) );
23
  }
24
 
25
  /**
@@ -37,7 +37,7 @@ class WPUF_Admin_Welcome {
37
  * @return void
38
  */
39
  public function redirect_to_page() {
40
- if ( ! get_transient( 'wpuf_activation_redirect' ) ) {
41
  return;
42
  }
43
 
7
  */
8
  class WPUF_Admin_Welcome {
9
 
10
+ public function __construct() {
11
+ add_action( 'admin_menu', [ $this, 'register_menu' ] );
12
+ add_action( 'admin_head', [ $this, 'hide_menu' ] );
13
  // add_action( 'admin_init', array( $this, 'redirect_to_page' ), 9999 );
14
  }
15
 
19
  * @return void
20
  */
21
  public function register_menu() {
22
+ add_dashboard_page( __( 'Welcome to WP User Frontend', 'wp-user-frontend' ), __( 'Welcome to WP User Frontend', 'wp-user-frontend' ), 'manage_options', 'wpuf-welcome', [ $this, 'welcome_page' ] );
23
  }
24
 
25
  /**
37
  * @return void
38
  */
39
  public function redirect_to_page() {
40
+ if ( !get_transient( 'wpuf_activation_redirect' ) ) {
41
  return;
42
  }
43
 
admin/class-tools.php CHANGED
@@ -4,54 +4,59 @@
4
  * Manage Import Export
5
  *
6
  * @since 2.2
7
- *
8
- * @package WP User Frontend
9
  */
10
  class WPUF_Admin_Tools {
11
-
12
  /**
13
  * List of All the post forms
14
  *
15
  * @return void
16
  */
17
- function list_forms() {
18
-
19
  if ( isset( $_POST['export'] ) ) {
20
- $this->export_data( $_POST['export_content'], $_POST['formlist'] );
 
 
 
 
 
 
 
 
 
21
  }
22
 
23
- $args = array(
24
  'post_type' => 'wpuf_forms',
25
  'posts_per_page' => -1,
26
- 'post_status' => 'publish'
27
- );
28
  $forms = get_posts( $args );
29
 
30
  if ( $forms ) {
31
  ?>
32
  <div class="postbox" style="margin-top: 15px;">
33
- <h3 style="padding:10px 15px"><?php _e( 'Form Export', 'wp-user-frontend' ); ?></h3>
34
  <div class="inside">
35
  <div class="main">
36
  <form action="" method="post" style="margin-top: 20px;">
37
  <p>
38
  <input class="export_type" type="radio" name="export_content" value="all" id="wpuf-all_export" checked>
39
- <label for="wpuf-all_export"><?php _e( 'All', 'wp-user-frontend' ); ?></label>
40
  </p>
41
 
42
  <p>
43
  <input class="export_type" type="radio" name="export_content" value="selected" id="wpuf-selected_export">
44
- <label for="wpuf-selected_export"><?php _e( 'Select individual', 'wp-user-frontend' ); ?></label></p>
45
  <p>
46
  <select class="formlist" name="formlist[]" multiple="multiple">
47
  <?php foreach ( $forms as $form ) { ?>
48
- <option value="<?php echo esc_attr( $form->ID ) ?>"><?php echo esc_attr( $form->post_title ); ?></option>
49
  <?php } ?>
50
  </select>
51
  </p>
52
 
53
  <?php wp_nonce_field( 'wpuf-export-form' ); ?>
54
- <input type="submit" class="button button-primary" name="export" value="<?php _e( 'Export', 'wp-user-frontend' ) ?>">
55
  </form>
56
  </div>
57
  </div>
@@ -68,23 +73,34 @@ class WPUF_Admin_Tools {
68
  *
69
  * @return void
70
  */
71
- function list_regis_forms() {
72
-
73
  if ( isset( $_POST['export_regis_form'] ) ) {
74
- $this->export_regis_data( $_POST['export_regis_content'], $_POST['formlist'] );
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
- $args = array(
78
  'post_type' => 'wpuf_profile',
79
  'posts_per_page' => -1,
80
- 'post_status' => 'publish'
81
- );
82
 
83
  $forms = get_posts( $args );
 
84
  if ( $forms ) {
85
  ?>
86
  <div class="postbox">
87
- <h3 style="padding:10px 15px"><?php _e( 'Registration Form Export', 'wp-user-frontend' ); ?></h3>
88
  <div class="inside">
89
  <div class="main">
90
 
@@ -92,12 +108,12 @@ class WPUF_Admin_Tools {
92
 
93
  <p>
94
  <input class="export_type" type="radio" name="export_regis_content" value="all" id="wpuf-all_regis_export" checked>
95
- <label for="wpuf-all_regis_export"><?php _e( 'All', 'wp-user-frontend' ); ?></label>
96
  </p>
97
 
98
  <p>
99
  <input class="export_type" type="radio" name="export_regis_content" value="selected" id="wpuf-selected_regis_export">
100
- <label for="wpuf-selected_regis_export"><?php _e( 'Select individual', 'wp-user-frontend' ); ?></label>
101
  </p>
102
 
103
  <p>
@@ -110,7 +126,7 @@ class WPUF_Admin_Tools {
110
 
111
  <?php wp_nonce_field( 'wpuf-export-regs-form' ); ?>
112
 
113
- <input type="submit" class="button button-primary" name="export_regis_form" value="<?php _e( 'Export', 'wp-user-frontend' ) ?>">
114
  </form>
115
  </div>
116
  </div>
@@ -124,70 +140,67 @@ class WPUF_Admin_Tools {
124
  /**
125
  * Import functionality
126
  */
127
- function import_data() {
128
-
129
  if ( isset( $_FILES['import'] ) && check_admin_referer( 'wpuf-import' ) ) {
 
130
 
131
- if ( $_FILES['import']['error'] > 0 ) {
132
-
133
- printf( '<div class="error"><p>%s</p></div>', __( 'Somthing went wrong. Please choose a file again', 'wp-user-frontend' ) );
134
  } else {
135
-
136
- $file_name = $_FILES['import']['name'];
137
  $file_ext = pathinfo( $file_name, PATHINFO_EXTENSION );
138
- $file_size = $_FILES['import']['size'];
139
 
140
- if ( ($file_ext == "json") && ($file_size < 500000) ) {
141
-
142
- $data = static::import_json_file( $_FILES['import']['tmp_name'] );
143
 
144
  if ( $data ) {
145
- printf( '<div class="updated"><p>%s</p></div>', __( 'Import successful. Have fun!', 'wp-user-frontend' ) );
146
  }
147
  } else {
148
- printf( '<div class="error"><p>%s</p></div>', __( 'Invalid file or file size too big.', 'wp-user-frontend' ) );
149
  }
150
  }
151
- }
152
- ?>
153
 
154
- <h3><?php _e( 'Import forms', 'wp-user-frontend' ); ?></h3>
155
 
156
- <p><?php _e( 'Click Browse button and choose a json file that you backup before.', 'wp-user-frontend' ); ?></p>
157
- <p><?php _e( 'Press <strong>Import</strong> button, we will do the rest for you.', 'wp-user-frontend' ); ?></p>
 
 
158
 
159
  <form action="" method="post" enctype='multipart/form-data' style="margin-top: 20px;">
160
  <?php wp_nonce_field( 'wpuf-import' ); ?>
161
  <input type='file' name='import' />
162
- <input type="submit" class="button button-primary" name="import_data" value="<?php _e( 'Import', 'wp-user-frontend' ); ?>">
163
  </form>
164
  <?php
165
  }
166
 
167
  /**
168
  * Import json file into database
169
- * @param array $file
170
- * @return boolean
 
 
171
  */
172
  public static function import_json_file( $file ) {
173
-
174
  $encode_data = file_get_contents( $file );
175
  $options = json_decode( $encode_data, true );
176
 
177
  foreach ( $options as $key => $value ) {
178
-
179
- $generate_post = array(
180
  'post_title' => $value['post_data']['post_title'],
181
  'post_status' => $value['post_data']['post_status'],
182
  'post_type' => $value['post_data']['post_type'],
183
  'ping_status' => $value['post_data']['ping_status'],
184
- 'comment_status' => $value['post_data']['comment_status']
185
- );
186
 
187
  $post_id = wp_insert_post( $generate_post, true );
188
 
189
  if ( $post_id && !is_wp_error( $post_id ) ) {
190
-
191
  foreach ( $value['meta_data']['fields'] as $order => $field ) {
192
  wpuf_insert_form_field( $post_id, $field, false, $order );
193
  }
@@ -202,19 +215,18 @@ class WPUF_Admin_Tools {
202
 
203
  /**
204
  * Export Registration form
205
- * @param string $export_type
206
- * @param integer $post_ids
 
207
  */
208
- function export_regis_data( $export_type, $post_ids ) {
209
-
210
  if ( $export_type == 'all' && check_admin_referer( 'wpuf-export-regs-form' ) ) {
211
-
212
  static::export_to_json( 'wpuf_profile' );
213
-
214
  } elseif ( $export_type == 'selected' && check_admin_referer( 'wpuf-export-regs-form' ) ) {
 
215
 
216
- if ( $_POST['formlist'] == NULL ) {
217
- printf( '<div class="error"><p>%s</p></div>', __( 'Please select some form for exporting', 'wp-user-frontend' ) );
218
  } else {
219
  static::export_to_json( 'wpuf_profile', $post_ids );
220
  }
@@ -223,18 +235,18 @@ class WPUF_Admin_Tools {
223
 
224
  /**
225
  * Export normal form data
226
- * @param string $export_type
227
- * @param integer $post_ids
 
228
  */
229
- function export_data( $export_type, $post_ids ) {
230
- if ( $export_type == 'all' && check_admin_referer( 'wpuf-export-form' ) ) {
231
 
 
232
  static::export_to_json( 'wpuf_forms' );
233
-
234
  } elseif ( $export_type == 'selected' && check_admin_referer( 'wpuf-export-form' ) ) {
235
-
236
- if ( $_POST['formlist'] == NULL ) {
237
- printf( '<div class="error"><p>%s</p></div>', __( 'Please select some form for exporting', 'wp-user-frontend' ) );
238
  } else {
239
  static::export_to_json( 'wpuf_forms', $post_ids );
240
  }
@@ -244,28 +256,27 @@ class WPUF_Admin_Tools {
244
  /**
245
  * Export into json file
246
  *
247
- * @param string $post_type
248
- * @param array $post_ids
249
  */
250
- public static function export_to_json( $post_type, $post_ids = array( ) ) {
251
-
252
- $formatted_data = array();
253
- $ids = array();
254
- $blogname = strtolower( str_replace( " ", "-", get_option( 'blogname' ) ) );
255
- $date = date( "Y-m-d" );
256
- $json_name = $blogname . "-wpuf-" . $post_type . '-' . $date; // Namming the filename will be generated.
257
-
258
- if ( ! empty( $post_ids ) ) {
259
  foreach ( $post_ids as $key => $value ) {
260
  array_push( $ids, $value );
261
  }
262
  }
263
 
264
- $args = array(
265
  'post_status' => 'publish',
266
  'post_type' => $post_type,
267
- 'post__in' => (!empty( $ids ) ) ? $ids : ''
268
- );
269
 
270
  $query = new WP_Query( $args );
271
 
@@ -273,14 +284,14 @@ class WPUF_Admin_Tools {
273
  $postdata = get_object_vars( $post );
274
  unset( $postdata['ID'] );
275
 
276
- $data = array(
277
  'post_data' => $postdata,
278
- 'meta_data' => array(
279
  'fields' => wpuf_get_form_fields( $post->ID ),
280
  'settings' => wpuf_get_form_settings( $post->ID ),
281
- 'notifications' => wpuf_get_form_notifications( $post->ID )
282
- )
283
- );
284
 
285
  array_push( $formatted_data, $data );
286
  }
@@ -289,9 +300,9 @@ class WPUF_Admin_Tools {
289
 
290
  ob_clean();
291
 
292
- echo $json_file;
293
 
294
- header( "Content-Type: text/json; charset=" . get_option( 'blog_charset' ) );
295
  header( "Content-Disposition: attachment; filename=$json_name.json" );
296
 
297
  exit();
@@ -300,11 +311,12 @@ class WPUF_Admin_Tools {
300
  /**
301
  * Formetted meta key value
302
  *
303
- * @param array $array
 
304
  * @return array
305
  */
306
- function formetted_meta_key_value( $array ) {
307
- $result = array( );
308
 
309
  foreach ( $array as $key => $val ) {
310
  $result[$key] = $val[0];
@@ -313,11 +325,11 @@ class WPUF_Admin_Tools {
313
  return $result;
314
  }
315
 
316
- function tool_page() {
317
- $msg = isset( $_GET['msg'] ) ? $_GET['msg'] : '';
318
- $text = '';
319
  $confirmation_message = __( 'Are you Sure?', 'wp-user-frontend' );
320
- switch ($msg) {
321
  case 'del_forms':
322
  $text = __( 'All forms has been deleted', 'wp-user-frontend' );
323
  break;
@@ -335,56 +347,54 @@ class WPUF_Admin_Tools {
335
  ?>
336
  <div class="updated">
337
  <p>
338
- <?php echo $text; ?>
339
  </p>
340
  </div>
341
 
342
  <?php } ?>
343
 
344
-
345
  <div class="metabox-holder">
346
  <div class="postbox">
347
- <h3><?php _e( 'Page Installation', 'wp-user-frontend' ); ?></h3>
348
 
349
  <div class="inside">
350
- <p><?php _e( 'Clicking this button will create required pages for the plugin. Note: It\'ll not delete/replace existing pages.', 'wp-user-frontend' ); ?></p>
351
- <a class="button button-primary" href="<?php echo add_query_arg( array( 'install_wpuf_pages' => true ) ); ?>"><?php _e( 'Install WPUF Pages', 'wp-user-frontend' ); ?></a>
352
  </div>
353
  </div>
354
 
355
  <div class="postbox">
356
- <h3><?php _e( 'Reset Settings', 'wp-user-frontend' ); ?></h3>
357
 
358
  <div class="inside">
359
- <p><?php _e( '<strong>Caution:</strong> This tool will delete all the plugin settings of WP User Frontend Pro', 'wp-user-frontend' ); ?></p>
360
- <a class="button button-primary" href="<?php echo wp_nonce_url( add_query_arg( array( 'wpuf_action' => 'clear_settings' ), 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ); ?>" onclick="return confirm('Are you sure?');"><?php _e( 'Reset Settings', 'wp-user-frontend' ); ?></a>
361
  </div>
362
  </div>
363
 
364
  <div class="postbox">
365
- <h3><?php _e( 'Delete Forms', 'wp-user-frontend' ); ?></h3>
366
 
367
  <div class="inside">
368
- <p><?php _e( '<strong>Caution:</strong> This tool will delete all the post and registration/profile forms.', 'wp-user-frontend' ); ?></p>
369
 
370
- <a class="button button-primary" href="<?php echo wp_nonce_url( add_query_arg( array( 'wpuf_action' => 'del_post_forms' ), 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ); ?>" onclick="return confirm('<?php echo $confirmation_message ?>');"><?php _e( 'Delete Post Forms', 'wp-user-frontend' ); ?></a>
371
- <a class="button button-primary" href="<?php echo wp_nonce_url( add_query_arg( array( 'wpuf_action' => 'del_pro_forms' ), 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ); ?>" onclick="return confirm('<?php echo $confirmation_message ?>');"><?php _e( 'Delete Registration Forms', 'wp-user-frontend' ); ?></a>
372
- <a class="button button-primary" href="<?php echo wp_nonce_url( add_query_arg( array( 'wpuf_action' => 'del_subs' ), 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ); ?>" onclick="return confirm('<?php echo $confirmation_message ?>');"><?php _e( 'Delete Subscriptions', 'wp-user-frontend' ); ?></a>
373
- <a class="button button-primary" href="<?php echo wp_nonce_url( add_query_arg( array( 'wpuf_action' => 'del_coupon' ), 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ); ?>" onclick="return confirm('<?php echo $confirmation_message ?>');"><?php _e( 'Delete Coupons', 'wp-user-frontend' ); ?></a>
374
  </div>
375
  </div>
376
 
377
  <div class="postbox">
378
- <h3><?php _e( 'Transactions', 'wp-user-frontend' ); ?></h3>
379
 
380
  <div class="inside">
381
- <p><?php _e( 'This tool will delete all the transactions from the transaction table.', 'wp-user-frontend' ); ?></p>
382
 
383
- <a class="button button-primary" href="<?php echo wp_nonce_url( add_query_arg( array( 'wpuf_action' => 'clear_transaction' ), 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ); ?>" onclick="return confirm('<?php echo $confirmation_message ?>');"><?php _e( 'Delete Transactions', 'wp-user-frontend' ); ?></a>
384
  </div>
385
  </div>
386
  </div>
387
  <?php
388
  }
389
-
390
  }
4
  * Manage Import Export
5
  *
6
  * @since 2.2
 
 
7
  */
8
  class WPUF_Admin_Tools {
 
9
  /**
10
  * List of All the post forms
11
  *
12
  * @return void
13
  */
14
+ public function list_forms() {
 
15
  if ( isset( $_POST['export'] ) ) {
16
+
17
+ $export_content = isset( $_POST['export_content'] ) ? sanitize_text_field( wp_unslash( $_POST['export_content'] ) ) : '';
18
+ $formlist = isset( $_POST['formlist'] ) ? sanitize_text_field( wp_unslash( $_POST['formlist'] ) ) : '';
19
+ $this->export_data( $export_content, $formlist );
20
+
21
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
22
+
23
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'wpuf-export-form' ) ) {
24
+ return ;
25
+ }
26
  }
27
 
28
+ $args = [
29
  'post_type' => 'wpuf_forms',
30
  'posts_per_page' => -1,
31
+ 'post_status' => 'publish',
32
+ ];
33
  $forms = get_posts( $args );
34
 
35
  if ( $forms ) {
36
  ?>
37
  <div class="postbox" style="margin-top: 15px;">
38
+ <h3 style="padding:10px 15px"><?php esc_html_e( 'Form Export', 'wp-user-frontend' ); ?></h3>
39
  <div class="inside">
40
  <div class="main">
41
  <form action="" method="post" style="margin-top: 20px;">
42
  <p>
43
  <input class="export_type" type="radio" name="export_content" value="all" id="wpuf-all_export" checked>
44
+ <label for="wpuf-all_export"><?php esc_html_e( 'All', 'wp-user-frontend' ); ?></label>
45
  </p>
46
 
47
  <p>
48
  <input class="export_type" type="radio" name="export_content" value="selected" id="wpuf-selected_export">
49
+ <label for="wpuf-selected_export"><?php esc_html_e( 'Select individual', 'wp-user-frontend' ); ?></label></p>
50
  <p>
51
  <select class="formlist" name="formlist[]" multiple="multiple">
52
  <?php foreach ( $forms as $form ) { ?>
53
+ <option value="<?php echo esc_attr( $form->ID ); ?>"><?php echo esc_attr( $form->post_title ); ?></option>
54
  <?php } ?>
55
  </select>
56
  </p>
57
 
58
  <?php wp_nonce_field( 'wpuf-export-form' ); ?>
59
+ <input type="submit" class="button button-primary" name="export" value="<?php esc_html_e( 'Export', 'wp-user-frontend' ); ?>">
60
  </form>
61
  </div>
62
  </div>
73
  *
74
  * @return void
75
  */
76
+ public function list_regis_forms() {
 
77
  if ( isset( $_POST['export_regis_form'] ) ) {
78
+
79
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ): '';
80
+
81
+ $export_regis_content = isset( $_POST['export_regis_content'] ) ? sanitize_text_field( wp_unslash( $_POST['export_regis_content'] ) ) : '';
82
+ $formlist = isset( $_POST['formlist'] ) ? sanitize_text_field( wp_unslash( $_POST['formlist'] ) ) : '';
83
+
84
+ $this->export_regis_data( $export_regis_content, $formlist );
85
+
86
+
87
+ if ( isset( $nonce) && ! wp_verify_nonce( $nonce, 'wpuf-export-regs-form' ) ) {
88
+ return ;
89
+ }
90
  }
91
 
92
+ $args = [
93
  'post_type' => 'wpuf_profile',
94
  'posts_per_page' => -1,
95
+ 'post_status' => 'publish',
96
+ ];
97
 
98
  $forms = get_posts( $args );
99
+
100
  if ( $forms ) {
101
  ?>
102
  <div class="postbox">
103
+ <h3 style="padding:10px 15px"><?php esc_html_e( 'Registration Form Export', 'wp-user-frontend' ); ?></h3>
104
  <div class="inside">
105
  <div class="main">
106
 
108
 
109
  <p>
110
  <input class="export_type" type="radio" name="export_regis_content" value="all" id="wpuf-all_regis_export" checked>
111
+ <label for="wpuf-all_regis_export"><?php esc_html_e( 'All', 'wp-user-frontend' ); ?></label>
112
  </p>
113
 
114
  <p>
115
  <input class="export_type" type="radio" name="export_regis_content" value="selected" id="wpuf-selected_regis_export">
116
+ <label for="wpuf-selected_regis_export"><?php esc_html_e( 'Select individual', 'wp-user-frontend' ); ?></label>
117
  </p>
118
 
119
  <p>
126
 
127
  <?php wp_nonce_field( 'wpuf-export-regs-form' ); ?>
128
 
129
+ <input type="submit" class="button button-primary" name="export_regis_form" value="<?php esc_html_e( 'Export', 'wp-user-frontend' ); ?>">
130
  </form>
131
  </div>
132
  </div>
140
  /**
141
  * Import functionality
142
  */
143
+ public function import_data() {
 
144
  if ( isset( $_FILES['import'] ) && check_admin_referer( 'wpuf-import' ) ) {
145
+ $import_files = array_map( 'sanitize_text_field', wp_unslash( $_FILES['import'] ) );
146
 
147
+ if ( $import_files['error'] > 0 ) {
148
+ printf( '<div class="error"><p>%s</p></div>', esc_html( __( 'Somthing went wrong. Please choose a file again', 'wp-user-frontend' ) ) );
 
149
  } else {
150
+ $file_name = $import_files['name'];
 
151
  $file_ext = pathinfo( $file_name, PATHINFO_EXTENSION );
152
+ $file_size = $import_files['size'];
153
 
154
+ if ( ( $file_ext == 'json' ) && ( $file_size < 500000 ) ) {
155
+ $data = static::import_json_file( $import_files['tmp_name'] );
 
156
 
157
  if ( $data ) {
158
+ printf( '<div class="updated"><p>%s</p></div>', esc_html( __( 'Import successful. Have fun!', 'wp-user-frontend' ) ) );
159
  }
160
  } else {
161
+ printf( '<div class="error"><p>%s</p></div>',esc_html( __( 'Invalid file or file size too big.', 'wp-user-frontend' ) ) );
162
  }
163
  }
164
+ } ?>
 
165
 
166
+ <h3><?php esc_html_e( 'Import forms', 'wp-user-frontend' ); ?></h3>
167
 
168
+ <p><?php esc_html_e( 'Click Browse button and choose a json file that you backup before.', 'wp-user-frontend' ); ?></p>
169
+ <p><?php echo wp_kses( __( 'Press <strong>Import</strong> button, we will do the rest for you.', 'wp-user-frontend' ), array(
170
+ 'strong' => array()
171
+ ) ); ?></p>
172
 
173
  <form action="" method="post" enctype='multipart/form-data' style="margin-top: 20px;">
174
  <?php wp_nonce_field( 'wpuf-import' ); ?>
175
  <input type='file' name='import' />
176
+ <input type="submit" class="button button-primary" name="import_data" value="<?php esc_html_e( 'Import', 'wp-user-frontend' ); ?>">
177
  </form>
178
  <?php
179
  }
180
 
181
  /**
182
  * Import json file into database
183
+ *
184
+ * @param array $file
185
+ *
186
+ * @return bool
187
  */
188
  public static function import_json_file( $file ) {
 
189
  $encode_data = file_get_contents( $file );
190
  $options = json_decode( $encode_data, true );
191
 
192
  foreach ( $options as $key => $value ) {
193
+ $generate_post = [
 
194
  'post_title' => $value['post_data']['post_title'],
195
  'post_status' => $value['post_data']['post_status'],
196
  'post_type' => $value['post_data']['post_type'],
197
  'ping_status' => $value['post_data']['ping_status'],
198
+ 'comment_status' => $value['post_data']['comment_status'],
199
+ ];
200
 
201
  $post_id = wp_insert_post( $generate_post, true );
202
 
203
  if ( $post_id && !is_wp_error( $post_id ) ) {
 
204
  foreach ( $value['meta_data']['fields'] as $order => $field ) {
205
  wpuf_insert_form_field( $post_id, $field, false, $order );
206
  }
215
 
216
  /**
217
  * Export Registration form
218
+ *
219
+ * @param string $export_type
220
+ * @param int $post_ids
221
  */
222
+ public function export_regis_data( $export_type, $post_ids ) {
 
223
  if ( $export_type == 'all' && check_admin_referer( 'wpuf-export-regs-form' ) ) {
 
224
  static::export_to_json( 'wpuf_profile' );
 
225
  } elseif ( $export_type == 'selected' && check_admin_referer( 'wpuf-export-regs-form' ) ) {
226
+ $formlist = isset( $_POST['formlist'] ) ? sanitize_text_field( wp_unslash( $_POST['formlist'] ) ) : '';
227
 
228
+ if ( $formlist == null ) {
229
+ printf( '<div class="error"><p>%s</p></div>', esc_html( __( 'Please select some form for exporting', 'wp-user-frontend' ) ) );
230
  } else {
231
  static::export_to_json( 'wpuf_profile', $post_ids );
232
  }
235
 
236
  /**
237
  * Export normal form data
238
+ *
239
+ * @param string $export_type
240
+ * @param int $post_ids
241
  */
242
+ public function export_data( $export_type, $post_ids ) {
243
+ $formlist = isset( $_POST['formlist'] ) ? sanitize_text_field( wp_unslash( $_POST['formlist'] ) ) : '';
244
 
245
+ if ( $export_type == 'all' && check_admin_referer( 'wpuf-export-form' ) ) {
246
  static::export_to_json( 'wpuf_forms' );
 
247
  } elseif ( $export_type == 'selected' && check_admin_referer( 'wpuf-export-form' ) ) {
248
+ if ( $formlist == null ) {
249
+ printf( '<div class="error"><p>%s</p></div>',esc_html( __( 'Please select some form for exporting', 'wp-user-frontend' ) ) );
 
250
  } else {
251
  static::export_to_json( 'wpuf_forms', $post_ids );
252
  }
256
  /**
257
  * Export into json file
258
  *
259
+ * @param string $post_type
260
+ * @param array $post_ids
261
  */
262
+ public static function export_to_json( $post_type, $post_ids = [ ] ) {
263
+ $formatted_data = [];
264
+ $ids = [];
265
+ $blogname = strtolower( str_replace( ' ', '-', get_option( 'blogname' ) ) );
266
+ $date = date( 'Y-m-d' );
267
+ $json_name = $blogname . '-wpuf-' . $post_type . '-' . $date; // Namming the filename will be generated.
268
+
269
+ if ( !empty( $post_ids ) ) {
 
270
  foreach ( $post_ids as $key => $value ) {
271
  array_push( $ids, $value );
272
  }
273
  }
274
 
275
+ $args = [
276
  'post_status' => 'publish',
277
  'post_type' => $post_type,
278
+ 'post__in' => ( !empty( $ids ) ) ? $ids : '',
279
+ ];
280
 
281
  $query = new WP_Query( $args );
282
 
284
  $postdata = get_object_vars( $post );
285
  unset( $postdata['ID'] );
286
 
287
+ $data = [
288
  'post_data' => $postdata,
289
+ 'meta_data' => [
290
  'fields' => wpuf_get_form_fields( $post->ID ),
291
  'settings' => wpuf_get_form_settings( $post->ID ),
292
+ 'notifications' => wpuf_get_form_notifications( $post->ID ),
293
+ ],
294
+ ];
295
 
296
  array_push( $formatted_data, $data );
297
  }
300
 
301
  ob_clean();
302
 
303
+ echo esc_js( $json_file );
304
 
305
+ header( 'Content-Type: text/json; charset=' . get_option( 'blog_charset' ) );
306
  header( "Content-Disposition: attachment; filename=$json_name.json" );
307
 
308
  exit();
311
  /**
312
  * Formetted meta key value
313
  *
314
+ * @param array $array
315
+ *
316
  * @return array
317
  */
318
+ public function formetted_meta_key_value( $array ) {
319
+ $result = [ ];
320
 
321
  foreach ( $array as $key => $val ) {
322
  $result[$key] = $val[0];
325
  return $result;
326
  }
327
 
328
+ public function tool_page() {
329
+ $msg = isset( $_GET['msg'] ) ? sanitize_text_field( wp_unslash( $_GET['msg'] ) ) : '';
330
+ $text = '';
331
  $confirmation_message = __( 'Are you Sure?', 'wp-user-frontend' );
332
+ switch ( $msg ) {
333
  case 'del_forms':
334
  $text = __( 'All forms has been deleted', 'wp-user-frontend' );
335
  break;
347
  ?>
348
  <div class="updated">
349
  <p>
350
+ <?php echo esc_html( $text ); ?>
351
  </p>
352
  </div>
353
 
354
  <?php } ?>
355
 
 
356
  <div class="metabox-holder">
357
  <div class="postbox">
358
+ <h3><?php esc_html_e( 'Page Installation', 'wp-user-frontend' ); ?></h3>
359
 
360
  <div class="inside">
361
+ <p><?php esc_html_e( 'Clicking this button will create required pages for the plugin. Note: It\'ll not delete/replace existing pages.', 'wp-user-frontend' ); ?></p>
362
+ <a class="button button-primary" href="<?php echo esc_attr( add_query_arg( [ 'install_wpuf_pages' => true ] ) ); ?>"><?php esc_html_e( 'Install WPUF Pages', 'wp-user-frontend' ); ?></a>
363
  </div>
364
  </div>
365
 
366
  <div class="postbox">
367
+ <h3><?php esc_html_e( 'Reset Settings', 'wp-user-frontend' ); ?></h3>
368
 
369
  <div class="inside">
370
+ <p><?php wp_kses_post('<strong>Caution:</strong> This tool will delete all the plugin settings of WP User Frontend Pro', 'wp-user-frontend' ); ?></p>
371
+ <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( [ 'wpuf_action' => 'clear_settings' ], 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ) ); ?>" onclick="return confirm('Are you sure?');"><?php esc_html_e( 'Reset Settings', 'wp-user-frontend' ); ?></a>
372
  </div>
373
  </div>
374
 
375
  <div class="postbox">
376
+ <h3><?php esc_html_e( 'Delete Forms', 'wp-user-frontend' ); ?></h3>
377
 
378
  <div class="inside">
379
+ <p><?php wp_kses_post( '<strong>Caution:</strong> This tool will delete all the post and registration/profile forms.', 'wp-user-frontend' ); ?></p>
380
 
381
+ <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( [ 'wpuf_action' => 'del_post_forms' ], 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ) ); ?>" onclick="return confirm('<?php echo esc_attr( $confirmation_message ); ?>');"><?php esc_html_e( 'Delete Post Forms', 'wp-user-frontend' ); ?></a>
382
+ <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( [ 'wpuf_action' => 'del_pro_forms' ], 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ) ); ?>" onclick="return confirm('<?php echo esc_attr( $confirmation_message ); ?>');"><?php esc_html_e( 'Delete Registration Forms', 'wp-user-frontend' ); ?></a>
383
+ <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( [ 'wpuf_action' => 'del_subs' ], 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ) ); ?>" onclick="return confirm('<?php echo esc_attr( $confirmation_message ); ?>');"><?php esc_html_e( 'Delete Subscriptions', 'wp-user-frontend' ); ?></a>
384
+ <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( [ 'wpuf_action' => 'del_coupon' ], 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ) ); ?>" onclick="return confirm('<?php echo esc_attr( $confirmation_message ); ?>');"><?php esc_html_e( 'Delete Coupons', 'wp-user-frontend' ); ?></a>
385
  </div>
386
  </div>
387
 
388
  <div class="postbox">
389
+ <h3><?php esc_html_e( 'Transactions', 'wp-user-frontend' ); ?></h3>
390
 
391
  <div class="inside">
392
+ <p><?php esc_html_e( 'This tool will delete all the transactions from the transaction table.', 'wp-user-frontend' ); ?></p>
393
 
394
+ <a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( [ 'wpuf_action' => 'clear_transaction' ], 'admin.php?page=wpuf_tools&action=tools' ), 'wpuf-tools-action' ) ); ?>" onclick="return confirm('<?php echo esc_attr( $confirmation_message ); ?>');"><?php esc_html_e( 'Delete Transactions', 'wp-user-frontend' ); ?></a>
395
  </div>
396
  </div>
397
  </div>
398
  <?php
399
  }
 
400
  }
admin/form-builder/assets/js/components/builder-stage/template.php CHANGED
@@ -1,6 +1,6 @@
1
  <div id="form-preview-stage" class="wpuf-style">
2
  <h4 v-if="!form_fields.length" class="text-center">
3
- <?php _e( 'Add fields by dragging the fields from the right sidebar to this area.', 'wp-user-frontend' ) ?>
4
  </h4>
5
 
6
  <ul :class="['wpuf-form', 'sortable-list', 'form-label-' + label_type]">
@@ -50,14 +50,14 @@
50
  </ul><!-- .wpuf-form -->
51
 
52
  <div v-if="hidden_fields.length" class="hidden-field-list">
53
- <h4><?php _e( 'Hidden Fields', 'wp-user-frontend' ); ?></h4>
54
 
55
  <ul class="wpuf-form">
56
  <li
57
  v-for="(field, index) in hidden_fields"
58
  :class="['field-items', parseInt(editing_form_id) === parseInt(field.id) ? 'current-editing' : '']"
59
  >
60
- <strong><?php _e('key', 'wp-user-frontend'); ?></strong>: {{ field.name }} | <strong><?php _e( 'value', 'wp-user-frontend' ); ?></strong>: {{ field.meta_value }}
61
 
62
  <div class="control-buttons">
63
  <p>
1
  <div id="form-preview-stage" class="wpuf-style">
2
  <h4 v-if="!form_fields.length" class="text-center">
3
+ <?php _e( 'Add fields by dragging the fields from the right sidebar to this area.', 'wp-user-frontend' ); ?>
4
  </h4>
5
 
6
  <ul :class="['wpuf-form', 'sortable-list', 'form-label-' + label_type]">
50
  </ul><!-- .wpuf-form -->
51
 
52
  <div v-if="hidden_fields.length" class="hidden-field-list">
53
+ <h4><?php esc_html_e( 'Hidden Fields', 'wp-user-frontend' ); ?></h4>
54
 
55
  <ul class="wpuf-form">
56
  <li
57
  v-for="(field, index) in hidden_fields"
58
  :class="['field-items', parseInt(editing_form_id) === parseInt(field.id) ? 'current-editing' : '']"
59
  >
60
+ <strong><?php esc_html_e( 'key', 'wp-user-frontend' ); ?></strong>: {{ field.name }} | <strong><?php esc_html_e( 'value', 'wp-user-frontend' ); ?></strong>: {{ field.meta_value }}
61
 
62
  <div class="control-buttons">
63
  <p>
admin/form-builder/assets/js/components/field-option-data/template.php CHANGED
@@ -17,7 +17,7 @@
17
  </div>
18
 
19
  <div v-if="show_value" class="value">
20
- <?php _e( 'Value', 'wp-user-frontend' ) ?>
21
  </div>
22
 
23
  <div class="action-buttons">&nbsp;</div>
17
  </div>
18
 
19
  <div v-if="show_value" class="value">
20
+ <?php _e( 'Value', 'wp-user-frontend' ); ?>
21
  </div>
22
 
23
  <div class="action-buttons">&nbsp;</div>
admin/form-builder/assets/js/components/field-visibility/template.php CHANGED
@@ -13,22 +13,20 @@
13
 
14
  <div v-if="'logged_in' === selected" class="condiotional-logic-container">
15
 
16
- <?php $roles = get_editable_roles() ?>
17
 
18
  <ul>
19
  <?php
20
- foreach ($roles as $role => $value) {
 
21
 
22
- $role_name = $value['name'];
 
 
23
 
24
- $output = "<li>";
25
- $output .= "<label><input type='checkbox' v-model='choices' value='{$role}'> {$role_name} </label>";
26
- $output .= "</li>";
27
-
28
- echo $output;
29
-
30
- }
31
- ?>
32
  </ul>
33
  </div>
34
 
@@ -41,14 +39,12 @@
41
  $subscriptions = WPUF_Subscription::init()->get_subscriptions();
42
 
43
  if ( $subscriptions ) {
44
- foreach ($subscriptions as $pack) {
45
-
46
- $output = "<li>";
47
  $output .= "<label><input type='checkbox' v-model='choices' value='{$pack->ID}' > {$pack->post_title} </label>";
48
- $output .= "</li>";
49
 
50
  echo $output;
51
-
52
  }
53
  } else {
54
  _e( 'No subscription plan found.', 'wp-user-frontend' );
13
 
14
  <div v-if="'logged_in' === selected" class="condiotional-logic-container">
15
 
16
+ <?php $roles = get_editable_roles(); ?>
17
 
18
  <ul>
19
  <?php
20
+ foreach ( $roles as $role => $value ) {
21
+ $role_name = $value['name'];
22
 
23
+ $output = '<li>';
24
+ $output .= "<label><input type='checkbox' v-model='choices' value='{$role}'> {$role_name} </label>";
25
+ $output .= '</li>';
26
 
27
+ echo $output;
28
+ }
29
+ ?>
 
 
 
 
 
30
  </ul>
31
  </div>
32
 
39
  $subscriptions = WPUF_Subscription::init()->get_subscriptions();
40
 
41
  if ( $subscriptions ) {
42
+ foreach ( $subscriptions as $pack ) {
43
+ $output = '<li>';
 
44
  $output .= "<label><input type='checkbox' v-model='choices' value='{$pack->ID}' > {$pack->post_title} </label>";
45
+ $output .= '</li>';
46
 
47
  echo $output;
 
48
  }
49
  } else {
50
  _e( 'No subscription plan found.', 'wp-user-frontend' );
admin/form-builder/assets/js/components/form-recaptcha/template.php CHANGED
@@ -5,7 +5,7 @@
5
 
6
  <template v-else>
7
  <div v-if="'invisible_recaptcha' != field.recaptcha_type">
8
- <img class="wpuf-recaptcha-placeholder" src="<?php echo WPUF_ASSET_URI . '/images/recaptcha-placeholder.png' ?>" alt="">
9
  </div>
10
  <div v-else><p><?php _e( 'Invisible reCaptcha', 'wp-user-frontend' ); ?></p></div>
11
  </template>
5
 
6
  <template v-else>
7
  <div v-if="'invisible_recaptcha' != field.recaptcha_type">
8
+ <img class="wpuf-recaptcha-placeholder" src="<?php echo WPUF_ASSET_URI . '/images/recaptcha-placeholder.png'; ?>" alt="">
9
  </div>
10
  <div v-else><p><?php _e( 'Invisible reCaptcha', 'wp-user-frontend' ); ?></p></div>
11
  </template>
admin/form-builder/class-wpuf-admin-form-builder-ajax.php CHANGED
@@ -12,7 +12,7 @@ class WPUF_Admin_Form_Builder_Ajax {
12
  * @return void
13
  */
14
  public function __construct() {
15
- add_action( 'wp_ajax_wpuf_form_builder_save_form', array( $this, 'save_form' ) );
16
  }
17
 
18
  /**
@@ -23,9 +23,15 @@ class WPUF_Admin_Form_Builder_Ajax {
23
  * @return void
24
  */
25
  public function save_form() {
26
- parse_str( $_POST['form_data'], $form_data );
27
 
28
- if ( ! wp_verify_nonce( $form_data['wpuf_form_builder_nonce'], 'wpuf_form_builder_save_form' ) ) {
 
 
 
 
 
 
29
  wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) );
30
  }
31
 
@@ -33,19 +39,20 @@ class WPUF_Admin_Form_Builder_Ajax {
33
  wp_send_json_error( __( 'Invalid form id', 'wp-user-frontend' ) );
34
  }
35
 
36
- $form_fields = isset( $_POST['form_fields'] ) ? $_POST['form_fields'] : '';
37
- $notifications = isset( $_POST['notifications'] ) ? $_POST['notifications'] : '';
38
- $settings = array();
39
- $integrations = array();
40
 
41
- if ( isset( $_POST['settings'] ) ) {
42
- $settings = (array) json_decode( wp_unslash( $_POST['settings'] ) );
 
43
  } else {
44
- $settings = isset( $form_data['wpuf_settings'] ) ? $form_data['wpuf_settings'] : array();
45
  }
46
 
47
- if ( isset( $_POST['integrations'] ) ) {
48
- $integrations = (array) json_decode( wp_unslash( $_POST['integrations'] ) );
49
  }
50
 
51
  $form_fields = wp_unslash( $form_fields );
@@ -54,21 +61,20 @@ class WPUF_Admin_Form_Builder_Ajax {
54
  $form_fields = json_decode( $form_fields, true );
55
  $notifications = json_decode( $notifications, true );
56
 
57
- $data = array(
58
  'form_id' => absint( $form_data['wpuf_form_id'] ),
59
  'post_title' => sanitize_text_field( $form_data['post_title'] ),
60
  'form_fields' => $form_fields,
61
  'form_settings' => $settings,
62
  'form_settings_key' => isset( $form_data['form_settings_key'] ) ? $form_data['form_settings_key'] : '',
63
  'notifications' => $notifications,
64
- 'integrations' => $integrations
65
- );
66
 
67
  $form_fields = WPUF_Admin_Form_Builder::save_form( $data );
68
 
69
- wp_send_json_success( array( 'form_fields' => $form_fields, 'form_settings' => $settings ) );
70
  }
71
-
72
  }
73
 
74
  new WPUF_Admin_Form_Builder_Ajax();
12
  * @return void
13
  */
14
  public function __construct() {
15
+ add_action( 'wp_ajax_wpuf_form_builder_save_form', [ $this, 'save_form' ] );
16
  }
17
 
18
  /**
23
  * @return void
24
  */
25
  public function save_form() {
26
+ $post_data = wp_unslash($_POST);
27
 
28
+ if ( isset( $post_data['form_data'] ) ) {
29
+ parse_str( wp_unslash( $post_data['form_data'] ), $form_data );
30
+ } else {
31
+ wp_send_json_error( __( 'form data is missing', 'wp-user-frontend'));
32
+ }
33
+
34
+ if ( !wp_verify_nonce( $form_data['wpuf_form_builder_nonce'], 'wpuf_form_builder_save_form' ) ) {
35
  wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) );
36
  }
37
 
39
  wp_send_json_error( __( 'Invalid form id', 'wp-user-frontend' ) );
40
  }
41
 
42
+ $form_fields = isset( $post_data['form_fields'] ) ? sanitize_text_field( wp_unslash( $post_data['form_fields'] ) ) : '';
43
+ $notifications = isset( $post_data['notifications'] ) ? sanitize_text_field( wp_unslash( $post_data['notifications'] ) ) : '';
44
+ $settings = [];
45
+ $integrations = [];
46
 
47
+ if ( isset( $post_data['settings'] ) ) {
48
+ $settings_data = array_map( 'sanitize_text_field', wp_unslash( $post_data['settings'] ) );
49
+ $settings = (array) json_decode( $settings_data );
50
  } else {
51
+ $settings = isset( $form_data['wpuf_settings'] ) ? $form_data['wpuf_settings'] : [];
52
  }
53
 
54
+ if ( isset( $post_data['integrations'] ) ) {
55
+ $integrations = (array) json_decode( sanitize_text_field( wp_unslash( $post_data['integrations'] ) ) );
56
  }
57
 
58
  $form_fields = wp_unslash( $form_fields );
61
  $form_fields = json_decode( $form_fields, true );
62
  $notifications = json_decode( $notifications, true );
63
 
64
+ $data = [
65
  'form_id' => absint( $form_data['wpuf_form_id'] ),
66
  'post_title' => sanitize_text_field( $form_data['post_title'] ),
67
  'form_fields' => $form_fields,
68
  'form_settings' => $settings,
69
  'form_settings_key' => isset( $form_data['form_settings_key'] ) ? $form_data['form_settings_key'] : '',
70
  'notifications' => $notifications,
71
+ 'integrations' => $integrations,
72
+ ];
73
 
74
  $form_fields = WPUF_Admin_Form_Builder::save_form( $data );
75
 
76
+ wp_send_json_success( [ 'form_fields' => $form_fields, 'form_settings' => $settings ] );
77
  }
 
78
  }
79
 
80
  new WPUF_Admin_Form_Builder_Ajax();
admin/form-builder/class-wpuf-admin-form-builder.php CHANGED
@@ -2,7 +2,6 @@
2
  /**
3
  * Form Builder framework
4
  */
5
-
6
  class WPUF_Admin_Form_Builder {
7
 
8
  /**
@@ -12,7 +11,7 @@ class WPUF_Admin_Form_Builder {
12
  *
13
  * @var string
14
  */
15
- private $settings = array();
16
 
17
  /**
18
  * Class contructor
@@ -24,13 +23,13 @@ class WPUF_Admin_Form_Builder {
24
  public function __construct( $settings ) {
25
  global $post;
26
 
27
- $defaults = array(
28
  'form_type' => '', // e.g 'post', 'profile' etc
29
  'post_type' => '', // e.g 'wpuf_forms', 'wpuf_profile' etc,
30
  'form_settings_key' => '',
31
  'post_id' => 0,
32
- 'shortcodes' => array() // [ [ 'name' => 'wpuf_form', 'type' => 'profile' ], [ 'name' => 'wpuf_form', 'type' => 'registration' ] ]
33
- );
34
 
35
  $this->settings = wp_parse_args( $settings, $defaults );
36
 
@@ -38,13 +37,13 @@ class WPUF_Admin_Form_Builder {
38
  $post = get_post( $this->settings['post_id'] );
39
 
40
  // if we have an existing post, then let's start
41
- if ( ! empty( $post->ID ) ) {
42
- add_action( 'in_admin_header', array( $this, 'remove_admin_notices' ) );
43
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
44
- add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ) );
45
- add_action( 'admin_footer', array( $this, 'custom_dequeue' ) );
46
- add_action( 'admin_footer', array( $this, 'admin_footer' ) );
47
- add_action( 'wpuf-admin-form-builder', array( $this, 'include_form_builder' ) );
48
  }
49
  }
50
 
@@ -75,19 +74,19 @@ class WPUF_Admin_Form_Builder {
75
  public function admin_enqueue_scripts() {
76
  global $post;
77
 
78
- /**
79
  * CSS
80
  */
81
  wp_enqueue_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
82
- wp_enqueue_style( 'wpuf-font-awesome', WPUF_ASSET_URI . '/vendor/font-awesome/css/font-awesome.min.css', array(), WPUF_VERSION );
83
- wp_enqueue_style( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.css', array(), WPUF_VERSION );
84
- wp_enqueue_style( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/css/selectize.default.css', array(), WPUF_VERSION );
85
- wp_enqueue_style( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr.min.css', array(), WPUF_VERSION );
86
- wp_enqueue_style( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip.css', array(), WPUF_VERSION );
87
 
88
- $form_builder_css_deps = apply_filters( 'wpuf-form-builder-css-deps', array(
89
- 'wpuf-css', 'wpuf-font-awesome', 'wpuf-sweetalert2', 'wpuf-selectize', 'wpuf-toastr', 'wpuf-tooltip'
90
- ) );
91
 
92
  wp_enqueue_style( 'wpuf-form-builder', WPUF_ASSET_URI . '/css/wpuf-form-builder.css', $form_builder_css_deps, WPUF_VERSION );
93
 
@@ -100,32 +99,32 @@ class WPUF_Admin_Form_Builder {
100
  */
101
  $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
102
 
103
- wp_enqueue_script( 'wpuf-vue', WPUF_ASSET_URI . '/vendor/vue/vue' . $prefix . '.js', array(), WPUF_VERSION, true );
104
- wp_enqueue_script( 'wpuf-vuex', WPUF_ASSET_URI . '/vendor/vuex/vuex' . $prefix . '.js', array( 'wpuf-vue' ), WPUF_VERSION, true );
105
- wp_enqueue_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', array(), WPUF_VERSION, true );
106
- wp_enqueue_script( 'wpuf-jquery-scrollTo', WPUF_ASSET_URI . '/vendor/jquery.scrollTo/jquery.scrollTo' . $prefix . '.js', array( 'jquery' ), WPUF_VERSION, true );
107
- wp_enqueue_script( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/js/standalone/selectize' . $prefix . '.js', array( 'jquery' ), WPUF_VERSION, true );
108
- wp_enqueue_script( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr' . $prefix . '.js', array(), WPUF_VERSION, true );
109
- wp_enqueue_script( 'wpuf-clipboard', WPUF_ASSET_URI . '/vendor/clipboard/clipboard' . $prefix . '.js', array(), WPUF_VERSION, true );
110
- wp_enqueue_script( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip' . $prefix . '.js', array(), WPUF_VERSION, true );
111
 
112
- $form_builder_js_deps = apply_filters( 'wpuf-form-builder-js-deps', array(
113
  'jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-resizable', 'underscore',
114
  'wpuf-vue', 'wpuf-vuex', 'wpuf-sweetalert2', 'wpuf-jquery-scrollTo',
115
- 'wpuf-selectize', 'wpuf-toastr', 'wpuf-clipboard', 'wpuf-tooltip'
116
- ) );
117
 
118
  wp_enqueue_script( 'wpuf-form-builder-mixins', WPUF_ASSET_URI . '/js/wpuf-form-builder-mixins.js', $form_builder_js_deps, WPUF_VERSION, true );
119
 
120
  do_action( 'wpuf-form-builder-enqueue-after-mixins' );
121
 
122
- wp_enqueue_script( 'wpuf-form-builder-components', WPUF_ASSET_URI . '/js/wpuf-form-builder-components.js', array( 'wpuf-form-builder-mixins' ), WPUF_VERSION, true );
123
 
124
  do_action( 'wpuf-form-builder-enqueue-after-components' );
125
 
126
- wp_enqueue_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', array( 'jquery-ui-datepicker' ) );
127
 
128
- wp_enqueue_script( 'wpuf-form-builder', WPUF_ASSET_URI . '/js/wpuf-form-builder.js', array( 'wpuf-form-builder-components' ), WPUF_VERSION, true );
129
 
130
  do_action( 'wpuf-form-builder-enqueue-after-main-instance' );
131
 
@@ -135,7 +134,7 @@ class WPUF_Admin_Form_Builder {
135
  require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-form-builder-field-settings.php';
136
  require_once WPUF_ROOT . '/includes/free/prompt.php';
137
 
138
- $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', array(
139
  'i18n' => $this->i18n(),
140
  'post' => $post,
141
  'form_fields' => wpuf_get_form_fields( $post->ID ),
@@ -144,20 +143,20 @@ class WPUF_Admin_Form_Builder {
144
  'form_settings' => wpuf_get_form_settings( $post->ID ),
145
  'notifications' => wpuf_get_form_notifications( $post->ID ),
146
  'pro_link' => WPUF_Pro_Prompt::get_pro_url(),
147
- 'site_url' => site_url('/'),
148
  'recaptcha_site' => wpuf_get_option( 'recaptcha_public', 'wpuf_general' ),
149
  'recaptcha_secret' => wpuf_get_option( 'recaptcha_private', 'wpuf_general' ),
150
- ) );
151
 
152
  wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
153
 
154
  // mixins
155
- $wpuf_mixins = array(
156
- 'root' => apply_filters( 'wpuf-form-builder-js-root-mixins', array() ),
157
- 'builder_stage' => apply_filters( 'wpuf-form-builder-js-builder-stage-mixins', array() ),
158
- 'form_fields' => apply_filters( 'wpuf-form-builder-js-form-fields-mixins', array() ),
159
- 'field_options' => apply_filters( 'wpuf-form-builder-js-field-options-mixins', array() ),
160
- );
161
 
162
  wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
163
  }
@@ -212,7 +211,6 @@ class WPUF_Admin_Form_Builder {
212
  do_action( 'wpuf-form-builder-add-js-templates' );
213
  }
214
 
215
-
216
  /**
217
  * Dequeue style and script to avoid conflict with Imagify Image Optimizer plugin
218
  *
@@ -244,7 +242,7 @@ class WPUF_Admin_Form_Builder {
244
  $form_settings_key = $this->settings['form_settings_key'];
245
  $shortcodes = $this->settings['shortcodes'];
246
 
247
- $forms = get_posts( array( 'post_type' => $post_type, 'post_status' => 'any' ) );
248
 
249
  include WPUF_ROOT . '/admin/form-builder/views/form-builder.php';
250
  }
@@ -257,7 +255,7 @@ class WPUF_Admin_Form_Builder {
257
  * @return array
258
  */
259
  private function i18n() {
260
- return apply_filters( 'wpuf-form-builder-i18n', array(
261
  'advanced_options' => __( 'Advanced Options', 'wp-user-frontend' ),
262
  'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'wp-user-frontend' ),
263
  'yes_delete_it' => __( 'Yes, delete it', 'wp-user-frontend' ),
@@ -276,7 +274,7 @@ class WPUF_Admin_Form_Builder {
276
  'saved_form_data' => __( 'Saved form data', 'wp-user-frontend' ),
277
  'unsaved_changes' => __( 'You have unsaved changes.', 'wp-user-frontend' ),
278
  'copy_shortcode' => __( 'Click to copy shortcode', 'wp-user-frontend' ),
279
- ) );
280
  }
281
 
282
  /**
@@ -286,34 +284,32 @@ class WPUF_Admin_Form_Builder {
286
  *
287
  * @param array $data Contains form_fields, form_settings, form_settings_key data
288
  *
289
- * @return boolean
290
  */
291
  public static function save_form( $data ) {
292
- $saved_wpuf_inputs = array();
293
 
294
- wp_update_post( array( 'ID' => $data['form_id'], 'post_status' => 'publish', 'post_title' => $data['post_title'] ) );
295
 
296
- $existing_wpuf_input_ids = get_children( array(
297
  'post_parent' => $data['form_id'],
298
  'post_status' => 'publish',
299
  'post_type' => 'wpuf_input',
300
  'numberposts' => '-1',
301
  'orderby' => 'menu_order',
302
  'order' => 'ASC',
303
- 'fields' => 'ids'
304
- ) );
305
 
306
- $new_wpuf_input_ids = array();
307
-
308
- if ( ! empty( $data['form_fields'] ) ) {
309
 
 
310
  foreach ( $data['form_fields'] as $order => $field ) {
311
- if ( ! empty( $field['is_new'] ) ) {
312
  unset( $field['is_new'] );
313
  unset( $field['id'] );
314
 
315
  $field_id = 0;
316
-
317
  } else {
318
  $field_id = $field['id'];
319
  }
@@ -326,14 +322,13 @@ class WPUF_Admin_Form_Builder {
326
 
327
  $saved_wpuf_inputs[] = $field;
328
  }
329
-
330
  }
331
 
332
  $inputs_to_delete = array_diff( $existing_wpuf_input_ids, $new_wpuf_input_ids );
333
 
334
- if ( ! empty( $inputs_to_delete ) ) {
335
  foreach ( $inputs_to_delete as $delete_id ) {
336
- wp_delete_post( $delete_id , true );
337
  }
338
  }
339
 
2
  /**
3
  * Form Builder framework
4
  */
 
5
  class WPUF_Admin_Form_Builder {
6
 
7
  /**
11
  *
12
  * @var string
13
  */
14
+ private $settings = [];
15
 
16
  /**
17
  * Class contructor
23
  public function __construct( $settings ) {
24
  global $post;
25
 
26
+ $defaults = [
27
  'form_type' => '', // e.g 'post', 'profile' etc
28
  'post_type' => '', // e.g 'wpuf_forms', 'wpuf_profile' etc,
29
  'form_settings_key' => '',
30
  'post_id' => 0,
31
+ 'shortcodes' => [], // [ [ 'name' => 'wpuf_form', 'type' => 'profile' ], [ 'name' => 'wpuf_form', 'type' => 'registration' ] ]
32
+ ];
33
 
34
  $this->settings = wp_parse_args( $settings, $defaults );
35
 
37
  $post = get_post( $this->settings['post_id'] );
38
 
39
  // if we have an existing post, then let's start
40
+ if ( !empty( $post->ID ) ) {
41
+ add_action( 'in_admin_header', [ $this, 'remove_admin_notices' ] );
42
+ add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
43
+ add_action( 'admin_print_scripts', [ $this, 'admin_print_scripts' ] );
44
+ add_action( 'admin_footer', [ $this, 'custom_dequeue' ] );
45
+ add_action( 'admin_footer', [ $this, 'admin_footer' ] );
46
+ add_action( 'wpuf-admin-form-builder', [ $this, 'include_form_builder' ] );
47
  }
48
  }
49
 
74
  public function admin_enqueue_scripts() {
75
  global $post;
76
 
77
+ /*
78
  * CSS
79
  */
80
  wp_enqueue_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
81
+ wp_enqueue_style( 'wpuf-font-awesome', WPUF_ASSET_URI . '/vendor/font-awesome/css/font-awesome.min.css', [], WPUF_VERSION );
82
+ wp_enqueue_style( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.css', [], WPUF_VERSION );
83
+ wp_enqueue_style( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/css/selectize.default.css', [], WPUF_VERSION );
84
+ wp_enqueue_style( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr.min.css', [], WPUF_VERSION );
85
+ wp_enqueue_style( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip.css', [], WPUF_VERSION );
86
 
87
+ $form_builder_css_deps = apply_filters( 'wpuf-form-builder-css-deps', [
88
+ 'wpuf-css', 'wpuf-font-awesome', 'wpuf-sweetalert2', 'wpuf-selectize', 'wpuf-toastr', 'wpuf-tooltip',
89
+ ] );
90
 
91
  wp_enqueue_style( 'wpuf-form-builder', WPUF_ASSET_URI . '/css/wpuf-form-builder.css', $form_builder_css_deps, WPUF_VERSION );
92
 
99
  */
100
  $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
101
 
102
+ wp_enqueue_script( 'wpuf-vue', WPUF_ASSET_URI . '/vendor/vue/vue' . $prefix . '.js', [], WPUF_VERSION, true );
103
+ wp_enqueue_script( 'wpuf-vuex', WPUF_ASSET_URI . '/vendor/vuex/vuex' . $prefix . '.js', [ 'wpuf-vue' ], WPUF_VERSION, true );
104
+ wp_enqueue_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', [], WPUF_VERSION, true );
105
+ wp_enqueue_script( 'wpuf-jquery-scrollTo', WPUF_ASSET_URI . '/vendor/jquery.scrollTo/jquery.scrollTo' . $prefix . '.js', [ 'jquery' ], WPUF_VERSION, true );
106
+ wp_enqueue_script( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/js/standalone/selectize' . $prefix . '.js', [ 'jquery' ], WPUF_VERSION, true );
107
+ wp_enqueue_script( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr' . $prefix . '.js', [], WPUF_VERSION, true );
108
+ wp_enqueue_script( 'wpuf-clipboard', WPUF_ASSET_URI . '/vendor/clipboard/clipboard' . $prefix . '.js', [], WPUF_VERSION, true );
109
+ wp_enqueue_script( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip' . $prefix . '.js', [], WPUF_VERSION, true );
110
 
111
+ $form_builder_js_deps = apply_filters( 'wpuf-form-builder-js-deps', [
112
  'jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-resizable', 'underscore',
113
  'wpuf-vue', 'wpuf-vuex', 'wpuf-sweetalert2', 'wpuf-jquery-scrollTo',
114
+ 'wpuf-selectize', 'wpuf-toastr', 'wpuf-clipboard', 'wpuf-tooltip',
115
+ ] );
116
 
117
  wp_enqueue_script( 'wpuf-form-builder-mixins', WPUF_ASSET_URI . '/js/wpuf-form-builder-mixins.js', $form_builder_js_deps, WPUF_VERSION, true );
118
 
119
  do_action( 'wpuf-form-builder-enqueue-after-mixins' );
120
 
121
+ wp_enqueue_script( 'wpuf-form-builder-components', WPUF_ASSET_URI . '/js/wpuf-form-builder-components.js', [ 'wpuf-form-builder-mixins' ], WPUF_VERSION, true );
122
 
123
  do_action( 'wpuf-form-builder-enqueue-after-components' );
124
 
125
+ wp_enqueue_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', [ 'jquery-ui-datepicker' ] );
126
 
127
+ wp_enqueue_script( 'wpuf-form-builder', WPUF_ASSET_URI . '/js/wpuf-form-builder.js', [ 'wpuf-form-builder-components' ], WPUF_VERSION, true );
128
 
129
  do_action( 'wpuf-form-builder-enqueue-after-main-instance' );
130
 
134
  require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-form-builder-field-settings.php';
135
  require_once WPUF_ROOT . '/includes/free/prompt.php';
136
 
137
+ $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', [
138
  'i18n' => $this->i18n(),
139
  'post' => $post,
140
  'form_fields' => wpuf_get_form_fields( $post->ID ),
143
  'form_settings' => wpuf_get_form_settings( $post->ID ),
144
  'notifications' => wpuf_get_form_notifications( $post->ID ),
145
  'pro_link' => WPUF_Pro_Prompt::get_pro_url(),
146
+ 'site_url' => site_url( '/' ),
147
  'recaptcha_site' => wpuf_get_option( 'recaptcha_public', 'wpuf_general' ),
148
  'recaptcha_secret' => wpuf_get_option( 'recaptcha_private', 'wpuf_general' ),
149
+ ] );
150
 
151
  wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
152
 
153
  // mixins
154
+ $wpuf_mixins = [
155
+ 'root' => apply_filters( 'wpuf-form-builder-js-root-mixins', [] ),
156
+ 'builder_stage' => apply_filters( 'wpuf-form-builder-js-builder-stage-mixins', [] ),
157
+ 'form_fields' => apply_filters( 'wpuf-form-builder-js-form-fields-mixins', [] ),
158
+ 'field_options' => apply_filters( 'wpuf-form-builder-js-field-options-mixins', [] ),
159
+ ];
160
 
161
  wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
162
  }
211
  do_action( 'wpuf-form-builder-add-js-templates' );
212
  }
213
 
 
214
  /**
215
  * Dequeue style and script to avoid conflict with Imagify Image Optimizer plugin
216
  *
242
  $form_settings_key = $this->settings['form_settings_key'];
243
  $shortcodes = $this->settings['shortcodes'];
244
 
245
+ $forms = get_posts( [ 'post_type' => $post_type, 'post_status' => 'any' ] );
246
 
247
  include WPUF_ROOT . '/admin/form-builder/views/form-builder.php';
248
  }
255
  * @return array
256
  */
257
  private function i18n() {
258
+ return apply_filters( 'wpuf-form-builder-i18n', [
259
  'advanced_options' => __( 'Advanced Options', 'wp-user-frontend' ),
260
  'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'wp-user-frontend' ),
261
  'yes_delete_it' => __( 'Yes, delete it', 'wp-user-frontend' ),
274
  'saved_form_data' => __( 'Saved form data', 'wp-user-frontend' ),
275
  'unsaved_changes' => __( 'You have unsaved changes.', 'wp-user-frontend' ),
276
  'copy_shortcode' => __( 'Click to copy shortcode', 'wp-user-frontend' ),
277
+ ] );
278
  }
279
 
280
  /**
284
  *
285
  * @param array $data Contains form_fields, form_settings, form_settings_key data
286
  *
287
+ * @return bool
288
  */
289
  public static function save_form( $data ) {
290
+ $saved_wpuf_inputs = [];
291
 
292
+ wp_update_post( [ 'ID' => $data['form_id'], 'post_status' => 'publish', 'post_title' => $data['post_title'] ] );
293
 
294
+ $existing_wpuf_input_ids = get_children( [
295
  'post_parent' => $data['form_id'],
296
  'post_status' => 'publish',
297
  'post_type' => 'wpuf_input',
298
  'numberposts' => '-1',
299
  'orderby' => 'menu_order',
300
  'order' => 'ASC',
301
+ 'fields' => 'ids',
302
+ ] );
303
 
304
+ $new_wpuf_input_ids = [];
 
 
305
 
306
+ if ( !empty( $data['form_fields'] ) ) {
307
  foreach ( $data['form_fields'] as $order => $field ) {
308
+ if ( !empty( $field['is_new'] ) ) {
309
  unset( $field['is_new'] );
310
  unset( $field['id'] );
311
 
312
  $field_id = 0;
 
313
  } else {
314
  $field_id = $field['id'];
315
  }
322
 
323
  $saved_wpuf_inputs[] = $field;
324
  }
 
325
  }
326
 
327
  $inputs_to_delete = array_diff( $existing_wpuf_input_ids, $new_wpuf_input_ids );
328
 
329
+ if ( !empty( $inputs_to_delete ) ) {
330
  foreach ( $inputs_to_delete as $delete_id ) {
331
+ wp_delete_post( $delete_id, true );
332
  }
333
  }
334
 
admin/form-builder/class-wpuf-form-builder-field-settings.php CHANGED
@@ -12,8 +12,6 @@ class WPUF_Form_Builder_Field_Settings {
12
  * @return array
13
  */
14
  public static function get_field_settings() {
15
-
16
- return array();
17
  }
18
-
19
  }
12
  * @return array
13
  */
14
  public static function get_field_settings() {
15
+ return [];
 
16
  }
 
17
  }
admin/form-builder/views/form-builder.php CHANGED
@@ -1,29 +1,29 @@
1
- <form id="wpuf-form-builder" class="wpuf-form-builder-<?php echo $form_type; ?>" method="post" action="" @submit.prevent="save_form_builder" v-cloak>
2
  <fieldset :class="[is_form_saving ? 'disabled' : '']" :disabled="is_form_saving">
3
  <h2 class="nav-tab-wrapper">
4
  <a href="#wpuf-form-builder-container" class="nav-tab nav-tab-active">
5
- <?php _e( 'Form Editor', 'wp-user-frontend' ); ?>
6
  </a>
7
 
8
  <a href="#wpuf-form-builder-settings" class="nav-tab">
9
- <?php _e( 'Settings', 'wp-user-frontend' ); ?>
10
  </a>
11
 
12
  <?php do_action( "wpuf-form-builder-tabs-{$form_type}" ); ?>
13
 
14
  <span class="pull-right">
15
- <a :href="'<?php echo site_url( '/' ); ?>?wpuf_preview=1&form_id=' + post.ID" target="_blank" class="button"><span class="dashicons dashicons-visibility" style="padding-top: 3px;"></span> <?php _e( 'Preview', 'wp-user-frontend' ); ?></a>
16
 
17
  <button v-if="!is_form_saving" type="button" class="button button-primary" @click="save_form_builder">
18
- <?php _e( 'Save Form', 'wp-user-frontend' ); ?>
19
  </button>
20
 
21
  <button v-else type="button" class="button button-primary button-ajax-working" disabled>
22
- <span class="loader"></span> <?php _e( 'Saving Form Data', 'wp-user-frontend' ); ?>
23
  </button>
24
  </span>
25
- <span id="wpuf-toggle-field-options"><?php _e( 'Add Fields', 'wp-user-frontend' ); ?></span>
26
- <span id="wpuf-toggle-show-form"><?php _e( 'Show Form', 'wp-user-frontend' ); ?></span>
27
  </h2>
28
 
29
  <div class="tab-contents">
@@ -39,14 +39,14 @@
39
 
40
  <i :class="(is_form_switcher ? 'fa fa-angle-up' : 'fa fa-angle-down') + ' form-switcher-arrow'" @click.prevent="switch_form"></i>
41
  <?php
42
- $form_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
43
 
44
  if ( count( $shortcodes ) > 1 && isset( $shortcodes[0]['type'] ) ) {
45
  foreach ( $shortcodes as $shortcode ) {
46
- printf( "<span class=\"form-id\" title=\"%s\" data-clipboard-text='%s'><i class=\"fa fa-clipboard\" aria-hidden=\"true\"></i> %s: #{{ post.ID }}</span>", sprintf( __( 'Click to copy %s shortcode', 'wp-user-frontend' ), $shortcode['type'] ), sprintf( '[%s type="%s" id="%s"]', $shortcode['name'], $shortcode['type'], $form_id ), ucwords( $shortcode['type'] ), $shortcode['type'] );
47
  }
48
  } else {
49
- printf( "<span class=\"form-id\" title=\"%s\" data-clipboard-text='%s'><i class=\"fa fa-clipboard\" aria-hidden=\"true\"></i> #{{ post.ID }}</span>", __( 'Click to copy shortcode', 'wp-user-frontend' ), '[' . $shortcodes[0]['name'] . ' id="' . $form_id . '"]' );
50
  }
51
  ?>
52
  </header>
@@ -54,8 +54,8 @@
54
  <ul v-if="is_form_switcher" class="form-switcher-content">
55
  <?php
56
  foreach ( $forms as $form ) {
57
- ?>
58
- <li><a class="<?php echo ( $form->ID == $_GET['id'] ) ? 'active' : ''; ?>" href="<?php echo admin_url( 'admin.php?page=wpuf-' . $form_type . '-forms&action=edit&id=' . $form->ID ); ?>"><?php echo $form->post_title; ?></a></li>
59
  <?php
60
  }
61
  ?>
@@ -73,13 +73,13 @@
73
  <ul class="clearfix">
74
  <li :class="['form-fields' === current_panel ? 'active' : '']">
75
  <a href="#add-fields" @click.prevent="set_current_panel('form-fields')">
76
- <?php _e( 'Add Fields', 'wp-user-frontend' ); ?>
77
  </a>
78
  </li>
79
 
80
  <li :class="['field-options' === current_panel ? 'active' : '', !form_fields_count ? 'disabled' : '']">
81
  <a href="#field-options" @click.prevent="set_current_panel('field-options')">
82
- <?php _e( 'Field Options', 'wp-user-frontend' ); ?>
83
  </a>
84
  </li>
85
  </ul>
@@ -108,12 +108,12 @@
108
  <?php do_action( "wpuf-form-builder-tab-contents-{$form_type}" ); ?>
109
  </div>
110
 
111
- <?php if ( ! empty( $form_settings_key ) ): ?>
112
- <input type="hidden" name="form_settings_key" value="<?php echo $form_settings_key; ?>">
113
- <?php endif; ?>
114
 
115
  <?php wp_nonce_field( 'wpuf_form_builder_save_form', 'wpuf_form_builder_nonce' ); ?>
116
 
117
- <input type="hidden" name="wpuf_form_id" value="<?php echo $form_id; ?>">
118
  </fieldset>
119
  </form><!-- #wpuf-form-builder -->
1
+ <form id="wpuf-form-builder" class="wpuf-form-builder-<?php echo esc_attr( $form_type ); ?>" method="post" action="" @submit.prevent="save_form_builder" v-cloak>
2
  <fieldset :class="[is_form_saving ? 'disabled' : '']" :disabled="is_form_saving">
3
  <h2 class="nav-tab-wrapper">
4
  <a href="#wpuf-form-builder-container" class="nav-tab nav-tab-active">
5
+ <?php esc_html_e( 'Form Editor', 'wp-user-frontend' ); ?>
6
  </a>
7
 
8
  <a href="#wpuf-form-builder-settings" class="nav-tab">
9
+ <?php esc_html_e( 'Settings', 'wp-user-frontend' ); ?>
10
  </a>
11
 
12
  <?php do_action( "wpuf-form-builder-tabs-{$form_type}" ); ?>
13
 
14
  <span class="pull-right">
15
+ <a :href="'<?php echo esc_url( site_url( '/' ) ); ?>?wpuf_preview=1&form_id=' + post.ID" target="_blank" class="button"><span class="dashicons dashicons-visibility" style="padding-top: 3px;"></span> <?php esc_html_e( 'Preview', 'wp-user-frontend' ); ?></a>
16
 
17
  <button v-if="!is_form_saving" type="button" class="button button-primary" @click="save_form_builder">
18
+ <?php esc_html_e( 'Save Form', 'wp-user-frontend' ); ?>
19
  </button>
20
 
21
  <button v-else type="button" class="button button-primary button-ajax-working" disabled>
22
+ <span class="loader"></span> <?php esc_html_e( 'Saving Form Data', 'wp-user-frontend' ); ?>
23
  </button>
24
  </span>
25
+ <span id="wpuf-toggle-field-options"><?php esc_html_e( 'Add Fields', 'wp-user-frontend' ); ?></span>
26
+ <span id="wpuf-toggle-show-form"><?php esc_html_e( 'Show Form', 'wp-user-frontend' ); ?></span>
27
  </h2>
28
 
29
  <div class="tab-contents">
39
 
40
  <i :class="(is_form_switcher ? 'fa fa-angle-up' : 'fa fa-angle-down') + ' form-switcher-arrow'" @click.prevent="switch_form"></i>
41
  <?php
42
+ $form_id = isset( $_GET['id'] ) ? intval( wp_unslash( $_GET['id'] ) ) : 0;
43
 
44
  if ( count( $shortcodes ) > 1 && isset( $shortcodes[0]['type'] ) ) {
45
  foreach ( $shortcodes as $shortcode ) {
46
+ printf( "<span class=\"form-id\" title=\"%s\" data-clipboard-text='%s'><i class=\"fa fa-clipboard\" aria-hidden=\"true\"></i> %s: #{{ post.ID }}</span>", sprintf( esc_html( __( 'Click to copy %s shortcode', 'wp-user-frontend' ) ), esc_attr( $shortcode['type'] ) ), sprintf( '[%s type="%s" id="%s"]', esc_attr( $shortcode['name'] ), esc_attr( $shortcode['type'] ), esc_attr( $form_id ) ), esc_attr( ucwords( $shortcode['type'] ) ), esc_attr( $shortcode['type'] ) );
47
  }
48
  } else {
49
+ printf( "<span class=\"form-id\" title=\"%s\" data-clipboard-text='%s'><i class=\"fa fa-clipboard\" aria-hidden=\"true\"></i> #{{ post.ID }}</span>", esc_html( __( 'Click to copy shortcode', 'wp-user-frontend' ) ), '[' . esc_attr( $shortcodes[0]['name'] ) . ' id="' . esc_attr( $form_id ) . '"]' );
50
  }
51
  ?>
52
  </header>
54
  <ul v-if="is_form_switcher" class="form-switcher-content">
55
  <?php
56
  foreach ( $forms as $form ) {
57
+ ?>
58
+ <li><a class="<?php echo ( $form->ID == $_GET['id'] ) ? 'active' : ''; ?>" href="<?php echo esc_url( admin_url( 'admin.php?page=wpuf-' . $form_type . '-forms&action=edit&id=' . $form->ID ) ); ?>"><?php echo esc_html( $form->post_title ); ?></a></li>
59
  <?php
60
  }
61
  ?>
73
  <ul class="clearfix">
74
  <li :class="['form-fields' === current_panel ? 'active' : '']">
75
  <a href="#add-fields" @click.prevent="set_current_panel('form-fields')">
76
+ <?php esc_html_e( 'Add Fields', 'wp-user-frontend' ); ?>
77
  </a>
78
  </li>
79
 
80
  <li :class="['field-options' === current_panel ? 'active' : '', !form_fields_count ? 'disabled' : '']">
81
  <a href="#field-options" @click.prevent="set_current_panel('field-options')">
82
+ <?php esc_html_e( 'Field Options', 'wp-user-frontend' ); ?>
83
  </a>
84
  </li>
85
  </ul>
108
  <?php do_action( "wpuf-form-builder-tab-contents-{$form_type}" ); ?>
109
  </div>
110
 
111
+ <?php if ( !empty( $form_settings_key ) ) { ?>
112
+ <input type="hidden" name="form_settings_key" value="<?php echo esc_attr( $form_settings_key ); ?>">
113
+ <?php } ?>
114
 
115
  <?php wp_nonce_field( 'wpuf_form_builder_save_form', 'wpuf_form_builder_nonce' ); ?>
116
 
117
+ <input type="hidden" name="wpuf_form_id" value="<?php echo esc_attr( $form_id ); ?>">
118
  </fieldset>
119
  </form><!-- #wpuf-form-builder -->
admin/form-handler.php CHANGED
@@ -1,12 +1,13 @@
1
  <?php
 
2
  class WPUF_Admin_Form_Handler {
3
 
4
  public function __construct() {
5
  // post forms list table
6
- add_action( "load-user-frontend_page_wpuf-post-forms", array( $this, 'post_forms_actions' ) );
7
- add_action( "load-user-frontend_page_wpuf-profile-forms", array( $this, 'profile_forms_actions' ) );
8
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
9
- add_action( 'removable_query_args', array( $this, 'removable_query_args' ) );
10
  }
11
 
12
  /**
@@ -14,14 +15,13 @@ class WPUF_Admin_Form_Handler {
14
  *
15
  * @since 2.5
16
  *
17
- * @param integer $page_id
18
- * @param integer $bulk_action
19
  *
20
- * @return boolean
21
  */
22
  public function verify_current_page_screen( $page_id, $bulk_action ) {
23
-
24
- if ( ! isset( $_GET['_wpnonce'] ) || ! isset( $_GET['page'] ) ) {
25
  return false;
26
  }
27
 
@@ -29,7 +29,9 @@ class WPUF_Admin_Form_Handler {
29
  return false;
30
  }
31
 
32
- if ( ! wp_verify_nonce( $_GET['_wpnonce'], $bulk_action ) ) {
 
 
33
  return false;
34
  }
35
 
@@ -45,46 +47,45 @@ class WPUF_Admin_Form_Handler {
45
  */
46
  public function post_forms_actions() {
47
  // Nonce validation
48
- if ( ! $this->verify_current_page_screen( 'wpuf-post-forms', 'bulk-post-forms' ) ) {
49
  return;
50
  }
51
 
52
  // Check permission if not wpuf admin then go out from here
53
- if ( ! current_user_can( wpuf_admin_role() ) ) {
54
- wp_die( __( 'You do not have sufficient permissions to do this action', 'wp-user-frontend' ) );
55
  }
56
 
57
-
58
  $post_forms = new WPUF_Admin_Post_Forms_List_Table();
59
- $action = $post_forms->current_action();
60
 
61
  if ( $action ) {
62
-
63
- $remove_query_args = array(
64
  '_wp_http_referer', '_wpnonce', 'action', 'id', 'post', 'action2',
65
- );
66
 
67
- $add_query_args = array();
68
 
69
  switch ( $action ) {
70
  case 'post_form_search':
71
- $redirect = remove_query_arg( array( 'post_form_search' ), $redirect );
72
 
73
  break;
74
 
75
- case 'trash' :
76
 
77
- if ( ! empty( $_GET['id'] ) ) {
78
- delete_post_meta( $_GET['id'], '_wp_trash_meta_status' );
79
- delete_post_meta( $_GET['id'], '_wp_trash_meta_time' );
80
- delete_post_meta( $_GET['id'], '_wp_desired_post_slug' );
 
81
 
82
- wp_trash_post( $_GET['id'] );
83
 
84
  $add_query_args['trashed'] = 1;
85
-
86
- } else if ( ! empty( $_GET['post'] ) ) {
87
- foreach ( $_GET['post'] as $post_id ) {
88
  delete_post_meta( $post_id, '_wp_trash_meta_status' );
89
  delete_post_meta( $post_id, '_wp_trash_meta_time' );
90
  delete_post_meta( $post_id, '_wp_desired_post_slug' );
@@ -97,49 +98,54 @@ class WPUF_Admin_Form_Handler {
97
 
98
  break;
99
 
100
- case 'restore' :
101
  if ( !empty( $_GET['id'] ) ) {
102
- $trash_meta_status = get_post_meta( $_GET['id'], '_wp_trash_meta_status', true );
 
103
 
104
- $args = array(
105
- 'ID' => $_GET['id'],
106
  'post_status' => $trash_meta_status,
107
- );
108
 
109
  wp_update_post( $args );
110
 
111
  $add_query_args['untrashed'] = 1;
 
 
 
112
 
113
- } else if ( ! empty( $_GET['post'] ) ) {
114
- foreach ( $_GET['post'] as $post_id ) {
115
  $trash_meta_status = get_post_meta( $post_id, '_wp_trash_meta_status', true );
116
 
117
- $args = array(
118
  'ID' => $post_id,
119
  'post_status' => $trash_meta_status,
120
- );
121
 
122
  wp_update_post( $args );
123
 
124
- $add_query_args['untrashed'] = count( $_GET['post'] );
125
  }
126
  }
127
 
128
  break;
129
 
130
- case 'delete' :
131
 
132
- if ( ! empty( $_GET['id'] ) ) {
133
- wp_delete_post( $_GET['id'] );
134
 
135
- $add_query_args['deleted'] = 1;
 
136
 
137
- } else if ( ! empty( $_GET['post'] ) ) {
138
- foreach ( $_GET['post'] as $post_id ) {
 
 
139
  wp_delete_post( $post_id );
140
  }
141
 
142
- $add_query_args['deleted'] = count( $_GET['post'] );
143
  }
144
 
145
  $add_query_args['post_status'] = 'trash';
@@ -147,14 +153,16 @@ class WPUF_Admin_Form_Handler {
147
  break;
148
 
149
  case 'duplicate':
150
- if ( ! empty( $_GET['id'] ) ) {
151
- $add_query_args['duplicated'] = wpuf_duplicate_form( $_GET['id'] );
 
152
  }
153
 
154
  break;
155
  }
156
 
157
- $redirect = remove_query_arg( $remove_query_args, wp_unslash( $_SERVER['REQUEST_URI'] ) );
 
158
 
159
  $redirect = add_query_arg( $add_query_args, $redirect );
160
 
@@ -172,46 +180,46 @@ class WPUF_Admin_Form_Handler {
172
  */
173
  public function profile_forms_actions() {
174
  // Nonce validation
175
- if ( ! $this->verify_current_page_screen( 'wpuf-profile-forms', 'bulk-profile-forms' ) ) {
176
  return;
177
  }
178
 
179
  // Check permission if not wpuf admin then go out from here
180
- if ( ! current_user_can( wpuf_admin_role() ) ) {
181
- wp_die( __( 'You do not have sufficient permissions to do this action', 'wp-user-frontend' ) );
182
  }
183
 
184
-
185
  $profile_forms = new WPUF_Admin_Profile_Forms_List_Table();
186
- $action = $profile_forms->current_action();
187
 
188
  if ( $action ) {
189
-
190
- $remove_query_args = array(
191
  '_wp_http_referer', '_wpnonce', 'action', 'id', 'post', 'action2',
192
- );
193
 
194
- $add_query_args = array();
195
 
196
  switch ( $action ) {
197
  case 'profile_form_search':
198
- $redirect = remove_query_arg( array( 'profile_form_search' ), $redirect );
199
 
200
  break;
201
 
202
- case 'trash' :
203
 
204
- if ( ! empty( $_GET['id'] ) ) {
205
- delete_post_meta( $_GET['id'], '_wp_trash_meta_status' );
206
- delete_post_meta( $_GET['id'], '_wp_trash_meta_time' );
207
- delete_post_meta( $_GET['id'], '_wp_desired_post_slug' );
 
208
 
209
- wp_trash_post( $_GET['id'] );
210
 
211
  $add_query_args['trashed'] = 1;
 
 
212
 
213
- } else if ( ! empty( $_GET['post'] ) ) {
214
- foreach ( $_GET['post'] as $post_id ) {
215
  delete_post_meta( $post_id, '_wp_trash_meta_status' );
216
  delete_post_meta( $post_id, '_wp_trash_meta_time' );
217
  delete_post_meta( $post_id, '_wp_desired_post_slug' );
@@ -224,27 +232,29 @@ class WPUF_Admin_Form_Handler {
224
 
225
  break;
226
 
227
- case 'restore' :
228
  if ( !empty( $_GET['id'] ) ) {
229
- $trash_meta_status = get_post_meta( $_GET['id'], '_wp_trash_meta_status', true );
 
230
 
231
- $args = array(
232
- 'ID' => $_GET['id'],
233
  'post_status' => $trash_meta_status,
234
- );
235
 
236
  wp_update_post( $args );
237
 
238
  $add_query_args['untrashed'] = 1;
 
 
239
 
240
- } else if ( ! empty( $_GET['post'] ) ) {
241
- foreach ( $_GET['post'] as $post_id ) {
242
  $trash_meta_status = get_post_meta( $post_id, '_wp_trash_meta_status', true );
243
 
244
- $args = array(
245
  'ID' => $post_id,
246
  'post_status' => $trash_meta_status,
247
- );
248
 
249
  wp_update_post( $args );
250
 
@@ -254,19 +264,22 @@ class WPUF_Admin_Form_Handler {
254
 
255
  break;
256
 
257
- case 'delete' :
258
 
259
- if ( ! empty( $_GET['id'] ) ) {
260
- wp_delete_post( $_GET['id'] );
 
 
261
 
262
  $add_query_args['deleted'] = 1;
 
 
263
 
264
- } else if ( ! empty( $_GET['post'] ) ) {
265
- foreach ( $_GET['post'] as $post_id ) {
266
  wp_delete_post( $post_id );
267
  }
268
 
269
- $add_query_args['deleted'] = count( $_GET['post'] );
270
  }
271
 
272
  $add_query_args['post_status'] = 'trash';
@@ -274,14 +287,17 @@ class WPUF_Admin_Form_Handler {
274
  break;
275
 
276
  case 'duplicate':
277
- if ( ! empty( $_GET['id'] ) ) {
278
- $add_query_args['duplicated'] = wpuf_duplicate_form( $_GET['id'] );
 
279
  }
280
 
281
  break;
282
  }
283
 
284
- $redirect = remove_query_arg( $remove_query_args, wp_unslash( $_SERVER['REQUEST_URI'] ) );
 
 
285
 
286
  $redirect = add_query_arg( $add_query_args, $redirect );
287
 
@@ -295,13 +311,13 @@ class WPUF_Admin_Form_Handler {
295
  *
296
  * @since 2.5
297
  *
298
- * @param string $text
299
- * @param string $type
300
  *
301
  * @return void
302
  */
303
  public function display_notice( $text, $type = 'updated' ) {
304
- printf( '<div class="%s"><p>%s</p></div>', esc_attr( $type ), $text );
305
  }
306
 
307
  /**
@@ -314,40 +330,49 @@ class WPUF_Admin_Form_Handler {
314
  public function admin_notices() {
315
  if ( !empty( $_GET['page'] ) && 'wpuf-post-forms' === $_GET['page'] ) {
316
  if ( !empty( $_GET['trashed'] ) ) {
317
- $notice = sprintf( _n( '%d form moved to the trash.', '%d forms moved to the trash.', $_GET['trashed'], 'wp-user-frontend' ), $_GET['trashed'] );
 
318
  $this->display_notice( $notice );
 
 
319
 
320
- } else if ( !empty( $_GET['untrashed'] ) ) {
321
- $notice = sprintf( _n( '%d form restored from the trash.', '%d forms restored from the trash.', $_GET['untrashed'], 'wp-user-frontend' ), $_GET['untrashed'] );
322
  $this->display_notice( $notice );
 
 
323
 
324
- } else if ( !empty( $_GET['deleted'] ) ) {
325
- $notice = sprintf( _n( '%d form permanently deleted.', '%d forms permanently deleted.', $_GET['deleted'], 'wp-user-frontend' ), $_GET['deleted'] );
326
  $this->display_notice( $notice );
 
 
327
 
328
- } else if ( !empty( $_GET['duplicated'] ) ) {
329
- $form_url = admin_url( 'admin.php?page=wpuf-post-forms&action=edit&id=' . $_GET['duplicated'] );
330
- $notice = sprintf( __( 'Form duplicated successfully. <a href="%s">View form.</a>', 'wp-user-frontend' ), $form_url );
331
  $this->display_notice( $notice );
332
  }
333
  }
334
 
335
  if ( !empty( $_GET['page'] ) && 'wpuf-profile-forms' === $_GET['page'] ) {
336
  if ( !empty( $_GET['trashed'] ) ) {
337
- $notice = sprintf( _n( '%d form moved to the trash.', '%d forms moved to the trash.', $_GET['trashed'], 'wp-user-frontend' ), $_GET['trashed'] );
 
 
338
  $this->display_notice( $notice );
 
 
339
 
340
- } else if ( !empty( $_GET['untrashed'] ) ) {
341
- $notice = sprintf( _n( '%d form restored from the trash.', '%d forms restored from the trash.', $_GET['untrashed'], 'wp-user-frontend' ), $_GET['untrashed'] );
342
  $this->display_notice( $notice );
 
 
343
 
344
- } else if ( !empty( $_GET['deleted'] ) ) {
345
- $notice = sprintf( _n( '%d form permanently deleted.', '%d forms permanently deleted.', $_GET['deleted'], 'wp-user-frontend' ), $_GET['deleted'] );
346
  $this->display_notice( $notice );
 
 
347
 
348
- } else if ( !empty( $_GET['duplicated'] ) ) {
349
- $form_url = admin_url( 'admin.php?page=wpuf-profile-forms&action=edit&id=' . $_GET['duplicated'] );
350
- $notice = sprintf( __( 'Form duplicated successfully. <a href="%s">View form.</a>', 'wp-user-frontend' ), $form_url );
351
  $this->display_notice( $notice );
352
  }
353
  }
1
  <?php
2
+
3
  class WPUF_Admin_Form_Handler {
4
 
5
  public function __construct() {
6
  // post forms list table
7
+ add_action( 'load-user-frontend_page_wpuf-post-forms', [ $this, 'post_forms_actions' ] );
8
+ add_action( 'load-user-frontend_page_wpuf-profile-forms', [ $this, 'profile_forms_actions' ] );
9
+ add_action( 'admin_notices', [ $this, 'admin_notices' ] );
10
+ add_action( 'removable_query_args', [ $this, 'removable_query_args' ] );
11
  }
12
 
13
  /**
15
  *
16
  * @since 2.5
17
  *
18
+ * @param int $page_id
19
+ * @param int $bulk_action
20
  *
21
+ * @return bool
22
  */
23
  public function verify_current_page_screen( $page_id, $bulk_action ) {
24
+ if ( !isset( $_GET['_wpnonce'] ) || !isset( $_GET['page'] ) ) {
 
25
  return false;
26
  }
27
 
29
  return false;
30
  }
31
 
32
+ $nonce = isset( $_GET['_wpnonce'] ) ? sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ) : '';
33
+
34
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, $bulk_action ) ) {
35
  return false;
36
  }
37
 
47
  */
48
  public function post_forms_actions() {
49
  // Nonce validation
50
+ if ( !$this->verify_current_page_screen( 'wpuf-post-forms', 'bulk-post-forms' ) ) {
51
  return;
52
  }
53
 
54
  // Check permission if not wpuf admin then go out from here
55
+ if ( !current_user_can( wpuf_admin_role() ) ) {
56
+ wp_die( esc_html( __( 'You do not have sufficient permissions to do this action', 'wp-user-frontend' ) ) );
57
  }
58
 
 
59
  $post_forms = new WPUF_Admin_Post_Forms_List_Table();
60
+ $action = $post_forms->current_action();
61
 
62
  if ( $action ) {
63
+ $remove_query_args = [
 
64
  '_wp_http_referer', '_wpnonce', 'action', 'id', 'post', 'action2',
65
+ ];
66
 
67
+ $add_query_args = [];
68
 
69
  switch ( $action ) {
70
  case 'post_form_search':
71
+ $redirect = remove_query_arg( [ 'post_form_search' ], $redirect );
72
 
73
  break;
74
 
75
+ case 'trash':
76
 
77
+ if ( !empty( $_GET['id'] ) ) {
78
+ $id = intval( wp_unslash( $_GET['id'] ) );
79
+ delete_post_meta( $id, '_wp_trash_meta_status' );
80
+ delete_post_meta( $id, '_wp_trash_meta_time' );
81
+ delete_post_meta( $id, '_wp_desired_post_slug' );
82
 
83
+ wp_trash_post( $id );
84
 
85
  $add_query_args['trashed'] = 1;
86
+ } elseif ( !empty( $_GET['post'] ) ) {
87
+ $posts = isset( $_GET['post'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_GET['post'] ) ) : [];
88
+ foreach ( $posts as $post_id ) {
89
  delete_post_meta( $post_id, '_wp_trash_meta_status' );
90
  delete_post_meta( $post_id, '_wp_trash_meta_time' );
91
  delete_post_meta( $post_id, '_wp_desired_post_slug' );
98
 
99
  break;
100
 
101
+ case 'restore':
102
  if ( !empty( $_GET['id'] ) ) {
103
+ $id = intval( wp_unslash( $_GET['id'] ) );
104
+ $trash_meta_status = get_post_meta( $id, '_wp_trash_meta_status', true );
105
 
106
+ $args = [
107
+ 'ID' => $id,
108
  'post_status' => $trash_meta_status,
109
+ ];
110
 
111
  wp_update_post( $args );
112
 
113
  $add_query_args['untrashed'] = 1;
114
+ } elseif ( !empty( $_GET['post'] ) ) {
115
+
116
+ $posts = array_map( 'sanitize_text_field', wp_unslash( $_GET['post'] ) );
117
 
118
+ foreach ( $posts as $post_id ) {
 
119
  $trash_meta_status = get_post_meta( $post_id, '_wp_trash_meta_status', true );
120
 
121
+ $args = [
122
  'ID' => $post_id,
123
  'post_status' => $trash_meta_status,
124
+ ];
125
 
126
  wp_update_post( $args );
127
 
128
+ $add_query_args['untrashed'] = count( $posts );
129
  }
130
  }
131
 
132
  break;
133
 
134
+ case 'delete':
135
 
136
+ if ( !empty( $_GET['id'] ) ) {
 
137
 
138
+ $id = intval( wp_unslash( $_GET['id'] ) );
139
+ wp_delete_post( $id );
140
 
141
+ $add_query_args['deleted'] = 1;
142
+ } elseif ( !empty( $_GET['post'] ) ) {
143
+ $posts = array_map( 'sanitize_text_field', wp_unslash( $_GET['post'] ) );
144
+ foreach ( $posts as $post_id ) {
145
  wp_delete_post( $post_id );
146
  }
147
 
148
+ $add_query_args['deleted'] = count( $posts );
149
  }
150
 
151
  $add_query_args['post_status'] = 'trash';
153
  break;
154
 
155
  case 'duplicate':
156
+ if ( !empty( $_GET['id'] ) ) {
157
+ $id = intval( wp_unslash( $_GET['id'] ) );
158
+ $add_query_args['duplicated'] = wpuf_duplicate_form( $id );
159
  }
160
 
161
  break;
162
  }
163
 
164
+ $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
165
+ $redirect = remove_query_arg( $remove_query_args, $request_uri );
166
 
167
  $redirect = add_query_arg( $add_query_args, $redirect );
168
 
180
  */
181
  public function profile_forms_actions() {
182
  // Nonce validation
183
+ if ( !$this->verify_current_page_screen( 'wpuf-profile-forms', 'bulk-profile-forms' ) ) {
184
  return;
185
  }
186
 
187
  // Check permission if not wpuf admin then go out from here
188
+ if ( !current_user_can( wpuf_admin_role() ) ) {
189
+ wp_die( esc_html( __( 'You do not have sufficient permissions to do this action', 'wp-user-frontend' ) ) );
190
  }
191
 
 
192
  $profile_forms = new WPUF_Admin_Profile_Forms_List_Table();
193
+ $action = $profile_forms->current_action();
194
 
195
  if ( $action ) {
196
+ $remove_query_args = [
 
197
  '_wp_http_referer', '_wpnonce', 'action', 'id', 'post', 'action2',
198
+ ];
199
 
200
+ $add_query_args = [];
201
 
202
  switch ( $action ) {
203
  case 'profile_form_search':
204
+ $redirect = remove_query_arg( [ 'profile_form_search' ], $redirect );
205
 
206
  break;
207
 
208
+ case 'trash':
209
 
210
+ if ( !empty( $_GET['id'] ) ) {
211
+ $id = intval( wp_unslash( $_GET['id'] ) );
212
+ delete_post_meta( $id, '_wp_trash_meta_status' );
213
+ delete_post_meta( $id, '_wp_trash_meta_time' );
214
+ delete_post_meta( $id, '_wp_desired_post_slug' );
215
 
216
+ wp_trash_post( $id );
217
 
218
  $add_query_args['trashed'] = 1;
219
+ } elseif ( !empty( $_GET['post'] ) ) {
220
+ $posts = array_map( 'sanitize_text_field', wp_unslash( $_GET['post'] ) );
221
 
222
+ foreach ( $posts as $post_id ) {
 
223
  delete_post_meta( $post_id, '_wp_trash_meta_status' );
224
  delete_post_meta( $post_id, '_wp_trash_meta_time' );
225
  delete_post_meta( $post_id, '_wp_desired_post_slug' );
232
 
233
  break;
234
 
235
+ case 'restore':
236
  if ( !empty( $_GET['id'] ) ) {
237
+ $id = intval( wp_unslash( $_GET['id'] ) );
238
+ $trash_meta_status = get_post_meta( $id, '_wp_trash_meta_status', true );
239
 
240
+ $args = [
241
+ 'ID' => $id,
242
  'post_status' => $trash_meta_status,
243
+ ];
244
 
245
  wp_update_post( $args );
246
 
247
  $add_query_args['untrashed'] = 1;
248
+ } elseif ( !empty( $_GET['post'] ) ) {
249
+ $posts = array_map( 'sanitize_text_field', wp_unslash( $_GET['post'] ) );
250
 
251
+ foreach ( $posts as $post_id ) {
 
252
  $trash_meta_status = get_post_meta( $post_id, '_wp_trash_meta_status', true );
253
 
254
+ $args = [
255
  'ID' => $post_id,
256
  'post_status' => $trash_meta_status,
257
+ ];
258
 
259
  wp_update_post( $args );
260
 
264
 
265
  break;
266
 
267
+ case 'delete':
268
 
269
+ if ( !empty( $_GET['id'] ) ) {
270
+ $id = intval( wp_unslash( $_GET['id'] ) );
271
+
272
+ wp_delete_post( $id );
273
 
274
  $add_query_args['deleted'] = 1;
275
+ } elseif ( !empty( $_GET['post'] ) ) {
276
+ $posts = array_map( 'sanitize_text_field', wp_unslash( $_GET['post'] ) );
277
 
278
+ foreach ( $posts as $post_id ) {
 
279
  wp_delete_post( $post_id );
280
  }
281
 
282
+ $add_query_args['deleted'] = count( $posts );
283
  }
284
 
285
  $add_query_args['post_status'] = 'trash';
287
  break;
288
 
289
  case 'duplicate':
290
+ if ( !empty( $_GET['id'] ) ) {
291
+ $id = intval( wp_unslash( $_GET['id'] ) );
292
+ $add_query_args['duplicated'] = wpuf_duplicate_form( $id );
293
  }
294
 
295
  break;
296
  }
297
 
298
+ $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
299
+
300
+ $redirect = remove_query_arg( $remove_query_args, $request_uri );
301
 
302
  $redirect = add_query_arg( $add_query_args, $redirect );
303
 
311
  *
312
  * @since 2.5
313
  *
314
+ * @param string $text
315
+ * @param string $type
316
  *
317
  * @return void
318
  */
319
  public function display_notice( $text, $type = 'updated' ) {
320
+ printf( '<div class="%s"><p>%s</p></div>', esc_attr( $type ), wp_kses_post( $text ) );
321
  }
322
 
323
  /**
330
  public function admin_notices() {
331
  if ( !empty( $_GET['page'] ) && 'wpuf-post-forms' === $_GET['page'] ) {
332
  if ( !empty( $_GET['trashed'] ) ) {
333
+ $trashed = sanitize_text_field( wp_unslash( $_GET['trashed'] ) );
334
+ $notice = sprintf( _n( '%d form moved to the trash.', '%d forms moved to the trash.', $trashed, 'wp-user-frontend' ), $trashed );
335
  $this->display_notice( $notice );
336
+ } elseif ( !empty( $_GET['untrashed'] ) ) {
337
+ $untrashed = isset( $_GET['untrashed'] ) ? sanitize_text_field( wp_unslash( $_GET['untrashed'] ) ) : '';
338
 
339
+ $notice = sprintf( _n( '%d form restored from the trash.', '%d forms restored from the trash.', $untrashed, 'wp-user-frontend' ), $untrashed );
 
340
  $this->display_notice( $notice );
341
+ } elseif ( !empty( $_GET['deleted'] ) ) {
342
+ $deleted = sanitize_text_field( wp_unslash( $_GET['deleted'] ) );
343
 
344
+ $notice = sprintf( _n( '%d form permanently deleted.', '%d forms permanently deleted.', $deleted, 'wp-user-frontend' ), $deleted );
 
345
  $this->display_notice( $notice );
346
+ } elseif ( !empty( $_GET['duplicated'] ) ) {
347
+ $duplicated = sanitize_text_field( wp_unslash( $_GET['duplicated'] ) );
348
 
349
+ $form_url = admin_url( 'admin.php?page=wpuf-post-forms&action=edit&id=' . $duplicated );
350
+ $notice = sprintf( __( 'Form duplicated successfully. <a href="%s">View form.</a>', 'wp-user-frontend' ), $form_url );
 
351
  $this->display_notice( $notice );
352
  }
353
  }
354
 
355
  if ( !empty( $_GET['page'] ) && 'wpuf-profile-forms' === $_GET['page'] ) {
356
  if ( !empty( $_GET['trashed'] ) ) {
357
+ $trashed = sanitize_text_field( wp_unslash( $_GET['trashed'] ) );
358
+
359
+ $notice = sprintf( _n( '%d form moved to the trash.', '%d forms moved to the trash.', $trashed, 'wp-user-frontend' ), $trashed );
360
  $this->display_notice( $notice );
361
+ } elseif ( !empty( $_GET['untrashed'] ) ) {
362
+ $untrashed = sanitize_text_field( wp_unslash( $_GET['untrashed'] ) );
363
 
364
+ $notice = sprintf( _n( '%d form restored from the trash.', '%d forms restored from the trash.', $untrashed, 'wp-user-frontend' ), $untrashed );
 
365
  $this->display_notice( $notice );
366
+ } elseif ( !empty( $_GET['deleted'] ) ) {
367
+ $deleted = sanitize_text_field( wp_unslash( $_GET['deleted'] ) );
368
 
369
+ $notice = sprintf( _n( '%d form permanently deleted.', '%d forms permanently deleted.', $deleted, 'wp-user-frontend' ), $deleted );
 
370
  $this->display_notice( $notice );
371
+ } elseif ( !empty( $_GET['duplicated'] ) ) {
372
+ $duplicated = sanitize_text_field( wp_unslash( $_GET['duplicated'] ) );
373
 
374
+ $form_url = admin_url( 'admin.php?page=wpuf-profile-forms&action=edit&id=' . $duplicated );
375
+ $notice = sprintf( __( 'Form duplicated successfully. <a href="%s">View form.</a>', 'wp-user-frontend' ), $form_url );
 
376
  $this->display_notice( $notice );
377
  }
378
  }
admin/form-template.php CHANGED
@@ -10,29 +10,29 @@
10
  class WPUF_Admin_Form_Template {
11
 
12
  public function __construct() {
13
- add_action( 'admin_enqueue_scripts', array($this, 'enqueue_scripts') );
14
 
15
  // post form templates
16
- add_action( 'admin_footer', array( $this, 'render_post_form_templates' ) );
17
- add_filter( 'admin_action_wpuf_post_form_template', array( $this, 'create_post_form_from_template' ) );
18
 
19
  // form settings
20
- add_action( 'wpuf_form_setting', array( $this, 'post_form_settings' ), 8, 2 );
21
 
22
  // frontend insert/update
23
- add_action( 'wpuf_add_post_after_insert', array( $this, 'post_form_submission' ), 10, 3 );
24
- add_action( 'wpuf_edit_post_after_update', array( $this, 'post_form_submission' ), 10, 3 );
25
  }
26
 
27
  /**
28
  * Should a form displayed or sciprt enqueued?
29
  *
30
- * @return boolean
31
  */
32
  public function should_display() {
33
  $current_screen = get_current_screen();
34
 
35
- if ( in_array( $current_screen->id, array( 'user-frontend_page_wpuf-post-forms' ) ) ) {
36
  return true;
37
  }
38
 
@@ -40,7 +40,7 @@ class WPUF_Admin_Form_Template {
40
  }
41
 
42
  public function enqueue_scripts() {
43
- if ( ! $this->should_display() ) {
44
  return;
45
  }
46
 
@@ -53,39 +53,39 @@ class WPUF_Admin_Form_Template {
53
  * @return void
54
  */
55
  public function render_post_form_templates() {
56
- if ( ! $this->should_display() ) {
57
  return;
58
  }
59
 
60
  $registry = wpuf_get_post_form_templates();
61
  $blank_form_url = admin_url( 'admin.php?page=wpuf-post-forms&action=add-new' );
62
  $action_name = 'wpuf_post_form_template';
63
- $footer_help = sprintf( __( 'Want a new integration? <a href="%s" target="_blank">Let us know</a>.', 'wp-user-frontend'), 'mailto:support@wedevs.com?subject=WPUF Custom Post Template Integration Request' );
64
 
65
- if ( ! $registry ) {
66
  return;
67
  }
68
 
69
- include dirname( __FILE__ ) . '/html/modal.php';
70
  }
71
 
72
  /**
73
  * Get a template object by name from the registry
74
  *
75
- * @param string $template
76
  *
77
- * @return boolean|WPUF_Post_Form_Template
78
  */
79
  public function get_template_object( $template ) {
80
  $registry = wpuf_get_post_form_templates();
81
 
82
- if ( ! array_key_exists( $template, $registry ) ) {
83
  return false;
84
  }
85
 
86
  $template_object = $registry[ $template ];
87
 
88
- if ( ! is_a( $template_object, 'WPUF_Post_Form_Template') ) {
89
  return false;
90
  }
91
 
@@ -102,9 +102,9 @@ class WPUF_Admin_Form_Template {
102
  public function create_post_form_from_template() {
103
  check_admin_referer( 'wpuf_create_from_template' );
104
 
105
- $template_name = isset( $_GET['template'] ) ? sanitize_text_field( $_GET['template'] ) : '';
106
 
107
- if ( ! $template_name ) {
108
  return;
109
  }
110
 
@@ -116,12 +116,12 @@ class WPUF_Admin_Form_Template {
116
 
117
  $current_user = get_current_user_id();
118
 
119
- $form_post_data = array(
120
  'post_title' => $template_object->get_title(),
121
  'post_type' => 'wpuf_forms',
122
  'post_status' => 'publish',
123
- 'post_author' => $current_user
124
- );
125
 
126
  $form_id = wp_insert_post( $form_post_data );
127
 
@@ -135,18 +135,18 @@ class WPUF_Admin_Form_Template {
135
 
136
  $form_fields = $template_object->get_form_fields();
137
 
138
- if ( ! $form_fields ) {
139
  return;
140
  }
141
 
142
- foreach ($form_fields as $menu_order => $field) {
143
- wp_insert_post( array(
144
  'post_type' => 'wpuf_input',
145
  'post_status' => 'publish',
146
  'post_content' => maybe_serialize( $field ),
147
  'post_parent' => $form_id,
148
- 'menu_order' => $menu_order
149
- ) );
150
  }
151
 
152
  wp_redirect( admin_url( 'admin.php?page=wpuf-post-forms&action=edit&id=' . $form_id ) );
@@ -156,29 +156,27 @@ class WPUF_Admin_Form_Template {
156
  /**
157
  * Add settings field to override a form template
158
  *
159
- * @param array $form_settings
160
- * @param object $post
161
  *
162
  * @return void
163
  */
164
  public function post_form_settings( $form_settings, $post ) {
165
  $registry = wpuf_get_post_form_templates();
166
- $selected = isset( $form_settings['form_template'] ) ? $form_settings['form_template'] : '';
167
- ?>
168
  <tr>
169
- <th><?php _e( 'Form Template', 'wp-user-frontend' ); ?></th>
170
  <td>
171
  <select name="wpuf_settings[form_template]">
172
- <option value=""><?php echo __( '&mdash; No Template &mdash;', 'wp-user-frontend' ); ?></option>
173
  <?php
174
  if ( $registry ) {
175
- foreach ($registry as $key => $template) {
176
- printf( '<option value="%s"%s>%s</option>' . "\n", $key, selected( $selected, $key, false ), $template->get_title() );
177
  }
178
- }
179
- ?>
180
  </select>
181
- <p class="description"><?php _e( 'If selected a form template, it will try to execute that integration options when new post created and updated.', 'wp-user-frontend' ); ?></p>
182
  </td>
183
  </tr>
184
  <?php
@@ -187,9 +185,9 @@ class WPUF_Admin_Form_Template {
187
  /**
188
  * Call the integration functions on form submission/update
189
  *
190
- * @param int $post_id
191
- * @param int $form_id
192
- * @param array $form_settings
193
  *
194
  * @return void
195
  */
10
  class WPUF_Admin_Form_Template {
11
 
12
  public function __construct() {
13
+ add_action( 'admin_enqueue_scripts', [$this, 'enqueue_scripts'] );
14
 
15
  // post form templates
16
+ add_action( 'admin_footer', [ $this, 'render_post_form_templates' ] );
17
+ add_filter( 'admin_action_wpuf_post_form_template', [ $this, 'create_post_form_from_template' ] );
18
 
19
  // form settings
20
+ add_action( 'wpuf_form_setting', [ $this, 'post_form_settings' ], 8, 2 );
21
 
22
  // frontend insert/update
23
+ add_action( 'wpuf_add_post_after_insert', [ $this, 'post_form_submission' ], 10, 3 );
24
+ add_action( 'wpuf_edit_post_after_update', [ $this, 'post_form_submission' ], 10, 3 );
25
  }
26
 
27
  /**
28
  * Should a form displayed or sciprt enqueued?
29
  *
30
+ * @return bool
31
  */
32
  public function should_display() {
33
  $current_screen = get_current_screen();
34
 
35
+ if ( in_array( $current_screen->id, [ 'user-frontend_page_wpuf-post-forms' ] ) ) {
36
  return true;
37
  }
38
 
40
  }
41
 
42
  public function enqueue_scripts() {
43
+ if ( !$this->should_display() ) {
44
  return;
45
  }
46
 
53
  * @return void
54
  */
55
  public function render_post_form_templates() {
56
+ if ( !$this->should_display() ) {
57
  return;
58
  }
59
 
60
  $registry = wpuf_get_post_form_templates();
61
  $blank_form_url = admin_url( 'admin.php?page=wpuf-post-forms&action=add-new' );
62
  $action_name = 'wpuf_post_form_template';
63
+ $footer_help = sprintf( __( 'Want a new integration? <a href="%s" target="_blank">Let us know</a>.', 'wp-user-frontend' ), 'mailto:support@wedevs.com?subject=WPUF Custom Post Template Integration Request' );
64
 
65
+ if ( !$registry ) {
66
  return;
67
  }
68
 
69
+ include __DIR__ . '/html/modal.php';
70
  }
71
 
72
  /**
73
  * Get a template object by name from the registry
74
  *
75
+ * @param string $template
76
  *
77
+ * @return bool|WPUF_Post_Form_Template
78
  */
79
  public function get_template_object( $template ) {
80
  $registry = wpuf_get_post_form_templates();
81
 
82
+ if ( !array_key_exists( $template, $registry ) ) {
83
  return false;
84
  }
85
 
86
  $template_object = $registry[ $template ];
87
 
88
+ if ( !is_a( $template_object, 'WPUF_Post_Form_Template' ) ) {
89
  return false;
90
  }
91
 
102
  public function create_post_form_from_template() {
103
  check_admin_referer( 'wpuf_create_from_template' );
104
 
105
+ $template_name = isset( $_GET['template'] ) ? sanitize_text_field( wp_unslash( $_GET['template'] ) ) : '';
106
 
107
+ if ( !$template_name ) {
108
  return;
109
  }
110
 
116
 
117
  $current_user = get_current_user_id();
118
 
119
+ $form_post_data = [
120
  'post_title' => $template_object->get_title(),
121
  'post_type' => 'wpuf_forms',
122
  'post_status' => 'publish',
123
+ 'post_author' => $current_user,
124
+ ];
125
 
126
  $form_id = wp_insert_post( $form_post_data );
127
 
135
 
136
  $form_fields = $template_object->get_form_fields();
137
 
138
+ if ( !$form_fields ) {
139
  return;
140
  }
141
 
142
+ foreach ( $form_fields as $menu_order => $field ) {
143
+ wp_insert_post( [
144
  'post_type' => 'wpuf_input',
145
  'post_status' => 'publish',
146
  'post_content' => maybe_serialize( $field ),
147
  'post_parent' => $form_id,
148
+ 'menu_order' => $menu_order,
149
+ ] );
150
  }
151
 
152
  wp_redirect( admin_url( 'admin.php?page=wpuf-post-forms&action=edit&id=' . $form_id ) );
156
  /**
157
  * Add settings field to override a form template
158
  *
159
+ * @param array $form_settings
160
+ * @param object $post
161
  *
162
  * @return void
163
  */
164
  public function post_form_settings( $form_settings, $post ) {
165
  $registry = wpuf_get_post_form_templates();
166
+ $selected = isset( $form_settings['form_template'] ) ? $form_settings['form_template'] : ''; ?>
 
167
  <tr>
168
+ <th><?php esc_html_e( 'Form Template', 'wp-user-frontend' ); ?></th>
169
  <td>
170
  <select name="wpuf_settings[form_template]">
171
+ <option value=""><?php esc_html_e( '&mdash; No Template &mdash;', 'wp-user-frontend' ); ?></option>
172
  <?php
173
  if ( $registry ) {
174
+ foreach ( $registry as $key => $template ) {
175
+ printf( '<option value="%s"%s>%s</option>' . "\n", esc_attr( $key ), esc_attr( selected( $selected, $key, false ) ), esc_html( $template->get_title() ) );
176
  }
177
+ } ?>
 
178
  </select>
179
+ <p class="description"><?php esc_html_e( 'If selected a form template, it will try to execute that integration options when new post created and updated.', 'wp-user-frontend' ); ?></p>
180
  </td>
181
  </tr>
182
  <?php
185
  /**
186
  * Call the integration functions on form submission/update
187
  *
188
+ * @param int $post_id
189
+ * @param int $form_id
190
+ * @param array $form_settings
191
  *
192
  * @return void
193
  */
admin/form.php CHANGED
@@ -1,10 +1,7 @@
1
  <?php
2
  /**
3
  * Post Forms or wpuf_forms form builder class
4
- *
5
- * @package WP User Frontend
6
  */
7
-
8
  class WPUF_Admin_Form {
9
  /**
10
  * Form type of which we're working on
@@ -25,7 +22,7 @@ class WPUF_Admin_Form {
25
  *
26
  * @var string
27
  */
28
- private $wp_post_types = array();
29
 
30
  /**
31
  * Add neccessary actions and filters
@@ -33,8 +30,8 @@ class WPUF_Admin_Form {
33
  * @return void
34
  */
35
  public function __construct() {
36
- add_action( 'init', array($this, 'register_post_type') );
37
- add_action( "load-user-frontend_page_wpuf-post-forms", array( $this, 'post_forms_builder_init' ) );
38
  }
39
 
40
  /**
@@ -45,7 +42,7 @@ class WPUF_Admin_Form {
45
  public function register_post_type() {
46
  $capability = wpuf_admin_role();
47
 
48
- register_post_type( 'wpuf_forms', array(
49
  'label' => __( 'Forms', 'wp-user-frontend' ),
50
  'public' => false,
51
  'show_ui' => false,
@@ -53,8 +50,8 @@ class WPUF_Admin_Form {
53
  'capability_type' => 'post',
54
  'hierarchical' => false,
55
  'query_var' => false,
56
- 'supports' => array('title'),
57
- 'capabilities' => array(
58
  'publish_posts' => $capability,
59
  'edit_posts' => $capability,
60
  'edit_others_posts' => $capability,
@@ -64,8 +61,8 @@ class WPUF_Admin_Form {
64
  'edit_post' => $capability,
65
  'delete_post' => $capability,
66
  'read_post' => $capability,
67
- ),
68
- 'labels' => array(
69
  'name' => __( 'Forms', 'wp-user-frontend' ),
70
  'singular_name' => __( 'Form', 'wp-user-frontend' ),
71
  'menu_name' => __( 'Forms', 'wp-user-frontend' ),
@@ -80,10 +77,10 @@ class WPUF_Admin_Form {
80
  'not_found' => __( 'No Form Found', 'wp-user-frontend' ),
81
  'not_found_in_trash' => __( 'No Form Found in Trash', 'wp-user-frontend' ),
82
  'parent' => __( 'Parent Form', 'wp-user-frontend' ),
83
- ),
84
- ) );
85
 
86
- register_post_type( 'wpuf_profile', array(
87
  'label' => __( 'Registraton Forms', 'wp-user-frontend' ),
88
  'public' => false,
89
  'show_ui' => false,
@@ -91,8 +88,8 @@ class WPUF_Admin_Form {
91
  'capability_type' => 'post',
92
  'hierarchical' => false,
93
  'query_var' => false,
94
- 'supports' => array('title'),
95
- 'capabilities' => array(
96
  'publish_posts' => $capability,
97
  'edit_posts' => $capability,
98
  'edit_others_posts' => $capability,
@@ -102,8 +99,8 @@ class WPUF_Admin_Form {
102
  'edit_post' => $capability,
103
  'delete_post' => $capability,
104
  'read_post' => $capability,
105
- ),
106
- 'labels' => array(
107
  'name' => __( 'Forms', 'wp-user-frontend' ),
108
  'singular_name' => __( 'Form', 'wp-user-frontend' ),
109
  'menu_name' => __( 'Registration Forms', 'wp-user-frontend' ),
@@ -118,14 +115,14 @@ class WPUF_Admin_Form {
118
  'not_found' => __( 'No Form Found', 'wp-user-frontend' ),
119
  'not_found_in_trash' => __( 'No Form Found in Trash', 'wp-user-frontend' ),
120
  'parent' => __( 'Parent Form', 'wp-user-frontend' ),
121
- ),
122
- ) );
123
 
124
- register_post_type( 'wpuf_input', array(
125
  'public' => false,
126
  'show_ui' => false,
127
  'show_in_menu' => false,
128
- ) );
129
  }
130
 
131
  /**
@@ -136,45 +133,43 @@ class WPUF_Admin_Form {
136
  * @return void
137
  */
138
  public function post_forms_builder_init() {
139
-
140
- if ( ! isset( $_GET['action'] ) ) {
141
  return;
142
  }
143
 
144
  if ( 'add-new' === $_GET['action'] && empty( $_GET['id'] ) ) {
145
  $form_id = wpuf_create_sample_form( 'Sample Form', 'wpuf_forms', true );
146
- $add_new_page_url = add_query_arg( array( 'id' => $form_id ), admin_url( 'admin.php?page=wpuf-post-forms&action=edit' ) );
147
  wp_redirect( $add_new_page_url );
148
  }
149
 
150
- if ( ( 'edit' === $_GET['action'] ) && ! empty( $_GET['id'] ) ) {
151
-
152
- add_action( 'wpuf-form-builder-tabs-post', array( $this, 'add_primary_tabs' ) );
153
- add_action( 'wpuf-form-builder-tab-contents-post', array( $this, 'add_primary_tab_contents' ) );
154
- add_action( 'wpuf-form-builder-settings-tabs-post', array( $this, 'add_settings_tabs' ) );
155
- add_action( 'wpuf-form-builder-settings-tab-contents-post', array( $this, 'add_settings_tab_contents' ) );
156
- add_filter( 'wpuf-form-fields-section-before', array( $this, 'add_post_field_section' ) );
157
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
158
- add_action( 'wpuf-form-builder-js-deps', array( $this, 'js_dependencies' ) );
159
- add_filter( 'wpuf-form-builder-js-root-mixins', array( $this, 'js_root_mixins' ) );
160
- add_filter( 'wpuf-form-builder-js-builder-stage-mixins', array( $this, 'js_builder_stage_mixins' ) );
161
- add_filter( 'wpuf-form-builder-js-field-options-mixins', array( $this, 'js_field_options_mixins' ) );
162
- add_action( 'wpuf-form-builder-template-builder-stage-submit-area', array( $this, 'add_form_submit_area' ) );
163
- add_action( 'wpuf-form-builder-localize-script', array( $this, 'add_to_localize_script' ) );
164
- add_filter( 'wpuf-form-fields', array( $this, 'add_field_settings' ) );
165
- add_filter( 'wpuf-form-builder-i18n', array( $this, 'i18n' ) );
166
 
167
  do_action( 'wpuf-form-builder-init-type-wpuf_forms' );
168
 
169
  $this->set_wp_post_types();
170
 
171
- $settings = array(
172
  'form_type' => 'post',
173
  'post_type' => 'wpuf_forms',
174
- 'post_id' => $_GET['id'],
175
  'form_settings_key' => $this->form_settings_key,
176
- 'shortcodes' => array( array( 'name' => 'wpuf_form' ) )
177
- );
178
 
179
  new WPUF_Admin_Form_Builder( $settings );
180
  }
@@ -191,7 +186,7 @@ class WPUF_Admin_Form {
191
  ?>
192
 
193
  <a href="#wpuf-form-builder-notification" class="nav-tab">
194
- <?php _e( 'Notification', 'wp-user-frontend' ); ?>
195
  </a>
196
 
197
  <?php
@@ -208,7 +203,7 @@ class WPUF_Admin_Form {
208
  ?>
209
 
210
  <div id="wpuf-form-builder-notification" class="group">
211
- <?php do_action('wpuf_form_settings_post_notification'); ?>
212
  </div><!-- #wpuf-form-builder-notification -->
213
 
214
  <?php
@@ -224,12 +219,12 @@ class WPUF_Admin_Form {
224
  public function add_settings_tabs() {
225
  ?>
226
 
227
- <a href="#wpuf-metabox-settings" class="nav-tab"><?php _e( 'Post Settings', 'wp-user-frontend' ); ?></a>
228
- <a href="#wpuf-metabox-settings-update" class="nav-tab"><?php _e( 'Edit Settings', 'wp-user-frontend' ); ?></a>
229
- <a href="#wpuf-metabox-submission-restriction" class="nav-tab"><?php _e( 'Submission Restriction', 'wp-user-frontend' ); ?></a>
230
- <a href="#wpuf-metabox-settings-payment" class="nav-tab"><?php _e( 'Payment Settings', 'wp-user-frontend' ); ?></a>
231
- <a href="#wpuf-metabox-settings-display" class="nav-tab"><?php _e( 'Display Settings', 'wp-user-frontend' ); ?></a>
232
- <a href="#wpuf-metabox-post_expiration" class="nav-tab"><?php _e( 'Post Expiration', 'wp-user-frontend' ); ?></a>
233
 
234
  <?php do_action( 'wpuf_post_form_tab' ); ?>
235
 
@@ -246,27 +241,26 @@ class WPUF_Admin_Form {
246
  public function add_settings_tab_contents() {
247
  global $post;
248
 
249
- $form_settings = wpuf_get_form_settings( $post->ID );
250
- ?>
251
 
252
  <div id="wpuf-metabox-settings" class="group">
253
- <?php include_once dirname( __FILE__ ) . '/html/form-settings-post.php'; ?>
254
  </div>
255
 
256
  <div id="wpuf-metabox-settings-update" class="group">
257
- <?php include_once dirname( __FILE__ ) . '/html/form-settings-post-edit.php'; ?>
258
  </div>
259
 
260
  <div id="wpuf-metabox-submission-restriction" class="group">
261
- <?php include_once dirname( __FILE__ ) . '/html/form-submission-restriction.php'; ?>
262
  </div>
263
 
264
  <div id="wpuf-metabox-settings-payment" class="group">
265
- <?php include_once dirname( __FILE__ ) . '/html/form-settings-payment.php'; ?>
266
  </div>
267
 
268
  <div id="wpuf-metabox-settings-display" class="group">
269
- <?php include_once dirname( __FILE__ ) . '/html/form-settings-display.php'; ?>
270
  </div>
271
 
272
  <div id="wpuf-metabox-post_expiration" class="group wpuf-metabox-post_expiration">
@@ -290,16 +284,17 @@ class WPUF_Admin_Form {
290
  public function subscription_dropdown( $selected = null ) {
291
  $subscriptions = WPUF_Subscription::init()->get_subscriptions();
292
 
293
- if ( ! $subscriptions ) {
294
- printf( '<option>%s</option>', __( '- Select -', 'wp-user-frontend' ) );
 
295
  return;
296
  }
297
 
298
- printf( '<option>%s</option>', __( '- Select -', 'wp-user-frontend' ) );
299
 
300
  foreach ( $subscriptions as $key => $subscription ) {
301
  ?>
302
- <option value="<?php echo esc_attr( $subscription->ID ); ?>" <?php selected( $selected, $subscription->ID ); ?> ><?php echo $subscription->post_title; ?></option>
303
  <?php
304
  }
305
  }
@@ -311,8 +306,8 @@ class WPUF_Admin_Form {
311
  *
312
  * @global $post
313
  */
314
- public function form_post_expiration(){
315
- do_action('wpuf_form_post_expiration');
316
  }
317
 
318
  /**
@@ -323,23 +318,23 @@ class WPUF_Admin_Form {
323
  * @return array
324
  */
325
  public function add_post_field_section() {
326
- $post_fields = apply_filters( 'wpuf-form-builder-wp_forms-fields-section-post-fields', array(
327
- 'post_title', 'post_content', 'post_excerpt', 'featured_image'
328
- ) );
329
 
330
- return array(
331
- array(
332
  'title' => __( 'Post Fields', 'wp-user-frontend' ),
333
  'id' => 'post-fields',
334
- 'fields' => $post_fields
335
- ),
336
 
337
- array(
338
  'title' => __( 'Taxonomies', 'wp-user-frontend' ),
339
  'id' => 'taxonomies',
340
- 'fields' => array()
341
- )
342
- );
343
  }
344
 
345
  /**
@@ -353,10 +348,10 @@ class WPUF_Admin_Form {
353
  wp_register_script(
354
  'wpuf-form-builder-wpuf-forms',
355
  WPUF_ASSET_URI . '/js/wpuf-form-builder-wpuf-forms.js',
356
- array( 'jquery', 'underscore', 'wpuf-vue', 'wpuf-vuex' ),
357
  WPUF_VERSION,
358
  true
359
- );
360
  }
361
 
362
  /**
@@ -384,7 +379,7 @@ class WPUF_Admin_Form {
384
  * @return array
385
  */
386
  public function js_root_mixins( $mixins ) {
387
- array_push( $mixins , 'wpuf_forms_mixin_root' );
388
 
389
  return $mixins;
390
  }
@@ -399,7 +394,7 @@ class WPUF_Admin_Form {
399
  * @return array
400
  */
401
  public function js_builder_stage_mixins( $mixins ) {
402
- array_push( $mixins , 'wpuf_forms_mixin_builder_stage' );
403
 
404
  return $mixins;
405
  }
@@ -414,7 +409,7 @@ class WPUF_Admin_Form {
414
  * @return array
415
  */
416
  public function js_field_options_mixins( $mixins ) {
417
- array_push( $mixins , 'wpuf_forms_mixin_field_options' );
418
 
419
  return $mixins;
420
  }
@@ -437,7 +432,7 @@ class WPUF_Admin_Form {
437
  class="btn"
438
  id="wpuf-post-draft"
439
  >
440
- <?php _e( 'Save Draft', 'wp-user-frontend' ); ?>
441
  </a>
442
  <?php
443
  }
@@ -450,30 +445,30 @@ class WPUF_Admin_Form {
450
  * @return void
451
  */
452
  public function set_wp_post_types() {
453
- $args = array( '_builtin' => true );
454
 
455
  $wpuf_post_types = wpuf_get_post_types( $args );
456
 
457
- $ignore_taxonomies = apply_filters( 'wpuf-ignore-taxonomies', array(
458
- 'post_format'
459
- ) );
460
 
461
  foreach ( $wpuf_post_types as $post_type ) {
462
- $this->wp_post_types[ $post_type ] = array();
463
 
464
  $taxonomies = get_object_taxonomies( $post_type, 'object' );
465
 
466
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
467
- if ( ! in_array( $tax_name, $ignore_taxonomies ) ) {
468
- $this->wp_post_types[ $post_type ][ $tax_name ] = array(
469
  'title' => $taxonomy->label,
470
- 'hierarchical' => $taxonomy->hierarchical
471
- );
472
 
473
- $this->wp_post_types[ $post_type ][ $tax_name ]['terms'] = get_terms( array(
474
- 'taxonomy' => $tax_name,
475
- 'hide_empty' => false
476
- ) );
477
  }
478
  }
479
  }
@@ -489,9 +484,9 @@ class WPUF_Admin_Form {
489
  * @return array
490
  */
491
  public function add_to_localize_script( $data ) {
492
- return array_merge( $data, array(
493
- 'wp_post_types' => $this->wp_post_types
494
- ) );
495
  }
496
 
497
  /**
@@ -504,9 +499,7 @@ class WPUF_Admin_Form {
504
  * @return array
505
  */
506
  public function add_field_settings( $field_settings ) {
507
-
508
  if ( class_exists( 'WPUF_Field_Contract' ) ) {
509
-
510
  require_once WPUF_ROOT . '/includes/fields/class-field-post-title.php';
511
  require_once WPUF_ROOT . '/includes/fields/class-field-post-content.php';
512
  require_once WPUF_ROOT . '/includes/fields/class-field-post-tags.php';
@@ -514,38 +507,32 @@ class WPUF_Admin_Form {
514
  require_once WPUF_ROOT . '/includes/fields/class-field-post-taxonomy.php';
515
  require_once WPUF_ROOT . '/includes/fields/class-field-featured-image.php';
516
 
517
- $field_settings['post_title'] = new WPUF_Form_Field_Post_Title();
518
- $field_settings['post_content'] = new WPUF_Form_Field_Post_Content();
519
- $field_settings['post_excerpt'] = new WPUF_Form_Field_Post_Excerpt();
520
  $field_settings['featured_image'] = new WPUF_Form_Field_Featured_Image();
521
 
522
- $taxonomy_templates = array();
523
 
524
  foreach ( $this->wp_post_types as $post_type => $taxonomies ) {
525
-
526
- if ( ! empty( $taxonomies ) ) {
527
-
528
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
529
  if ( 'post_tag' === $tax_name ) {
530
  $taxonomy_templates['post_tag'] = new WPUF_Form_Field_Post_Tags();
531
  } else {
532
- $taxonomy_templates[ $tax_name ] = new WPUF_Form_Field_Post_Taxonomy($tax_name, $taxonomy);
533
  // $taxonomy_templates[ 'taxonomy' ] = new WPUF_Form_Field_Post_Taxonomy($tax_name, $taxonomy);
534
  }
535
  }
536
-
537
  }
538
-
539
  }
540
 
541
  $field_settings = array_merge( $field_settings, $taxonomy_templates );
542
-
543
  }
544
 
545
  return $field_settings;
546
  }
547
 
548
-
549
  /**
550
  * i18n strings specially for Post Forms
551
  *
@@ -556,9 +543,8 @@ class WPUF_Admin_Form {
556
  * @return array
557
  */
558
  public function i18n( $i18n ) {
559
- return array_merge( $i18n, array(
560
- 'any_of_three_needed' => __( 'Post Forms must have either Post Title, Post Body or Excerpt field', 'wp-user-frontend' )
561
- ) );
562
  }
563
-
564
  }
1
  <?php
2
  /**
3
  * Post Forms or wpuf_forms form builder class
 
 
4
  */
 
5
  class WPUF_Admin_Form {
6
  /**
7
  * Form type of which we're working on
22
  *
23
  * @var string
24
  */
25
+ private $wp_post_types = [];
26
 
27
  /**
28
  * Add neccessary actions and filters
30
  * @return void
31
  */
32
  public function __construct() {
33
+ add_action( 'init', [$this, 'register_post_type'] );
34
+ add_action( 'load-user-frontend_page_wpuf-post-forms', [ $this, 'post_forms_builder_init' ] );
35
  }
36
 
37
  /**
42
  public function register_post_type() {
43
  $capability = wpuf_admin_role();
44
 
45
+ register_post_type( 'wpuf_forms', [
46
  'label' => __( 'Forms', 'wp-user-frontend' ),
47
  'public' => false,
48
  'show_ui' => false,
50
  'capability_type' => 'post',
51
  'hierarchical' => false,
52
  'query_var' => false,
53
+ 'supports' => ['title'],
54
+ 'capabilities' => [
55
  'publish_posts' => $capability,
56
  'edit_posts' => $capability,
57
  'edit_others_posts' => $capability,
61
  'edit_post' => $capability,
62
  'delete_post' => $capability,
63
  'read_post' => $capability,
64
+ ],
65
+ 'labels' => [
66
  'name' => __( 'Forms', 'wp-user-frontend' ),
67
  'singular_name' => __( 'Form', 'wp-user-frontend' ),
68
  'menu_name' => __( 'Forms', 'wp-user-frontend' ),
77
  'not_found' => __( 'No Form Found', 'wp-user-frontend' ),
78
  'not_found_in_trash' => __( 'No Form Found in Trash', 'wp-user-frontend' ),
79
  'parent' => __( 'Parent Form', 'wp-user-frontend' ),
80
+ ],
81
+ ] );
82
 
83
+ register_post_type( 'wpuf_profile', [
84
  'label' => __( 'Registraton Forms', 'wp-user-frontend' ),
85
  'public' => false,
86
  'show_ui' => false,
88
  'capability_type' => 'post',
89
  'hierarchical' => false,
90
  'query_var' => false,
91
+ 'supports' => ['title'],
92
+ 'capabilities' => [
93
  'publish_posts' => $capability,
94
  'edit_posts' => $capability,
95
  'edit_others_posts' => $capability,
99
  'edit_post' => $capability,
100
  'delete_post' => $capability,
101
  'read_post' => $capability,
102
+ ],
103
+ 'labels' => [
104
  'name' => __( 'Forms', 'wp-user-frontend' ),
105
  'singular_name' => __( 'Form', 'wp-user-frontend' ),
106
  'menu_name' => __( 'Registration Forms', 'wp-user-frontend' ),
115
  'not_found' => __( 'No Form Found', 'wp-user-frontend' ),
116
  'not_found_in_trash' => __( 'No Form Found in Trash', 'wp-user-frontend' ),
117
  'parent' => __( 'Parent Form', 'wp-user-frontend' ),
118
+ ],
119
+ ] );
120
 
121
+ register_post_type( 'wpuf_input', [
122
  'public' => false,
123
  'show_ui' => false,
124
  'show_in_menu' => false,
125
+ ] );
126
  }
127
 
128
  /**
133
  * @return void
134
  */
135
  public function post_forms_builder_init() {
136
+ if ( !isset( $_GET['action'] ) ) {
 
137
  return;
138
  }
139
 
140
  if ( 'add-new' === $_GET['action'] && empty( $_GET['id'] ) ) {
141
  $form_id = wpuf_create_sample_form( 'Sample Form', 'wpuf_forms', true );
142
+ $add_new_page_url = add_query_arg( [ 'id' => $form_id ], admin_url( 'admin.php?page=wpuf-post-forms&action=edit' ) );
143
  wp_redirect( $add_new_page_url );
144
  }
145
 
146
+ if ( ( 'edit' === $_GET['action'] ) && !empty( $_GET['id'] ) ) {
147
+ add_action( 'wpuf-form-builder-tabs-post', [ $this, 'add_primary_tabs' ] );
148
+ add_action( 'wpuf-form-builder-tab-contents-post', [ $this, 'add_primary_tab_contents' ] );
149
+ add_action( 'wpuf-form-builder-settings-tabs-post', [ $this, 'add_settings_tabs' ] );
150
+ add_action( 'wpuf-form-builder-settings-tab-contents-post', [ $this, 'add_settings_tab_contents' ] );
151
+ add_filter( 'wpuf-form-fields-section-before', [ $this, 'add_post_field_section' ] );
152
+ add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
153
+ add_action( 'wpuf-form-builder-js-deps', [ $this, 'js_dependencies' ] );
154
+ add_filter( 'wpuf-form-builder-js-root-mixins', [ $this, 'js_root_mixins' ] );
155
+ add_filter( 'wpuf-form-builder-js-builder-stage-mixins', [ $this, 'js_builder_stage_mixins' ] );
156
+ add_filter( 'wpuf-form-builder-js-field-options-mixins', [ $this, 'js_field_options_mixins' ] );
157
+ add_action( 'wpuf-form-builder-template-builder-stage-submit-area', [ $this, 'add_form_submit_area' ] );
158
+ add_action( 'wpuf-form-builder-localize-script', [ $this, 'add_to_localize_script' ] );
159
+ add_filter( 'wpuf-form-fields', [ $this, 'add_field_settings' ] );
160
+ add_filter( 'wpuf-form-builder-i18n', [ $this, 'i18n' ] );
 
161
 
162
  do_action( 'wpuf-form-builder-init-type-wpuf_forms' );
163
 
164
  $this->set_wp_post_types();
165
 
166
+ $settings = [
167
  'form_type' => 'post',
168
  'post_type' => 'wpuf_forms',
169
+ 'post_id' => isset( $_GET['id'] ) ? intval( wp_unslash( $_GET['id'] ) ) : '',
170
  'form_settings_key' => $this->form_settings_key,
171
+ 'shortcodes' => [ [ 'name' => 'wpuf_form' ] ],
172
+ ];
173
 
174
  new WPUF_Admin_Form_Builder( $settings );
175
  }
186
  ?>
187
 
188
  <a href="#wpuf-form-builder-notification" class="nav-tab">
189
+ <?php esc_html_e( 'Notification', 'wp-user-frontend' ); ?>
190
  </a>
191
 
192
  <?php
203
  ?>
204
 
205
  <div id="wpuf-form-builder-notification" class="group">
206
+ <?php do_action( 'wpuf_form_settings_post_notification' ); ?>
207
  </div><!-- #wpuf-form-builder-notification -->
208
 
209
  <?php
219
  public function add_settings_tabs() {
220
  ?>
221
 
222
+ <a href="#wpuf-metabox-settings" class="nav-tab"><?php esc_html_e( 'Post Settings', 'wp-user-frontend' ); ?></a>
223
+ <a href="#wpuf-metabox-settings-update" class="nav-tab"><?php esc_html_e( 'Edit Settings', 'wp-user-frontend' ); ?></a>
224
+ <a href="#wpuf-metabox-submission-restriction" class="nav-tab"><?php esc_html_e( 'Submission Restriction', 'wp-user-frontend' ); ?></a>
225
+ <a href="#wpuf-metabox-settings-payment" class="nav-tab"><?php esc_html_e( 'Payment Settings', 'wp-user-frontend' ); ?></a>
226
+ <a href="#wpuf-metabox-settings-display" class="nav-tab"><?php esc_html_e( 'Display Settings', 'wp-user-frontend' ); ?></a>
227
+ <a href="#wpuf-metabox-post_expiration" class="nav-tab"><?php esc_html_e( 'Post Expiration', 'wp-user-frontend' ); ?></a>
228
 
229
  <?php do_action( 'wpuf_post_form_tab' ); ?>
230
 
241
  public function add_settings_tab_contents() {
242
  global $post;
243
 
244
+ $form_settings = wpuf_get_form_settings( $post->ID ); ?>
 
245
 
246
  <div id="wpuf-metabox-settings" class="group">
247
+ <?php include_once __DIR__ . '/html/form-settings-post.php'; ?>
248
  </div>
249
 
250
  <div id="wpuf-metabox-settings-update" class="group">
251
+ <?php include_once __DIR__ . '/html/form-settings-post-edit.php'; ?>
252
  </div>
253
 
254
  <div id="wpuf-metabox-submission-restriction" class="group">
255
+ <?php include_once __DIR__ . '/html/form-submission-restriction.php'; ?>
256
  </div>
257
 
258
  <div id="wpuf-metabox-settings-payment" class="group">
259
+ <?php include_once __DIR__ . '/html/form-settings-payment.php'; ?>
260
  </div>
261
 
262
  <div id="wpuf-metabox-settings-display" class="group">
263
+ <?php include_once __DIR__ . '/html/form-settings-display.php'; ?>
264
  </div>
265
 
266
  <div id="wpuf-metabox-post_expiration" class="group wpuf-metabox-post_expiration">
284
  public function subscription_dropdown( $selected = null ) {
285
  $subscriptions = WPUF_Subscription::init()->get_subscriptions();
286
 
287
+ if ( !$subscriptions ) {
288
+ printf( '<option>%s</option>', esc_html( __( '- Select -', 'wp-user-frontend' ) ) );
289
+
290
  return;
291
  }
292
 
293
+ printf( '<option>%s</option>', esc_html( __( '- Select -', 'wp-user-frontend' ) ) );
294
 
295
  foreach ( $subscriptions as $key => $subscription ) {
296
  ?>
297
+ <option value="<?php echo esc_attr( $subscription->ID ); ?>" <?php selected( $selected, $subscription->ID ); ?> ><?php echo esc_html( $subscription->post_title ); ?></option>
298
  <?php
299
  }
300
  }
306
  *
307
  * @global $post
308
  */
309
+ public function form_post_expiration() {
310
+ do_action( 'wpuf_form_post_expiration' );
311
  }
312
 
313
  /**
318
  * @return array
319
  */
320
  public function add_post_field_section() {
321
+ $post_fields = apply_filters( 'wpuf-form-builder-wp_forms-fields-section-post-fields', [
322
+ 'post_title', 'post_content', 'post_excerpt', 'featured_image',
323
+ ] );
324
 
325
+ return [
326
+ [
327
  'title' => __( 'Post Fields', 'wp-user-frontend' ),
328
  'id' => 'post-fields',
329
+ 'fields' => $post_fields,
330
+ ],
331
 
332
+ [
333
  'title' => __( 'Taxonomies', 'wp-user-frontend' ),
334
  'id' => 'taxonomies',
335
+ 'fields' => [],
336
+ ],
337
+ ];
338
  }
339
 
340
  /**
348
  wp_register_script(
349
  'wpuf-form-builder-wpuf-forms',
350
  WPUF_ASSET_URI . '/js/wpuf-form-builder-wpuf-forms.js',
351
+ [ 'jquery', 'underscore', 'wpuf-vue', 'wpuf-vuex' ],
352
  WPUF_VERSION,
353
  true
354
+ );
355
  }
356
 
357
  /**
379
  * @return array
380
  */
381
  public function js_root_mixins( $mixins ) {
382
+ array_push( $mixins, 'wpuf_forms_mixin_root' );
383
 
384
  return $mixins;
385
  }
394
  * @return array
395
  */
396
  public function js_builder_stage_mixins( $mixins ) {
397
+ array_push( $mixins, 'wpuf_forms_mixin_builder_stage' );
398
 
399
  return $mixins;
400
  }
409
  * @return array
410
  */
411
  public function js_field_options_mixins( $mixins ) {
412
+ array_push( $mixins, 'wpuf_forms_mixin_field_options' );
413
 
414
  return $mixins;
415
  }
432
  class="btn"
433
  id="wpuf-post-draft"
434
  >
435
+ <?php esc_html_e( 'Save Draft', 'wp-user-frontend' ); ?>
436
  </a>
437
  <?php
438
  }
445
  * @return void
446
  */
447
  public function set_wp_post_types() {
448
+ $args = [ '_builtin' => true ];
449
 
450
  $wpuf_post_types = wpuf_get_post_types( $args );
451
 
452
+ $ignore_taxonomies = apply_filters( 'wpuf-ignore-taxonomies', [
453
+ 'post_format',
454
+ ] );
455
 
456
  foreach ( $wpuf_post_types as $post_type ) {
457
+ $this->wp_post_types[ $post_type ] = [];
458
 
459
  $taxonomies = get_object_taxonomies( $post_type, 'object' );
460
 
461
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
462
+ if ( !in_array( $tax_name, $ignore_taxonomies ) ) {
463
+ $this->wp_post_types[ $post_type ][ $tax_name ] = [
464
  'title' => $taxonomy->label,
465
+ 'hierarchical' => $taxonomy->hierarchical,
466
+ ];
467
 
468
+ $this->wp_post_types[ $post_type ][ $tax_name ]['terms'] = get_terms( [
469
+ 'taxonomy' => $tax_name,
470
+ 'hide_empty' => false,
471
+ ] );
472
  }
473
  }
474
  }
484
  * @return array
485
  */
486
  public function add_to_localize_script( $data ) {
487
+ return array_merge( $data, [
488
+ 'wp_post_types' => $this->wp_post_types,
489
+ ] );
490
  }
491
 
492
  /**
499
  * @return array
500
  */
501
  public function add_field_settings( $field_settings ) {
 
502
  if ( class_exists( 'WPUF_Field_Contract' ) ) {
 
503
  require_once WPUF_ROOT . '/includes/fields/class-field-post-title.php';
504
  require_once WPUF_ROOT . '/includes/fields/class-field-post-content.php';
505
  require_once WPUF_ROOT . '/includes/fields/class-field-post-tags.php';
507
  require_once WPUF_ROOT . '/includes/fields/class-field-post-taxonomy.php';
508
  require_once WPUF_ROOT . '/includes/fields/class-field-featured-image.php';
509
 
510
+ $field_settings['post_title'] = new WPUF_Form_Field_Post_Title();
511
+ $field_settings['post_content'] = new WPUF_Form_Field_Post_Content();
512
+ $field_settings['post_excerpt'] = new WPUF_Form_Field_Post_Excerpt();
513
  $field_settings['featured_image'] = new WPUF_Form_Field_Featured_Image();
514
 
515
+ $taxonomy_templates = [];
516
 
517
  foreach ( $this->wp_post_types as $post_type => $taxonomies ) {
518
+ if ( !empty( $taxonomies ) ) {
 
 
519
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
520
  if ( 'post_tag' === $tax_name ) {
521
  $taxonomy_templates['post_tag'] = new WPUF_Form_Field_Post_Tags();
522
  } else {
523
+ $taxonomy_templates[ $tax_name ] = new WPUF_Form_Field_Post_Taxonomy( $tax_name, $taxonomy );
524
  // $taxonomy_templates[ 'taxonomy' ] = new WPUF_Form_Field_Post_Taxonomy($tax_name, $taxonomy);
525
  }
526
  }
 
527
  }
 
528
  }
529
 
530
  $field_settings = array_merge( $field_settings, $taxonomy_templates );
 
531
  }
532
 
533
  return $field_settings;
534
  }
535
 
 
536
  /**
537
  * i18n strings specially for Post Forms
538
  *
543
  * @return array
544
  */
545
  public function i18n( $i18n ) {
546
+ return array_merge( $i18n, [
547
+ 'any_of_three_needed' => __( 'Post Forms must have either Post Title, Post Body or Excerpt field', 'wp-user-frontend' ),
548
+ ] );
549
  }
 
550
  }
admin/html/form-settings-display.php CHANGED
@@ -8,64 +8,64 @@ $theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use
8
  <table class="form-table">
9
 
10
  <tr class="wpuf-label-position">
11
- <th><?php _e( 'Label Position', 'wp-user-frontend' ); ?></th>
12
  <td>
13
  <select name="wpuf_settings[label_position]">
14
  <?php
15
- $positions = array(
16
  'above' => __( 'Above Element', 'wp-user-frontend' ),
17
  'left' => __( 'Left of Element', 'wp-user-frontend' ),
18
  'right' => __( 'Right of Element', 'wp-user-frontend' ),
19
  'hidden' => __( 'Hidden', 'wp-user-frontend' ),
20
- );
21
 
22
- foreach ($positions as $to => $label) {
23
- printf('<option value="%s"%s>%s</option>', $to, selected( $label_position, $to, false ), $label );
24
  }
25
  ?>
26
  </select>
27
 
28
  <p class="description">
29
- <?php _e( 'Where the labels of the form should display', 'wp-user-frontend' ) ?>
30
  </p>
31
  </td>
32
  </tr>
33
 
34
  <tr class="wpuf-override-theme-css">
35
- <th><?php _e( 'Use Theme CSS', 'wp-user-frontend' ); ?></th>
36
  <td>
37
  <select name="wpuf_settings[use_theme_css]">
38
  <?php
39
- $options = array(
40
  'wpuf-style' => __( 'No', 'wp-user-frontend' ),
41
  'wpuf-theme-style' => __( 'Yes', 'wp-user-frontend' ),
42
- );
43
 
44
- foreach ($options as $to => $label) {
45
- printf('<option value="%s"%s>%s</option>', $to, selected( $theme_css, $to, false ), $label );
46
  }
47
  ?>
48
  </select>
49
 
50
  <p class="description">
51
- <?php _e( 'Selecting "Yes" will use your theme\'s style for form fields.', 'wp-user-frontend' ) ?>
52
  </p>
53
  </td>
54
  </tr>
55
 
56
- <?php if( class_exists( 'WP_User_Frontend_Pro' ) ) : ?>
57
  <tr class="wpuf-form-layouts">
58
- <th><?php _e( 'Form Style', 'wp-user-frontend' ); ?></th>
59
  <td>
60
  <ul>
61
  <?php
62
- $layouts = array(
63
  'layout1' => WPUF_PRO_ASSET_URI . '/images/forms/layout1.png',
64
  'layout2' => WPUF_PRO_ASSET_URI . '/images/forms/layout2.png',
65
  'layout3' => WPUF_PRO_ASSET_URI . '/images/forms/layout3.png',
66
  'layout4' => WPUF_PRO_ASSET_URI . '/images/forms/layout4.png',
67
- 'layout5' => WPUF_PRO_ASSET_URI . '/images/forms/layout5.png'
68
- );
69
 
70
  foreach ( $layouts as $key => $image ) {
71
  $class = '';
@@ -75,16 +75,16 @@ $theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use
75
  }
76
 
77
  $output = '<li class="' . $class . '">';
78
- $output .= '<input type="radio" name="wpuf_settings[form_layout]" value="' . $key . '" ' . checked( $form_layout, $key, false ). '>';
79
  $output .= '<img src="' . $image . '" alt="">';
80
  $output .= '</li>';
81
 
82
- echo $output;
83
  }
84
  ?>
85
  </ul>
86
  </td>
87
  </tr>
88
- <?php endif; ?>
89
 
90
  </table>
8
  <table class="form-table">
9
 
10
  <tr class="wpuf-label-position">
11
+ <th><?php esc_html_e( 'Label Position', 'wp-user-frontend' ); ?></th>
12
  <td>
13
  <select name="wpuf_settings[label_position]">
14
  <?php
15
+ $positions = [
16
  'above' => __( 'Above Element', 'wp-user-frontend' ),
17
  'left' => __( 'Left of Element', 'wp-user-frontend' ),
18
  'right' => __( 'Right of Element', 'wp-user-frontend' ),
19
  'hidden' => __( 'Hidden', 'wp-user-frontend' ),
20
+ ];
21
 
22
+ foreach ( $positions as $to => $label ) {
23
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $to ), esc_attr( selected( $label_position, $to, false ) ), esc_html( $label ) );
24
  }
25
  ?>
26
  </select>
27
 
28
  <p class="description">
29
+ <?php esc_html_e( 'Where the labels of the form should display', 'wp-user-frontend' ); ?>
30
  </p>
31
  </td>
32
  </tr>
33
 
34
  <tr class="wpuf-override-theme-css">
35
+ <th><?php esc_html_e( 'Use Theme CSS', 'wp-user-frontend' ); ?></th>
36
  <td>
37
  <select name="wpuf_settings[use_theme_css]">
38
  <?php
39
+ $options = [
40
  'wpuf-style' => __( 'No', 'wp-user-frontend' ),
41
  'wpuf-theme-style' => __( 'Yes', 'wp-user-frontend' ),
42
+ ];
43
 
44
+ foreach ( $options as $to => $label ) {
45
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $to ), esc_attr( selected( $theme_css, $to, false ) ), esc_html( $label ) );
46
  }
47
  ?>
48
  </select>
49
 
50
  <p class="description">
51
+ <?php esc_html_e( 'Selecting "Yes" will use your theme\'s style for form fields.', 'wp-user-frontend' ); ?>
52
  </p>
53
  </td>
54
  </tr>
55
 
56
+ <?php if ( class_exists( 'WP_User_Frontend_Pro' ) ) { ?>
57
  <tr class="wpuf-form-layouts">
58
+ <th><?php esc_html_e( 'Form Style', 'wp-user-frontend' ); ?></th>
59
  <td>
60
  <ul>
61
  <?php
62
+ $layouts = [
63
  'layout1' => WPUF_PRO_ASSET_URI . '/images/forms/layout1.png',
64
  'layout2' => WPUF_PRO_ASSET_URI . '/images/forms/layout2.png',
65
  'layout3' => WPUF_PRO_ASSET_URI . '/images/forms/layout3.png',
66
  'layout4' => WPUF_PRO_ASSET_URI . '/images/forms/layout4.png',
67
+ 'layout5' => WPUF_PRO_ASSET_URI . '/images/forms/layout5.png',
68
+ ];
69
 
70
  foreach ( $layouts as $key => $image ) {
71
  $class = '';
75
  }
76
 
77
  $output = '<li class="' . $class . '">';
78
+ $output .= '<input type="radio" name="wpuf_settings[form_layout]" value="' . $key . '" ' . checked( $form_layout, $key, false ) . '>';
79
  $output .= '<img src="' . $image . '" alt="">';
80
  $output .= '</li>';
81
 
82
+ echo wp_kses_post( $output );
83
  }
84
  ?>
85
  </ul>
86
  </td>
87
  </tr>
88
+ <?php } ?>
89
 
90
  </table>
admin/html/form-settings-payment.php CHANGED
@@ -17,70 +17,70 @@ $fallback_ppp_cost = isset( $form_settings['fallback_ppp_cost'] ) ? $form_se
17
  <!-- Added Payment Settings -->
18
 
19
  <tr>
20
- <th><?php _e( 'Payment Options', 'wp-user-frontend' ); ?></th>
21
  <td>
22
  <label>
23
  <input type="hidden" name="wpuf_settings[payment_options]" value="false">
24
  <input type="checkbox" name="wpuf_settings[payment_options]" value="true"<?php checked( $payment_options, 'true' ); ?> />
25
- <?php _e( 'Enable Payments', 'wp-user-frontend' ) ?>
26
  </label>
27
- <p class="description"><?php _e( 'Check to enable Payments for this form.', 'wp-user-frontend' ); ?></p>
28
  </td>
29
  </tr>
30
 
31
  <tr class="show-if-payment">
32
- <th>&mdash; <?php _e( 'Force Pack', 'wp-user-frontend' ); ?></th>
33
  <td>
34
  <label>
35
  <input type="hidden" name="wpuf_settings[force_pack_purchase]" value="false">
36
  <input type="checkbox" name="wpuf_settings[force_pack_purchase]" value="true"<?php checked( $force_pack_purchase, 'true' ); ?> />
37
- <?php _e( 'Force subscription pack', 'wp-user-frontend' ) ?>
38
  </label>
39
- <p class="description"><?php _e( 'Force users to purchase and use subscription pack.', 'wp-user-frontend' ); ?></p>
40
  </td>
41
  </tr>
42
 
43
  <tr class="show-if-payment show-if-force-pack">
44
- <th>&mdash; &mdash; <?php _e( 'Fallback to pay per post', 'wp-user-frontend' ); ?></th>
45
  <td>
46
  <label>
47
  <input type="hidden" name="wpuf_settings[fallback_ppp_enable]" value="false">
48
  <input type="checkbox" name="wpuf_settings[fallback_ppp_enable]" value="true"<?php checked( $fallback_ppp_enable, 'true' ); ?> />
49
- <?php _e( 'Fallback pay per post charging', 'wp-user-frontend' ) ?>
50
  </label>
51
- <p class="description"><?php _e( 'Fallback to pay per post charging if pack limit exceeds', 'wp-user-frontend' ); ?></p>
52
  </td>
53
  </tr>
54
 
55
  <tr class="show-if-payment show-if-force-pack">
56
- <th>&mdash; &mdash; <?php _e( 'Fallback cost', 'wp-user-frontend' ); ?></th>
57
  <td>
58
  <label>
59
  <input type="number" name="wpuf_settings[fallback_ppp_cost]" value="<?php echo esc_attr( $fallback_ppp_cost ); ?>" />
60
  </label>
61
- <p class="description"><?php _e( 'Cost of pay per post after a subscription pack limit is reached.', 'wp-user-frontend' ); ?></p>
62
  </td>
63
  </tr>
64
 
65
  <tr class="show-if-payment">
66
- <th>&mdash; <?php _e( 'Pay Per Post', 'wp-user-frontend' ); ?></th>
67
  <td>
68
  <label>
69
  <input type="hidden" name="wpuf_settings[enable_pay_per_post]" value="false">
70
  <input type="checkbox" name="wpuf_settings[enable_pay_per_post]" value="true"<?php checked( $enable_pay_per_post, 'true' ); ?> />
71
- <?php _e( 'Enable Pay Per Post', 'wp-user-frontend' ) ?>
72
  </label>
73
- <p class="description"><?php _e( 'Charge users for posting,', 'wp-user-frontend' ); ?><a target="_blank" href="https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/how-to-charge-for-each-post-submission/"><?php _e( ' Learn More about Pay Per Post.', 'wp-user-frontend' ); ?></a></p>
74
  </td>
75
  </tr>
76
 
77
  <tr class="show-if-payment show-if-pay-per-post">
78
- <th>&mdash; &mdash; <?php _e( 'Cost Settings', 'wp-user-frontend' ); ?></th>
79
  <td>
80
  <label>
81
  <input type="number" name="wpuf_settings[pay_per_post_cost]" value="<?php echo esc_attr( $pay_per_post_cost ); ?>" />
82
  </label>
83
- <p class="description"><?php _e( 'Amount to be charged per post', 'wp-user-frontend' ); ?></p>
84
  </td>
85
  </tr>
86
  <?php do_action( 'wpuf_form_setting_payment', $form_settings, $post ); ?>
17
  <!-- Added Payment Settings -->
18
 
19
  <tr>
20
+ <th><?php esc_html_e( 'Payment Options', 'wp-user-frontend' ); ?></th>
21
  <td>
22
  <label>
23
  <input type="hidden" name="wpuf_settings[payment_options]" value="false">
24
  <input type="checkbox" name="wpuf_settings[payment_options]" value="true"<?php checked( $payment_options, 'true' ); ?> />
25
+ <?php esc_html_e( 'Enable Payments', 'wp-user-frontend' ); ?>
26
  </label>
27
+ <p class="description"><?php esc_html_e( 'Check to enable Payments for this form.', 'wp-user-frontend' ); ?></p>
28
  </td>
29
  </tr>
30
 
31
  <tr class="show-if-payment">
32
+ <th>&mdash; <?php esc_html_e( 'Force Pack', 'wp-user-frontend' ); ?></th>
33
  <td>
34
  <label>
35
  <input type="hidden" name="wpuf_settings[force_pack_purchase]" value="false">
36
  <input type="checkbox" name="wpuf_settings[force_pack_purchase]" value="true"<?php checked( $force_pack_purchase, 'true' ); ?> />
37
+ <?php esc_html_e( 'Force subscription pack', 'wp-user-frontend' ); ?>
38
  </label>
39
+ <p class="description"><?php esc_html_e( 'Force users to purchase and use subscription pack.', 'wp-user-frontend' ); ?></p>
40
  </td>
41
  </tr>
42
 
43
  <tr class="show-if-payment show-if-force-pack">
44
+ <th>&mdash; &mdash; <?php esc_html_e( 'Fallback to pay per post', 'wp-user-frontend' ); ?></th>
45
  <td>
46
  <label>
47
  <input type="hidden" name="wpuf_settings[fallback_ppp_enable]" value="false">
48
  <input type="checkbox" name="wpuf_settings[fallback_ppp_enable]" value="true"<?php checked( $fallback_ppp_enable, 'true' ); ?> />
49
+ <?php esc_html_e( 'Fallback pay per post charging', 'wp-user-frontend' ); ?>
50
  </label>
51
+ <p class="description"><?php esc_html_e( 'Fallback to pay per post charging if pack limit exceeds', 'wp-user-frontend' ); ?></p>
52
  </td>
53
  </tr>
54
 
55
  <tr class="show-if-payment show-if-force-pack">
56
+ <th>&mdash; &mdash; <?php esc_html_e( 'Fallback cost', 'wp-user-frontend' ); ?></th>
57
  <td>
58
  <label>
59
  <input type="number" name="wpuf_settings[fallback_ppp_cost]" value="<?php echo esc_attr( $fallback_ppp_cost ); ?>" />
60
  </label>
61
+ <p class="description"><?php esc_html_e( 'Cost of pay per post after a subscription pack limit is reached.', 'wp-user-frontend' ); ?></p>
62
  </td>
63
  </tr>
64
 
65
  <tr class="show-if-payment">
66
+ <th>&mdash; <?php esc_html_e( 'Pay Per Post', 'wp-user-frontend' ); ?></th>
67
  <td>
68
  <label>
69
  <input type="hidden" name="wpuf_settings[enable_pay_per_post]" value="false">
70
  <input type="checkbox" name="wpuf_settings[enable_pay_per_post]" value="true"<?php checked( $enable_pay_per_post, 'true' ); ?> />
71
+ <?php esc_html_e( 'Enable Pay Per Post', 'wp-user-frontend' ); ?>
72
  </label>
73
+ <p class="description"><?php esc_html_e( 'Charge users for posting,', 'wp-user-frontend' ); ?><a target="_blank" href="https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/how-to-charge-for-each-post-submission/"><?php esc_html_e( ' Learn More about Pay Per Post.', 'wp-user-frontend' ); ?></a></p>
74
  </td>
75
  </tr>
76
 
77
  <tr class="show-if-payment show-if-pay-per-post">
78
+ <th>&mdash; &mdash; <?php esc_html_e( 'Cost Settings', 'wp-user-frontend' ); ?></th>
79
  <td>
80
  <label>
81
  <input type="number" name="wpuf_settings[pay_per_post_cost]" value="<?php echo esc_attr( $pay_per_post_cost ); ?>" />
82
  </label>
83
+ <p class="description"><?php esc_html_e( 'Amount to be charged per post', 'wp-user-frontend' ); ?></p>
84
  </td>
85
  </tr>
86
  <?php do_action( 'wpuf_form_setting_payment', $form_settings, $post ); ?>
admin/html/form-settings-post-edit.php CHANGED
@@ -11,61 +11,61 @@ $lock_edit_post = isset( $form_settings['lock_edit_post'] ) ? $form_settin
11
  <table class="form-table">
12
 
13
  <tr class="wpuf-post-status">
14
- <th><?php _e( 'Set Post Status to', 'wp-user-frontend' ); ?></th>
15
  <td>
16
  <select name="wpuf_settings[edit_post_status]">
17
  <?php
18
  $statuses = get_post_statuses();
19
 
20
- foreach ($statuses as $status => $label) {
21
- printf('<option value="%s"%s>%s</option>', $status, selected( $post_status_selected, $status, false ), $label );
22
  }
23
 
24
- printf( '<option value="_nochange"%s>%s</option>', selected( $post_status_selected, '_nochange', false ), __( 'No Change', 'wp-user-frontend' ) );
25
  ?>
26
  </select>
27
  </td>
28
  </tr>
29
 
30
  <tr class="wpuf-redirect-to">
31
- <th><?php _e( 'Redirect To', 'wp-user-frontend' ); ?></th>
32
  <td>
33
  <select name="wpuf_settings[edit_redirect_to]">
34
  <?php
35
- $redirect_options = array(
36
  'post' => __( 'Newly created post', 'wp-user-frontend' ),
37
  'same' => __( 'Same Page', 'wp-user-frontend' ),
38
  'page' => __( 'To a page', 'wp-user-frontend' ),
39
- 'url' => __( 'To a custom URL', 'wp-user-frontend' )
40
- );
41
 
42
- foreach ($redirect_options as $to => $label) {
43
- printf('<option value="%s"%s>%s</option>', $to, selected( $redirect_to, $to, false ), $label );
44
  }
45
  ?>
46
  </select>
47
  <p class="description">
48
- <?php _e( 'After successfull submit, where the page will redirect to', $domain = 'wp-user-frontend' ) ?>
49
  </p>
50
  </td>
51
  </tr>
52
 
53
  <tr class="wpuf-same-page">
54
- <th><?php _e( 'Post Update Message', 'wp-user-frontend' ); ?></th>
55
  <td>
56
  <textarea rows="3" cols="40" name="wpuf_settings[update_message]"><?php echo esc_textarea( $update_message ); ?></textarea>
57
  </td>
58
  </tr>
59
 
60
  <tr class="wpuf-page-id">
61
- <th><?php _e( 'Page', 'wp-user-frontend' ); ?></th>
62
  <td>
63
  <select name="wpuf_settings[edit_page_id]">
64
  <?php
65
- $pages = get_posts( array( 'numberposts' => -1, 'post_type' => 'page') );
66
 
67
- foreach ($pages as $page) {
68
- printf('<option value="%s"%s>%s</option>', $page->ID, selected( $page_id, $page->ID, false ), esc_attr( $page->post_title ) );
69
  }
70
  ?>
71
  </select>
@@ -73,14 +73,14 @@ $lock_edit_post = isset( $form_settings['lock_edit_post'] ) ? $form_settin
73
  </tr>
74
 
75
  <tr class="wpuf-url">
76
- <th><?php _e( 'Custom URL', 'wp-user-frontend' ); ?></th>
77
  <td>
78
  <input type="url" name="wpuf_settings[edit_url]" value="<?php echo esc_attr( $url ); ?>">
79
  </td>
80
  </tr>
81
 
82
  <tr class="wpuf-subscription-pack" style="display: none;">
83
- <th><?php _e( 'Subscription Title', 'wp-user-frontend'); ?></th>
84
  <td>
85
  <select id="wpuf-subscription-list" name="wpuf_settings[subscription]">
86
  <?php $this->subscription_dropdown( $subscription ); ?>
@@ -89,19 +89,19 @@ $lock_edit_post = isset( $form_settings['lock_edit_post'] ) ? $form_settin
89
  </tr>
90
 
91
  <tr class="wpuf-update-text">
92
- <th><?php _e( 'Update Post Button text', 'wp-user-frontend' ); ?></th>
93
  <td>
94
  <input type="text" name="wpuf_settings[update_text]" value="<?php echo esc_attr( $update_text ); ?>">
95
  </td>
96
  </tr>
97
 
98
  <tr class="lock-edit-post">
99
- <th><?php _e( 'Lock User From Editing After', 'wp-user-frontend' ); ?></th>
100
  <td>
101
- <input type="number" name="wpuf_settings[lock_edit_post]" id="lock_edit_post" value="<?php echo $lock_edit_post; ?>">
102
- <span><?php _e( 'hours', 'wp-user-frontend' ); ?></span>
103
  <p class="description">
104
- <?php _e( 'After how many hours user will be locked from editing the submitted post.', 'wp-user-frontend' ) ?>
105
  </p>
106
  </td>
107
  </tr>
11
  <table class="form-table">
12
 
13
  <tr class="wpuf-post-status">
14
+ <th><?php esc_html_e( 'Set Post Status to', 'wp-user-frontend' ); ?></th>
15
  <td>
16
  <select name="wpuf_settings[edit_post_status]">
17
  <?php
18
  $statuses = get_post_statuses();
19
 
20
+ foreach ( $statuses as $status => $label ) {
21
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $status ), esc_attr( selected( $post_status_selected ), $status, false ), esc_html( $label ) );
22
  }
23
 
24
+ printf( '<option value="_nochange"%s>%s</option>', esc_attr( selected( $post_status_selected, '_nochange', false ) ), esc_html( __( 'No Change', 'wp-user-frontend' ) ) );
25
  ?>
26
  </select>
27
  </td>
28
  </tr>
29
 
30
  <tr class="wpuf-redirect-to">
31
+ <th><?php esc_html_e( 'Redirect To', 'wp-user-frontend' ); ?></th>
32
  <td>
33
  <select name="wpuf_settings[edit_redirect_to]">
34
  <?php
35
+ $redirect_options = [
36
  'post' => __( 'Newly created post', 'wp-user-frontend' ),
37
  'same' => __( 'Same Page', 'wp-user-frontend' ),
38
  'page' => __( 'To a page', 'wp-user-frontend' ),
39
+ 'url' => __( 'To a custom URL', 'wp-user-frontend' ),
40
+ ];
41
 
42
+ foreach ( $redirect_options as $to => $label ) {
43
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $to ), esc_attr( selected( $redirect_to, $to, false ) ), esc_html( $label ) );
44
  }
45
  ?>
46
  </select>
47
  <p class="description">
48
+ <?php esc_html_e( 'After successfull submit, where the page will redirect to', $domain = 'wp-user-frontend' ); ?>
49
  </p>
50
  </td>
51
  </tr>
52
 
53
  <tr class="wpuf-same-page">
54
+ <th><?php esc_html_e( 'Post Update Message', 'wp-user-frontend' ); ?></th>
55
  <td>
56
  <textarea rows="3" cols="40" name="wpuf_settings[update_message]"><?php echo esc_textarea( $update_message ); ?></textarea>
57
  </td>
58
  </tr>
59
 
60
  <tr class="wpuf-page-id">
61
+ <th><?php esc_html_e( 'Page', 'wp-user-frontend' ); ?></th>
62
  <td>
63
  <select name="wpuf_settings[edit_page_id]">
64
  <?php
65
+ $pages = get_posts( [ 'numberposts' => -1, 'post_type' => 'page'] );
66
 
67
+ foreach ( $pages as $page ) {
68
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $page->ID ), esc_attr( selected( $page_id, $page->ID, false ) ), esc_attr( $page->post_title ) );
69
  }
70
  ?>
71
  </select>
73
  </tr>
74
 
75
  <tr class="wpuf-url">
76
+ <th><?php esc_html_e( 'Custom URL', 'wp-user-frontend' ); ?></th>
77
  <td>
78
  <input type="url" name="wpuf_settings[edit_url]" value="<?php echo esc_attr( $url ); ?>">
79
  </td>
80
  </tr>
81
 
82
  <tr class="wpuf-subscription-pack" style="display: none;">
83
+ <th><?php esc_html_e( 'Subscription Title', 'wp-user-frontend' ); ?></th>
84
  <td>
85
  <select id="wpuf-subscription-list" name="wpuf_settings[subscription]">
86
  <?php $this->subscription_dropdown( $subscription ); ?>
89
  </tr>
90
 
91
  <tr class="wpuf-update-text">
92
+ <th><?php esc_html_e( 'Update Post Button text', 'wp-user-frontend' ); ?></th>
93
  <td>
94
  <input type="text" name="wpuf_settings[update_text]" value="<?php echo esc_attr( $update_text ); ?>">
95
  </td>
96
  </tr>
97
 
98
  <tr class="lock-edit-post">
99
+ <th><?php esc_html_e( 'Lock User From Editing After', 'wp-user-frontend' ); ?></th>
100
  <td>
101
+ <input type="number" name="wpuf_settings[lock_edit_post]" id="lock_edit_post" value="<?php echo esc_attr( $lock_edit_post ); ?>">
102
+ <span><?php esc_html_e( 'hours', 'wp-user-frontend' ); ?></span>
103
  <p class="description">
104
+ <?php esc_html_e( 'After how many hours user will be locked from editing the submitted post.', 'wp-user-frontend' ); ?>
105
  </p>
106
  </td>
107
  </tr>
admin/html/form-settings-post.php CHANGED
@@ -4,12 +4,12 @@ global $post;
4
  $form_settings = wpuf_get_form_settings( $post->ID );
5
 
6
  $post_status_selected = isset( $form_settings['post_status'] ) ? $form_settings['post_status'] : 'publish';
7
- $restrict_message = __( "This page is restricted. Please Log in / Register to view this page.", 'wp-user-frontend' );
8
 
9
  $post_type_selected = isset( $form_settings['post_type'] ) ? $form_settings['post_type'] : 'post';
10
 
11
  $post_format_selected = isset( $form_settings['post_format'] ) ? $form_settings['post_format'] : 0;
12
- $default_cat = !empty( $form_settings['default_cat'] ) ? $form_settings['default_cat'] : array();
13
 
14
  $redirect_to = isset( $form_settings['redirect_to'] ) ? $form_settings['redirect_to'] : 'post';
15
  $message = isset( $form_settings['message'] ) ? $form_settings['message'] : __( 'Post saved', 'wp-user-frontend' );
@@ -27,40 +27,41 @@ $draft_post = isset( $form_settings['draft_post'] ) ? $form_settings[
27
  <table class="form-table">
28
 
29
  <tr class="wpuf-post-type">
30
- <th><?php _e( 'Post Type', 'wp-user-frontend' ); ?></th>
31
  <td>
32
  <select name="wpuf_settings[post_type]">
33
  <?php
34
  $post_types = get_post_types();
35
- unset($post_types['attachment']);
36
- unset($post_types['revision']);
37
- unset($post_types['nav_menu_item']);
38
- unset($post_types['wpuf_forms']);
39
- unset($post_types['wpuf_profile']);
40
- unset($post_types['wpuf_input']);
41
- unset($post_types['wpuf_subscription']);
42
- unset($post_types['custom_css']);
43
- unset($post_types['customize_changeset']);
44
- unset($post_types['wpuf_coupon']);
45
- unset($post_types['oembed_cache']);
46
-
47
- foreach ($post_types as $post_type) {
48
- printf('<option value="%s"%s>%s</option>', $post_type, selected( $post_type_selected, $post_type, false ), $post_type );
49
  }
50
  ?>
51
  </select>
52
- <p class="description"><?php _e( 'Custom Post Type will appear here. ', 'wp-user-frontend' );?><a target="_blank" href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/different-custom-post-type-submission-2/"><?php _e('Learn More ', 'wp-user-frontend')?></a></p>
53
  </td>
54
  </tr>
55
 
56
  <tr class="wpuf-post-status">
57
- <th><?php _e( 'Post Status', 'wp-user-frontend' ); ?></th>
58
  <td>
59
  <select name="wpuf_settings[post_status]">
60
  <?php
61
  $statuses = get_post_statuses();
62
- foreach ($statuses as $status => $label) {
63
- printf('<option value="%s"%s>%s</option>', $status, selected( $post_status_selected, $status, false ), $label );
 
64
  }
65
  ?>
66
  </select>
@@ -68,16 +69,16 @@ $draft_post = isset( $form_settings['draft_post'] ) ? $form_settings[
68
  </tr>
69
 
70
  <tr class="wpuf-post-fromat">
71
- <th><?php _e( 'Post Format', 'wp-user-frontend' ); ?></th>
72
  <td>
73
  <select name="wpuf_settings[post_format]">
74
- <option value="0"><?php _e( '- None -', 'wp-user-frontend' ); ?></option>
75
  <?php
76
  $post_formats = get_theme_support( 'post-formats' );
77
 
78
- if ( isset($post_formats[0]) && is_array( $post_formats[0] ) ) {
79
- foreach ($post_formats[0] as $format) {
80
- printf('<option value="%s"%s>%s</option>', $format, selected( $post_format_selected, $format, false ), $format );
81
  }
82
  }
83
  ?>
@@ -86,7 +87,7 @@ $draft_post = isset( $form_settings['draft_post'] ) ? $form_settings[
86
  </tr>
87
 
88
  <tr class="wpuf-default-cat">
89
- <th><?php _e( 'Default Post Category', 'wp-user-frontend' ); ?></th>
90
  <td>
91
  <?php
92
 
@@ -95,7 +96,7 @@ $draft_post = isset( $form_settings['draft_post'] ) ? $form_settings[
95
  }
96
 
97
  $post_taxonomies = get_object_taxonomies( $post_type_selected, 'objects' );
98
- $post_terms = array();
99
 
100
  foreach ( $post_taxonomies as $tax ) {
101
  if ( $tax->hierarchical ) {
@@ -103,70 +104,81 @@ $draft_post = isset( $form_settings['draft_post'] ) ? $form_settings[
103
  }
104
  }
105
 
106
- $args = array(
107
  'hide_empty' => false,
108
  'hierarchical' => true,
109
  'selected' => $default_cat,
110
- 'taxonomy' => $post_terms
111
- );
112
 
113
- echo '<select multiple name="wpuf_settings[default_cat][]">';
114
  $categories = get_terms( $args );
115
 
116
  foreach ( $categories as $category ) {
117
  $selected = '';
 
118
  if ( in_array( $category->term_id, $default_cat ) ) {
119
  $selected = 'selected ';
120
  }
121
- echo '<option ' . $selected . 'value="' . $category->term_id . '">' . $category->name . '</option>';
122
  }
123
 
124
- echo '</select>';
 
 
 
 
 
 
 
 
 
 
125
 
126
  ?>
127
- <p class="description"><?php echo __( 'If users are not allowed to choose any category, this category will be used instead (if post type supports)', 'wp-user-frontend' ); ?></p>
128
  </td>
129
  </tr>
130
 
131
  <tr class="wpuf-redirect-to">
132
- <th><?php _e( 'Redirect To', 'wp-user-frontend' ); ?></th>
133
  <td>
134
  <select name="wpuf_settings[redirect_to]">
135
  <?php
136
- $redirect_options = array(
137
  'post' => __( 'Newly created post', 'wp-user-frontend' ),
138
  'same' => __( 'Same Page', 'wp-user-frontend' ),
139
  'page' => __( 'To a page', 'wp-user-frontend' ),
140
- 'url' => __( 'To a custom URL', 'wp-user-frontend' )
141
- );
142
 
143
- foreach ($redirect_options as $to => $label) {
144
- printf('<option value="%s"%s>%s</option>', $to, selected( $redirect_to, $to, false ), $label );
145
  }
146
  ?>
147
  </select>
148
  <p class="description">
149
- <?php _e( 'After successfull submit, where the page will redirect to', $domain = 'wp-user-frontend' ) ?>
150
  </p>
151
  </td>
152
  </tr>
153
 
154
  <tr class="wpuf-same-page">
155
- <th><?php _e( 'Message to show', 'wp-user-frontend' ); ?></th>
156
  <td>
157
  <textarea rows="3" cols="40" name="wpuf_settings[message]"><?php echo esc_textarea( $message ); ?></textarea>
158
  </td>
159
  </tr>
160
 
161
  <tr class="wpuf-page-id">
162
- <th><?php _e( 'Page', 'wp-user-frontend' ); ?></th>
163
  <td>
164
  <select name="wpuf_settings[page_id]">
165
  <?php
166
- $pages = get_posts( array( 'numberposts' => -1, 'post_type' => 'page') );
167
 
168
- foreach ($pages as $page) {
169
- printf('<option value="%s"%s>%s</option>', $page->ID, selected( $page_id, $page->ID, false ), esc_attr( $page->post_title ) );
170
  }
171
  ?>
172
  </select>
@@ -174,38 +186,38 @@ $draft_post = isset( $form_settings['draft_post'] ) ? $form_settings[
174
  </tr>
175
 
176
  <tr class="wpuf-url">
177
- <th><?php _e( 'Custom URL', 'wp-user-frontend' ); ?></th>
178
  <td>
179
  <input type="url" name="wpuf_settings[url]" value="<?php echo esc_attr( $url ); ?>">
180
  </td>
181
  </tr>
182
 
183
  <tr class="wpuf-comment">
184
- <th><?php _e( 'Comment Status', 'wp-user-frontend' ); ?></th>
185
  <td>
186
  <select name="wpuf_settings[comment_status]">
187
- <option value="open" <?php selected( $comment_status, 'open'); ?>><?php _e('Open', 'wp-user-frontend'); ?></option>
188
- <option value="closed" <?php selected( $comment_status, 'closed'); ?>><?php _e('Closed', 'wp-user-frontend'); ?></option>
189
  </select>
190
  </td>
191
  </tr>
192
 
193
  <tr class="wpuf-submit-text">
194
- <th><?php _e( 'Submit Post Button text', 'wp-user-frontend' ); ?></th>
195
  <td>
196
  <input type="text" name="wpuf_settings[submit_text]" value="<?php echo esc_attr( $submit_text ); ?>">
197
  </td>
198
  </tr>
199
 
200
  <tr>
201
- <th><?php _e( 'Post Draft', 'wp-user-frontend' ); ?></th>
202
  <td>
203
  <label>
204
  <input type="hidden" name="wpuf_settings[draft_post]" value="false">
205
  <input type="checkbox" name="wpuf_settings[draft_post]" value="true"<?php checked( $draft_post, 'true' ); ?> />
206
- <?php _e( 'Enable Saving as draft', 'wp-user-frontend' ) ?>
207
  </label>
208
- <p class="description"><?php _e( 'It will show a button to save as draft', 'wp-user-frontend' ); ?></p>
209
  </td>
210
  </tr>
211
 
4
  $form_settings = wpuf_get_form_settings( $post->ID );
5
 
6
  $post_status_selected = isset( $form_settings['post_status'] ) ? $form_settings['post_status'] : 'publish';
7
+ $restrict_message = __( 'This page is restricted. Please Log in / Register to view this page.', 'wp-user-frontend' );
8
 
9
  $post_type_selected = isset( $form_settings['post_type'] ) ? $form_settings['post_type'] : 'post';
10
 
11
  $post_format_selected = isset( $form_settings['post_format'] ) ? $form_settings['post_format'] : 0;
12
+ $default_cat = !empty( $form_settings['default_cat'] ) ? $form_settings['default_cat'] : [];
13
 
14
  $redirect_to = isset( $form_settings['redirect_to'] ) ? $form_settings['redirect_to'] : 'post';
15
  $message = isset( $form_settings['message'] ) ? $form_settings['message'] : __( 'Post saved', 'wp-user-frontend' );
27
  <table class="form-table">
28
 
29
  <tr class="wpuf-post-type">
30
+ <th><?php esc_html_e( 'Post Type', 'wp-user-frontend' ); ?></th>
31
  <td>
32
  <select name="wpuf_settings[post_type]">
33
  <?php
34
  $post_types = get_post_types();
35
+ unset( $post_types['attachment'] );
36
+ unset( $post_types['revision'] );
37
+ unset( $post_types['nav_menu_item'] );
38
+ unset( $post_types['wpuf_forms'] );
39
+ unset( $post_types['wpuf_profile'] );
40
+ unset( $post_types['wpuf_input'] );
41
+ unset( $post_types['wpuf_subscription'] );
42
+ unset( $post_types['custom_css'] );
43
+ unset( $post_types['customize_changeset'] );
44
+ unset( $post_types['wpuf_coupon'] );
45
+ unset( $post_types['oembed_cache'] );
46
+
47
+ foreach ( $post_types as $post_type ) {
48
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $post_type ), esc_attr( selected( $post_type_selected, $post_type, false ) ), esc_html( $post_type ) );
49
  }
50
  ?>
51
  </select>
52
+ <p class="description"><?php esc_html_e( 'Custom Post Type will appear here. ', 'wp-user-frontend' ); ?><a target="_blank" href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/different-custom-post-type-submission-2/"><?php esc_html_e( 'Learn More ', 'wp-user-frontend' ); ?></a></p>
53
  </td>
54
  </tr>
55
 
56
  <tr class="wpuf-post-status">
57
+ <th><?php esc_html_e( 'Post Status', 'wp-user-frontend' ); ?></th>
58
  <td>
59
  <select name="wpuf_settings[post_status]">
60
  <?php
61
  $statuses = get_post_statuses();
62
+
63
+ foreach ( $statuses as $status => $label ) {
64
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $status ), esc_attr( selected( $post_status_selected, $status, false ) ), esc_html( $label ) );
65
  }
66
  ?>
67
  </select>
69
  </tr>
70
 
71
  <tr class="wpuf-post-fromat">
72
+ <th><?php esc_html_e( 'Post Format', 'wp-user-frontend' ); ?></th>
73
  <td>
74
  <select name="wpuf_settings[post_format]">
75
+ <option value="0"><?php esc_html_e( '- None -', 'wp-user-frontend' ); ?></option>
76
  <?php
77
  $post_formats = get_theme_support( 'post-formats' );
78
 
79
+ if ( isset( $post_formats[0] ) && is_array( $post_formats[0] ) ) {
80
+ foreach ( $post_formats[0] as $format ) {
81
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $format ), esc_attr( selected( $post_format_selected, $format, false ) ), esc_html( $format ) );
82
  }
83
  }
84
  ?>
87
  </tr>
88
 
89
  <tr class="wpuf-default-cat">
90
+ <th><?php esc_html_e( 'Default Post Category', 'wp-user-frontend' ); ?></th>
91
  <td>
92
  <?php
93
 
96
  }
97
 
98
  $post_taxonomies = get_object_taxonomies( $post_type_selected, 'objects' );
99
+ $post_terms = [];
100
 
101
  foreach ( $post_taxonomies as $tax ) {
102
  if ( $tax->hierarchical ) {
104
  }
105
  }
106
 
107
+ $args = [
108
  'hide_empty' => false,
109
  'hierarchical' => true,
110
  'selected' => $default_cat,
111
+ 'taxonomy' => $post_terms,
112
+ ];
113
 
114
+ $cat = '<select multiple name="wpuf_settings[default_cat][]">';
115
  $categories = get_terms( $args );
116
 
117
  foreach ( $categories as $category ) {
118
  $selected = '';
119
+
120
  if ( in_array( $category->term_id, $default_cat ) ) {
121
  $selected = 'selected ';
122
  }
123
+ $cat .= '<option ' . $selected . 'value="' . $category->term_id . '">' . $category->name . '</option>';
124
  }
125
 
126
+ $cat .='</select>';
127
+ echo wp_kses( $cat, [
128
+ 'select' => [
129
+ 'multiple' => [],
130
+ 'name' => []
131
+ ],
132
+ 'option' => [
133
+ 'selected' => [],
134
+ 'value' => [],
135
+ ]
136
+ ]);
137
 
138
  ?>
139
+ <p class="description"><?php echo esc_html( __( 'If users are not allowed to choose any category, this category will be used instead (if post type supports)', 'wp-user-frontend' ) ); ?></p>
140
  </td>
141
  </tr>
142
 
143
  <tr class="wpuf-redirect-to">
144
+ <th><?php esc_html_e( 'Redirect To', 'wp-user-frontend' ); ?></th>
145
  <td>
146
  <select name="wpuf_settings[redirect_to]">
147
  <?php
148
+ $redirect_options = [
149
  'post' => __( 'Newly created post', 'wp-user-frontend' ),
150
  'same' => __( 'Same Page', 'wp-user-frontend' ),
151
  'page' => __( 'To a page', 'wp-user-frontend' ),
152
+ 'url' => __( 'To a custom URL', 'wp-user-frontend' ),
153
+ ];
154
 
155
+ foreach ( $redirect_options as $to => $label ) {
156
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $to ), esc_attr( selected( $redirect_to, $to, false ) ), esc_html( $label ) );
157
  }
158
  ?>
159
  </select>
160
  <p class="description">
161
+ <?php esc_html_e( 'After successfull submit, where the page will redirect to', $domain = 'wp-user-frontend' ); ?>
162
  </p>
163
  </td>
164
  </tr>
165
 
166
  <tr class="wpuf-same-page">
167
+ <th><?php esc_html_e( 'Message to show', 'wp-user-frontend' ); ?></th>
168
  <td>
169
  <textarea rows="3" cols="40" name="wpuf_settings[message]"><?php echo esc_textarea( $message ); ?></textarea>
170
  </td>
171
  </tr>
172
 
173
  <tr class="wpuf-page-id">
174
+ <th><?php esc_html_e( 'Page', 'wp-user-frontend' ); ?></th>
175
  <td>
176
  <select name="wpuf_settings[page_id]">
177
  <?php
178
+ $pages = get_posts( [ 'numberposts' => -1, 'post_type' => 'page'] );
179
 
180
+ foreach ( $pages as $page ) {
181
+ printf( '<option value="%s"%s>%s</option>', esc_attr( $page->ID ), esc_attr( selected( $page_id, $page->ID, false ) ), esc_attr( $page->post_title ) );
182
  }
183
  ?>
184
  </select>
186
  </tr>
187
 
188
  <tr class="wpuf-url">
189
+ <th><?php esc_html_e( 'Custom URL', 'wp-user-frontend' ); ?></th>
190
  <td>
191
  <input type="url" name="wpuf_settings[url]" value="<?php echo esc_attr( $url ); ?>">
192
  </td>
193
  </tr>
194
 
195
  <tr class="wpuf-comment">
196
+ <th><?php esc_html_e( 'Comment Status', 'wp-user-frontend' ); ?></th>
197
  <td>
198
  <select name="wpuf_settings[comment_status]">
199
+ <option value="open" <?php selected( $comment_status, 'open' ); ?>><?php esc_html_e( 'Open', 'wp-user-frontend' ); ?></option>
200
+ <option value="closed" <?php selected( $comment_status, 'closed' ); ?>><?php esc_html_e( 'Closed', 'wp-user-frontend' ); ?></option>
201
  </select>
202
  </td>
203
  </tr>
204
 
205
  <tr class="wpuf-submit-text">
206
+ <th><?php esc_html_e( 'Submit Post Button text', 'wp-user-frontend' ); ?></th>
207
  <td>
208
  <input type="text" name="wpuf_settings[submit_text]" value="<?php echo esc_attr( $submit_text ); ?>">
209
  </td>
210
  </tr>
211
 
212
  <tr>
213
+ <th><?php esc_html_e( 'Post Draft', 'wp-user-frontend' ); ?></th>
214
  <td>
215
  <label>
216
  <input type="hidden" name="wpuf_settings[draft_post]" value="false">
217
  <input type="checkbox" name="wpuf_settings[draft_post]" value="true"<?php checked( $draft_post, 'true' ); ?> />
218
+ <?php esc_html_e( 'Enable Saving as draft', 'wp-user-frontend' ); ?>
219
  </label>
220
+ <p class="description"><?php esc_html_e( 'It will show a button to save as draft', 'wp-user-frontend' ); ?></p>
221
  </td>
222
  </tr>
223
 
admin/html/form-submission-restriction.php CHANGED
@@ -5,7 +5,7 @@ $form_settings = wpuf_get_form_settings( $post->ID );
5
 
6
  $guest_post = !empty( $form_settings['guest_post'] ) ? $form_settings['guest_post'] : 'false';
7
  $role_base = !empty( $form_settings['role_base'] ) ? $form_settings['role_base'] : 'false';
8
- $roles = !empty( $form_settings['roles'] ) ? $form_settings['roles'] : array( 'administrator' );
9
  $guest_details = !empty( $form_settings['guest_details'] ) ? $form_settings['guest_details'] : 'true';
10
  $guest_email_verify = !empty( $form_settings['guest_email_verify'] ) ? $form_settings['guest_email_verify'] : 'false';
11
  $name_label = !empty( $form_settings['name_label'] ) ? $form_settings['name_label'] : __( 'Name', 'wp-user-frontend' );
@@ -19,169 +19,169 @@ $form_pending_message = !empty( $form_settings['form_pending_message'] ) ? $fo
19
  $form_expired_message = !empty( $form_settings['form_expired_message'] ) ? $form_settings['form_expired_message'] : 'Submission date expired.';
20
 
21
  $limit_entries = !empty( $form_settings['limit_entries'] ) ? $form_settings['limit_entries'] : 'false';
22
- $limit_number = !empty( $form_settings['limit_number'] ) ? $form_settings['limit_number'] : 100;
23
  $limit_message = !empty( $form_settings['limit_message'] ) ? $form_settings['limit_message'] : 'Form submission limit exceeded';
24
  ?>
25
  <table class="form-table">
26
 
27
  <!-- Added Submission Restriction Settings -->
28
  <tr>
29
- <th><?php _e( 'Guest Post', 'wp-user-frontend' ); ?></th>
30
  <td>
31
  <label>
32
  <input type="hidden" name="wpuf_settings[guest_post]" value="false">
33
  <input type="checkbox" name="wpuf_settings[guest_post]" value="true"<?php checked( $guest_post, 'true' ); ?> />
34
- <?php _e( 'Enable Guest Post', 'wp-user-frontend' ) ?>
35
  </label>
36
- <p class="description"><?php _e( 'Unregistered users will be able to submit posts', 'wp-user-frontend' ); ?>. <a href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/guest-posting/"><?php _e( 'Learn more about guest posting.', 'wp-user-frontend' ); ?></a></p>
37
  </td>
38
  </tr>
39
 
40
  <tr class="show-if-guest">
41
- <th>&mdash; <?php _e( 'User Details', 'wp-user-frontend' ); ?></th>
42
  <td>
43
  <label>
44
  <input type="hidden" name="wpuf_settings[guest_details]" value="false">
45
  <input type="checkbox" name="wpuf_settings[guest_details]" value="true"<?php checked( $guest_details, 'true' ); ?> />
46
- <?php _e( 'Require Name and Email address', 'wp-user-frontend' ) ?>
47
  </label>
48
- <p class="description"><?php _e( 'If requires, users will be automatically registered to the site using the name and email address', 'wp-user-frontend' ); ?></p>
49
  </td>
50
  </tr>
51
 
52
  <tr class="show-if-guest show-if-details">
53
- <th>&mdash; &mdash; <?php _e( 'Name Label', 'wp-user-frontend' ); ?></th>
54
  <td>
55
  <label>
56
  <input type="text" name="wpuf_settings[name_label]" value="<?php echo esc_attr( $name_label ); ?>" />
57
  </label>
58
- <p class="description"><?php _e( 'Label text for name field', 'wp-user-frontend' ); ?></p>
59
  </td>
60
  </tr>
61
 
62
  <tr class="show-if-guest show-if-details">
63
- <th>&mdash; &mdash; <?php _e( 'E-Mail Label', 'wp-user-frontend' ); ?></th>
64
  <td>
65
  <label>
66
  <input type="text" name="wpuf_settings[email_label]" value="<?php echo esc_attr( $email_label ); ?>" />
67
  </label>
68
- <p class="description"><?php _e( 'Label text for email field', 'wp-user-frontend' ); ?></p>
69
  </td>
70
  </tr>
71
 
72
  <tr class="show-if-guest">
73
- <th>&mdash; <?php _e( 'Email Verification', 'wp-user-frontend' ); ?></th>
74
  <td>
75
  <label>
76
  <input type="checkbox" name="wpuf_settings[guest_email_verify]" value="true"<?php checked( $guest_email_verify, 'true' ); ?> />
77
- <?php _e( 'Require Email Verification for Guests', 'wp-user-frontend' ) ?>
78
  </label>
79
- <p class="description"><?php _e( 'If requires, users will be required to verify their email adress.', 'wp-user-frontend' ); ?></p>
80
  </td>
81
  </tr>
82
 
83
  <tr class="show-if-not-guest">
84
- <th>&mdash; <?php _e( 'Role Base', 'wp-user-frontend' ); ?></th>
85
  <td>
86
  <label>
87
  <input type="hidden" name="wpuf_settings[role_base]" value="false">
88
  <input type="checkbox" name="wpuf_settings[role_base]" value="true"<?php checked( $role_base, 'true' ); ?> />
89
- <?php _e( 'Enable role base post', 'wp-user-frontend' ) ?>
90
  </label>
91
- <p class="description"><?php _e( 'You can choose which role can submit posts by this form.', 'wp-user-frontend' ); ?></p>
92
  </td>
93
  </tr>
94
 
95
  <tr class="show-if-not-guest show-if-roles">
96
- <th>&mdash; &mdash; <?php _e( 'Roles', 'wp-user-frontend' ); ?></th>
97
  <td>
98
  <?php
99
  foreach ( wpuf_get_user_roles() as $key => $role ) { ?>
100
  <label>
101
- <input type="checkbox" name="wpuf_settings[roles][]" value="<?php echo $key; ?>"
102
- <?php echo in_array($key, $roles) || 'administrator' == $key ? 'checked="checked"' : '';
103
  echo 'administrator' == $key ? 'disabled' : '';
104
  ?> />
105
- <?php echo $role; ?>
106
  </label><br>
107
  <?php } ?>
108
  <input type="hidden" name="wpuf_settings[roles][]" value="administrator">
109
- <p class="description"><?php _e( 'Choose which roles can submit posts.', 'wp-user-frontend' ); ?></p>
110
  </td>
111
  </tr>
112
 
113
  <tr class="show-if-not-guest">
114
- <th>&mdash; <?php _e( 'Unauthorized Message', 'wp-user-frontend' ); ?></th>
115
  <td>
116
  <textarea rows="3" cols="40" name="wpuf_settings[message_restrict]"><?php echo esc_textarea( $message_restrict ); ?></textarea>
117
- <p class="description"><?php _e( 'Not logged in users will see this message', 'wp-user-frontend' ); ?></p>
118
  </td>
119
  </tr>
120
 
121
  <tr>
122
- <th><?php _e( 'Schedule form', 'wp-user-frontend' ); ?></th>
123
  <td>
124
  <label>
125
  <input type="hidden" name="wpuf_settings[schedule_form]" value="false">
126
  <input type="checkbox" name="wpuf_settings[schedule_form]" value="true"<?php checked( $schedule_form, 'true' ); ?> />
127
- <?php _e( 'Schedule form for a period', 'wp-user-frontend' ) ?>
128
  </label>
129
- <p class="description"><?php _e( 'Schedule for a time period the form is active.', 'wp-user-frontend' ); ?></p>
130
  </td>
131
  </tr>
132
 
133
  <tr class="show-if-schedule">
134
- <th>&mdash; <?php _e( 'Schedule Period', 'wp-user-frontend' ); ?></th>
135
  <td>
136
 
137
- <?php _e( 'From', 'wp-user-frontend' ); ?>
138
- <input type="text" name="wpuf_settings[schedule_start]" id="schedule_start" value="<?php echo $schedule_start; ?>" class="datepicker">
139
  <!-- <datepicker name="wpuf_settings[schedule_start]"></datepicker> -->
140
 
141
- <?php _e( 'To', 'wp-user-frontend' ); ?>
142
- <input type="text" name="wpuf_settings[schedule_end]" id="schedule_end" value="<?php echo $schedule_end; ?>" class="datepicker">
143
  <!-- <datepicker name="wpuf_settings[schedule_end]"></datepicker> -->
144
  </td>
145
  </tr>
146
 
147
  <tr class="show-if-schedule">
148
- <th>&mdash; <?php _e( 'Form Pending Message', 'wp-user-frontend' ); ?></th>
149
  <td>
150
  <textarea rows="3" cols="40" name="wpuf_settings[form_pending_message]"><?php echo esc_textarea( $form_pending_message ); ?></textarea>
151
  </td>
152
  </tr>
153
 
154
  <tr class="show-if-schedule">
155
- <th>&mdash; <?php _e( 'Form Expired Message', 'wp-user-frontend' ); ?></th>
156
  <td>
157
  <textarea rows="3" cols="40" name="wpuf_settings[form_expired_message]"><?php echo esc_textarea( $form_expired_message ); ?></textarea>
158
  </td>
159
  </tr>
160
 
161
  <tr class="wpuf-limit-entries">
162
- <th><?php _e( 'Limit Entries', 'wp-user-frontend' ); ?></th>
163
  <td>
164
  <label>
165
  <input type="hidden" name="wpuf_settings[limit_entries]" value="false">
166
  <input type="checkbox" name="wpuf_settings[limit_entries]" value="true"<?php checked( $limit_entries, 'true' ); ?> />
167
- <?php _e( 'Enable form entry limit', 'wp-user-frontend' ); ?>
168
  </label>
169
 
170
  <p class="description">
171
- <?php _e( 'Limit the number of entries allowed for this form', 'wp-user-frontend' ) ?>
172
  </p>
173
  </td>
174
  </tr>
175
 
176
  <tr class="show-if-limit-entries">
177
- <th>&mdash; <?php _e( 'Number of Entries', 'wp-user-frontend' ); ?></th>
178
  <td>
179
  <input type="number" value="<?php echo esc_attr( $limit_number ); ?>" name="wpuf_settings[limit_number]">
180
  </td>
181
  </tr>
182
 
183
  <tr class="show-if-limit-entries">
184
- <th>&mdash; <?php _e( 'Limit Reached Message', 'wp-user-frontend' ); ?></th>
185
  <td>
186
  <textarea rows="3" cols="40" name="wpuf_settings[limit_message]"><?php echo esc_textarea( $limit_message ); ?></textarea>
187
  </td>
5
 
6
  $guest_post = !empty( $form_settings['guest_post'] ) ? $form_settings['guest_post'] : 'false';
7
  $role_base = !empty( $form_settings['role_base'] ) ? $form_settings['role_base'] : 'false';
8
+ $roles = !empty( $form_settings['roles'] ) ? $form_settings['roles'] : [ 'administrator' ];
9
  $guest_details = !empty( $form_settings['guest_details'] ) ? $form_settings['guest_details'] : 'true';
10
  $guest_email_verify = !empty( $form_settings['guest_email_verify'] ) ? $form_settings['guest_email_verify'] : 'false';
11
  $name_label = !empty( $form_settings['name_label'] ) ? $form_settings['name_label'] : __( 'Name', 'wp-user-frontend' );
19
  $form_expired_message = !empty( $form_settings['form_expired_message'] ) ? $form_settings['form_expired_message'] : 'Submission date expired.';
20
 
21
  $limit_entries = !empty( $form_settings['limit_entries'] ) ? $form_settings['limit_entries'] : 'false';
22
+ $limit_number = !empty( $form_settings['limit_number'] ) ? $form_settings['limit_number'] : 100;
23
  $limit_message = !empty( $form_settings['limit_message'] ) ? $form_settings['limit_message'] : 'Form submission limit exceeded';
24
  ?>
25
  <table class="form-table">
26
 
27
  <!-- Added Submission Restriction Settings -->
28
  <tr>
29
+ <th><?php esc_html_e( 'Guest Post', 'wp-user-frontend' ); ?></th>
30
  <td>
31
  <label>
32
  <input type="hidden" name="wpuf_settings[guest_post]" value="false">
33
  <input type="checkbox" name="wpuf_settings[guest_post]" value="true"<?php checked( $guest_post, 'true' ); ?> />
34
+ <?php esc_html_e( 'Enable Guest Post', 'wp-user-frontend' ); ?>
35
  </label>
36
+ <p class="description"><?php esc_html_e( 'Unregistered users will be able to submit posts', 'wp-user-frontend' ); ?>. <a href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/guest-posting/"><?php esc_html_e( 'Learn more about guest posting.', 'wp-user-frontend' ); ?></a></p>
37
  </td>
38
  </tr>
39
 
40
  <tr class="show-if-guest">
41
+ <th>&mdash; <?php esc_html_e( 'User Details', 'wp-user-frontend' ); ?></th>
42
  <td>
43
  <label>
44
  <input type="hidden" name="wpuf_settings[guest_details]" value="false">
45
  <input type="checkbox" name="wpuf_settings[guest_details]" value="true"<?php checked( $guest_details, 'true' ); ?> />
46
+ <?php esc_html_e( 'Require Name and Email address', 'wp-user-frontend' ); ?>
47
  </label>
48
+ <p class="description"><?php esc_html_e( 'If requires, users will be automatically registered to the site using the name and email address', 'wp-user-frontend' ); ?></p>
49
  </td>
50
  </tr>
51
 
52
  <tr class="show-if-guest show-if-details">
53
+ <th>&mdash; &mdash; <?php esc_html_e( 'Name Label', 'wp-user-frontend' ); ?></th>
54
  <td>
55
  <label>
56
  <input type="text" name="wpuf_settings[name_label]" value="<?php echo esc_attr( $name_label ); ?>" />
57
  </label>
58
+ <p class="description"><?php esc_html_e( 'Label text for name field', 'wp-user-frontend' ); ?></p>
59
  </td>
60
  </tr>
61
 
62
  <tr class="show-if-guest show-if-details">
63
+ <th>&mdash; &mdash; <?php esc_html_e( 'E-Mail Label', 'wp-user-frontend' ); ?></th>
64
  <td>
65
  <label>
66
  <input type="text" name="wpuf_settings[email_label]" value="<?php echo esc_attr( $email_label ); ?>" />
67
  </label>
68
+ <p class="description"><?php esc_html_e( 'Label text for email field', 'wp-user-frontend' ); ?></p>
69
  </td>
70
  </tr>
71
 
72
  <tr class="show-if-guest">
73
+ <th>&mdash; <?php esc_html_e( 'Email Verification', 'wp-user-frontend' ); ?></th>
74
  <td>
75
  <label>
76
  <input type="checkbox" name="wpuf_settings[guest_email_verify]" value="true"<?php checked( $guest_email_verify, 'true' ); ?> />
77
+ <?php esc_html_e( 'Require Email Verification for Guests', 'wp-user-frontend' ); ?>
78
  </label>
79
+ <p class="description"><?php esc_html_e( 'If requires, users will be required to verify their email adress.', 'wp-user-frontend' ); ?></p>
80
  </td>
81
  </tr>
82
 
83
  <tr class="show-if-not-guest">
84
+ <th>&mdash; <?php esc_html_e( 'Role Base', 'wp-user-frontend' ); ?></th>
85
  <td>
86
  <label>
87
  <input type="hidden" name="wpuf_settings[role_base]" value="false">
88
  <input type="checkbox" name="wpuf_settings[role_base]" value="true"<?php checked( $role_base, 'true' ); ?> />
89
+ <?php esc_html_e( 'Enable role base post', 'wp-user-frontend' ); ?>
90
  </label>
91
+ <p class="description"><?php esc_html_e( 'You can choose which role can submit posts by this form.', 'wp-user-frontend' ); ?></p>
92
  </td>
93
  </tr>
94
 
95
  <tr class="show-if-not-guest show-if-roles">
96
+ <th>&mdash; &mdash; <?php esc_html_e( 'Roles', 'wp-user-frontend' ); ?></th>
97
  <td>
98
  <?php
99
  foreach ( wpuf_get_user_roles() as $key => $role ) { ?>
100
  <label>
101
+ <input type="checkbox" name="wpuf_settings[roles][]" value="<?php echo esc_attr( $key ); ?>"
102
+ <?php echo in_array( $key, $roles ) || 'administrator' == $key ? 'checked="checked"' : '';
103
  echo 'administrator' == $key ? 'disabled' : '';
104
  ?> />
105
+ <?php echo esc_html( $role ); ?>
106
  </label><br>
107
  <?php } ?>
108
  <input type="hidden" name="wpuf_settings[roles][]" value="administrator">
109
+ <p class="description"><?php esc_html_e( 'Choose which roles can submit posts.', 'wp-user-frontend' ); ?></p>
110
  </td>
111
  </tr>
112
 
113
  <tr class="show-if-not-guest">
114
+ <th>&mdash; <?php esc_html_e( 'Unauthorized Message', 'wp-user-frontend' ); ?></th>
115
  <td>
116
  <textarea rows="3" cols="40" name="wpuf_settings[message_restrict]"><?php echo esc_textarea( $message_restrict ); ?></textarea>
117
+ <p class="description"><?php esc_html_e( 'Not logged in users will see this message', 'wp-user-frontend' ); ?></p>
118
  </td>
119
  </tr>
120
 
121
  <tr>
122
+ <th><?php esc_html_e( 'Schedule form', 'wp-user-frontend' ); ?></th>
123
  <td>
124
  <label>
125
  <input type="hidden" name="wpuf_settings[schedule_form]" value="false">
126
  <input type="checkbox" name="wpuf_settings[schedule_form]" value="true"<?php checked( $schedule_form, 'true' ); ?> />
127
+ <?php esc_html_e( 'Schedule form for a period', 'wp-user-frontend' ); ?>
128
  </label>
129
+ <p class="description"><?php esc_html_e( 'Schedule for a time period the form is active.', 'wp-user-frontend' ); ?></p>
130
  </td>
131
  </tr>
132
 
133
  <tr class="show-if-schedule">
134
+ <th>&mdash; <?php esc_html_e( 'Schedule Period', 'wp-user-frontend' ); ?></th>
135
  <td>
136
 
137
+ <?php esc_html_e( 'From', 'wp-user-frontend' ); ?>
138
+ <input type="text" name="wpuf_settings[schedule_start]" id="schedule_start" value="<?php echo esc_attr( $schedule_start ); ?>" class="datepicker">
139
  <!-- <datepicker name="wpuf_settings[schedule_start]"></datepicker> -->
140
 
141
+ <?php esc_html_e( 'To', 'wp-user-frontend' ); ?>
142
+ <input type="text" name="wpuf_settings[schedule_end]" id="schedule_end" value="<?php echo esc_attr( $schedule_end ); ?>" class="datepicker">
143
  <!-- <datepicker name="wpuf_settings[schedule_end]"></datepicker> -->
144
  </td>
145
  </tr>
146
 
147
  <tr class="show-if-schedule">
148
+ <th>&mdash; <?php esc_html_e( 'Form Pending Message', 'wp-user-frontend' ); ?></th>
149
  <td>
150
  <textarea rows="3" cols="40" name="wpuf_settings[form_pending_message]"><?php echo esc_textarea( $form_pending_message ); ?></textarea>
151
  </td>
152
  </tr>
153
 
154
  <tr class="show-if-schedule">
155
+ <th>&mdash; <?php esc_html_e( 'Form Expired Message', 'wp-user-frontend' ); ?></th>
156
  <td>
157
  <textarea rows="3" cols="40" name="wpuf_settings[form_expired_message]"><?php echo esc_textarea( $form_expired_message ); ?></textarea>
158
  </td>
159
  </tr>
160
 
161
  <tr class="wpuf-limit-entries">
162
+ <th><?php esc_html_e( 'Limit Entries', 'wp-user-frontend' ); ?></th>
163
  <td>
164
  <label>
165
  <input type="hidden" name="wpuf_settings[limit_entries]" value="false">
166
  <input type="checkbox" name="wpuf_settings[limit_entries]" value="true"<?php checked( $limit_entries, 'true' ); ?> />
167
+ <?php esc_html_e( 'Enable form entry limit', 'wp-user-frontend' ); ?>
168
  </label>
169
 
170
  <p class="description">
171
+ <?php esc_html_e( 'Limit the number of entries allowed for this form', 'wp-user-frontend' ); ?>
172
  </p>
173
  </td>
174
  </tr>
175
 
176
  <tr class="show-if-limit-entries">
177
+ <th>&mdash; <?php esc_html_e( 'Number of Entries', 'wp-user-frontend' ); ?></th>
178
  <td>
179
  <input type="number" value="<?php echo esc_attr( $limit_number ); ?>" name="wpuf_settings[limit_number]">
180
  </td>
181
  </tr>
182
 
183
  <tr class="show-if-limit-entries">
184
+ <th>&mdash; <?php esc_html_e( 'Limit Reached Message', 'wp-user-frontend' ); ?></th>
185
  <td>
186
  <textarea rows="3" cols="40" name="wpuf_settings[limit_message]"><?php echo esc_textarea( $limit_message ); ?></textarea>
187
  </td>
admin/html/modal.php CHANGED
@@ -1,17 +1,17 @@
1
  <div id="wpuf-form-template-modal">
2
  <div class="wpuf-form-template-modal">
3
 
4
- <span id="modal-label" class="screen-reader-text"><?php _e( 'Modal window. Press escape to close.', 'wp-user-frontend' ); ?></span>
5
- <a href="#" class="close">× <span class="screen-reader-text"><?php _e( 'Close modal window', 'wp-user-frontend' ); ?></span></a>
6
 
7
  <header class="modal-header">
8
  <h2>
9
- <?php _e( 'Select a Template', 'wp-user-frontend' ); ?>
10
  <small><?php
11
  printf(
12
- __( 'Select from a pre-defined template or from a <a href="%s">blank form</a>', 'wp-user-frontend' ),
13
- $blank_form_url
14
- ); ?></small>
15
  </h2>
16
  </header>
17
 
@@ -20,67 +20,69 @@
20
 
21
  <ul>
22
  <li class="blank-form">
23
- <h3><?php _e( 'Blank Form', 'wp-user-frontend' ); ?></h3>
24
 
25
  <div class="form-middle-text">
26
  <span class="dashicons dashicons-plus"></span>
27
- <div class="title"><?php _e( 'Blank Form', 'wp-user-frontend' ); ?></div>
28
  </div>
29
 
30
  <div class="form-create-overlay">
31
- <div class="title"><?php _e( 'Blank Form', 'wp-user-frontend' ); ?></div>
32
  <br>
33
- <a href="<?php echo $blank_form_url; ?>" class="button button-primary" title="<?php echo esc_attr('Blank Form'); ?>">
34
- <?php _e('Create Form', 'wp-user-frontend' ); ?>
35
  </a>
36
  </div>
37
  </li>
38
 
39
  <?php
40
- foreach ($registry as $key => $template ) {
41
- $class = 'template-active';
42
- $title = $template->title;
43
- $image = $template->image ? $template->image : '';
44
  $disabled = '';
45
 
46
- $url = esc_url( add_query_arg( array(
47
  'action' => $action_name,
48
  'template' => $key,
49
- '_wpnonce' => wp_create_nonce( 'wpuf_create_from_template' )
50
- ), admin_url( 'admin.php' ) ) );
51
 
52
- if ( ! $template->is_enabled() ) {
53
- $url = '#';
54
- $class = 'template-inactive';
55
- $title = __( 'This integration is not installed.', 'wp-user-frontend' );
56
  $disabled = 'disabled';
57
- }
58
- ?>
59
 
60
- <li class="<?php echo $class; ?>">
61
- <h3><?php echo $template->get_title(); ?></h3>
62
- <?php if ( $image ) { printf( '<img src="%s" alt="%s">', $image, $title ); } ?>
 
 
63
 
64
  <div class="form-create-overlay">
65
- <div class="title"><?php echo $title; ?></div>
66
- <div class="description"><?php echo $template->get_description(); ?></div>
67
  <br>
68
- <a href="<?php echo $url; ?>" class="button button-primary" title="<?php echo $template->get_title(); ?>" <?php echo $disabled ?>>
69
- <?php _e('Create Form', 'wp-user-frontend' ); ?>
70
  </a>
71
  </div>
72
  </li>
73
 
74
- <?php } ?>
 
75
  </ul>
76
  </div>
77
  </div>
78
 
79
- <?php if ( $footer_help ) : ?>
80
  <footer>
81
- <?php echo $footer_help; ?>
82
  </footer>
83
- <?php endif; ?>
84
  </div>
85
  <div class="wpuf-form-template-modal-backdrop"></div>
86
  </div>
1
  <div id="wpuf-form-template-modal">
2
  <div class="wpuf-form-template-modal">
3
 
4
+ <span id="modal-label" class="screen-reader-text"><?php esc_html_e( 'Modal window. Press escape to close.', 'wp-user-frontend' ); ?></span>
5
+ <a href="#" class="close">× <span class="screen-reader-text"><?php esc_html_e( 'Close modal window', 'wp-user-frontend' ); ?></span></a>
6
 
7
  <header class="modal-header">
8
  <h2>
9
+ <?php esc_html_e( 'Select a Template', 'wp-user-frontend' ); ?>
10
  <small><?php
11
  printf(
12
+ wp_kses_post( __( 'Select from a pre-defined template or from a <a href="%s">blank form</a>', 'wp-user-frontend' ) ),
13
+ esc_attr( $blank_form_url )
14
+ ); ?></small>
15
  </h2>
16
  </header>
17
 
20
 
21
  <ul>
22
  <li class="blank-form">
23
+ <h3><?php esc_html_e( 'Blank Form', 'wp-user-frontend' ); ?></h3>
24
 
25
  <div class="form-middle-text">
26
  <span class="dashicons dashicons-plus"></span>
27
+ <div class="title"><?php esc_html_e( 'Blank Form', 'wp-user-frontend' ); ?></div>
28
  </div>
29
 
30
  <div class="form-create-overlay">
31
+ <div class="title"><?php esc_html_e( 'Blank Form', 'wp-user-frontend' ); ?></div>
32
  <br>
33
+ <a href="<?php echo esc_url( $blank_form_url ); ?>" class="button button-primary" title="<?php echo esc_attr( 'Blank Form' ); ?>">
34
+ <?php esc_html_e( 'Create Form', 'wp-user-frontend' ); ?>
35
  </a>
36
  </div>
37
  </li>
38
 
39
  <?php
40
+ foreach ( $registry as $key => $template ) {
41
+ $class = 'template-active';
42
+ $title = $template->title;
43
+ $image = $template->image ? $template->image : '';
44
  $disabled = '';
45
 
46
+ $url = esc_url( add_query_arg( [
47
  'action' => $action_name,
48
  'template' => $key,
49
+ '_wpnonce' => wp_create_nonce( 'wpuf_create_from_template' ),
50
+ ], admin_url( 'admin.php' ) ) );
51
 
52
+ if ( !$template->is_enabled() ) {
53
+ $url = '#';
54
+ $class = 'template-inactive';
55
+ $title = __( 'This integration is not installed.', 'wp-user-frontend' );
56
  $disabled = 'disabled';
57
+ } ?>
 
58
 
59
+ <li class="<?php echo esc_attr( $class ); ?>">
60
+ <h3><?php echo esc_html( $template->get_title() ); ?></h3>
61
+ <?php if ( $image ) {
62
+ printf( '<img src="%s" alt="%s">', esc_attr( $image ), esc_attr( $title ) );
63
+ } ?>
64
 
65
  <div class="form-create-overlay">
66
+ <div class="title"><?php echo esc_html( $title ); ?></div>
67
+ <div class="description"><?php echo esc_html( $template->get_description() ); ?></div>
68
  <br>
69
+ <a href="<?php echo esc_url( $url ); ?>" class="button button-primary" title="<?php echo esc_attr( $template->get_title() ); ?>" <?php echo esc_attr($disabled ); ?>>
70
+ <?php esc_html_e( 'Create Form', 'wp-user-frontend' ); ?>
71
  </a>
72
  </div>
73
  </li>
74
 
75
+ <?php
76
+ } ?>
77
  </ul>
78
  </div>
79
  </div>
80
 
81
+ <?php if ( $footer_help ) { ?>
82
  <footer>
83
+ <?php echo wp_kses_post( $footer_help ); ?>
84
  </footer>
85
+ <?php } ?>
86
  </div>
87
  <div class="wpuf-form-template-modal-backdrop"></div>
88
  </div>
admin/html/support.php CHANGED
@@ -1,190 +1,190 @@
1
  <?php
2
  $current_user = wp_get_current_user();
3
 
4
- $articles = array(
5
- 'setup' => array(
6
- array(
7
  'title' => 'How to Install',
8
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/getting-started/how-to-install/'
9
- ),
10
- array(
11
  'title' => 'License Activation',
12
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/troubleshoot/license-activation/'
13
- ),
14
- array(
15
  'title' => 'Shortcodes',
16
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/getting-started/wpuf-shortcodes/'
17
- ),
18
- array(
19
  'title' => 'User Dashboard',
20
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/getting-started/user-dashboard/'
21
- ),
22
- ),
23
- 'posting' => array(
24
- array(
25
  'title' => 'Creating Posting Forms',
26
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/creating-posting-forms/'
27
- ),
28
- array(
29
  'title' => 'Available Form Elements',
30
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/form-elements/'
31
- ),
32
- array(
33
  'title' => 'Creating Forms Using The Form Templates',
34
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/form-templates/'
35
- ),
36
- array(
37
  'title' => 'How to Allow Guest Posting',
38
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/guest-posting/'
39
- ),
40
- array(
41
  'title' => 'Setup Automatic Post Expiration',
42
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/using-post-expiration-wp-user-frontend/'
43
- ),
44
- array(
45
  'title' => 'How to create Multistep forms',
46
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/how-to-add-multi-step-form/'
47
- ),
48
- ),
49
- 'dashboard' => array(
50
- array(
51
  'title' => 'Setting up Frontend Dashboard for Users',
52
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/frontend/configuring-dashboard-settings/'
53
- ),
54
- array(
55
  'title' => 'Unified My Account Page',
56
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/frontend/how-to-create-my-account-page/'
57
- ),
58
- array(
59
  'title' => 'Showing meta fields in frontend',
60
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/frontend/showing-meta-fields-in-frontend/'
61
- ),
62
- ),
63
- 'settings' => array(
64
- array(
65
  'title' => 'General Options',
66
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/settings/configuring-general-options/'
67
- ),
68
- array(
69
  'title' => 'Dashboard Settings',
70
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/settings/configuring-dashboard-settings/'
71
- ),
72
- array(
73
  'title' => 'Login Registration Settings',
74
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/settings/login-registration-settings/'
75
- ),
76
- array(
77
  'title' => 'Payment Settings',
78
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/settings/configuring-payment-settings/'
79
- ),
80
- ),
81
- 'registration' => array(
82
- array(
83
  'title' => 'Creating Registration Form',
84
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-forms/'
85
- ),
86
- array(
87
  'title' => 'Creating a Multistep Registration Form',
88
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/creating-a-multistep-registration-form/'
89
- ),
90
- array(
91
  'title' => 'Setting Up Confirmation Message',
92
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/setup-confirmation-message/'
93
- ),
94
- array(
95
  'title' => 'Paid Membership Registration',
96
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/paid-membership-registration/'
97
- ),
98
- array(
99
  'title' => 'Setting Up Email Verification for New Users',
100
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/setting-up-email-verification-for-new-users/'
101
- ),
102
- ),
103
- 'profile' => array(
104
- array(
105
  'title' => 'Creating a Profile Editing Form',
106
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/wordpress-edit-user-profile-from-front-end/'
107
- ),
108
- ),
109
- 'subscription' => array(
110
- array(
111
  'title' => 'Creating Subscription Packs',
112
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/creating-subscription-packs/'
113
- ),
114
- array(
115
  'title' => 'Payment & Gateway Settings',
116
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/configuring-payment-settings/'
117
- ),
118
- array(
119
  'title' => 'Setting Up Recurring Payment',
120
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/setting-up-recurring-payment/'
121
- ),
122
- array(
123
  'title' => 'Forcing Subscription Pack For Post Submission',
124
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/forcing-subscription-pack-for-post-submission/'
125
- ),
126
- array(
127
  'title' => 'How to Charge for Each Post Submission?',
128
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/how-to-charge-for-each-post-submission/'
129
- ),
130
- array(
131
  'title' => 'Creating Coupons',
132
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/coupons/'
133
- ),
134
- ),
135
 
136
- 'developer' => array(
137
- array(
138
  'title' => 'Action Hook Field',
139
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/action-hook-field/'
140
- ),
141
- array(
142
  'title' => 'Add a New Tab on My Account Page',
143
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/add-a-new-tab-on-my-account-page/'
144
- ),
145
- array(
146
  'title' => 'Insert/update checkbox or radio field data as serialize',
147
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/insertupdate-checkbox-or-radio-field-data-as-serialize/'
148
- ),
149
- array(
150
  'title' => 'Filters',
151
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/filters/'
152
- ),
153
- array(
154
  'title' => 'Actions',
155
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/actions/'
156
- ),
157
- array(
158
  'title' => 'Changelog',
159
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/changelog/'
160
- ),
161
- ),
162
- 'restriction' => array(
163
- array(
164
  'title' => 'Content Restriction for Logged in Users',
165
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/content-restriction/'
166
- ),
167
- array(
168
  'title' => 'Restricting Content by User Roles',
169
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/restricting-content-by-user-roles/'
170
- ),
171
- array(
172
  'title' => 'Restricting Contents for Different Subscription Packs',
173
- 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/restricting-contents-for-different-subscription-packs/'
174
- ),
175
- )
176
- );
177
 
178
  /**
179
  * Print related articles
180
  *
181
- * @param array $articles
182
  *
183
  * @return void
184
  */
185
  function wpuf_help_related_articles( $articles ) {
186
  ?>
187
- <h2><?php _e( 'Related Articles:', 'wp-user-frontend' ); ?></h2>
188
 
189
  <ul class="related-articles">
190
  <?php
@@ -192,36 +192,35 @@ function wpuf_help_related_articles( $articles ) {
192
  ?>
193
  <li>
194
  <span class="dashicons dashicons-media-text"></span>
195
- <a href="<?php echo trailingslashit( $article['link'] ); ?>?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=<?php echo sanitize_title( $article['title'] ); ?>" target="_blank"><?php echo $article['title']; ?></a>
196
  </li>
197
  <?php
198
- }
199
- ?>
200
  </ul>
201
  <?php
202
  }
203
  ?>
204
 
205
  <div class="wrap wpuf-help-page">
206
- <h1><?php _e( 'General Help Questions', 'wp-user-frontend' ); ?> <a href="https://wedevs.com/docs/wp-user-frontend-pro/?utm_source=wpuf-help-page&utm_medium=button-primary&utm_campaign=view-all-docs" target="_blank" class="page-title-action"><span class="dashicons dashicons-external" style="margin-top: 8px;"></span> <?php _e( 'View all Documentations', 'wp-user-frontend' ); ?></a></h1>
207
 
208
  <form class="wpuf-subscribe-box" id="wpuf-form-subscribe" action="https://wedevs.us16.list-manage.com/subscribe/post-json?u=66e606cfe0af264974258f030&id=0d176bb256&c=?" method="get">
209
 
210
  <div class="text-wrap">
211
- <h3><?php _e( 'Subscribe to Our Newsletter', 'wp-user-frontend' ); ?></h3>
212
  <p>
213
- <?php _e( 'Subscribe to our newsletter for regular <strong>tips</strong>, <strong>offers</strong> and <strong>news updates</strong>.', 'wp-user-frontend' ); ?>
214
  </p>
215
  </div>
216
 
217
  <div class="form-wrap">
218
  <div class="fname">
219
- <label for="fname"><?php _e( 'First Name', 'wp-user-frontend' ); ?></label>
220
  <input type="text" name="FNAME" id="fname" class="regular-text" value="<?php echo esc_attr( $current_user->first_name ); ?>" required>
221
  </div>
222
 
223
  <div class="email">
224
- <label for="email"><?php _e( 'Email', 'wp-user-frontend' ); ?></label>
225
  <input type="email" name="EMAIL" id="email" class="regular-text" value="<?php echo esc_attr( $current_user->user_email ); ?>" required>
226
  </div>
227
 
@@ -238,49 +237,49 @@ function wpuf_help_related_articles( $articles ) {
238
  <li class="tab-current">
239
  <a href="#setup">
240
  <span class="dashicons dashicons-admin-home"></span>
241
- <label><?php _e( 'Plugin Setup', 'wp-user-frontend' ); ?></label>
242
  </a>
243
  </li>
244
  <li>
245
  <a href="#frontend-posting">
246
  <span class="dashicons dashicons-media-text"></span>
247
- <label><?php _e( 'Frontend Posting', 'wp-user-frontend' ); ?></label>
248
  </a>
249
  </li>
250
  <li>
251
  <a href="#frontend-dashboard">
252
  <span class="dashicons dashicons-dashboard"></span>
253
- <label><?php _e( 'Frontend Dashboard', 'wp-user-frontend' ); ?></label>
254
  </a>
255
  </li>
256
  <li>
257
  <a href="#user-registration">
258
  <span class="dashicons dashicons-admin-users"></span>
259
- <label><?php _e( 'User Registration', 'wp-user-frontend' ); ?></label>
260
  </a>
261
  </li>
262
  <li>
263
  <a href="#login-page">
264
  <span class="dashicons dashicons-lock"></span>
265
- <label><?php _e( 'User Login', 'wp-user-frontend' ); ?></label>
266
  </a>
267
  </li>
268
  <li>
269
  <a href="#profile-editing">
270
  <span class="dashicons dashicons-edit"></span>
271
- <label><?php _e( 'Profile Editing', 'wp-user-frontend' ); ?></label>
272
  </a>
273
  </li>
274
  <li>
275
  <a href="#subscription-payment">
276
  <span class="dashicons dashicons-cart"></span>
277
- <label><?php _e( 'Subscription &amp; Payment', 'wp-user-frontend' ); ?></label>
278
  </a>
279
  </li>
280
  <li>
281
  <a href="#content-restriction">
282
  <span class="dashicons dashicons-unlock"></span>
283
- <label><?php _e( 'Content Restriction', 'wp-user-frontend' ); ?></label>
284
  </a>
285
  </li>
286
  </ul>
@@ -296,13 +295,13 @@ function wpuf_help_related_articles( $articles ) {
296
  <li><strong>Install WPUF Pages</strong> with a single click. Check your admin dashboard for a message to install WPUF required pages.</li>
297
  <li>You can create amazing frontend posting forms with more than 20 useful form fields. </li>
298
  <li>Posting the forms in the frontend is also very easy. All you have to do is <strong>put the shortcode</strong> of your form to a page. </li>
299
- <li>Building registration &amp; profile editing forms has never been easier, thanks to WP User Frontend. <a href="<?php echo admin_url( 'admin.php?page=wpuf-profile-forms' ); ?>" target="_blank">Build registration &amp; profile forms</a> on the go with simple steps.</li>
300
  <li>Add customized <strong>login forms</strong> using simple shortcodes and override default WordPress login and registration.</li>
301
  <li>Create customized <strong>subscription forms</strong> and let your users buy with multiple payment gateways.</li>
302
  <li><strong>Enable guest posting</strong> and earn from each posts without any difficulties. </li>
303
  </ol>
304
 
305
- <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/getting-started/how-to-install/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=how-to-install" target="_blank"><?php _e( 'Learn More About Installation', 'wp-user-frontend' ); ?></a>
306
 
307
  <?php wpuf_help_related_articles( $articles['setup'] ); ?>
308
  </section>
@@ -310,10 +309,10 @@ function wpuf_help_related_articles( $articles ) {
310
  <h2>Frontend Posting</h2>
311
 
312
  <p>Posting Forms are used to <strong>create new</strong> blog posts, WooCommerce Products, Directory Listing Entries etc. You can create any custom post type from the front using this feature. You just need to create a form with necessary fields and embed the form in a page and your users will be able to create posts from frontend in no time.</p>
313
- <p>To create a posting form, go to <a href="<?php echo admin_url( 'admin.php?page=wpuf-post-forms' ); ?>" target="_blank">Post Forms</a> → Add Form and start building your ultimate frontend posting forms. </p>
314
  <p>After building your forms, <strong>use the shortcodes</strong> on any new page or post and publish them before sharing.</p>
315
 
316
- <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=frontend-posting" target="_blank"><?php _e( 'Learn More About Frontend Posting', 'wp-user-frontend' ); ?></a>
317
 
318
  <?php wpuf_help_related_articles( $articles['posting'] ); ?>
319
  </section>
@@ -321,16 +320,16 @@ function wpuf_help_related_articles( $articles ) {
321
  <h2>Frontend Dashboard</h2>
322
 
323
  <p>WP User Frontend generates <strong>Frontend Dashboard</strong> and <strong>My Account</strong> page for all your users. Using these pages, they can get a list of their posts and subscriptions directly at frontend. They can also customize the details of their profile. You don’t need to give them access to the backend at all!</p>
324
- <p>To crate this page, <a href="<?php echo admin_url( 'post-new.php?post_type=page' ); ?>" target="_blank">create a new page</a>, put a title and simply copy-paste the following shortcode: <code>[wpuf_dashboard]</code>. Alternatively, there is an unified <a href="https://wedevs.com/docs/wp-user-frontend-pro/frontend/how-to-create-my-account-page/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=unified-my-account-page" target="_blank">my account page</a> as well. Finally, hit the publish button and you are done.</p>
325
 
326
- <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/frontend/configuring-dashboard-settings/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=frontend-dashboard" target="_blank"><?php _e( 'Learn More About Frontend Dashboard', 'wp-user-frontend' ); ?></a>
327
 
328
  <?php wpuf_help_related_articles( $articles['dashboard'] ); ?>
329
  </section>
330
  <section id="user-registration">
331
  <h2>User Registration</h2>
332
 
333
- <p>You can create as many registration forms as you want and assign them to different user roles. Creating Registration forms are easy. Navigate to <a href="<?php echo admin_url( 'admin.php?page=wpuf-profile-forms' ); ?>" target="_blank">Registration Forms</a>.</p>
334
  <p>You can create new forms just you would create posts in WordPress.</p>
335
 
336
  <ol>
@@ -353,7 +352,7 @@ function wpuf_help_related_articles( $articles ) {
353
  </ul>
354
 
355
 
356
- <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=registration-profile-forms" target="_blank"><?php _e( 'Learn More About Registration', 'wp-user-frontend' ); ?></a>
357
 
358
  <?php wpuf_help_related_articles( $articles['registration'] ); ?>
359
  </section>
@@ -362,14 +361,14 @@ function wpuf_help_related_articles( $articles ) {
362
 
363
  <p>WP User Frontend Automatically creates important pages when you install it for the first time. You can also create login forms manually. </p>
364
 
365
- <p>Navigate to <a href="<?php echo admin_url( 'admin.php?page=wpuf-settings' ); ?>" target="_blank">Settings</a> → <strong>Login/Registration</strong> tab.
366
  In this page, you will find several useful settings related to WPUF login. You can override default registration and login forms with WPUF login &amp; registration feature if you want. To do this, check the <strong>Login/Registration override option</strong>.</p>
367
 
368
  <p>You can also specify the login page. WPUF automatically adds the default login page that it has created. If you manually create one, use the following shortcode – <code>[wpuf-login]</code></p>
369
 
370
  <p>Simply, create a new page and put the above shortcode. Finally, publish the page and add it to the Login Page option in the settings.</p>
371
 
372
- <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/user-login/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=learn-more-login" target="_blank"><?php _e( 'Learn More About Login', 'wp-user-frontend' ); ?></a>
373
  </section>
374
  <section id="profile-editing">
375
  <h2>Creating a Profile Editing Form</h2>
@@ -386,7 +385,7 @@ function wpuf_help_related_articles( $articles ) {
386
  <p>We assume that you already have created a registration form. If not you can use the default registration form, that was created automatically while installing the plugin.
387
  So to get the shortcode, navigate to <strong>User Frontend</strong> → <strong>Registration Forms</strong> and you will be able to see the shortcodes on the right side of your screen.</p>
388
 
389
- <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=registration-profile-forms" target="_blank"><?php _e( 'Learn More About Profile Editing', 'wp-user-frontend' ); ?></a>
390
 
391
  <?php wpuf_help_related_articles( $articles['profile'] ); ?>
392
  </section>
@@ -439,14 +438,14 @@ function wpuf_help_related_articles( $articles ) {
439
  <p>Currently only PayPal basic gateway is supported. The plugin is extension aware, that means other gateways can be integrated.</p>
440
 
441
 
442
- <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=subscription-payment" target="_blank"><?php _e( 'Learn More About Payments', 'wp-user-frontend' ); ?></a>
443
 
444
  <?php wpuf_help_related_articles( $articles['subscription'] ); ?>
445
  </section>
446
  <section id="content-restriction">
447
  <h2>Content Restriction</h2>
448
 
449
- <p>To set content restriction for a certain form, navigate to <a href="<?php echo admin_url( 'edit.php?post_type=page' ); ?>" target="_blank">Pages</a></strong></p>
450
 
451
  <ol>
452
  <li>Now, select the page that has the shortcode of the selected form.</li>
@@ -456,7 +455,7 @@ function wpuf_help_related_articles( $articles ) {
456
  <li>Finally, update the page.</li>
457
  </ol>
458
 
459
- <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=content-restriction" target="_blank"><?php _e( 'Learn More About Content Restriction', 'wp-user-frontend' ); ?></a>
460
 
461
  <?php wpuf_help_related_articles( $articles['restriction'] ); ?>
462
  </section>
@@ -465,33 +464,33 @@ function wpuf_help_related_articles( $articles ) {
465
 
466
  <div class="help-blocks">
467
  <div class="help-block">
468
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/help/like.svg" alt="<?php esc_attr_e( 'Like The Plugin?', 'wp-user-frontend' ); ?>">
469
 
470
- <h3><?php _e( 'Like The Plugin?', 'wp-user-frontend' ); ?></h3>
471
 
472
- <p><?php _e( 'Your Review is very important to us as it helps us to grow more.', 'wp-user-frontend' ); ?></p>
473
 
474
- <a target="_blank" class="button button-primary" href="https://wordpress.org/support/plugin/wp-user-frontend/reviews/?rate=5#new-post"><?php _e( 'Review Us on WP.org', 'wp-user-frontend' ); ?></a>
475
  </div>
476
 
477
  <div class="help-block">
478
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/help/bugs.svg" alt="<?php esc_attr_e( 'Found Any Bugs?', 'wp-user-frontend' ); ?>">
479
 
480
- <h3><?php _e( 'Found Any Bugs?', 'wp-user-frontend' ); ?></h3>
481
 
482
- <p><?php _e( 'Report any Bug that you Discovered, Get Instant Solutions.', 'wp-user-frontend' ); ?></p>
483
 
484
- <a target="_blank" class="button button-primary" href="https://github.com/weDevsOfficial/wp-user-frontend/?utm_source=wpuf-help-page&utm_medium=help-block&utm_campaign=found-bugs"><?php _e( 'Report to GitHub', 'wp-user-frontend' ); ?></a>
485
  </div>
486
 
487
  <div class="help-block">
488
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/help/support.svg" alt="<?php esc_attr_e( 'Need Any Assistance?', 'wp-user-frontend' ); ?>">
489
 
490
- <h3><?php _e( 'Need Any Assistance?', 'wp-user-frontend' ); ?></h3>
491
 
492
- <p><?php _e( 'Our EXPERT Support Team is always ready to Help you out.', 'wp-user-frontend' ); ?></p>
493
 
494
- <a target="_blank" class="button button-primary" href="https://wedevs.com/account/tickets/?utm_source=wpuf-help-page&utm_medium=help-block&utm_campaign=need-assistance"><?php _e( 'Contact Support', 'wp-user-frontend' ); ?></a>
495
  </div>
496
  </div>
497
  </div>
1
  <?php
2
  $current_user = wp_get_current_user();
3
 
4
+ $articles = [
5
+ 'setup' => [
6
+ [
7
  'title' => 'How to Install',
8
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/getting-started/how-to-install/',
9
+ ],
10
+ [
11
  'title' => 'License Activation',
12
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/troubleshoot/license-activation/',
13
+ ],
14
+ [
15
  'title' => 'Shortcodes',
16
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/getting-started/wpuf-shortcodes/',
17
+ ],
18
+ [
19
  'title' => 'User Dashboard',
20
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/getting-started/user-dashboard/',
21
+ ],
22
+ ],
23
+ 'posting' => [
24
+ [
25
  'title' => 'Creating Posting Forms',
26
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/creating-posting-forms/',
27
+ ],
28
+ [
29
  'title' => 'Available Form Elements',
30
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/form-elements/',
31
+ ],
32
+ [
33
  'title' => 'Creating Forms Using The Form Templates',
34
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/form-templates/',
35
+ ],
36
+ [
37
  'title' => 'How to Allow Guest Posting',
38
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/guest-posting/',
39
+ ],
40
+ [
41
  'title' => 'Setup Automatic Post Expiration',
42
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/using-post-expiration-wp-user-frontend/',
43
+ ],
44
+ [
45
  'title' => 'How to create Multistep forms',
46
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/how-to-add-multi-step-form/',
47
+ ],
48
+ ],
49
+ 'dashboard' => [
50
+ [
51
  'title' => 'Setting up Frontend Dashboard for Users',
52
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/frontend/configuring-dashboard-settings/',
53
+ ],
54
+ [
55
  'title' => 'Unified My Account Page',
56
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/frontend/how-to-create-my-account-page/',
57
+ ],
58
+ [
59
  'title' => 'Showing meta fields in frontend',
60
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/frontend/showing-meta-fields-in-frontend/',
61
+ ],
62
+ ],
63
+ 'settings' => [
64
+ [
65
  'title' => 'General Options',
66
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/settings/configuring-general-options/',
67
+ ],
68
+ [
69
  'title' => 'Dashboard Settings',
70
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/settings/configuring-dashboard-settings/',
71
+ ],
72
+ [
73
  'title' => 'Login Registration Settings',
74
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/settings/login-registration-settings/',
75
+ ],
76
+ [
77
  'title' => 'Payment Settings',
78
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/settings/configuring-payment-settings/',
79
+ ],
80
+ ],
81
+ 'registration' => [
82
+ [
83
  'title' => 'Creating Registration Form',
84
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-forms/',
85
+ ],
86
+ [
87
  'title' => 'Creating a Multistep Registration Form',
88
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/creating-a-multistep-registration-form/',
89
+ ],
90
+ [
91
  'title' => 'Setting Up Confirmation Message',
92
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/setup-confirmation-message/',
93
+ ],
94
+ [
95
  'title' => 'Paid Membership Registration',
96
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/paid-membership-registration/',
97
+ ],
98
+ [
99
  'title' => 'Setting Up Email Verification for New Users',
100
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/setting-up-email-verification-for-new-users/',
101
+ ],
102
+ ],
103
+ 'profile' => [
104
+ [
105
  'title' => 'Creating a Profile Editing Form',
106
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/wordpress-edit-user-profile-from-front-end/',
107
+ ],
108
+ ],
109
+ 'subscription' => [
110
+ [
111
  'title' => 'Creating Subscription Packs',
112
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/creating-subscription-packs/',
113
+ ],
114
+ [
115
  'title' => 'Payment & Gateway Settings',
116
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/configuring-payment-settings/',
117
+ ],
118
+ [
119
  'title' => 'Setting Up Recurring Payment',
120
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/setting-up-recurring-payment/',
121
+ ],
122
+ [
123
  'title' => 'Forcing Subscription Pack For Post Submission',
124
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/forcing-subscription-pack-for-post-submission/',
125
+ ],
126
+ [
127
  'title' => 'How to Charge for Each Post Submission?',
128
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/how-to-charge-for-each-post-submission/',
129
+ ],
130
+ [
131
  'title' => 'Creating Coupons',
132
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/coupons/',
133
+ ],
134
+ ],
135
 
136
+ 'developer' => [
137
+ [
138
  'title' => 'Action Hook Field',
139
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/action-hook-field/',
140
+ ],
141
+ [
142
  'title' => 'Add a New Tab on My Account Page',
143
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/add-a-new-tab-on-my-account-page/',
144
+ ],
145
+ [
146
  'title' => 'Insert/update checkbox or radio field data as serialize',
147
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/insertupdate-checkbox-or-radio-field-data-as-serialize/',
148
+ ],
149
+ [
150
  'title' => 'Filters',
151
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/filters/',
152
+ ],
153
+ [
154
  'title' => 'Actions',
155
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/actions/',
156
+ ],
157
+ [
158
  'title' => 'Changelog',
159
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/changelog/',
160
+ ],
161
+ ],
162
+ 'restriction' => [
163
+ [
164
  'title' => 'Content Restriction for Logged in Users',
165
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/content-restriction/',
166
+ ],
167
+ [
168
  'title' => 'Restricting Content by User Roles',
169
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/restricting-content-by-user-roles/',
170
+ ],
171
+ [
172
  'title' => 'Restricting Contents for Different Subscription Packs',
173
+ 'link' => 'https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/restricting-contents-for-different-subscription-packs/',
174
+ ],
175
+ ],
176
+ ];
177
 
178
  /**
179
  * Print related articles
180
  *
181
+ * @param array $articles
182
  *
183
  * @return void
184
  */
185
  function wpuf_help_related_articles( $articles ) {
186
  ?>
187
+ <h2><?php esc_html_e( 'Related Articles:', 'wp-user-frontend' ); ?></h2>
188
 
189
  <ul class="related-articles">
190
  <?php
192
  ?>
193
  <li>
194
  <span class="dashicons dashicons-media-text"></span>
195
+ <a href="<?php echo esc_attr( trailingslashit( $article['link'] ) ); ?>?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=<?php echo esc_attr( $article['title'] ); ?>" target="_blank"><?php echo esc_attr( $article['title'] ); ?></a>
196
  </li>
197
  <?php
198
+ } ?>
 
199
  </ul>
200
  <?php
201
  }
202
  ?>
203
 
204
  <div class="wrap wpuf-help-page">
205
+ <h1><?php esc_html_e( 'General Help Questions', 'wp-user-frontend' ); ?> <a href="https://wedevs.com/docs/wp-user-frontend-pro/?utm_source=wpuf-help-page&utm_medium=button-primary&utm_campaign=view-all-docs" target="_blank" class="page-title-action"><span class="dashicons dashicons-external" style="margin-top: 8px;"></span> <?php esc_html_e( 'View all Documentations', 'wp-user-frontend' ); ?></a></h1>
206
 
207
  <form class="wpuf-subscribe-box" id="wpuf-form-subscribe" action="https://wedevs.us16.list-manage.com/subscribe/post-json?u=66e606cfe0af264974258f030&id=0d176bb256&c=?" method="get">
208
 
209
  <div class="text-wrap">
210
+ <h3><?php esc_html_e( 'Subscribe to Our Newsletter', 'wp-user-frontend' ); ?></h3>
211
  <p>
212
+ <?php echo wp_kses_post( __( 'Subscribe to our newsletter for regular <strong>tips</strong>, <strong>offers</strong> and <strong>news updates</strong>.', 'wp-user-frontend' ) ); ?>
213
  </p>
214
  </div>
215
 
216
  <div class="form-wrap">
217
  <div class="fname">
218
+ <label for="fname"><?php esc_html_e( 'First Name', 'wp-user-frontend' ); ?></label>
219
  <input type="text" name="FNAME" id="fname" class="regular-text" value="<?php echo esc_attr( $current_user->first_name ); ?>" required>
220
  </div>
221
 
222
  <div class="email">
223
+ <label for="email"><?php esc_html_e( 'Email', 'wp-user-frontend' ); ?></label>
224
  <input type="email" name="EMAIL" id="email" class="regular-text" value="<?php echo esc_attr( $current_user->user_email ); ?>" required>
225
  </div>
226
 
237
  <li class="tab-current">
238
  <a href="#setup">
239
  <span class="dashicons dashicons-admin-home"></span>
240
+ <label><?php esc_html_e( 'Plugin Setup', 'wp-user-frontend' ); ?></label>
241
  </a>
242
  </li>
243
  <li>
244
  <a href="#frontend-posting">
245
  <span class="dashicons dashicons-media-text"></span>
246
+ <label><?php esc_html_e( 'Frontend Posting', 'wp-user-frontend' ); ?></label>
247
  </a>
248
  </li>
249
  <li>
250
  <a href="#frontend-dashboard">
251
  <span class="dashicons dashicons-dashboard"></span>
252
+ <label><?php esc_html_e( 'Frontend Dashboard', 'wp-user-frontend' ); ?></label>
253
  </a>
254
  </li>
255
  <li>
256
  <a href="#user-registration">
257
  <span class="dashicons dashicons-admin-users"></span>
258
+ <label><?php esc_html_e( 'User Registration', 'wp-user-frontend' ); ?></label>
259
  </a>
260
  </li>
261
  <li>
262
  <a href="#login-page">
263
  <span class="dashicons dashicons-lock"></span>
264
+ <label><?php esc_html_e( 'User Login', 'wp-user-frontend' ); ?></label>
265
  </a>
266
  </li>
267
  <li>
268
  <a href="#profile-editing">
269
  <span class="dashicons dashicons-edit"></span>
270
+ <label><?php esc_html_e( 'Profile Editing', 'wp-user-frontend' ); ?></label>
271
  </a>
272
  </li>
273
  <li>
274
  <a href="#subscription-payment">
275
  <span class="dashicons dashicons-cart"></span>
276
+ <label><?php esc_html_e( 'Subscription &amp; Payment', 'wp-user-frontend' ); ?></label>
277
  </a>
278
  </li>
279
  <li>
280
  <a href="#content-restriction">
281
  <span class="dashicons dashicons-unlock"></span>
282
+ <label><?php esc_html_e( 'Content Restriction', 'wp-user-frontend' ); ?></label>
283
  </a>
284
  </li>
285
  </ul>
295
  <li><strong>Install WPUF Pages</strong> with a single click. Check your admin dashboard for a message to install WPUF required pages.</li>
296
  <li>You can create amazing frontend posting forms with more than 20 useful form fields. </li>
297
  <li>Posting the forms in the frontend is also very easy. All you have to do is <strong>put the shortcode</strong> of your form to a page. </li>
298
+ <li>Building registration &amp; profile editing forms has never been easier, thanks to WP User Frontend. <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpuf-profile-forms' ) ); ?>" target="_blank">Build registration &amp; profile forms</a> on the go with simple steps.</li>
299
  <li>Add customized <strong>login forms</strong> using simple shortcodes and override default WordPress login and registration.</li>
300
  <li>Create customized <strong>subscription forms</strong> and let your users buy with multiple payment gateways.</li>
301
  <li><strong>Enable guest posting</strong> and earn from each posts without any difficulties. </li>
302
  </ol>
303
 
304
+ <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/getting-started/how-to-install/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=how-to-install" target="_blank"><?php esc_html_e( 'Learn More About Installation', 'wp-user-frontend' ); ?></a>
305
 
306
  <?php wpuf_help_related_articles( $articles['setup'] ); ?>
307
  </section>
309
  <h2>Frontend Posting</h2>
310
 
311
  <p>Posting Forms are used to <strong>create new</strong> blog posts, WooCommerce Products, Directory Listing Entries etc. You can create any custom post type from the front using this feature. You just need to create a form with necessary fields and embed the form in a page and your users will be able to create posts from frontend in no time.</p>
312
+ <p>To create a posting form, go to <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpuf-post-forms' ) ); ?>" target="_blank">Post Forms</a> → Add Form and start building your ultimate frontend posting forms. </p>
313
  <p>After building your forms, <strong>use the shortcodes</strong> on any new page or post and publish them before sharing.</p>
314
 
315
+ <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=frontend-posting" target="_blank"><?php esc_html_e( 'Learn More About Frontend Posting', 'wp-user-frontend' ); ?></a>
316
 
317
  <?php wpuf_help_related_articles( $articles['posting'] ); ?>
318
  </section>
320
  <h2>Frontend Dashboard</h2>
321
 
322
  <p>WP User Frontend generates <strong>Frontend Dashboard</strong> and <strong>My Account</strong> page for all your users. Using these pages, they can get a list of their posts and subscriptions directly at frontend. They can also customize the details of their profile. You don’t need to give them access to the backend at all!</p>
323
+ <p>To crate this page, <a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=page' ) ); ?>" target="_blank">create a new page</a>, put a title and simply copy-paste the following shortcode: <code>[wpuf_dashboard]</code>. Alternatively, there is an unified <a href="https://wedevs.com/docs/wp-user-frontend-pro/frontend/how-to-create-my-account-page/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=unified-my-account-page" target="_blank">my account page</a> as well. Finally, hit the publish button and you are done.</p>
324
 
325
+ <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/frontend/configuring-dashboard-settings/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=frontend-dashboard" target="_blank"><?php esc_html_e( 'Learn More About Frontend Dashboard', 'wp-user-frontend' ); ?></a>
326
 
327
  <?php wpuf_help_related_articles( $articles['dashboard'] ); ?>
328
  </section>
329
  <section id="user-registration">
330
  <h2>User Registration</h2>
331
 
332
+ <p>You can create as many registration forms as you want and assign them to different user roles. Creating Registration forms are easy. Navigate to <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpuf-profile-forms' ) ); ?>" target="_blank">Registration Forms</a>.</p>
333
  <p>You can create new forms just you would create posts in WordPress.</p>
334
 
335
  <ol>
352
  </ul>
353
 
354
 
355
+ <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=registration-profile-forms" target="_blank"><?php esc_html_e( 'Learn More About Registration', 'wp-user-frontend' ); ?></a>
356
 
357
  <?php wpuf_help_related_articles( $articles['registration'] ); ?>
358
  </section>
361
 
362
  <p>WP User Frontend Automatically creates important pages when you install it for the first time. You can also create login forms manually. </p>
363
 
364
+ <p>Navigate to <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpuf-settings' ) ); ?>" target="_blank">Settings</a> → <strong>Login/Registration</strong> tab.
365
  In this page, you will find several useful settings related to WPUF login. You can override default registration and login forms with WPUF login &amp; registration feature if you want. To do this, check the <strong>Login/Registration override option</strong>.</p>
366
 
367
  <p>You can also specify the login page. WPUF automatically adds the default login page that it has created. If you manually create one, use the following shortcode – <code>[wpuf-login]</code></p>
368
 
369
  <p>Simply, create a new page and put the above shortcode. Finally, publish the page and add it to the Login Page option in the settings.</p>
370
 
371
+ <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/user-login/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=learn-more-login" target="_blank"><?php esc_html_e( 'Learn More About Login', 'wp-user-frontend' ); ?></a>
372
  </section>
373
  <section id="profile-editing">
374
  <h2>Creating a Profile Editing Form</h2>
385
  <p>We assume that you already have created a registration form. If not you can use the default registration form, that was created automatically while installing the plugin.
386
  So to get the shortcode, navigate to <strong>User Frontend</strong> → <strong>Registration Forms</strong> and you will be able to see the shortcodes on the right side of your screen.</p>
387
 
388
+ <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=registration-profile-forms" target="_blank"><?php esc_html_e( 'Learn More About Profile Editing', 'wp-user-frontend' ); ?></a>
389
 
390
  <?php wpuf_help_related_articles( $articles['profile'] ); ?>
391
  </section>
438
  <p>Currently only PayPal basic gateway is supported. The plugin is extension aware, that means other gateways can be integrated.</p>
439
 
440
 
441
+ <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=subscription-payment" target="_blank"><?php esc_html_e( 'Learn More About Payments', 'wp-user-frontend' ); ?></a>
442
 
443
  <?php wpuf_help_related_articles( $articles['subscription'] ); ?>
444
  </section>
445
  <section id="content-restriction">
446
  <h2>Content Restriction</h2>
447
 
448
+ <p>To set content restriction for a certain form, navigate to <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=page' ) ); ?>" target="_blank">Pages</a></strong></p>
449
 
450
  <ol>
451
  <li>Now, select the page that has the shortcode of the selected form.</li>
455
  <li>Finally, update the page.</li>
456
  </ol>
457
 
458
+ <a class="button button-primary button-large" href="https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/?utm_source=wpuf-help-page&utm_medium=help-links&utm_campaign=wpuf-help&utm_term=content-restriction" target="_blank"><?php esc_html_e( 'Learn More About Content Restriction', 'wp-user-frontend' ); ?></a>
459
 
460
  <?php wpuf_help_related_articles( $articles['restriction'] ); ?>
461
  </section>
464
 
465
  <div class="help-blocks">
466
  <div class="help-block">
467
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/help/like.svg" alt="<?php esc_attr_e( 'Like The Plugin?', 'wp-user-frontend' ); ?>">
468
 
469
+ <h3><?php esc_html_e( 'Like The Plugin?', 'wp-user-frontend' ); ?></h3>
470
 
471
+ <p><?php esc_html_e( 'Your Review is very important to us as it helps us to grow more.', 'wp-user-frontend' ); ?></p>
472
 
473
+ <a target="_blank" class="button button-primary" href="https://wordpress.org/support/plugin/wp-user-frontend/reviews/?rate=5#new-post"><?php esc_html_e( 'Review Us on WP.org', 'wp-user-frontend' ); ?></a>
474
  </div>
475
 
476
  <div class="help-block">
477
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/help/bugs.svg" alt="<?php esc_attr_e( 'Found Any Bugs?', 'wp-user-frontend' ); ?>">
478
 
479
+ <h3><?php esc_html_e( 'Found Any Bugs?', 'wp-user-frontend' ); ?></h3>
480
 
481
+ <p><?php esc_html_e( 'Report any Bug that you Discovered, Get Instant Solutions.', 'wp-user-frontend' ); ?></p>
482
 
483
+ <a target="_blank" class="button button-primary" href="https://github.com/weDevsOfficial/wp-user-frontend/?utm_source=wpuf-help-page&utm_medium=help-block&utm_campaign=found-bugs"><?php esc_html_e( 'Report to GitHub', 'wp-user-frontend' ); ?></a>
484
  </div>
485
 
486
  <div class="help-block">
487
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/help/support.svg" alt="<?php esc_attr_e( 'Need Any Assistance?', 'wp-user-frontend' ); ?>">
488
 
489
+ <h3><?php esc_html_e( 'Need Any Assistance?', 'wp-user-frontend' ); ?></h3>
490
 
491
+ <p><?php esc_html_e( 'Our EXPERT Support Team is always ready to Help you out.', 'wp-user-frontend' ); ?></p>
492
 
493
+ <a target="_blank" class="button button-primary" href="https://wedevs.com/account/tickets/?utm_source=wpuf-help-page&utm_medium=help-block&utm_campaign=need-assistance"><?php esc_html_e( 'Contact Support', 'wp-user-frontend' ); ?></a>
494
  </div>
495
  </div>
496
  </div>
admin/html/whats-new.php CHANGED
@@ -1,518 +1,518 @@
1
  <?php
2
- $changelog = array(
3
- array(
4
  'version' => 'Version 3.1.12',
5
  'released' => '2019-10-17',
6
- 'changes' => array(
7
- array(
8
- 'title' => __( "Nonce not verify on login", 'wp-user-frontend' ),
9
- 'type' => 'Fix',
10
- 'description' => __( "Return of function wp_verify_nonce() was ignored.", 'wp-user-frontend' )
11
- )
12
- )
13
- ),
14
- array(
15
  'version' => 'Version 3.1.11',
16
  'released' => '2019-10-02',
17
- 'changes' => array(
18
- array(
19
  'title' => __( 'Option to set which tab shows as active on the account page', 'wp-user-frontend' ),
20
  'type' => 'New',
21
  'description' => __( 'Option to set which tab shows as active on the account page. To configure this setting navigate to wp-admin->User Frontend->Settings->My Account->Active Tab ', 'wp-user-frontend' ),
22
- ),
23
- array(
24
  'title' => __( 'Unlock option was unavailable after the post being locked', 'wp-user-frontend' ),
25
  'type' => 'Fix',
26
- 'description' => __( 'Unlock option was unavailable after the post being locked.', 'wp-user-frontend' )
27
- ),
28
- array(
29
  'title' => __( "Gutenberg block of WPUF didn't work on bedrock installation", 'wp-user-frontend' ),
30
  'type' => 'Fix',
31
- 'description' => __( "Gutenberg block of WPUF didn't work on bedrock installation.", 'wp-user-frontend' )
32
- ),
33
- array(
34
- 'title' => __( "Sending admin payment received email twice", 'wp-user-frontend' ),
35
  'type' => 'Fix',
36
- 'description' => __( "After processing payment admin & user was receiving payment received email twice.", 'wp-user-frontend' )
37
- ),
38
- array(
39
- 'title' => __( "Add shortcode support to display post information in the Post Expiration Message", 'wp-user-frontend' ),
40
  'type' => 'Improvement',
41
- 'description' => __( "Add shortcode support to display post information in the Post Expiration Message. You can use: <strong>{post_author} {post_url} {blogname} {post_title} {post_status}</strong>", 'wp-user-frontend' )
42
- ),
43
- array(
44
- 'title' => __( "Add optin on the setup wizard", 'wp-user-frontend' ),
45
  'type' => 'Improvement',
46
- 'description' => __( "Added optin on the setup wizard, admin can choose whether he/she wants to share server environment details (php, mysql, server, WordPress versions), Number of users, Site language, Number of active and inactive plugins, Site name and url, admin name and email address. No sensitive data is tracked", 'wp-user-frontend' )
47
- ),
48
- )
49
- ),
50
- array(
51
  'version' => 'Version 3.1.10',
52
  'released' => '2019-09-06',
53
- 'changes' => array(
54
- array(
55
  'title' => __( 'Post Owner problem', 'wp-user-frontend' ),
56
  'type' => 'Fix',
57
  'description' => __( 'Posts were not assigned to the selected default post owner, this issue has been fixed.', 'wp-user-frontend' ),
58
- ),
59
- array(
60
  'title' => __( 'Google reCaptcha was not working', 'wp-user-frontend' ),
61
  'type' => 'Fix',
62
- 'description' => __( 'Google reCaptcha was not working, users could submit the form without reCaptcha validation.', 'wp-user-frontend' )
63
- ),
64
- )
65
- ),
66
- array(
67
  'version' => 'Version 3.1.2',
68
  'released' => '2019-04-01',
69
- 'changes' => array(
70
- array(
71
  'title' => __( 'Added column field', 'wp-user-frontend' ),
72
  'type' => 'New',
73
- 'description' => 'Now, creating multi-column in a single row is super easy with WPUF Column field. Just drag the column field in the builder area, configure columns number, column space and any fields you want inside that Column field.' .'<img src="'. WPUF_ASSET_URI .'/images/whats-new/column-field.png" alt="Multi-select Category">',
74
- ),
75
- array(
76
  'title' => __( 'Unable to render the events on the front-end dashboard', 'wp-user-frontend' ),
77
  'type' => 'Fix',
78
- 'description' => __( 'On the frontend dashboard, the submitted events were not showing, you will get it fixed in this version.', 'wp-user-frontend' )
79
- ),
80
- array(
81
  'title' => __( 'Page order getting 0(zero) after editing from the frontend', 'wp-user-frontend' ),
82
  'type' => 'Fix',
83
- 'description' => __( 'Page order was not saving while editing a post using WPUF form, it has been fixed.', 'wp-user-frontend' )
84
- ),
85
- array(
86
  'title' => __( 'Text input field for taxonomies not working', 'wp-user-frontend' ),
87
  'type' => 'Fix',
88
- 'description' => __( "When taxonomy field type is set to `Text Input` then a fatal error was showing on the frontend, no error with taxonomy field in the latest version.", 'wp-user-frontend' )
89
- ),
90
- array(
91
  'title' => __( 'In radio and checkbox field use conditional logic that value does not save in database', 'wp-user-frontend' ),
92
  'type' => 'Fix',
93
- 'description' => __( "The selected value of radio and checkbox field were not showing while editing posts from the backend or frontend, you can see the selected value in this version.", 'wp-user-frontend' )
94
- ),
95
- array(
96
  'title' => __( 'The args param not working with get_avatar filter', 'wp-user-frontend' ),
97
  'type' => 'Fix',
98
- 'description' => __( "The args parameter did not exist with get_avatar filter, which now exists.", 'wp-user-frontend' )
99
- ),
100
- array(
101
  'title' => __( 'The item in ajax taxonomy field was not selected', 'wp-user-frontend' ),
102
  'type' => 'Fix',
103
- 'description' => __( "When the taxonomy field type is set to Ajax, the submitted terms were not showing in the backend and frontend which have been fixed.", 'wp-user-frontend' )
104
- ),
105
- )
106
- ),
107
- array(
108
  'version' => 'Version 3.1.0',
109
  'released' => '2019-01-31',
110
- 'changes' => array(
111
- array(
112
  'title' => __( 'Unable to send new user registration email', 'wp-user-frontend' ),
113
  'type' => 'Fix',
114
- 'description' => __( 'WP User Frontend default registration form `[wpuf-registration]` was unable to send the new user registration email.', 'wp-user-frontend' )
115
- ),
116
- array(
117
  'title' => __( 'WPUF forms block compatibility issue with the latest WP version', 'wp-user-frontend' ),
118
  'type' => 'Fix',
119
- 'description' => __( 'With the latest version of WordPress the gutenberg block of WP User Frontend were not working. In this version, you will get it fixed.', 'wp-user-frontend' )
120
- ),
121
- array(
122
  'title' => __( 'Page not update where `[wpuf_dashboard]` shortcode exist', 'wp-user-frontend' ),
123
  'type' => 'Fix',
124
- 'description' => __( 'While using Gutenberg, the page were not being updated with WPUF shortcode [wpuf dashboard]', 'wp-user-frontend' )
125
- ),
126
- array(
127
  'title' => __( 'Retain default when determining whether to display the admin bar', 'wp-user-frontend' ),
128
  'type' => 'Fix',
129
- 'description' => __( "From the User Frontend Settings, set that Administrator, Editor, Vendor can see the admin bar. Now, the super admin want, one specific user ( who has the user role from the above ) can't see the admin bar and disabled it from the Toolbar form that specific user profile. And this configuration ( Toolbar ) from the specific user profile were unable to impact on the frontend.", 'wp-user-frontend' )
130
- ),
131
- array(
132
  'title' => __( 'Fatal error when use PHP lower version (5.4 or lower)', 'wp-user-frontend' ),
133
  'type' => 'Fix',
134
- 'description' => __( "It was unable to install WP User Frontend with PHP 5.4 or lower version. Here is the error details: <br><br><strong>Fatal error: Can't use method return value in write context in /wp-user-frontend/class/frontend-form-post.php on line 194</strong>", 'wp-user-frontend' )
135
- ),
136
- array(
137
  'title' => __( 'Product form was unable to show the single gallery image', 'wp-user-frontend' ),
138
  'type' => 'Fix',
139
- 'description' => __( "When user upload single image for product gallery using WPUF WooCommerce product form, that image were not showing on the frontend.", 'wp-user-frontend' )
140
- ),
141
- )
142
- ),
143
- array(
144
  'version' => 'Version 2.9.4',
145
  'released' => '2018-11-20',
146
- 'changes' => array(
147
- array(
148
  'title' => __( 'WooCommerce gallery images not getting saved', 'wp-user-frontend' ),
149
  'type' => 'Fix',
150
- 'description' => __( 'After releasing version 2.9.3, WooCommerce gallery image field stopped working. You will get it fixed in this version.', 'wp-user-frontend' )
151
- ),
152
- )
153
- ),
154
- array(
155
  'version' => 'Version 2.9.0',
156
  'released' => '2018-08-14',
157
- 'changes' => array(
158
- array(
159
  'title' => __( 'The Events Calendar Integration Form', 'wp-user-frontend' ),
160
  'type' => 'New',
161
- 'description' => __( 'Now admin can allow users to create event from the frontend. Currently WPUF has a one click pre-build event form that has been integrated with The Events Calendar plugin', 'wp-user-frontend' )
162
- ),
163
- array(
164
  'title' => __( 'Post Submission Facility From Account Page', 'wp-user-frontend' ),
165
  'type' => 'New',
166
- 'description' => __( 'On the frontend account page, added a new menu item named <b>Submit Post</b>. Now admin can allow users to submit post from their default account page. As an admin you can disable or enable this option from <b>User Frontend -> Settings -> My Account -> Post Submission</b>, Also, you can assign any post form that will use to submit posts.', 'wp-user-frontend' )
167
- ),
168
- array(
169
  'title' => __( 'Login/Lost Password Link Under Registration Form', 'wp-user-frontend' ),
170
  'type' => 'Improvement',
171
- 'description' => __( 'Added Login/Lost Password link under registration form', 'wp-user-frontend' )
172
- ),
173
- )
174
- ),
175
- array(
176
  'version' => 'Version 2.8.10',
177
  'released' => '2018-07-17',
178
- 'changes' => array(
179
- array(
180
  'title' => __( 'Added drag and drop image ordering on image upload', 'wp-user-frontend' ),
181
  'type' => 'New',
182
- 'description' => __( 'Now frontend users can drag & drop the images/files to change the order while uploading.', 'wp-user-frontend' )
183
- ),
184
- array(
185
  'title' => __( 'Added reCAPTCHA field in login form', 'wp-user-frontend' ),
186
  'type' => 'New',
187
- 'description' => __( 'Admin has the option to show reCAPTCHA field in login form. Check the related settings from <strong>User Frontend > Settings > Login/Registration</strong>', 'wp-user-frontend' )
188
- ),
189
- array(
190
  'title' => __( 'Added preview option in forms', 'wp-user-frontend' ),
191
  'type' => 'New',
192
- 'description' => __( 'You can see a nice <strong>Preview</strong> button with <strong>Save Form</strong> button, admin can take a quick look of the form without using shortcode', 'wp-user-frontend' )
193
- ),
194
- array(
195
  'title' => __( 'Fixed hiding “Select Image” button while uploading multiple images.', 'wp-user-frontend' ),
196
  'type' => 'Fix',
197
- 'description' => __( 'The upload button will not be hidden until the user selects max number of files ', 'wp-user-frontend' )
198
- ),
199
- array(
200
  'title' => __( 'Added form limit notice before form submission', 'wp-user-frontend' ),
201
  'type' => 'Improvement',
202
- 'description' => __( 'Limit notice message was showing after submission, now it is showing when rendering the form', 'wp-user-frontend' )
203
- ),
204
- array(
205
  'title' => __( 'Fixed: default post category not saving', 'wp-user-frontend' ),
206
  'type' => 'Fix',
207
- 'description' => __( 'From the form <strong>Settings > Post Settings</strong>, default post category options were not saving. Now, it\'s fixed.', 'wp-user-frontend' )
208
- ),
209
- array(
210
  'title' => __( 'WPUF dashboard shortcode with form_id attribute was not showing posts properly', 'wp-user-frontend' ),
211
  'type' => 'Fix',
212
- 'description' => __( 'Now you can list posts on the frontend by using <strong>form_id<strong/> attribute with <strong>[wpuf_dashboard]</strong> shortcode', 'wp-user-frontend' )
213
- ),
214
- )
215
- ),
216
- array(
217
  'version' => 'Version 2.8.9',
218
  'released' => '2018-06-06',
219
- 'changes' => array(
220
- array(
221
  'title' => __( 'Changed text domain to `wp-user-frontend` from `wpuf` ', 'wp-user-frontend' ),
222
  'type' => 'Improvement',
223
- 'description' => __( 'If you are using other language than English. Please <b>rename</b> your <i>.po and .mo </i> files to `wp-user-frontend_` from `wpuf_` <br> This change was made to support translations from translate.wordpress.org', 'wp-user-frontend' )
224
- ),
225
- array(
226
  'title' => __( 'Added WP User Frontend Data export and erase functionality.', 'wp-user-frontend' ),
227
  'type' => 'New',
228
- 'description' => __( 'Added functionality to export WP User Frontend Data to comply with GDPR.', 'wp-user-frontend' )
229
- ),
230
- array(
231
  'title' => __( 'Added billing address customizer.', 'wp-user-frontend' ),
232
  'type' => 'New',
233
  'description' => __( 'Added customizer options for billing address in payment page.', 'wp-user-frontend' ),
234
- ),
235
- array(
236
  'title' => __( 'Make the payment page responsive.', 'wp-user-frontend' ),
237
  'type' => 'Improvement',
238
  'description' => __( 'Some css adjustments are made in payment page to make it responsive.', 'wp-user-frontend' ),
239
- ),
240
- array(
241
  'title' => __( 'Fixed image upload issue in Safari.', 'wp-user-frontend' ),
242
  'type' => 'Fix',
243
  'description' => __( 'Images were not showing after upload in safari, it is fixed now.', 'wp-user-frontend' ),
244
- ),
245
- array(
246
  'title' => __( 'Post update issue after updating or removing post images.', 'wp-user-frontend' ),
247
  'type' => 'Fix',
248
  'description' => __( 'Posts cannot be updated after updating or removing post images, it is fixed now.', 'wp-user-frontend' ),
249
- ),
250
- )
251
- ),
252
- array(
253
  'version' => 'Version 2.8.8',
254
  'released' => '2018-05-16',
255
- 'changes' => array(
256
- array(
257
  'title' => __( 'Allow overriding form input styles using theme styling.', 'wp-user-frontend' ),
258
  'type' => 'New',
259
- 'description' => __( 'Overriding form input styles using theme style is now possible.', 'wp-user-frontend' )
260
- ),
261
- array(
262
  'title' => __( 'Fixed Auto Login after registration.', 'wp-user-frontend' ),
263
  'type' => 'Fix',
264
  'description' => __( 'Auto Login after registration was not working is fixed now.', 'wp-user-frontend' ),
265
- ),
266
- array(
267
  'title' => __( 'Fixed fallback cost calculation', 'wp-user-frontend' ),
268
  'type' => 'Fix',
269
  'description' => __( 'Fallback cost calculation was inaccurate for some cases, it is fixed now.', 'wp-user-frontend' ),
270
- ),
271
- array(
272
  'title' => __( 'Removal of subscription from User Profile gets reverted if updated', 'wp-user-frontend' ),
273
  'type' => 'Fix',
274
  'description' => __( 'User subscription deletion gets reverted if updated is fixed.', 'wp-user-frontend' ),
275
- ),
276
- array(
277
  'title' => __( 'Show Free pack users in subscribers list.', 'wp-user-frontend' ),
278
  'type' => 'Improvement',
279
  'description' => __( 'Free pack users were not showing in subscribers list, now they will.', 'wp-user-frontend' ),
280
- )
281
- )
282
- ),
283
- array(
284
  'version' => 'Version 2.8.7',
285
  'released' => '2018-04-09',
286
- 'changes' => array(
287
- array(
288
  'title' => __( 'WP User Frontend Guten Block is added', 'wp-user-frontend' ),
289
  'type' => 'New',
290
- 'description' => __( 'WPUF Form Block is now available to be used within gutenberg editor with preview of the form. ', 'wp-user-frontend' )
291
- ),
292
- array(
293
  'title' => __( 'Advanced Custom Fields plugin compatibility', 'wp-user-frontend' ),
294
  'type' => 'New',
295
  'description' => __( 'Now all your ACF fields can be used within WPUF Post forms. ', 'wp-user-frontend' ),
296
- ),
297
- array(
298
  'title' => __( 'Taxonomy Terms not showing for custom post types', 'wp-user-frontend' ),
299
  'type' => 'Fix',
300
  'description' => __( 'Fixed an issue with taxonomy terms not appearing for Custom Post types within Form Settings and Dashboard Post Listing', 'wp-user-frontend' ),
301
- ),
302
- array(
303
  'title' => __( 'Various other code optimizations', 'wp-user-frontend' ),
304
  'type' => 'Improvement',
305
  'description' => __( 'Code structure organization and optimization for better performance', 'wp-user-frontend' ),
306
- )
307
- )
308
- ),
309
- array(
310
  'version' => 'Version 2.8.6',
311
  'released' => '2018-03-22',
312
- 'changes' => array(
313
- array(
314
  'title' => __( 'WoooCommerce billing address Sync', 'wp-user-frontend' ),
315
  'type' => 'Improvement',
316
- 'description' => __( 'If an existing customer has previously set his billing address, that will be imported into WPUF Billing address ', 'wp-user-frontend' )
317
- ),
318
- array(
319
  'title' => __( 'Trial subscription message not showing properly', 'wp-user-frontend' ),
320
  'type' => 'Improvement',
321
  'description' => __( 'Subscriptions with Trial now shows trial notices', 'wp-user-frontend' ),
322
- ),
323
- array(
324
  'title' => __( 'Reset email Key not working', 'wp-user-frontend' ),
325
  'type' => 'Fix',
326
  'description' => __( 'Reset Email key was not working in some cases', 'wp-user-frontend' ),
327
- ),
328
- array(
329
  'title' => __( 'Post count not showing on the frontend dashboard', 'wp-user-frontend' ),
330
  'type' => 'Fix',
331
  'description' => __( 'Dashboard with multiple post type was not showing post counts properly, is now fixed and shows count for each post type', 'wp-user-frontend' ),
332
- ),
333
- array(
334
  'title' => __( 'Login Redirect showing blank page is fixed', 'wp-user-frontend' ),
335
  'type' => 'Fix',
336
  'description' => __( 'If "Previous Page" was set for redirection, login redirect was redirecting to blank page for users who hit login page directly', 'wp-user-frontend' ),
337
- ),
338
- )
339
- ),
340
- array(
341
  'version' => 'Version 2.8.5',
342
  'released' => '2018-03-12',
343
- 'changes' => array(
344
- array(
345
  'title' => __( 'Enhanced Login Redirect to redirect users to previous page', 'wp-user-frontend' ),
346
  'type' => 'New',
347
- 'description' => __( 'You can choose Previous Page as Login Redirect page settings now to redirect users to the page from which they went for Login. ', 'wp-user-frontend' )
348
- ),
349
- array(
350
  'title' => __( 'Email HTML links not Rendreing properly issue is fixed', 'wp-user-frontend' ),
351
  'type' => 'Fix',
352
  'description' => __( 'For some clients emails were not rendering the HTML links properly, this is now fixed', 'wp-user-frontend' ),
353
- ),
354
- array(
355
  'title' => __( 'Form Builder : Form Field\'s Help text styles not showing properly', 'wp-user-frontend' ),
356
  'type' => 'Fix',
357
  'description' => __( 'Help texts styling is now fixed and much easier to read and understand', 'wp-user-frontend' ),
358
- ),
359
- array(
360
  'title' => __( 'Various other code improvements', 'wp-user-frontend' ),
361
  'type' => 'Improvement',
362
  'description' => __( 'Code structure organization and optimization for better performance', 'wp-user-frontend' ),
363
- )
364
- )
365
- ),
366
- array(
367
  'version' => 'Version 2.8.4',
368
  'released' => '2018-03-04',
369
- 'changes' => array(
370
- array(
371
  'title' => __( 'Dashboard Post Listing now supports multiple post types', 'wp-user-frontend' ),
372
  'type' => 'New',
373
- 'description' => __( 'Now you can show multiple post type in user dashboard using shortcode like this : <br><b>[wpuf_dashboard post_type="post,page,custom_type"]</b> ', 'wp-user-frontend' )
374
- ),
375
- array(
376
  'title' => __( 'Added Login Redirect Settings', 'wp-user-frontend' ),
377
  'type' => 'New',
378
  'description' => __( 'You can now set a page from <i>WPUF Settings > Login/Registration > Redirect after Login</i>. When login redirection is active the user will be redirected to this page after login.', 'wp-user-frontend' ),
379
- ),
380
- array(
381
  'title' => __( 'Image Upload field button text can be changed', 'wp-user-frontend' ),
382
  'type' => 'New',
383
- 'description' => __( 'The upload button text can now be changed for image upload fields which defaults to "Select Image" if not set. ', 'wp-user-frontend' ).'<img src="'. WPUF_ASSET_URI .'/images/whats-new/image_upload_label.png" alt="Multi-select Category">',
384
- ),
385
- array(
386
  'title' => __( 'Multi Step Form styles made compatible with more themes', 'wp-user-frontend' ),
387
  'type' => 'Fix',
388
  'description' => __( 'Multi Step form can now be styled more easily with other themes ', 'wp-user-frontend' ),
389
- ),
390
- array(
391
  'title' => __( 'Required field condition for google map not working is fixed', 'wp-user-frontend' ),
392
  'type' => 'Fix',
393
  'description' => __( 'If Google Map field was set as required users were able to submit form without changing the default value.', 'wp-user-frontend' ),
394
- )
395
- )
396
- ),
397
- array(
398
  'version' => 'Version 2.8.3',
399
  'released' => '2018-02-15',
400
- 'changes' => array(
401
- array(
402
  'title' => __( 'Admin form builder is now fully responsive.', 'wp-user-frontend' ),
403
  'type' => 'New',
404
- 'description' => __( 'Now you can edit forms from your mobile devices directly. Our improved responsive layouts of form builder makes it easy for you to build forms on the go.', 'wp-user-frontend' )
405
- ),
406
- array(
407
  'title' => __( 'Added color schemes for creating attractive form layouts.', 'wp-user-frontend' ),
408
  'type' => 'New',
409
  'description' => __( 'We have added 3 new color schemes for the form layouts which you can choose from each form\'s new display settings.', 'wp-user-frontend' ),
410
- ),
411
- array(
412
  'title' => __( 'Restrict Free subscription pack to be enabled multiple times ', 'wp-user-frontend' ),
413
  'type' => 'Fix',
414
  'description' => __( 'Free subscription packs now can only be purchased once and the limit applies properly', 'wp-user-frontend' ),
415
- ),
416
- array(
417
  'title' => __( 'Various other bug fixes and improvements were made ', 'wp-user-frontend' ),
418
  'type' => 'Fix',
419
  'description' => __( 'Please see the change log to see full details.', 'wp-user-frontend' ),
420
- ),
421
- )
422
- ),
423
- array(
424
  'version' => 'Version 2.8.2',
425
  'released' => '2018-01-23',
426
- 'changes' => array(
427
- array(
428
  'title' => __( 'Added upgrade function for default category', 'wp-user-frontend' ),
429
  'type' => 'Improvement',
430
- 'description' => __( 'Upgrader added to upgrade previously set default post category.', 'wp-user-frontend' )
431
- ),
432
- array(
433
  'title' => __( 'Subscription pack cannot be canceled', 'wp-user-frontend' ),
434
  'type' => 'Fix',
435
  'description' => __( 'Fixed recurring subscription pack cannot be canceled from my account page in subscription details section.', 'wp-user-frontend' ),
436
- ),
437
- array(
438
  'title' => __( 'page installer admin notice logic issue', 'wp-user-frontend' ),
439
  'type' => 'Fix',
440
  'description' => __( 'Fixed page installer admin notice logic problem due to new payment settings default value not set.', 'wp-user-frontend' ),
441
- ),
442
- )
443
- ),
444
 
445
- array(
446
  'version' => 'Version 2.8.1',
447
  'released' => '2018-01-14',
448
- 'changes' => array(
449
- array(
450
  'title' => __( 'Setup Wizard', 'wp-user-frontend' ),
451
  'type' => 'New',
452
  'description' => __( 'Setup Wizard added to turn off payment options and install pages.', 'wp-user-frontend' ) .
453
- '<img src="'. WPUF_ASSET_URI .'/images/whats-new/wizard.gif" alt="Setup Wizard">'
454
- ),
455
- array(
456
  'title' => __( 'Multi-select Category', 'wp-user-frontend' ),
457
  'type' => 'New',
458
  'description' => __( 'Add multi-select to default category in post form settings.', 'wp-user-frontend' ) .
459
- '<img src="'. WPUF_ASSET_URI .'/images/whats-new/category.png" alt="Multi-select Category">'
460
- ),
461
- array(
462
  'title' => __( 'Select Text option for Taxonomy', 'wp-user-frontend' ),
463
  'type' => 'Improvement',
464
- 'description' => __( 'Add Select Text option for taxonomy fields. Now you can add default text with empty value as first option for Taxonomy dropdown.', 'wp-user-frontend' )
465
- ),
466
- array(
467
  'title' => __( 'Taxonomy Checkbox Inline', 'wp-user-frontend' ),
468
  'type' => 'Improvement',
469
- 'description' => __( 'Added checkbox inline option to taxonomy checkbox. You can now display Taxonomy checkbox fields inline.', 'wp-user-frontend' )
470
- ),
471
- )
472
- ),
473
 
474
- array(
475
  'version' => 'Version 2.8',
476
  'released' => '2018-01-06',
477
- 'changes' => array(
478
- array(
479
  'title' => __( 'Manage schedule for form submission', 'wp-user-frontend' ),
480
  'type' => 'New',
481
  'description' => __( 'Do not accept form submission if the current date is not between the date range of the schedule.', 'wp-user-frontend' ) .
482
- '<img src="'. WPUF_ASSET_URI .'/images/whats-new/schedule.png" alt="Manage schedule for form submission">'
483
- ),
484
- array(
485
  'title' => __( 'Restrict form submission based on the user roles', 'wp-user-frontend' ),
486
  'type' => 'New',
487
  'description' => __( 'Restrict form submission based on the user roles. Now you can manage user role base permission on form submission.', 'wp-user-frontend' ) .
488
- '<img src="'. WPUF_ASSET_URI .'/images/whats-new/role-base.png" alt="Restrict form submission based on the users role">'
489
- ),
490
- array(
491
  'title' => __( 'Limit how many entries a form will accept', 'wp-user-frontend' ),
492
  'type' => 'New',
493
  'description' => __( 'Limit how many entries a form will accept and display a custom message when that limit is reached.', 'wp-user-frontend' ) .
494
- '<img src="'. WPUF_ASSET_URI .'/images/whats-new/limit.png" alt="Limit how many entries a form will accept">'
495
- ),
496
- array(
497
  'title' => __( 'Show/hide Admin Bar', 'wp-user-frontend' ),
498
  'type' => 'New',
499
  'description' => __( 'Control the admin bar visibility based on user roles.', 'wp-user-frontend' ) .
500
- '<img src="'. WPUF_ASSET_URI .'/images/whats-new/admin-bar.png" alt="Show/hide Admin Bar">'
501
- ),
502
- array(
503
  'title' => __( 'Ajax Login widget', 'wp-user-frontend' ),
504
  'type' => 'New',
505
  'description' => __( 'Login user is more simple now with Ajax Login Widget. The simple ajax login form do not required page loading for login.', 'wp-user-frontend' ) .
506
- '<br><br><iframe width="100%" height="372" src="https://www.youtube.com/embed/eZYSuXsCw8E" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>'
507
- ),
508
- array(
509
  'title' => __( 'Form submission with Captcha field', 'wp-user-frontend' ),
510
  'type' => 'Improvement',
511
- 'description' => __( 'Form field validation process updated if form submits with captcha field.', 'wp-user-frontend' )
512
- ),
513
- )
514
- )
515
- );
516
 
517
  function _wpuf_changelog_content( $content ) {
518
  $content = wpautop( $content, true );
@@ -522,7 +522,7 @@ function _wpuf_changelog_content( $content ) {
522
  ?>
523
 
524
  <div class="wrap wpuf-whats-new">
525
- <h1><?php _e( 'What\'s New in WPUF?', 'wp-user-frontend' ); ?></h1>
526
 
527
  <div class="wedevs-changelog-wrapper">
528
 
@@ -531,7 +531,7 @@ function _wpuf_changelog_content( $content ) {
531
  <div class="wedevs-changelog-version">
532
  <h3><?php echo esc_html( $release['version'] ); ?></h3>
533
  <p class="released">
534
- (<?php echo human_time_diff( time(), strtotime( $release['released'] ) ); ?> ago)
535
  </p>
536
  </div>
537
  <div class="wedevs-changelog-history">
@@ -540,11 +540,11 @@ function _wpuf_changelog_content( $content ) {
540
  <li>
541
  <h4>
542
  <span class="title"><?php echo esc_html( $change['title'] ); ?></span>
543
- <span class="label <?php echo strtolower( $change['type'] ); ?>"><?php echo esc_html( $change['type'] ); ?></span>
544
  </h4>
545
 
546
  <div class="description">
547
- <?php echo _wpuf_changelog_content( $change['description'] ); ?>
548
  </div>
549
  </li>
550
  <?php } ?>
1
  <?php
2
+ $changelog = [
3
+ [
4
  'version' => 'Version 3.1.12',
5
  'released' => '2019-10-17',
6
+ 'changes' => [
7
+ [
8
+ 'title' => __( 'Nonce not verify on login', 'wp-user-frontend' ),
9
+ 'type' => 'Fix',
10
+ 'description' => __( 'Return of function wp_verify_nonce() was ignored.', 'wp-user-frontend' ),
11
+ ],
12
+ ],
13
+ ],
14
+ [
15
  'version' => 'Version 3.1.11',
16
  'released' => '2019-10-02',
17
+ 'changes' => [
18
+ [
19
  'title' => __( 'Option to set which tab shows as active on the account page', 'wp-user-frontend' ),
20
  'type' => 'New',
21
  'description' => __( 'Option to set which tab shows as active on the account page. To configure this setting navigate to wp-admin->User Frontend->Settings->My Account->Active Tab ', 'wp-user-frontend' ),
22
+ ],
23
+ [
24
  'title' => __( 'Unlock option was unavailable after the post being locked', 'wp-user-frontend' ),
25
  'type' => 'Fix',
26
+ 'description' => __( 'Unlock option was unavailable after the post being locked.', 'wp-user-frontend' ),
27
+ ],
28
+ [
29
  'title' => __( "Gutenberg block of WPUF didn't work on bedrock installation", 'wp-user-frontend' ),
30
  'type' => 'Fix',
31
+ 'description' => __( "Gutenberg block of WPUF didn't work on bedrock installation.", 'wp-user-frontend' ),
32
+ ],
33
+ [
34
+ 'title' => __( 'Sending admin payment received email twice', 'wp-user-frontend' ),
35
  'type' => 'Fix',
36
+ 'description' => __( 'After processing payment admin & user was receiving payment received email twice.', 'wp-user-frontend' ),
37
+ ],
38
+ [
39
+ 'title' => __( 'Add shortcode support to display post information in the Post Expiration Message', 'wp-user-frontend' ),
40
  'type' => 'Improvement',
41
+ 'description' => __( 'Add shortcode support to display post information in the Post Expiration Message. You can use: <strong>{post_author} {post_url} {blogname} {post_title} {post_status}</strong>', 'wp-user-frontend' ),
42
+ ],
43
+ [
44
+ 'title' => __( 'Add optin on the setup wizard', 'wp-user-frontend' ),
45
  'type' => 'Improvement',
46
+ 'description' => __( 'Added optin on the setup wizard, admin can choose whether he/she wants to share server environment details (php, mysql, server, WordPress versions), Number of users, Site language, Number of active and inactive plugins, Site name and url, admin name and email address. No sensitive data is tracked', 'wp-user-frontend' ),
47
+ ],
48
+ ],
49
+ ],
50
+ [
51
  'version' => 'Version 3.1.10',
52
  'released' => '2019-09-06',
53
+ 'changes' => [
54
+ [
55
  'title' => __( 'Post Owner problem', 'wp-user-frontend' ),
56
  'type' => 'Fix',
57
  'description' => __( 'Posts were not assigned to the selected default post owner, this issue has been fixed.', 'wp-user-frontend' ),
58
+ ],
59
+ [
60
  'title' => __( 'Google reCaptcha was not working', 'wp-user-frontend' ),
61
  'type' => 'Fix',
62
+ 'description' => __( 'Google reCaptcha was not working, users could submit the form without reCaptcha validation.', 'wp-user-frontend' ),
63
+ ],
64
+ ],
65
+ ],
66
+ [
67
  'version' => 'Version 3.1.2',
68
  'released' => '2019-04-01',
69
+ 'changes' => [
70
+ [
71
  'title' => __( 'Added column field', 'wp-user-frontend' ),
72
  'type' => 'New',
73
+ 'description' => 'Now, creating multi-column in a single row is super easy with WPUF Column field. Just drag the column field in the builder area, configure columns number, column space and any fields you want inside that Column field.' . '<img src="' . WPUF_ASSET_URI . '/images/whats-new/column-field.png" alt="Multi-select Category">',
74
+ ],
75
+ [
76
  'title' => __( 'Unable to render the events on the front-end dashboard', 'wp-user-frontend' ),
77
  'type' => 'Fix',
78
+ 'description' => __( 'On the frontend dashboard, the submitted events were not showing, you will get it fixed in this version.', 'wp-user-frontend' ),
79
+ ],
80
+ [
81
  'title' => __( 'Page order getting 0(zero) after editing from the frontend', 'wp-user-frontend' ),
82
  'type' => 'Fix',
83
+ 'description' => __( 'Page order was not saving while editing a post using WPUF form, it has been fixed.', 'wp-user-frontend' ),
84
+ ],
85
+ [
86
  'title' => __( 'Text input field for taxonomies not working', 'wp-user-frontend' ),
87
  'type' => 'Fix',
88
+ 'description' => __( 'When taxonomy field type is set to `Text Input` then a fatal error was showing on the frontend, no error with taxonomy field in the latest version.', 'wp-user-frontend' ),
89
+ ],
90
+ [
91
  'title' => __( 'In radio and checkbox field use conditional logic that value does not save in database', 'wp-user-frontend' ),
92
  'type' => 'Fix',
93
+ 'description' => __( 'The selected value of radio and checkbox field were not showing while editing posts from the backend or frontend, you can see the selected value in this version.', 'wp-user-frontend' ),
94
+ ],
95
+ [
96
  'title' => __( 'The args param not working with get_avatar filter', 'wp-user-frontend' ),
97
  'type' => 'Fix',
98
+ 'description' => __( 'The args parameter did not exist with get_avatar filter, which now exists.', 'wp-user-frontend' ),
99
+ ],
100
+ [
101
  'title' => __( 'The item in ajax taxonomy field was not selected', 'wp-user-frontend' ),
102
  'type' => 'Fix',
103
+ 'description' => __( 'When the taxonomy field type is set to Ajax, the submitted terms were not showing in the backend and frontend which have been fixed.', 'wp-user-frontend' ),
104
+ ],
105
+ ],
106
+ ],
107
+ [
108
  'version' => 'Version 3.1.0',
109
  'released' => '2019-01-31',
110
+ 'changes' => [
111
+ [
112
  'title' => __( 'Unable to send new user registration email', 'wp-user-frontend' ),
113
  'type' => 'Fix',
114
+ 'description' => __( 'WP User Frontend default registration form `[wpuf-registration]` was unable to send the new user registration email.', 'wp-user-frontend' ),
115
+ ],
116
+ [
117
  'title' => __( 'WPUF forms block compatibility issue with the latest WP version', 'wp-user-frontend' ),
118
  'type' => 'Fix',
119
+ 'description' => __( 'With the latest version of WordPress the gutenberg block of WP User Frontend were not working. In this version, you will get it fixed.', 'wp-user-frontend' ),
120
+ ],
121
+ [
122
  'title' => __( 'Page not update where `[wpuf_dashboard]` shortcode exist', 'wp-user-frontend' ),
123
  'type' => 'Fix',
124
+ 'description' => __( 'While using Gutenberg, the page were not being updated with WPUF shortcode [wpuf dashboard]', 'wp-user-frontend' ),
125
+ ],
126
+ [
127
  'title' => __( 'Retain default when determining whether to display the admin bar', 'wp-user-frontend' ),
128
  'type' => 'Fix',
129
+ 'description' => __( "From the User Frontend Settings, set that Administrator, Editor, Vendor can see the admin bar. Now, the super admin want, one specific user ( who has the user role from the above ) can't see the admin bar and disabled it from the Toolbar form that specific user profile. And this configuration ( Toolbar ) from the specific user profile were unable to impact on the frontend.", 'wp-user-frontend' ),
130
+ ],
131
+ [
132
  'title' => __( 'Fatal error when use PHP lower version (5.4 or lower)', 'wp-user-frontend' ),
133
  'type' => 'Fix',
134
+ 'description' => __( "It was unable to install WP User Frontend with PHP 5.4 or lower version. Here is the error details: <br><br><strong>Fatal error: Can't use method return value in write context in /wp-user-frontend/class/frontend-form-post.php on line 194</strong>", 'wp-user-frontend' ),
135
+ ],
136
+ [
137
  'title' => __( 'Product form was unable to show the single gallery image', 'wp-user-frontend' ),
138
  'type' => 'Fix',
139
+ 'description' => __( 'When user upload single image for product gallery using WPUF WooCommerce product form, that image were not showing on the frontend.', 'wp-user-frontend' ),
140
+ ],
141
+ ],
142
+ ],
143
+ [
144
  'version' => 'Version 2.9.4',
145
  'released' => '2018-11-20',
146
+ 'changes' => [
147
+ [
148
  'title' => __( 'WooCommerce gallery images not getting saved', 'wp-user-frontend' ),
149
  'type' => 'Fix',
150
+ 'description' => __( 'After releasing version 2.9.3, WooCommerce gallery image field stopped working. You will get it fixed in this version.', 'wp-user-frontend' ),
151
+ ],
152
+ ],
153
+ ],
154
+ [
155
  'version' => 'Version 2.9.0',
156
  'released' => '2018-08-14',
157
+ 'changes' => [
158
+ [
159
  'title' => __( 'The Events Calendar Integration Form', 'wp-user-frontend' ),
160
  'type' => 'New',
161
+ 'description' => __( 'Now admin can allow users to create event from the frontend. Currently WPUF has a one click pre-build event form that has been integrated with The Events Calendar plugin', 'wp-user-frontend' ),
162
+ ],
163
+ [
164
  'title' => __( 'Post Submission Facility From Account Page', 'wp-user-frontend' ),
165
  'type' => 'New',
166
+ 'description' => __( 'On the frontend account page, added a new menu item named <b>Submit Post</b>. Now admin can allow users to submit post from their default account page. As an admin you can disable or enable this option from <b>User Frontend -> Settings -> My Account -> Post Submission</b>, Also, you can assign any post form that will use to submit posts.', 'wp-user-frontend' ),
167
+ ],
168
+ [
169
  'title' => __( 'Login/Lost Password Link Under Registration Form', 'wp-user-frontend' ),
170
  'type' => 'Improvement',
171
+ 'description' => __( 'Added Login/Lost Password link under registration form', 'wp-user-frontend' ),
172
+ ],
173
+ ],
174
+ ],
175
+ [
176
  'version' => 'Version 2.8.10',
177
  'released' => '2018-07-17',
178
+ 'changes' => [
179
+ [
180
  'title' => __( 'Added drag and drop image ordering on image upload', 'wp-user-frontend' ),
181
  'type' => 'New',
182
+ 'description' => __( 'Now frontend users can drag & drop the images/files to change the order while uploading.', 'wp-user-frontend' ),
183
+ ],
184
+ [
185
  'title' => __( 'Added reCAPTCHA field in login form', 'wp-user-frontend' ),
186
  'type' => 'New',
187
+ 'description' => __( 'Admin has the option to show reCAPTCHA field in login form. Check the related settings from <strong>User Frontend > Settings > Login/Registration</strong>', 'wp-user-frontend' ),
188
+ ],
189
+ [
190
  'title' => __( 'Added preview option in forms', 'wp-user-frontend' ),
191
  'type' => 'New',
192
+ 'description' => __( 'You can see a nice <strong>Preview</strong> button with <strong>Save Form</strong> button, admin can take a quick look of the form without using shortcode', 'wp-user-frontend' ),
193
+ ],
194
+ [
195
  'title' => __( 'Fixed hiding “Select Image” button while uploading multiple images.', 'wp-user-frontend' ),
196
  'type' => 'Fix',
197
+ 'description' => __( 'The upload button will not be hidden until the user selects max number of files ', 'wp-user-frontend' ),
198
+ ],
199
+ [
200
  'title' => __( 'Added form limit notice before form submission', 'wp-user-frontend' ),
201
  'type' => 'Improvement',
202
+ 'description' => __( 'Limit notice message was showing after submission, now it is showing when rendering the form', 'wp-user-frontend' ),
203
+ ],
204
+ [
205
  'title' => __( 'Fixed: default post category not saving', 'wp-user-frontend' ),
206
  'type' => 'Fix',
207
+ 'description' => __( 'From the form <strong>Settings > Post Settings</strong>, default post category options were not saving. Now, it\'s fixed.', 'wp-user-frontend' ),
208
+ ],
209
+ [
210
  'title' => __( 'WPUF dashboard shortcode with form_id attribute was not showing posts properly', 'wp-user-frontend' ),
211
  'type' => 'Fix',
212
+ 'description' => __( 'Now you can list posts on the frontend by using <strong>form_id<strong/> attribute with <strong>[wpuf_dashboard]</strong> shortcode', 'wp-user-frontend' ),
213
+ ],
214
+ ],
215
+ ],
216
+ [
217
  'version' => 'Version 2.8.9',
218
  'released' => '2018-06-06',
219
+ 'changes' => [
220
+ [
221
  'title' => __( 'Changed text domain to `wp-user-frontend` from `wpuf` ', 'wp-user-frontend' ),
222
  'type' => 'Improvement',
223
+ 'description' => __( 'If you are using other language than English. Please <b>rename</b> your <i>.po and .mo </i> files to `wp-user-frontend_` from `wpuf_` <br> This change was made to support translations from translate.wordpress.org', 'wp-user-frontend' ),
224
+ ],
225
+ [
226
  'title' => __( 'Added WP User Frontend Data export and erase functionality.', 'wp-user-frontend' ),
227
  'type' => 'New',
228
+ 'description' => __( 'Added functionality to export WP User Frontend Data to comply with GDPR.', 'wp-user-frontend' ),
229
+ ],
230
+ [
231
  'title' => __( 'Added billing address customizer.', 'wp-user-frontend' ),
232
  'type' => 'New',
233
  'description' => __( 'Added customizer options for billing address in payment page.', 'wp-user-frontend' ),
234
+ ],
235
+ [
236
  'title' => __( 'Make the payment page responsive.', 'wp-user-frontend' ),
237
  'type' => 'Improvement',
238
  'description' => __( 'Some css adjustments are made in payment page to make it responsive.', 'wp-user-frontend' ),
239
+ ],
240
+ [
241
  'title' => __( 'Fixed image upload issue in Safari.', 'wp-user-frontend' ),
242
  'type' => 'Fix',
243
  'description' => __( 'Images were not showing after upload in safari, it is fixed now.', 'wp-user-frontend' ),
244
+ ],
245
+ [
246
  'title' => __( 'Post update issue after updating or removing post images.', 'wp-user-frontend' ),
247
  'type' => 'Fix',
248
  'description' => __( 'Posts cannot be updated after updating or removing post images, it is fixed now.', 'wp-user-frontend' ),
249
+ ],
250
+ ],
251
+ ],
252
+ [
253
  'version' => 'Version 2.8.8',
254
  'released' => '2018-05-16',
255
+ 'changes' => [
256
+ [
257
  'title' => __( 'Allow overriding form input styles using theme styling.', 'wp-user-frontend' ),
258
  'type' => 'New',
259
+ 'description' => __( 'Overriding form input styles using theme style is now possible.', 'wp-user-frontend' ),
260
+ ],
261
+ [
262
  'title' => __( 'Fixed Auto Login after registration.', 'wp-user-frontend' ),
263
  'type' => 'Fix',
264
  'description' => __( 'Auto Login after registration was not working is fixed now.', 'wp-user-frontend' ),
265
+ ],
266
+ [
267
  'title' => __( 'Fixed fallback cost calculation', 'wp-user-frontend' ),
268
  'type' => 'Fix',
269
  'description' => __( 'Fallback cost calculation was inaccurate for some cases, it is fixed now.', 'wp-user-frontend' ),
270
+ ],
271
+ [
272
  'title' => __( 'Removal of subscription from User Profile gets reverted if updated', 'wp-user-frontend' ),
273
  'type' => 'Fix',
274
  'description' => __( 'User subscription deletion gets reverted if updated is fixed.', 'wp-user-frontend' ),
275
+ ],
276
+ [
277
  'title' => __( 'Show Free pack users in subscribers list.', 'wp-user-frontend' ),
278
  'type' => 'Improvement',
279
  'description' => __( 'Free pack users were not showing in subscribers list, now they will.', 'wp-user-frontend' ),
280
+ ],
281
+ ],
282
+ ],
283
+ [
284
  'version' => 'Version 2.8.7',
285
  'released' => '2018-04-09',
286
+ 'changes' => [
287
+ [
288
  'title' => __( 'WP User Frontend Guten Block is added', 'wp-user-frontend' ),
289
  'type' => 'New',
290
+ 'description' => __( 'WPUF Form Block is now available to be used within gutenberg editor with preview of the form. ', 'wp-user-frontend' ),
291
+ ],
292
+ [
293
  'title' => __( 'Advanced Custom Fields plugin compatibility', 'wp-user-frontend' ),
294
  'type' => 'New',
295
  'description' => __( 'Now all your ACF fields can be used within WPUF Post forms. ', 'wp-user-frontend' ),
296
+ ],
297
+ [
298
  'title' => __( 'Taxonomy Terms not showing for custom post types', 'wp-user-frontend' ),
299
  'type' => 'Fix',
300
  'description' => __( 'Fixed an issue with taxonomy terms not appearing for Custom Post types within Form Settings and Dashboard Post Listing', 'wp-user-frontend' ),
301
+ ],
302
+ [
303
  'title' => __( 'Various other code optimizations', 'wp-user-frontend' ),
304
  'type' => 'Improvement',
305
  'description' => __( 'Code structure organization and optimization for better performance', 'wp-user-frontend' ),
306
+ ],
307
+ ],
308
+ ],
309
+ [
310
  'version' => 'Version 2.8.6',
311
  'released' => '2018-03-22',
312
+ 'changes' => [
313
+ [
314
  'title' => __( 'WoooCommerce billing address Sync', 'wp-user-frontend' ),
315
  'type' => 'Improvement',
316
+ 'description' => __( 'If an existing customer has previously set his billing address, that will be imported into WPUF Billing address ', 'wp-user-frontend' ),
317
+ ],
318
+ [
319
  'title' => __( 'Trial subscription message not showing properly', 'wp-user-frontend' ),
320
  'type' => 'Improvement',
321
  'description' => __( 'Subscriptions with Trial now shows trial notices', 'wp-user-frontend' ),
322
+ ],
323
+ [
324
  'title' => __( 'Reset email Key not working', 'wp-user-frontend' ),
325
  'type' => 'Fix',
326
  'description' => __( 'Reset Email key was not working in some cases', 'wp-user-frontend' ),
327
+ ],
328
+ [
329
  'title' => __( 'Post count not showing on the frontend dashboard', 'wp-user-frontend' ),
330
  'type' => 'Fix',
331
  'description' => __( 'Dashboard with multiple post type was not showing post counts properly, is now fixed and shows count for each post type', 'wp-user-frontend' ),
332
+ ],
333
+ [
334
  'title' => __( 'Login Redirect showing blank page is fixed', 'wp-user-frontend' ),
335
  'type' => 'Fix',
336
  'description' => __( 'If "Previous Page" was set for redirection, login redirect was redirecting to blank page for users who hit login page directly', 'wp-user-frontend' ),
337
+ ],
338
+ ],
339
+ ],
340
+ [
341
  'version' => 'Version 2.8.5',
342
  'released' => '2018-03-12',
343
+ 'changes' => [
344
+ [
345
  'title' => __( 'Enhanced Login Redirect to redirect users to previous page', 'wp-user-frontend' ),
346
  'type' => 'New',
347
+ 'description' => __( 'You can choose Previous Page as Login Redirect page settings now to redirect users to the page from which they went for Login. ', 'wp-user-frontend' ),
348
+ ],
349
+ [
350
  'title' => __( 'Email HTML links not Rendreing properly issue is fixed', 'wp-user-frontend' ),
351
  'type' => 'Fix',
352
  'description' => __( 'For some clients emails were not rendering the HTML links properly, this is now fixed', 'wp-user-frontend' ),
353
+ ],
354
+ [
355
  'title' => __( 'Form Builder : Form Field\'s Help text styles not showing properly', 'wp-user-frontend' ),
356
  'type' => 'Fix',
357
  'description' => __( 'Help texts styling is now fixed and much easier to read and understand', 'wp-user-frontend' ),
358
+ ],
359
+ [
360
  'title' => __( 'Various other code improvements', 'wp-user-frontend' ),
361
  'type' => 'Improvement',
362
  'description' => __( 'Code structure organization and optimization for better performance', 'wp-user-frontend' ),
363
+ ],
364
+ ],
365
+ ],
366
+ [
367
  'version' => 'Version 2.8.4',
368
  'released' => '2018-03-04',
369
+ 'changes' => [
370
+ [
371
  'title' => __( 'Dashboard Post Listing now supports multiple post types', 'wp-user-frontend' ),
372
  'type' => 'New',
373
+ 'description' => __( 'Now you can show multiple post type in user dashboard using shortcode like this : <br><b>[wpuf_dashboard post_type="post,page,custom_type"]</b> ', 'wp-user-frontend' ),
374
+ ],
375
+ [
376
  'title' => __( 'Added Login Redirect Settings', 'wp-user-frontend' ),
377
  'type' => 'New',
378
  'description' => __( 'You can now set a page from <i>WPUF Settings > Login/Registration > Redirect after Login</i>. When login redirection is active the user will be redirected to this page after login.', 'wp-user-frontend' ),
379
+ ],
380
+ [
381
  'title' => __( 'Image Upload field button text can be changed', 'wp-user-frontend' ),
382
  'type' => 'New',
383
+ 'description' => __( 'The upload button text can now be changed for image upload fields which defaults to "Select Image" if not set. ', 'wp-user-frontend' ) . '<img src="' . WPUF_ASSET_URI . '/images/whats-new/image_upload_label.png" alt="Multi-select Category">',
384
+ ],
385
+ [
386
  'title' => __( 'Multi Step Form styles made compatible with more themes', 'wp-user-frontend' ),
387
  'type' => 'Fix',
388
  'description' => __( 'Multi Step form can now be styled more easily with other themes ', 'wp-user-frontend' ),
389
+ ],
390
+ [
391
  'title' => __( 'Required field condition for google map not working is fixed', 'wp-user-frontend' ),
392
  'type' => 'Fix',
393
  'description' => __( 'If Google Map field was set as required users were able to submit form without changing the default value.', 'wp-user-frontend' ),
394
+ ],
395
+ ],
396
+ ],
397
+ [
398
  'version' => 'Version 2.8.3',
399
  'released' => '2018-02-15',
400
+ 'changes' => [
401
+ [
402
  'title' => __( 'Admin form builder is now fully responsive.', 'wp-user-frontend' ),
403
  'type' => 'New',
404
+ 'description' => __( 'Now you can edit forms from your mobile devices directly. Our improved responsive layouts of form builder makes it easy for you to build forms on the go.', 'wp-user-frontend' ),
405
+ ],
406
+ [
407
  'title' => __( 'Added color schemes for creating attractive form layouts.', 'wp-user-frontend' ),
408
  'type' => 'New',
409
  'description' => __( 'We have added 3 new color schemes for the form layouts which you can choose from each form\'s new display settings.', 'wp-user-frontend' ),
410
+ ],
411
+ [
412
  'title' => __( 'Restrict Free subscription pack to be enabled multiple times ', 'wp-user-frontend' ),
413
  'type' => 'Fix',
414
  'description' => __( 'Free subscription packs now can only be purchased once and the limit applies properly', 'wp-user-frontend' ),
415
+ ],
416
+ [
417
  'title' => __( 'Various other bug fixes and improvements were made ', 'wp-user-frontend' ),
418
  'type' => 'Fix',
419
  'description' => __( 'Please see the change log to see full details.', 'wp-user-frontend' ),
420
+ ],
421
+ ],
422
+ ],
423
+ [
424
  'version' => 'Version 2.8.2',
425
  'released' => '2018-01-23',
426
+ 'changes' => [
427
+ [
428
  'title' => __( 'Added upgrade function for default category', 'wp-user-frontend' ),
429
  'type' => 'Improvement',
430
+ 'description' => __( 'Upgrader added to upgrade previously set default post category.', 'wp-user-frontend' ),
431
+ ],
432
+ [
433
  'title' => __( 'Subscription pack cannot be canceled', 'wp-user-frontend' ),
434
  'type' => 'Fix',
435
  'description' => __( 'Fixed recurring subscription pack cannot be canceled from my account page in subscription details section.', 'wp-user-frontend' ),
436
+ ],
437
+ [
438
  'title' => __( 'page installer admin notice logic issue', 'wp-user-frontend' ),
439
  'type' => 'Fix',
440
  'description' => __( 'Fixed page installer admin notice logic problem due to new payment settings default value not set.', 'wp-user-frontend' ),
441
+ ],
442
+ ],
443
+ ],
444
 
445
+ [
446
  'version' => 'Version 2.8.1',
447
  'released' => '2018-01-14',
448
+ 'changes' => [
449
+ [
450
  'title' => __( 'Setup Wizard', 'wp-user-frontend' ),
451
  'type' => 'New',
452
  'description' => __( 'Setup Wizard added to turn off payment options and install pages.', 'wp-user-frontend' ) .
453
+ '<img src="' . WPUF_ASSET_URI . '/images/whats-new/wizard.gif" alt="Setup Wizard">',
454
+ ],
455
+ [
456
  'title' => __( 'Multi-select Category', 'wp-user-frontend' ),
457
  'type' => 'New',
458
  'description' => __( 'Add multi-select to default category in post form settings.', 'wp-user-frontend' ) .
459
+ '<img src="' . WPUF_ASSET_URI . '/images/whats-new/category.png" alt="Multi-select Category">',
460
+ ],
461
+ [
462
  'title' => __( 'Select Text option for Taxonomy', 'wp-user-frontend' ),
463
  'type' => 'Improvement',
464
+ 'description' => __( 'Add Select Text option for taxonomy fields. Now you can add default text with empty value as first option for Taxonomy dropdown.', 'wp-user-frontend' ),
465
+ ],
466
+ [
467
  'title' => __( 'Taxonomy Checkbox Inline', 'wp-user-frontend' ),
468
  'type' => 'Improvement',
469
+ 'description' => __( 'Added checkbox inline option to taxonomy checkbox. You can now display Taxonomy checkbox fields inline.', 'wp-user-frontend' ),
470
+ ],
471
+ ],
472
+ ],
473
 
474
+ [
475
  'version' => 'Version 2.8',
476
  'released' => '2018-01-06',
477
+ 'changes' => [
478
+ [
479
  'title' => __( 'Manage schedule for form submission', 'wp-user-frontend' ),
480
  'type' => 'New',
481
  'description' => __( 'Do not accept form submission if the current date is not between the date range of the schedule.', 'wp-user-frontend' ) .
482
+ '<img src="' . WPUF_ASSET_URI . '/images/whats-new/schedule.png" alt="Manage schedule for form submission">',
483
+ ],
484
+ [
485
  'title' => __( 'Restrict form submission based on the user roles', 'wp-user-frontend' ),
486
  'type' => 'New',
487
  'description' => __( 'Restrict form submission based on the user roles. Now you can manage user role base permission on form submission.', 'wp-user-frontend' ) .
488
+ '<img src="' . WPUF_ASSET_URI . '/images/whats-new/role-base.png" alt="Restrict form submission based on the users role">',
489
+ ],
490
+ [
491
  'title' => __( 'Limit how many entries a form will accept', 'wp-user-frontend' ),
492
  'type' => 'New',
493
  'description' => __( 'Limit how many entries a form will accept and display a custom message when that limit is reached.', 'wp-user-frontend' ) .
494
+ '<img src="' . WPUF_ASSET_URI . '/images/whats-new/limit.png" alt="Limit how many entries a form will accept">',
495
+ ],
496
+ [
497
  'title' => __( 'Show/hide Admin Bar', 'wp-user-frontend' ),
498
  'type' => 'New',
499
  'description' => __( 'Control the admin bar visibility based on user roles.', 'wp-user-frontend' ) .
500
+ '<img src="' . WPUF_ASSET_URI . '/images/whats-new/admin-bar.png" alt="Show/hide Admin Bar">',
501
+ ],
502
+ [
503
  'title' => __( 'Ajax Login widget', 'wp-user-frontend' ),
504
  'type' => 'New',
505
  'description' => __( 'Login user is more simple now with Ajax Login Widget. The simple ajax login form do not required page loading for login.', 'wp-user-frontend' ) .
506
+ '<br><br><iframe width="100%" height="372" src="https://www.youtube.com/embed/eZYSuXsCw8E" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>',
507
+ ],
508
+ [
509
  'title' => __( 'Form submission with Captcha field', 'wp-user-frontend' ),
510
  'type' => 'Improvement',
511
+ 'description' => __( 'Form field validation process updated if form submits with captcha field.', 'wp-user-frontend' ),
512
+ ],
513
+ ],
514
+ ],
515
+ ];
516
 
517
  function _wpuf_changelog_content( $content ) {
518
  $content = wpautop( $content, true );
522
  ?>
523
 
524
  <div class="wrap wpuf-whats-new">
525
+ <h1><?php esc_html_e( 'What\'s New in WPUF?', 'wp-user-frontend' ); ?></h1>
526
 
527
  <div class="wedevs-changelog-wrapper">
528
 
531
  <div class="wedevs-changelog-version">
532
  <h3><?php echo esc_html( $release['version'] ); ?></h3>
533
  <p class="released">
534
+ (<?php echo esc_html( human_time_diff( time(), strtotime( $release['released'] ) ) ); ?> ago)
535
  </p>
536
  </div>
537
  <div class="wedevs-changelog-history">
540
  <li>
541
  <h4>
542
  <span class="title"><?php echo esc_html( $change['title'] ); ?></span>
543
+ <span class="label <?php echo esc_html( strtolower( $change['type'] ) ); ?>"><?php echo esc_html( $change['type'] ); ?></span>
544
  </h4>
545
 
546
  <div class="description">
547
+ <?php echo esc_html( _wpuf_changelog_content( $change['description'] ) ); ?>
548
  </div>
549
  </li>
550
  <?php } ?>
admin/installer.php CHANGED
@@ -7,9 +7,9 @@
7
  */
8
  class WPUF_Admin_Installer {
9
 
10
- function __construct() {
11
- add_action( 'admin_notices', array($this, 'admin_notice') );
12
- add_action( 'admin_init', array($this, 'handle_request') );
13
  }
14
 
15
  /**
@@ -17,19 +17,19 @@ class WPUF_Admin_Installer {
17
  *
18
  * @return void
19
  */
20
- function admin_notice() {
21
  $page_created = get_option( '_wpuf_page_created' );
22
 
23
  if ( $page_created != '1' && 'off' == wpuf_get_option( 'install_wpuf_pages', 'wpuf_general', 'on' ) ) {
24
  ?>
25
  <div class="updated error">
26
  <p>
27
- <?php _e( 'If you have not created <strong>WP User Frontend</strong> pages yet, you can do this by one click.', 'wp-user-frontend' ); ?>
28
  </p>
29
  <p class="submit">
30
- <a class="button button-primary" href="<?php echo add_query_arg( array( 'install_wpuf_pages' => true ), admin_url( 'admin.php?page=wpuf-settings' ) ); ?>"><?php _e( 'Install WPUF Pages', 'wp-user-frontend' ); ?></a>
31
- <?php _e( 'or', 'wp-user-frontend' ); ?>
32
- <a class="button" href="<?php echo add_query_arg( array( 'wpuf_hide_page_nag' => true ) ); ?>"><?php _e( 'Skip Setup', 'wp-user-frontend' ); ?></a>
33
  </p>
34
  </div>
35
  <?php
@@ -39,7 +39,7 @@ class WPUF_Admin_Installer {
39
  ?>
40
  <div class="updated">
41
  <p>
42
- <strong><?php _e( 'Congratulations!', 'wp-user-frontend' ); ?></strong> <?php _e( 'Pages for <strong>WP User Frontend</strong> has been successfully installed and saved!', 'wp-user-frontend' ); ?>
43
  </p>
44
  </div>
45
  <?php
@@ -51,7 +51,13 @@ class WPUF_Admin_Installer {
51
  *
52
  * @return void
53
  */
54
- function handle_request() {
 
 
 
 
 
 
55
  if ( isset( $_GET['install_wpuf_pages'] ) && $_GET['install_wpuf_pages'] == '1' ) {
56
  $this->init_pages();
57
  }
@@ -69,9 +75,10 @@ class WPUF_Admin_Installer {
69
  * Initialize the plugin with some default page/settings
70
  *
71
  * @since 2.2
 
72
  * @return void
73
  */
74
- function init_pages() {
75
 
76
  // create a dashboard page
77
  $dashboard_page = $this->create_page( __( 'Dashboard', 'wp-user-frontend' ), '[wpuf_dashboard]' );
@@ -85,23 +92,23 @@ class WPUF_Admin_Installer {
85
 
86
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
87
  // payment page
88
- $subscr_page = $this->create_page( __( 'Subscription', 'wp-user-frontend' ), __( '[wpuf_sub_pack]', 'wp-user-frontend') );
89
- $payment_page = $this->create_page( __( 'Payment', 'wp-user-frontend' ), __( 'Please select a gateway for payment', 'wp-user-frontend') );
90
- $thank_page = $this->create_page( __( 'Thank You', 'wp-user-frontend' ), __( '<h1>Payment is complete</h1><p>Congratulations, your payment has been completed!</p>', 'wp-user-frontend') );
91
- $bank_page = $this->create_page( __( 'Order Received', 'wp-user-frontend' ), __( 'Hi, we have received your order. We will validate the order and will take necessary steps to move forward.', 'wp-user-frontend') );
92
  }
93
 
94
  // save the settings
95
  if ( $edit_page ) {
96
- update_option( 'wpuf_frontend_posting', array(
97
  'edit_page_id' => $edit_page,
98
- 'default_post_form' => $post_form
99
- ) );
100
  }
101
 
102
  // profile pages
103
- $profile_options = array();
104
- $reg_page = false;
105
 
106
  if ( $login_page ) {
107
  $profile_options['login_page'] = $login_page;
@@ -110,11 +117,11 @@ class WPUF_Admin_Installer {
110
  $data = apply_filters( 'wpuf_pro_page_install', $profile_options );
111
 
112
  if ( is_array( $data ) ) {
113
-
114
- if ( isset ( $data['profile_options'] ) ) {
115
  $profile_options = $data['profile_options'];
116
  }
117
- if ( isset ( $data['reg_page'] ) ) {
 
118
  $reg_page = $data['reg_page'];
119
  }
120
  }
@@ -127,17 +134,18 @@ class WPUF_Admin_Installer {
127
 
128
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
129
  // payment pages
130
- update_option( 'wpuf_payment', array(
131
  'subscription_page' => $subscr_page,
132
  'payment_page' => $payment_page,
133
  'payment_success' => $thank_page,
134
- 'bank_success' => $bank_page
135
- ) );
136
  }
137
 
138
  update_option( '_wpuf_page_created', '1' );
139
 
140
- if ( $_GET['page'] != 'wpuf-setup' ) {
 
141
  wp_redirect( admin_url( 'admin.php?page=wpuf-settings&wpuf_page_installed=1' ) );
142
  exit;
143
  }
@@ -146,20 +154,21 @@ class WPUF_Admin_Installer {
146
  /**
147
  * Create a page with title and content
148
  *
149
- * @param string $page_title
150
- * @param string $post_content
 
151
  * @return false|int
152
  */
153
- function create_page( $page_title, $post_content = '', $post_type = 'page' ) {
154
- $page_id = wp_insert_post( array(
155
  'post_title' => $page_title,
156
  'post_type' => $post_type,
157
  'post_status' => 'publish',
158
  'comment_status' => 'closed',
159
- 'post_content' => $post_content
160
- ) );
161
 
162
- if ( $page_id && ! is_wp_error( $page_id ) ) {
163
  return $page_id;
164
  }
165
 
@@ -169,9 +178,9 @@ class WPUF_Admin_Installer {
169
  /**
170
  * Create a basic registration form by default
171
  *
172
- * @return int|boolean
173
  */
174
- function create_reg_form() {
175
  return wpuf_create_sample_form( __( 'Registration', 'wp-user-frontend' ), 'wpuf_profile' );
176
  }
177
 
@@ -180,8 +189,7 @@ class WPUF_Admin_Installer {
180
  *
181
  * @return void
182
  */
183
- function create_form() {
184
  return wpuf_create_sample_form( __( 'Sample Form', 'wp-user-frontend' ), 'wpuf_forms' );
185
  }
186
-
187
  }
7
  */
8
  class WPUF_Admin_Installer {
9
 
10
+ public function __construct() {
11
+ add_action( 'admin_notices', [$this, 'admin_notice'] );
12
+ add_action( 'admin_init', [$this, 'handle_request'] );
13
  }
14
 
15
  /**
17
  *
18
  * @return void
19
  */
20
+ public function admin_notice() {
21
  $page_created = get_option( '_wpuf_page_created' );
22
 
23
  if ( $page_created != '1' && 'off' == wpuf_get_option( 'install_wpuf_pages', 'wpuf_general', 'on' ) ) {
24
  ?>
25
  <div class="updated error">
26
  <p>
27
+ <?php esc_html_e( 'If you have not created <strong>WP User Frontend</strong> pages yet, you can do this by one click.', 'wp-user-frontend' ); ?>
28
  </p>
29
  <p class="submit">
30
+ <a class="button button-primary" href="<?php echo esc_url( add_query_arg( [ 'install_wpuf_pages' => true ], admin_url( 'admin.php?page=wpuf-settings' ) ) ); ?>"><?php esc_html_e( 'Install WPUF Pages', 'wp-user-frontend' ); ?></a>
31
+ <?php esc_html_e( 'or', 'wp-user-frontend' ); ?>
32
+ <a class="button" href="<?php echo esc_url( add_query_arg( [ 'wpuf_hide_page_nag' => true ] ) ); ?>"><?php esc_html_e( 'Skip Setup', 'wp-user-frontend' ); ?></a>
33
  </p>
34
  </div>
35
  <?php
39
  ?>
40
  <div class="updated">
41
  <p>
42
+ <strong><?php esc_html_e( 'Congratulations!', 'wp-user-frontend' ); ?></strong> <?php echo wp_kses_post( 'Pages for <strong>WP User Frontend</strong> has been successfully installed and saved!', 'wp-user-frontend' ); ?>
43
  </p>
44
  </div>
45
  <?php
51
  *
52
  * @return void
53
  */
54
+ public function handle_request() {
55
+ $nonce = isset($_REQUEST['wpuf_steup'] ) ? sanitize_key( wp_unslash( $_REQUEST['wpuf_steup'] ) ) : '';
56
+
57
+ if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( 'wpuf_steup' ) ) {
58
+
59
+ }
60
+
61
  if ( isset( $_GET['install_wpuf_pages'] ) && $_GET['install_wpuf_pages'] == '1' ) {
62
  $this->init_pages();
63
  }
75
  * Initialize the plugin with some default page/settings
76
  *
77
  * @since 2.2
78
+ *
79
  * @return void
80
  */
81
+ public function init_pages() {
82
 
83
  // create a dashboard page
84
  $dashboard_page = $this->create_page( __( 'Dashboard', 'wp-user-frontend' ), '[wpuf_dashboard]' );
92
 
93
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
94
  // payment page
95
+ $subscr_page = $this->create_page( __( 'Subscription', 'wp-user-frontend' ), __( '[wpuf_sub_pack]', 'wp-user-frontend' ) );
96
+ $payment_page = $this->create_page( __( 'Payment', 'wp-user-frontend' ), __( 'Please select a gateway for payment', 'wp-user-frontend' ) );
97
+ $thank_page = $this->create_page( __( 'Thank You', 'wp-user-frontend' ), __( '<h1>Payment is complete</h1><p>Congratulations, your payment has been completed!</p>', 'wp-user-frontend' ) );
98
+ $bank_page = $this->create_page( __( 'Order Received', 'wp-user-frontend' ), __( 'Hi, we have received your order. We will validate the order and will take necessary steps to move forward.', 'wp-user-frontend' ) );
99
  }
100
 
101
  // save the settings
102
  if ( $edit_page ) {
103
+ update_option( 'wpuf_frontend_posting', [
104
  'edit_page_id' => $edit_page,
105
+ 'default_post_form' => $post_form,
106
+ ] );
107
  }
108
 
109
  // profile pages
110
+ $profile_options = [];
111
+ $reg_page = false;
112
 
113
  if ( $login_page ) {
114
  $profile_options['login_page'] = $login_page;
117
  $data = apply_filters( 'wpuf_pro_page_install', $profile_options );
118
 
119
  if ( is_array( $data ) ) {
120
+ if ( isset( $data['profile_options'] ) ) {
 
121
  $profile_options = $data['profile_options'];
122
  }
123
+
124
+ if ( isset( $data['reg_page'] ) ) {
125
  $reg_page = $data['reg_page'];
126
  }
127
  }
134
 
135
  if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
136
  // payment pages
137
+ update_option( 'wpuf_payment', [
138
  'subscription_page' => $subscr_page,
139
  'payment_page' => $payment_page,
140
  'payment_success' => $thank_page,
141
+ 'bank_success' => $bank_page,
142
+ ] );
143
  }
144
 
145
  update_option( '_wpuf_page_created', '1' );
146
 
147
+ $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
148
+ if ( $page != 'wpuf-setup' ) {
149
  wp_redirect( admin_url( 'admin.php?page=wpuf-settings&wpuf_page_installed=1' ) );
150
  exit;
151
  }
154
  /**
155
  * Create a page with title and content
156
  *
157
+ * @param string $page_title
158
+ * @param string $post_content
159
+ *
160
  * @return false|int
161
  */
162
+ public function create_page( $page_title, $post_content = '', $post_type = 'page' ) {
163
+ $page_id = wp_insert_post( [
164
  'post_title' => $page_title,
165
  'post_type' => $post_type,
166
  'post_status' => 'publish',
167
  'comment_status' => 'closed',
168
+ 'post_content' => $post_content,
169
+ ] );
170
 
171
+ if ( $page_id && !is_wp_error( $page_id ) ) {
172
  return $page_id;
173
  }
174
 
178
  /**
179
  * Create a basic registration form by default
180
  *
181
+ * @return int|bool
182
  */
183
+ public function create_reg_form() {
184
  return wpuf_create_sample_form( __( 'Registration', 'wp-user-frontend' ), 'wpuf_profile' );
185
  }
186
 
189
  *
190
  * @return void
191
  */
192
+ public function create_form() {
193
  return wpuf_create_sample_form( __( 'Sample Form', 'wp-user-frontend' ), 'wpuf_forms' );
194
  }
 
195
  }
admin/post-forms-list-table-view.php CHANGED
@@ -1,13 +1,13 @@
1
  <div class="wrap">
2
  <h2>
3
  <?php
4
- _e( 'Post Forms', 'wp-user-frontend' );
5
 
6
- if ( current_user_can( wpuf_admin_role() ) ):
7
- ?>
8
- <a href="<?php echo $add_new_page_url; ?>" id="new-wpuf-post-form" class="page-title-action add-form"><?php _e( 'Add Form', 'wp-user-frontend' ); ?></a>
9
  <?php
10
- endif;
11
  ?>
12
  </h2>
13
 
@@ -36,7 +36,7 @@
36
  <div class="wpuf-footer-help">
37
  <span class="wpuf-footer-help-content">
38
  <span class="dashicons dashicons-editor-help"></span>
39
- <?php printf( __( 'Learn more about <a href="%s" target="_blank">Frontend Posting</a>', 'wp-user-frontend' ), 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/?utm_source=wpuf-footer-help&utm_medium=text-link&utm_campaign=learn-more-frontend-posting' ); ?>
40
  </span>
41
  </div>
42
  </div>
1
  <div class="wrap">
2
  <h2>
3
  <?php
4
+ esc_html_e( 'Post Forms', 'wp-user-frontend' );
5
 
6
+ if ( current_user_can( wpuf_admin_role() ) ) {
7
+ ?>
8
+ <a href="<?php echo esc_url( $add_new_page_url ); ?>" id="new-wpuf-post-form" class="page-title-action add-form"><?php esc_html_e( 'Add Form', 'wp-user-frontend' ); ?></a>
9
  <?php
10
+ }
11
  ?>
12
  </h2>
13
 
36
  <div class="wpuf-footer-help">
37
  <span class="wpuf-footer-help-content">
38
  <span class="dashicons dashicons-editor-help"></span>
39
+ <?php printf( wp_kses_post( __( 'Learn more about <a href="%s" target="_blank">Frontend Posting</a>', 'wp-user-frontend' ) ), 'https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/?utm_source=wpuf-footer-help&utm_medium=text-link&utm_campaign=learn-more-frontend-posting' ); ?>
40
  </span>
41
  </div>
42
  </div>
admin/post-forms-list-table.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- if ( ! class_exists( 'WP_List_Table' ) ) {
4
  require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
  }
6
 
@@ -21,11 +21,11 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
21
  public function __construct() {
22
  global $status, $page, $page_status;
23
 
24
- parent::__construct( array(
25
  'singular' => 'post-form',
26
  'plural' => 'post-forms',
27
- 'ajax' => false
28
- ) );
29
  }
30
 
31
  /**
@@ -36,16 +36,16 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
36
  * @return array
37
  */
38
  public function get_views() {
39
- $status_links = array();
40
  $base_link = admin_url( 'admin.php?page=wpuf-post-forms' );
41
 
42
- $post_statuses = apply_filters( 'wpuf_post_forms_list_table_post_statuses', array(
43
  'all' => __( 'All', 'wp-user-frontend' ),
44
  'publish' => __( 'Published', 'wp-user-frontend' ),
45
- 'trash' => __( 'Trash', 'wp-user-frontend' )
46
- ) );
47
 
48
- $current_status = isset( $_GET['post_status'] ) ? $_GET['post_status'] : 'all';
49
 
50
  $post_counts = (array) wp_count_posts( 'wpuf_forms' );
51
 
@@ -78,7 +78,7 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
78
  $status_links[ $status ] = sprintf(
79
  '<a class="%s" href="%s">%s <span class="count">(%s)</span></a>',
80
  $class, $link, $status_title, $count
81
- );
82
  }
83
 
84
  return apply_filters( 'wpuf_post_forms_list_table_get_views', $status_links, $post_statuses, $current_status );
@@ -92,7 +92,7 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
92
  * @return void
93
  */
94
  public function no_items() {
95
- _e( 'No form found.', 'wp-user-frontend' );
96
  }
97
 
98
  /**
@@ -103,9 +103,9 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
103
  * @return array
104
  */
105
  public function get_bulk_actions() {
106
- $actions = array();
107
 
108
- if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
109
  $actions['trash'] = __( 'Move to Trash', 'wp-user-frontend' );
110
  }
111
 
@@ -128,31 +128,50 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
128
  * @return void
129
  */
130
  public function search_box( $text, $input_id ) {
131
- if ( empty( $_GET['s'] ) && ! $this->has_items() ) {
132
  return;
133
  }
134
 
135
- if ( ! empty( $_GET['orderby'] ) ) {
136
- echo '<input type="hidden" name="orderby" value="' . esc_attr( $_GET['orderby'] ) . '" />';
 
 
 
 
 
 
 
137
  }
138
 
139
- if ( ! empty( $_GET['order'] ) ) {
140
- echo '<input type="hidden" name="order" value="' . esc_attr( $_GET['order'] ) . '" />';
 
 
 
 
 
 
 
141
  }
142
 
143
- if ( ! empty( $_GET['post_status'] ) ) {
144
- echo '<input type="hidden" name="post_status" value="' . esc_attr( $_GET['post_status'] ) . '" />';
 
 
 
 
 
 
 
145
  }
146
 
147
  do_action( 'wpuf_post_forms_list_table_search_box', $text, $input_id );
148
 
149
- $input_id = $input_id . '-search-input';
150
-
151
- ?>
152
  <p class="search-box">
153
- <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
154
- <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
155
- <?php submit_button( $text, 'button', 'post_form_search', false, array( 'id' => 'search-submit' ) ); ?>
156
  </p>
157
  <?php
158
  }
@@ -165,7 +184,6 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
165
  * @return string
166
  */
167
  public function current_action() {
168
-
169
  if ( isset( $_GET['post_form_search'] ) ) {
170
  return 'post_form_search';
171
  }
@@ -182,45 +200,44 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
182
  */
183
  public function prepare_items() {
184
  $columns = $this->get_columns();
185
- $hidden = array();
186
  $sortable = $this->get_sortable_columns();
187
- $this->_column_headers = array( $columns, $hidden, $sortable );
188
 
189
  $per_page = get_option( 'posts_per_page', 20 );
190
  $current_page = $this->get_pagenum();
191
  $offset = ( $current_page - 1 ) * $per_page;
192
 
193
- $args = array(
194
  'offset' => $offset,
195
  'posts_per_page' => $per_page,
196
- );
197
 
198
  if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
199
- $args['s'] = $_GET['s'];
200
  }
201
 
202
  if ( isset( $_GET['post_status'] ) && !empty( $_GET['post_status'] ) ) {
203
- $args['post_status'] = $_GET['post_status'];
204
  }
205
 
206
  if ( isset( $_GET['orderby'] ) && !empty( $_GET['orderby'] ) ) {
207
- $args['orderby'] = $_GET['orderby'];
208
  }
209
 
210
  if ( isset( $_GET['order'] ) && !empty( $_GET['order'] ) ) {
211
- $args['order'] = $_GET['order'];
212
  }
213
 
214
-
215
  $items = $this->item_query( $args );
216
 
217
  $this->counts = $items['count'];
218
  $this->items = $items['forms'];
219
 
220
- $this->set_pagination_args( array(
221
  'total_items' => $items['count'],
222
- 'per_page' => $per_page
223
- ) );
224
  }
225
 
226
  /**
@@ -233,11 +250,11 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
233
  * @return array
234
  */
235
  public function item_query( $args ) {
236
- $defauls = array(
237
  'post_status' => 'any',
238
  'orderby' => 'DESC',
239
  'order' => 'ID',
240
- );
241
 
242
  $args = wp_parse_args( $args, $defauls );
243
 
@@ -245,10 +262,9 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
245
 
246
  $query = new WP_Query( $args );
247
 
248
- $forms = array();
249
 
250
  if ( $query->have_posts() ) {
251
-
252
  $i = 0;
253
 
254
  while ( $query->have_posts() ) {
@@ -258,14 +274,14 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
258
 
259
  $settings = get_post_meta( get_the_ID(), 'wpuf_form_settings', true );
260
 
261
- $forms[ $i ] = array(
262
  'ID' => $form->ID,
263
  'post_title' => $form->post_title,
264
  'post_status' => $form->post_status,
265
  'settings_post_type' => isset( $settings['post_type'] ) ? $settings['post_type'] : '',
266
  'settings_post_status' => isset( $settings['post_status'] ) ? $settings['post_status'] : '',
267
  'settings_guest_post' => isset( $settings['guest_post'] ) ? $settings['guest_post'] : '',
268
- );
269
 
270
  $i++;
271
  }
@@ -276,10 +292,10 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
276
 
277
  wp_reset_postdata();
278
 
279
- return array(
280
  'forms' => $forms,
281
- 'count' => $count
282
- );
283
  }
284
 
285
  /**
@@ -290,14 +306,14 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
290
  * @return array
291
  */
292
  public function get_columns() {
293
- $columns = array(
294
  'cb' => '<input type="checkbox" />',
295
  'form_name' => __( 'Form Name', 'wp-user-frontend' ),
296
  'post_type' => __( 'Post Type', 'wp-user-frontend' ),
297
  'post_status' => __( 'Post Status', 'wp-user-frontend' ),
298
  'guest_post' => __( 'Guest Post', 'wp-user-frontend' ),
299
  'shortcode' => __( 'Shortcode', 'wp-user-frontend' ),
300
- );
301
 
302
  return apply_filters( 'wpuf_post_forms_list_table_cols', $columns );
303
  }
@@ -310,9 +326,9 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
310
  * @return array
311
  */
312
  public function get_sortable_columns() {
313
- $sortable_columns = array(
314
- 'form_name' => array( 'form_name', false ),
315
- );
316
 
317
  return apply_filters( 'wpuf_post_forms_list_table_sortable_columns', $sortable_columns );
318
  }
@@ -322,7 +338,7 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
322
  *
323
  * @since 2.5
324
  *
325
- * @param array $item
326
  * @param string $column_name
327
  *
328
  * @return string
@@ -375,10 +391,9 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
375
  * @return string
376
  */
377
  public function column_form_name( $item ) {
378
- $actions = array();
379
 
380
  $edit_url = admin_url( 'admin.php?page=wpuf-post-forms&action=edit&id=' . $item['ID'] );
381
-
382
  $wpnonce = wp_create_nonce( 'bulk-post-forms' );
383
  $admin_url = admin_url( 'admin.php?page=wpuf-post-forms&id=' . $item['ID'] . '&_wpnonce=' . $wpnonce );
384
 
@@ -418,5 +433,4 @@ class WPUF_Admin_Post_Forms_List_Table extends WP_List_Table {
418
 
419
  return apply_filters( 'wpuf_post_forms_list_table_column_form_name', $form_name, $item );
420
  }
421
-
422
  }
1
  <?php
2
 
3
+ if ( !class_exists( 'WP_List_Table' ) ) {
4
  require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
  }
6
 
21
  public function __construct() {
22
  global $status, $page, $page_status;
23
 
24
+ parent::__construct( [
25
  'singular' => 'post-form',
26
  'plural' => 'post-forms',
27
+ 'ajax' => false,
28
+ ] );
29
  }
30
 
31
  /**
36
  * @return array
37
  */
38
  public function get_views() {
39
+ $status_links = [];
40
  $base_link = admin_url( 'admin.php?page=wpuf-post-forms' );
41
 
42
+ $post_statuses = apply_filters( 'wpuf_post_forms_list_table_post_statuses', [
43
  'all' => __( 'All', 'wp-user-frontend' ),
44
  'publish' => __( 'Published', 'wp-user-frontend' ),
45
+ 'trash' => __( 'Trash', 'wp-user-frontend' ),
46
+ ] );
47
 
48
+ $current_status = isset( $_GET['post_status'] ) ? sanitize_text_field( wp_unslash( $_GET['post_status'] ) ) : 'all';
49
 
50
  $post_counts = (array) wp_count_posts( 'wpuf_forms' );
51
 
78
  $status_links[ $status ] = sprintf(
79
  '<a class="%s" href="%s">%s <span class="count">(%s)</span></a>',
80
  $class, $link, $status_title, $count
81
+ );
82
  }
83
 
84
  return apply_filters( 'wpuf_post_forms_list_table_get_views', $status_links, $post_statuses, $current_status );
92
  * @return void
93
  */
94
  public function no_items() {
95
+ esc_html_e( 'No form found.', 'wp-user-frontend' );
96
  }
97
 
98
  /**
103
  * @return array
104
  */
105
  public function get_bulk_actions() {
106
+ $actions = [];
107
 
108
+ if ( !isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
109
  $actions['trash'] = __( 'Move to Trash', 'wp-user-frontend' );
110
  }
111
 
128
  * @return void
129
  */
130
  public function search_box( $text, $input_id ) {
131
+ if ( empty( $_GET['s'] ) && !$this->has_items() ) {
132
  return;
133
  }
134
 
135
+ if ( !empty( $_GET['orderby'] ) ) {
136
+ $orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) );
137
+ echo wp_kses('<input type="hidden" name="orderby" value="' . esc_attr( $orderby ) . '" />', [
138
+ 'input' => [
139
+ 'type' => [],
140
+ 'name' => [],
141
+ 'value' => [],
142
+ ]
143
+ ]);
144
  }
145
 
146
+ if ( !empty( $_GET['order'] ) ) {
147
+ $order = sanitize_text_field( wp_unslash( $_GET['order'] ) );
148
+ echo wp_kses( '<input type="hidden" name="order" value="' . esc_attr( $order ) . '" />', [
149
+ 'input' => [
150
+ 'type' => [],
151
+ 'name' => [],
152
+ 'value' => [],
153
+ ]
154
+ ] );
155
  }
156
 
157
+ if ( !empty( $_GET['post_status'] ) ) {
158
+ $post_status = sanitize_text_field( wp_unslash( $_GET['post_status'] ) );
159
+ echo wp_kses( '<input type="hidden" name="post_status" value="' . esc_attr( $post_status ) . '" />', [
160
+ 'input' => [
161
+ 'type' => [],
162
+ 'name' => [],
163
+ 'value' => [],
164
+ ]
165
+ ] );
166
  }
167
 
168
  do_action( 'wpuf_post_forms_list_table_search_box', $text, $input_id );
169
 
170
+ $input_id = $input_id . '-search-input'; ?>
 
 
171
  <p class="search-box">
172
+ <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_attr( $text ); ?>:</label>
173
+ <input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" value="<?php _admin_search_query(); ?>" />
174
+ <?php submit_button( $text, 'button', 'post_form_search', false, [ 'id' => 'search-submit' ] ); ?>
175
  </p>
176
  <?php
177
  }
184
  * @return string
185
  */
186
  public function current_action() {
 
187
  if ( isset( $_GET['post_form_search'] ) ) {
188
  return 'post_form_search';
189
  }
200
  */
201
  public function prepare_items() {
202
  $columns = $this->get_columns();
203
+ $hidden = [];
204
  $sortable = $this->get_sortable_columns();
205
+ $this->_column_headers = [ $columns, $hidden, $sortable ];
206
 
207
  $per_page = get_option( 'posts_per_page', 20 );
208
  $current_page = $this->get_pagenum();
209
  $offset = ( $current_page - 1 ) * $per_page;
210
 
211
+ $args = [
212
  'offset' => $offset,
213
  'posts_per_page' => $per_page,
214
+ ];
215
 
216
  if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
217
+ $args['s'] = sanitize_text_field( wp_unslash( $_GET['s'] ) );
218
  }
219
 
220
  if ( isset( $_GET['post_status'] ) && !empty( $_GET['post_status'] ) ) {
221
+ $args['post_status'] = sanitize_text_field( wp_unslash( $_GET['post_status'] ) );
222
  }
223
 
224
  if ( isset( $_GET['orderby'] ) && !empty( $_GET['orderby'] ) ) {
225
+ $args['orderby'] = sanitize_text_field( wp_unslash( $_GET['orderby'] ) );
226
  }
227
 
228
  if ( isset( $_GET['order'] ) && !empty( $_GET['order'] ) ) {
229
+ $args['order'] = sanitize_text_field( wp_unslash( $_GET['order'] ) );
230
  }
231
 
 
232
  $items = $this->item_query( $args );
233
 
234
  $this->counts = $items['count'];
235
  $this->items = $items['forms'];
236
 
237
+ $this->set_pagination_args( [
238
  'total_items' => $items['count'],
239
+ 'per_page' => $per_page,
240
+ ] );
241
  }
242
 
243
  /**
250
  * @return array
251
  */
252
  public function item_query( $args ) {
253
+ $defauls = [
254
  'post_status' => 'any',
255
  'orderby' => 'DESC',
256
  'order' => 'ID',
257
+ ];
258
 
259
  $args = wp_parse_args( $args, $defauls );
260
 
262
 
263
  $query = new WP_Query( $args );
264
 
265
+ $forms = [];
266
 
267
  if ( $query->have_posts() ) {
 
268
  $i = 0;
269
 
270
  while ( $query->have_posts() ) {
274
 
275
  $settings = get_post_meta( get_the_ID(), 'wpuf_form_settings', true );
276
 
277
+ $forms[ $i ] = [
278
  'ID' => $form->ID,
279
  'post_title' => $form->post_title,
280
  'post_status' => $form->post_status,
281
  'settings_post_type' => isset( $settings['post_type'] ) ? $settings['post_type'] : '',
282
  'settings_post_status' => isset( $settings['post_status'] ) ? $settings['post_status'] : '',
283
  'settings_guest_post' => isset( $settings['guest_post'] ) ? $settings['guest_post'] : '',
284
+ ];
285
 
286
  $i++;
287
  }
292
 
293
  wp_reset_postdata();
294
 
295
+ return [
296
  'forms' => $forms,
297
+ 'count' => $count,
298
+ ];
299
  }
300
 
301
  /**
306
  * @return array
307
  */
308
  public function get_columns() {
309
+ $columns = [
310
  'cb' => '<input type="checkbox" />',
311
  'form_name' => __( 'Form Name', 'wp-user-frontend' ),
312
  'post_type' => __( 'Post Type', 'wp-user-frontend' ),
313
  'post_status' => __( 'Post Status', 'wp-user-frontend' ),
314
  'guest_post' => __( 'Guest Post', 'wp-user-frontend' ),
315
  'shortcode' => __( 'Shortcode', 'wp-user-frontend' ),
316
+ ];
317
 
318
  return apply_filters( 'wpuf_post_forms_list_table_cols', $columns );
319
  }
326
  * @return array
327
  */
328
  public function get_sortable_columns() {
329
+ $sortable_columns = [
330
+ 'form_name' => [ 'form_name', false ],
331
+ ];
332
 
333
  return apply_filters( 'wpuf_post_forms_list_table_sortable_columns', $sortable_columns );
334
  }
338
  *
339
  * @since 2.5
340
  *
341
+ * @param array $item
342
  * @param string $column_name
343
  *
344
  * @return string
391
  * @return string
392
  */
393
  public function column_form_name( $item ) {
394
+ $actions = [];
395
 
396
  $edit_url = admin_url( 'admin.php?page=wpuf-post-forms&action=edit&id=' . $item['ID'] );
 
397
  $wpnonce = wp_create_nonce( 'bulk-post-forms' );
398
  $admin_url = admin_url( 'admin.php?page=wpuf-post-forms&id=' . $item['ID'] . '&_wpnonce=' . $wpnonce );
399
 
433
 
434
  return apply_filters( 'wpuf_post_forms_list_table_column_form_name', $form_name, $item );
435
  }
 
436
  }
admin/posting.php CHANGED
@@ -5,23 +5,21 @@
5
  *
6
  * Builds custom fields UI for post add/edit screen
7
  * and handles value saving.
8
- *
9
- * @package WP User Frontend
10
  */
11
  class WPUF_Admin_Posting {
12
 
13
  private static $_instance;
14
 
15
- function __construct() {
16
  // meta boxes
17
- add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes') );
18
- add_action( 'add_meta_boxes', array( $this, 'add_meta_box_form_select') );
19
- add_action( 'add_meta_boxes', array( $this, 'add_meta_box_post_lock') );
20
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_script') );
21
- add_action( 'save_post', array( $this, 'save_meta'), 1, 2 ); // save the custom fields
22
- add_action( 'save_post', array( $this, 'form_selection_metabox_save' ), 1, 2 ); // save edit form id
23
- add_action( 'save_post', array( $this, 'post_lock_metabox_save' ), 1, 2 ); // save post lock option
24
- add_action( 'wp_ajax_wpuf_clear_schedule_lock', array($this, 'clear_schedule_lock') );
25
  }
26
 
27
  public static function init() {
@@ -32,56 +30,59 @@ class WPUF_Admin_Posting {
32
  return self::$_instance;
33
  }
34
 
35
- function enqueue_script() {
36
  global $pagenow;
37
 
38
- if ( !in_array( $pagenow, array( 'profile.php', 'post-new.php', 'post.php', 'user-edit.php' ) ) ) {
39
  return;
40
  }
41
 
42
- $scheme = is_ssl() ? 'https' : 'http';
43
  $api_key = wpuf_get_option( 'gmap_api_key', 'wpuf_general' );
44
 
45
  wp_enqueue_style( 'jquery-ui', WPUF_ASSET_URI . '/css/jquery-ui-1.9.1.custom.css' );
46
 
47
  wp_enqueue_script( 'jquery-ui-datepicker' );
48
  wp_enqueue_script( 'jquery-ui-slider' );
49
- wp_enqueue_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker') );
50
 
51
  if ( !empty( $api_key ) ) {
52
- wp_enqueue_script( 'google-maps', $scheme . '://maps.google.com/maps/api/js?libraries=places&key='.$api_key, array(), null );
53
  } else {
54
- add_action('admin_head', 'wpuf_hide_google_map_button');
55
 
56
  function wpuf_hide_google_map_button() {
57
- echo "<style>
58
  button.button[data-name='custom_map'] {
59
  display: none;
60
  }
61
- </style>";
 
 
 
62
  }
63
  }
64
 
65
- wp_enqueue_style( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.css', array(), WPUF_VERSION );
66
- wp_enqueue_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', array(), WPUF_VERSION, true );
67
- wp_enqueue_script( 'wpuf-upload', WPUF_ASSET_URI . '/js/upload.js', array('jquery', 'plupload-handlers') );
68
- wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', array(
69
  'confirmMsg' => __( 'Are you sure?', 'wp-user-frontend' ),
70
  'delete_it' => __( 'Yes, delete it', 'wp-user-frontend' ),
71
  'cancel_it' => __( 'No, cancel it', 'wp-user-frontend' ),
72
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
73
  'nonce' => wp_create_nonce( 'wpuf_nonce' ),
74
- 'plupload' => array(
75
  'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
76
  'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
77
- 'filters' => array(array('title' => __( 'Allowed Files', 'wp-user-frontend' ), 'extensions' => '*')),
78
  'multipart' => true,
79
  'urlstream_upload' => true,
80
  'warning' => __( 'Maximum number of files reached!', 'wp-user-frontend' ),
81
  'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'wp-user-frontend' ),
82
- 'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'wp-user-frontend' )
83
- )
84
- ) );
85
  }
86
 
87
  /**
@@ -94,11 +95,11 @@ class WPUF_Admin_Posting {
94
  *
95
  * @return void
96
  */
97
- function add_meta_box_form_select() {
 
98
 
99
- $post_types = get_post_types( array('public' => true) );
100
- foreach ($post_types as $post_type) {
101
- add_meta_box( 'wpuf-select-form', __('WPUF Form', 'wp-user-frontend'), array($this, 'form_selection_metabox'), $post_type, 'side', 'high' );
102
  }
103
  }
104
 
@@ -111,23 +112,22 @@ class WPUF_Admin_Posting {
111
  *
112
  * @global object $post
113
  */
114
- function form_selection_metabox() {
115
  global $post;
116
 
117
- $forms = get_posts( array('post_type' => 'wpuf_forms', 'numberposts' => '-1') );
118
- $selected = get_post_meta( $post->ID, '_wpuf_form_id', true );
119
- ?>
120
 
121
- <input type="hidden" name="wpuf_form_select_nonce" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
122
 
123
  <select name="wpuf_form_select">
124
  <option value="">--</option>
125
- <?php foreach ($forms as $form) { ?>
126
- <option value="<?php echo $form->ID; ?>"<?php selected($selected, $form->ID); ?>><?php echo $form->post_title; ?></option>
127
  <?php } ?>
128
  </select>
129
  <div>
130
- <p><a href="https://wedevs.com/docs/wp-user-frontend-pro/tutorials/purpose-of-the-wpuf-form-metabox/" target="_blank"><?php _e( 'Learn more', 'wp-user-frontend' ); ?></a></p>
131
  </div>
132
  <?php
133
  }
@@ -137,16 +137,17 @@ class WPUF_Admin_Posting {
137
  *
138
  * @since 2.5.2
139
  *
140
- * @param int $post_id
141
  * @param object $post
 
142
  * @return int|void
143
  */
144
- function form_selection_metabox_save( $post_id, $post ) {
145
- if ( !isset($_POST['wpuf_form_select'])) {
146
  return $post->ID;
147
  }
148
-
149
- if ( !wp_verify_nonce( $_POST['wpuf_form_select_nonce'], plugin_basename( __FILE__ ) ) ) {
150
  return $post->ID;
151
  }
152
 
@@ -154,8 +155,9 @@ class WPUF_Admin_Posting {
154
  if ( !current_user_can( 'edit_post', $post->ID ) ) {
155
  return $post->ID;
156
  }
 
157
 
158
- update_post_meta( $post->ID, '_wpuf_form_id', $_POST['wpuf_form_select'] );
159
  }
160
 
161
  /**
@@ -168,11 +170,11 @@ class WPUF_Admin_Posting {
168
  *
169
  * @return void
170
  */
171
- function add_meta_box_post_lock() {
172
- $post_types = get_post_types( array('public' => true) );
173
 
174
- foreach ($post_types as $post_type) {
175
- add_meta_box( 'wpuf-post-lock', __('WPUF Lock User', 'wp-user-frontend'), array($this, 'post_lock_metabox'), $post_type, 'side', 'high' );
176
  }
177
  }
178
 
@@ -185,7 +187,7 @@ class WPUF_Admin_Posting {
185
  *
186
  * @global object $post
187
  */
188
- function post_lock_metabox() {
189
  global $post;
190
 
191
  $msg = '';
@@ -196,35 +198,33 @@ class WPUF_Admin_Posting {
196
  $is_locked = false;
197
  }
198
 
199
- if( ( !empty( $edit_post_lock_time ) && $edit_post_lock_time < time() ) || $edit_post_lock == "yes" ) {
200
  $is_locked = true;
201
  $msg = sprintf( __( 'Post is locked, to allow user to edit this post <a id="wpuf_clear_schedule_lock" data="%s" href="#">Click here</a>', 'wp-user-frontend' ), $post->ID );
202
  }
203
 
204
- if( !empty( $edit_post_lock_time ) && $edit_post_lock_time > time() ) {
205
  $is_locked = false;
206
  $time = date( 'Y-m-d H:i:s', $edit_post_lock_time );
207
- $local_time = get_date_from_gmt( $time, get_option('date_format') . ' ' . get_option('time_format') );
208
  $msg = sprintf( __( 'Frontend edit access for this post will be automatically locked after %s, <a id="wpuf_clear_schedule_lock" data="%s" href="#">Clear Lock</a> Or,', 'wp-user-frontend' ), $local_time, $post->ID );
209
- }
210
-
211
- ?>
212
 
213
- <input type="hidden" name="wpuf_lock_editing_post_nonce" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
214
 
215
- <p><?php echo $msg; ?></p>
216
 
217
  <label>
218
- <?php if ( !$is_locked ): ?>
219
  <input type="hidden" name="wpuf_lock_post" value="no">
220
- <input type="checkbox" name="wpuf_lock_post" value="yes" <?php checked($edit_post_lock, 'yes'); ?>>
221
- <?php _e( 'Lock Post Permanently', 'wp-user-frontend' ); ?>
222
- <?php endif ?>
223
  </label>
224
 
225
- <?php if ( !$is_locked ): ?>
226
- <p style="margin-top: 10px"><?php _e( 'Lock user from editing this post from the frontend dashboard', 'wp-user-frontend' ); ?></p>
227
- <?php endif ?>
228
 
229
  <?php
230
  }
@@ -234,18 +234,21 @@ class WPUF_Admin_Posting {
234
  *
235
  * @since 3.0.2
236
  *
237
- * @param int $post_id
238
  * @param object $post
 
239
  * @return int|void
240
  */
241
- function post_lock_metabox_save( $post_id, $post ) {
242
- $edit_post_lock_time = isset( $_POST['_wpuf_lock_user_editing_post_time'] ) ? $_POST['_wpuf_lock_user_editing_post_time'] : '';
243
 
244
- if ( !isset($_POST['wpuf_lock_post'])) {
245
  return $post->ID;
246
  }
247
 
248
- if ( !wp_verify_nonce( $_POST['wpuf_lock_editing_post_nonce'], plugin_basename( __FILE__ ) ) ) {
 
 
249
  return $post->ID;
250
  }
251
 
@@ -253,8 +256,9 @@ class WPUF_Admin_Posting {
253
  if ( !current_user_can( 'edit_post', $post->ID ) ) {
254
  return $post->ID;
255
  }
 
256
 
257
- update_post_meta( $post->ID, '_wpuf_lock_editing_post', $_POST['wpuf_lock_post'] );
258
  }
259
 
260
  /**
@@ -266,11 +270,11 @@ class WPUF_Admin_Posting {
266
  *
267
  * @return void
268
  */
269
- function add_meta_boxes() {
270
- $post_types = get_post_types( array('public' => true) );
271
 
272
- foreach ($post_types as $post_type) {
273
- add_meta_box( 'wpuf-custom-fields', __( 'WPUF Custom Fields', 'wp-user-frontend' ), array($this, 'render_form'), $post_type, 'normal', 'high' );
274
  }
275
  }
276
 
@@ -281,7 +285,7 @@ class WPUF_Admin_Posting {
281
  *
282
  * @return void
283
  */
284
- function hide_form() {
285
  ?>
286
  <style type="text/css">
287
  #wpuf-custom-fields { display: none; }
@@ -299,10 +303,10 @@ class WPUF_Admin_Posting {
299
  *
300
  * @return void
301
  */
302
- function render_form( $form_id, $post_id = null ) {
303
  global $post;
304
 
305
- $form_id = get_post_meta( $post->ID, '_wpuf_form_id', true );
306
  $form_settings = wpuf_get_form_settings( $form_id );
307
 
308
  /**
@@ -315,19 +319,20 @@ class WPUF_Admin_Posting {
315
  // hide the metabox itself if no form ID is set
316
  if ( !$form_id || $hide_with_acf ) {
317
  $this->hide_form();
 
318
  return;
319
  }
320
 
321
- list($post_fields, $taxonomy_fields, $custom_fields) = $this->get_input_fields( $form_id );
322
 
323
  if ( empty( $custom_fields ) ) {
324
- _e( 'No custom fields found.', 'wp-user-frontend' );
 
325
  return;
326
- }
327
- ?>
328
 
329
- <input type="hidden" name="wpuf_cf_update" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
330
- <input type="hidden" name="wpuf_cf_form_id" value="<?php echo $form_id; ?>" />
331
 
332
  <table class="form-table wpuf-cf-table">
333
  <tbody>
@@ -347,16 +352,15 @@ class WPUF_Admin_Posting {
347
  </script>
348
 
349
  <?php
350
- $atts = array();
351
- wpuf()->fields->render_fields( $custom_fields, $form_id, $atts, $type = 'post', $post->ID );
352
- ?>
353
  </tbody>
354
  </table>
355
  <?php
356
  $this->scripts_styles();
357
  }
358
 
359
- function scripts_styles() {
360
  ?>
361
  <script type="text/javascript">
362
  jQuery(function($){
@@ -395,7 +399,7 @@ class WPUF_Admin_Posting {
395
  var data = {
396
  action: 'wpuf_delete_avatar',
397
  user_id : $('#profile-page').find('#user_id').val(),
398
- _wpnonce: '<?php echo wp_create_nonce( 'wpuf_nonce' ); ?>'
399
  };
400
 
401
  if ( confirm( $(this).data('confirm') ) ) {
@@ -478,17 +482,19 @@ class WPUF_Admin_Posting {
478
  * @return void
479
  */
480
  // Save the Metabox Data
481
- function save_meta( $post_id, $post = null ) {
 
 
482
 
483
  if ( !isset( $post_id ) ) {
484
  return;
485
  }
486
 
487
- if ( !isset( $_POST['wpuf_cf_update'] ) ) {
488
  return $post_id;
489
  }
490
 
491
- if ( !wp_verify_nonce( $_POST['wpuf_cf_update'], plugin_basename( __FILE__ ) ) ) {
492
  return $post_id;
493
  }
494
 
@@ -497,7 +503,7 @@ class WPUF_Admin_Posting {
497
  return $post_id;
498
  }
499
 
500
- list( $post_vars, $tax_vars, $meta_vars ) = self::get_input_fields( $_POST['wpuf_cf_form_id'] );
501
 
502
  // WPUF_Frontend_Form_Post::update_post_meta( $meta_vars, $post_id );
503
  WPUF_Frontend_Form::update_post_meta( $meta_vars, $post_id );
@@ -511,7 +517,7 @@ class WPUF_Admin_Posting {
511
  public function clear_schedule_lock() {
512
  check_ajax_referer( 'wpuf_nonce', 'nonce' );
513
 
514
- $post_id = isset( $_POST['post_id'] ) ? $_POST['post_id'] : '';
515
 
516
  if ( !empty( $post_id ) ) {
517
  update_post_meta( $post_id, '_wpuf_lock_user_editing_post_time', '' );
@@ -524,23 +530,24 @@ class WPUF_Admin_Posting {
524
  * Get input meta fields separated as post vars, taxonomy and meta vars
525
  *
526
  * @param int $form_id form id
 
527
  * @return array
528
  */
529
  public static function get_input_fields( $form_id ) {
530
  $form_vars = wpuf_get_form_fields( $form_id );
531
 
532
- $ignore_lists = array('section_break', 'html');
533
- $post_vars = $meta_vars = $taxonomy_vars = array();
534
 
535
- foreach ($form_vars as $key => $value) {
536
  // get column field input fields
537
  if ( $value['input_type'] == 'column_field' ) {
538
  $inner_fields = $value['inner_fields'];
539
 
540
- foreach ($inner_fields as $column_key => $column_fields) {
541
- if (!empty($column_fields)) {
542
  // ignore section break and HTML input type
543
- foreach ($column_fields as $column_field_key => $column_field) {
544
  if ( in_array( $column_field['input_type'], $ignore_lists ) ) {
545
  continue;
546
  }
@@ -592,6 +599,6 @@ class WPUF_Admin_Posting {
592
  }
593
  }
594
 
595
- return array($post_vars, $taxonomy_vars, $meta_vars);
596
  }
597
  }
5
  *
6
  * Builds custom fields UI for post add/edit screen
7
  * and handles value saving.
 
 
8
  */
9
  class WPUF_Admin_Posting {
10
 
11
  private static $_instance;
12
 
13
+ public function __construct() {
14
  // meta boxes
15
+ add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes'] );
16
+ add_action( 'add_meta_boxes', [ $this, 'add_meta_box_form_select'] );
17
+ add_action( 'add_meta_boxes', [ $this, 'add_meta_box_post_lock'] );
18
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_script'] );
19
+ add_action( 'save_post', [ $this, 'save_meta'], 1, 2 ); // save the custom fields
20
+ add_action( 'save_post', [ $this, 'form_selection_metabox_save' ], 1, 2 ); // save edit form id
21
+ add_action( 'save_post', [ $this, 'post_lock_metabox_save' ], 1, 2 ); // save post lock option
22
+ add_action( 'wp_ajax_wpuf_clear_schedule_lock', [$this, 'clear_schedule_lock'] );
23
  }
24
 
25
  public static function init() {
30
  return self::$_instance;
31
  }
32
 
33
+ public function enqueue_script() {
34
  global $pagenow;
35
 
36
+ if ( !in_array( $pagenow, [ 'profile.php', 'post-new.php', 'post.php', 'user-edit.php' ] ) ) {
37
  return;
38
  }
39
 
40
+ $scheme = is_ssl() ? 'https' : 'http';
41
  $api_key = wpuf_get_option( 'gmap_api_key', 'wpuf_general' );
42
 
43
  wp_enqueue_style( 'jquery-ui', WPUF_ASSET_URI . '/css/jquery-ui-1.9.1.custom.css' );
44
 
45
  wp_enqueue_script( 'jquery-ui-datepicker' );
46
  wp_enqueue_script( 'jquery-ui-slider' );
47
+ wp_enqueue_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', ['jquery-ui-datepicker'] );
48
 
49
  if ( !empty( $api_key ) ) {
50
+ wp_enqueue_script( 'google-maps', $scheme . '://maps.google.com/maps/api/js?libraries=places&key=' . $api_key, [], null );
51
  } else {
52
+ add_action( 'admin_head', 'wpuf_hide_google_map_button' );
53
 
54
  function wpuf_hide_google_map_button() {
55
+ echo wp_kses( "<style>
56
  button.button[data-name='custom_map'] {
57
  display: none;
58
  }
59
+ </style>", [
60
+ 'style' => [],
61
+ 'button' => []
62
+ ] );
63
  }
64
  }
65
 
66
+ wp_enqueue_style( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.css', [], WPUF_VERSION );
67
+ wp_enqueue_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', [], WPUF_VERSION, true );
68
+ wp_enqueue_script( 'wpuf-upload', WPUF_ASSET_URI . '/js/upload.js', ['jquery', 'plupload-handlers'] );
69
+ wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', [
70
  'confirmMsg' => __( 'Are you sure?', 'wp-user-frontend' ),
71
  'delete_it' => __( 'Yes, delete it', 'wp-user-frontend' ),
72
  'cancel_it' => __( 'No, cancel it', 'wp-user-frontend' ),
73
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
74
  'nonce' => wp_create_nonce( 'wpuf_nonce' ),
75
+ 'plupload' => [
76
  'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
77
  'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
78
+ 'filters' => [['title' => __( 'Allowed Files', 'wp-user-frontend' ), 'extensions' => '*']],
79
  'multipart' => true,
80
  'urlstream_upload' => true,
81
  'warning' => __( 'Maximum number of files reached!', 'wp-user-frontend' ),
82
  'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'wp-user-frontend' ),
83
+ 'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'wp-user-frontend' ),
84
+ ],
85
+ ] );
86
  }
87
 
88
  /**
95
  *
96
  * @return void
97
  */
98
+ public function add_meta_box_form_select() {
99
+ $post_types = get_post_types( ['public' => true] );
100
 
101
+ foreach ( $post_types as $post_type ) {
102
+ add_meta_box( 'wpuf-select-form', __( 'WPUF Form', 'wp-user-frontend' ), [$this, 'form_selection_metabox'], $post_type, 'side', 'high' );
 
103
  }
104
  }
105
 
112
  *
113
  * @global object $post
114
  */
115
+ public function form_selection_metabox() {
116
  global $post;
117
 
118
+ $forms = get_posts( ['post_type' => 'wpuf_forms', 'numberposts' => '-1'] );
119
+ $selected = get_post_meta( $post->ID, '_wpuf_form_id', true ); ?>
 
120
 
121
+ <input type="hidden" name="wpuf_form_select_nonce" value="<?php echo esc_url( wp_create_nonce( plugin_basename( __FILE__ ) ) ); ?>" />
122
 
123
  <select name="wpuf_form_select">
124
  <option value="">--</option>
125
+ <?php foreach ( $forms as $form ) { ?>
126
+ <option value="<?php echo esc_attr( $form->ID ); ?>"<?php selected( $selected, $form->ID ); ?>><?php echo esc_html( $form->post_title ); ?></option>
127
  <?php } ?>
128
  </select>
129
  <div>
130
+ <p><a href="https://wedevs.com/docs/wp-user-frontend-pro/tutorials/purpose-of-the-wpuf-form-metabox/" target="_blank"><?php esc_html_e( 'Learn more', 'wp-user-frontend' ); ?></a></p>
131
  </div>
132
  <?php
133
  }
137
  *
138
  * @since 2.5.2
139
  *
140
+ * @param int $post_id
141
  * @param object $post
142
+ *
143
  * @return int|void
144
  */
145
+ public function form_selection_metabox_save( $post_id, $post ) {
146
+ if ( !isset( $_POST['wpuf_form_select'] ) ) {
147
  return $post->ID;
148
  }
149
+ $nonce = isset( $_POST['wpuf_form_select_nonce'] ) ? sanitize_key( wp_unslash( $_POST['wpuf_form_select_nonce'] ) ) : '';
150
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce , plugin_basename( __FILE__ ) ) ) {
151
  return $post->ID;
152
  }
153
 
155
  if ( !current_user_can( 'edit_post', $post->ID ) ) {
156
  return $post->ID;
157
  }
158
+ $wpuf_form_select = isset( $_POST['wpuf_form_select'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_form_select'] ) ) : '';
159
 
160
+ update_post_meta( $post->ID, '_wpuf_form_id', $wpuf_form_select );
161
  }
162
 
163
  /**
170
  *
171
  * @return void
172
  */
173
+ public function add_meta_box_post_lock() {
174
+ $post_types = get_post_types( ['public' => true] );
175
 
176
+ foreach ( $post_types as $post_type ) {
177
+ add_meta_box( 'wpuf-post-lock', __( 'WPUF Lock User', 'wp-user-frontend' ), [$this, 'post_lock_metabox'], $post_type, 'side', 'high' );
178
  }
179
  }
180
 
187
  *
188
  * @global object $post
189
  */
190
+ public function post_lock_metabox() {
191
  global $post;
192
 
193
  $msg = '';
198
  $is_locked = false;
199
  }
200
 
201
+ if ( ( !empty( $edit_post_lock_time ) && $edit_post_lock_time < time() ) || $edit_post_lock == 'yes' ) {
202
  $is_locked = true;
203
  $msg = sprintf( __( 'Post is locked, to allow user to edit this post <a id="wpuf_clear_schedule_lock" data="%s" href="#">Click here</a>', 'wp-user-frontend' ), $post->ID );
204
  }
205
 
206
+ if ( !empty( $edit_post_lock_time ) && $edit_post_lock_time > time() ) {
207
  $is_locked = false;
208
  $time = date( 'Y-m-d H:i:s', $edit_post_lock_time );
209
+ $local_time = get_date_from_gmt( $time, get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
210
  $msg = sprintf( __( 'Frontend edit access for this post will be automatically locked after %s, <a id="wpuf_clear_schedule_lock" data="%s" href="#">Clear Lock</a> Or,', 'wp-user-frontend' ), $local_time, $post->ID );
211
+ } ?>
 
 
212
 
213
+ <input type="hidden" name="wpuf_lock_editing_post_nonce" value="<?php echo esc_url( wp_create_nonce( plugin_basename( __FILE__ ) ) ); ?>" />
214
 
215
+ <p><?php echo esc_html( $msg ); ?></p>
216
 
217
  <label>
218
+ <?php if ( !$is_locked ) { ?>
219
  <input type="hidden" name="wpuf_lock_post" value="no">
220
+ <input type="checkbox" name="wpuf_lock_post" value="yes" <?php checked( $edit_post_lock, 'yes' ); ?>>
221
+ <?php esc_html_e( 'Lock Post Permanently', 'wp-user-frontend' ); ?>
222
+ <?php } ?>
223
  </label>
224
 
225
+ <?php if ( !$is_locked ) { ?>
226
+ <p style="margin-top: 10px"><?php esc_html_e( 'Lock user from editing this post from the frontend dashboard', 'wp-user-frontend' ); ?></p>
227
+ <?php } ?>
228
 
229
  <?php
230
  }
234
  *
235
  * @since 3.0.2
236
  *
237
+ * @param int $post_id
238
  * @param object $post
239
+ *
240
  * @return int|void
241
  */
242
+ public function post_lock_metabox_save( $post_id, $post ) {
243
+ $edit_post_lock_time = isset( $_POST['_wpuf_lock_user_editing_post_time'] ) ? sanitize_text_field( wp_unslash( $_POST['_wpuf_lock_user_editing_post_time'] ) ) : '';
244
 
245
+ if ( !isset( $_POST['wpuf_lock_post'] ) ) {
246
  return $post->ID;
247
  }
248
 
249
+ $nonce = isset( $_POST['wpuf_lock_editing_post_nonce'] ) ? sanitize_key( wp_unslash( $_POST['wpuf_lock_editing_post_nonce'] ) ) : '';
250
+
251
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, plugin_basename( __FILE__ ) ) ) {
252
  return $post->ID;
253
  }
254
 
256
  if ( !current_user_can( 'edit_post', $post->ID ) ) {
257
  return $post->ID;
258
  }
259
+ $wpuf_lock_post = isset( $_POST['wpuf_lock_post'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_lock_post'] ) ) : '';
260
 
261
+ update_post_meta( $post->ID, '_wpuf_lock_editing_post', $wpuf_lock_post );
262
  }
263
 
264
  /**
270
  *
271
  * @return void
272
  */
273
+ public function add_meta_boxes() {
274
+ $post_types = get_post_types( ['public' => true] );
275
 
276
+ foreach ( $post_types as $post_type ) {
277
+ add_meta_box( 'wpuf-custom-fields', __( 'WPUF Custom Fields', 'wp-user-frontend' ), [$this, 'render_form'], $post_type, 'normal', 'high' );
278
  }
279
  }
280
 
285
  *
286
  * @return void
287
  */
288
+ public function hide_form() {
289
  ?>
290
  <style type="text/css">
291
  #wpuf-custom-fields { display: none; }
303
  *
304
  * @return void
305
  */
306
+ public function render_form( $form_id, $post_id = null ) {
307
  global $post;
308
 
309
+ $form_id = get_post_meta( $post->ID, '_wpuf_form_id', true );
310
  $form_settings = wpuf_get_form_settings( $form_id );
311
 
312
  /**
319
  // hide the metabox itself if no form ID is set
320
  if ( !$form_id || $hide_with_acf ) {
321
  $this->hide_form();
322
+
323
  return;
324
  }
325
 
326
+ list( $post_fields, $taxonomy_fields, $custom_fields ) = $this->get_input_fields( $form_id );
327
 
328
  if ( empty( $custom_fields ) ) {
329
+ esc_html_e( 'No custom fields found.', 'wp-user-frontend' );
330
+
331
  return;
332
+ } ?>
 
333
 
334
+ <input type="hidden" name="wpuf_cf_update" value="<?php echo esc_attr( wp_create_nonce( plugin_basename( __FILE__ ) ) ); ?>" />
335
+ <input type="hidden" name="wpuf_cf_form_id" value="<?php echo esc_attr( $form_id ); ?>" />
336
 
337
  <table class="form-table wpuf-cf-table">
338
  <tbody>
352
  </script>
353
 
354
  <?php
355
+ $atts = [];
356
+ wpuf()->fields->render_fields( $custom_fields, $form_id, $atts, $type = 'post', $post->ID ); ?>
 
357
  </tbody>
358
  </table>
359
  <?php
360
  $this->scripts_styles();
361
  }
362
 
363
+ public function scripts_styles() {
364
  ?>
365
  <script type="text/javascript">
366
  jQuery(function($){
399
  var data = {
400
  action: 'wpuf_delete_avatar',
401
  user_id : $('#profile-page').find('#user_id').val(),
402
+ _wpnonce: '<?php echo esc_url( wp_create_nonce( 'wpuf_nonce' ) ); ?>'
403
  };
404
 
405
  if ( confirm( $(this).data('confirm') ) ) {
482
  * @return void
483
  */
484
  // Save the Metabox Data
485
+ public function save_meta( $post_id, $post = null ) {
486
+ $wpuf_cf_update = isset( $_POST['wpuf_cf_update'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_cf_update'] ) ) : '';
487
+ $wpuf_cf_form_id = isset( $_POST['wpuf_cf_form_id'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_cf_form_id'] ) ) : '';
488
 
489
  if ( !isset( $post_id ) ) {
490
  return;
491
  }
492
 
493
+ if ( empty( $wpuf_cf_update ) ) {
494
  return $post_id;
495
  }
496
 
497
+ if ( isset( $wpuf_cf_update ) && !wp_verify_nonce( $wpuf_cf_update, plugin_basename( __FILE__ ) ) ) {
498
  return $post_id;
499
  }
500
 
503
  return $post_id;
504
  }
505
 
506
+ list( $post_vars, $tax_vars, $meta_vars ) = self::get_input_fields( $wpuf_cf_form_id );
507
 
508
  // WPUF_Frontend_Form_Post::update_post_meta( $meta_vars, $post_id );
509
  WPUF_Frontend_Form::update_post_meta( $meta_vars, $post_id );
517
  public function clear_schedule_lock() {
518
  check_ajax_referer( 'wpuf_nonce', 'nonce' );
519
 
520
+ $post_id = isset( $_POST['post_id'] ) ? intval( wp_unslash( $_POST['post_id'] ) ) : '';
521
 
522
  if ( !empty( $post_id ) ) {
523
  update_post_meta( $post_id, '_wpuf_lock_user_editing_post_time', '' );
530
  * Get input meta fields separated as post vars, taxonomy and meta vars
531
  *
532
  * @param int $form_id form id
533
+ *
534
  * @return array
535
  */
536
  public static function get_input_fields( $form_id ) {
537
  $form_vars = wpuf_get_form_fields( $form_id );
538
 
539
+ $ignore_lists = ['section_break', 'html'];
540
+ $post_vars = $meta_vars = $taxonomy_vars = [];
541
 
542
+ foreach ( $form_vars as $key => $value ) {
543
  // get column field input fields
544
  if ( $value['input_type'] == 'column_field' ) {
545
  $inner_fields = $value['inner_fields'];
546
 
547
+ foreach ( $inner_fields as $column_key => $column_fields ) {
548
+ if ( !empty( $column_fields ) ) {
549
  // ignore section break and HTML input type
550
+ foreach ( $column_fields as $column_field_key => $column_field ) {
551
  if ( in_array( $column_field['input_type'], $ignore_lists ) ) {
552
  continue;
553
  }
599
  }
600
  }
601
 
602
+ return [$post_vars, $taxonomy_vars, $meta_vars];
603
  }
604
  }
admin/premium.php CHANGED
@@ -1,88 +1,88 @@
1
  <div class="wrap wpuf-premium about-wrap">
2
- <h1><?php _e( 'WPUF Pro', 'wp-user-frontend' ); ?></h1>
3
 
4
- <p class="about-text"><?php _e( 'Upgrade to the premium versions of WPUF and unlock even more useful features.', 'wp-user-frontend' ); ?></p>
5
- <div class="wp-badge"><?php _e( 'WPUF Pro', 'wp-user-frontend' ); ?></div>
6
 
7
  <hr>
8
  <div class="feature-section one-col">
9
  <div class="col">
10
- <h2><?php _e( 'Pro Features', 'wp-user-frontend' ); ?></h2>
11
- <p style="text-align: center; font-size: 16px;"><?php _e( 'WPUF Pro is designed just for you, specially to fulfil your business needs. We have designed and curated every feature keeping your requirements in mind.', 'wp-user-frontend' ); ?></p>
12
  </div>
13
  </div>
14
 
15
  <div class="feature-section two-col">
16
  <div class="col feature-wrap">
17
  <div class="feature-image">
18
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/premium/registration.gif" alt="<?php _e( 'Registration Form Builder', 'wp-user-frontend' ); ?>">
19
  </div>
20
  <div class="feature-details">
21
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/how-to-setup-registrationlogin-page/" target="_blank"><?php _e( 'Registration Form Builder', 'wp-user-frontend' ); ?></a></h3>
22
- <p><?php _e( 'Registration form builder is a two way form which can be used both for user registration and profile editing. You could also manage Register for Subscription Package Purchase.', 'wp-user-frontend' ); ?></p>
23
  </div>
24
  </div>
25
 
26
  <div class="col feature-wrap">
27
  <div class="feature-image">
28
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/premium/advanced-fields.png" alt="<?php _e( 'Advanced Fields', 'wp-user-frontend' ); ?>">
29
  </div>
30
  <div class="feature-details">
31
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/form-elements/" target="_blank"><?php _e( 'Advanced Fields', 'wp-user-frontend' ); ?></a></h3>
32
  <ul>
33
- <li><?php _e( 'Country List', 'wp-user-frontend' ); ?></li>
34
- <li><?php _e( 'Address', 'wp-user-frontend' ); ?></li>
35
- <li><?php _e( 'Date Field', 'wp-user-frontend' ); ?></li>
36
- <li><?php _e( 'Google Map', 'wp-user-frontend' ); ?></li>
37
- <li><?php _e( 'Action Hook', 'wp-user-frontend' ); ?></li>
38
- <li><?php _e( 'Rating', 'wp-user-frontend' ); ?></li>
39
- <li><?php _e( 'Shortcode', 'wp-user-frontend' ); ?></li>
40
- <li><?php _e( 'Number', 'wp-user-frontend' ); ?></li>
41
- <li><?php _e( 'Repeater', 'wp-user-frontend' ); ?></li>
42
- <li><?php _e( 'File Upload', 'wp-user-frontend' ); ?></li>
43
- <li><?php _e( 'Captcha', 'wp-user-frontend' ); ?></li>
44
- <li><?php _e( 'TOC', 'wp-user-frontend' ); ?></li>
45
  </ul>
46
  </div>
47
  </div>
48
 
49
  <div class="col feature-wrap">
50
  <div class="feature-image">
51
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/premium/coupon.gif" alt="<?php _e( 'Manage Coupons', 'wp-user-frontend' ); ?>">
52
  </div>
53
  <div class="feature-details">
54
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/coupons/" target="_blank"><?php _e( 'Manage Coupons', 'wp-user-frontend' ); ?></a></h3>
55
- <p><?php _e( 'Simple yet powerful coupon management system. Use Coupon codes for selling subscription pack with discounts.', 'wp-user-frontend' ); ?></p>
56
  </div>
57
  </div>
58
 
59
  <div class="col feature-wrap">
60
  <div class="feature-image">
61
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/premium/content-restrictions.gif" alt="<?php _e( 'Content Restrictions', 'wp-user-frontend' ); ?>">
62
  </div>
63
  <div class="feature-details">
64
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/content-restriction/" target="_blank"><?php _e( 'Content Restrictions', 'wp-user-frontend' ); ?></a></h3>
65
- <p><?php _e( 'You can restrict premium content for users by access role, registration or subscriptions only with just a shortcode.', 'wp-user-frontend' ); ?></p>
66
  </div>
67
  </div>
68
 
69
  <div class="col feature-wrap">
70
  <div class="feature-image">
71
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/premium/conditional-logic.gif" alt="<?php _e( 'Conditional Logic', 'wp-user-frontend' ); ?>">
72
  </div>
73
  <div class="feature-details">
74
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/how-to-use-conditional-logic/" target="_blank"><?php _e( 'Conditional Logic', 'wp-user-frontend' ); ?></a></h3>
75
- <p><?php _e( 'Configure your form’s settings and user flow based on conditional selection. Your forms should appear just the way you want it.', 'wp-user-frontend' ); ?></p>
76
  </div>
77
  </div>
78
 
79
  <div class="col feature-wrap">
80
  <div class="feature-image">
81
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/premium/multi-step.gif" alt="<?php _e( 'Multi-step Form', 'wp-user-frontend' ); ?>">
82
  </div>
83
  <div class="feature-details">
84
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/how-to-add-multi-step-form/" target="_blank"><?php _e( 'Multi-step Form', 'wp-user-frontend' ); ?></a></h3>
85
- <p><?php _e( 'Break down the long forms into smaller and attractive multi step forms. Long and lengthy forms are uninviting, why build one?', 'wp-user-frontend' ); ?></p>
86
  </div>
87
  </div>
88
  </div>
@@ -90,129 +90,129 @@
90
  <hr>
91
  <div class="feature-section one-col">
92
  <div class="col">
93
- <h2><?php _e( 'Modules', 'wp-user-frontend' ); ?></h2>
94
- <p style="text-align: center; font-size: 16px;"><?php _e( 'A bunch of awesome modules to speed up your business growth.', 'wp-user-frontend' ); ?></p>
95
  </div>
96
  </div>
97
 
98
  <div class="headline-feature two-col">
99
  <div class="col module-wrap">
100
  <div class="module-image">
101
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/Social-Media-Login.png" alt="<?php _e( 'BuddyPress Profile', 'wp-user-frontend' ); ?>">
102
  </div>
103
  <div class="module-details">
104
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/social-login-registration/" target="_blank"><?php _e( 'Social Login', 'wp-user-frontend' ); ?></a></h3>
105
- <p><?php _e( 'Allow your users to Register or Login using Social networks like Google, Facebook, Twitter and LinkedIn.', 'wp-user-frontend' ); ?></p>
106
  </div>
107
  </div>
108
 
109
  <div class="col module-wrap">
110
  <div class="module-image">
111
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-ul.png" alt="<?php _e( 'User Directory', 'wp-user-frontend' ); ?>">
112
  </div>
113
  <div class="module-details">
114
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/user-listing-profile/" target="_blank"><?php _e( 'User Directory', 'wp-user-frontend' ); ?></a></h3>
115
- <p><?php _e( 'Handle user listing and user profile in the frontend. Create a directory site easily.', 'wp-user-frontend' ); ?></p>
116
  </div>
117
  </div>
118
 
119
  <div class="col module-wrap">
120
  <div class="module-image">
121
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-buddypress.png" alt="<?php _e( 'BuddyPress Profile', 'wp-user-frontend' ); ?>">
122
  </div>
123
  <div class="module-details">
124
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/buddypress-profile-integration/" target="_blank"><?php _e( 'BuddyPress Profile', 'wp-user-frontend' ); ?></a></h3>
125
- <p><?php _e( 'Register and upgrade user profiles and sync data with BuddyPress.', 'wp-user-frontend' ); ?></p>
126
  </div>
127
  </div>
128
 
129
  <div class="col module-wrap">
130
  <div class="module-image">
131
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-ua.png" alt="<?php _e( 'MailChimp Integration', 'wp-user-frontend' ); ?>">
132
  </div>
133
  <div class="module-details">
134
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/user-analytics/" target="_blank"><?php _e( 'User Analytics', 'wp-user-frontend' ); ?></a></h3>
135
- <p><?php _e( 'Show user tracking info during post and registration directly on Frontend.', 'wp-user-frontend' ); ?></p>
136
  </div>
137
  </div>
138
 
139
  <div class="col module-wrap">
140
  <div class="module-image">
141
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-pmpro.png" alt="<?php _e( 'Paid Membership Pro', 'wp-user-frontend' ); ?>">
142
  </div>
143
  <div class="module-details">
144
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/install-and-configure-pmpro-add-on-for-wpuf/" target="_blank"><?php _e( 'Paid Membership Pro', 'wp-user-frontend' ); ?></a></h3>
145
- <p><?php _e( 'Membership Integration of WP User Frontend with Paid Membership Pro.', 'wp-user-frontend' ); ?></p>
146
  </div>
147
  </div>
148
 
149
  <div class="col module-wrap">
150
  <div class="module-image">
151
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-stripe.png" alt="<?php _e( 'Stripe Payment', 'wp-user-frontend' ); ?>">
152
  </div>
153
  <div class="module-details">
154
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/stripe/" target="_blank"><?php _e( 'Stripe Payment', 'wp-user-frontend' ); ?></a></h3>
155
- <p><?php _e( 'Stripe payment gateway for WP User Frontend. Get your subscription payment with Stripe.', 'wp-user-frontend' ); ?></p>
156
  </div>
157
  </div>
158
 
159
  <div class="col module-wrap">
160
  <div class="module-image">
161
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-mailpoet.png" alt="<?php _e( 'Mailpoet', 'wp-user-frontend' ); ?>">
162
  </div>
163
  <div class="module-details">
164
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/mailpoet/" target="_blank"><?php _e( 'Mailpoet', 'wp-user-frontend' ); ?></a></h3>
165
- <p><?php _e( 'Add subscribers to mailpoet mailing list when they registers via WP User Frontend Pro.', 'wp-user-frontend' ); ?></p>
166
  </div>
167
  </div>
168
 
169
  <div class="col module-wrap">
170
  <div class="module-image">
171
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-mailchimp.png" alt="<?php _e( 'MailChimp Integration', 'wp-user-frontend' ); ?>">
172
  </div>
173
  <div class="module-details">
174
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/add-users-to-mailchimp-subscribers-list-upon-registration-from-frontend/" target="_blank"><?php _e( 'MailChimp', 'wp-user-frontend' ); ?></a></h3>
175
- <p><?php _e( 'Integrate your desired form to your MailChimp email newsletter using latest API.', 'wp-user-frontend' ); ?></p>
176
  </div>
177
  </div>
178
 
179
  <div class="col module-wrap">
180
  <div class="module-image">
181
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-sms.png" alt="<?php _e( 'SMS Notification', 'wp-user-frontend' ); ?>">
182
  </div>
183
  <div class="module-details">
184
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/sms-notification/" target="_blank"><?php _e( 'SMS Notification', 'wp-user-frontend' ); ?></a></h3>
185
- <p><?php _e( 'Get instant SMS notification on your mobile when post submits on your site.', 'wp-user-frontend' ); ?></p>
186
  </div>
187
  </div>
188
 
189
  <div class="col module-wrap">
190
  <div class="module-image">
191
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-comment.png" alt="<?php _e( 'SMS Notification', 'wp-user-frontend' ); ?>">
192
  </div>
193
  <div class="module-details">
194
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/frontend-comment-manager/" target="_blank"><?php _e( 'Comment Manager', 'wp-user-frontend' ); ?></a></h3>
195
- <p><?php _e( 'Handle comments in frontend. View / reply comments on post.', 'wp-user-frontend' ); ?></p>
196
  </div>
197
  </div>
198
 
199
  <div class="col module-wrap">
200
  <div class="module-image">
201
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/wpuf-qr.png" alt="<?php _e( 'SMS Notification', 'wp-user-frontend' ); ?>">
202
  </div>
203
  <div class="module-details">
204
- <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/qr-code/" target="_blank"><?php _e( 'QR Code Generator', 'wp-user-frontend' ); ?></a></h3>
205
- <p><?php _e( 'Generate QR Code with your custom fields or custom post meta.', 'wp-user-frontend' ); ?></p>
206
  </div>
207
  </div>
208
 
209
  <div class="col module-wrap">
210
  <div class="module-image">
211
- <img src="<?php echo WPUF_ASSET_URI; ?>/images/modules/more.png" alt="<?php _e( 'More...', 'wp-user-frontend' ); ?>">
212
  </div>
213
  <div class="module-details">
214
- <h3><?php _e( 'More...', 'wp-user-frontend' ); ?></h3>
215
- <p><?php _e( 'A bunch of more modules are coming soon.', 'wp-user-frontend' ); ?></p>
216
  </div>
217
  </div>
218
  </div>
@@ -222,13 +222,13 @@
222
  <div class="wpuf-upgrade-sticky-footer">
223
 
224
  <div class="text-left">
225
- <h3><?php _e( 'Upgrade To The Most Powerful Frontend Plugin', 'wp-user-frontend' ); ?></h3>
226
 
227
- <p><?php _e( 'WP User Frontend Pro is the most powerful solution for your frontend needs.', 'wp-user-frontend' ); ?></p>
228
  </div>
229
 
230
  <div class="text-right">
231
-
232
  </div>
233
  </div>
234
 
1
  <div class="wrap wpuf-premium about-wrap">
2
+ <h1><?php esc_html_e( 'WPUF Pro', 'wp-user-frontend' ); ?></h1>
3
 
4
+ <p class="about-text"><?php esc_html_e( 'Upgrade to the premium versions of WPUF and unlock even more useful features.', 'wp-user-frontend' ); ?></p>
5
+ <div class="wp-badge"><?php esc_html_e( 'WPUF Pro', 'wp-user-frontend' ); ?></div>
6
 
7
  <hr>
8
  <div class="feature-section one-col">
9
  <div class="col">
10
+ <h2><?php esc_html_e( 'Pro Features', 'wp-user-frontend' ); ?></h2>
11
+ <p style="text-align: center; font-size: 16px;"><?php esc_html_e( 'WPUF Pro is designed just for you, specially to fulfil your business needs. We have designed and curated every feature keeping your requirements in mind.', 'wp-user-frontend' ); ?></p>
12
  </div>
13
  </div>
14
 
15
  <div class="feature-section two-col">
16
  <div class="col feature-wrap">
17
  <div class="feature-image">
18
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/premium/registration.gif" alt="<?php esc_html_e( 'Registration Form Builder', 'wp-user-frontend' ); ?>">
19
  </div>
20
  <div class="feature-details">
21
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/registration-profile-forms/how-to-setup-registrationlogin-page/" target="_blank"><?php esc_html_e( 'Registration Form Builder', 'wp-user-frontend' ); ?></a></h3>
22
+ <p><?php esc_html_e( 'Registration form builder is a two way form which can be used both for user registration and profile editing. You could also manage Register for Subscription Package Purchase.', 'wp-user-frontend' ); ?></p>
23
  </div>
24
  </div>
25
 
26
  <div class="col feature-wrap">
27
  <div class="feature-image">
28
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/premium/advanced-fields.png" alt="<?php esc_html_e( 'Advanced Fields', 'wp-user-frontend' ); ?>">
29
  </div>
30
  <div class="feature-details">
31
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/form-elements/" target="_blank"><?php esc_html_e( 'Advanced Fields', 'wp-user-frontend' ); ?></a></h3>
32
  <ul>
33
+ <li><?php esc_html_e( 'Country List', 'wp-user-frontend' ); ?></li>
34
+ <li><?php esc_html_e( 'Address', 'wp-user-frontend' ); ?></li>
35
+ <li><?php esc_html_e( 'Date Field', 'wp-user-frontend' ); ?></li>
36
+ <li><?php esc_html_e( 'Google Map', 'wp-user-frontend' ); ?></li>
37
+ <li><?php esc_html_e( 'Action Hook', 'wp-user-frontend' ); ?></li>
38
+ <li><?php esc_html_e( 'Rating', 'wp-user-frontend' ); ?></li>
39
+ <li><?php esc_html_e( 'Shortcode', 'wp-user-frontend' ); ?></li>
40
+ <li><?php esc_html_e( 'Number', 'wp-user-frontend' ); ?></li>
41
+ <li><?php esc_html_e( 'Repeater', 'wp-user-frontend' ); ?></li>
42
+ <li><?php esc_html_e( 'File Upload', 'wp-user-frontend' ); ?></li>
43
+ <li><?php esc_html_e( 'Captcha', 'wp-user-frontend' ); ?></li>
44
+ <li><?php esc_html_e( 'TOC', 'wp-user-frontend' ); ?></li>
45
  </ul>
46
  </div>
47
  </div>
48
 
49
  <div class="col feature-wrap">
50
  <div class="feature-image">
51
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/premium/coupon.gif" alt="<?php esc_html_e( 'Manage Coupons', 'wp-user-frontend' ); ?>">
52
  </div>
53
  <div class="feature-details">
54
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/subscription-payment/coupons/" target="_blank"><?php esc_html_e( 'Manage Coupons', 'wp-user-frontend' ); ?></a></h3>
55
+ <p><?php esc_html_e( 'Simple yet powerful coupon management system. Use Coupon codes for selling subscription pack with discounts.', 'wp-user-frontend' ); ?></p>
56
  </div>
57
  </div>
58
 
59
  <div class="col feature-wrap">
60
  <div class="feature-image">
61
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/premium/content-restrictions.gif" alt="<?php esc_html_e( 'Content Restrictions', 'wp-user-frontend' ); ?>">
62
  </div>
63
  <div class="feature-details">
64
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/content-restriction/content-restriction/" target="_blank"><?php esc_html_e( 'Content Restrictions', 'wp-user-frontend' ); ?></a></h3>
65
+ <p><?php esc_html_e( 'You can restrict premium content for users by access role, registration or subscriptions only with just a shortcode.', 'wp-user-frontend' ); ?></p>
66
  </div>
67
  </div>
68
 
69
  <div class="col feature-wrap">
70
  <div class="feature-image">
71
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/premium/conditional-logic.gif" alt="<?php esc_html_e( 'Conditional Logic', 'wp-user-frontend' ); ?>">
72
  </div>
73
  <div class="feature-details">
74
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/how-to-use-conditional-logic/" target="_blank"><?php esc_html_e( 'Conditional Logic', 'wp-user-frontend' ); ?></a></h3>
75
+ <p><?php esc_html_e( 'Configure your form’s settings and user flow based on conditional selection. Your forms should appear just the way you want it.', 'wp-user-frontend' ); ?></p>
76
  </div>
77
  </div>
78
 
79
  <div class="col feature-wrap">
80
  <div class="feature-image">
81
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/premium/multi-step.gif" alt="<?php esc_html_e( 'Multi-step Form', 'wp-user-frontend' ); ?>">
82
  </div>
83
  <div class="feature-details">
84
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/posting-forms/how-to-add-multi-step-form/" target="_blank"><?php esc_html_e( 'Multi-step Form', 'wp-user-frontend' ); ?></a></h3>
85
+ <p><?php esc_html_e( 'Break down the long forms into smaller and attractive multi step forms. Long and lengthy forms are uninviting, why build one?', 'wp-user-frontend' ); ?></p>
86
  </div>
87
  </div>
88
  </div>
90
  <hr>
91
  <div class="feature-section one-col">
92
  <div class="col">
93
+ <h2><?php esc_html_e( 'Modules', 'wp-user-frontend' ); ?></h2>
94
+ <p style="text-align: center; font-size: 16px;"><?php esc_html_e( 'A bunch of awesome modules to speed up your business growth.', 'wp-user-frontend' ); ?></p>
95
  </div>
96
  </div>
97
 
98
  <div class="headline-feature two-col">
99
  <div class="col module-wrap">
100
  <div class="module-image">
101
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/Social-Media-Login.png" alt="<?php esc_html_e( 'BuddyPress Profile', 'wp-user-frontend' ); ?>">
102
  </div>
103
  <div class="module-details">
104
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/social-login-registration/" target="_blank"><?php esc_html_e( 'Social Login', 'wp-user-frontend' ); ?></a></h3>
105
+ <p><?php esc_html_e( 'Allow your users to Register or Login using Social networks like Google, Facebook, Twitter and LinkedIn.', 'wp-user-frontend' ); ?></p>
106
  </div>
107
  </div>
108
 
109
  <div class="col module-wrap">
110
  <div class="module-image">
111
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-ul.png" alt="<?php esc_html_e( 'User Directory', 'wp-user-frontend' ); ?>">
112
  </div>
113
  <div class="module-details">
114
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/user-listing-profile/" target="_blank"><?php esc_html_e( 'User Directory', 'wp-user-frontend' ); ?></a></h3>
115
+ <p><?php esc_html_e( 'Handle user listing and user profile in the frontend. Create a directory site easily.', 'wp-user-frontend' ); ?></p>
116
  </div>
117
  </div>
118
 
119
  <div class="col module-wrap">
120
  <div class="module-image">
121
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-buddypress.png" alt="<?php esc_html_e( 'BuddyPress Profile', 'wp-user-frontend' ); ?>">
122
  </div>
123
  <div class="module-details">
124
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/buddypress-profile-integration/" target="_blank"><?php esc_html_e( 'BuddyPress Profile', 'wp-user-frontend' ); ?></a></h3>
125
+ <p><?php esc_html_e( 'Register and upgrade user profiles and sync data with BuddyPress.', 'wp-user-frontend' ); ?></p>
126
  </div>
127
  </div>
128
 
129
  <div class="col module-wrap">
130
  <div class="module-image">
131
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-ua.png" alt="<?php esc_html_e( 'MailChimp Integration', 'wp-user-frontend' ); ?>">
132
  </div>
133
  <div class="module-details">
134
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/user-analytics/" target="_blank"><?php esc_html_e( 'User Analytics', 'wp-user-frontend' ); ?></a></h3>
135
+ <p><?php esc_html_e( 'Show user tracking info during post and registration directly on Frontend.', 'wp-user-frontend' ); ?></p>
136
  </div>
137
  </div>
138
 
139
  <div class="col module-wrap">
140
  <div class="module-image">
141
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-pmpro.png" alt="<?php esc_html_e( 'Paid Membership Pro', 'wp-user-frontend' ); ?>">
142
  </div>
143
  <div class="module-details">
144
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/install-and-configure-pmpro-add-on-for-wpuf/" target="_blank"><?php esc_html_e( 'Paid Membership Pro', 'wp-user-frontend' ); ?></a></h3>
145
+ <p><?php esc_html_e( 'Membership Integration of WP User Frontend with Paid Membership Pro.', 'wp-user-frontend' ); ?></p>
146
  </div>
147
  </div>
148
 
149
  <div class="col module-wrap">
150
  <div class="module-image">
151
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-stripe.png" alt="<?php esc_html_e( 'Stripe Payment', 'wp-user-frontend' ); ?>">
152
  </div>
153
  <div class="module-details">
154
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/stripe/" target="_blank"><?php esc_html_e( 'Stripe Payment', 'wp-user-frontend' ); ?></a></h3>
155
+ <p><?php esc_html_e( 'Stripe payment gateway for WP User Frontend. Get your subscription payment with Stripe.', 'wp-user-frontend' ); ?></p>
156
  </div>
157
  </div>
158
 
159
  <div class="col module-wrap">
160
  <div class="module-image">
161
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-mailpoet.png" alt="<?php esc_html_e( 'Mailpoet', 'wp-user-frontend' ); ?>">
162
  </div>
163
  <div class="module-details">
164
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/mailpoet/" target="_blank"><?php esc_html_e( 'Mailpoet', 'wp-user-frontend' ); ?></a></h3>
165
+ <p><?php esc_html_e( 'Add subscribers to mailpoet mailing list when they registers via WP User Frontend Pro.', 'wp-user-frontend' ); ?></p>
166
  </div>
167
  </div>
168
 
169
  <div class="col module-wrap">
170
  <div class="module-image">
171
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-mailchimp.png" alt="<?php esc_html_e( 'MailChimp Integration', 'wp-user-frontend' ); ?>">
172
  </div>
173
  <div class="module-details">
174
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/add-users-to-mailchimp-subscribers-list-upon-registration-from-frontend/" target="_blank"><?php esc_html_e( 'MailChimp', 'wp-user-frontend' ); ?></a></h3>
175
+ <p><?php esc_html_e( 'Integrate your desired form to your MailChimp email newsletter using latest API.', 'wp-user-frontend' ); ?></p>
176
  </div>
177
  </div>
178
 
179
  <div class="col module-wrap">
180
  <div class="module-image">
181
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-sms.png" alt="<?php esc_html_e( 'SMS Notification', 'wp-user-frontend' ); ?>">
182
  </div>
183
  <div class="module-details">
184
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/sms-notification/" target="_blank"><?php esc_html_e( 'SMS Notification', 'wp-user-frontend' ); ?></a></h3>
185
+ <p><?php esc_html_e( 'Get instant SMS notification on your mobile when post submits on your site.', 'wp-user-frontend' ); ?></p>
186
  </div>
187
  </div>
188
 
189
  <div class="col module-wrap">
190
  <div class="module-image">
191
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-comment.png" alt="<?php esc_html_e( 'SMS Notification', 'wp-user-frontend' ); ?>">
192
  </div>
193
  <div class="module-details">
194
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/frontend-comment-manager/" target="_blank"><?php esc_html_e( 'Comment Manager', 'wp-user-frontend' ); ?></a></h3>
195
+ <p><?php esc_html_e( 'Handle comments in frontend. View / reply comments on post.', 'wp-user-frontend' ); ?></p>
196
  </div>
197
  </div>
198
 
199
  <div class="col module-wrap">
200
  <div class="module-image">
201
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/wpuf-qr.png" alt="<?php esc_html_e( 'SMS Notification', 'wp-user-frontend' ); ?>">
202
  </div>
203
  <div class="module-details">
204
+ <h3><a href="https://wedevs.com/docs/wp-user-frontend-pro/modules/qr-code/" target="_blank"><?php esc_html_e( 'QR Code Generator', 'wp-user-frontend' ); ?></a></h3>
205
+ <p><?php esc_html_e( 'Generate QR Code with your custom fields or custom post meta.', 'wp-user-frontend' ); ?></p>
206
  </div>
207
  </div>
208
 
209
  <div class="col module-wrap">
210
  <div class="module-image">
211
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ); ?>/images/modules/more.png" alt="<?php esc_html_e( 'More...', 'wp-user-frontend' ); ?>">
212
  </div>
213
  <div class="module-details">
214
+ <h3><?php esc_html_e( 'More...', 'wp-user-frontend' ); ?></h3>
215
+ <p><?php esc_html_e( 'A bunch of more modules are coming soon.', 'wp-user-frontend' ); ?></p>
216
  </div>
217
  </div>
218
  </div>
222
  <div class="wpuf-upgrade-sticky-footer">
223
 
224
  <div class="text-left">
225
+ <h3><?php esc_html_e( 'Upgrade To The Most Powerful Frontend Plugin', 'wp-user-frontend' ); ?></h3>
226
 
227
+ <p><?php esc_html_e( 'WP User Frontend Pro is the most powerful solution for your frontend needs.', 'wp-user-frontend' ); ?></p>
228
  </div>
229
 
230
  <div class="text-right">
231
+
232
  </div>
233
  </div>
234
 
admin/promotion.php CHANGED
@@ -6,10 +6,10 @@
6
  class WPUF_Admin_Promotion {
7
 
8
  public function __construct() {
9
- add_action( 'admin_notices', array( $this, 'promotional_offer' ) );
10
- add_action( 'admin_notices' , array( $this, 'wpuf_review_notice_message' ) );
11
- add_action( 'wp_ajax_wpuf-dismiss-promotional-offer-notice', array( $this, 'dismiss_promotional_offer' ) );
12
- add_action( 'wp_ajax_wpuf-dismiss-review-notice', array( $this, 'dismiss_review_notice' ) );
13
  }
14
 
15
  /**
@@ -20,7 +20,7 @@ class WPUF_Admin_Promotion {
20
  * @return void
21
  */
22
  public function promotional_offer() {
23
- if ( ! current_user_can( 'manage_options' ) ) {
24
  return;
25
  }
26
 
@@ -42,7 +42,7 @@ class WPUF_Admin_Promotion {
42
  ?>
43
  <div class="notice notice-success is-dismissible" id="wpuf-bfcm-notice">
44
  <div class="logo">
45
- <img src="<?php echo WPUF_ASSET_URI . '/images/promo-logo.png' ?>" alt="WPUF">
46
  </div>
47
  <div class="content">
48
  <p>Biggest Sale of the year on this</p>
@@ -52,7 +52,7 @@ class WPUF_Admin_Promotion {
52
  </div>
53
  <div class="call-to-action">
54
  <a target="_blank" href="https://wedevs.com/wp-user-frontend-pro/pricing?utm_campaign=black_friday_&_cyber_monday&utm_medium=banner&utm_source=plugin_dashboard">
55
- <img src="<?php echo WPUF_ASSET_URI . '/images/promo-btn.png' ?>" alt="Btn">
56
  </a>
57
  <p>
58
  <span class="highlight-green2">Coupon: </span>
@@ -147,7 +147,8 @@ class WPUF_Admin_Promotion {
147
  e.preventDefault();
148
 
149
  wp.ajax.post('wpuf-dismiss-promotional-offer-notice', {
150
- dismissed: true
 
151
  });
152
  });
153
  </script>
@@ -156,14 +157,13 @@ class WPUF_Admin_Promotion {
156
  }
157
 
158
  /**
159
- *
160
  * @since 3.1.0
161
  *
162
  * @return void
163
  **/
164
  public function wpuf_review_notice_message() {
165
  // Show only to Admins
166
- if ( ! current_user_can( 'manage_options' ) ) {
167
  return;
168
  }
169
 
@@ -178,21 +178,19 @@ class WPUF_Admin_Promotion {
178
 
179
  if ( time() - $activation_time < 1296000 ) {
180
  return;
181
- }
182
-
183
- ?>
184
  <div id="wpuf-review-notice" class="wpuf-review-notice">
185
  <div class="wpuf-review-thumbnail">
186
- <img src="<?php echo WPUF_ASSET_URI . '/images/icon-128x128.png' ?>" alt="">
187
  </div>
188
  <div class="wpuf-review-text">
189
- <h3><?php _e( 'Enjoying <strong>WP User Frontend</strong>?', 'wp-user-frontend' ) ?></h3>
190
- <p><?php _e( 'Hope that you had a neat and snappy experience with the tool. Would you please show us a little love by rating us in the <a href="https://wordpress.org/support/plugin/wp-user-frontend/reviews/#new-post" target="_blank"><strong>WordPress.org</strong></a>?', 'wp-user-frontend' ) ?></p>
191
 
192
  <ul class="wpuf-review-ul">
193
- <li><a href="https://wordpress.org/support/plugin/wp-user-frontend/reviews/#new-post" target="_blank"><span class="dashicons dashicons-external"></span><?php _e( 'Sure! I\'d love to!', 'wp-user-frontend' ) ?></a></li>
194
- <li><a href="#" class="notice-dismiss"><span class="dashicons dashicons-smiley"></span><?php _e( 'I\'ve already left a review', 'wp-user-frontend' ) ?></a></li>
195
- <li><a href="#" class="notice-dismiss"><span class="dashicons dashicons-dismiss"></span><?php _e( 'Never show again', 'wp-user-frontend' ) ?></a></li>
196
  </ul>
197
  </div>
198
  </div>
@@ -272,37 +270,53 @@ class WPUF_Admin_Promotion {
272
  jQuery("#wpuf-review-notice").hide();
273
 
274
  wp.ajax.post('wpuf-dismiss-review-notice', {
275
- dismissed: true
 
276
  });
277
  });
278
  </script>
279
  <?php
280
-
281
  }
282
 
283
- /**
284
- * Dismiss promotion notice
285
- *
286
- * @since 2.5
287
- *
288
- * @return void
289
- */
290
- public function dismiss_promotional_offer() {
291
- if ( ! empty( $_POST['dismissed'] ) ) {
 
 
 
 
 
 
 
 
292
  $offer_key = 'wpuf_promotional_offer_notice';
293
  update_option( $offer_key, 'hide' );
294
  }
295
  }
296
 
297
  /**
298
- * Dismiss review notice
299
- *
300
- * @since 3.1.0
301
- *
302
- * @return void
303
- **/
304
- public function dismiss_review_notice() {
305
- if ( ! empty( $_POST['dismissed'] ) ) {
 
 
 
 
 
 
 
 
306
  update_option( 'wpuf_review_notice_dismiss', 'yes' );
307
  }
308
  }
6
  class WPUF_Admin_Promotion {
7
 
8
  public function __construct() {
9
+ add_action( 'admin_notices', [ $this, 'promotional_offer' ] );
10
+ add_action( 'admin_notices', [ $this, 'wpuf_review_notice_message' ] );
11
+ add_action( 'wp_ajax_wpuf-dismiss-promotional-offer-notice', [ $this, 'dismiss_promotional_offer' ] );
12
+ add_action( 'wp_ajax_wpuf-dismiss-review-notice', [ $this, 'dismiss_review_notice' ] );
13
  }
14
 
15
  /**
20
  * @return void
21
  */
22
  public function promotional_offer() {
23
+ if ( !current_user_can( 'manage_options' ) ) {
24
  return;
25
  }
26
 
42
  ?>
43
  <div class="notice notice-success is-dismissible" id="wpuf-bfcm-notice">
44
  <div class="logo">
45
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ) . '/images/promo-logo.png'; ?>" alt="WPUF">
46
  </div>
47
  <div class="content">
48
  <p>Biggest Sale of the year on this</p>
52
  </div>
53
  <div class="call-to-action">
54
  <a target="_blank" href="https://wedevs.com/wp-user-frontend-pro/pricing?utm_campaign=black_friday_&_cyber_monday&utm_medium=banner&utm_source=plugin_dashboard">
55
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ) . '/images/promo-btn.png'; ?>" alt="Btn">
56
  </a>
57
  <p>
58
  <span class="highlight-green2">Coupon: </span>
147
  e.preventDefault();
148
 
149
  wp.ajax.post('wpuf-dismiss-promotional-offer-notice', {
150
+ dismissed: true,
151
+ _wpnonce: '<?php echo esc_attr ( wp_create_nonce( 'wpuf_nonce' ) ); ?>'
152
  });
153
  });
154
  </script>
157
  }
158
 
159
  /**
 
160
  * @since 3.1.0
161
  *
162
  * @return void
163
  **/
164
  public function wpuf_review_notice_message() {
165
  // Show only to Admins
166
+ if ( !current_user_can( 'manage_options' ) ) {
167
  return;
168
  }
169
 
178
 
179
  if ( time() - $activation_time < 1296000 ) {
180
  return;
181
+ } ?>
 
 
182
  <div id="wpuf-review-notice" class="wpuf-review-notice">
183
  <div class="wpuf-review-thumbnail">
184
+ <img src="<?php echo esc_attr( WPUF_ASSET_URI ) . '/images/icon-128x128.png'; ?>" alt="">
185
  </div>
186
  <div class="wpuf-review-text">
187
+ <h3><?php esc_html_e( 'Enjoying <strong>WP User Frontend</strong>?', 'wp-user-frontend' ); ?></h3>
188
+ <p><?php esc_html_e( 'Hope that you had a neat and snappy experience with the tool. Would you please show us a little love by rating us in the <a href="https://wordpress.org/support/plugin/wp-user-frontend/reviews/#new-post" target="_blank"><strong>WordPress.org</strong></a>?', 'wp-user-frontend' ); ?></p>
189
 
190
  <ul class="wpuf-review-ul">
191
+ <li><a href="https://wordpress.org/support/plugin/wp-user-frontend/reviews/#new-post" target="_blank"><span class="dashicons dashicons-external"></span><?php esc_html_e( 'Sure! I\'d love to!', 'wp-user-frontend' ); ?></a></li>
192
+ <li><a href="#" class="notice-dismiss"><span class="dashicons dashicons-smiley"></span><?php esc_html_e( 'I\'ve already left a review', 'wp-user-frontend' ); ?></a></li>
193
+ <li><a href="#" class="notice-dismiss"><span class="dashicons dashicons-dismiss"></span><?php esc_html_e( 'Never show again', 'wp-user-frontend' ); ?></a></li>
194
  </ul>
195
  </div>
196
  </div>
270
  jQuery("#wpuf-review-notice").hide();
271
 
272
  wp.ajax.post('wpuf-dismiss-review-notice', {
273
+ dismissed: true,
274
+ _wpnonce: '<?php echo esc_attr ( wp_create_nonce( 'wpuf_nonce' ) ); ?>'
275
  });
276
  });
277
  </script>
278
  <?php
 
279
  }
280
 
281
+ /**
282
+ * Dismiss promotion notice
283
+ *
284
+ * @since 2.5
285
+ *
286
+ * @return void
287
+ */
288
+ public function dismiss_promotional_offer() {
289
+ if( empty( $_POST['_wpnonce'] ) ) {
290
+ wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) );
291
+ }
292
+
293
+ if ( isset( $_POST['_wpnonce'] ) && ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_nonce' ) ) {
294
+ wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) );
295
+ }
296
+
297
+ if ( !empty( $_POST['dismissed'] ) ) {
298
  $offer_key = 'wpuf_promotional_offer_notice';
299
  update_option( $offer_key, 'hide' );
300
  }
301
  }
302
 
303
  /**
304
+ * Dismiss review notice
305
+ *
306
+ * @since 3.1.0
307
+ *
308
+ * @return void
309
+ **/
310
+ public function dismiss_review_notice() {
311
+ if( empty( $_POST['_wpnonce'] ) ) {
312
+ wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) );
313
+ }
314
+
315
+ if ( isset( $_POST['_wpnonce'] ) && ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_nonce' ) ) {
316
+ wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) );
317
+ }
318
+
319
+ if ( !empty( $_POST['dismissed'] ) ) {
320
  update_option( 'wpuf_review_notice_dismiss', 'yes' );
321
  }
322
  }
admin/settings-options.php CHANGED
@@ -4,482 +4,484 @@
4
  * Settings Sections
5
  *
6
  * @since 1.0
 
7
  * @return array
8
  */
9
  function wpuf_settings_sections() {
10
- $sections = array(
11
- array(
12
  'id' => 'wpuf_general',
13
  'title' => __( 'General Options', 'wp-user-frontend' ),
14
- 'icon' => 'dashicons-admin-generic'
15
- ),
16
- array(
17
  'id' => 'wpuf_frontend_posting',
18
  'title' => __( 'Frontend Posting', 'wp-user-frontend' ),
19
- 'icon' => 'dashicons-welcome-write-blog'
20
- ),
21
- array(
22
  'id' => 'wpuf_dashboard',
23
  'title' => __( 'Dashboard', 'wp-user-frontend' ),
24
- 'icon' => 'dashicons-dashboard'
25
- ),
26
- array(
27
  'id' => 'wpuf_my_account',
28
  'title' => __( 'My Account', 'wp-user-frontend' ),
29
- 'icon' => 'dashicons-id'
30
- ),
31
- array(
32
  'id' => 'wpuf_profile',
33
  'title' => __( 'Login / Registration', 'wp-user-frontend' ),
34
- 'icon' => 'dashicons-admin-users'
35
- ),
36
- array(
37
  'id' => 'wpuf_payment',
38
  'title' => __( 'Payments', 'wp-user-frontend' ),
39
- 'icon' => 'dashicons-money'
40
- ),
41
- array(
42
  'id' => 'wpuf_mails',
43
  'title' => __( 'E-Mails', 'wp-user-frontend' ),
44
- 'icon' => 'dashicons-email-alt'
45
- ),
46
- array(
47
  'id' => 'wpuf_privacy',
48
  'title' => __( 'Privacy Options', 'wp-user-frontend' ),
49
- 'icon' => 'dashicons-shield-alt'
50
- ),
51
- );
52
 
53
  return apply_filters( 'wpuf_settings_sections', $sections );
54
  }
55
 
56
  function wpuf_settings_fields() {
57
- $pages = wpuf_get_pages();
58
- $users = wpuf_list_users();
59
  $post_types = get_post_types();
60
  unset( $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item'], $post_types['wpuf_forms'], $post_types['wpuf_profile'], $post_types['wpuf_input'], $post_types['wpuf_subscription'], $post_types['custom_css'], $post_types['customize_changeset'], $post_types['wpuf_coupon'], $post_types['oembed_cache'] );
61
 
62
- $login_redirect_pages = array(
63
- 'previous_page' => __( 'Previous Page', 'wp-user-frontend' )
64
- ) + $pages;
65
 
66
  $all_currencies = wpuf_get_currencies();
67
 
68
- $currencies = array();
 
69
  foreach ( $all_currencies as $currency ) {
70
  $currencies[ $currency['currency'] ] = $currency['label'] . ' (' . $currency['symbol'] . ')';
71
  }
72
 
73
  $default_currency_symbol = wpuf_get_currency( 'symbol' );
74
 
75
- $user_roles = array();
76
- $all_roles = get_editable_roles();
77
- foreach( $all_roles as $key=>$value ) {
 
78
  $user_roles[$key] = $value['name'];
79
  }
80
 
81
- $settings_fields = array(
82
- 'wpuf_general' => apply_filters( 'wpuf_options_others', array(
83
- array(
84
  'name' => 'show_admin_bar',
85
  'label' => __( 'Show Admin Bar', 'wp-user-frontend' ),
86
  'desc' => __( 'Select user by roles, who can view admin bar in frontend.', 'wp-user-frontend' ),
87
  'callback'=> 'wpuf_settings_multiselect',
88
  'options' => $user_roles,
89
- 'default' => array( 'administrator', 'editor', 'author', 'contributor' ),
90
- ),
91
- array(
92
  'name' => 'admin_access',
93
  'label' => __( 'Admin area access', 'wp-user-frontend' ),
94
  'desc' => __( 'Allow you to block specific user role to Ajax request and Media upload.', 'wp-user-frontend' ),
95
  'type' => 'select',
96
  'default' => 'read',
97
- 'options' => array(
98
  'manage_options' => __( 'Admin Only', 'wp-user-frontend' ),
99
  'edit_others_posts' => __( 'Admins, Editors', 'wp-user-frontend' ),
100
  'publish_posts' => __( 'Admins, Editors, Authors', 'wp-user-frontend' ),
101
  'edit_posts' => __( 'Admins, Editors, Authors, Contributors', 'wp-user-frontend' ),
102
- 'read' => __( 'Default', 'wp-user-frontend' )
103
- )
104
- ),
105
- array(
106
  'name' => 'override_editlink',
107
  'label' => __( 'Override the post edit link', 'wp-user-frontend' ),
108
  'desc' => __( 'Users see the edit link in post if s/he is capable to edit the post/page. Selecting <strong>Yes</strong> will override the default WordPress edit post link in frontend', 'wp-user-frontend' ),
109
  'type' => 'select',
110
  'default' => 'no',
111
- 'options' => array(
112
  'yes' => __( 'Yes', 'wp-user-frontend' ),
113
- 'no' => __( 'No', 'wp-user-frontend' )
114
- )
115
- ),
116
- array(
117
  'name' => 'wpuf_compatibility_acf',
118
  'label' => __( 'ACF Compatibility', 'wp-user-frontend' ),
119
  'desc' => __( 'Select <strong>Yes</strong> if you want to make compatible WPUF custom fields data with advanced custom fields.', 'wp-user-frontend' ),
120
  'type' => 'select',
121
  'default' => 'no',
122
- 'options' => array(
123
  'yes' => __( 'Yes', 'wp-user-frontend' ),
124
- 'no' => __( 'No', 'wp-user-frontend' )
125
- )
126
- ),
127
- array(
128
  'name' => 'load_script',
129
  'label' => __( 'Load Scripts', 'wp-user-frontend' ),
130
  'desc' => __( 'Load scripts/styles in all pages', 'wp-user-frontend' ),
131
  'type' => 'checkbox',
132
- 'default' => 'on'
133
- ),
134
- array(
135
  'name' => 'recaptcha_public',
136
  'label' => __( 'reCAPTCHA Site Key', 'wp-user-frontend' ),
137
- ),
138
- array(
139
  'name' => 'recaptcha_private',
140
  'label' => __( 'reCAPTCHA Secret Key', 'wp-user-frontend' ),
141
  'desc' => __( '<a target="_blank" href="https://www.google.com/recaptcha/">Register here</a> to get reCaptcha Site and Secret keys.', 'wp-user-frontend' ),
142
- ),
143
- array(
144
  'name' => 'custom_css',
145
  'label' => __( 'Custom CSS codes', 'wp-user-frontend' ),
146
  'desc' => __( 'If you want to add your custom CSS code, it will be added on page header wrapped with style tag', 'wp-user-frontend' ),
147
- 'type' => 'textarea'
148
- ),
149
- ) ),
150
- 'wpuf_frontend_posting' => apply_filters( 'wpuf_options_frontend_posting', array(
151
- array(
152
  'name' => 'edit_page_id',
153
  'label' => __( 'Edit Page', 'wp-user-frontend' ),
154
  'desc' => __( 'Select the page where <code>[wpuf_edit]</code> is located', 'wp-user-frontend' ),
155
  'type' => 'select',
156
- 'options' => $pages
157
- ),
158
- array(
159
  'name' => 'default_post_owner',
160
  'label' => __( 'Default Post Owner', 'wp-user-frontend' ),
161
  'desc' => __( 'If guest post is enabled and user details are OFF, the posts are assigned to this user', 'wp-user-frontend' ),
162
  'type' => 'select',
163
  'options' => $users,
164
- 'default' => '1'
165
- ),
166
- array(
167
  'name' => 'cf_show_front',
168
  'label' => __( 'Custom Fields in post', 'wp-user-frontend' ),
169
  'desc' => __( 'Show custom fields on post content area', 'wp-user-frontend' ),
170
  'type' => 'checkbox',
171
- 'default' => 'off'
172
- ),
173
- array(
174
  'name' => 'insert_photo_size',
175
  'label' => __( 'Insert Photo image size', 'wp-user-frontend' ),
176
  'desc' => __( 'Default image size of "<strong>Insert Photo</strong>" button in post content area', 'wp-user-frontend' ),
177
  'type' => 'select',
178
  'options' => wpuf_get_image_sizes(),
179
- 'default' => 'thumbnail'
180
- ),
181
- array(
182
- 'name' => 'insert_photo_type',
183
- 'label' => __( 'Insert Photo image type', 'wp-user-frontend' ),
184
- 'desc' => __( 'Default image type of "<strong>Insert Photo</strong>" button in post content area', 'wp-user-frontend' ),
185
- 'type' => 'select',
186
- 'options' => array(
187
  'image' => __( 'Image only', 'wp-user-frontend' ),
188
- 'link' => __( 'Image with link', 'wp-user-frontend' )
189
- ),
190
- 'default' => 'link'
191
- ),
192
- array(
193
  'name' => 'image_caption',
194
  'label' => __( 'Enable Image Caption', 'wp-user-frontend' ),
195
  'desc' => __( 'Allow users to update image/video title, caption and description', 'wp-user-frontend' ),
196
  'type' => 'checkbox',
197
- 'default' => 'off'
198
- ),
199
- array(
200
  'name' => 'default_post_form',
201
  'label' => __( 'Default Post Form', 'wp-user-frontend' ),
202
  'desc' => __( 'Fallback form for post editing if no associated form found', 'wp-user-frontend' ),
203
  'type' => 'select',
204
- 'options' => wpuf_get_pages( 'wpuf_forms' )
205
- ),
206
- ) ),
207
- 'wpuf_dashboard' => apply_filters( 'wpuf_options_dashboard', array(
208
- array(
209
  'name' => 'enable_post_edit',
210
  'label' => __( 'Users can edit post?', 'wp-user-frontend' ),
211
  'desc' => __( 'Users will be able to edit their own posts', 'wp-user-frontend' ),
212
  'type' => 'select',
213
  'default' => 'yes',
214
- 'options' => array(
215
  'yes' => __( 'Yes', 'wp-user-frontend' ),
216
- 'no' => __( 'No', 'wp-user-frontend' )
217
- )
218
- ),
219
- array(
220
  'name' => 'enable_post_del',
221
  'label' => __( 'User can delete post?', 'wp-user-frontend' ),
222
  'desc' => __( 'Users will be able to delete their own posts', 'wp-user-frontend' ),
223
  'type' => 'select',
224
  'default' => 'yes',
225
- 'options' => array(
226
  'yes' => __( 'Yes', 'wp-user-frontend' ),
227
- 'no' => __( 'No', 'wp-user-frontend' )
228
- )
229
- ),
230
- array(
231
  'name' => 'disable_pending_edit',
232
  'label' => __( 'Pending Post Edit', 'wp-user-frontend' ),
233
  'desc' => __( 'Disable post editing while post in "pending" status', 'wp-user-frontend' ),
234
  'type' => 'checkbox',
235
- 'default' => 'on'
236
- ),
237
- array(
238
  'name' => 'per_page',
239
  'label' => __( 'Posts per page', 'wp-user-frontend' ),
240
  'desc' => __( 'How many posts will be listed in a page', 'wp-user-frontend' ),
241
  'type' => 'text',
242
- 'default' => '10'
243
- ),
244
- array(
245
  'name' => 'show_user_bio',
246
  'label' => __( 'Show user bio', 'wp-user-frontend' ),
247
  'desc' => __( 'Users biographical info will be shown', 'wp-user-frontend' ),
248
  'type' => 'checkbox',
249
- 'default' => 'on'
250
- ),
251
- array(
252
  'name' => 'show_post_count',
253
  'label' => __( 'Show post count', 'wp-user-frontend' ),
254
  'desc' => __( 'Show how many posts are created by the user', 'wp-user-frontend' ),
255
  'type' => 'checkbox',
256
- 'default' => 'on'
257
- ),
258
- array(
259
  'name' => 'show_ft_image',
260
  'label' => __( 'Show Featured Image', 'wp-user-frontend' ),
261
  'desc' => __( 'Show featured image of the post (Overridden by Shortcode)', 'wp-user-frontend' ),
262
- 'type' => 'checkbox'
263
- ),
264
- array(
265
- 'name' => 'show_payment_column',
266
- 'label' => __( 'Show Payment Column', 'wp-user-frontend' ),
267
- 'desc' => __( 'Enable if you want show payment column on posts table', 'wp-user-frontend' ),
268
  'type' => 'checkbox',
 
 
 
 
 
 
269
  'default' => 'on',
270
- ),
271
- array(
272
  'name' => 'ft_img_size',
273
  'label' => __( 'Featured Image size', 'wp-user-frontend' ),
274
  'type' => 'select',
275
- 'options' => wpuf_get_image_sizes()
276
- ),
277
- array(
278
  'name' => 'un_auth_msg',
279
  'label' => __( 'Unauthorized Message', 'wp-user-frontend' ),
280
  'desc' => __( 'Not logged in users will see this message', 'wp-user-frontend' ),
281
- 'type' => 'textarea'
282
- ),
283
- ) ),
284
- 'wpuf_my_account' => apply_filters( 'wpuf_options_wpuf_my_account', array(
285
- array(
286
  'name' => 'account_page',
287
  'label' => __( 'Account Page', 'wp-user-frontend' ),
288
  'desc' => __( 'Select the page which contains <code>[wpuf_account]</code> shortcode', 'wp-user-frontend' ),
289
  'type' => 'select',
290
- 'options' => $pages
291
- ),
292
- array(
293
  'name' => 'account_page_active_tab',
294
  'label' => __( 'Active Tab', 'wp-user-frontend' ),
295
  'desc' => __( 'Which tab should be set as active by default when opening the account page', 'wp-user-frontend' ),
296
  'type' => 'select',
297
- 'options' => wpuf_get_account_sections_list()
298
- ),
299
- array(
300
  'name' => 'show_subscriptions',
301
  'label' => __( 'Show Subscriptions', 'wp-user-frontend' ),
302
  'desc' => __( 'Show Subscriptions tab in "my account" page where <code>[wpuf_account]</code> is located', 'wp-user-frontend' ),
303
  'type' => 'checkbox',
304
  'default' => 'on',
305
- ),
306
- array(
307
- 'name' => 'show_billing_address',
308
- 'label' => __( 'Show Billing Address', 'wp-user-frontend' ),
309
- 'desc' => __( 'Show billing address in account page.', 'wp-user-frontend' ),
310
- 'type' => 'checkbox',
311
  'default' => 'on',
312
- ),
313
- ) ),
314
- 'wpuf_profile' => apply_filters( 'wpuf_options_profile', array(
315
- array(
316
  'name' => 'autologin_after_registration',
317
  'label' => __( 'Auto Login After Registration', 'wp-user-frontend' ),
318
  'desc' => __( 'If enabled, users after registration will be logged in to the system', 'wp-user-frontend' ),
319
  'type' => 'checkbox',
320
- 'default' => 'on'
321
- ),
322
- array(
323
  'name' => 'register_link_override',
324
  'label' => __( 'Login/Registration override', 'wp-user-frontend' ),
325
  'desc' => __( 'If enabled, default login and registration forms will be overridden by WPUF with pages below', 'wp-user-frontend' ),
326
  'type' => 'checkbox',
327
- 'default' => 'on'
328
- ),
329
- array(
330
  'name' => 'reg_override_page',
331
  'label' => __( 'Registration Page', 'wp-user-frontend' ),
332
  'desc' => __( 'Select the page you want to use as registration page override <em>(should have shortcode)</em>', 'wp-user-frontend' ),
333
  'type' => 'select',
334
- 'options' => $pages
335
- ),
336
- array(
337
  'name' => 'login_page',
338
  'label' => __( 'Login Page', 'wp-user-frontend' ),
339
  'desc' => __( 'Select the page which contains <code>[wpuf-login]</code> shortcode', 'wp-user-frontend' ),
340
  'type' => 'select',
341
- 'options' => $pages
342
- ),
343
- array(
344
  'name' => 'redirect_after_login_page',
345
  'label' => __( 'Redirect After Login', 'wp-user-frontend' ),
346
  'desc' => __( 'After successfull login, where the page will redirect to', 'wp-user-frontend' ),
347
  'type' => 'select',
348
- 'options' => $login_redirect_pages
349
- ),
350
- array(
351
  'name' => 'wp_default_login_redirect',
352
  'label' => __( 'Default Login Redirect', 'wp-user-frontend' ),
353
  'desc' => __( 'If enabled, users who login using WordPress default login form will be redirected to the selected page.', 'wp-user-frontend' ),
354
  'type' => 'checkbox',
355
- 'default' => 'off'
356
- ),
357
- array(
358
  'name' => 'login_form_recaptcha',
359
  'label' => __( 'reCAPTCHA in Login Form', 'wp-user-frontend' ),
360
  'desc' => __( 'If enabled, users have to verify reCAPTCHA in login page. Also, make sure that reCAPTCHA is configured properly from <b>General Options</b>', 'wp-user-frontend' ),
361
  'type' => 'checkbox',
362
- 'default' => 'off'
363
- ),
364
-
365
- ) ),
366
- 'wpuf_payment' => apply_filters( 'wpuf_options_payment', array(
367
- array(
368
- 'name' => 'enable_payment',
369
- 'label' => __( 'Enable Payments', 'wp-user-frontend' ),
370
- 'desc' => __( 'Enable payments on your site.', 'wp-user-frontend' ),
371
- 'type' => 'checkbox',
372
  'default' => 'on',
373
- ),
374
- array(
375
  'name' => 'subscription_page',
376
  'label' => __( 'Subscription Pack Page', 'wp-user-frontend' ),
377
  'desc' => __( 'Select the page where <code>[wpuf_sub_pack]</code> located.', 'wp-user-frontend' ),
378
  'type' => 'select',
379
- 'options' => $pages
380
- ),
381
- array(
382
  'name' => 'register_subscription',
383
  'label' => __( 'Subscription at registration', 'wp-user-frontend' ),
384
  'desc' => __( 'Registration time redirect to subscription page', 'wp-user-frontend' ),
385
  'type' => 'checkbox',
386
- ),
387
- array(
388
  'name' => 'currency',
389
  'label' => __( 'Currency', 'wp-user-frontend' ),
390
  'type' => 'select',
391
  'default' => 'USD',
392
- 'options' => $currencies
393
- ),
394
- array(
395
  'name' => 'currency_position',
396
  'label' => __( 'Currency Position', 'wp-user-frontend' ),
397
  'type' => 'select',
398
  'default' => 'left',
399
- 'options' => array(
400
  'left' => sprintf( '%1$s (%2$s99.99)', __( 'Left', 'wp-user-frontend' ), $default_currency_symbol ),
401
  'right' => sprintf( '%1$s (99.99%2$s)', __( 'Right', 'wp-user-frontend' ), $default_currency_symbol ),
402
  'left_space' => sprintf( '%1$s (%2$s 99.99)', __( 'Left with space', 'wp-user-frontend' ), $default_currency_symbol ),
403
  'right_space' => sprintf( '%1$s (99.99 %2$s)', __( 'Right with space', 'wp-user-frontend' ), $default_currency_symbol ),
404
- )
405
- ),
406
- array(
407
  'name' => 'wpuf_price_thousand_sep',
408
- 'label' => __( 'Thousand Separator', 'wp-user-frontend' ),
409
- 'desc' => __( 'This sets the thousand separator of displayed prices.', 'wp-user-frontend' ),
410
- 'css' => 'width:50px;',
411
- 'default' => ',',
412
- 'type' => 'text',
413
- 'desc_tip' => true,
414
- ),
415
- array(
416
  'name' => 'wpuf_price_decimal_sep',
417
- 'label' => __( 'Decimal Separator', 'wp-user-frontend' ),
418
- 'desc' => __( 'This sets the decimal separator of displayed prices.', 'wp-user-frontend' ),
419
- 'default' => '.',
420
- 'type' => 'text',
421
- ),
422
 
423
- array(
424
- 'name' => 'wpuf_price_num_decimals',
425
- 'label' => __( 'Number of Decimals', 'wp-user-frontend' ),
426
- 'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'wp-user-frontend' ),
427
- 'default' => '2',
428
- 'type' => 'number',
429
- 'custom_attributes' => array(
430
  'min' => 0,
431
- 'step' => 1
432
- )
433
- ),
434
- array(
435
  'name' => 'sandbox_mode',
436
  'label' => __( 'Enable demo/sandbox mode', 'wp-user-frontend' ),
437
  'desc' => __( 'When sandbox mode is active, all payment gateway will be used in demo mode', 'wp-user-frontend' ),
438
  'type' => 'checkbox',
439
- 'default' => 'on'
440
- ),
441
- array(
442
  'name' => 'payment_page',
443
  'label' => __( 'Payment Page', 'wp-user-frontend' ),
444
  'desc' => __( 'This page will be used to process payment options', 'wp-user-frontend' ),
445
  'type' => 'select',
446
- 'options' => $pages
447
- ),
448
- array(
449
  'name' => 'payment_success',
450
  'label' => __( 'Payment Success Page', 'wp-user-frontend' ),
451
  'desc' => __( 'After payment users will be redirected here', 'wp-user-frontend' ),
452
  'type' => 'select',
453
- 'options' => $pages
454
- ),
455
- array(
456
  'name' => 'active_gateways',
457
  'label' => __( 'Payment Gateways', 'wp-user-frontend' ),
458
  'desc' => __( 'Active payment gateways', 'wp-user-frontend' ),
459
  'type' => 'multicheck',
460
- 'options' => wpuf_get_gateways()
461
- )
462
- ) ),
463
- 'wpuf_mails' => apply_filters( 'wpuf_mail_options', array(
464
- array(
465
  'name' => 'guest_email_setting',
466
  'label' => __( '<span class="dashicons dashicons-universal-access-alt"></span> Guest Email', 'wp-user-frontend' ),
467
  'type' => 'html',
468
  'class' => 'guest-email-setting',
469
- ),
470
- array(
471
  'name' => 'guest_email_subject',
472
  'label' => __( 'Guest mail subject', 'wp-user-frontend' ),
473
  'desc' => __( 'This sets the subject of the emails sent to guest users', 'wp-user-frontend' ),
474
  'default' => 'Please Confirm Your Email to Get the Post Published!',
475
  'type' => 'text',
476
  'class' => 'guest-email-setting-option',
477
- ),
478
- array(
479
  'name' => 'guest_email_body',
480
  'label' => __( 'Guest mail body', 'wp-user-frontend' ),
481
  'desc' => __( "This sets the body of the emails sent to guest users. Please DON'T edit the <code>{activation_link}</code> part, you can use {sitename} too.", 'wp-user-frontend' ),
482
- 'default' => "Hey There,
483
 
484
  We just received your guest post and now we want you to confirm your email so that we can verify the content and move on to the publishing process.
485
 
@@ -487,57 +489,57 @@ function wpuf_settings_fields() {
487
  {activation_link}
488
 
489
  Regards,
490
- {sitename}",
491
  'type' => 'wysiwyg',
492
  'class' => 'guest-email-setting-option',
493
- ),
494
- ) ),
495
- 'wpuf_privacy' => apply_filters( 'wpuf_privacy_options', array(
496
- array(
497
  'name' => 'export_post_types',
498
  'label' => __( 'Post Types', 'wp-user-frontend' ),
499
  'desc' => __( 'Select the post types you will allow users to export.', 'wp-user-frontend' ),
500
  'callback'=> 'wpuf_settings_multiselect',
501
  'options' => $post_types,
502
- ),
503
- ) ),
504
- );
505
 
506
  return apply_filters( 'wpuf_settings_fields', $settings_fields );
507
  }
508
 
509
  function wpuf_settings_field_profile( $form ) {
510
  $user_roles = wpuf_get_user_roles();
511
- $forms = get_posts( array(
512
  'numberposts' => -1,
513
- 'post_type' => 'wpuf_profile'
514
- ) );
515
 
516
- $val = get_option( 'wpuf_profile', array() );
517
 
518
- if ( class_exists('WP_User_Frontend_Pro') ) {
519
- ?>
520
 
521
  <p style="padding-left: 10px; font-style: italic; font-size: 13px;">
522
- <strong><?php _e( 'Select profile/registration forms for user roles. These forms will be used to populate extra edit profile fields in backend.', 'wp-user-frontend' ); ?></strong>
523
  </p>
524
  <table class="form-table">
525
  <?php
526
- foreach ($user_roles as $role => $name) {
527
- $current = isset( $val['roles'][$role] ) ? $val['roles'][$role] : '';
528
- ?>
529
  <tr valign="top">
530
- <th scrope="row"><?php echo $name; ?></th>
531
  <td>
532
- <select name="wpuf_profile[roles][<?php echo $role; ?>]">
533
- <option value=""><?php _e( ' - select - ', 'wp-user-frontend' ); ?></option>
534
- <?php foreach ($forms as $form) { ?>
535
- <option value="<?php echo $form->ID; ?>"<?php selected( $current, $form->ID ); ?>><?php echo $form->post_title; ?></option>
536
  <?php } ?>
537
  </select>
538
  </td>
539
  </tr>
540
- <?php } ?>
 
541
  </table>
542
  <?php
543
  }
4
  * Settings Sections
5
  *
6
  * @since 1.0
7
+ *
8
  * @return array
9
  */
10
  function wpuf_settings_sections() {
11
+ $sections = [
12
+ [
13
  'id' => 'wpuf_general',
14
  'title' => __( 'General Options', 'wp-user-frontend' ),
15
+ 'icon' => 'dashicons-admin-generic',
16
+ ],
17
+ [
18
  'id' => 'wpuf_frontend_posting',
19
  'title' => __( 'Frontend Posting', 'wp-user-frontend' ),
20
+ 'icon' => 'dashicons-welcome-write-blog',
21
+ ],
22
+ [
23
  'id' => 'wpuf_dashboard',
24
  'title' => __( 'Dashboard', 'wp-user-frontend' ),
25
+ 'icon' => 'dashicons-dashboard',
26
+ ],
27
+ [
28
  'id' => 'wpuf_my_account',
29
  'title' => __( 'My Account', 'wp-user-frontend' ),
30
+ 'icon' => 'dashicons-id',
31
+ ],
32
+ [
33
  'id' => 'wpuf_profile',
34
  'title' => __( 'Login / Registration', 'wp-user-frontend' ),
35
+ 'icon' => 'dashicons-admin-users',
36
+ ],
37
+ [
38
  'id' => 'wpuf_payment',
39
  'title' => __( 'Payments', 'wp-user-frontend' ),
40
+ 'icon' => 'dashicons-money',
41
+ ],
42
+ [
43
  'id' => 'wpuf_mails',
44
  'title' => __( 'E-Mails', 'wp-user-frontend' ),
45
+ 'icon' => 'dashicons-email-alt',
46
+ ],
47
+ [
48
  'id' => 'wpuf_privacy',
49
  'title' => __( 'Privacy Options', 'wp-user-frontend' ),
50
+ 'icon' => 'dashicons-shield-alt',
51
+ ],
52
+ ];
53
 
54
  return apply_filters( 'wpuf_settings_sections', $sections );
55
  }
56
 
57
  function wpuf_settings_fields() {
58
+ $pages = wpuf_get_pages();
59
+ $users = wpuf_list_users();
60
  $post_types = get_post_types();
61
  unset( $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item'], $post_types['wpuf_forms'], $post_types['wpuf_profile'], $post_types['wpuf_input'], $post_types['wpuf_subscription'], $post_types['custom_css'], $post_types['customize_changeset'], $post_types['wpuf_coupon'], $post_types['oembed_cache'] );
62
 
63
+ $login_redirect_pages = [
64
+ 'previous_page' => __( 'Previous Page', 'wp-user-frontend' ),
65
+ ] + $pages;
66
 
67
  $all_currencies = wpuf_get_currencies();
68
 
69
+ $currencies = [];
70
+
71
  foreach ( $all_currencies as $currency ) {
72
  $currencies[ $currency['currency'] ] = $currency['label'] . ' (' . $currency['symbol'] . ')';
73
  }
74
 
75
  $default_currency_symbol = wpuf_get_currency( 'symbol' );
76
 
77
+ $user_roles = [];
78
+ $all_roles = get_editable_roles();
79
+
80
+ foreach ( $all_roles as $key=>$value ) {
81
  $user_roles[$key] = $value['name'];
82
  }
83
 
84
+ $settings_fields = [
85
+ 'wpuf_general' => apply_filters( 'wpuf_options_others', [
86
+ [
87
  'name' => 'show_admin_bar',
88
  'label' => __( 'Show Admin Bar', 'wp-user-frontend' ),
89
  'desc' => __( 'Select user by roles, who can view admin bar in frontend.', 'wp-user-frontend' ),
90
  'callback'=> 'wpuf_settings_multiselect',
91
  'options' => $user_roles,
92
+ 'default' => [ 'administrator', 'editor', 'author', 'contributor' ],
93
+ ],
94
+ [
95
  'name' => 'admin_access',
96
  'label' => __( 'Admin area access', 'wp-user-frontend' ),
97
  'desc' => __( 'Allow you to block specific user role to Ajax request and Media upload.', 'wp-user-frontend' ),
98
  'type' => 'select',
99
  'default' => 'read',
100
+ 'options' => [
101
  'manage_options' => __( 'Admin Only', 'wp-user-frontend' ),
102
  'edit_others_posts' => __( 'Admins, Editors', 'wp-user-frontend' ),
103
  'publish_posts' => __( 'Admins, Editors, Authors', 'wp-user-frontend' ),
104
  'edit_posts' => __( 'Admins, Editors, Authors, Contributors', 'wp-user-frontend' ),
105
+ 'read' => __( 'Default', 'wp-user-frontend' ),
106
+ ],
107
+ ],
108
+ [
109
  'name' => 'override_editlink',
110
  'label' => __( 'Override the post edit link', 'wp-user-frontend' ),
111
  'desc' => __( 'Users see the edit link in post if s/he is capable to edit the post/page. Selecting <strong>Yes</strong> will override the default WordPress edit post link in frontend', 'wp-user-frontend' ),
112
  'type' => 'select',
113
  'default' => 'no',
114
+ 'options' => [
115
  'yes' => __( 'Yes', 'wp-user-frontend' ),
116
+ 'no' => __( 'No', 'wp-user-frontend' ),
117
+ ],
118
+ ],
119
+ [
120
  'name' => 'wpuf_compatibility_acf',
121
  'label' => __( 'ACF Compatibility', 'wp-user-frontend' ),
122
  'desc' => __( 'Select <strong>Yes</strong> if you want to make compatible WPUF custom fields data with advanced custom fields.', 'wp-user-frontend' ),
123
  'type' => 'select',
124
  'default' => 'no',
125
+ 'options' => [
126
  'yes' => __( 'Yes', 'wp-user-frontend' ),
127
+ 'no' => __( 'No', 'wp-user-frontend' ),
128
+ ],
129
+ ],
130
+ [
131
  'name' => 'load_script',
132
  'label' => __( 'Load Scripts', 'wp-user-frontend' ),
133
  'desc' => __( 'Load scripts/styles in all pages', 'wp-user-frontend' ),
134
  'type' => 'checkbox',
135
+ 'default' => 'on',
136
+ ],
137
+ [
138
  'name' => 'recaptcha_public',
139
  'label' => __( 'reCAPTCHA Site Key', 'wp-user-frontend' ),
140
+ ],
141
+ [
142
  'name' => 'recaptcha_private',
143
  'label' => __( 'reCAPTCHA Secret Key', 'wp-user-frontend' ),
144
  'desc' => __( '<a target="_blank" href="https://www.google.com/recaptcha/">Register here</a> to get reCaptcha Site and Secret keys.', 'wp-user-frontend' ),
145
+ ],
146
+ [
147
  'name' => 'custom_css',
148
  'label' => __( 'Custom CSS codes', 'wp-user-frontend' ),
149
  'desc' => __( 'If you want to add your custom CSS code, it will be added on page header wrapped with style tag', 'wp-user-frontend' ),
150
+ 'type' => 'textarea',
151
+ ],
152
+ ] ),
153
+ 'wpuf_frontend_posting' => apply_filters( 'wpuf_options_frontend_posting', [
154
+ [
155
  'name' => 'edit_page_id',
156
  'label' => __( 'Edit Page', 'wp-user-frontend' ),
157
  'desc' => __( 'Select the page where <code>[wpuf_edit]</code> is located', 'wp-user-frontend' ),
158
  'type' => 'select',
159
+ 'options' => $pages,
160
+ ],
161
+ [
162
  'name' => 'default_post_owner',
163
  'label' => __( 'Default Post Owner', 'wp-user-frontend' ),
164
  'desc' => __( 'If guest post is enabled and user details are OFF, the posts are assigned to this user', 'wp-user-frontend' ),
165
  'type' => 'select',
166
  'options' => $users,
167
+ 'default' => '1',
168
+ ],
169
+ [
170
  'name' => 'cf_show_front',
171
  'label' => __( 'Custom Fields in post', 'wp-user-frontend' ),
172
  'desc' => __( 'Show custom fields on post content area', 'wp-user-frontend' ),
173
  'type' => 'checkbox',
174
+ 'default' => 'off',
175
+ ],
176
+ [
177
  'name' => 'insert_photo_size',
178
  'label' => __( 'Insert Photo image size', 'wp-user-frontend' ),
179
  'desc' => __( 'Default image size of "<strong>Insert Photo</strong>" button in post content area', 'wp-user-frontend' ),
180
  'type' => 'select',
181
  'options' => wpuf_get_image_sizes(),
182
+ 'default' => 'thumbnail',
183
+ ],
184
+ [
185
+ 'name' => 'insert_photo_type',
186
+ 'label' => __( 'Insert Photo image type', 'wp-user-frontend' ),
187
+ 'desc' => __( 'Default image type of "<strong>Insert Photo</strong>" button in post content area', 'wp-user-frontend' ),
188
+ 'type' => 'select',
189
+ 'options' => [
190
  'image' => __( 'Image only', 'wp-user-frontend' ),
191
+ 'link' => __( 'Image with link', 'wp-user-frontend' ),
192
+ ],
193
+ 'default' => 'link',
194
+ ],
195
+ [
196
  'name' => 'image_caption',
197
  'label' => __( 'Enable Image Caption', 'wp-user-frontend' ),
198
  'desc' => __( 'Allow users to update image/video title, caption and description', 'wp-user-frontend' ),
199
  'type' => 'checkbox',
200
+ 'default' => 'off',
201
+ ],
202
+ [
203
  'name' => 'default_post_form',
204
  'label' => __( 'Default Post Form', 'wp-user-frontend' ),
205
  'desc' => __( 'Fallback form for post editing if no associated form found', 'wp-user-frontend' ),
206
  'type' => 'select',
207
+ 'options' => wpuf_get_pages( 'wpuf_forms' ),
208
+ ],
209
+ ] ),
210
+ 'wpuf_dashboard' => apply_filters( 'wpuf_options_dashboard', [
211
+ [
212
  'name' => 'enable_post_edit',
213
  'label' => __( 'Users can edit post?', 'wp-user-frontend' ),
214
  'desc' => __( 'Users will be able to edit their own posts', 'wp-user-frontend' ),
215
  'type' => 'select',
216
  'default' => 'yes',
217
+ 'options' => [
218
  'yes' => __( 'Yes', 'wp-user-frontend' ),
219
+ 'no' => __( 'No', 'wp-user-frontend' ),
220
+ ],
221
+ ],
222
+ [
223
  'name' => 'enable_post_del',
224
  'label' => __( 'User can delete post?', 'wp-user-frontend' ),
225
  'desc' => __( 'Users will be able to delete their own posts', 'wp-user-frontend' ),
226
  'type' => 'select',
227
  'default' => 'yes',
228
+ 'options' => [
229
  'yes' => __( 'Yes', 'wp-user-frontend' ),
230
+ 'no' => __( 'No', 'wp-user-frontend' ),
231
+ ],
232
+ ],
233
+ [
234
  'name' => 'disable_pending_edit',
235
  'label' => __( 'Pending Post Edit', 'wp-user-frontend' ),
236
  'desc' => __( 'Disable post editing while post in "pending" status', 'wp-user-frontend' ),
237
  'type' => 'checkbox',
238
+ 'default' => 'on',
239
+ ],
240
+ [
241
  'name' => 'per_page',
242
  'label' => __( 'Posts per page', 'wp-user-frontend' ),
243
  'desc' => __( 'How many posts will be listed in a page', 'wp-user-frontend' ),
244
  'type' => 'text',
245
+ 'default' => '10',
246
+ ],
247
+ [
248
  'name' => 'show_user_bio',
249
  'label' => __( 'Show user bio', 'wp-user-frontend' ),
250
  'desc' => __( 'Users biographical info will be shown', 'wp-user-frontend' ),
251
  'type' => 'checkbox',
252
+ 'default' => 'on',
253
+ ],
254
+ [
255
  'name' => 'show_post_count',
256
  'label' => __( 'Show post count', 'wp-user-frontend' ),
257
  'desc' => __( 'Show how many posts are created by the user', 'wp-user-frontend' ),
258
  'type' => 'checkbox',
259
+ 'default' => 'on',
260
+ ],
261
+ [
262
  'name' => 'show_ft_image',
263
  'label' => __( 'Show Featured Image', 'wp-user-frontend' ),
264
  'desc' => __( 'Show featured image of the post (Overridden by Shortcode)', 'wp-user-frontend' ),
 
 
 
 
 
 
265
  'type' => 'checkbox',
266
+ ],
267
+ [
268
+ 'name' => 'show_payment_column',
269
+ 'label' => __( 'Show Payment Column', 'wp-user-frontend' ),
270
+ 'desc' => __( 'Enable if you want show payment column on posts table', 'wp-user-frontend' ),
271
+ 'type' => 'checkbox',
272
  'default' => 'on',
273
+ ],
274
+ [
275
  'name' => 'ft_img_size',
276
  'label' => __( 'Featured Image size', 'wp-user-frontend' ),
277
  'type' => 'select',
278
+ 'options' => wpuf_get_image_sizes(),
279
+ ],
280
+ [
281
  'name' => 'un_auth_msg',
282
  'label' => __( 'Unauthorized Message', 'wp-user-frontend' ),
283
  'desc' => __( 'Not logged in users will see this message', 'wp-user-frontend' ),
284
+ 'type' => 'textarea',
285
+ ],
286
+ ] ),
287
+ 'wpuf_my_account' => apply_filters( 'wpuf_options_wpuf_my_account', [
288
+ [
289
  'name' => 'account_page',
290
  'label' => __( 'Account Page', 'wp-user-frontend' ),
291
  'desc' => __( 'Select the page which contains <code>[wpuf_account]</code> shortcode', 'wp-user-frontend' ),
292
  'type' => 'select',
293
+ 'options' => $pages,
294
+ ],
295
+ [
296
  'name' => 'account_page_active_tab',
297
  'label' => __( 'Active Tab', 'wp-user-frontend' ),
298
  'desc' => __( 'Which tab should be set as active by default when opening the account page', 'wp-user-frontend' ),
299
  'type' => 'select',
300
+ 'options' => wpuf_get_account_sections_list(),
301
+ ],
302
+ [
303
  'name' => 'show_subscriptions',
304
  'label' => __( 'Show Subscriptions', 'wp-user-frontend' ),
305
  'desc' => __( 'Show Subscriptions tab in "my account" page where <code>[wpuf_account]</code> is located', 'wp-user-frontend' ),
306
  'type' => 'checkbox',
307
  'default' => 'on',
308
+ ],
309
+ [
310
+ 'name' => 'show_billing_address',
311
+ 'label' => __( 'Show Billing Address', 'wp-user-frontend' ),
312
+ 'desc' => __( 'Show billing address in account page.', 'wp-user-frontend' ),
313
+ 'type' => 'checkbox',
314
  'default' => 'on',
315
+ ],
316
+ ] ),
317
+ 'wpuf_profile' => apply_filters( 'wpuf_options_profile', [
318
+ [
319
  'name' => 'autologin_after_registration',
320
  'label' => __( 'Auto Login After Registration', 'wp-user-frontend' ),
321
  'desc' => __( 'If enabled, users after registration will be logged in to the system', 'wp-user-frontend' ),
322
  'type' => 'checkbox',
323
+ 'default' => 'on',
324
+ ],
325
+ [
326
  'name' => 'register_link_override',
327
  'label' => __( 'Login/Registration override', 'wp-user-frontend' ),
328
  'desc' => __( 'If enabled, default login and registration forms will be overridden by WPUF with pages below', 'wp-user-frontend' ),
329
  'type' => 'checkbox',
330
+ 'default' => 'on',
331
+ ],
332
+ [
333
  'name' => 'reg_override_page',
334
  'label' => __( 'Registration Page', 'wp-user-frontend' ),
335
  'desc' => __( 'Select the page you want to use as registration page override <em>(should have shortcode)</em>', 'wp-user-frontend' ),
336
  'type' => 'select',
337
+ 'options' => $pages,
338
+ ],
339
+ [
340
  'name' => 'login_page',
341
  'label' => __( 'Login Page', 'wp-user-frontend' ),
342
  'desc' => __( 'Select the page which contains <code>[wpuf-login]</code> shortcode', 'wp-user-frontend' ),
343
  'type' => 'select',
344
+ 'options' => $pages,
345
+ ],
346
+ [
347
  'name' => 'redirect_after_login_page',
348
  'label' => __( 'Redirect After Login', 'wp-user-frontend' ),
349
  'desc' => __( 'After successfull login, where the page will redirect to', 'wp-user-frontend' ),
350
  'type' => 'select',
351
+ 'options' => $login_redirect_pages,
352
+ ],
353
+ [
354
  'name' => 'wp_default_login_redirect',
355
  'label' => __( 'Default Login Redirect', 'wp-user-frontend' ),
356
  'desc' => __( 'If enabled, users who login using WordPress default login form will be redirected to the selected page.', 'wp-user-frontend' ),
357
  'type' => 'checkbox',
358
+ 'default' => 'off',
359
+ ],
360
+ [
361
  'name' => 'login_form_recaptcha',
362
  'label' => __( 'reCAPTCHA in Login Form', 'wp-user-frontend' ),
363
  'desc' => __( 'If enabled, users have to verify reCAPTCHA in login page. Also, make sure that reCAPTCHA is configured properly from <b>General Options</b>', 'wp-user-frontend' ),
364
  'type' => 'checkbox',
365
+ 'default' => 'off',
366
+ ],
367
+ ] ),
368
+ 'wpuf_payment' => apply_filters( 'wpuf_options_payment', [
369
+ [
370
+ 'name' => 'enable_payment',
371
+ 'label' => __( 'Enable Payments', 'wp-user-frontend' ),
372
+ 'desc' => __( 'Enable payments on your site.', 'wp-user-frontend' ),
373
+ 'type' => 'checkbox',
 
374
  'default' => 'on',
375
+ ],
376
+ [
377
  'name' => 'subscription_page',
378
  'label' => __( 'Subscription Pack Page', 'wp-user-frontend' ),
379
  'desc' => __( 'Select the page where <code>[wpuf_sub_pack]</code> located.', 'wp-user-frontend' ),
380
  'type' => 'select',
381
+ 'options' => $pages,
382
+ ],
383
+ [
384
  'name' => 'register_subscription',
385
  'label' => __( 'Subscription at registration', 'wp-user-frontend' ),
386
  'desc' => __( 'Registration time redirect to subscription page', 'wp-user-frontend' ),
387
  'type' => 'checkbox',
388
+ ],
389
+ [
390
  'name' => 'currency',
391
  'label' => __( 'Currency', 'wp-user-frontend' ),
392
  'type' => 'select',
393
  'default' => 'USD',
394
+ 'options' => $currencies,
395
+ ],
396
+ [
397
  'name' => 'currency_position',
398
  'label' => __( 'Currency Position', 'wp-user-frontend' ),
399
  'type' => 'select',
400
  'default' => 'left',
401
+ 'options' => [
402
  'left' => sprintf( '%1$s (%2$s99.99)', __( 'Left', 'wp-user-frontend' ), $default_currency_symbol ),
403
  'right' => sprintf( '%1$s (99.99%2$s)', __( 'Right', 'wp-user-frontend' ), $default_currency_symbol ),
404
  'left_space' => sprintf( '%1$s (%2$s 99.99)', __( 'Left with space', 'wp-user-frontend' ), $default_currency_symbol ),
405
  'right_space' => sprintf( '%1$s (99.99 %2$s)', __( 'Right with space', 'wp-user-frontend' ), $default_currency_symbol ),
406
+ ],
407
+ ],
408
+ [
409
  'name' => 'wpuf_price_thousand_sep',
410
+ 'label' => __( 'Thousand Separator', 'wp-user-frontend' ),
411
+ 'desc' => __( 'This sets the thousand separator of displayed prices.', 'wp-user-frontend' ),
412
+ 'css' => 'width:50px;',
413
+ 'default' => ',',
414
+ 'type' => 'text',
415
+ 'desc_tip' => true,
416
+ ],
417
+ [
418
  'name' => 'wpuf_price_decimal_sep',
419
+ 'label' => __( 'Decimal Separator', 'wp-user-frontend' ),
420
+ 'desc' => __( 'This sets the decimal separator of displayed prices.', 'wp-user-frontend' ),
421
+ 'default' => '.',
422
+ 'type' => 'text',
423
+ ],
424
 
425
+ [
426
+ 'name' => 'wpuf_price_num_decimals',
427
+ 'label' => __( 'Number of Decimals', 'wp-user-frontend' ),
428
+ 'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'wp-user-frontend' ),
429
+ 'default' => '2',
430
+ 'type' => 'number',
431
+ 'custom_attributes' => [
432
  'min' => 0,
433
+ 'step' => 1,
434
+ ],
435
+ ],
436
+ [
437
  'name' => 'sandbox_mode',
438
  'label' => __( 'Enable demo/sandbox mode', 'wp-user-frontend' ),
439
  'desc' => __( 'When sandbox mode is active, all payment gateway will be used in demo mode', 'wp-user-frontend' ),
440
  'type' => 'checkbox',
441
+ 'default' => 'on',
442
+ ],
443
+ [
444
  'name' => 'payment_page',
445
  'label' => __( 'Payment Page', 'wp-user-frontend' ),
446
  'desc' => __( 'This page will be used to process payment options', 'wp-user-frontend' ),
447
  'type' => 'select',
448
+ 'options' => $pages,
449
+ ],
450
+ [
451
  'name' => 'payment_success',
452
  'label' => __( 'Payment Success Page', 'wp-user-frontend' ),
453
  'desc' => __( 'After payment users will be redirected here', 'wp-user-frontend' ),
454
  'type' => 'select',
455
+ 'options' => $pages,
456
+ ],
457
+ [
458
  'name' => 'active_gateways',
459
  'label' => __( 'Payment Gateways', 'wp-user-frontend' ),
460
  'desc' => __( 'Active payment gateways', 'wp-user-frontend' ),
461
  'type' => 'multicheck',
462
+ 'options' => wpuf_get_gateways(),
463
+ ],
464
+ ] ),
465
+ 'wpuf_mails' => apply_filters( 'wpuf_mail_options', [
466
+ [
467
  'name' => 'guest_email_setting',
468
  'label' => __( '<span class="dashicons dashicons-universal-access-alt"></span> Guest Email', 'wp-user-frontend' ),
469
  'type' => 'html',
470
  'class' => 'guest-email-setting',
471
+ ],
472
+ [
473
  'name' => 'guest_email_subject',
474
  'label' => __( 'Guest mail subject', 'wp-user-frontend' ),
475
  'desc' => __( 'This sets the subject of the emails sent to guest users', 'wp-user-frontend' ),
476
  'default' => 'Please Confirm Your Email to Get the Post Published!',
477
  'type' => 'text',
478
  'class' => 'guest-email-setting-option',
479
+ ],
480
+ [
481
  'name' => 'guest_email_body',
482
  'label' => __( 'Guest mail body', 'wp-user-frontend' ),
483
  'desc' => __( "This sets the body of the emails sent to guest users. Please DON'T edit the <code>{activation_link}</code> part, you can use {sitename} too.", 'wp-user-frontend' ),
484
+ 'default' => 'Hey There,
485
 
486
  We just received your guest post and now we want you to confirm your email so that we can verify the content and move on to the publishing process.
487
 
489
  {activation_link}
490
 
491
  Regards,
492
+ {sitename}',
493
  'type' => 'wysiwyg',
494
  'class' => 'guest-email-setting-option',
495
+ ],
496
+ ] ),
497
+ 'wpuf_privacy' => apply_filters( 'wpuf_privacy_options', [
498
+ [
499
  'name' => 'export_post_types',
500
  'label' => __( 'Post Types', 'wp-user-frontend' ),
501
  'desc' => __( 'Select the post types you will allow users to export.', 'wp-user-frontend' ),
502
  'callback'=> 'wpuf_settings_multiselect',
503
  'options' => $post_types,
504
+ ],
505
+ ] ),
506
+ ];
507
 
508
  return apply_filters( 'wpuf_settings_fields', $settings_fields );
509
  }
510
 
511
  function wpuf_settings_field_profile( $form ) {
512
  $user_roles = wpuf_get_user_roles();
513
+ $forms = get_posts( [
514
  'numberposts' => -1,
515
+ 'post_type' => 'wpuf_profile',
516
+ ] );
517
 
518
+ $val = get_option( 'wpuf_profile', [] );
519
 
520
+ if ( class_exists( 'WP_User_Frontend_Pro' ) ) {
521
+ ?>
522
 
523
  <p style="padding-left: 10px; font-style: italic; font-size: 13px;">
524
+ <strong><?php esc_html_e( 'Select profile/registration forms for user roles. These forms will be used to populate extra edit profile fields in backend.', 'wp-user-frontend' ); ?></strong>
525
  </p>
526
  <table class="form-table">
527
  <?php
528
+ foreach ( $user_roles as $role => $name ) {
529
+ $current = isset( $val['roles'][$role] ) ? $val['roles'][$role] : ''; ?>
 
530
  <tr valign="top">
531
+ <th scrope="row"><?php echo esc_attr( $name ); ?></th>
532
  <td>
533
+ <select name="wpuf_profile[roles][<?php echo esc_attr( $role ); ?>]">
534
+ <option value=""><?php esc_html_e( ' - select - ', 'wp-user-frontend' ); ?></option>
535
+ <?php foreach ( $forms as $form ) { ?>
536
+ <option value="<?php echo esc_attr( $form->ID ); ?>"<?php selected( $current, $form->ID ); ?>><?php echo esc_html( $form->post_title ); ?></option>
537
  <?php } ?>
538
  </select>
539
  </td>
540
  </tr>
541
+ <?php
542
+ } ?>
543
  </table>
544
  <?php
545
  }
admin/subscribers.php CHANGED
@@ -1,21 +1,21 @@
1
  <?php
2
  $option = 'per_page';
3
- $args = array(
4
  'label' => __( 'Number of subscribers per page:', 'wp-user-frontend' ),
5
  'default' => 20,
6
- 'option' => 'subscribers_per_page'
7
- );
8
 
9
  add_screen_option( $option, $args );
10
 
11
- if ( ! class_exists( 'WPUF_List_Table_Subscribers' ) ) {
12
  require_once WPUF_ROOT . '/includes/class-list-table-subscribers.php';
13
  }
14
 
15
  $this->subscribers_list_table_obj = new WPUF_List_Table_Subscribers();
16
  ?>
17
  <div class="wrap">
18
- <h2><?php _e( 'Subscribers', 'wp-user-frontend' ); ?></h2>
19
 
20
  <form method="post">
21
  <input type="hidden" name="page" value="subscribers">
1
  <?php
2
  $option = 'per_page';
3
+ $args = [
4
  'label' => __( 'Number of subscribers per page:', 'wp-user-frontend' ),
5
  'default' => 20,
6
+ 'option' => 'subscribers_per_page',
7
+ ];
8
 
9
  add_screen_option( $option, $args );
10
 
11
+ if ( !class_exists( 'WPUF_List_Table_Subscribers' ) ) {
12
  require_once WPUF_ROOT . '/includes/class-list-table-subscribers.php';
13
  }
14
 
15
  $this->subscribers_list_table_obj = new WPUF_List_Table_Subscribers();
16
  ?>
17
  <div class="wrap">
18
+ <h2><?php esc_html_e( 'Subscribers', 'wp-user-frontend' ); ?></h2>
19
 
20
  <form method="post">
21
  <input type="hidden" name="page" value="subscribers">
admin/template-post.php CHANGED
@@ -1,13 +1,10 @@
1
  <?php
2
  /**
3
  * Post related form templates
4
- *
5
- * @package WP User Frontend
6
  */
7
  class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
8
 
9
- public static function post_title( $field_id, $label, $values = array() ) {
10
-
11
  ?>
12
  <li class="post_title">
13
  <?php self::legend( $label, $values, $field_id ); ?>
@@ -23,11 +20,9 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
23
  <?php
24
  }
25
 
26
- public static function post_content( $field_id, $label, $values = array() ) {
27
-
28
  $image_insert_name = sprintf( '%s[%d][insert_image]', self::$input_name, $field_id );
29
- $image_insert_value = isset( $values['insert_image'] ) ? $values['insert_image'] : 'yes';
30
- ?>
31
  <li class="post_content">
32
  <?php self::legend( $label, $values, $field_id ); ?>
33
  <?php self::hidden_field( "[$field_id][input_type]", 'textarea' ); ?>
@@ -38,13 +33,13 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
38
  <?php self::common_textarea( $field_id, $values ); ?>
39
 
40
  <div class="wpuf-form-rows">
41
- <label><?php _e( 'Enable Image Insertion', 'wp-user-frontend' ); ?></label>
42
 
43
  <div class="wpuf-form-sub-fields">
44
  <label>
45
  <?php self::hidden_field( "[$field_id][insert_image]", 'no' ); ?>
46
- <input type="checkbox" name="<?php echo $image_insert_name ?>" value="yes"<?php checked( $image_insert_value, 'yes' ); ?> />
47
- <?php _e( 'Enable image upload in post area', 'wp-user-frontend' ); ?>
48
  </label>
49
  </div>
50
  </div> <!-- .wpuf-form-rows -->
@@ -55,7 +50,7 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
55
  <?php
56
  }
57
 
58
- public static function post_excerpt( $field_id, $label, $values = array() ) {
59
  ?>
60
  <li class="post_excerpt">
61
  <?php self::legend( $label, $values, $field_id ); ?>
@@ -71,7 +66,7 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
71
  <?php
72
  }
73
 
74
- public static function post_tags( $field_id, $label, $values = array() ) {
75
  ?>
76
  <li class="post_tags">
77
  <?php self::legend( $label, $values, $field_id ); ?>
@@ -87,11 +82,10 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
87
  <?php
88
  }
89
 
90
- public static function featured_image( $field_id, $label, $values = array() ) {
91
- $max_file_name = sprintf( '%s[%d][max_size]', self::$input_name, $field_id );
92
  $max_file_value = $values ? $values['max_size'] : '1024';
93
- $help = esc_attr( __( 'Enter maximum upload size limit in KB', 'wp-user-frontend' ) );
94
- ?>
95
  <li class="featured_image">
96
  <?php self::legend( $label, $values, $field_id ); ?>
97
  <?php self::hidden_field( "[$field_id][input_type]", 'image_upload' ); ?>
@@ -102,8 +96,8 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
102
  <?php self::common( $field_id, 'featured_image', false, $values ); ?>
103
 
104
  <div class="wpuf-form-rows">
105
- <label><?php _e( 'Max. file size', 'wp-user-frontend' ); ?></label>
106
- <input type="text" class="smallipopInput" name="<?php echo $max_file_name; ?>" value="<?php echo $max_file_value; ?>" title="<?php echo $help; ?>">
107
  </div> <!-- .wpuf-form-rows -->
108
  <?php self::conditional_field( $field_id, $values ); ?>
109
  </div> <!-- .wpuf-form-holder -->
@@ -111,7 +105,7 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
111
  <?php
112
  }
113
 
114
- public static function post_category( $field_id, $label, $values = array() ) {
115
  ?>
116
  <li class="post_category">
117
  <?php self::legend( $label, $values, $field_id ); ?>
@@ -125,7 +119,7 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
125
  <?php
126
  }
127
 
128
- public static function taxonomy( $field_id, $label, $taxonomy = '', $values = array() ) {
129
  $type_name = sprintf( '%s[%d][type]', self::$input_name, $field_id );
130
  $order_name = sprintf( '%s[%d][order]', self::$input_name, $field_id );
131
  $orderby_name = sprintf( '%s[%d][orderby]', self::$input_name, $field_id );
@@ -140,9 +134,8 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
140
  $exclude_type_value = $values ? esc_attr( $values['exclude_type'] ) : 'exclude';
141
  $exclude_value = $values ? esc_attr( $values['exclude'] ) : '';
142
  $woo_attr_value = $values ? esc_attr( $values['woo_attr'] ) : 'no';
143
- $woo_attr_vis_value = $values ? esc_attr( $values['woo_attr_vis'] ) : 'no';
144
- ?>
145
- <li class="taxonomy <?php echo $taxonomy; ?> wpuf-conditional">
146
  <?php self::legend( $label, $values, $field_id ); ?>
147
  <?php self::hidden_field( "[$field_id][input_type]", 'taxonomy' ); ?>
148
  <?php self::hidden_field( "[$field_id][template]", 'taxonomy' ); ?>
@@ -151,69 +144,69 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
151
  <?php self::common( $field_id, $taxonomy, false, $values ); ?>
152
 
153
  <div class="wpuf-form-rows">
154
- <label><?php _e( 'Type', 'wp-user-frontend' ); ?></label>
155
- <select name="<?php echo $type_name ?>">
156
- <option value="select"<?php selected( $type_value, 'select' ); ?>><?php _e( 'Dropdown', 'wp-user-frontend' ); ?></option>
157
- <option value="multiselect"<?php selected( $type_value, 'multiselect' ); ?>><?php _e( 'Multi Select', 'wp-user-frontend' ); ?></option>
158
- <option value="checkbox"<?php selected( $type_value, 'checkbox' ); ?>><?php _e( 'Checkbox', 'wp-user-frontend' ); ?></option>
159
- <option value="text"<?php selected( $type_value, 'text' ); ?>><?php _e( 'Text Input', 'wp-user-frontend' ); ?></option>
160
- <option value="ajax"<?php selected( $type_value, 'ajax' ); ?>><?php _e( 'Ajax', 'wp-user-frontend' ); ?></option>
161
  </select>
162
  </div> <!-- .wpuf-form-rows -->
163
 
164
  <div class="wpuf-form-rows">
165
- <label><?php _e( 'Order By', 'wp-user-frontend' ); ?></label>
166
- <select name="<?php echo $orderby_name ?>">
167
- <option value="name"<?php selected( $orderby_value, 'name' ); ?>><?php _e( 'Name', 'wp-user-frontend' ); ?></option>
168
- <option value="id"<?php selected( $orderby_value, 'id' ); ?>><?php _e( 'Term ID', 'wp-user-frontend' ); ?></option>
169
- <option value="slug"<?php selected( $orderby_value, 'slug' ); ?>><?php _e( 'Slug', 'wp-user-frontend' ); ?></option>
170
- <option value="count"<?php selected( $orderby_value, 'count' ); ?>><?php _e( 'Count', 'wp-user-frontend' ); ?></option>
171
- <option value="term_group"<?php selected( $orderby_value, 'term_group' ); ?>><?php _e( 'Term Group', 'wp-user-frontend' ); ?></option>
172
  </select>
173
  </div> <!-- .wpuf-form-rows -->
174
 
175
  <div class="wpuf-form-rows">
176
- <label><?php _e( 'Order', 'wp-user-frontend' ); ?></label>
177
- <select name="<?php echo $order_name ?>">
178
- <option value="ASC"<?php selected( $order_value, 'ASC' ); ?>><?php _e( 'ASC', 'wp-user-frontend' ); ?></option>
179
- <option value="DESC"<?php selected( $order_value, 'DESC' ); ?>><?php _e( 'DESC', 'wp-user-frontend' ); ?></option>
180
  </select>
181
  </div> <!-- .wpuf-form-rows -->
182
 
183
  <div class="wpuf-form-rows">
184
- <label><?php _e( 'Selection Type', 'wp-user-frontend' ); ?></label>
185
- <select name="<?php echo $exclude_type_name ?>">
186
- <option value="exclude"<?php selected( $exclude_type_value, 'exclude' ); ?>><?php _e( 'Exclude', 'wp-user-frontend' ); ?></option>
187
- <option value="include"<?php selected( $exclude_type_value, 'include' ); ?>><?php _e( 'Include', 'wp-user-frontend' ); ?></option>
188
- <option value="child_of"<?php selected( $exclude_type_value, 'child_of' ); ?>><?php _e( 'Child of', 'wp-user-frontend' ); ?></option>
189
  </select>
190
  </div> <!-- .wpuf-form-rows -->
191
 
192
  <div class="wpuf-form-rows">
193
- <label><?php _e( 'Selection terms', 'wp-user-frontend' ); ?></label>
194
- <input type="text" class="smallipopInput" name="<?php echo $exclude_name; ?>" title="<?php _e( 'Search the terms name.', 'wp-user-frontend' ); ?>" value="<?php echo $exclude_value; ?>" />
195
  </div> <!-- .wpuf-form-rows -->
196
 
197
  <div class="wpuf-form-rows">
198
- <label><?php _e( 'WooCommerce Attribute', 'wp-user-frontend' ); ?></label>
199
 
200
  <div class="wpuf-form-sub-fields">
201
  <label>
202
  <?php self::hidden_field( "[$field_id][woo_attr]", 'no' ); ?>
203
- <input type="checkbox" class="woo_attr" name="<?php echo $woo_attr_name ?>" value="yes"<?php checked( $woo_attr_value, 'yes' ); ?> />
204
- <?php _e( 'This taxonomy is a WooCommerce attribute', 'wp-user-frontend' ); ?>
205
  </label>
206
  </div>
207
  </div> <!-- .wpuf-form-rows -->
208
 
209
  <div class="wpuf-form-rows<?php echo $woo_attr_value == 'no' ? ' wpuf-hide' : ''; ?>">
210
- <label><?php _e( 'Visibility', 'wp-user-frontend' ); ?></label>
211
 
212
  <div class="wpuf-form-sub-fields">
213
  <label>
214
  <?php self::hidden_field( "[$field_id][woo_attr_vis]", 'no' ); ?>
215
- <input type="checkbox" name="<?php echo $woo_attr_vis_name ?>" value="yes"<?php checked( $woo_attr_vis_value, 'yes' ); ?> />
216
- <?php _e( 'Visible on product page', 'wp-user-frontend' ); ?>
217
  </label>
218
  </div>
219
  </div> <!-- .wpuf-form-rows -->
@@ -222,58 +215,55 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
222
  <div class="wpuf-options">
223
  <?php
224
 
225
- $tax = get_terms( $taxonomy, array(
226
  'orderby' => 'count',
227
- 'hide_empty' => 0
228
- ) );
229
 
230
- $tax = is_array( $tax ) ? $tax : array();
231
 
232
- foreach($tax as $tax_obj) {
233
- ?>
234
  <div>
235
- <input type="hidden" value="<?php echo $tax_obj->name;?>" data-taxonomy="yes" data-term-id="<?php echo $tax_obj->term_id;?>" data-type="option">
236
- <input type="hidden" value="<?php echo $tax_obj->term_id;?>" data-taxonomy="yes" data-term-id="<?php echo $tax_obj->term_id;?>" data-type="option_value">
237
  </div>
238
  <?php
239
- }
240
- ?>
241
  </div>
242
  </div> <!-- .wpuf-form-holder -->
243
  </li>
244
  <?php
245
  }
246
 
247
-
248
  /**
249
  * Drop Down portion
 
250
  * @param array $param
251
  */
252
- public static function render_drop_down_portion( $param = array( 'names_to_hide' => array( 'name' => '', 'value' => '' ),'names_to_show' => array( 'name' => '', 'value' => '' ),'option_to_chose' => array('name' => '', 'value' => '' ) ) ) {
253
- empty( $param['option_to_chose']['value'] ) ? ( $param['option_to_chose']['value'] = 'all' ) : '';
254
-
255
- ?>
256
  <div class="wpuf-form-rows">
257
- <label><input type="radio" name="<?php echo $param['option_to_chose']['name'] ?>" value="<?php echo _e('all','wp-user-frontend'); ?>" <?php echo ( ( $param['option_to_chose']['value'] == 'all' )?'checked':'' ); ?> /><?php _e( 'Show All', 'wp-user-frontend' ); ?></label>
258
  </div>
259
  <div class="wpuf-form-rows">
260
- <label><input type="radio" name="<?php echo $param['option_to_chose']['name'] ?>" value="<?php echo _e('hide','wp-user-frontend'); ?>" <?php echo ( ( $param['option_to_chose']['value'] == 'hide' )?'checked':'' ); ?> /><?php _e( 'Hide These Countries', 'wp-user-frontend' ); ?></label>
261
- <select name="<?php echo $param['names_to_hide']['name'];?>" class="wpuf-country_to_hide" multiple data-placeholder="<?php esc_attr_e( 'Chose Country to hide from List', 'wp-user-frontend' ); ?>"></select>
262
  </div>
263
 
264
  <div class="wpuf-form-rows">
265
- <label><input type="radio" name="<?php echo $param['option_to_chose']['name'] ?>" value="<?php echo _e('show','wp-user-frontend'); ?>" <?php echo ( ( $param['option_to_chose']['value'] == 'show' )?'checked':'' ); ?> /><?php _e( 'Show These Countries', 'wp-user-frontend' ); ?></label>
266
- <select name="<?php echo $param['names_to_show']['name'];?>" class="wpuf-country_to_hide" multiple data-placeholder="<?php esc_attr_e( 'Add Country to List', 'wp-user-frontend' ); ?>"></select>
267
  </div>
268
 
269
  <script>
270
  (function($){
271
  $(document).ready(function(){
272
- var hide_field_name = '<?php echo $param['names_to_hide']['name'];?>';
273
- var hide_field_value = JSON.parse('<?php echo json_encode($param['names_to_hide']['value']);?>');
274
- var show_field_name = '<?php echo $param['names_to_show']['name'];?>';
275
- var show_field_value = JSON.parse('<?php echo json_encode($param['names_to_show']['value']);?>');
276
- var countries = <?php echo wpuf_get_countries( 'json' ); ?>;
277
  var hide_field_option_string = '';
278
  var show_field_option_string = '';
279
 
@@ -292,5 +282,4 @@ class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
292
  </script>
293
  <?php
294
  }
295
-
296
  }
1
  <?php
2
  /**
3
  * Post related form templates
 
 
4
  */
5
  class WPUF_Admin_Template_Post extends WPUF_Admin_Template {
6
 
7
+ public static function post_title( $field_id, $label, $values = [] ) {
 
8
  ?>
9
  <li class="post_title">
10
  <?php self::legend( $label, $values, $field_id ); ?>
20
  <?php
21
  }
22
 
23
+ public static function post_content( $field_id, $label, $values = [] ) {
 
24
  $image_insert_name = sprintf( '%s[%d][insert_image]', self::$input_name, $field_id );
25
+ $image_insert_value = isset( $values['insert_image'] ) ? $values['insert_image'] : 'yes'; ?>
 
26
  <li class="post_content">
27
  <?php self::legend( $label, $values, $field_id ); ?>
28
  <?php self::hidden_field( "[$field_id][input_type]", 'textarea' ); ?>
33
  <?php self::common_textarea( $field_id, $values ); ?>
34
 
35
  <div class="wpuf-form-rows">
36
+ <label><?php esc_html_e( 'Enable Image Insertion', 'wp-user-frontend' ); ?></label>
37
 
38
  <div class="wpuf-form-sub-fields">
39
  <label>
40
  <?php self::hidden_field( "[$field_id][insert_image]", 'no' ); ?>
41
+ <input type="checkbox" name="<?php echo esc_attr( $image_insert_name ); ?>" value="yes"<?php checked( $image_insert_value, 'yes' ); ?> />
42
+ <?php esc_html_e( 'Enable image upload in post area', 'wp-user-frontend' ); ?>
43
  </label>
44
  </div>
45
  </div> <!-- .wpuf-form-rows -->
50
  <?php
51
  }
52
 
53
+ public static function post_excerpt( $field_id, $label, $values = [] ) {
54
  ?>
55
  <li class="post_excerpt">
56
  <?php self::legend( $label, $values, $field_id ); ?>
66
  <?php
67
  }
68
 
69
+ public static function post_tags( $field_id, $label, $values = [] ) {
70
  ?>
71
  <li class="post_tags">
72
  <?php self::legend( $label, $values, $field_id ); ?>
82
  <?php
83
  }
84
 
85
+ public static function featured_image( $field_id, $label, $values = [] ) {
86
+ $max_file_name = sprintf( '%s[%d][max_size]', self::$input_name, $field_id );
87
  $max_file_value = $values ? $values['max_size'] : '1024';
88
+ $help = esc_attr( __( 'Enter maximum upload size limit in KB', 'wp-user-frontend' ) ); ?>
 
89
  <li class="featured_image">
90
  <?php self::legend( $label, $values, $field_id ); ?>
91
  <?php self::hidden_field( "[$field_id][input_type]", 'image_upload' ); ?>
96
  <?php self::common( $field_id, 'featured_image', false, $values ); ?>
97
 
98
  <div class="wpuf-form-rows">
99
+ <label><?php esc_html_e( 'Max. file size', 'wp-user-frontend' ); ?></label>
100
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $max_file_name ); ?>" value="<?php echo esc_attr( $max_file_value ); ?>" title="<?php echo esc_attr( $help ); ?>">
101
  </div> <!-- .wpuf-form-rows -->
102
  <?php self::conditional_field( $field_id, $values ); ?>
103
  </div> <!-- .wpuf-form-holder -->
105
  <?php
106
  }
107
 
108
+ public static function post_category( $field_id, $label, $values = [] ) {
109
  ?>
110
  <li class="post_category">
111
  <?php self::legend( $label, $values, $field_id ); ?>
119
  <?php
120
  }
121
 
122
+ public static function taxonomy( $field_id, $label, $taxonomy = '', $values = [] ) {
123
  $type_name = sprintf( '%s[%d][type]', self::$input_name, $field_id );
124
  $order_name = sprintf( '%s[%d][order]', self::$input_name, $field_id );
125
  $orderby_name = sprintf( '%s[%d][orderby]', self::$input_name, $field_id );
134
  $exclude_type_value = $values ? esc_attr( $values['exclude_type'] ) : 'exclude';
135
  $exclude_value = $values ? esc_attr( $values['exclude'] ) : '';
136
  $woo_attr_value = $values ? esc_attr( $values['woo_attr'] ) : 'no';
137
+ $woo_attr_vis_value = $values ? esc_attr( $values['woo_attr_vis'] ) : 'no'; ?>
138
+ <li class="taxonomy <?php echo esc_attr( $taxonomy ); ?> wpuf-conditional">
 
139
  <?php self::legend( $label, $values, $field_id ); ?>
140
  <?php self::hidden_field( "[$field_id][input_type]", 'taxonomy' ); ?>
141
  <?php self::hidden_field( "[$field_id][template]", 'taxonomy' ); ?>
144
  <?php self::common( $field_id, $taxonomy, false, $values ); ?>
145
 
146
  <div class="wpuf-form-rows">
147
+ <label><?php esc_html_e( 'Type', 'wp-user-frontend' ); ?></label>
148
+ <select name="<?php echo esc_attr( $type_name ); ?>">
149
+ <option value="select"<?php selected( $type_value, 'select' ); ?>><?php esc_html_e( 'Dropdown', 'wp-user-frontend' ); ?></option>
150
+ <option value="multiselect"<?php selected( $type_value, 'multiselect' ); ?>><?php esc_html_e( 'Multi Select', 'wp-user-frontend' ); ?></option>
151
+ <option value="checkbox"<?php selected( $type_value, 'checkbox' ); ?>><?php esc_html_e( 'Checkbox', 'wp-user-frontend' ); ?></option>
152
+ <option value="text"<?php selected( $type_value, 'text' ); ?>><?php esc_html_e( 'Text Input', 'wp-user-frontend' ); ?></option>
153
+ <option value="ajax"<?php selected( $type_value, 'ajax' ); ?>><?php esc_html_e( 'Ajax', 'wp-user-frontend' ); ?></option>
154
  </select>
155
  </div> <!-- .wpuf-form-rows -->
156
 
157
  <div class="wpuf-form-rows">
158
+ <label><?php esc_html_e( 'Order By', 'wp-user-frontend' ); ?></label>
159
+ <select name="<?php echo esc_attr( $orderby_name ); ?>">
160
+ <option value="name"<?php selected( $orderby_value, 'name' ); ?>><?php esc_html_e( 'Name', 'wp-user-frontend' ); ?></option>
161
+ <option value="id"<?php selected( $orderby_value, 'id' ); ?>><?php esc_html_e( 'Term ID', 'wp-user-frontend' ); ?></option>
162
+ <option value="slug"<?php selected( $orderby_value, 'slug' ); ?>><?php esc_html_e( 'Slug', 'wp-user-frontend' ); ?></option>
163
+ <option value="count"<?php selected( $orderby_value, 'count' ); ?>><?php esc_html_e( 'Count', 'wp-user-frontend' ); ?></option>
164
+ <option value="term_group"<?php selected( $orderby_value, 'term_group' ); ?>><?php esc_html_e( 'Term Group', 'wp-user-frontend' ); ?></option>
165
  </select>
166
  </div> <!-- .wpuf-form-rows -->
167
 
168
  <div class="wpuf-form-rows">
169
+ <label><?php esc_html_e( 'Order', 'wp-user-frontend' ); ?></label>
170
+ <select name="<?php echo esc_attr( $order_name ); ?>">
171
+ <option value="ASC"<?php selected( $order_value, 'ASC' ); ?>><?php esc_html_e( 'ASC', 'wp-user-frontend' ); ?></option>
172
+ <option value="DESC"<?php selected( $order_value, 'DESC' ); ?>><?php esc_html_e( 'DESC', 'wp-user-frontend' ); ?></option>
173
  </select>
174
  </div> <!-- .wpuf-form-rows -->
175
 
176
  <div class="wpuf-form-rows">
177
+ <label><?php esc_html_e( 'Selection Type', 'wp-user-frontend' ); ?></label>
178
+ <select name="<?php echo esc_attr( $exclude_type_name ); ?>">
179
+ <option value="exclude"<?php selected( $exclude_type_value, 'exclude' ); ?>><?php esc_html_e( 'Exclude', 'wp-user-frontend' ); ?></option>
180
+ <option value="include"<?php selected( $exclude_type_value, 'include' ); ?>><?php esc_html_e( 'Include', 'wp-user-frontend' ); ?></option>
181
+ <option value="child_of"<?php selected( $exclude_type_value, 'child_of' ); ?>><?php esc_html_e( 'Child of', 'wp-user-frontend' ); ?></option>
182
  </select>
183
  </div> <!-- .wpuf-form-rows -->
184
 
185
  <div class="wpuf-form-rows">
186
+ <label><?php esc_html_e( 'Selection terms', 'wp-user-frontend' ); ?></label>
187
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $exclude_name ); ?>" title="<?php esc_html_e( 'Search the terms name.', 'wp-user-frontend' ); ?>" value="<?php echo esc_attr( $exclude_value ); ?>" />
188
  </div> <!-- .wpuf-form-rows -->
189
 
190
  <div class="wpuf-form-rows">
191
+ <label><?php esc_html_e( 'WooCommerce Attribute', 'wp-user-frontend' ); ?></label>
192
 
193
  <div class="wpuf-form-sub-fields">
194
  <label>
195
  <?php self::hidden_field( "[$field_id][woo_attr]", 'no' ); ?>
196
+ <input type="checkbox" class="woo_attr" name="<?php echo esc_attr( $woo_attr_name ); ?>" value="yes"<?php checked( $woo_attr_value, 'yes' ); ?> />
197
+ <?php esc_html_e( 'This taxonomy is a WooCommerce attribute', 'wp-user-frontend' ); ?>
198
  </label>
199
  </div>
200
  </div> <!-- .wpuf-form-rows -->
201
 
202
  <div class="wpuf-form-rows<?php echo $woo_attr_value == 'no' ? ' wpuf-hide' : ''; ?>">
203
+ <label><?php esc_html_e( 'Visibility', 'wp-user-frontend' ); ?></label>
204
 
205
  <div class="wpuf-form-sub-fields">
206
  <label>
207
  <?php self::hidden_field( "[$field_id][woo_attr_vis]", 'no' ); ?>
208
+ <input type="checkbox" name="<?php echo esc_attr( $woo_attr_vis_name ); ?>" value="yes"<?php checked( $woo_attr_vis_value, 'yes' ); ?> />
209
+ <?php esc_html_e( 'Visible on product page', 'wp-user-frontend' ); ?>
210
  </label>
211
  </div>
212
  </div> <!-- .wpuf-form-rows -->
215
  <div class="wpuf-options">
216
  <?php
217
 
218
+ $tax = get_terms( $taxonomy, [
219
  'orderby' => 'count',
220
+ 'hide_empty' => 0,
221
+ ] );
222
 
223
+ $tax = is_array( $tax ) ? $tax : [];
224
 
225
+ foreach ( $tax as $tax_obj ) {
226
+ ?>
227
  <div>
228
+ <input type="hidden" value="<?php echo esc_attr( $tax_obj->name ); ?>" data-taxonomy="yes" data-term-id="<?php echo esc_attr( $tax_obj->term_id ); ?>" data-type="option">
229
+ <input type="hidden" value="<?php echo esc_attr( $tax_obj->term_id ); ?>" data-taxonomy="yes" data-term-id="<?php echo esc_attr( $tax_obj->term_id ); ?>" data-type="option_value">
230
  </div>
231
  <?php
232
+ } ?>
 
233
  </div>
234
  </div> <!-- .wpuf-form-holder -->
235
  </li>
236
  <?php
237
  }
238
 
 
239
  /**
240
  * Drop Down portion
241
+ *
242
  * @param array $param
243
  */
244
+ public static function render_drop_down_portion( $param = [ 'names_to_hide' => [ 'name' => '', 'value' => '' ], 'names_to_show' => [ 'name' => '', 'value' => '' ], 'option_to_chose' => ['name' => '', 'value' => '' ] ] ) {
245
+ empty( $param['option_to_chose']['value'] ) ? ( $param['option_to_chose']['value'] = 'all' ) : ''; ?>
 
 
246
  <div class="wpuf-form-rows">
247
+ <label><input type="radio" name="<?php echo esc_attr( $param['option_to_chose']['name'] ); ?>" value="<?php esc_html_e( 'all', 'wp-user-frontend' ); ?>" <?php echo ( $param['option_to_chose']['value'] == 'all' ) ? 'checked' : ''; ?> /><?php esc_html_e( 'Show All', 'wp-user-frontend' ); ?></label>
248
  </div>
249
  <div class="wpuf-form-rows">
250
+ <label><input type="radio" name="<?php echo esc_attr( $param['option_to_chose']['name'] ); ?>" value="<?php esc_html_e( 'hide', 'wp-user-frontend' ); ?>" <?php echo ( $param['option_to_chose']['value'] == 'hide' ) ? 'checked' : ''; ?> /><?php esc_html_e( 'Hide These Countries', 'wp-user-frontend' ); ?></label>
251
+ <select name="<?php echo esc_attr( $param['names_to_hide']['name'] ); ?>" class="wpuf-country_to_hide" multiple data-placeholder="<?php esc_attr_e( 'Chose Country to hide from List', 'wp-user-frontend' ); ?>"></select>
252
  </div>
253
 
254
  <div class="wpuf-form-rows">
255
+ <label><input type="radio" name="<?php echo esc_attr( $param['option_to_chose']['name'] ); ?>" value="<?php esc_html_e( 'show', 'wp-user-frontend' ); ?>" <?php echo ( $param['option_to_chose']['value'] == 'show' ) ? 'checked' : ''; ?> /><?php esc_html_e( 'Show These Countries', 'wp-user-frontend' ); ?></label>
256
+ <select name="<?php echo esc_attr( $param['names_to_show']['name'] ); ?>" class="wpuf-country_to_hide" multiple data-placeholder="<?php esc_attr_e( 'Add Country to List', 'wp-user-frontend' ); ?>"></select>
257
  </div>
258
 
259
  <script>
260
  (function($){
261
  $(document).ready(function(){
262
+ var hide_field_name = '<?php echo esc_attr( $param['names_to_hide']['name'] ); ?>';
263
+ var hide_field_value = JSON.parse('<?php echo json_encode( $param['names_to_hide']['value'] ); ?>');
264
+ var show_field_name = '<?php echo esc_attr( $param['names_to_show']['name'] ); ?>';
265
+ var show_field_value = JSON.parse('<?php echo esc_attr( json_encode( $param['names_to_show']['value'] ) ); ?>');
266
+ var countries = <?php echo esc_attr( wpuf_get_countries( 'json' ) ); ?>;
267
  var hide_field_option_string = '';
268
  var show_field_option_string = '';
269
 
282
  </script>
283
  <?php
284
  }
 
285
  }
admin/template.php CHANGED
@@ -1,713 +1,685 @@
1
- <?php
2
-
3
- /**
4
- * WPUF Form builder template
5
- *
6
- * @package WP User Frontend
7
- * @author Tareq Hasan <tareq@wedevs.com>
8
- */
9
- class WPUF_Admin_Template {
10
-
11
- static $input_name = 'wpuf_input';
12
- static $cond_name = 'wpuf_cond';
13
-
14
- /**
15
- * Legend of a form item
16
- *
17
- * @param string $title
18
- * @param array $values
19
- */
20
- public static function legend( $title = 'Field Name', $values = array(), $field_id = 0 ) {
21
-
22
- $field_label = $values ? ': <strong>' . $values['label'] . '</strong>' : '';
23
- $id = isset( $values['id'] ) ? $values['id'] : '';
24
- ?>
25
- <div class="wpuf-legend" title="<?php _e( 'Click and Drag to rearrange', 'wp-user-frontend' ); ?>">
26
- <input type="hidden" value="<?php echo $id; ?>" name="wpuf_input[<?php echo $field_id; ?>][id]">
27
- <div class="wpuf-label"><?php echo $title . $field_label; ?></div>
28
- <div class="wpuf-actions">
29
- <a href="#" class="wpuf-remove"><?php _e( 'Remove', 'wp-user-frontend' ); ?></a>
30
- <a href="#" class="wpuf-toggle"><?php _e( 'Toggle', 'wp-user-frontend' ); ?></a>
31
- </div>
32
- </div> <!-- .wpuf-legend -->
33
- <?php
34
- }
35
-
36
- /**
37
- * Common Fields for a input field
38
- *
39
- * Contains required, label, meta_key, help text, css class name
40
- *
41
- * @param int $id field order
42
- * @param mixed $field_name_value
43
- * @param bool $custom_field if it a custom field or not
44
- * @param array $values saved value
45
- */
46
- public static function common( $id, $field_name_value = '', $custom_field = true, $values = array() ) {
47
-
48
- $tpl = '%s[%d][%s]';
49
- $required_name = sprintf( $tpl, self::$input_name, $id, 'required' );
50
- $field_name = sprintf( $tpl, self::$input_name, $id, 'name' );
51
- $label_name = sprintf( $tpl, self::$input_name, $id, 'label' );
52
- $is_meta_name = sprintf( $tpl, self::$input_name, $id, 'is_meta' );
53
- $help_name = sprintf( $tpl, self::$input_name, $id, 'help' );
54
- $css_name = sprintf( $tpl, self::$input_name, $id, 'css' );
55
-
56
- // $field_name_value = $field_name_value ?
57
- $required = $values ? esc_attr( $values['required'] ) : 'yes';
58
- $label_value = $values ? esc_attr( $values['label'] ) : '';
59
- $help_value = $values ? stripslashes( $values['help'] ) : '';
60
- $css_value = $values ? esc_attr( $values['css'] ) : '';
61
-
62
- if ( $custom_field && $values ) {
63
- $field_name_value = $values['name'];
64
- }
65
- ?>
66
- <div class="wpuf-form-rows required-field">
67
- <label><?php _e( 'Required', 'wp-user-frontend' ); ?></label>
68
-
69
- <div class="wpuf-form-sub-fields">
70
- <label><input type="radio" name="<?php echo $required_name; ?>" value="yes"<?php checked( $required, 'yes' ); ?>> <?php _e( 'Yes', 'wp-user-frontend' ); ?> </label>
71
- <label><input type="radio" name="<?php echo $required_name; ?>" value="no"<?php checked( $required, 'no' ); ?>> <?php _e( 'No', 'wp-user-frontend' ); ?> </label>
72
- </div>
73
- </div> <!-- .wpuf-form-rows -->
74
-
75
- <div class="wpuf-form-rows">
76
- <label><?php _e( 'Field Label', 'wp-user-frontend' ); ?></label>
77
- <input type="text" data-type="label" name="<?php echo $label_name; ?>" value="<?php echo $label_value; ?>" class="smallipopInput" title="<?php _e( 'Enter a title of this field', 'wp-user-frontend' ); ?>">
78
- </div> <!-- .wpuf-form-rows -->
79
-
80
- <?php if ( $custom_field ) { ?>
81
- <div class="wpuf-form-rows">
82
- <label><?php _e( 'Meta Key', 'wp-user-frontend' ); ?></label>
83
- <input type="text" data-type="name" name="<?php echo $field_name; ?>" value="<?php echo $field_name_value; ?>" class="smallipopInput" title="<?php _e( 'Name of the meta key this field will save to', 'wp-user-frontend' ); ?>">
84
- <input type="hidden" name="<?php echo $is_meta_name; ?>" value="yes">
85
- </div> <!-- .wpuf-form-rows -->
86
- <?php } else { ?>
87
-
88
- <input type="hidden" data-type="name" name="<?php echo $field_name; ?>" value="<?php echo $field_name_value; ?>">
89
- <input type="hidden" name="<?php echo $is_meta_name; ?>" value="no">
90
-
91
- <?php } ?>
92
-
93
- <div class="wpuf-form-rows">
94
- <label><?php _e( 'Help text', 'wp-user-frontend' ); ?></label>
95
- <textarea name="<?php echo $help_name; ?>" class="smallipopInput" title="<?php _e( 'Give the user some information about this field', 'wp-user-frontend' ); ?>"><?php echo $help_value; ?></textarea>
96
- </div> <!-- .wpuf-form-rows -->
97
-
98
- <div class="wpuf-form-rows">
99
- <label><?php _e( 'CSS Class Name', 'wp-user-frontend' ); ?></label>
100
- <input type="text" name="<?php echo $css_name; ?>" value="<?php echo $css_value; ?>" class="smallipopInput" title="<?php _e( 'Add a CSS class name for this field', 'wp-user-frontend' ); ?>">
101
- </div> <!-- .wpuf-form-rows -->
102
-
103
- <?php
104
- }
105
-
106
- /**
107
- * Common fields for a text area
108
- *
109
- * @param int $id
110
- * @param array $values
111
- */
112
- public static function common_text( $id, $values = array() ) {
113
- $tpl = '%s[%d][%s]';
114
- $placeholder_name = sprintf( $tpl, self::$input_name, $id, 'placeholder' );
115
- $default_name = sprintf( $tpl, self::$input_name, $id, 'default' );
116
- $size_name = sprintf( $tpl, self::$input_name, $id, 'size' );
117
- $word_restriction_name = sprintf( $tpl, self::$input_name, $id, 'word_restriction' );
118
-
119
- $placeholder_value = $values ? esc_attr( $values['placeholder'] ) : '';
120
- $default_value = $values ? esc_attr( $values['default'] ) : '';
121
- $size_value = $values ? esc_attr( $values['size'] ) : '40';
122
- $word_restriction_value = $values ? esc_attr( $values['word_restriction'] ) : '';
123
-
124
- ?>
125
- <div class="wpuf-form-rows">
126
- <label><?php _e( 'Placeholder text', 'wp-user-frontend' ); ?></label>
127
- <input type="text" class="smallipopInput" name="<?php echo $placeholder_name; ?>" title="<?php esc_attr_e( 'Text for HTML5 placeholder attribute', 'wp-user-frontend' ); ?>" value="<?php echo $placeholder_value; ?>" />
128
- </div> <!-- .wpuf-form-rows -->
129
-
130
- <div class="wpuf-form-rows">
131
- <label><?php _e( 'Default value', 'wp-user-frontend' ); ?></label>
132
- <input type="text" class="smallipopInput" name="<?php echo $default_name; ?>" title="<?php esc_attr_e( 'The default value this field will have', 'wp-user-frontend' ); ?>" value="<?php echo $default_value; ?>" />
133
- </div> <!-- .wpuf-form-rows -->
134
-
135
- <div class="wpuf-form-rows">
136
- <label><?php _e( 'Size', 'wp-user-frontend' ); ?></label>
137
- <input type="text" class="smallipopInput" name="<?php echo $size_name; ?>" title="<?php esc_attr_e( 'Size of this input field', 'wp-user-frontend' ); ?>" value="<?php echo $size_value; ?>" />
138
- </div> <!-- .wpuf-form-rows -->
139
-
140
- <div class="wpuf-form-rows">
141
- <label><?php _e( 'Word Restriction', 'wp-user-frontend' ); ?></label>
142
-
143
- <div class="wpuf-form-sub-fields">
144
- <label>
145
- <input type="text" class="smallipopInput" name="<?php echo $word_restriction_name ?>" value="<?php echo $word_restriction_value; ?>" title="<?php esc_attr_e( 'Numebr of words the author to be restricted in', 'wp-user-frontend' ); ?>" />
146
- </label>
147
- </div>
148
- </div> <!-- .wpuf-form-rows -->
149
- <?php
150
- }
151
-
152
- /**
153
- * Common fields for a textarea
154
- *
155
- * @param int $id
156
- * @param array $values
157
- */
158
- public static function common_textarea( $id, $values = array() ) {
159
- $tpl = '%s[%d][%s]';
160
- $rows_name = sprintf( $tpl, self::$input_name, $id, 'rows' );
161
- $cols_name = sprintf( $tpl, self::$input_name, $id, 'cols' );
162
- $rich_name = sprintf( $tpl, self::$input_name, $id, 'rich' );
163
- $placeholder_name = sprintf( $tpl, self::$input_name, $id, 'placeholder' );
164
- $default_name = sprintf( $tpl, self::$input_name, $id, 'default' );
165
- $word_restriction_name = sprintf( $tpl, self::$input_name, $id, 'word_restriction' );
166
-
167
- $rows_value = $values ? esc_attr( $values['rows'] ) : '5';
168
- $cols_value = $values ? esc_attr( $values['cols'] ) : '25';
169
- $rich_value = $values ? esc_attr( $values['rich'] ) : 'no';
170
- $placeholder_value = $values ? esc_attr( $values['placeholder'] ) : '';
171
- $default_value = $values ? esc_attr( $values['default'] ) : '';
172
- $word_restriction_value = $values ? esc_attr( $values['word_restriction'] ) : '';
173
-
174
- ?>
175
- <div class="wpuf-form-rows">
176
- <label><?php _e( 'Rows', 'wp-user-frontend' ); ?></label>
177
- <input type="text" class="smallipopInput" name="<?php echo $rows_name; ?>" title="Number of rows in textarea" value="<?php echo $rows_value; ?>" />
178
- </div> <!-- .wpuf-form-rows -->
179
-
180
- <div class="wpuf-form-rows">
181
- <label><?php _e( 'Columns', 'wp-user-frontend' ); ?></label>
182
- <input type="text" class="smallipopInput" name="<?php echo $cols_name; ?>" title="Number of columns in textarea" value="<?php echo $cols_value; ?>" />
183
- </div> <!-- .wpuf-form-rows -->
184
-
185
- <div class="wpuf-form-rows">
186
- <label><?php _e( 'Placeholder text', 'wp-user-frontend' ); ?></label>
187
- <input type="text" class="smallipopInput" name="<?php echo $placeholder_name; ?>" title="text for HTML5 placeholder attribute" value="<?php echo $placeholder_value; ?>" />
188
- </div> <!-- .wpuf-form-rows -->
189
-
190
- <div class="wpuf-form-rows">
191
- <label><?php _e( 'Default value', 'wp-user-frontend' ); ?></label>
192
- <input type="text" class="smallipopInput" name="<?php echo $default_name; ?>" title="the default value this field will have" value="<?php echo $default_value; ?>" />
193
- </div> <!-- .wpuf-form-rows -->
194
-
195
- <div class="wpuf-form-rows">
196
- <label><?php _e( 'Textarea', 'wp-user-frontend' ); ?></label>
197
-
198
- <div class="wpuf-form-sub-fields">
199
- <label><input type="radio" name="<?php echo $rich_name; ?>" value="no"<?php checked( $rich_value, 'no' ); ?>> <?php _e( 'Normal', 'wp-user-frontend' ); ?></label>
200
- <label><input type="radio" name="<?php echo $rich_name; ?>" value="yes"<?php checked( $rich_value, 'yes' ); ?>> <?php _e( 'Rich textarea', 'wp-user-frontend' ); ?></label>
201
- <label><input type="radio" name="<?php echo $rich_name; ?>" value="teeny"<?php checked( $rich_value, 'teeny' ); ?>> <?php _e( 'Teeny Rich textarea', 'wp-user-frontend' ); ?></label>
202
- </div>
203
- </div> <!-- .wpuf-form-rows -->
204
-
205
- <div class="wpuf-form-rows">
206
- <label><?php _e( 'Word Restriction', 'wp-user-frontend' ); ?></label>
207
-
208
- <div class="wpuf-form-sub-fields">
209
- <label>
210
- <input type="text" class="smallipopInput" name="<?php echo $word_restriction_name ?>" value="<?php echo $word_restriction_value; ?>" title="<?php esc_attr_e( 'Numebr of words the author to be restricted in', 'wp-user-frontend' ); ?>" />
211
- </label>
212
- </div>
213
- </div> <!-- .wpuf-form-rows -->
214
- <?php
215
- }
216
-
217
- /**
218
- * Hidden field helper function
219
- *
220
- * @param string $name
221
- * @param string $value
222
- */
223
- public static function hidden_field( $name, $value = '' ) {
224
- printf( '<input type="hidden" name="%s" value="%s" />', self::$input_name . $name, $value );
225
- }
226
-
227
- /**
228
- * Displays a radio custom field
229
- *
230
- * @param int $field_id
231
- * @param string $name
232
- * @param array $values
233
- */
234
- public static function radio_fields( $field_id, $name, $values = array() ) {
235
-
236
- $selected_name = sprintf( '%s[%d][selected]', self::$input_name, $field_id );
237
- $input_name = sprintf( '%s[%d][%s]', self::$input_name, $field_id, $name );
238
- $input_value_name = sprintf( '%s[%d][%s]', self::$input_name, $field_id, $name.'_values' );
239
-
240
- $selected_value = ( $values && isset( $values['selected'] ) ) ? $values['selected'] : '';
241
- ?>
242
-
243
- <label for="wpuf-<?php echo $name.'_'.$field_id; ?>" class="wpuf-show-field-value">
244
- <input type="checkbox" class="wpuf-value-handelar" id="wpuf-<?php echo $name . '_' . $field_id; ?>"><?php _e( 'Show values', 'wp-user-frontend' ); ?>
245
- </label>
246
-
247
- <div class="wpuf-option-label-value"><span><?php _e( 'Label', 'wp-user-frontend' ); ?></span><span class="wpuf-option-value" style="display: none;"><?php _e( 'Value', 'wp-user-frontend' ); ?></span></div>
248
- <?php
249
- if ( $values && $values['options'] > 0 ) {
250
- foreach ($values['options'] as $key => $value) {
251
- ?>
252
- <div class="wpuf-clone-field">
253
- <input type="radio" name="<?php echo $selected_name ?>" value="<?php echo $value; ?>" <?php checked( $selected_value, $value ); ?>>
254
- <input type="text" data-type="option" name="<?php echo $input_name; ?>[]" value="<?php echo $value; ?>">
255
- <input type="text" data-type="option_value" name="<?php echo $input_value_name; ?>[]" value="<?php echo $key; ?>" style="display:none;">
256
-
257
- <?php self::remove_button(); ?>
258
- </div>
259
- <?php
260
- }
261
-
262
- } else {
263
- ?>
264
- <div class="wpuf-clone-field">
265
- <input type="radio" name="<?php echo $selected_name ?>">
266
- <input type="text" data-type="option" name="<?php echo $input_name; ?>[]" value="">
267
- <input type="text" data-type="option_value" name="<?php echo $input_value_name; ?>[]" value="" style="display:none;">
268
-
269
- <?php self::remove_button(); ?>
270
- </div>
271
- <?php
272
- }
273
- }
274
-
275
- public static function conditional_field( $field_id, $con_fields = array() ) {
276
-
277
- do_action( 'wpuf_conditional_field_render_hook',$field_id, $con_fields, 'WPUF_Admin_Template' );
278
-
279
- }
280
-
281
- /**
282
- * Displays a checkbox custom field
283
- *
284
- * @param int $field_id
285
- * @param string $name
286
- * @param array $values
287
- */
288
- public static function common_checkbox( $field_id, $name, $values = array() ) {
289
-
290
- $selected_name = sprintf( '%s[%d][selected]', self::$input_name, $field_id );
291
- $input_name = sprintf( '%s[%d][%s]', self::$input_name, $field_id, $name );
292
- $input_value_name = sprintf( '%s[%d][%s]', self::$input_name, $field_id, $name.'_values' );
293
-
294
- $selected_value = ( $values && isset( $values['selected'] ) ) ? $values['selected'] : array();
295
-
296
- ?>
297
- <style>
298
- .wpuf-option-label-value span {
299
- font-weight: bold;
300
- margin-left: 5%;
301
- margin-right: 27%;
302
- }
303
- </style>
304
- <input type="checkbox" class="wpuf-value-handelar" id="<?php echo $name.'_'.$field_id; ?>"><label for="<?php echo $name.'_'.$field_id; ?>"><?php _e('show values', 'wp-user-frontend'); ?></label>
305
- <div class="wpuf-option-label-value"><span><?php _e( 'Label', 'wp-user-frontend' ); ?></span><span class="wpuf-option-value" style="display: none;"><?php _e( 'Value', 'wp-user-frontend' ); ?></span></div>
306
- <?php
307
- if ( $values && $values['options'] > 0 ) {
308
- foreach ($values['options'] as $key => $value) {
309
- ?>
310
- <div class="wpuf-clone-field">
311
-
312
- <input type="checkbox" name="<?php echo $selected_name ?>[]" value="<?php echo $value; ?>"<?php echo in_array( $value, $selected_value ) ? ' checked="checked"' : ''; ?> />
313
- <input type="text" data-type="option" name="<?php echo $input_name; ?>[]" value="<?php echo $value; ?>">
314
- <input type="text" data-type="option_value" name="<?php echo $input_value_name; ?>[]" value="<?php echo $key; ?>" style="display:none;">
315
- <?php self::remove_button(); ?>
316
- </div>
317
- <?php
318
- }
319
- } else {
320
- ?>
321
- <div class="wpuf-clone-field">
322
- <input type="checkbox" name="<?php echo $selected_name ?>[]">
323
- <input type="text" data-type="option" name="<?php echo $input_name; ?>[]" value="">
324
- <input type="text" data-type="option_value" name="<?php echo $input_value_name; ?>[]" value="" style="display:none;">
325
-
326
- <?php self::remove_button(); ?>
327
- </div>
328
- <?php
329
- }
330
- }
331
-
332
- /**
333
- * Add/remove buttons for repeatable fields
334
- *
335
- * @return void
336
- */
337
- public static function remove_button() {
338
- $add = plugins_url( 'assets/images/add.png', dirname( __FILE__ ) );
339
- $remove = plugins_url( 'assets/images/remove.png', dirname( __FILE__ ) );
340
- ?>
341
- <img style="cursor:pointer; margin:0 3px;" alt="add another choice" title="add another choice" class="wpuf-clone-field" src="<?php echo $add; ?>">
342
- <img style="cursor:pointer;" class="wpuf-remove-field" alt="remove this choice" title="remove this choice" src="<?php echo $remove; ?>">
343
- <?php
344
- }
345
-
346
- public static function get_buffered( $func, $field_id, $label ) {
347
- ob_start();
348
-
349
- self::$func( $field_id, $label );
350
-
351
- return ob_get_clean();
352
- }
353
-
354
- public static function text_field( $field_id, $label, $values = array() ) {
355
-
356
- ?>
357
- <li class="custom-field text_field">
358
- <?php self::legend( $label, $values, $field_id ); ?>
359
- <?php self::hidden_field( "[$field_id][input_type]", 'text' ); ?>
360
- <?php self::hidden_field( "[$field_id][template]", 'text_field' ); ?>
361
-
362
- <div class="wpuf-form-holder">
363
- <?php self::common( $field_id, '', true, $values ); ?>
364
- <?php self::common_text( $field_id, $values ); ?>
365
- <?php self::conditional_field( $field_id, $values ); ?>
366
- </div> <!-- .wpuf-form-holder -->
367
- </li>
368
- <?php
369
- }
370
-
371
- public static function textarea_field( $field_id, $label, $values = array() ) {
372
- ?>
373
- <li class="custom-field textarea_field">
374
- <?php self::legend( $label, $values, $field_id ); ?>
375
- <?php self::hidden_field( "[$field_id][input_type]", 'textarea' ); ?>
376
- <?php self::hidden_field( "[$field_id][template]", 'textarea_field' ); ?>
377
-
378
- <div class="wpuf-form-holder">
379
- <?php self::common( $field_id, '', true, $values ); ?>
380
- <?php self::common_textarea( $field_id, $values ); ?>
381
- <?php self::conditional_field( $field_id, $values ); ?>
382
- </div> <!-- .wpuf-form-holder -->
383
- </li>
384
- <?php
385
- }
386
-
387
- public static function radio_field( $field_id, $label, $values = array() ) {
388
- ?>
389
- <li class="custom-field radio_field wpuf-conditional">
390
- <?php self::legend( $label, $values, $field_id ); ?>
391
- <?php self::hidden_field( "[$field_id][input_type]", 'radio' ); ?>
392
- <?php self::hidden_field( "[$field_id][template]", 'radio_field' ); ?>
393
-
394
- <div class="wpuf-form-holder">
395
- <?php self::common( $field_id, '', true, $values ); ?>
396
-
397
- <div class="wpuf-form-rows">
398
- <label><?php _e( 'Options', 'wp-user-frontend' ); ?></label>
399
-
400
- <div class="wpuf-form-sub-fields wpuf-options">
401
- <?php self::radio_fields( $field_id, 'options', $values ); ?>
402
-
403
- </div> <!-- .wpuf-form-sub-fields -->
404
- <?php self::conditional_field( $field_id, $values ); ?>
405
- </div> <!-- .wpuf-form-rows -->
406
- </div> <!-- .wpuf-form-holder -->
407
- </li>
408
- <?php
409
- }
410
-
411
- public static function checkbox_field( $field_id, $label, $values = array() ) {
412
- ?>
413
- <li class="custom-field checkbox_field wpuf-conditional">
414
- <?php self::legend( $label, $values, $field_id ); ?>
415
- <?php self::hidden_field( "[$field_id][input_type]", 'checkbox' ); ?>
416
- <?php self::hidden_field( "[$field_id][template]", 'checkbox_field' ); ?>
417
-
418
- <div class="wpuf-form-holder">
419
- <?php self::common( $field_id, '', true, $values ); ?>
420
-
421
- <div class="wpuf-form-rows">
422
- <label><?php _e( 'Options', 'wp-user-frontend' ); ?></label>
423
-
424
- <div class="wpuf-form-sub-fields wpuf-options">
425
- <?php self::common_checkbox( $field_id, 'options', $values ); ?>
426
-
427
- </div> <!-- .wpuf-form-sub-fields -->
428
- <?php self::conditional_field( $field_id, $values ); ?>
429
- </div> <!-- .wpuf-form-rows -->
430
- </div> <!-- .wpuf-form-holder -->
431
- </li>
432
- <?php
433
- }
434
-
435
- public static function dropdown_field( $field_id, $label, $values = array() ) {
436
- $first_name = sprintf( '%s[%d][first]', self::$input_name, $field_id );
437
- $first_value = $values ? $values['first'] : ' - select -';
438
- $help = esc_attr( __( 'First element of the select dropdown. Leave this empty if you don\'t want to show this field', 'wp-user-frontend' ) );
439
- ?>
440
- <li class="custom-field dropdown_field wpuf-conditional">
441
- <?php self::legend( $label, $values, $field_id ); ?>
442
- <?php self::hidden_field( "[$field_id][input_type]", 'select' ); ?>
443
- <?php self::hidden_field( "[$field_id][template]", 'dropdown_field' ); ?>
444
-
445
- <div class="wpuf-form-holder">
446
- <?php self::common( $field_id, '', true, $values ); ?>
447
-
448
- <div class="wpuf-form-rows">
449
- <label><?php _e( 'Select Text', 'wp-user-frontend' ); ?></label>
450
- <input type="text" class="smallipopInput" name="<?php echo $first_name; ?>" value="<?php echo $first_value; ?>" title="<?php echo $help; ?>">
451
- </div> <!-- .wpuf-form-rows -->
452
-
453
- <div class="wpuf-form-rows">
454
- <label><?php _e( 'Options', 'wp-user-frontend' ); ?></label>
455
-
456
- <div class="wpuf-form-sub-fields wpuf-options">
457
- <?php self::radio_fields( $field_id, 'options', $values ); ?>
458
- </div> <!-- .wpuf-form-sub-fields -->
459
-
460
- <?php self::conditional_field( $field_id, $values ); ?>
461
- </div> <!-- .wpuf-form-rows -->
462
- </div> <!-- .wpuf-form-holder -->
463
- </li>
464
- <?php
465
- }
466
-
467
- public static function multiple_select( $field_id, $label, $values = array() ) {
468
- $first_name = sprintf( '%s[%d][first]', self::$input_name, $field_id );
469
- $first_value = $values ? $values['first'] : ' - select -';
470
- $help = esc_attr( __( 'First element of the select dropdown. Leave this empty if you don\'t want to show this field', 'wp-user-frontend' ) );
471
- ?>
472
- <li class="custom-field multiple_select">
473
- <?php self::legend( $label, $values, $field_id ); ?>
474
- <?php self::hidden_field( "[$field_id][input_type]", 'multiselect' ); ?>
475
- <?php self::hidden_field( "[$field_id][template]", 'multiple_select' ); ?>
476
-
477
- <div class="wpuf-form-holder">
478
- <?php self::common( $field_id, '', true, $values ); ?>
479
-
480
- <div class="wpuf-form-rows">
481
- <label><?php _e( 'Select Text', 'wp-user-frontend' ); ?></label>
482
- <input type="text" class="smallipopInput" name="<?php echo $first_name; ?>" value="<?php echo $first_value; ?>" title="<?php echo $help; ?>">
483
- </div> <!-- .wpuf-form-rows -->
484
-
485
- <div class="wpuf-form-rows">
486
- <label><?php _e( 'Options', 'wp-user-frontend' ); ?></label>
487
-
488
- <div class="wpuf-form-sub-fields wpuf-options">
489
- <?php self::radio_fields( $field_id, 'options', $values ); ?>
490
- </div> <!-- .wpuf-form-sub-fields -->
491
-
492
- <?php self::conditional_field( $field_id, $values ); ?>
493
- </div> <!-- .wpuf-form-rows -->
494
- </div> <!-- .wpuf-form-holder -->
495
- </li>
496
- <?php
497
- }
498
-
499
- public static function website_url( $field_id, $label, $values = array() ) {
500
- ?>
501
- <li class="custom-field website_url">
502
- <?php self::legend( $label, $values, $field_id ); ?>
503
- <?php self::hidden_field( "[$field_id][input_type]", 'url' ); ?>
504
- <?php self::hidden_field( "[$field_id][template]", 'website_url' ); ?>
505
-
506
- <div class="wpuf-form-holder">
507
- <?php self::common( $field_id, '', true, $values ); ?>
508
- <?php self::common_text( $field_id, $values ); ?>
509
- <?php self::conditional_field( $field_id, $values ); ?>
510
- </div> <!-- .wpuf-form-holder -->
511
- </li>
512
- <?php
513
- }
514
-
515
- public static function email_address( $field_id, $label, $values = array() ) {
516
- ?>
517
- <li class="custom-field eamil_address">
518
- <?php self::legend( $label, $values, $field_id ); ?>
519
- <?php self::hidden_field( "[$field_id][input_type]", 'email' ); ?>
520
- <?php self::hidden_field( "[$field_id][template]", 'email_address' ); ?>
521
-
522
- <div class="wpuf-form-holder">
523
- <?php self::common( $field_id, '', true, $values ); ?>
524
- <?php self::common_text( $field_id, $values ); ?>
525
- <?php self::conditional_field( $field_id, $values ); ?>
526
- </div> <!-- .wpuf-form-holder -->
527
- </li>
528
- <?php
529
- }
530
-
531
- public static function custom_html( $field_id, $label, $values = array() ) {
532
- $title_name = sprintf( '%s[%d][label]', self::$input_name, $field_id );
533
- $html_name = sprintf( '%s[%d][html]', self::$input_name, $field_id );
534
- $title_value = $values ? esc_attr( $values['label'] ) : '';
535
- $html_value = $values ? esc_attr( $values['html'] ) : '';
536
- ?>
537
- <li class="custom-field custom_html">
538
- <?php self::legend( $label, $values, $field_id ); ?>
539
- <?php self::hidden_field( "[$field_id][input_type]", 'html' ); ?>
540
- <?php self::hidden_field( "[$field_id][template]", 'custom_html' ); ?>
541
-
542
- <div class="wpuf-form-holder">
543
- <div class="wpuf-form-rows">
544
- <label><?php _e( 'Title', 'wp-user-frontend' ); ?></label>
545
- <input type="text" class="smallipopInput" title="Title of the section" name="<?php echo $title_name; ?>" value="<?php echo esc_attr( $title_value ); ?>" />
546
- </div> <!-- .wpuf-form-rows -->
547
-
548
- <div class="wpuf-form-rows">
549
- <label><?php _e( 'HTML Codes', 'wp-user-frontend' ); ?></label>
550
- <textarea class="smallipopInput" title="Paste your HTML codes, WordPress shortcodes will also work here" name="<?php echo $html_name; ?>" rows="10"><?php echo esc_html( $html_value ); ?></textarea>
551
- </div>
552
-
553
- <?php self::conditional_field( $field_id, $values ); ?>
554
- </div> <!-- .wpuf-form-holder -->
555
- </li>
556
- <?php
557
- }
558
-
559
- public static function custom_hidden_field( $field_id, $label, $values = array() ) {
560
- $meta_name = sprintf( '%s[%d][name]', self::$input_name, $field_id );
561
- $value_name = sprintf( '%s[%d][meta_value]', self::$input_name, $field_id );
562
- $is_meta_name = sprintf( '%s[%d][is_meta]', self::$input_name, $field_id );
563
- $label_name = sprintf( '%s[%d][label]', self::$input_name, $field_id );
564
-
565
- $meta_value = $values ? esc_attr( $values['name'] ) : '';
566
- $value_value = $values ? esc_attr( $values['meta_value'] ) : '';
567
- ?>
568
- <li class="custom-field custom_hidden_field">
569
- <?php self::legend( $label, $values, $field_id ); ?>
570
- <?php self::hidden_field( "[$field_id][input_type]", 'hidden' ); ?>
571
- <?php self::hidden_field( "[$field_id][template]", 'custom_hidden_field' ); ?>
572
-
573
- <div class="wpuf-form-holder">
574
- <div class="wpuf-form-rows">
575
- <label><?php _e( 'Meta Key', 'wp-user-frontend' ); ?></label>
576
- <input type="text" name="<?php echo $meta_name; ?>" value="<?php echo $meta_value; ?>" class="smallipopInput" title="<?php _e( 'Name of the meta key this field will save to', 'wp-user-frontend' ); ?>">
577
- <input type="hidden" name="<?php echo $is_meta_name; ?>" value="yes">
578
- <input type="hidden" name="<?php echo $label_name; ?>" value="">
579
- </div> <!-- .wpuf-form-rows -->
580
-
581
- <div class="wpuf-form-rows">
582
- <label><?php _e( 'Meta Value', 'wp-user-frontend' ); ?></label>
583
- <input type="text" class="smallipopInput" title="<?php esc_attr_e( 'Enter the meta value', 'wp-user-frontend' ); ?>" name="<?php echo $value_name; ?>" value="<?php echo $value_value; ?>">
584
- </div>
585
- </div> <!-- .wpuf-form-holder -->
586
- </li>
587
- <?php
588
- }
589
-
590
- public static function section_break( $field_id, $label, $values = array() ) {
591
- $title_name = sprintf( '%s[%d][label]', self::$input_name, $field_id );
592
- $description_name = sprintf( '%s[%d][description]', self::$input_name, $field_id );
593
-
594
- $title_value = $values ? esc_attr( $values['label'] ) : '';
595
- $description_value = $values ? esc_attr( $values['description'] ) : '';
596
- ?>
597
- <li class="custom-field custom_html">
598
- <?php self::legend( $label, $values, $field_id ); ?>
599
- <?php self::hidden_field( "[$field_id][input_type]", 'section_break' ); ?>
600
- <?php self::hidden_field( "[$field_id][template]", 'section_break' ); ?>
601
-
602
- <div class="wpuf-form-holder">
603
- <div class="wpuf-form-rows">
604
- <label><?php _e( 'Title', 'wp-user-frontend' ); ?></label>
605
- <input type="text" class="smallipopInput" title="Title of the section" name="<?php echo $title_name; ?>" value="<?php echo esc_attr( $title_value ); ?>" />
606
- </div> <!-- .wpuf-form-rows -->
607
-
608
- <div class="wpuf-form-rows">
609
- <label><?php _e( 'Description', 'wp-user-frontend' ); ?></label>
610
- <textarea class="smallipopInput" title="Some details text about the section" name="<?php echo $description_name; ?>" rows="3"><?php echo esc_html( $description_value ); ?></textarea>
611
- </div> <!-- .wpuf-form-rows -->
612
-
613
- <?php self::conditional_field( $field_id, $values ); ?>
614
- </div> <!-- .wpuf-form-holder -->
615
- </li>
616
- <?php
617
- }
618
-
619
- /**
620
- * Render image upload
621
- *
622
- * @param $field_id
623
- * @param $label
624
- * @param self
625
- * @param array $values
626
- */
627
- public static function image_upload( $field_id, $label, $values = array() ) {
628
- $max_size_name = sprintf( '%s[%d][max_size]', self::$input_name, $field_id );
629
- $max_files_name = sprintf( '%s[%d][count]', self::$input_name, $field_id );
630
-
631
- $max_size_value = $values ? $values['max_size'] : '1024';
632
- $max_files_value = $values ? $values['count'] : '1';
633
-
634
- $help = esc_attr( __( 'Enter maximum upload size limit in KB', 'wp-user-frontend' ) );
635
- $count = esc_attr( __( 'Number of images can be uploaded', 'wp-user-frontend' ) );
636
- ?>
637
- <li class="custom-field image_upload">
638
- <?php self::legend( $label, $values, $field_id ); ?>
639
- <?php self::hidden_field( "[$field_id][input_type]", 'image_upload' ); ?>
640
- <?php self::hidden_field( "[$field_id][template]", 'image_upload' ); ?>
641
-
642
- <div class="wpuf-form-holder">
643
- <?php self::common( $field_id, '', true, $values ); ?>
644
-
645
- <div class="wpuf-form-rows">
646
- <label><?php _e( 'Max. file size', 'wp-user-frontend' ); ?></label>
647
- <input type="text" class="smallipopInput" name="<?php echo $max_size_name; ?>" value="<?php echo $max_size_value; ?>" title="<?php echo $help; ?>">
648
- </div> <!-- .wpuf-form-rows -->
649
-
650
- <div class="wpuf-form-rows">
651
- <label><?php _e( 'Max. files', 'wp-user-frontend' ); ?></label>
652
- <input type="text" class="smallipopInput" name="<?php echo $max_files_name; ?>" value="<?php echo $max_files_value; ?>" title="<?php echo $count; ?>">
653
- </div> <!-- .wpuf-form-rows -->
654
-
655
- <?php self::conditional_field( $field_id, $values ); ?>
656
- </div> <!-- .wpuf-form-holder -->
657
- </li>
658
- <?php
659
- }
660
-
661
- /**
662
- * Render recaptcha
663
- * @param $field_id
664
- * @param $label
665
- * @param array $values
666
- */
667
- public static function recaptcha( $field_id, $label, $values = array() ) {
668
- $title_name = sprintf( '%s[%d][label]', self::$input_name, $field_id );
669
- $html_name = sprintf( '%s[%d][html]', self::$input_name, $field_id );
670
- $recaptcha_type_name = sprintf( '%s[%d][recaptcha_type]', self::$input_name, $field_id );
671
-
672
- $title_value = $values ? esc_attr( $values['label'] ) : '';
673
- $html_value = isset( $values['html'] ) ? esc_attr( $values['html'] ) : '';
674
- $recaptcha_type_value = isset( $values['recaptcha_type'] ) ? esc_attr( $values['recaptcha_type'] ) : ( !empty( $values ) ? '' : 'enable_no_captcha' );
675
- ?>
676
- <li class="custom-field custom_html">
677
- <?php self::legend( $label, $values, $field_id ); ?>
678
- <?php self::hidden_field( "[$field_id][input_type]", 'recaptcha' ); ?>
679
- <?php self::hidden_field( "[$field_id][template]", 'recaptcha' ); ?>
680
-
681
- <div class="wpuf-form-holder">
682
- <div class="wpuf-form-rows">
683
- <label><?php _e( 'Title', 'wp-user-frontend' ); ?></label>
684
-
685
- <div class="wpuf-form-sub-fields">
686
- <input type="text" class="smallipopInput" title="Title of the section" name="<?php echo $title_name; ?>" value="<?php echo esc_attr( $title_value ); ?>" />
687
-
688
- <div class="description" style="margin-top: 8px;">
689
- <?php printf( __( "Insert your public key and private key in <a href='%s'>plugin settings</a>. <a href='%s' target='_blank'>Register</a> first if you don't have any keys.", 'wp-user-frontend' ), admin_url( 'admin.php?page=wpuf-settings' ), 'https://www.google.com/recaptcha/' ); ?>
690
- </div>
691
- </div> <!-- .wpuf-form-rows -->
692
- </div>
693
-
694
- <div class="wpuf-form-rows">
695
- <label><?php _e( 'reCaptcha type', 'wp-user-frontend' ); ?></label>
696
-
697
- <div class="wpuf-form-sub-fields">
698
- <input type="radio" class="smallipopInput" title="reCaptcha type" name="<?php echo $recaptcha_type_name; ?>" value="invisible_recaptcha" <?php echo $recaptcha_type_value == 'invisible_recaptcha' ? 'checked':''; ?> />
699
- <?php _e( 'Enable Invisible reCaptcha', 'wp-user-frontend' );?>
700
- </div> <!-- .wpuf-form-rows -->
701
- <div class="wpuf-form-sub-fields">
702
- <input type="radio" class="smallipopInput" title="reCaptcha type" name="<?php echo $recaptcha_type_name; ?>" value="enable_no_captcha" <?php echo $recaptcha_type_value == 'enable_no_captcha' ? 'checked':''; ?> />
703
- <?php _e( 'Enable noCaptcha', 'wp-user-frontend' );?>
704
- </div> <!-- .wpuf-form-rows -->
705
- </div>
706
-
707
- <?php self::conditional_field( $field_id, $values ); ?>
708
- </div> <!-- .wpuf-form-holder -->
709
- </li>
710
- <?php
711
- }
712
-
713
- }
1
+ <?php
2
+
3
+ /**
4
+ * WPUF Form builder template
5
+ */
6
+ class WPUF_Admin_Template {
7
+ public static $input_name = 'wpuf_input';
8
+
9
+ public static $cond_name = 'wpuf_cond';
10
+
11
+ /**
12
+ * Legend of a form item
13
+ *
14
+ * @param string $title
15
+ * @param array $values
16
+ */
17
+ public static function legend( $title = 'Field Name', $values = [], $field_id = 0 ) {
18
+ $field_label = $values ? ': <strong>' . $values['label'] . '</strong>' : '';
19
+ $id = isset( $values['id'] ) ? $values['id'] : ''; ?>
20
+ <div class="wpuf-legend" title="<?php esc_html_e( 'Click and Drag to rearrange', 'wp-user-frontend' ); ?>">
21
+ <input type="hidden" value="<?php echo esc_attr( $id ); ?>" name="wpuf_input[<?php echo esc_attr( $field_id ); ?>][id]">
22
+ <div class="wpuf-label"><?php echo esc_attr( $title . $field_label ); ?></div>
23
+ <div class="wpuf-actions">
24
+ <a href="#" class="wpuf-remove"><?php esc_html_e( 'Remove', 'wp-user-frontend' ); ?></a>
25
+ <a href="#" class="wpuf-toggle"><?php esc_html_e( 'Toggle', 'wp-user-frontend' ); ?></a>
26
+ </div>
27
+ </div> <!-- .wpuf-legend -->
28
+ <?php
29
+ }
30
+
31
+ /**
32
+ * Common Fields for a input field
33
+ *
34
+ * Contains required, label, meta_key, help text, css class name
35
+ *
36
+ * @param int $id field order
37
+ * @param mixed $field_name_value
38
+ * @param bool $custom_field if it a custom field or not
39
+ * @param array $values saved value
40
+ */
41
+ public static function common( $id, $field_name_value = '', $custom_field = true, $values = [] ) {
42
+ $tpl = '%s[%d][%s]';
43
+ $required_name = sprintf( $tpl, self::$input_name, $id, 'required' );
44
+ $field_name = sprintf( $tpl, self::$input_name, $id, 'name' );
45
+ $label_name = sprintf( $tpl, self::$input_name, $id, 'label' );
46
+ $is_meta_name = sprintf( $tpl, self::$input_name, $id, 'is_meta' );
47
+ $help_name = sprintf( $tpl, self::$input_name, $id, 'help' );
48
+ $css_name = sprintf( $tpl, self::$input_name, $id, 'css' );
49
+
50
+ // $field_name_value = $field_name_value ?
51
+ $required = $values ? esc_attr( $values['required'] ) : 'yes';
52
+ $label_value = $values ? esc_attr( $values['label'] ) : '';
53
+ $help_value = $values ? stripslashes( $values['help'] ) : '';
54
+ $css_value = $values ? esc_attr( $values['css'] ) : '';
55
+
56
+ if ( $custom_field && $values ) {
57
+ $field_name_value = $values['name'];
58
+ } ?>
59
+ <div class="wpuf-form-rows required-field">
60
+ <label><?php esc_html_e( 'Required', 'wp-user-frontend' ); ?></label>
61
+
62
+ <div class="wpuf-form-sub-fields">
63
+ <label><input type="radio" name="<?php echo esc_attr( $required_name ); ?>" value="yes"<?php checked( $required, 'yes' ); ?>> <?php esc_html_e( 'Yes', 'wp-user-frontend' ); ?> </label>
64
+ <label><input type="radio" name="<?php echo esc_attr( $required_name ); ?>" value="no"<?php checked( $required, 'no' ); ?>> <?php esc_html_e( 'No', 'wp-user-frontend' ); ?> </label>
65
+ </div>
66
+ </div> <!-- .wpuf-form-rows -->
67
+
68
+ <div class="wpuf-form-rows">
69
+ <label><?php esc_html_e( 'Field Label', 'wp-user-frontend' ); ?></label>
70
+ <input type="text" data-type="label" name="<?php echo esc_attr( $label_name ); ?>" value="<?php echo esc_attr( $label_value ); ?>" class="smallipopInput" title="<?php esc_html_e( 'Enter a title of this field', 'wp-user-frontend' ); ?>">
71
+ </div> <!-- .wpuf-form-rows -->
72
+
73
+ <?php if ( $custom_field ) { ?>
74
+ <div class="wpuf-form-rows">
75
+ <label><?php esc_html_e( 'Meta Key', 'wp-user-frontend' ); ?></label>
76
+ <input type="text" data-type="name" name="<?php echo esc_attr( $field_name ); ?>" value="<?php echo esc_attr( $field_name_value ); ?>" class="smallipopInput" title="<?php esc_html_e( 'Name of the meta key this field will save to', 'wp-user-frontend' ); ?>">
77
+ <input type="hidden" name="<?php echo esc_attr( $is_meta_name ); ?>" value="yes">
78
+ </div> <!-- .wpuf-form-rows -->
79
+ <?php } else { ?>
80
+
81
+ <input type="hidden" data-type="name" name="<?php echo esc_attr( $field_name ); ?>" value="<?php echo esc_attr( $field_name_value ); ?>">
82
+ <input type="hidden" name="<?php echo esc_attr( $is_meta_name ); ?>" value="no">
83
+
84
+ <?php } ?>
85
+
86
+ <div class="wpuf-form-rows">
87
+ <label><?php esc_html_e( 'Help text', 'wp-user-frontend' ); ?></label>
88
+ <textarea name="<?php echo esc_attr( $help_name ); ?>" class="smallipopInput" title="<?php esc_html_e( 'Give the user some information about this field', 'wp-user-frontend' ); ?>"><?php echo esc_attr( $help_value ); ?></textarea>
89
+ </div> <!-- .wpuf-form-rows -->
90
+
91
+ <div class="wpuf-form-rows">
92
+ <label><?php esc_html_e( 'CSS Class Name', 'wp-user-frontend' ); ?></label>
93
+ <input type="text" name="<?php echo esc_attr( $css_name ); ?>" value="<?php echo esc_attr( $css_value ); ?>" class="smallipopInput" title="<?php esc_html_e( 'Add a CSS class name for this field', 'wp-user-frontend' ); ?>">
94
+ </div> <!-- .wpuf-form-rows -->
95
+
96
+ <?php
97
+ }
98
+
99
+ /**
100
+ * Common fields for a text area
101
+ *
102
+ * @param int $id
103
+ * @param array $values
104
+ */
105
+ public static function common_text( $id, $values = [] ) {
106
+ $tpl = '%s[%d][%s]';
107
+ $placeholder_name = sprintf( $tpl, self::$input_name, $id, 'placeholder' );
108
+ $default_name = sprintf( $tpl, self::$input_name, $id, 'default' );
109
+ $size_name = sprintf( $tpl, self::$input_name, $id, 'size' );
110
+ $word_restriction_name = sprintf( $tpl, self::$input_name, $id, 'word_restriction' );
111
+
112
+ $placeholder_value = $values ? esc_attr( $values['placeholder'] ) : '';
113
+ $default_value = $values ? esc_attr( $values['default'] ) : '';
114
+ $size_value = $values ? esc_attr( $values['size'] ) : '40';
115
+ $word_restriction_value = $values ? esc_attr( $values['word_restriction'] ) : ''; ?>
116
+ <div class="wpuf-form-rows">
117
+ <label><?php esc_html_e( 'Placeholder text', 'wp-user-frontend' ); ?></label>
118
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $placeholder_name ); ?>" title="<?php esc_attr_e( 'Text for HTML5 placeholder attribute', 'wp-user-frontend' ); ?>" value="<?php echo esc_attr( $placeholder_value ); ?>" />
119
+ </div> <!-- .wpuf-form-rows -->
120
+
121
+ <div class="wpuf-form-rows">
122
+ <label><?php esc_html_e( 'Default value', 'wp-user-frontend' ); ?></label>
123
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $default_name ); ?>" title="<?php esc_attr_e( 'The default value this field will have', 'wp-user-frontend' ); ?>" value="<?php echo esc_attr( $default_value ); ?>" />
124
+ </div> <!-- .wpuf-form-rows -->
125
+
126
+ <div class="wpuf-form-rows">
127
+ <label><?php esc_html_e( 'Size', 'wp-user-frontend' ); ?></label>
128
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $size_name ); ?>" title="<?php esc_attr_e( 'Size of this input field', 'wp-user-frontend' ); ?>" value="<?php echo esc_attr( $size_value ); ?>" />
129
+ </div> <!-- .wpuf-form-rows -->
130
+
131
+ <div class="wpuf-form-rows">
132
+ <label><?php esc_html_e( 'Word Restriction', 'wp-user-frontend' ); ?></label>
133
+
134
+ <div class="wpuf-form-sub-fields">
135
+ <label>
136
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $word_restriction_name ); ?>" value="<?php echo esc_attr( $word_restriction_value ); ?>" title="<?php esc_attr_e( 'Numebr of words the author to be restricted in', 'wp-user-frontend' ); ?>" />
137
+ </label>
138
+ </div>
139
+ </div> <!-- .wpuf-form-rows -->
140
+ <?php
141
+ }
142
+
143
+ /**
144
+ * Common fields for a textarea
145
+ *
146
+ * @param int $id
147
+ * @param array $values
148
+ */
149
+ public static function common_textarea( $id, $values = [] ) {
150
+ $tpl = '%s[%d][%s]';
151
+ $rows_name = sprintf( $tpl, self::$input_name, $id, 'rows' );
152
+ $cols_name = sprintf( $tpl, self::$input_name, $id, 'cols' );
153
+ $rich_name = sprintf( $tpl, self::$input_name, $id, 'rich' );
154
+ $placeholder_name = sprintf( $tpl, self::$input_name, $id, 'placeholder' );
155
+ $default_name = sprintf( $tpl, self::$input_name, $id, 'default' );
156
+ $word_restriction_name = sprintf( $tpl, self::$input_name, $id, 'word_restriction' );
157
+
158
+ $rows_value = $values ? esc_attr( $values['rows'] ) : '5';
159
+ $cols_value = $values ? esc_attr( $values['cols'] ) : '25';
160
+ $rich_value = $values ? esc_attr( $values['rich'] ) : 'no';
161
+ $placeholder_value = $values ? esc_attr( $values['placeholder'] ) : '';
162
+ $default_value = $values ? esc_attr( $values['default'] ) : '';
163
+ $word_restriction_value = $values ? esc_attr( $values['word_restriction'] ) : ''; ?>
164
+ <div class="wpuf-form-rows">
165
+ <label><?php esc_html_e( 'Rows', 'wp-user-frontend' ); ?></label>
166
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $rows_name ); ?>" title="Number of rows in textarea" value="<?php echo esc_attr( $rows_value ); ?>" />
167
+ </div> <!-- .wpuf-form-rows -->
168
+
169
+ <div class="wpuf-form-rows">
170
+ <label><?php esc_html_e( 'Columns', 'wp-user-frontend' ); ?></label>
171
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $cols_name ); ?>" title="Number of columns in textarea" value="<?php echo esc_attr( $cols_value ); ?>" />
172
+ </div> <!-- .wpuf-form-rows -->
173
+
174
+ <div class="wpuf-form-rows">
175
+ <label><?php esc_html_e( 'Placeholder text', 'wp-user-frontend' ); ?></label>
176
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $placeholder_name ); ?>" title="text for HTML5 placeholder attribute" value="<?php echo esc_attr( $placeholder_value ); ?>" />
177
+ </div> <!-- .wpuf-form-rows -->
178
+
179
+ <div class="wpuf-form-rows">
180
+ <label><?php esc_html_e( 'Default value', 'wp-user-frontend' ); ?></label>
181
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $default_name ); ?>" title="the default value this field will have" value="<?php echo esc_attr( $default_value ); ?>" />
182
+ </div> <!-- .wpuf-form-rows -->
183
+
184
+ <div class="wpuf-form-rows">
185
+ <label><?php esc_html_e( 'Textarea', 'wp-user-frontend' ); ?></label>
186
+
187
+ <div class="wpuf-form-sub-fields">
188
+ <label><input type="radio" name="<?php echo esc_attr( $rich_name ); ?>" value="no"<?php checked( $rich_value, 'no' ); ?>> <?php esc_html_e( 'Normal', 'wp-user-frontend' ); ?></label>
189
+ <label><input type="radio" name="<?php echo esc_attr( $rich_name ); ?>" value="yes"<?php checked( $rich_value, 'yes' ); ?>> <?php esc_html_e( 'Rich textarea', 'wp-user-frontend' ); ?></label>
190
+ <label><input type="radio" name="<?php echo esc_attr( $rich_name ); ?>" value="teeny"<?php checked( $rich_value, 'teeny' ); ?>> <?php esc_html_e( 'Teeny Rich textarea', 'wp-user-frontend' ); ?></label>
191
+ </div>
192
+ </div> <!-- .wpuf-form-rows -->
193
+
194
+ <div class="wpuf-form-rows">
195
+ <label><?php esc_html_e( 'Word Restriction', 'wp-user-frontend' ); ?></label>
196
+
197
+ <div class="wpuf-form-sub-fields">
198
+ <label>
199
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $word_restriction_name ); ?>" value="<?php echo esc_attr( $word_restriction_value ); ?>" title="<?php esc_attr_e( 'Numebr of words the author to be restricted in', 'wp-user-frontend' ); ?>" />
200
+ </label>
201
+ </div>
202
+ </div> <!-- .wpuf-form-rows -->
203
+ <?php
204
+ }
205
+
206
+ /**
207
+ * Hidden field helper function
208
+ *
209
+ * @param string $name
210
+ * @param string $value
211
+ */
212
+ public static function hidden_field( $name, $value = '' ) {
213
+ printf( '<input type="hidden" name="%s" value="%s" />', esc_attr( self::$input_name ) . esc_attr( $name ), esc_attr( $value ) );
214
+ }
215
+
216
+ /**
217
+ * Displays a radio custom field
218
+ *
219
+ * @param int $field_id
220
+ * @param string $name
221
+ * @param array $values
222
+ */
223
+ public static function radio_fields( $field_id, $name, $values = [] ) {
224
+ $selected_name = sprintf( '%s[%d][selected]', self::$input_name, $field_id );
225
+ $input_name = sprintf( '%s[%d][%s]', self::$input_name, $field_id, $name );
226
+ $input_value_name = sprintf( '%s[%d][%s]', self::$input_name, $field_id, $name . '_values' );
227
+
228
+ $selected_value = ( $values && isset( $values['selected'] ) ) ? $values['selected'] : ''; ?>
229
+
230
+ <label for="wpuf-<?php echo esc_attr( $name . '_' . $field_id ); ?>" class="wpuf-show-field-value">
231
+ <input type="checkbox" class="wpuf-value-handelar" id="wpuf-<?php echo esc_attr( $name . '_' . $field_id ); ?>"><?php esc_html_e( 'Show values', 'wp-user-frontend' ); ?>
232
+ </label>
233
+
234
+ <div class="wpuf-option-label-value"><span><?php esc_html_e( 'Label', 'wp-user-frontend' ); ?></span><span class="wpuf-option-value" style="display: none;"><?php esc_html_e( 'Value', 'wp-user-frontend' ); ?></span></div>
235
+ <?php
236
+ if ( $values && $values['options'] > 0 ) {
237
+ foreach ( $values['options'] as $key => $value ) {
238
+ ?>
239
+ <div class="wpuf-clone-field">
240
+ <input type="radio" name="<?php echo esc_attr( $selected_name ); ?>" value="<?php echo esc_attr( $value ); ?>" <?php checked( $selected_value, $value ); ?>>
241
+ <input type="text" data-type="option" name="<?php echo esc_attr( $input_name ); ?>[]" value="<?php echo esc_attr( $value ); ?>">
242
+ <input type="text" data-type="option_value" name="<?php echo esc_attr( $input_value_name ); ?>[]" value="<?php echo esc_attr( $key ); ?>" style="display:none;">
243
+
244
+ <?php self::remove_button(); ?>
245
+ </div>
246
+ <?php
247
+ }
248
+ } else {
249
+ ?>
250
+ <div class="wpuf-clone-field">
251
+ <input type="radio" name="<?php echo esc_attr( $selected_name ); ?>">
252
+ <input type="text" data-type="option" name="<?php echo esc_attr( $input_name ); ?>[]" value="">
253
+ <input type="text" data-type="option_value" name="<?php echo esc_attr( $input_value_name ); ?>[]" value="" style="display:none;">
254
+
255
+ <?php self::remove_button(); ?>
256
+ </div>
257
+ <?php
258
+ }
259
+ }
260
+
261
+ public static function conditional_field( $field_id, $con_fields = [] ) {
262
+ do_action( 'wpuf_conditional_field_render_hook', $field_id, $con_fields, 'WPUF_Admin_Template' );
263
+ }
264
+
265
+ /**
266
+ * Displays a checkbox custom field
267
+ *
268
+ * @param int $field_id
269
+ * @param string $name
270
+ * @param array $values
271
+ */
272
+ public static function common_checkbox( $field_id, $name, $values = [] ) {
273
+ $selected_name = sprintf( '%s[%d][selected]', self::$input_name, $field_id );
274
+ $input_name = sprintf( '%s[%d][%s]', self::$input_name, $field_id, $name );
275
+ $input_value_name = sprintf( '%s[%d][%s]', self::$input_name, $field_id, $name . '_values' );
276
+
277
+ $selected_value = ( $values && isset( $values['selected'] ) ) ? $values['selected'] : []; ?>
278
+ <style>
279
+ .wpuf-option-label-value span {
280
+ font-weight: bold;
281
+ margin-left: 5%;
282
+ margin-right: 27%;
283
+ }
284
+ </style>
285
+ <input type="checkbox" class="wpuf-value-handelar" id="<?php echo esc_attr( $name . '_' . $field_id ); ?>"><label for="<?php echo esc_attr( $name . '_' . $field_id ); ?>"><?php esc_html_e( 'show values', 'wp-user-frontend' ); ?></label>
286
+ <div class="wpuf-option-label-value"><span><?php esc_html_e( 'Label', 'wp-user-frontend' ); ?></span><span class="wpuf-option-value" style="display: none;"><?php esc_html_e( 'Value', 'wp-user-frontend' ); ?></span></div>
287
+ <?php
288
+ if ( $values && $values['options'] > 0 ) {
289
+ foreach ( $values['options'] as $key => $value ) {
290
+ ?>
291
+ <div class="wpuf-clone-field">
292
+
293
+ <input type="checkbox" name="<?php echo esc_attr( $selected_name ); ?>[]" value="<?php echo esc_attr( $value ); ?>"<?php echo in_array( $value, $selected_value ) ? ' checked="checked"' : ''; ?> />
294
+ <input type="text" data-type="option" name="<?php echo esc_attr( $input_name ); ?>[]" value="<?php echo esc_attr( $value ); ?>">
295
+ <input type="text" data-type="option_value" name="<?php echo esc_attr( $input_value_name ); ?>[]" value="<?php echo esc_attr( $key ); ?>" style="display:none;">
296
+ <?php self::remove_button(); ?>
297
+ </div>
298
+ <?php
299
+ }
300
+ } else {
301
+ ?>
302
+ <div class="wpuf-clone-field">
303
+ <input type="checkbox" name="<?php echo esc_attr( $selected_name ); ?>[]">
304
+ <input type="text" data-type="option" name="<?php echo esc_attr( $input_name ); ?>[]" value="">
305
+ <input type="text" data-type="option_value" name="<?php echo esc_attr( $input_value_name ); ?>[]" value="" style="display:none;">
306
+
307
+ <?php self::remove_button(); ?>
308
+ </div>
309
+ <?php
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Add/remove buttons for repeatable fields
315
+ *
316
+ * @return void
317
+ */
318
+ public static function remove_button() {
319
+ $add = plugins_url( 'assets/images/add.png', __DIR__ );
320
+ $remove = plugins_url( 'assets/images/remove.png', __DIR__ ); ?>
321
+ <img style="cursor:pointer; margin:0 3px;" alt="add another choice" title="add another choice" class="wpuf-clone-field" src="<?php echo esc_attr( $add ); ?>">
322
+ <img style="cursor:pointer;" class="wpuf-remove-field" alt="remove this choice" title="remove this choice" src="<?php echo esc_attr( $remove ); ?>">
323
+ <?php
324
+ }
325
+
326
+ public static function get_buffered( $func, $field_id, $label ) {
327
+ ob_start();
328
+
329
+ self::$func( $field_id, $label );
330
+
331
+ return ob_get_clean();
332
+ }
333
+
334
+ public static function text_field( $field_id, $label, $values = [] ) {
335
+ ?>
336
+ <li class="custom-field text_field">
337
+ <?php self::legend( $label, $values, $field_id ); ?>
338
+ <?php self::hidden_field( "[$field_id][input_type]", 'text' ); ?>
339
+ <?php self::hidden_field( "[$field_id][template]", 'text_field' ); ?>
340
+
341
+ <div class="wpuf-form-holder">
342
+ <?php self::common( $field_id, '', true, $values ); ?>
343
+ <?php self::common_text( $field_id, $values ); ?>
344
+ <?php self::conditional_field( $field_id, $values ); ?>
345
+ </div> <!-- .wpuf-form-holder -->
346
+ </li>
347
+ <?php
348
+ }
349
+
350
+ public static function textarea_field( $field_id, $label, $values = [] ) {
351
+ ?>
352
+ <li class="custom-field textarea_field">
353
+ <?php self::legend( $label, $values, $field_id ); ?>
354
+ <?php self::hidden_field( "[$field_id][input_type]", 'textarea' ); ?>
355
+ <?php self::hidden_field( "[$field_id][template]", 'textarea_field' ); ?>
356
+
357
+ <div class="wpuf-form-holder">
358
+ <?php self::common( $field_id, '', true, $values ); ?>
359
+ <?php self::common_textarea( $field_id, $values ); ?>
360
+ <?php self::conditional_field( $field_id, $values ); ?>
361
+ </div> <!-- .wpuf-form-holder -->
362
+ </li>
363
+ <?php
364
+ }
365
+
366
+ public static function radio_field( $field_id, $label, $values = [] ) {
367
+ ?>
368
+ <li class="custom-field radio_field wpuf-conditional">
369
+ <?php self::legend( $label, $values, $field_id ); ?>
370
+ <?php self::hidden_field( "[$field_id][input_type]", 'radio' ); ?>
371
+ <?php self::hidden_field( "[$field_id][template]", 'radio_field' ); ?>
372
+
373
+ <div class="wpuf-form-holder">
374
+ <?php self::common( $field_id, '', true, $values ); ?>
375
+
376
+ <div class="wpuf-form-rows">
377
+ <label><?php esc_html_e( 'Options', 'wp-user-frontend' ); ?></label>
378
+
379
+ <div class="wpuf-form-sub-fields wpuf-options">
380
+ <?php self::radio_fields( $field_id, 'options', $values ); ?>
381
+
382
+ </div> <!-- .wpuf-form-sub-fields -->
383
+ <?php self::conditional_field( $field_id, $values ); ?>
384
+ </div> <!-- .wpuf-form-rows -->
385
+ </div> <!-- .wpuf-form-holder -->
386
+ </li>
387
+ <?php
388
+ }
389
+
390
+ public static function checkbox_field( $field_id, $label, $values = [] ) {
391
+ ?>
392
+ <li class="custom-field checkbox_field wpuf-conditional">
393
+ <?php self::legend( $label, $values, $field_id ); ?>
394
+ <?php self::hidden_field( "[$field_id][input_type]", 'checkbox' ); ?>
395
+ <?php self::hidden_field( "[$field_id][template]", 'checkbox_field' ); ?>
396
+
397
+ <div class="wpuf-form-holder">
398
+ <?php self::common( $field_id, '', true, $values ); ?>
399
+
400
+ <div class="wpuf-form-rows">
401
+ <label><?php esc_html_e( 'Options', 'wp-user-frontend' ); ?></label>
402
+
403
+ <div class="wpuf-form-sub-fields wpuf-options">
404
+ <?php self::common_checkbox( $field_id, 'options', $values ); ?>
405
+
406
+ </div> <!-- .wpuf-form-sub-fields -->
407
+ <?php self::conditional_field( $field_id, $values ); ?>
408
+ </div> <!-- .wpuf-form-rows -->
409
+ </div> <!-- .wpuf-form-holder -->
410
+ </li>
411
+ <?php
412
+ }
413
+
414
+ public static function dropdown_field( $field_id, $label, $values = [] ) {
415
+ $first_name = sprintf( '%s[%d][first]', self::$input_name, $field_id );
416
+ $first_value = $values ? $values['first'] : ' - select -';
417
+ $help = esc_attr( __( 'First element of the select dropdown. Leave this empty if you don\'t want to show this field', 'wp-user-frontend' ) ); ?>
418
+ <li class="custom-field dropdown_field wpuf-conditional">
419
+ <?php self::legend( $label, $values, $field_id ); ?>
420
+ <?php self::hidden_field( "[$field_id][input_type]", 'select' ); ?>
421
+ <?php self::hidden_field( "[$field_id][template]", 'dropdown_field' ); ?>
422
+
423
+ <div class="wpuf-form-holder">
424
+ <?php self::common( $field_id, '', true, $values ); ?>
425
+
426
+ <div class="wpuf-form-rows">
427
+ <label><?php esc_html_e( 'Select Text', 'wp-user-frontend' ); ?></label>
428
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $first_name ); ?>" value="<?php echo esc_attr( $first_value ); ?>" title="<?php echo esc_attr( $help ); ?>">
429
+ </div> <!-- .wpuf-form-rows -->
430
+
431
+ <div class="wpuf-form-rows">
432
+ <label><?php esc_html_e( 'Options', 'wp-user-frontend' ); ?></label>
433
+
434
+ <div class="wpuf-form-sub-fields wpuf-options">
435
+ <?php self::radio_fields( $field_id, 'options', $values ); ?>
436
+ </div> <!-- .wpuf-form-sub-fields -->
437
+
438
+ <?php self::conditional_field( $field_id, $values ); ?>
439
+ </div> <!-- .wpuf-form-rows -->
440
+ </div> <!-- .wpuf-form-holder -->
441
+ </li>
442
+ <?php
443
+ }
444
+
445
+ public static function multiple_select( $field_id, $label, $values = [] ) {
446
+ $first_name = sprintf( '%s[%d][first]', esc_attr( self::$input_name ), esc_attr( $field_id ) );
447
+ $first_value = $values ? $values['first'] : ' - select -';
448
+ $help = esc_attr( __( 'First element of the select dropdown. Leave this empty if you don\'t want to show this field', 'wp-user-frontend' ) ); ?>
449
+ <li class="custom-field multiple_select">
450
+ <?php self::legend( $label, $values, $field_id ); ?>
451
+ <?php self::hidden_field( "[$field_id][input_type]", 'multiselect' ); ?>
452
+ <?php self::hidden_field( "[$field_id][template]", 'multiple_select' ); ?>
453
+
454
+ <div class="wpuf-form-holder">
455
+ <?php self::common( $field_id, '', true, $values ); ?>
456
+
457
+ <div class="wpuf-form-rows">
458
+ <label><?php esc_html_e( 'Select Text', 'wp-user-frontend' ); ?></label>
459
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $first_name ); ?>" value="<?php echo esc_attr( $first_value ); ?>" title="<?php echo esc_attr( $help ); ?>">
460
+ </div> <!-- .wpuf-form-rows -->
461
+
462
+ <div class="wpuf-form-rows">
463
+ <label><?php esc_html_e( 'Options', 'wp-user-frontend' ); ?></label>
464
+
465
+ <div class="wpuf-form-sub-fields wpuf-options">
466
+ <?php self::radio_fields( $field_id, 'options', $values ); ?>
467
+ </div> <!-- .wpuf-form-sub-fields -->
468
+
469
+ <?php self::conditional_field( $field_id, $values ); ?>
470
+ </div> <!-- .wpuf-form-rows -->
471
+ </div> <!-- .wpuf-form-holder -->
472
+ </li>
473
+ <?php
474
+ }
475
+
476
+ public static function website_url( $field_id, $label, $values = [] ) {
477
+ ?>
478
+ <li class="custom-field website_url">
479
+ <?php self::legend( $label, $values, $field_id ); ?>
480
+ <?php self::hidden_field( "[$field_id][input_type]", 'url' ); ?>
481
+ <?php self::hidden_field( "[$field_id][template]", 'website_url' ); ?>
482
+
483
+ <div class="wpuf-form-holder">
484
+ <?php self::common( $field_id, '', true, $values ); ?>
485
+ <?php self::common_text( $field_id, $values ); ?>
486
+ <?php self::conditional_field( $field_id, $values ); ?>
487
+ </div> <!-- .wpuf-form-holder -->
488
+ </li>
489
+ <?php
490
+ }
491
+
492
+ public static function email_address( $field_id, $label, $values = [] ) {
493
+ ?>
494
+ <li class="custom-field eamil_address">
495
+ <?php self::legend( $label, $values, $field_id ); ?>
496
+ <?php self::hidden_field( "[$field_id][input_type]", 'email' ); ?>
497
+ <?php self::hidden_field( "[$field_id][template]", 'email_address' ); ?>
498
+
499
+ <div class="wpuf-form-holder">
500
+ <?php self::common( $field_id, '', true, $values ); ?>
501
+ <?php self::common_text( $field_id, $values ); ?>
502
+ <?php self::conditional_field( $field_id, $values ); ?>
503
+ </div> <!-- .wpuf-form-holder -->
504
+ </li>
505
+ <?php
506
+ }
507
+
508
+ public static function custom_html( $field_id, $label, $values = [] ) {
509
+ $title_name = sprintf( '%s[%d][label]', self::$input_name, $field_id );
510
+ $html_name = sprintf( '%s[%d][html]', self::$input_name, $field_id );
511
+ $title_value = $values ? esc_attr( $values['label'] ) : '';
512
+ $html_value = $values ? esc_attr( $values['html'] ) : ''; ?>
513
+ <li class="custom-field custom_html">
514
+ <?php self::legend( $label, $values, $field_id ); ?>
515
+ <?php self::hidden_field( "[$field_id][input_type]", 'html' ); ?>
516
+ <?php self::hidden_field( "[$field_id][template]", 'custom_html' ); ?>
517
+
518
+ <div class="wpuf-form-holder">
519
+ <div class="wpuf-form-rows">
520
+ <label><?php esc_html_e( 'Title', 'wp-user-frontend' ); ?></label>
521
+ <input type="text" class="smallipopInput" title="Title of the section" name="<?php echo esc_attr( $title_name ); ?>" value="<?php echo esc_attr( $title_value ); ?>" />
522
+ </div> <!-- .wpuf-form-rows -->
523
+
524
+ <div class="wpuf-form-rows">
525
+ <label><?php esc_html_e( 'HTML Codes', 'wp-user-frontend' ); ?></label>
526
+ <textarea class="smallipopInput" title="Paste your HTML codes, WordPress shortcodes will also work here" name="<?php echo esc_attr( $html_name ); ?>" rows="10"><?php echo esc_html( $html_value ); ?></textarea>
527
+ </div>
528
+
529
+ <?php self::conditional_field( $field_id, $values ); ?>
530
+ </div> <!-- .wpuf-form-holder -->
531
+ </li>
532
+ <?php
533
+ }
534
+
535
+ public static function custom_hidden_field( $field_id, $label, $values = [] ) {
536
+ $meta_name = sprintf( '%s[%d][name]', self::$input_name, $field_id );
537
+ $value_name = sprintf( '%s[%d][meta_value]', self::$input_name, $field_id );
538
+ $is_meta_name = sprintf( '%s[%d][is_meta]', self::$input_name, $field_id );
539
+ $label_name = sprintf( '%s[%d][label]', self::$input_name, $field_id );
540
+
541
+ $meta_value = $values ? esc_attr( $values['name'] ) : '';
542
+ $value_value = $values ? esc_attr( $values['meta_value'] ) : ''; ?>
543
+ <li class="custom-field custom_hidden_field">
544
+ <?php self::legend( $label, $values, $field_id ); ?>
545
+ <?php self::hidden_field( "[$field_id][input_type]", 'hidden' ); ?>
546
+ <?php self::hidden_field( "[$field_id][template]", 'custom_hidden_field' ); ?>
547
+
548
+ <div class="wpuf-form-holder">
549
+ <div class="wpuf-form-rows">
550
+ <label><?php esc_html_e( 'Meta Key', 'wp-user-frontend' ); ?></label>
551
+ <input type="text" name="<?php echo esc_attr( $meta_name ); ?>" value="<?php echo esc_attr( $meta_value ); ?>" class="smallipopInput" title="<?php esc_html_e( 'Name of the meta key this field will save to', 'wp-user-frontend' ); ?>">
552
+ <input type="hidden" name="<?php echo esc_attr( $is_meta_name ); ?>" value="yes">
553
+ <input type="hidden" name="<?php echo esc_attr( $label_name ); ?>" value="">
554
+ </div> <!-- .wpuf-form-rows -->
555
+
556
+ <div class="wpuf-form-rows">
557
+ <label><?php esc_html_e( 'Meta Value', 'wp-user-frontend' ); ?></label>
558
+ <input type="text" class="smallipopInput" title="<?php esc_attr_e( 'Enter the meta value', 'wp-user-frontend' ); ?>" name="<?php echo esc_attr( $value_name ); ?>" value="<?php echo esc_attr( $value_value ); ?>">
559
+ </div>
560
+ </div> <!-- .wpuf-form-holder -->
561
+ </li>
562
+ <?php
563
+ }
564
+
565
+ public static function section_break( $field_id, $label, $values = [] ) {
566
+ $title_name = sprintf( '%s[%d][label]', self::$input_name, $field_id );
567
+ $description_name = sprintf( '%s[%d][description]', self::$input_name, $field_id );
568
+
569
+ $title_value = $values ? esc_attr( $values['label'] ) : '';
570
+ $description_value = $values ? esc_attr( $values['description'] ) : ''; ?>
571
+ <li class="custom-field custom_html">
572
+ <?php self::legend( $label, $values, $field_id ); ?>
573
+ <?php self::hidden_field( "[$field_id][input_type]", 'section_break' ); ?>
574
+ <?php self::hidden_field( "[$field_id][template]", 'section_break' ); ?>
575
+
576
+ <div class="wpuf-form-holder">
577
+ <div class="wpuf-form-rows">
578
+ <label><?php esc_html_e( 'Title', 'wp-user-frontend' ); ?></label>
579
+ <input type="text" class="smallipopInput" title="Title of the section" name="<?php echo esc_attr( $title_name ); ?>" value="<?php echo esc_attr( $title_value ); ?>" />
580
+ </div> <!-- .wpuf-form-rows -->
581
+
582
+ <div class="wpuf-form-rows">
583
+ <label><?php esc_html_e( 'Description', 'wp-user-frontend' ); ?></label>
584
+ <textarea class="smallipopInput" title="Some details text about the section" name="<?php echo esc_attr( $description_name ); ?>" rows="3"><?php echo esc_html( $description_value ); ?></textarea>
585
+ </div> <!-- .wpuf-form-rows -->
586
+
587
+ <?php self::conditional_field( $field_id, $values ); ?>
588
+ </div> <!-- .wpuf-form-holder -->
589
+ </li>
590
+ <?php
591
+ }
592
+
593
+ /**
594
+ * Render image upload
595
+ *
596
+ * @param $field_id
597
+ * @param $label
598
+ * @param self
599
+ * @param array $values
600
+ */
601
+ public static function image_upload( $field_id, $label, $values = [] ) {
602
+ $max_size_name = sprintf( '%s[%d][max_size]', self::$input_name, $field_id );
603
+ $max_files_name = sprintf( '%s[%d][count]', self::$input_name, $field_id );
604
+
605
+ $max_size_value = $values ? $values['max_size'] : '1024';
606
+ $max_files_value = $values ? $values['count'] : '1';
607
+
608
+ $help = esc_attr( __( 'Enter maximum upload size limit in KB', 'wp-user-frontend' ) );
609
+ $count = esc_attr( __( 'Number of images can be uploaded', 'wp-user-frontend' ) ); ?>
610
+ <li class="custom-field image_upload">
611
+ <?php self::legend( $label, $values, $field_id ); ?>
612
+ <?php self::hidden_field( "[$field_id][input_type]", 'image_upload' ); ?>
613
+ <?php self::hidden_field( "[$field_id][template]", 'image_upload' ); ?>
614
+
615
+ <div class="wpuf-form-holder">
616
+ <?php self::common( $field_id, '', true, $values ); ?>
617
+
618
+ <div class="wpuf-form-rows">
619
+ <label><?php esc_html_e( 'Max. file size', 'wp-user-frontend' ); ?></label>
620
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $max_size_name ); ?>" value="<?php echo esc_attr( $max_size_value ); ?>" title="<?php echo esc_attr( $help ); ?>">
621
+ </div> <!-- .wpuf-form-rows -->
622
+
623
+ <div class="wpuf-form-rows">
624
+ <label><?php esc_html_e( 'Max. files', 'wp-user-frontend' ); ?></label>
625
+ <input type="text" class="smallipopInput" name="<?php echo esc_attr( $max_files_name ); ?>" value="<?php echo esc_attr( $max_files_value ); ?>" title="<?php echo esc_attr( $count ); ?>">
626
+ </div> <!-- .wpuf-form-rows -->
627
+
628
+ <?php self::conditional_field( $field_id, $values ); ?>
629
+ </div> <!-- .wpuf-form-holder -->
630
+ </li>
631
+ <?php
632
+ }
633
+
634
+ /**
635
+ * Render recaptcha
636
+ *
637
+ * @param $field_id
638
+ * @param $label
639
+ * @param array $values
640
+ */
641
+ public static function recaptcha( $field_id, $label, $values = [] ) {
642
+ $title_name = sprintf( '%s[%d][label]', self::$input_name, $field_id );
643
+ $html_name = sprintf( '%s[%d][html]', self::$input_name, $field_id );
644
+ $recaptcha_type_name = sprintf( '%s[%d][recaptcha_type]', self::$input_name, $field_id );
645
+
646
+ $title_value = $values ? esc_attr( $values['label'] ) : '';
647
+ $html_value = isset( $values['html'] ) ? esc_attr( $values['html'] ) : '';
648
+ $recaptcha_type_value = isset( $values['recaptcha_type'] ) ? esc_attr( $values['recaptcha_type'] ) : ( !empty( $values ) ? '' : 'enable_no_captcha' ); ?>
649
+ <li class="custom-field custom_html">
650
+ <?php self::legend( $label, $values, $field_id ); ?>
651
+ <?php self::hidden_field( "[$field_id][input_type]", 'recaptcha' ); ?>
652
+ <?php self::hidden_field( "[$field_id][template]", 'recaptcha' ); ?>
653
+
654
+ <div class="wpuf-form-holder">
655
+ <div class="wpuf-form-rows">
656
+ <label><?php esc_html_e( 'Title', 'wp-user-frontend' ); ?></label>
657
+
658
+ <div class="wpuf-form-sub-fields">
659
+ <input type="text" class="smallipopInput" title="Title of the section" name="<?php echo esc_attr( $title_name ); ?>" value="<?php echo esc_attr( $title_value ); ?>" />
660
+
661
+ <div class="description" style="margin-top: 8px;">
662
+ <?php printf( esc_html( __( "Insert your public key and private key in <a href='%s'>plugin settings</a>. <a href='%s' target='_blank'>Register</a> first if you don't have any keys.", 'wp-user-frontend' ) ), esc_url( admin_url( 'admin.php?page=wpuf-settings' ) ), 'https://www.google.com/recaptcha/' ); ?>
663
+ </div>
664
+ </div> <!-- .wpuf-form-rows -->
665
+ </div>
666
+
667
+ <div class="wpuf-form-rows">
668
+ <label><?php esc_html_e( 'reCaptcha type', 'wp-user-frontend' ); ?></label>
669
+
670
+ <div class="wpuf-form-sub-fields">
671
+ <input type="radio" class="smallipopInput" title="reCaptcha type" name="<?php echo esc_attr( $recaptcha_type_name ); ?>" value="invisible_recaptcha" <?php echo $recaptcha_type_value == 'invisible_recaptcha' ? 'checked' : ''; ?> />
672
+ <?php esc_html_e( 'Enable Invisible reCaptcha', 'wp-user-frontend' ); ?>
673
+ </div> <!-- .wpuf-form-rows -->
674
+ <div class="wpuf-form-sub-fields">
675
+ <input type="radio" class="smallipopInput" title="reCaptcha type" name="<?php echo esc_attr( $recaptcha_type_name ); ?>" value="enable_no_captcha" <?php echo $recaptcha_type_value == 'enable_no_captcha' ? 'checked' : ''; ?> />
676
+ <?php esc_html_e( 'Enable noCaptcha', 'wp-user-frontend' ); ?>
677
+ </div> <!-- .wpuf-form-rows -->
678
+ </div>
679
+
680
+ <?php self::conditional_field( $field_id, $values ); ?>
681
+ </div> <!-- .wpuf-form-holder -->
682
+ </li>
683
+ <?php
684
+ }
685
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/tools.php CHANGED
@@ -1,18 +1,20 @@
1
  <?php
2
 
3
- if ( ! class_exists( 'WPUF_Admin_Tools' ) ) {
4
  require_once WPUF_ROOT . '/admin/class-tools.php';
5
  }
6
 
7
- $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'tools';
8
  $tools = new WPUF_Admin_Tools();
9
  ?>
10
 
11
  <div class="wrap">
12
  <h2 class="nav-tab-wrapper">
13
- <a class="nav-tab <?php echo ( $tab == 'tools' ) ? 'nav-tab-active' : ''; ?>" href="<?php echo add_query_arg( array( 'page' => 'wpuf_tools', 'tab' => 'tools' ), admin_url( 'admin.php' ) ); ?>"><?php _e( 'Tools', 'wp-user-frontend' ); ?></a>
14
- <a class="nav-tab <?php echo ( $tab == 'import' ) ? 'nav-tab-active' : ''; ?>" href="<?php echo add_query_arg( array( 'page' => 'wpuf_tools', 'tab' => 'import' ), admin_url( 'admin.php' ) ); ?>"><?php _e( 'Import', 'wp-user-frontend' ); ?></a>
15
- <a class="nav-tab <?php echo ( $tab == 'export' ) ? 'nav-tab-active' : ''; ?>" href="<?php echo add_query_arg( array( 'page' => 'wpuf_tools', 'tab' => 'export' ), admin_url( 'admin.php' ) ); ?>"><?php _e( 'Export', 'wp-user-frontend' ); ?></a>
 
 
16
  </h2>
17
 
18
  <?php
1
  <?php
2
 
3
+ if ( !class_exists( 'WPUF_Admin_Tools' ) ) {
4
  require_once WPUF_ROOT . '/admin/class-tools.php';
5
  }
6
 
7
+ $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'tools';
8
  $tools = new WPUF_Admin_Tools();
9
  ?>
10
 
11
  <div class="wrap">
12
  <h2 class="nav-tab-wrapper">
13
+ <a class="nav-tab <?php echo ( $tab == 'tools' ) ? 'nav-tab-active' : ''; ?>" href="<?php echo esc_url( add_query_arg( [ 'page' => 'wpuf_tools', 'tab' => 'tools' ], admin_url( 'admin.php' ) ) ); ?>"><?php esc_html_e( 'Tools', 'wp-user-frontend' ); ?></a>
14
+
15
+ <a class="nav-tab <?php echo ( $tab == 'import' ) ? 'nav-tab-active' : ''; ?>" href="<?php echo esc_url( add_query_arg( [ 'page' => 'wpuf_tools', 'tab' => 'import' ], admin_url( 'admin.php' ) ) ); ?>"><?php esc_html_e( 'Import', 'wp-user-frontend' ); ?></a>
16
+
17
+ <a class="nav-tab <?php echo ( $tab == 'export' ) ? 'nav-tab-active' : ''; ?>" href="<?php echo esc_url( add_query_arg( [ 'page' => 'wpuf_tools', 'tab' => 'export' ], admin_url( 'admin.php' ) ) ); ?>"><?php esc_html_e( 'Export', 'wp-user-frontend' ); ?></a>
18
  </h2>
19
 
20
  <?php
admin/transactions.php CHANGED
@@ -1,5 +1,5 @@
1
  <div class="wrap">
2
- <h2><?php _e( 'Transactions', 'wp-user-frontend' ); ?></h2>
3
 
4
  <?php
5
  global $wpdb;
1
  <div class="wrap">
2
+ <h2><?php esc_html_e( 'Transactions', 'wp-user-frontend' ); ?></h2>
3
 
4
  <?php
5
  global $wpdb;
admin/weforms.php CHANGED
@@ -1,20 +1,20 @@
1
  <div class="wrap about-wrap">
2
- <h1><?php _e( 'weForms', 'wp-user-frontend' ); ?></h1>
3
 
4
- <p class="about-text"><?php _e( 'The Easiest &amp; Fastest Contact Form Plugin on WordPress', 'wp-user-frontend' ) ?></p>
5
 
6
  <hr>
7
- <p><?php _e( 'Quickly create rich contact forms to generate leads, taking feedbacks, onboarding visitors and flourishing <br /> your imagination! Comes with the best frontend post submission plugin for WordPress, WP User Frontend.', 'wp-user-frontend' ) ?>
8
 
9
 
10
  <div class="install" id="wpuf-weforms-installer-notice" style="padding: 1em 0; position: relative;">
11
  <p>
12
- <button id="wpuf-weforms-installer" class="button button-primary"><?php _e( 'Install Now', 'wp-user-frontend' ); ?></button>
13
  </p>
14
  </div>
15
 
16
  <figure class="we-gif" style="width: 944px;">
17
- <img class="img-responsive inline-block image-gif shadow" src="https://wedevs-com-wedevs.netdna-ssl.com/wp-content/uploads/2017/08/weforms-final-promo-video.gif" >
18
  </figure>
19
  </div>
20
 
@@ -30,7 +30,7 @@
30
  self.text('<?php echo esc_js( 'Installing...', 'weforms' ); ?>');
31
  var data = {
32
  action: 'wpuf_weforms_install',
33
- _wpnonce: '<?php echo wp_create_nonce('wpuf-weforms-installer-nonce'); ?>'
34
  };
35
 
36
  $.post(ajaxurl, data, function (response) {
@@ -39,7 +39,7 @@
39
  self.removeClass('install-now updating-message');
40
  self.text('<?php echo esc_js( 'Installed', 'weforms' ); ?>');
41
 
42
- window.location.href = '<?php echo admin_url( 'admin.php?page=weforms' ); ?>';
43
  }
44
  });
45
  });
1
  <div class="wrap about-wrap">
2
+ <h1><?php esc_html_e( 'weForms', 'wp-user-frontend' ); ?></h1>
3
 
4
+ <p class="about-text"><?php esc_html_e( 'The Easiest &amp; Fastest Contact Form Plugin on WordPress', 'wp-user-frontend' ); ?></p>
5
 
6
  <hr>
7
+ <p><?php echo wp_kses_post( __( 'Quickly create rich contact forms to generate leads, taking feedbacks, onboarding visitors and flourishing <br /> your imagination! Comes with the best frontend post submission plugin for WordPress, WP User Frontend.', 'wp-user-frontend' ) ); ?>
8
 
9
 
10
  <div class="install" id="wpuf-weforms-installer-notice" style="padding: 1em 0; position: relative;">
11
  <p>
12
+ <button id="wpuf-weforms-installer" class="button button-primary"><?php esc_html_e( 'Install Now', 'wp-user-frontend' ); ?></button>
13
  </p>
14
  </div>
15
 
16
  <figure class="we-gif" style="width: 944px;">
17
+ <img class="img-responsive inline-block image-gif shadow" src="esc_url(https://wedevs-com-wedevs.netdna-ssl.com/wp-content/uploads/2017/08/weforms-final-promo-video.gif )" >
18
  </figure>
19
  </div>
20
 
30
  self.text('<?php echo esc_js( 'Installing...', 'weforms' ); ?>');
31
  var data = {
32
  action: 'wpuf_weforms_install',
33
+ _wpnonce: '<?php echo esc_html( wp_create_nonce( 'wpuf-weforms-installer-nonce' ) ); ?>'
34
  };
35
 
36
  $.post(ajaxurl, data, function (response) {
39
  self.removeClass('install-now updating-message');
40
  self.text('<?php echo esc_js( 'Installed', 'weforms' ); ?>');
41
 
42
+ window.location.href = '<?php echo esc_url( admin_url( 'admin.php?page=weforms' ) ); ?>';
43
  }
44
  });
45
  });
assets/css/admin.css CHANGED
File without changes
assets/css/chosen/chosen-sprite.png CHANGED
File without changes
assets/css/chosen/chosen-sprite@2x.png CHANGED
File without changes
assets/css/chosen/chosen.css CHANGED
File without changes
assets/css/frontend-forms.css CHANGED
File without changes
assets/css/images/ui-bg_diagonals-small_75_cccccc_40x40.png CHANGED
File without changes
assets/css/images/ui-bg_flat_0_aaaaaa_40x100.png CHANGED
File without changes
assets/css/images/ui-bg_flat_0_ffffff_40x100.png CHANGED
File without changes
assets/css/images/ui-bg_flat_75_ffffff_40x100.png CHANGED
File without changes
assets/css/images/ui-bg_glass_55_fbf9ee_1x400.png CHANGED
File without changes
assets/css/images/ui-bg_glass_65_ffffff_1x400.png CHANGED
File without changes
assets/css/images/ui-bg_glass_75_dadada_1x400.png CHANGED
File without changes
assets/css/images/ui-bg_glass_75_e6e6e6_1x400.png CHANGED
File without changes
assets/css/images/ui-bg_glass_95_fef1ec_1x400.png CHANGED
File without changes
assets/css/images/ui-icons_222222_256x240.png CHANGED
File without changes
assets/css/images/ui-icons_2e83ff_256x240.png CHANGED
File without changes
assets/css/images/ui-icons_454545_256x240.png CHANGED
File without changes
assets/css/images/ui-icons_888888_256x240.png CHANGED
File without changes
assets/css/images/ui-icons_cd0a0a_256x240.png CHANGED
File without changes
assets/css/jquery-ui-1.9.1.custom.css CHANGED
File without changes
assets/css/jquery.smallipop.css CHANGED
File without changes
assets/css/wpuf.css CHANGED
File without changes
assets/images/add.png CHANGED
File without changes
assets/images/arrow-move.png CHANGED
File without changes
assets/images/arrows.png CHANGED
File without changes
assets/images/completed.png CHANGED
File without changes
assets/images/cross.png CHANGED
File without changes
assets/images/del.png CHANGED
File without changes
assets/images/delete.png CHANGED
File without changes
assets/images/edit.png CHANGED
File without changes
assets/images/help.png CHANGED
File without changes
assets/images/help/bugs.svg CHANGED
File without changes
assets/images/help/customization.svg CHANGED
File without changes
assets/images/help/docs.svg CHANGED
File without changes
assets/images/help/like.svg CHANGED
File without changes
assets/images/help/support.svg CHANGED
File without changes
assets/images/icon-128x128.png CHANGED
File without changes
assets/images/no-image.png CHANGED
File without changes
assets/images/paypal.png CHANGED
File without changes
assets/images/processing.png CHANGED
File without changes
assets/images/remove.png CHANGED
File without changes
assets/images/tick.png CHANGED
File without changes
assets/images/wpspin_light.gif CHANGED
File without changes
assets/js-templates/form-components.php CHANGED
@@ -1,7 +1,7 @@
1
  <script type="text/x-template" id="tmpl-wpuf-builder-stage">
2
  <div id="form-preview-stage" class="wpuf-style">
3
  <h4 v-if="!form_fields.length" class="text-center">
4
- <?php _e( 'Add fields by dragging the fields from the right sidebar to this area.', 'wp-user-frontend' ) ?>
5
  </h4>
6
 
7
  <ul :class="['wpuf-form', 'sortable-list', 'form-label-' + label_type]">
@@ -58,7 +58,7 @@
58
  v-for="(field, index) in hidden_fields"
59
  :class="['field-items', parseInt(editing_form_id) === parseInt(field.id) ? 'current-editing' : '']"
60
  >
61
- <strong><?php _e('key', 'wp-user-frontend'); ?></strong>: {{ field.name }} | <strong><?php _e( 'value', 'wp-user-frontend' ); ?></strong>: {{ field.meta_value }}
62
 
63
  <div class="control-buttons">
64
  <p>
@@ -130,7 +130,7 @@
130
  </div>
131
 
132
  <div v-if="show_value" class="value">
133
- <?php _e( 'Value', 'wp-user-frontend' ) ?>
134
  </div>
135
 
136
  <div class="action-buttons">&nbsp;</div>
@@ -349,22 +349,20 @@
349
 
350
  <div v-if="'logged_in' === selected" class="condiotional-logic-container">
351
 
352
- <?php $roles = get_editable_roles() ?>
353
 
354
  <ul>
355
  <?php
356
- foreach ($roles as $role => $value) {
 
357
 
358
- $role_name = $value['name'];
 
 
359
 
360
- $output = "<li>";
361
- $output .= "<label><input type='checkbox' v-model='choices' value='{$role}'> {$role_name} </label>";
362
- $output .= "</li>";
363
-
364
- echo $output;
365
-
366
- }
367
- ?>
368
  </ul>
369
  </div>
370
 
@@ -377,14 +375,12 @@
377
  $subscriptions = WPUF_Subscription::init()->get_subscriptions();
378
 
379
  if ( $subscriptions ) {
380
- foreach ($subscriptions as $pack) {
381
-
382
- $output = "<li>";
383
  $output .= "<label><input type='checkbox' v-model='choices' value='{$pack->ID}' > {$pack->post_title} </label>";
384
- $output .= "</li>";
385
 
386
  echo $output;
387
-
388
  }
389
  } else {
390
  _e( 'No subscription plan found.', 'wp-user-frontend' );
@@ -713,7 +709,7 @@
713
 
714
  <template v-else>
715
  <div v-if="'invisible_recaptcha' != field.recaptcha_type">
716
- <img class="wpuf-recaptcha-placeholder" src="<?php echo WPUF_ASSET_URI . '/images/recaptcha-placeholder.png' ?>" alt="">
717
  </div>
718
  <div v-else><p><?php _e( 'Invisible reCaptcha', 'wp-user-frontend' ); ?></p></div>
719
  </template>
1
  <script type="text/x-template" id="tmpl-wpuf-builder-stage">
2
  <div id="form-preview-stage" class="wpuf-style">
3
  <h4 v-if="!form_fields.length" class="text-center">
4
+ <?php _e( 'Add fields by dragging the fields from the right sidebar to this area.', 'wp-user-frontend' ); ?>
5
  </h4>
6
 
7
  <ul :class="['wpuf-form', 'sortable-list', 'form-label-' + label_type]">
58
  v-for="(field, index) in hidden_fields"
59
  :class="['field-items', parseInt(editing_form_id) === parseInt(field.id) ? 'current-editing' : '']"
60
  >
61
+ <strong><?php _e( 'key', 'wp-user-frontend' ); ?></strong>: {{ field.name }} | <strong><?php _e( 'value', 'wp-user-frontend' ); ?></strong>: {{ field.meta_value }}
62
 
63
  <div class="control-buttons">
64
  <p>
130
  </div>
131
 
132
  <div v-if="show_value" class="value">
133
+ <?php _e( 'Value', 'wp-user-frontend' ); ?>
134
  </div>
135
 
136
  <div class="action-buttons">&nbsp;</div>
349
 
350
  <div v-if="'logged_in' === selected" class="condiotional-logic-container">
351
 
352
+ <?php $roles = get_editable_roles(); ?>
353
 
354
  <ul>
355
  <?php
356
+ foreach ( $roles as $role => $value ) {
357
+ $role_name = $value['name'];
358
 
359
+ $output = '<li>';
360
+ $output .= "<label><input type='checkbox' v-model='choices' value='{$role}'> {$role_name} </label>";
361
+ $output .= '</li>';
362
 
363
+ echo $output;
364
+ }
365
+ ?>
 
 
 
 
 
366
  </ul>
367
  </div>
368
 
375
  $subscriptions = WPUF_Subscription::init()->get_subscriptions();
376
 
377
  if ( $subscriptions ) {
378
+ foreach ( $subscriptions as $pack ) {
379
+ $output = '<li>';
 
380
  $output .= "<label><input type='checkbox' v-model='choices' value='{$pack->ID}' > {$pack->post_title} </label>";
381
+ $output .= '</li>';
382
 
383
  echo $output;
 
384
  }
385
  } else {
386
  _e( 'No subscription plan found.', 'wp-user-frontend' );
709
 
710
  <template v-else>
711
  <div v-if="'invisible_recaptcha' != field.recaptcha_type">
712
+ <img class="wpuf-recaptcha-placeholder" src="<?php echo WPUF_ASSET_URI . '/images/recaptcha-placeholder.png'; ?>" alt="">
713
  </div>
714
  <div v-else><p><?php _e( 'Invisible reCaptcha', 'wp-user-frontend' ); ?></p></div>
715
  </template>
assets/js/chosen.jquery.js CHANGED
File without changes
assets/js/conditional.js CHANGED
File without changes
assets/js/frontend-form.js CHANGED
File without changes
assets/js/frontend-form.min.js CHANGED
File without changes
assets/js/jquery-ui-timepicker-addon.js CHANGED
File without changes
assets/js/jquery.smallipop-0.4.0.min.js CHANGED
File without changes
assets/js/jquery.validate.min.js CHANGED
File without changes
assets/js/subscriptions.js CHANGED
@@ -72,7 +72,8 @@
72
  {
73
  'action' : 'wpuf_delete_user_package',
74
  'userid' : userid,
75
- 'packid' : packid
 
76
  },
77
  function(data){
78
  if(data){
72
  {
73
  'action' : 'wpuf_delete_user_package',
74
  'userid' : userid,
75
+ 'packid' : packid,
76
+ 'wpuf_subscription_delete_nonce': '<?php echo wp_create_nonce("wpuf-subscription-delete-nonce"); ?>'
77
  },
78
  function(data){
79
  if(data){
assets/js/upload.js CHANGED
File without changes
assets/js/upload.min.js CHANGED
File without changes
class/admin-asset-loader.php CHANGED
@@ -5,9 +5,9 @@
5
  */
6
  class WPUF_Admin_Assets {
7
 
8
- function __construct() {
9
- add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) );
10
- add_action( 'wp_enqueue_style', array( $this, 'register_admin_styles' ) );
11
  }
12
 
13
  /**
@@ -19,26 +19,24 @@ class WPUF_Admin_Assets {
19
  global $post;
20
  $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
21
 
22
- wp_register_script( 'wpuf-vue', WPUF_ASSET_URI . '/vendor/vue/vue' . $prefix . '.js', array(), WPUF_VERSION, true );
23
- wp_register_script( 'wpuf-vuex', WPUF_ASSET_URI . '/vendor/vuex/vuex' . $prefix . '.js', array( 'wpuf-vue' ), WPUF_VERSION, true );
24
- wp_register_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', array(), WPUF_VERSION, true );
25
- wp_register_script( 'wpuf-jquery-scrollTo', WPUF_ASSET_URI . '/vendor/jquery.scrollTo/jquery.scrollTo' . $prefix . '.js', array( 'jquery' ), WPUF_VERSION, true );
26
- wp_register_script( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/js/standalone/selectize' . $prefix . '.js', array( 'jquery' ), WPUF_VERSION, true );
27
- wp_register_script( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr' . $prefix . '.js', array(), WPUF_VERSION, true );
28
- wp_register_script( 'wpuf-clipboard', WPUF_ASSET_URI . '/vendor/clipboard/clipboard' . $prefix . '.js', array(), WPUF_VERSION, true );
29
- wp_register_script( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip' . $prefix . '.js', array(), WPUF_VERSION, true );
30
 
31
- $form_builder_js_deps = apply_filters( 'wpuf-form-builder-js-deps', array(
32
  'jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'underscore',
33
  'wpuf-vue', 'wpuf-vuex', 'wpuf-sweetalert2', 'wpuf-jquery-scrollTo',
34
- 'wpuf-selectize', 'wpuf-toastr', 'wpuf-clipboard', 'wpuf-tooltip'
35
- ) );
36
 
37
  wp_register_script( 'wpuf-form-builder-mixins', WPUF_ASSET_URI . '/js/wpuf-form-builder-mixins.js', $form_builder_js_deps, WPUF_VERSION, true );
38
-
39
- wp_register_script( 'wpuf-form-builder-components', WPUF_ASSET_URI . '/js/wpuf-form-builder-components.js', array( 'wpuf-form-builder-mixins' ), WPUF_VERSION, true );
40
-
41
- wp_register_script( 'wpuf-form-builder', WPUF_ASSET_URI . '/js/wpuf-form-builder.js', array( 'wpuf-form-builder-components' ), WPUF_VERSION, true );
42
 
43
  /*
44
  * Data required for building the form
@@ -46,26 +44,26 @@ class WPUF_Admin_Assets {
46
  require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-form-builder-field-settings.php';
47
  require_once WPUF_ROOT . '/includes/free/prompt.php';
48
 
49
- $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', array(
50
  'post' => $post,
51
  'form_fields' => wpuf_get_form_fields( $post->ID ),
52
  'field_settings' => wpuf()->fields->get_js_settings(),
53
  'notifications' => wpuf_get_form_notifications( $post->ID ),
54
  'pro_link' => WPUF_Pro_Prompt::get_pro_url(),
55
- 'site_url' => site_url('/'),
56
  'recaptcha_site' => wpuf_get_option( 'recaptcha_public', 'wpuf_general' ),
57
  'recaptcha_secret' => wpuf_get_option( 'recaptcha_private', 'wpuf_general' ),
58
- ) );
59
 
60
  wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
61
 
62
  // mixins
63
- $wpuf_mixins = array(
64
- 'root' => apply_filters( 'wpuf-form-builder-js-root-mixins', array() ),
65
- 'builder_stage' => apply_filters( 'wpuf-form-builder-js-builder-stage-mixins', array() ),
66
- 'form_fields' => apply_filters( 'wpuf-form-builder-js-form-fields-mixins', array() ),
67
- 'field_options' => apply_filters( 'wpuf-form-builder-js-field-options-mixins', array() ),
68
- );
69
 
70
  wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
71
  }
@@ -77,16 +75,16 @@ class WPUF_Admin_Assets {
77
  */
78
  public function register_admin_styles() {
79
  wp_register_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
80
- wp_register_style( 'wpuf-font-awesome', WPUF_ASSET_URI . '/vendor/font-awesome/css/font-awesome.min.css', array(), WPUF_VERSION );
81
- wp_register_style( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.css', array(), WPUF_VERSION );
82
- wp_register_style( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/css/selectize.default.css', array(), WPUF_VERSION );
83
- wp_register_style( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr.min.css', array(), WPUF_VERSION );
84
- wp_register_style( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip.css', array(), WPUF_VERSION );
85
 
86
- $form_builder_css_deps = apply_filters( 'wpuf-form-builder-css-deps', array(
87
- 'wpuf-css', 'wpuf-font-awesome', 'wpuf-sweetalert2', 'wpuf-selectize', 'wpuf-toastr', 'wpuf-tooltip'
88
- ) );
89
 
90
  wp_register_style( 'wpuf-form-builder', WPUF_ASSET_URI . '/css/wpuf-form-builder.css', $form_builder_css_deps, WPUF_VERSION );
91
  }
92
- }
5
  */
6
  class WPUF_Admin_Assets {
7
 
8
+ public function __construct() {
9
+ add_action( 'admin_enqueue_scripts', [ $this, 'register_admin_scripts' ] );
10
+ add_action( 'wp_enqueue_style', [ $this, 'register_admin_styles' ] );
11
  }
12
 
13
  /**
19
  global $post;
20
  $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
21
 
22
+ wp_register_script( 'wpuf-vue', WPUF_ASSET_URI . '/vendor/vue/vue' . $prefix . '.js', [], WPUF_VERSION, true );
23
+ wp_register_script( 'wpuf-vuex', WPUF_ASSET_URI . '/vendor/vuex/vuex' . $prefix . '.js', [ 'wpuf-vue' ], WPUF_VERSION, true );
24
+ wp_register_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', [], WPUF_VERSION, true );
25
+ wp_register_script( 'wpuf-jquery-scrollTo', WPUF_ASSET_URI . '/vendor/jquery.scrollTo/jquery.scrollTo' . $prefix . '.js', [ 'jquery' ], WPUF_VERSION, true );
26
+ wp_register_script( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/js/standalone/selectize' . $prefix . '.js', [ 'jquery' ], WPUF_VERSION, true );
27
+ wp_register_script( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr' . $prefix . '.js', [], WPUF_VERSION, true );
28
+ wp_register_script( 'wpuf-clipboard', WPUF_ASSET_URI . '/vendor/clipboard/clipboard' . $prefix . '.js', [], WPUF_VERSION, true );
29
+ wp_register_script( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip' . $prefix . '.js', [], WPUF_VERSION, true );
30
 
31
+ $form_builder_js_deps = apply_filters( 'wpuf-form-builder-js-deps', [
32
  'jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'underscore',
33
  'wpuf-vue', 'wpuf-vuex', 'wpuf-sweetalert2', 'wpuf-jquery-scrollTo',
34
+ 'wpuf-selectize', 'wpuf-toastr', 'wpuf-clipboard', 'wpuf-tooltip',
35
+ ] );
36
 
37
  wp_register_script( 'wpuf-form-builder-mixins', WPUF_ASSET_URI . '/js/wpuf-form-builder-mixins.js', $form_builder_js_deps, WPUF_VERSION, true );
38
+ wp_register_script( 'wpuf-form-builder-components', WPUF_ASSET_URI . '/js/wpuf-form-builder-components.js', [ 'wpuf-form-builder-mixins' ], WPUF_VERSION, true );
39
+ wp_register_script( 'wpuf-form-builder', WPUF_ASSET_URI . '/js/wpuf-form-builder.js', [ 'wpuf-form-builder-components' ], WPUF_VERSION, true );
 
 
40
 
41
  /*
42
  * Data required for building the form
44
  require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-form-builder-field-settings.php';
45
  require_once WPUF_ROOT . '/includes/free/prompt.php';
46
 
47
+ $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', [
48
  'post' => $post,
49
  'form_fields' => wpuf_get_form_fields( $post->ID ),
50
  'field_settings' => wpuf()->fields->get_js_settings(),
51
  'notifications' => wpuf_get_form_notifications( $post->ID ),
52
  'pro_link' => WPUF_Pro_Prompt::get_pro_url(),
53
+ 'site_url' => site_url( '/' ),
54
  'recaptcha_site' => wpuf_get_option( 'recaptcha_public', 'wpuf_general' ),
55
  'recaptcha_secret' => wpuf_get_option( 'recaptcha_private', 'wpuf_general' ),
56
+ ] );
57
 
58
  wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
59
 
60
  // mixins
61
+ $wpuf_mixins = [
62
+ 'root' => apply_filters( 'wpuf-form-builder-js-root-mixins', [] ),
63
+ 'builder_stage' => apply_filters( 'wpuf-form-builder-js-builder-stage-mixins', [] ),
64
+ 'form_fields' => apply_filters( 'wpuf-form-builder-js-form-fields-mixins', [] ),
65
+ 'field_options' => apply_filters( 'wpuf-form-builder-js-field-options-mixins', [] ),
66
+ ];
67
 
68
  wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
69
  }
75
  */
76
  public function register_admin_styles() {
77
  wp_register_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
78
+ wp_register_style( 'wpuf-font-awesome', WPUF_ASSET_URI . '/vendor/font-awesome/css/font-awesome.min.css', [], WPUF_VERSION );
79
+ wp_register_style( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.css', [], WPUF_VERSION );
80
+ wp_register_style( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/css/selectize.default.css', [], WPUF_VERSION );
81
+ wp_register_style( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr.min.css', [], WPUF_VERSION );
82
+ wp_register_style( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip.css', [], WPUF_VERSION );
83
 
84
+ $form_builder_css_deps = apply_filters( 'wpuf-form-builder-css-deps', [
85
+ 'wpuf-css', 'wpuf-font-awesome', 'wpuf-sweetalert2', 'wpuf-selectize', 'wpuf-toastr', 'wpuf-tooltip',
86
+ ] );
87
 
88
  wp_register_style( 'wpuf-form-builder', WPUF_ASSET_URI . '/css/wpuf-form-builder.css', $form_builder_css_deps, WPUF_VERSION );
89
  }
90
+ }
class/asset-loader.php CHANGED
@@ -5,9 +5,9 @@
5
  */
6
  class WPUF_Assets {
7
 
8
- function __construct() {
9
- add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
10
- add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ) );
11
  }
12
 
13
  /**
@@ -17,14 +17,15 @@ class WPUF_Assets {
17
  */
18
  public function register_scripts() {
19
  global $post;
20
- $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
21
- $scheme = is_ssl() ? 'https' : 'http';
22
  $api_key = wpuf_get_option( 'gmap_api_key', 'wpuf_general' );
23
 
24
  if ( !empty( $api_key ) ) {
25
- wp_register_script( 'google-maps', $scheme . '://maps.google.com/maps/api/js?libraries=places&key=' . $api_key, array(), null );
26
  }
27
- if ( isset ( $post->ID ) ) {
 
28
  ?>
29
  <script type="text/javascript" id="wpuf-language-script">
30
  var error_str_obj = {
@@ -34,13 +35,13 @@ class WPUF_Assets {
34
  }
35
  </script>
36
  <?php
37
- wp_register_script( 'wpuf-form', WPUF_ASSET_URI . '/js/frontend-form' . $prefix . '.js', array('jquery') );
38
  }
39
- wp_register_script( 'wpuf-subscriptions', WPUF_ASSET_URI . '/js/subscriptions.js', array('jquery'), false, true );
40
- wp_register_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker') );
41
- wp_register_script( 'wpuf-upload', WPUF_ASSET_URI . '/js/upload.js', array('jquery', 'plupload-handlers') );
42
 
43
- wp_localize_script( 'wpuf-form', 'wpuf_frontend', array(
44
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
45
  'error_message' => __( 'Please fix the errors to proceed', 'wp-user-frontend' ),
46
  'nonce' => wp_create_nonce( 'wpuf_nonce' ),
@@ -48,34 +49,34 @@ class WPUF_Assets {
48
  'cancelSubMsg' => __( 'Are you sure you want to cancel your current subscription ?', 'wp-user-frontend' ),
49
  'delete_it' => __( 'Yes', 'wp-user-frontend' ),
50
  'cancel_it' => __( 'No', 'wp-user-frontend' ),
51
- ) );
52
 
53
- wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', array(
54
  'confirmMsg' => __( 'Are you sure?', 'wp-user-frontend' ),
55
  'delete_it' => __( 'Yes, delete it', 'wp-user-frontend' ),
56
  'cancel_it' => __( 'No, cancel it', 'wp-user-frontend' ),
57
  'nonce' => wp_create_nonce( 'wpuf_nonce' ),
58
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
59
- 'plupload' => array(
60
  'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
61
  'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
62
- 'filters' => array(array('title' => __( 'Allowed Files', 'wp-user-frontend' ), 'extensions' => '*')),
63
  'multipart' => true,
64
  'urlstream_upload' => true,
65
  'warning' => __( 'Maximum number of files reached!', 'wp-user-frontend' ),
66
  'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'wp-user-frontend' ),
67
- 'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'wp-user-frontend' )
68
- )
69
- ));
70
 
71
- wp_register_script( 'wpuf-vue', WPUF_ASSET_URI . '/vendor/vue/vue' . $prefix . '.js', array(), WPUF_VERSION, true );
72
- wp_register_script( 'wpuf-vuex', WPUF_ASSET_URI . '/vendor/vuex/vuex' . $prefix . '.js', array( 'wpuf-vue' ), WPUF_VERSION, true );
73
- wp_register_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', array(), WPUF_VERSION, true );
74
- wp_register_script( 'wpuf-jquery-scrollTo', WPUF_ASSET_URI . '/vendor/jquery.scrollTo/jquery.scrollTo' . $prefix . '.js', array( 'jquery' ), WPUF_VERSION, true );
75
- wp_register_script( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/js/standalone/selectize' . $prefix . '.js', array( 'jquery' ), WPUF_VERSION, true );
76
- wp_register_script( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr' . $prefix . '.js', array(), WPUF_VERSION, true );
77
- wp_register_script( 'wpuf-clipboard', WPUF_ASSET_URI . '/vendor/clipboard/clipboard' . $prefix . '.js', array(), WPUF_VERSION, true );
78
- wp_register_script( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip' . $prefix . '.js', array(), WPUF_VERSION, true );
79
  }
80
 
81
  /**
@@ -87,4 +88,4 @@ class WPUF_Assets {
87
  wp_register_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
88
  wp_register_style( 'jquery-ui', WPUF_ASSET_URI . '/css/jquery-ui-1.9.1.custom.css' );
89
  }
90
- }
5
  */
6
  class WPUF_Assets {
7
 
8
+ public function __construct() {
9
+ add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ] );
10
+ add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ] );
11
  }
12
 
13
  /**
17
  */
18
  public function register_scripts() {
19
  global $post;
20
+ $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
21
+ $scheme = is_ssl() ? 'https' : 'http';
22
  $api_key = wpuf_get_option( 'gmap_api_key', 'wpuf_general' );
23
 
24
  if ( !empty( $api_key ) ) {
25
+ wp_register_script( 'google-maps', $scheme . '://maps.google.com/maps/api/js?libraries=places&key=' . $api_key, [], null );
26
  }
27
+
28
+ if ( isset( $post->ID ) ) {
29
  ?>
30
  <script type="text/javascript" id="wpuf-language-script">
31
  var error_str_obj = {
35
  }
36
  </script>
37
  <?php
38
+ wp_register_script( 'wpuf-form', WPUF_ASSET_URI . '/js/frontend-form' . $prefix . '.js', ['jquery'] );
39
  }
40
+ wp_register_script( 'wpuf-subscriptions', WPUF_ASSET_URI . '/js/subscriptions.js', ['jquery'], false, true );
41
+ wp_register_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', ['jquery-ui-datepicker'] );
42
+ wp_register_script( 'wpuf-upload', WPUF_ASSET_URI . '/js/upload.js', ['jquery', 'plupload-handlers'] );
43
 
44
+ wp_localize_script( 'wpuf-form', 'wpuf_frontend', [
45
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
46
  'error_message' => __( 'Please fix the errors to proceed', 'wp-user-frontend' ),
47
  'nonce' => wp_create_nonce( 'wpuf_nonce' ),
49
  'cancelSubMsg' => __( 'Are you sure you want to cancel your current subscription ?', 'wp-user-frontend' ),
50
  'delete_it' => __( 'Yes', 'wp-user-frontend' ),
51
  'cancel_it' => __( 'No', 'wp-user-frontend' ),
52
+ ] );
53
 
54
+ wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', [
55
  'confirmMsg' => __( 'Are you sure?', 'wp-user-frontend' ),
56
  'delete_it' => __( 'Yes, delete it', 'wp-user-frontend' ),
57
  'cancel_it' => __( 'No, cancel it', 'wp-user-frontend' ),
58
  'nonce' => wp_create_nonce( 'wpuf_nonce' ),
59
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
60
+ 'plupload' => [
61
  'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
62
  'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
63
+ 'filters' => [['title' => __( 'Allowed Files', 'wp-user-frontend' ), 'extensions' => '*']],
64
  'multipart' => true,
65
  'urlstream_upload' => true,
66
  'warning' => __( 'Maximum number of files reached!', 'wp-user-frontend' ),
67
  'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'wp-user-frontend' ),
68
+ 'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'wp-user-frontend' ),
69
+ ],
70
+ ] );
71
 
72
+ wp_register_script( 'wpuf-vue', WPUF_ASSET_URI . '/vendor/vue/vue' . $prefix . '.js', [], WPUF_VERSION, true );
73
+ wp_register_script( 'wpuf-vuex', WPUF_ASSET_URI . '/vendor/vuex/vuex' . $prefix . '.js', [ 'wpuf-vue' ], WPUF_VERSION, true );
74
+ wp_register_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', [], WPUF_VERSION, true );
75
+ wp_register_script( 'wpuf-jquery-scrollTo', WPUF_ASSET_URI . '/vendor/jquery.scrollTo/jquery.scrollTo' . $prefix . '.js', [ 'jquery' ], WPUF_VERSION, true );
76
+ wp_register_script( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/js/standalone/selectize' . $prefix . '.js', [ 'jquery' ], WPUF_VERSION, true );
77
+ wp_register_script( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr' . $prefix . '.js', [], WPUF_VERSION, true );
78
+ wp_register_script( 'wpuf-clipboard', WPUF_ASSET_URI . '/vendor/clipboard/clipboard' . $prefix . '.js', [], WPUF_VERSION, true );
79
+ wp_register_script( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip' . $prefix . '.js', [], WPUF_VERSION, true );
80
  }
81
 
82
  /**
88
  wp_register_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
89
  wp_register_style( 'jquery-ui', WPUF_ASSET_URI . '/css/jquery-ui-1.9.1.custom.css' );
90
  }
91
+ }
class/frontend-account.php CHANGED
@@ -4,24 +4,24 @@
4
  * Dashboard class
5
  *
6
  * @author Tareq Hasan
7
- * @package WP User Frontend
8
  */
9
  class WPUF_Frontend_Account {
10
 
11
  /**
 
12
  * Class constructor
13
  */
14
  public function __construct() {
15
- add_shortcode( 'wpuf_account', array( $this, 'shortcode' ) );
16
- add_action( 'wpuf_account_content_dashboard', array( $this, 'dashboard_section' ), 10, 2 );
17
- add_action( 'wpuf_account_content_posts', array( $this, 'posts_section' ), 10, 2 );
18
- add_action( 'wpuf_account_content_subscription', array( $this, 'subscription_section' ), 10, 2 );
19
- add_action( 'wpuf_account_content_edit-profile', array( $this, 'edit_profile_section' ), 10, 2 );
20
- add_action( 'wpuf_account_content_billing-address', array( $this, 'billing_address_section' ), 10, 2 );
21
- add_action( 'wp_ajax_wpuf_account_update_profile', array( $this, 'update_profile' ) );
22
- add_filter( 'wpuf_options_wpuf_my_account', array( $this, 'add_settings_options' ) );
23
- add_filter( 'wpuf_account_sections', array( $this, 'add_account_sections' ) );
24
- add_action( 'wpuf_account_content_submit-post', array( $this, 'submit_post_section' ), 10, 2 );
25
  }
26
 
27
  /**
@@ -32,29 +32,29 @@ class WPUF_Frontend_Account {
32
  * @since 2.9.0
33
  */
34
  public function add_settings_options( $options ) {
35
- $options[] = array(
36
- 'name' => 'allow_post_submission',
37
- 'label' => __( 'Post Submission', 'wp-user-frontend' ),
38
- 'desc' => __( 'Enable if you want to allow users to submit post from the account page.', 'wp-user-frontend' ),
39
- 'type' => 'checkbox',
40
  'default' => 'on',
41
- );
42
 
43
- $options[] = array(
44
- 'name' => 'post_submission_label',
45
- 'label' => __( 'Submission Menu Label', 'wp-user-frontend' ),
46
- 'desc' => __( 'Label for post submission menu', 'wp-user-frontend' ),
47
- 'type' => 'text',
48
  'default' => __( 'Submit Post', 'wp-user-frontend' ),
49
- );
50
 
51
- $options[] = array(
52
  'name' => 'post_submission_form',
53
  'label' => __( 'Submission Form', 'wp-user-frontend' ),
54
  'desc' => __( 'Select a post form that will use to submit post by the users from their account page.', 'wp-user-frontend' ),
55
  'type' => 'select',
56
- 'options' => $this->get_post_forms()
57
- );
58
 
59
  return $options;
60
  }
@@ -67,19 +67,18 @@ class WPUF_Frontend_Account {
67
  * @since 2.9.0
68
  */
69
  public function get_post_forms() {
70
- $args = array(
71
- 'post_type' => 'wpuf_forms',
72
  'post_status' => 'any',
73
  'orderby' => 'DESC',
74
- 'order' => 'ID'
75
- );
76
 
77
  $query = new WP_Query( $args );
78
 
79
- $forms = array();
80
 
81
  if ( $query->have_posts() ) {
82
-
83
  $i = 0;
84
 
85
  while ( $query->have_posts() ) {
@@ -110,7 +109,7 @@ class WPUF_Frontend_Account {
110
  $submission_label = wpuf_get_option( 'post_submission_label', 'wpuf_my_account', __( 'Submit Post', 'wp-user-frontend' ) );
111
 
112
  if ( $allow_post_submission == 'on' ) {
113
- $sections = array_merge( $sections, array( array( 'slug' => 'submit-post', 'label' => $submission_label ) ) );
114
  }
115
 
116
  return $sections;
@@ -119,8 +118,8 @@ class WPUF_Frontend_Account {
119
  /**
120
  * Display the submit post section
121
  *
122
- * @param array $sections
123
- * @param string $current_section
124
  *
125
  * @return void
126
  *
@@ -134,9 +133,9 @@ class WPUF_Frontend_Account {
134
  }
135
 
136
  wpuf_load_template(
137
- "submit-post.php",
138
- array( 'sections' => $sections, 'current_section' => $current_section )
139
- );
140
  }
141
 
142
  /**
@@ -147,17 +146,16 @@ class WPUF_Frontend_Account {
147
  *
148
  * @since 2.4.2
149
  */
150
- function shortcode( $atts ) {
151
-
152
- extract( shortcode_atts( array(), $atts ) );
153
 
154
  ob_start();
155
 
156
  if ( is_user_logged_in() ) {
157
  $default_active_tab = wpuf_get_option( 'account_page_active_tab', 'wpuf_my_account', 'dashboard' );
158
- $section = isset( $_REQUEST['section'] ) ? $_REQUEST['section'] : $default_active_tab;
159
  $sections = wpuf_get_account_sections();
160
- $current_section = array();
161
 
162
  foreach ( $sections as $account_section ) {
163
  if ( $section == $account_section['slug'] ) {
@@ -166,10 +164,10 @@ class WPUF_Frontend_Account {
166
  }
167
  }
168
 
169
- wpuf_load_template( 'account.php', array( 'sections' => $sections, 'current_section' => $current_section ) );
170
  } else {
171
  $message = wpuf_get_option( 'un_auth_msg', 'wpuf_dashboard' );
172
- wpuf_load_template( 'unauthorized.php', array( 'message' => $message ) );
173
  }
174
 
175
  $content = ob_get_contents();
@@ -181,8 +179,8 @@ class WPUF_Frontend_Account {
181
  /**
182
  * Display the dashboard section
183
  *
184
- * @param array $sections
185
- * @param string $current_section
186
  *
187
  * @since 2.4.2
188
  *
@@ -190,16 +188,16 @@ class WPUF_Frontend_Account {
190
  */
191
  public function dashboard_section( $sections, $current_section ) {
192
  wpuf_load_template(
193
- "dashboard/dashboard.php",
194
- array( 'sections' => $sections, 'current_section' => $current_section )
195
- );
196
  }
197
 
198
  /**
199
  * Display the posts section
200
  *
201
- * @param array $sections
202
- * @param string $current_section
203
  *
204
  * @since 2.4.2
205
  *
@@ -207,35 +205,36 @@ class WPUF_Frontend_Account {
207
  */
208
  public function posts_section( $sections, $current_section ) {
209
  wpuf_load_template(
210
- "dashboard/posts.php",
211
- array( 'sections' => $sections, 'current_section' => $current_section )
212
- );
213
  }
214
 
215
  /**
216
  * Display the subscription section
217
  *
218
- * @param array $sections
219
- * @param string $current_section
220
  *
221
  * @since 2.4.2
222
  *
223
  * @return void
224
  */
225
  public function subscription_section( $sections, $current_section ) {
226
-
227
  $wpuf_user = wpuf_get_user();
228
  $sub_id = $wpuf_user->subscription()->current_pack_id();
229
 
230
  if ( !$sub_id ) {
231
- _e( "<p>You are not subscribed to any package yet.</p>", 'wp-user-frontend' );
 
232
  return;
233
  }
234
  $user_subscription = new WPUF_User_Subscription( $wpuf_user );
235
- $user_sub = $user_subscription->current_pack();
 
 
 
236
 
237
- if ( $user_sub['status'] != "completed" && $user_sub['status'] != "free" ) {
238
- _e( "<p>You may processed your payment, but the pack is not activated yet.</p>", 'wp-user-frontend' );
239
  return;
240
  }
241
 
@@ -248,14 +247,15 @@ class WPUF_Frontend_Account {
248
  $recurring_des = '';
249
 
250
  $billing_amount = ( intval( $pack->meta_value['billing_amount'] ) > 0 ) ? $details_meta['symbol'] . $pack->meta_value['billing_amount'] : __( 'Free', 'wp-user-frontend' );
 
251
  if ( $pack->meta_value['recurring_pay'] == 'yes' ) {
252
- $recurring_des = sprintf( __( 'For each', 'wp-user-frontend' ).' %s %s', $pack->meta_value['billing_cycle_number'], WPUF_Subscription::get_cycle_label( $pack->meta_value['cycle_period'], $pack->meta_value['billing_cycle_number'] ), $pack->meta_value['trial_duration_type'] );
253
  $recurring_des .= !empty( $pack->meta_value['billing_limit'] ) ? sprintf( __( ', for %s installments', 'wp-user-frontend' ), $pack->meta_value['billing_limit'] ) : '';
254
  }
255
 
256
  wpuf_load_template(
257
- "dashboard/subscription.php",
258
- array(
259
  'sections' => $sections,
260
  'current_section' => $current_section,
261
  'userdata' => $wpuf_user->user,
@@ -263,15 +263,15 @@ class WPUF_Frontend_Account {
263
  'pack' => $pack,
264
  'billing_amount' => $billing_amount,
265
  'recurring_des' => $recurring_des,
266
- )
267
- );
268
  }
269
 
270
  /**
271
  * Display the edit profile section
272
  *
273
- * @param array $sections
274
- * @param string $current_section
275
  *
276
  * @since 2.4.2
277
  *
@@ -279,24 +279,24 @@ class WPUF_Frontend_Account {
279
  */
280
  public function edit_profile_section( $sections, $current_section ) {
281
  wpuf_load_template(
282
- "dashboard/edit-profile.php",
283
- array( 'sections' => $sections, 'current_section' => $current_section )
284
- );
285
  }
286
 
287
  /**
288
  * Display the billing address section
289
  *
290
- * @param array $sections
291
- * @param string $current_section
292
  *
293
  * @return void
294
  */
295
  public function billing_address_section( $sections, $current_section ) {
296
  wpuf_load_template(
297
- "dashboard/billing-address.php",
298
- array( 'sections' => $sections, 'current_section' => $current_section )
299
- );
300
  }
301
 
302
  /**
@@ -307,18 +307,20 @@ class WPUF_Frontend_Account {
307
  * @return json
308
  */
309
  public function update_profile() {
310
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpuf-account-update-profile' ) ) {
 
 
311
  wp_send_json_error( __( 'Nonce failure', 'wp-user-frontend' ) );
312
  }
313
 
314
  global $current_user;
315
 
316
- $first_name = ! empty( $_POST['first_name'] ) ? sanitize_text_field( $_POST['first_name'] ) : '';
317
- $last_name = ! empty( $_POST['last_name'] ) ? sanitize_text_field( $_POST['last_name'] ) : '';
318
- $email = ! empty( $_POST['email'] ) ? sanitize_text_field( $_POST['email'] ) : '';
319
- $current_password = ! empty( $_POST['current_password'] ) ? $_POST['current_password'] : '';
320
- $pass1 = ! empty( $_POST['pass1'] ) ? $_POST['pass1'] : '';
321
- $pass2 = ! empty( $_POST['pass2'] ) ? $_POST['pass2'] : '';
322
  $save_pass = true;
323
 
324
  if ( empty( $first_name ) ) {
@@ -340,7 +342,8 @@ class WPUF_Frontend_Account {
340
 
341
  if ( $email ) {
342
  $email = sanitize_email( $email );
343
- if ( ! is_email( $email ) ) {
 
344
  wp_send_json_error( __( 'Please provide a valid email address.', 'wp-user-frontend' ) );
345
  } elseif ( email_exists( $email ) && $email !== $current_user->user_email ) {
346
  wp_send_json_error( __( 'This email address is already registered.', 'wp-user-frontend' ) );
@@ -348,19 +351,19 @@ class WPUF_Frontend_Account {
348
  $user->user_email = $email;
349
  }
350
 
351
- if ( ! empty( $current_password ) && empty( $pass1 ) && empty( $pass2 ) ) {
352
  wp_send_json_error( __( 'Please fill out all password fields.', 'wp-user-frontend' ) );
353
  $save_pass = false;
354
- } elseif ( ! empty( $pass1 ) && empty( $current_password ) ) {
355
  wp_send_json_error( __( 'Please enter your current password.', 'wp-user-frontend' ) );
356
  $save_pass = false;
357
- } elseif ( ! empty( $pass1 ) && empty( $pass2 ) ) {
358
  wp_send_json_error( __( 'Please re-enter your password.', 'wp-user-frontend' ) );
359
  $save_pass = false;
360
- } elseif ( ( ! empty( $pass1 ) || ! empty( $pass2 ) ) && $pass1 !== $pass2 ) {
361
  wp_send_json_error( __( 'New passwords do not match.', 'wp-user-frontend' ) );
362
  $save_pass = false;
363
- } elseif ( ! empty( $pass1 ) && ! wp_check_password( $current_password, $current_user->user_pass, $current_user->ID ) ) {
364
  wp_send_json_error( __( 'Your current password is incorrect.', 'wp-user-frontend' ) );
365
  $save_pass = false;
366
  }
@@ -377,5 +380,4 @@ class WPUF_Frontend_Account {
377
 
378
  wp_send_json_success();
379
  }
380
-
381
  }
4
  * Dashboard class
5
  *
6
  * @author Tareq Hasan
 
7
  */
8
  class WPUF_Frontend_Account {
9
 
10
  /**
11
+
12
  * Class constructor
13
  */
14
  public function __construct() {
15
+ add_shortcode( 'wpuf_account', [ $this, 'shortcode' ] );
16
+ add_action( 'wpuf_account_content_dashboard', [ $this, 'dashboard_section' ], 10, 2 );
17
+ add_action( 'wpuf_account_content_posts', [ $this, 'posts_section' ], 10, 2 );
18
+ add_action( 'wpuf_account_content_subscription', [ $this, 'subscription_section' ], 10, 2 );
19
+ add_action( 'wpuf_account_content_edit-profile', [ $this, 'edit_profile_section' ], 10, 2 );
20
+ add_action( 'wpuf_account_content_billing-address', [ $this, 'billing_address_section' ], 10, 2 );
21
+ add_action( 'wp_ajax_wpuf_account_update_profile', [ $this, 'update_profile' ] );
22
+ add_filter( 'wpuf_options_wpuf_my_account', [ $this, 'add_settings_options' ] );
23
+ add_filter( 'wpuf_account_sections', [ $this, 'add_account_sections' ] );
24
+ add_action( 'wpuf_account_content_submit-post', [ $this, 'submit_post_section' ], 10, 2 );
25
  }
26
 
27
  /**
32
  * @since 2.9.0
33
  */
34
  public function add_settings_options( $options ) {
35
+ $options[] = [
36
+ 'name' => 'allow_post_submission',
37
+ 'label' => __( 'Post Submission', 'wp-user-frontend' ),
38
+ 'desc' => __( 'Enable if you want to allow users to submit post from the account page.', 'wp-user-frontend' ),
39
+ 'type' => 'checkbox',
40
  'default' => 'on',
41
+ ];
42
 
43
+ $options[] = [
44
+ 'name' => 'post_submission_label',
45
+ 'label' => __( 'Submission Menu Label', 'wp-user-frontend' ),
46
+ 'desc' => __( 'Label for post submission menu', 'wp-user-frontend' ),
47
+ 'type' => 'text',
48
  'default' => __( 'Submit Post', 'wp-user-frontend' ),
49
+ ];
50
 
51
+ $options[] = [
52
  'name' => 'post_submission_form',
53
  'label' => __( 'Submission Form', 'wp-user-frontend' ),
54
  'desc' => __( 'Select a post form that will use to submit post by the users from their account page.', 'wp-user-frontend' ),
55
  'type' => 'select',
56
+ 'options' => $this->get_post_forms(),
57
+ ];
58
 
59
  return $options;
60
  }
67
  * @since 2.9.0
68
  */
69
  public function get_post_forms() {
70
+ $args = [
71
+ 'post_type' => 'wpuf_forms',
72
  'post_status' => 'any',
73
  'orderby' => 'DESC',
74
+ 'order' => 'ID',
75
+ ];
76
 
77
  $query = new WP_Query( $args );
78
 
79
+ $forms = [];
80
 
81
  if ( $query->have_posts() ) {
 
82
  $i = 0;
83
 
84
  while ( $query->have_posts() ) {
109
  $submission_label = wpuf_get_option( 'post_submission_label', 'wpuf_my_account', __( 'Submit Post', 'wp-user-frontend' ) );
110
 
111
  if ( $allow_post_submission == 'on' ) {
112
+ $sections = array_merge( $sections, [ [ 'slug' => 'submit-post', 'label' => $submission_label ] ] );
113
  }
114
 
115
  return $sections;
118
  /**
119
  * Display the submit post section
120
  *
121
+ * @param array $sections
122
+ * @param string $current_section
123
  *
124
  * @return void
125
  *
133
  }
134
 
135
  wpuf_load_template(
136
+ 'submit-post.php',
137
+ [ 'sections' => $sections, 'current_section' => $current_section ]
138
+ );
139
  }
140
 
141
  /**
146
  *
147
  * @since 2.4.2
148
  */
149
+ public function shortcode( $atts ) {
150
+ extract( shortcode_atts( [], $atts ) );
 
151
 
152
  ob_start();
153
 
154
  if ( is_user_logged_in() ) {
155
  $default_active_tab = wpuf_get_option( 'account_page_active_tab', 'wpuf_my_account', 'dashboard' );
156
+ $section = isset( $_REQUEST['section'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ) : $default_active_tab;
157
  $sections = wpuf_get_account_sections();
158
+ $current_section = [];
159
 
160
  foreach ( $sections as $account_section ) {
161
  if ( $section == $account_section['slug'] ) {
164
  }
165
  }
166
 
167
+ wpuf_load_template( 'account.php', [ 'sections' => $sections, 'current_section' => $current_section ] );
168
  } else {
169
  $message = wpuf_get_option( 'un_auth_msg', 'wpuf_dashboard' );
170
+ wpuf_load_template( 'unauthorized.php', [ 'message' => $message ] );
171
  }
172
 
173
  $content = ob_get_contents();
179
  /**
180
  * Display the dashboard section
181
  *
182
+ * @param array $sections
183
+ * @param string $current_section
184
  *
185
  * @since 2.4.2
186
  *
188
  */
189
  public function dashboard_section( $sections, $current_section ) {
190
  wpuf_load_template(
191
+ 'dashboard/dashboard.php',
192
+ [ 'sections' => $sections, 'current_section' => $current_section ]
193
+ );
194
  }
195
 
196
  /**
197
  * Display the posts section
198
  *
199
+ * @param array $sections
200
+ * @param string $current_section
201
  *
202
  * @since 2.4.2
203
  *
205
  */
206
  public function posts_section( $sections, $current_section ) {
207
  wpuf_load_template(
208
+ 'dashboard/posts.php',
209
+ [ 'sections' => $sections, 'current_section' => $current_section ]
210
+ );
211
  }
212
 
213
  /**
214
  * Display the subscription section
215
  *
216
+ * @param array $sections
217
+ * @param string $current_section
218
  *
219
  * @since 2.4.2
220
  *
221
  * @return void
222
  */
223
  public function subscription_section( $sections, $current_section ) {
 
224
  $wpuf_user = wpuf_get_user();
225
  $sub_id = $wpuf_user->subscription()->current_pack_id();
226
 
227
  if ( !$sub_id ) {
228
+ echo wp_kses_post( __( '<p>You are not subscribed to any package yet.</p>', 'wp-user-frontend' ) );
229
+
230
  return;
231
  }
232
  $user_subscription = new WPUF_User_Subscription( $wpuf_user );
233
+ $user_sub = $user_subscription->current_pack();
234
+
235
+ if ( $user_sub['status'] != 'completed' && $user_sub['status'] != 'free' ) {
236
+ esc_html_e( '<p>You may processed your payment, but the pack is not activated yet.</p>', 'wp-user-frontend' );
237
 
 
 
238
  return;
239
  }
240
 
247
  $recurring_des = '';
248
 
249
  $billing_amount = ( intval( $pack->meta_value['billing_amount'] ) > 0 ) ? $details_meta['symbol'] . $pack->meta_value['billing_amount'] : __( 'Free', 'wp-user-frontend' );
250
+
251
  if ( $pack->meta_value['recurring_pay'] == 'yes' ) {
252
+ $recurring_des = sprintf( __( 'For each', 'wp-user-frontend' ) . ' %s %s', $pack->meta_value['billing_cycle_number'], WPUF_Subscription::get_cycle_label( $pack->meta_value['cycle_period'], $pack->meta_value['billing_cycle_number'] ), $pack->meta_value['trial_duration_type'] );
253
  $recurring_des .= !empty( $pack->meta_value['billing_limit'] ) ? sprintf( __( ', for %s installments', 'wp-user-frontend' ), $pack->meta_value['billing_limit'] ) : '';
254
  }
255
 
256
  wpuf_load_template(
257
+ 'dashboard/subscription.php',
258
+ [
259
  'sections' => $sections,
260
  'current_section' => $current_section,
261
  'userdata' => $wpuf_user->user,
263
  'pack' => $pack,
264
  'billing_amount' => $billing_amount,
265
  'recurring_des' => $recurring_des,
266
+ ]
267
+ );
268
  }
269
 
270
  /**
271
  * Display the edit profile section
272
  *
273
+ * @param array $sections
274
+ * @param string $current_section
275
  *
276
  * @since 2.4.2
277
  *
279
  */
280
  public function edit_profile_section( $sections, $current_section ) {
281
  wpuf_load_template(
282
+ 'dashboard/edit-profile.php',
283
+ [ 'sections' => $sections, 'current_section' => $current_section ]
284
+ );
285
  }
286
 
287
  /**
288
  * Display the billing address section
289
  *
290
+ * @param array $sections
291
+ * @param string $current_section
292
  *
293
  * @return void
294
  */
295
  public function billing_address_section( $sections, $current_section ) {
296
  wpuf_load_template(
297
+ 'dashboard/billing-address.php',
298
+ [ 'sections' => $sections, 'current_section' => $current_section ]
299
+ );
300
  }
301
 
302
  /**
307
  * @return json
308
  */
309
  public function update_profile() {
310
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
311
+
312
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf-account-update-profile' ) ) {
313
  wp_send_json_error( __( 'Nonce failure', 'wp-user-frontend' ) );
314
  }
315
 
316
  global $current_user;
317
 
318
+ $first_name = !empty( $_POST['first_name'] ) ? sanitize_text_field( wp_unslash( $_POST['first_name'] ) ) : '';
319
+ $last_name = !empty( $_POST['last_name'] ) ? sanitize_text_field( wp_unslash( $_POST['last_name'] ) ) : '';
320
+ $email = !empty( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '';
321
+ $current_password = !empty( $_POST['current_password'] ) ? sanitize_text_field( wp_unslash( $_POST['current_password'] ) ): '';
322
+ $pass1 = !empty( $_POST['pass1'] ) ? sanitize_text_field( wp_unslash( $_POST['pass1'] ) ) : '';
323
+ $pass2 = !empty( $_POST['pass2'] ) ? sanitize_text_field( wp_unslash( $_POST['pass2'] ) ) : '';
324
  $save_pass = true;
325
 
326
  if ( empty( $first_name ) ) {
342
 
343
  if ( $email ) {
344
  $email = sanitize_email( $email );
345
+
346
+ if ( !is_email( $email ) ) {
347
  wp_send_json_error( __( 'Please provide a valid email address.', 'wp-user-frontend' ) );
348
  } elseif ( email_exists( $email ) && $email !== $current_user->user_email ) {
349
  wp_send_json_error( __( 'This email address is already registered.', 'wp-user-frontend' ) );
351
  $user->user_email = $email;
352
  }
353
 
354
+ if ( !empty( $current_password ) && empty( $pass1 ) && empty( $pass2 ) ) {
355
  wp_send_json_error( __( 'Please fill out all password fields.', 'wp-user-frontend' ) );
356
  $save_pass = false;
357
+ } elseif ( !empty( $pass1 ) && empty( $current_password ) ) {
358
  wp_send_json_error( __( 'Please enter your current password.', 'wp-user-frontend' ) );
359
  $save_pass = false;
360
+ } elseif ( !empty( $pass1 ) && empty( $pass2 ) ) {
361
  wp_send_json_error( __( 'Please re-enter your password.', 'wp-user-frontend' ) );
362
  $save_pass = false;
363
+ } elseif ( ( !empty( $pass1 ) || !empty( $pass2 ) ) && $pass1 !== $pass2 ) {
364
  wp_send_json_error( __( 'New passwords do not match.', 'wp-user-frontend' ) );
365
  $save_pass = false;
366
+ } elseif ( !empty( $pass1 ) && !wp_check_password( $current_password, $current_user->user_pass, $current_user->ID ) ) {
367
  wp_send_json_error( __( 'Your current password is incorrect.', 'wp-user-frontend' ) );
368
  $save_pass = false;
369
  }
380
 
381
  wp_send_json_success();
382
  }
 
383
  }
class/frontend-dashboard.php CHANGED
@@ -4,13 +4,12 @@
4
  * Dashboard class
5
  *
6
  * @author Tareq Hasan
7
- * @package WP User Frontend
8
  */
9
  class WPUF_Frontend_Dashboard {
10
 
11
- function __construct() {
12
- add_shortcode( 'wpuf_dashboard', array($this, 'shortcode') );
13
- add_action( 'wpuf_dashboard_shortcode_init', array( $this, 'remove_tribe_pre_get_posts' ) );
14
  }
15
 
16
  /**
@@ -33,17 +32,17 @@ class WPUF_Frontend_Dashboard {
33
  *
34
  * @since 0.1
35
  */
36
- function shortcode( $atts ) {
37
  do_action( 'wpuf_dashboard_shortcode_init', $atts );
38
 
39
- $attributes = shortcode_atts( array( 'form_id'=>'off', 'post_type' => 'post', 'category' =>'off', 'featured_image' => 'default', 'meta' => 'off', 'excerpt' =>'off', 'payment_column' => 'on' ), $atts ) ;
40
  ob_start();
41
 
42
  if ( is_user_logged_in() ) {
43
  $this->post_listing( $attributes );
44
  } else {
45
  $message = wpuf_get_option( 'un_auth_msg', 'wpuf_dashboard' );
46
- wpuf_load_template( 'unauthorized.php', array( 'message' => $message ) );
47
  }
48
 
49
  $content = ob_get_contents();
@@ -58,49 +57,50 @@ class WPUF_Frontend_Dashboard {
58
  * @global object $wpdb
59
  * @global object $userdata
60
  */
61
- function post_listing( $attributes ) {
62
  global $post;
63
- extract ( $attributes );
64
-
65
- $pagenum = isset( $_GET['pagenum'] ) ? intval( $_GET['pagenum'] ) : 1;
66
 
 
 
 
67
  //delete post
68
- if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == "del" ) {
69
  $this->delete_post();
70
  }
71
 
72
  //show delete success message
73
- if ( isset( $_GET['msg'] ) && $_GET['msg'] == 'deleted' ) {
74
- echo '<div class="success">' . __( 'Post Deleted', 'wp-user-frontend' ) . '</div>';
75
  }
76
- $post_type = explode( ",", $post_type );
77
- $args = array(
78
  'author' => get_current_user_id(),
79
- 'post_status' => array('draft', 'future', 'pending', 'publish', 'private'),
80
  'post_type' => $post_type,
81
  'posts_per_page' => wpuf_get_option( 'per_page', 'wpuf_dashboard', 10 ),
82
  'paged' => $pagenum,
83
- );
84
 
85
- if ( isset($attributes['form_id']) && $attributes['form_id'] != 'off' ) {
86
- $args['meta_query'] = array(
87
- array(
88
  'key' => '_wpuf_form_id',
89
  'value' => $attributes['form_id'],
90
  'compare' => 'IN',
91
- )
92
- );
93
  }
94
 
95
  $original_post = $post;
96
  $dashboard_query = new WP_Query( apply_filters( 'wpuf_dashboard_query', $args, $attributes ) );
97
- $post_type_obj = array();
98
 
99
- foreach ($post_type as $key => $value) {
100
- $post_type_obj[$value] = get_post_type_object( $value );
101
  }
102
 
103
- wpuf_load_template( 'dashboard.php', array(
104
  'post_type' => $post_type,
105
  'userdata' => wp_get_current_user(),
106
  'dashboard_query' => $dashboard_query,
@@ -112,8 +112,8 @@ class WPUF_Frontend_Dashboard {
112
  'form_id' => $form_id,
113
  'meta' => $meta,
114
  'excerpt' => $excerpt,
115
- 'payment_column' => $payment_column
116
- ) );
117
 
118
  wp_reset_postdata();
119
 
@@ -123,18 +123,18 @@ class WPUF_Frontend_Dashboard {
123
  /**
124
  * Show user info on dashboard
125
  */
126
- function user_info() {
127
  global $userdata;
128
 
129
  if ( wpuf_get_option( 'show_user_bio', 'wpuf_dashboard', 'on' ) == 'on' ) {
130
  ?>
131
  <div class="wpuf-author">
132
- <h3><?php _e( 'Author Info', 'wp-user-frontend' ); ?></h3>
133
  <div class="wpuf-author-inside odd">
134
  <div class="wpuf-user-image"><?php echo get_avatar( $userdata->user_email, 80 ); ?></div>
135
  <div class="wpuf-author-body">
136
- <p class="wpuf-user-name"><a href="<?php echo get_author_posts_url( $userdata->ID ); ?>"><?php printf( esc_attr__( '%s', 'wp-user-frontend' ), $userdata->display_name ); ?></a></p>
137
- <p class="wpuf-author-info"><?php echo $userdata->description; ?></p>
138
  </div>
139
  </div>
140
  </div><!-- .author -->
@@ -147,29 +147,30 @@ class WPUF_Frontend_Dashboard {
147
  *
148
  * Only post author and editors has the capability to delete a post
149
  */
150
- function delete_post() {
151
  global $userdata;
152
 
153
- $nonce = $_REQUEST['_wpnonce'];
154
- if ( !wp_verify_nonce( $nonce, 'wpuf_del' ) ) {
155
- die( "Security check" );
 
 
156
  }
157
 
158
  //check, if the requested user is the post author
159
- $maybe_delete = get_post( $_REQUEST['pid'] );
160
 
161
- if ( ($maybe_delete->post_author == $userdata->ID) || current_user_can( 'delete_others_pages' ) ) {
162
- wp_trash_post( $_REQUEST['pid'] );
163
 
164
  //redirect
165
- $redirect = add_query_arg( array('msg' => 'deleted'), get_permalink() );
166
 
167
  $redirect = apply_filters( 'wpuf_delete_post_redirect', $redirect );
168
 
169
  wp_redirect( $redirect );
170
  } else {
171
- echo '<div class="error">' . __( 'You are not the post author. Cheeting huh!', 'wp-user-frontend' ) . '</div>';
172
  }
173
  }
174
-
175
  }
4
  * Dashboard class
5
  *
6
  * @author Tareq Hasan
 
7
  */
8
  class WPUF_Frontend_Dashboard {
9
 
10
+ public function __construct() {
11
+ add_shortcode( 'wpuf_dashboard', [$this, 'shortcode'] );
12
+ add_action( 'wpuf_dashboard_shortcode_init', [ $this, 'remove_tribe_pre_get_posts' ] );
13
  }
14
 
15
  /**
32
  *
33
  * @since 0.1
34
  */
35
+ public function shortcode( $atts ) {
36
  do_action( 'wpuf_dashboard_shortcode_init', $atts );
37
 
38
+ $attributes = shortcode_atts( [ 'form_id'=>'off', 'post_type' => 'post', 'category' =>'off', 'featured_image' => 'default', 'meta' => 'off', 'excerpt' =>'off', 'payment_column' => 'on' ], $atts );
39
  ob_start();
40
 
41
  if ( is_user_logged_in() ) {
42
  $this->post_listing( $attributes );
43
  } else {
44
  $message = wpuf_get_option( 'un_auth_msg', 'wpuf_dashboard' );
45
+ wpuf_load_template( 'unauthorized.php', [ 'message' => $message ] );
46
  }
47
 
48
  $content = ob_get_contents();
57
  * @global object $wpdb
58
  * @global object $userdata
59
  */
60
+ public function post_listing( $attributes ) {
61
  global $post;
62
+ extract( $attributes );
 
 
63
 
64
+ $pagenum = isset( $_GET['pagenum'] ) ? intval( wp_unslash( $_GET['pagenum'] ) ) : 1;
65
+ $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : '';
66
+ $msg = isset( $_GET['msg'] ) ? sanitize_text_field( wp_unslash( $_GET['msg'] ) ) : '';
67
  //delete post
68
+ if ( $action == 'del' ) {
69
  $this->delete_post();
70
  }
71
 
72
  //show delete success message
73
+ if ( $msg == 'deleted' ) {
74
+ echo wp_kses_post( '<div class="success">' . __( 'Post Deleted', 'wp-user-frontend' ) . '</div>' );
75
  }
76
+ $post_type = explode( ',', $post_type );
77
+ $args = [
78
  'author' => get_current_user_id(),
79
+ 'post_status' => ['draft', 'future', 'pending', 'publish', 'private'],
80
  'post_type' => $post_type,
81
  'posts_per_page' => wpuf_get_option( 'per_page', 'wpuf_dashboard', 10 ),
82
  'paged' => $pagenum,
83
+ ];
84
 
85
+ if ( isset( $attributes['form_id'] ) && $attributes['form_id'] != 'off' ) {
86
+ $args['meta_query'] = [
87
+ [
88
  'key' => '_wpuf_form_id',
89
  'value' => $attributes['form_id'],
90
  'compare' => 'IN',
91
+ ],
92
+ ];
93
  }
94
 
95
  $original_post = $post;
96
  $dashboard_query = new WP_Query( apply_filters( 'wpuf_dashboard_query', $args, $attributes ) );
97
+ $post_type_obj = [];
98
 
99
+ foreach ( $post_type as $key => $value ) {
100
+ $post_type_obj[$value] = get_post_type_object( $value );
101
  }
102
 
103
+ wpuf_load_template( 'dashboard.php', [
104
  'post_type' => $post_type,
105
  'userdata' => wp_get_current_user(),
106
  'dashboard_query' => $dashboard_query,
112
  'form_id' => $form_id,
113
  'meta' => $meta,
114
  'excerpt' => $excerpt,
115
+ 'payment_column' => $payment_column,
116
+ ] );
117
 
118
  wp_reset_postdata();
119
 
123
  /**
124
  * Show user info on dashboard
125
  */
126
+ public function user_info() {
127
  global $userdata;
128
 
129
  if ( wpuf_get_option( 'show_user_bio', 'wpuf_dashboard', 'on' ) == 'on' ) {
130
  ?>
131
  <div class="wpuf-author">
132
+ <h3><?php esc_html_e( 'Author Info', 'wp-user-frontend' ); ?></h3>
133
  <div class="wpuf-author-inside odd">
134
  <div class="wpuf-user-image"><?php echo get_avatar( $userdata->user_email, 80 ); ?></div>
135
  <div class="wpuf-author-body">
136
+ <p class="wpuf-user-name"><a href="<?php echo esc_url( get_author_posts_url( esc_attr( $userdata->ID ) ) ); ?>"><?php printf( esc_attr__( '%s', 'wp-user-frontend' ), esc_attr( $userdata->display_name ) ); ?></a></p>
137
+ <p class="wpuf-author-info"><?php echo esc_html( $userdata->description ); ?></p>
138
  </div>
139
  </div>
140
  </div><!-- .author -->
147
  *
148
  * Only post author and editors has the capability to delete a post
149
  */
150
+ public function delete_post() {
151
  global $userdata;
152
 
153
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
154
+ $pid = isset( $_REQUEST['pid'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['pid'] ) ) : '';
155
+
156
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf_del' ) ) {
157
+ return ;
158
  }
159
 
160
  //check, if the requested user is the post author
161
+ $maybe_delete = get_post( $pid );
162
 
163
+ if ( ( $maybe_delete->post_author == $userdata->ID ) || current_user_can( 'delete_others_pages' ) ) {
164
+ wp_trash_post( $pid );
165
 
166
  //redirect
167
+ $redirect = add_query_arg( ['msg' => 'deleted'], get_permalink() );
168
 
169
  $redirect = apply_filters( 'wpuf_delete_post_redirect', $redirect );
170
 
171
  wp_redirect( $redirect );
172
  } else {
173
+ echo wp_kses_post( '<div class="error">' . __( 'You are not the post author. Cheeting huh!', 'wp-user-frontend' ) . '</div>' );
174
  }
175
  }
 
176
  }
class/payment.php CHANGED
@@ -4,31 +4,30 @@
4
  * WP User Frontend payment gateway handler
5
  *
6
  * @since 0.8
7
- * @package WP User Frontend
8
  */
9
  class WPUF_Payment {
10
 
11
- function __construct() {
12
- add_action( 'init', array( $this, 'send_to_gateway' ) );
13
- add_action( 'wpuf_payment_received', array( $this, 'payment_notify_admin' ) );
14
- add_filter( 'the_content', array( $this, 'payment_page' ) );
15
- add_action( 'init', array( $this, 'handle_cancel_payment' ) );
16
  }
17
 
18
  public static function get_payment_gateways() {
19
 
20
  // default, built-in gateways
21
- $gateways = array(
22
- 'paypal' => array(
23
  'admin_label' => __( 'PayPal', 'wp-user-frontend' ),
24
  'checkout_label' => __( 'PayPal', 'wp-user-frontend' ),
25
- 'icon' => apply_filters( 'wpuf_paypal_checkout_icon', WPUF_ASSET_URI . '/images/paypal.png' )
26
- ),
27
- 'bank' => array(
28
  'admin_label' => __( 'Bank Payment', 'wp-user-frontend' ),
29
  'checkout_label' => __( 'Bank Payment', 'wp-user-frontend' ),
30
- )
31
- );
32
 
33
  $gateways = apply_filters( 'wpuf_payment_gateways', $gateways );
34
 
@@ -40,13 +39,13 @@ class WPUF_Payment {
40
  *
41
  * @return array
42
  */
43
- function get_active_gateways() {
44
  $all_gateways = wpuf_get_gateways( 'checkout' );
45
  $active_gateways = wpuf_get_option( 'active_gateways', 'wpuf_payment' );
46
- $active_gateways = is_array( $active_gateways ) ? $active_gateways : array();
47
- $gateways = array();
48
 
49
- foreach ($all_gateways as $id => $label) {
50
  if ( array_key_exists( $id, $active_gateways ) ) {
51
  $gateways[$id] = $label;
52
  }
@@ -58,36 +57,38 @@ class WPUF_Payment {
58
  /**
59
  * Show the payment page
60
  *
61
- * @param string $content
 
62
  * @return string
63
  */
64
- function payment_page( $content ) {
65
  global $post;
66
 
67
- $pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
68
  $billing_amount = 0;
 
 
 
 
69
 
70
- if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'wpuf_pay' && $pay_page == 0 ) {
71
- _e('Please select your payment page from admin panel', 'wp-user-frontend' );
72
  return;
73
  }
74
 
75
- if ( $post->ID == $pay_page && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'wpuf_pay' ) {
76
-
77
  if ( !is_user_logged_in() ) {
78
  //return __( 'You are not logged in', 'wpuf' );
79
  }
80
-
81
- $type = ( $_REQUEST['type'] == 'post' ) ? 'post' : 'pack';
82
- $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
83
- $pack_id = isset( $_REQUEST['pack_id'] ) ? intval( $_REQUEST['pack_id'] ) : 0;
84
  $is_free = false;
85
 
86
  if ( $pack_id ) {
87
  $pack_detail = WPUF_Subscription::get_subscription( $pack_id );
88
  $recurring_pay = isset( $pack_detail->meta_value['recurring_pay'] ) ? $pack_detail->meta_value['recurring_pay'] : 'no';
89
 
90
- if ( empty( $pack_detail->meta_value['billing_amount'] ) || $pack_detail->meta_value['billing_amount'] <= 0) {
91
  $is_free = true;
92
  }
93
  }
@@ -95,7 +96,7 @@ class WPUF_Payment {
95
  $gateways = $this->get_active_gateways();
96
 
97
  if ( isset( $_REQUEST['wpuf_payment_submit'] ) ) {
98
- $selected_gateway = $_REQUEST['wpuf_payment_method'];
99
  } else {
100
  $selected_gateway = 'paypal';
101
  }
@@ -105,25 +106,23 @@ class WPUF_Payment {
105
  if ( is_user_logged_in() ) {
106
  $current_user = wp_get_current_user();
107
  } else {
108
- $user_id = isset( $_GET['user_id'] ) ? $_GET['user_id'] : 0;
109
  $current_user = get_userdata( $user_id );
110
  }
111
 
112
  if ( $pack_id && $is_free ) {
113
-
114
  $wpuf_subscription = WPUF_Subscription::init();
115
- $wpuf_user = new WPUF_User( $current_user->ID );
116
 
117
- if ( ! $wpuf_user->subscription()->used_free_pack( $pack_id ) ) {
118
  wpuf_get_user( $current_user->ID )->subscription()->add_pack( $pack_id, null, false, 'free' );
119
  $wpuf_user->subscription()->add_free_pack( $current_user->ID, $pack_id );
120
 
121
  $message = apply_filters( 'wpuf_fp_activated_msg', __( 'Your free package has been activated. Enjoy!', 'wp-user-frontend' ) );
122
  } else {
123
  $message = apply_filters( 'wpuf_fp_activated_error', __( 'You already have activated a free package previously.', 'wp-user-frontend' ) );
124
- }
125
- ?>
126
- <div class="wpuf-info"><?php echo $message; ?></div>
127
  <?php
128
  } else {
129
  ?>
@@ -131,14 +130,12 @@ class WPUF_Payment {
131
  ?>
132
  <div class="wpuf-payment-page-wrap wpuf-pay-row">
133
  <?php
134
- $pay_page_style = "";
135
- ?>
136
  <div class="wpuf-bill-addr-wrap wpuf-pay-col">
137
  <?php if ( wpuf_get_option( 'show_address', 'wpuf_address_options', false ) ) {
138
- $pay_page_style = "vertical-align:top; margin-left: 20px; display: inline-block;";
139
- ?>
140
  <div class="wpuf-bill-addr-info">
141
- <h3> <?php _e( 'Billing Address', 'wp-user-frontend' ); ?> </h3>
142
  <div class="wpuf-bill_addr-inner">
143
  <?php
144
  $add_form = new WPUF_Ajax_Address_Form();
@@ -146,48 +143,54 @@ class WPUF_Payment {
146
  ?>
147
  </div>
148
  </div>
149
- <?php } ?>
 
150
  </div>
151
- <div class="wpuf-payment-gateway-wrap" style="<?php echo $pay_page_style; ?>">
152
  <form id="wpuf-payment-gateway" action="" method="POST">
153
 
154
  <?php if ( $pack_id ) {
155
  $pack = WPUF_Subscription::init()->get_subscription( $pack_id );
156
  $details_meta = WPUF_Subscription::init()->get_details_meta_value();
157
  $currency = wpuf_get_currency( 'symbol' );
 
158
  if ( is_user_logged_in() ) {
159
  ?>
160
- <input type="hidden" name="user_id" value="<?php echo $current_user->ID; ?>">
161
- <?php } ?>
 
162
 
163
  <div class="wpuf-coupon-info-wrap wpuf-pay-col">
164
  <div class="wpuf-coupon-info">
165
  <div class="wpuf-pack-info">
166
  <h3 class="wpuf-pay-col">
167
- <?php _e( 'Pricing & Plans', 'wp-user-frontend' ); ?>
168
 
169
- <a style="white-space: nowrap" href="<?php echo wpuf_get_subscription_page_url(); ?>"><?php _e( 'Change Pack', 'wp-user-frontend' ); ?></a>
170
  </h3>
171
  <div class="wpuf-subscription-error"></div>
172
  <div class="wpuf-subscription-success"></div>
173
 
174
  <div class="wpuf-pack-inner">
175
 
176
- <?php if ( class_exists( 'WPUF_Coupons' ) ) { ?>
177
- <?php echo WPUF_Coupons::init()->after_apply_coupon( $pack ); ?>
178
- <?php } else {
179
- $pack_cost = $pack->meta_value['billing_amount'];
 
180
  $billing_amount = apply_filters( 'wpuf_payment_amount', $pack->meta_value['billing_amount'] );
181
  ?>
 
182
  <div id="wpuf_type" style="display: none"><?php echo 'pack'; ?></div>
183
- <div id="wpuf_id" style="display: none"><?php echo $pack_id; ?></div>
184
- <div><?php _e( 'Selected Pack ', 'wp-user-frontend' ); ?>: <strong><?php echo $pack->post_title; ?></strong></div>
185
- <div><?php _e( 'Pack Price ', 'wp-user-frontend' ); ?>: <strong><span id="wpuf_pay_page_cost"><?php echo wpuf_format_price( $pack_cost ); ?></strong></span></div>
186
 
187
  <?php do_action( 'wpuf_before_pack_payment_total' ); ?>
188
 
189
- <div><?php _e( 'Total', 'wp-user-frontend' ); ?>: <strong><span id="wpuf_pay_page_total"><?php echo wpuf_format_price( $billing_amount ); ?></strong></span></div>
190
- <?php } ?>
 
191
  </div>
192
  </div>
193
  </div>
@@ -198,65 +201,68 @@ class WPUF_Payment {
198
  <input type="text" name="coupon_code" size="20" class="wpuf-coupon-field">
199
  <input type="hidden" name="coupon_id" size="20" class="wpuf-coupon-id-field">
200
  <div>
201
- <a href="#" data-pack_id="<?php echo $pack_id; ?>" class="wpuf-apply-coupon"><?php _e( 'Apply Coupon', 'wp-user-frontend' ); ?></a>
202
- <a href="#" data-pack_id="<?php echo $pack_id; ?>" class="wpuf-copon-cancel"><?php _e( 'Cancel', 'wp-user-frontend' ); ?></a>
203
  </div>
204
  </div>
205
- <a href="#" class="wpuf-copon-show"><?php _e( 'Have a discount code?', 'wp-user-frontend' ); ?></a>
206
 
207
- <?php } // coupon ?>
208
  </div>
209
 
210
- <?php }
211
- if ( $post_id ) {
212
- $form = new WPUF_Form( get_post_meta( $post_id, '_wpuf_form_id', true ) );
213
- $force_pack = $form->is_enabled_force_pack();
214
- $pay_per_post = $form->is_enabled_pay_per_post();
215
- $fallback_enabled = $form->is_enabled_fallback_cost();
216
- $fallback_cost = (float)$form->get_subs_fallback_cost();
217
- $pay_per_post_cost = (float)$form->get_pay_per_post_cost();
218
- $current_user = wpuf_get_user();
219
-
220
- $current_pack = $current_user->subscription()->current_pack();
221
- if ( $force_pack && !is_wp_error( $current_pack ) && $fallback_enabled ) {
222
- $post_cost = $fallback_cost;
223
- $billing_amount = apply_filters( 'wpuf_payment_amount', $fallback_cost );
224
- } else {
225
- $post_cost = $pay_per_post_cost;
226
- $billing_amount = apply_filters( 'wpuf_payment_amount', $pay_per_post_cost );
227
- }
228
- ?>
 
 
229
  <div id="wpuf_type" style="display: none"><?php echo 'post'; ?></div>
230
- <div id="wpuf_id" style="display: none"><?php echo $post_id; ?></div>
231
- <div><?php _e( 'Post cost', 'wp-user-frontend' ); ?>: <strong><span id="wpuf_pay_page_cost"><?php echo wpuf_format_price( $post_cost ); ?></strong></span></div>
232
 
233
  <?php do_action( 'wpuf_before_pack_payment_total' ); ?>
234
 
235
- <div><?php _e( 'Total', 'wp-user-frontend' ); ?>: <strong><span id="wpuf_pay_page_total"><?php echo wpuf_format_price( $billing_amount ); ?></strong></span></div>
236
- <?php } ?>
237
- <?php wp_nonce_field( 'wpuf_payment_gateway' ) ?>
 
238
 
239
  <?php do_action( 'wpuf_before_payment_gateway' ); ?>
240
 
241
  <p>
242
- <label for="wpuf-payment-method"><?php _e( 'Choose Your Payment Method', 'wp-user-frontend' ); ?></label><br />
243
 
244
  <ul class="wpuf-payment-gateways">
245
- <?php foreach ($gateways as $gateway_id => $gateway) { ?>
246
- <li class="wpuf-gateway-<?php echo $gateway_id; ?>">
247
  <label>
248
  <input name="wpuf_payment_method" type="radio" value="<?php echo esc_attr( $gateway_id ); ?>" <?php checked( $selected_gateway, $gateway_id ); ?>>
249
  <?php
250
- echo $gateway['label'];
251
 
252
  if ( !empty( $gateway['icon'] ) ) {
253
- printf(' <img src="%s" alt="image">', $gateway['icon'] );
254
  }
255
  ?>
256
  </label>
257
 
258
  <div class="wpuf-payment-instruction" style="display: none;">
259
- <div class="wpuf-instruction"><?php echo wpuf_get_option( 'gate_instruct_' . $gateway_id, 'wpuf_payment' ); ?></div>
260
 
261
  <?php do_action( 'wpuf_gateway_form_' . $gateway_id, $type, $post_id, $pack_id ); ?>
262
  </div>
@@ -266,23 +272,24 @@ class WPUF_Payment {
266
  </p>
267
  <?php do_action( 'wpuf_after_payment_gateway' ); ?>
268
  <p>
269
- <input type="hidden" name="type" value="<?php echo $type; ?>" />
270
  <input type="hidden" name="action" value="wpuf_pay" />
271
  <?php if ( $post_id ) { ?>
272
- <input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
273
  <?php } ?>
274
 
275
  <?php if ( $pack_id ) { ?>
276
- <input type="hidden" name="pack_id" value="<?php echo $pack_id; ?>" />
277
- <input type="hidden" name="recurring_pay" value="<?php echo $recurring_pay; ?>" />
278
  <?php } ?>
279
- <input type="submit" name="wpuf_payment_submit" class="wpuf-btn" value="<?php _e( 'Proceed', 'wp-user-frontend' ); ?>"/>
280
  </p>
281
  </form>
282
  </div>
283
  </div>
284
- <?php } else { ?>
285
- <?php _e( 'No Payment gateway found', 'wp-user-frontend' ); ?>
 
286
  <?php } ?>
287
 
288
  <?php
@@ -304,31 +311,32 @@ class WPUF_Payment {
304
  *
305
  * Need to use `wpuf_gateway_{$gateway_name}
306
  */
307
- function send_to_gateway() {
308
-
309
- if ( isset( $_POST['action'] ) && $_POST['action'] == 'wpuf_pay' && wp_verify_nonce( $_POST['_wpnonce'], 'wpuf_payment_gateway' ) ) {
310
-
311
- $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
312
- $pack_id = isset( $_REQUEST['pack_id'] ) ? intval( $_REQUEST['pack_id'] ) : 0;
313
- $gateway = $_POST['wpuf_payment_method'];
314
- $type = $_POST['type'];
 
315
  $current_user = wpuf_get_user();
316
  $current_pack = $current_user->subscription()->current_pack();
317
- $cost = 0 ;
318
 
319
  if ( is_user_logged_in() ) {
320
  $userdata = wp_get_current_user();
321
  } else {
322
- $user_id = isset( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : 0;
323
 
324
  if ( $user_id ) {
325
  $userdata = get_userdata( $user_id );
326
- } else if ( $type == 'post' && !is_user_logged_in() ) {
327
  $post = get_post( $post_id );
328
  $user_id = $post->post_author;
329
  $userdata = get_userdata( $user_id );
330
  } else {
331
- $userdata = new stdClass;
332
  $userdata->ID = 0;
333
  $userdata->user_email = '';
334
  $userdata->first_name = '';
@@ -336,7 +344,7 @@ class WPUF_Payment {
336
  }
337
  }
338
 
339
- switch ($type) {
340
  case 'post':
341
  $post = get_post( $post_id );
342
  $form_id = get_post_meta( $post_id, '_wpuf_form_id', true );
@@ -346,7 +354,7 @@ class WPUF_Payment {
346
  $fallback_on = $form->is_enabled_fallback_cost();
347
  $post_count = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
348
 
349
- if ( $force_pack && $fallback_on && !is_wp_error ( $current_pack ) && !$post_count ) {
350
  $amount = $form->get_subs_fallback_cost();
351
  } else {
352
  $amount = $form->get_pay_per_post_cost();
@@ -365,22 +373,22 @@ class WPUF_Payment {
365
  break;
366
  }
367
 
368
- $payment_vars = array(
369
  'currency' => wpuf_get_option( 'currency', 'wpuf_payment' ),
370
  'price' => $amount,
371
  'item_number' => $item_number,
372
  'item_name' => $item_name,
373
  'type' => $type,
374
- 'user_info' => array(
375
  'id' => $userdata->ID,
376
  'email' => $userdata->user_email,
377
  'first_name' => $userdata->first_name,
378
- 'last_name' => $userdata->last_name
379
- ),
380
  'date' => date( 'Y-m-d H:i:s' ),
381
  'post_data' => $_POST,
382
  'custom' => isset( $custom ) ? $custom : '',
383
- );
384
 
385
  $address_fields = wpuf_get_user_address();
386
 
@@ -403,8 +411,9 @@ class WPUF_Payment {
403
  * Insert payment info to database
404
  *
405
  * @global object $wpdb
406
- * @param array $data payment data to insert
407
- * @param int $transaction_id the transaction id in case of update
 
408
  */
409
  public static function insert_payment( $data, $transaction_id = 0, $recurring = false ) {
410
  global $wpdb;
@@ -412,9 +421,9 @@ class WPUF_Payment {
412
  $user_id = get_current_user_id();
413
 
414
  //check if it's already there
415
- $sql = $wpdb->prepare( "SELECT transaction_id
416
- FROM " . $wpdb->prefix . "wpuf_transaction
417
- WHERE transaction_id = %s LIMIT 1", $transaction_id );
418
 
419
  $result = $wpdb->get_row( $sql );
420
 
@@ -438,7 +447,7 @@ class WPUF_Payment {
438
  $data['payer_address'] = maybe_serialize( $data['payer_address'] );
439
  }
440
 
441
- if( isset( $profile_id ) ) {
442
  $data['profile_id'] = $profile_id;
443
  }
444
 
@@ -447,11 +456,11 @@ class WPUF_Payment {
447
 
448
  do_action( 'wpuf_payment_received', $data, $recurring );
449
  } else {
450
- $wpdb->update( $wpdb->prefix . 'wpuf_transaction', $data, array('transaction_id' => $transaction_id) );
451
  }
452
 
453
  //workaround for subscriptions can't be assigned from user profile regression
454
- if ( ! did_action( 'wpuf_payment_received' ) ) {
455
  do_action( 'wpuf_payment_received', $data, $recurring );
456
  }
457
  }
@@ -461,10 +470,10 @@ class WPUF_Payment {
461
  *
462
  * @param array $info payment information
463
  */
464
- function payment_notify_admin( $info ) {
465
- $headers = "From: " . get_bloginfo( 'name' ) . " <" . get_bloginfo( 'admin_email' ) . ">" . "\r\n\\";
466
  $subject = sprintf( __( '[%s] Payment Received', 'wp-user-frontend' ), get_bloginfo( 'name' ) );
467
- $msg = sprintf( __( 'New payment received at %s', 'wp-user-frontend' ), get_bloginfo( 'name' ) );
468
 
469
  $receiver = get_bloginfo( 'admin_email' );
470
  wp_mail( $receiver, $subject, $msg, $headers );
@@ -478,13 +487,15 @@ class WPUF_Payment {
478
  * @since 2.4.1
479
  */
480
  public function handle_cancel_payment() {
481
- if ( ! isset( $_POST['wpuf_payment_cancel_submit'] ) || $_POST['action'] != 'wpuf_cancel_pay' || ! wp_verify_nonce( $_POST['wpuf_payment_cancel'], '_wpnonce' ) ) {
 
 
 
482
  return;
483
  }
484
 
485
- $gateway = sanitize_text_field( $_POST['gateway'] );
486
 
487
  do_action( "wpuf_cancel_payment_{$gateway}", $_POST );
488
  }
489
-
490
  }
4
  * WP User Frontend payment gateway handler
5
  *
6
  * @since 0.8
 
7
  */
8
  class WPUF_Payment {
9
 
10
+ public function __construct() {
11
+ add_action( 'init', [ $this, 'send_to_gateway' ] );
12
+ add_action( 'wpuf_payment_received', [ $this, 'payment_notify_admin' ] );
13
+ add_filter( 'the_content', [ $this, 'payment_page' ] );
14
+ add_action( 'init', [ $this, 'handle_cancel_payment' ] );
15
  }
16
 
17
  public static function get_payment_gateways() {
18
 
19
  // default, built-in gateways
20
+ $gateways = [
21
+ 'paypal' => [
22
  'admin_label' => __( 'PayPal', 'wp-user-frontend' ),
23
  'checkout_label' => __( 'PayPal', 'wp-user-frontend' ),
24
+ 'icon' => apply_filters( 'wpuf_paypal_checkout_icon', WPUF_ASSET_URI . '/images/paypal.png' ),
25
+ ],
26
+ 'bank' => [
27
  'admin_label' => __( 'Bank Payment', 'wp-user-frontend' ),
28
  'checkout_label' => __( 'Bank Payment', 'wp-user-frontend' ),
29
+ ],
30
+ ];
31
 
32
  $gateways = apply_filters( 'wpuf_payment_gateways', $gateways );
33
 
39
  *
40
  * @return array
41
  */
42
+ public function get_active_gateways() {
43
  $all_gateways = wpuf_get_gateways( 'checkout' );
44
  $active_gateways = wpuf_get_option( 'active_gateways', 'wpuf_payment' );
45
+ $active_gateways = is_array( $active_gateways ) ? $active_gateways : [];
46
+ $gateways = [];
47
 
48
+ foreach ( $all_gateways as $id => $label ) {
49
  if ( array_key_exists( $id, $active_gateways ) ) {
50
  $gateways[$id] = $label;
51
  }
57
  /**
58
  * Show the payment page
59
  *
60
+ * @param string $content
61
+ *
62
  * @return string
63
  */
64
+ public function payment_page( $content ) {
65
  global $post;
66
 
67
+ $pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
68
  $billing_amount = 0;
69
+ $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : '';
70
+
71
+ if ( $action == 'wpuf_pay' && $pay_page == 0 ) {
72
+ esc_html_e( 'Please select your payment page from admin panel', 'wp-user-frontend' );
73
 
 
 
74
  return;
75
  }
76
 
77
+ if ( $post->ID == $pay_page && $action == 'wpuf_pay' ) {
 
78
  if ( !is_user_logged_in() ) {
79
  //return __( 'You are not logged in', 'wpuf' );
80
  }
81
+ $get_type = isset( $_REQUEST['type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['type'] ) ) : '';
82
+ $type = ( $get_type == 'post' ) ? 'post' : 'pack';
83
+ $post_id = isset( $_REQUEST['post_id'] ) ? intval( wp_unslash( $_REQUEST['post_id'] ) ) : 0;
84
+ $pack_id = isset( $_REQUEST['pack_id'] ) ? intval( wp_unslash( $_REQUEST['pack_id'] ) ) : 0;
85
  $is_free = false;
86
 
87
  if ( $pack_id ) {
88
  $pack_detail = WPUF_Subscription::get_subscription( $pack_id );
89
  $recurring_pay = isset( $pack_detail->meta_value['recurring_pay'] ) ? $pack_detail->meta_value['recurring_pay'] : 'no';
90
 
91
+ if ( empty( $pack_detail->meta_value['billing_amount'] ) || $pack_detail->meta_value['billing_amount'] <= 0 ) {
92
  $is_free = true;
93
  }
94
  }
96
  $gateways = $this->get_active_gateways();
97
 
98
  if ( isset( $_REQUEST['wpuf_payment_submit'] ) ) {
99
+ $selected_gateway = isset( $_REQUEST['wpuf_payment_method'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpuf_payment_method'] ) ) : '';
100
  } else {
101
  $selected_gateway = 'paypal';
102
  }
106
  if ( is_user_logged_in() ) {
107
  $current_user = wp_get_current_user();
108
  } else {
109
+ $user_id = isset( $_GET['user_id'] ) ? intval( wp_unslash( $_GET['user_id'] ) ) : 0;
110
  $current_user = get_userdata( $user_id );
111
  }
112
 
113
  if ( $pack_id && $is_free ) {
 
114
  $wpuf_subscription = WPUF_Subscription::init();
115
+ $wpuf_user = new WPUF_User( $current_user->ID );
116
 
117
+ if ( !$wpuf_user->subscription()->used_free_pack( $pack_id ) ) {
118
  wpuf_get_user( $current_user->ID )->subscription()->add_pack( $pack_id, null, false, 'free' );
119
  $wpuf_user->subscription()->add_free_pack( $current_user->ID, $pack_id );
120
 
121
  $message = apply_filters( 'wpuf_fp_activated_msg', __( 'Your free package has been activated. Enjoy!', 'wp-user-frontend' ) );
122
  } else {
123
  $message = apply_filters( 'wpuf_fp_activated_error', __( 'You already have activated a free package previously.', 'wp-user-frontend' ) );
124
+ } ?>
125
+ <div class="wpuf-info"><?php echo esc_html( $message ); ?></div>
 
126
  <?php
127
  } else {
128
  ?>
130
  ?>
131
  <div class="wpuf-payment-page-wrap wpuf-pay-row">
132
  <?php
133
+ $pay_page_style = ''; ?>
 
134
  <div class="wpuf-bill-addr-wrap wpuf-pay-col">
135
  <?php if ( wpuf_get_option( 'show_address', 'wpuf_address_options', false ) ) {
136
+ $pay_page_style = 'vertical-align:top; margin-left: 20px; display: inline-block;'; ?>
 
137
  <div class="wpuf-bill-addr-info">
138
+ <h3> <?php esc_html_e( 'Billing Address', 'wp-user-frontend' ); ?> </h3>
139
  <div class="wpuf-bill_addr-inner">
140
  <?php
141
  $add_form = new WPUF_Ajax_Address_Form();
143
  ?>
144
  </div>
145
  </div>
146
+ <?php
147
+ } ?>
148
  </div>
149
+ <div class="wpuf-payment-gateway-wrap" style="<?php echo esc_attr( $pay_page_style ); ?>">
150
  <form id="wpuf-payment-gateway" action="" method="POST">
151
 
152
  <?php if ( $pack_id ) {
153
  $pack = WPUF_Subscription::init()->get_subscription( $pack_id );
154
  $details_meta = WPUF_Subscription::init()->get_details_meta_value();
155
  $currency = wpuf_get_currency( 'symbol' );
156
+
157
  if ( is_user_logged_in() ) {
158
  ?>
159
+ <input type="hidden" name="user_id" value="<?php echo esc_attr( $current_user->ID ); ?>">
160
+ <?php
161
+ } ?>
162
 
163
  <div class="wpuf-coupon-info-wrap wpuf-pay-col">
164
  <div class="wpuf-coupon-info">
165
  <div class="wpuf-pack-info">
166
  <h3 class="wpuf-pay-col">
167
+ <?php esc_html_e( 'Pricing & Plans', 'wp-user-frontend' ); ?>
168
 
169
+ <a style="white-space: nowrap" href="<?php echo esc_attr( wpuf_get_subscription_page_url() ); ?>"><?php esc_html_e( 'Change Pack', 'wp-user-frontend' ); ?></a>
170
  </h3>
171
  <div class="wpuf-subscription-error"></div>
172
  <div class="wpuf-subscription-success"></div>
173
 
174
  <div class="wpuf-pack-inner">
175
 
176
+ <?php
177
+ if ( class_exists( 'WPUF_Coupons' ) ) {
178
+ echo wp_kses_post( WPUF_Coupons::init()->after_apply_coupon( $pack ) );
179
+ } else {
180
+ $pack_cost = $pack->meta_value['billing_amount'];
181
  $billing_amount = apply_filters( 'wpuf_payment_amount', $pack->meta_value['billing_amount'] );
182
  ?>
183
+
184
  <div id="wpuf_type" style="display: none"><?php echo 'pack'; ?></div>
185
+ <div id="wpuf_id" style="display: none"><?php echo esc_attr( $pack_id ); ?></div>
186
+ <div><?php esc_html_e( 'Selected Pack ', 'wp-user-frontend' ); ?>: <strong><?php echo esc_attr( $pack->post_title ); ?></strong></div>
187
+ <div><?php esc_html_e( 'Pack Price ', 'wp-user-frontend' ); ?>: <strong><span id="wpuf_pay_page_cost"><?php echo esc_attr( wpuf_format_price( $pack_cost ) ); ?></strong></span></div>
188
 
189
  <?php do_action( 'wpuf_before_pack_payment_total' ); ?>
190
 
191
+ <div><?php esc_html_e( 'Total', 'wp-user-frontend' ); ?>: <strong><span id="wpuf_pay_page_total"><?php echo esc_attr( wpuf_format_price( $billing_amount ) ); ?></strong></span></div>
192
+ <?php
193
+ } ?>
194
  </div>
195
  </div>
196
  </div>
201
  <input type="text" name="coupon_code" size="20" class="wpuf-coupon-field">
202
  <input type="hidden" name="coupon_id" size="20" class="wpuf-coupon-id-field">
203
  <div>
204
+ <a href="#" data-pack_id="<?php echo esc_attr( $pack_id ); ?>" class="wpuf-apply-coupon"><?php esc_html_e( 'Apply Coupon', 'wp-user-frontend' ); ?></a>
205
+ <a href="#" data-pack_id="<?php echo esc_attr( $pack_id ); ?>" class="wpuf-copon-cancel"><?php esc_html_e( 'Cancel', 'wp-user-frontend' ); ?></a>
206
  </div>
207
  </div>
208
+ <a href="#" class="wpuf-copon-show"><?php esc_html_e( 'Have a discount code?', 'wp-user-frontend' ); ?></a>
209
 
210
+ <?php } // coupon?>
211
  </div>
212
 
213
+ <?php
214
+ }
215
+
216
+ if ( $post_id ) {
217
+ $form = new WPUF_Form( get_post_meta( $post_id, '_wpuf_form_id', true ) );
218
+ $force_pack = $form->is_enabled_force_pack();
219
+ $pay_per_post = $form->is_enabled_pay_per_post();
220
+ $fallback_enabled = $form->is_enabled_fallback_cost();
221
+ $fallback_cost = (float) $form->get_subs_fallback_cost();
222
+ $pay_per_post_cost = (float) $form->get_pay_per_post_cost();
223
+ $current_user = wpuf_get_user();
224
+
225
+ $current_pack = $current_user->subscription()->current_pack();
226
+
227
+ if ( $force_pack && !is_wp_error( $current_pack ) && $fallback_enabled ) {
228
+ $post_cost = $fallback_cost;
229
+ $billing_amount = apply_filters( 'wpuf_payment_amount', $fallback_cost );
230
+ } else {
231
+ $post_cost = $pay_per_post_cost;
232
+ $billing_amount = apply_filters( 'wpuf_payment_amount', $pay_per_post_cost );
233
+ } ?>
234
  <div id="wpuf_type" style="display: none"><?php echo 'post'; ?></div>
235
+ <div id="wpuf_id" style="display: none"><?php echo esc_attr( $post_id ); ?></div>
236
+ <div><?php esc_html_e( 'Post cost', 'wp-user-frontend' ); ?>: <strong><span id="wpuf_pay_page_cost"><?php echo esc_attr( wpuf_format_price( $post_cost ) ); ?></strong></span></div>
237
 
238
  <?php do_action( 'wpuf_before_pack_payment_total' ); ?>
239
 
240
+ <div><?php esc_html_e( 'Total', 'wp-user-frontend' ); ?>: <strong><span id="wpuf_pay_page_total"><?php echo esc_html( wpuf_format_price( $billing_amount ) ); ?></strong></span></div>
241
+ <?php
242
+ } ?>
243
+ <?php wp_nonce_field( 'wpuf_payment_gateway' ); ?>
244
 
245
  <?php do_action( 'wpuf_before_payment_gateway' ); ?>
246
 
247
  <p>
248
+ <label for="wpuf-payment-method"><?php esc_html_e( 'Choose Your Payment Method', 'wp-user-frontend' ); ?></label><br />
249
 
250
  <ul class="wpuf-payment-gateways">
251
+ <?php foreach ( $gateways as $gateway_id => $gateway ) { ?>
252
+ <li class="wpuf-gateway-<?php echo esc_attr( $gateway_id ); ?>">
253
  <label>
254
  <input name="wpuf_payment_method" type="radio" value="<?php echo esc_attr( $gateway_id ); ?>" <?php checked( $selected_gateway, $gateway_id ); ?>>
255
  <?php
256
+ echo esc_html( $gateway['label'] );
257
 
258
  if ( !empty( $gateway['icon'] ) ) {
259
+ printf( ' <img src="%s" alt="image">', wp_kses_post( $gateway['icon'] ) );
260
  }
261
  ?>
262
  </label>
263
 
264
  <div class="wpuf-payment-instruction" style="display: none;">
265
+ <div class="wpuf-instruction"><?php echo esc_html( wpuf_get_option( 'gate_instruct_' . esc_html( $gateway_id ), 'wpuf_payment' ) ); ?></div>
266
 
267
  <?php do_action( 'wpuf_gateway_form_' . $gateway_id, $type, $post_id, $pack_id ); ?>
268
  </div>
272
  </p>
273
  <?php do_action( 'wpuf_after_payment_gateway' ); ?>
274
  <p>
275
+ <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
276
  <input type="hidden" name="action" value="wpuf_pay" />
277
  <?php if ( $post_id ) { ?>
278
+ <input type="hidden" name="post_id" value="<?php echo esc_attr( $post_id ); ?>" />
279
  <?php } ?>
280
 
281
  <?php if ( $pack_id ) { ?>
282
+ <input type="hidden" name="pack_id" value="<?php echo esc_attr( $pack_id ); ?>" />
283
+ <input type="hidden" name="recurring_pay" value="<?php echo esc_attr( $recurring_pay ); ?>" />
284
  <?php } ?>
285
+ <input type="submit" name="wpuf_payment_submit" class="wpuf-btn" value="<?php esc_html_e( 'Proceed', 'wp-user-frontend' ); ?>"/>
286
  </p>
287
  </form>
288
  </div>
289
  </div>
290
+ <?php
291
+ } else { ?>
292
+ <?php esc_html_e( 'No Payment gateway found', 'wp-user-frontend' ); ?>
293
  <?php } ?>
294
 
295
  <?php
311
  *
312
  * Need to use `wpuf_gateway_{$gateway_name}
313
  */
314
+ public function send_to_gateway() {
315
+ $action = isset( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
316
+ $nonce = isset( $_POST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ) : '';
317
+
318
+ if ( $action == 'wpuf_pay' && isset( $nonce ) && wp_verify_nonce( $nonce, 'wpuf_payment_gateway' ) ) {
319
+ $post_id = isset( $_REQUEST['post_id'] ) ? intval( wp_unslash( $_REQUEST['post_id'] ) ) : 0;
320
+ $pack_id = isset( $_REQUEST['pack_id'] ) ? intval( wp_unslash( $_REQUEST['pack_id'] ) ) : 0;
321
+ $gateway = isset( $_POST['wpuf_payment_method'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_payment_method'] ) ) : '';
322
+ $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
323
  $current_user = wpuf_get_user();
324
  $current_pack = $current_user->subscription()->current_pack();
325
+ $cost = 0;
326
 
327
  if ( is_user_logged_in() ) {
328
  $userdata = wp_get_current_user();
329
  } else {
330
+ $user_id = isset( $_REQUEST['user_id'] ) ? intval( wp_unslash( $_REQUEST['user_id'] ) ) : 0;
331
 
332
  if ( $user_id ) {
333
  $userdata = get_userdata( $user_id );
334
+ } elseif ( $type == 'post' && !is_user_logged_in() ) {
335
  $post = get_post( $post_id );
336
  $user_id = $post->post_author;
337
  $userdata = get_userdata( $user_id );
338
  } else {
339
+ $userdata = new stdClass();
340
  $userdata->ID = 0;
341
  $userdata->user_email = '';
342
  $userdata->first_name = '';
344
  }
345
  }
346
 
347
+ switch ( $type ) {
348
  case 'post':
349
  $post = get_post( $post_id );
350
  $form_id = get_post_meta( $post_id, '_wpuf_form_id', true );
354
  $fallback_on = $form->is_enabled_fallback_cost();
355
  $post_count = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
356
 
357
+ if ( $force_pack && $fallback_on && !is_wp_error( $current_pack ) && !$post_count ) {
358
  $amount = $form->get_subs_fallback_cost();
359
  } else {
360
  $amount = $form->get_pay_per_post_cost();
373
  break;
374
  }
375
 
376
+ $payment_vars = [
377
  'currency' => wpuf_get_option( 'currency', 'wpuf_payment' ),
378
  'price' => $amount,
379
  'item_number' => $item_number,
380
  'item_name' => $item_name,
381
  'type' => $type,
382
+ 'user_info' => [
383
  'id' => $userdata->ID,
384
  'email' => $userdata->user_email,
385
  'first_name' => $userdata->first_name,
386
+ 'last_name' => $userdata->last_name,
387
+ ],
388
  'date' => date( 'Y-m-d H:i:s' ),
389
  'post_data' => $_POST,
390
  'custom' => isset( $custom ) ? $custom : '',
391
+ ];
392
 
393
  $address_fields = wpuf_get_user_address();
394
 
411
  * Insert payment info to database
412
  *
413
  * @global object $wpdb
414
+ *
415
+ * @param array $data payment data to insert
416
+ * @param int $transaction_id the transaction id in case of update
417
  */
418
  public static function insert_payment( $data, $transaction_id = 0, $recurring = false ) {
419
  global $wpdb;
421
  $user_id = get_current_user_id();
422
 
423
  //check if it's already there
424
+ $sql = $wpdb->prepare( 'SELECT transaction_id
425
+ FROM ' . $wpdb->prefix . 'wpuf_transaction
426
+ WHERE transaction_id = %s LIMIT 1', $transaction_id );
427
 
428
  $result = $wpdb->get_row( $sql );
429
 
447
  $data['payer_address'] = maybe_serialize( $data['payer_address'] );
448
  }
449
 
450
+ if ( isset( $profile_id ) ) {
451
  $data['profile_id'] = $profile_id;
452
  }
453
 
456
 
457
  do_action( 'wpuf_payment_received', $data, $recurring );
458
  } else {
459
+ $wpdb->update( $wpdb->prefix . 'wpuf_transaction', $data, ['transaction_id' => $transaction_id] );
460
  }
461
 
462
  //workaround for subscriptions can't be assigned from user profile regression
463
+ if ( !did_action( 'wpuf_payment_received' ) ) {
464
  do_action( 'wpuf_payment_received', $data, $recurring );
465
  }
466
  }
470
  *
471
  * @param array $info payment information
472
  */
473
+ public function payment_notify_admin( $info ) {
474
+ $headers = 'From: ' . get_bloginfo( 'name' ) . ' <' . get_bloginfo( 'admin_email' ) . '>' . "\r\n\\";
475
  $subject = sprintf( __( '[%s] Payment Received', 'wp-user-frontend' ), get_bloginfo( 'name' ) );
476
+ $msg = sprintf( __( 'New payment received at %s', 'wp-user-frontend' ), get_bloginfo( 'name' ) );
477
 
478
  $receiver = get_bloginfo( 'admin_email' );
479
  wp_mail( $receiver, $subject, $msg, $headers );
487
  * @since 2.4.1
488
  */
489
  public function handle_cancel_payment() {
490
+ $nonce = isset( $_POST['wpuf_payment_cancel'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_payment_cancel'] ) ) : '';
491
+ $action = isset( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
492
+
493
+ if ( !isset( $_POST['wpuf_payment_cancel_submit'] ) || $action != 'wpuf_cancel_pay' || !wp_verify_nonce( $nonce, '_wpnonce' ) ) {
494
  return;
495
  }
496
 
497
+ $gateway = isset( $_POST['gateway'] ) ? sanitize_text_field( wp_unslash( $_POST['gateway'] ) ) : '';
498
 
499
  do_action( "wpuf_cancel_payment_{$gateway}", $_POST );
500
  }
 
501
  }
class/post-form-template.php CHANGED
@@ -10,7 +10,7 @@ abstract class WPUF_Post_Form_Template {
10
  /**
11
  * If the form is enabled
12
  *
13
- * @var boolean
14
  */
15
  public $enabled = true;
16
 
@@ -66,13 +66,13 @@ abstract class WPUF_Post_Form_Template {
66
  protected $form_notifications;
67
 
68
  public function __construct() {
69
- $this->conditionals = array(
70
  'condition_status' => 'no',
71
- 'cond_field' => array(),
72
- 'cond_operator' => array( '=' ),
73
- 'cond_option' => array( '- select -' ),
74
- 'cond_logic' => 'all'
75
- );
76
  }
77
 
78
  /**
@@ -125,7 +125,7 @@ abstract class WPUF_Post_Form_Template {
125
  /**
126
  * Check if the template is enabled
127
  *
128
- * @return boolean
129
  */
130
  public function is_enabled() {
131
  return $this->enabled;
@@ -134,24 +134,26 @@ abstract class WPUF_Post_Form_Template {
134
  /**
135
  * Run necessary processing after new post insert
136
  *
137
- * @param int $post_id
138
- * @param int $form_id
139
- * @param array $form_settings
140
  *
141
  * @return void
142
  */
143
- public function after_insert( $post_id, $form_id, $form_settings ) {}
 
144
 
145
  /**
146
  * Run necessary processing after editing a post
147
  *
148
- * @param int $post_id
149
- * @param int $form_id
150
- * @param array $form_settings
151
  *
152
  * @return void
153
  */
154
- public function after_update( $post_id, $form_id, $form_settings ) {}
 
155
 
156
  /**
157
  * wpuf_visibility property for all fields
@@ -159,11 +161,11 @@ abstract class WPUF_Post_Form_Template {
159
  * @since 2.6
160
  *
161
  * @return array
162
- */
163
  public function get_default_visibility_prop( $default = 'everyone' ) {
164
- return array(
165
- 'selected' => $default,
166
- 'choices' => array()
167
- );
168
  }
169
  }
10
  /**
11
  * If the form is enabled
12
  *
13
+ * @var bool
14
  */
15
  public $enabled = true;
16
 
66
  protected $form_notifications;
67
 
68
  public function __construct() {
69
+ $this->conditionals = [
70
  'condition_status' => 'no',
71
+ 'cond_field' => [],
72
+ 'cond_operator' => [ '=' ],
73
+ 'cond_option' => [ '- select -' ],
74
+ 'cond_logic' => 'all',
75
+ ];
76
  }
77
 
78
  /**
125
  /**
126
  * Check if the template is enabled
127
  *
128
+ * @return bool
129
  */
130
  public function is_enabled() {
131
  return $this->enabled;
134
  /**
135
  * Run necessary processing after new post insert
136
  *
137
+ * @param int $post_id
138
+ * @param int $form_id
139
+ * @param array $form_settings
140
  *
141
  * @return void
142
  */
143
+ public function after_insert( $post_id, $form_id, $form_settings ) {
144
+ }
145
 
146
  /**
147
  * Run necessary processing after editing a post
148
  *
149
+ * @param int $post_id
150
+ * @param int $form_id
151
+ * @param array $form_settings
152
  *
153
  * @return void
154
  */
155
+ public function after_update( $post_id, $form_id, $form_settings ) {
156
+ }
157
 
158
  /**
159
  * wpuf_visibility property for all fields
161
  * @since 2.6
162
  *
163
  * @return array
164
+ */
165
  public function get_default_visibility_prop( $default = 'everyone' ) {
166
+ return [
167
+ 'selected' => $default,
168
+ 'choices' => [],
169
+ ];
170
  }
171
  }
class/post-form-templates/post.php CHANGED
@@ -12,8 +12,8 @@ class WPUF_Post_Form_Template_Post extends WPUF_Post_Form_Template {
12
  $this->title = __( 'Post Form', 'wp-user-frontend' );
13
  $this->description = __( 'Form for creating a blog post.', 'wp-user-frontend' );
14
  $this->image = WPUF_ASSET_URI . '/images/templates/post.png';
15
- $this->form_fields = array(
16
- array(
17
  'input_type' => 'text',
18
  'template' => 'post_title',
19
  'required' => 'yes',
@@ -26,30 +26,30 @@ class WPUF_Post_Form_Template_Post extends WPUF_Post_Form_Template {
26
  'default' => '',
27
  'size' => '40',
28
  'wpuf_cond' => $this->conditionals,
29
- 'wpuf_visibility' => $this->get_default_visibility_prop()
30
- ),
31
- array(
32
  'input_type' => 'taxonomy',
33
  'template' => 'taxonomy',
34
  'required' => 'yes',
35
  'label' => __( 'Category', 'wp-user-frontend' ),
36
  'name' => 'category',
37
  'is_meta' => 'no',
38
- 'help' => __( 'Select a category for your post', 'wp-user-frontend' ) ,
39
  'first' => __( '- select -', 'wp-user-frontend' ),
40
  'css' => '',
41
  'type' => 'select',
42
  'orderby' => 'name',
43
  'order' => 'ASC',
44
  'exclude_type' => 'exclude',
45
- 'exclude' => array(),
46
  'woo_attr' => 'no',
47
  'woo_attr_vis' => 'no',
48
- 'options' => array(),
49
  'wpuf_cond' => $this->conditionals,
50
- 'wpuf_visibility' => $this->get_default_visibility_prop()
51
- ),
52
- array(
53
  'input_type' => 'textarea',
54
  'template' => 'post_content',
55
  'required' => 'yes',
@@ -66,9 +66,9 @@ class WPUF_Post_Form_Template_Post extends WPUF_Post_Form_Template {
66
  'insert_image' => 'yes',
67
  'word_restriction' => '',
68
  'wpuf_cond' => $this->conditionals,
69
- 'wpuf_visibility' => $this->get_default_visibility_prop()
70
- ),
71
- array(
72
  'input_type' => 'image_upload',
73
  'template' => 'featured_image',
74
  'count' => '1',
@@ -81,9 +81,9 @@ class WPUF_Post_Form_Template_Post extends WPUF_Post_Form_Template {
81
  'css' => '',
82
  'max_size' => '1024',
83
  'wpuf_cond' => $this->conditionals,
84
- 'wpuf_visibility' => $this->get_default_visibility_prop()
85
- ),
86
- array(
87
  'input_type' => 'textarea',
88
  'template' => 'post_excerpt',
89
  'required' => 'no',
@@ -98,9 +98,9 @@ class WPUF_Post_Form_Template_Post extends WPUF_Post_Form_Template {
98
  'default' => '',
99
  'rich' => 'no',
100
  'wpuf_cond' => $this->conditionals,
101
- 'wpuf_visibility' => $this->get_default_visibility_prop()
102
- ),
103
- array(
104
  'input_type' => 'text',
105
  'template' => 'post_tags',
106
  'required' => 'no',
@@ -113,11 +113,11 @@ class WPUF_Post_Form_Template_Post extends WPUF_Post_Form_Template {
113
  'default' => '',
114
  'size' => '40',
115
  'wpuf_cond' => $this->conditionals,
116
- 'wpuf_visibility' => $this->get_default_visibility_prop()
117
- ),
118
- );
119
 
120
- $this->form_settings = array (
121
  'post_type' => 'post',
122
  'post_status' => 'publish',
123
  'default_cat' => '-1',
@@ -126,24 +126,24 @@ class WPUF_Post_Form_Template_Post extends WPUF_Post_Form_Template {
126
  'redirect_to' => 'post',
127
  'comment_status' => 'open',
128
  'submit_text' => __( 'Create Post', 'wp-user-frontend' ),
129
- 'submit_button_cond' => array(
130
  'condition_status' => 'no',
131
  'cond_logic' => 'any',
132
- 'conditions' => array(
133
- array(
134
  'name' => '',
135
  'operator' => '=',
136
- 'option' => ''
137
- )
138
- )
139
- ),
140
  'edit_post_status' => 'publish',
141
  'edit_redirect_to' => 'same',
142
  'update_message' => __( 'Post has been updated successfully. <a target="_blank" href="%link%">View post</a>', 'wp-user-frontend' ),
143
  'edit_url' => '',
144
  'update_text' => __( 'Update Post', 'wp-user-frontend' ),
145
  'form_template' => __CLASS__,
146
- 'notification' => array(
147
  'new' => 'on',
148
  'new_to' => get_option( 'admin_email' ),
149
  'new_subject' => 'New post has been created',
@@ -170,7 +170,7 @@ class WPUF_Post_Form_Template_Post extends WPUF_Post_Form_Template {
170
  Author: %author%
171
  Post URL: %permalink%
172
  Edit URL: %editlink%',
173
- ),
174
- );
175
  }
176
  }
12
  $this->title = __( 'Post Form', 'wp-user-frontend' );
13
  $this->description = __( 'Form for creating a blog post.', 'wp-user-frontend' );
14
  $this->image = WPUF_ASSET_URI . '/images/templates/post.png';
15
+ $this->form_fields = [
16
+ [
17
  'input_type' => 'text',
18
  'template' => 'post_title',
19
  'required' => 'yes',
26
  'default' => '',
27
  'size' => '40',
28
  'wpuf_cond' => $this->conditionals,
29
+ 'wpuf_visibility' => $this->get_default_visibility_prop(),
30
+ ],
31
+ [
32
  'input_type' => 'taxonomy',
33
  'template' => 'taxonomy',
34
  'required' => 'yes',
35
  'label' => __( 'Category', 'wp-user-frontend' ),
36
  'name' => 'category',
37
  'is_meta' => 'no',
38
+ 'help' => __( 'Select a category for your post', 'wp-user-frontend' ),
39
  'first' => __( '- select -', 'wp-user-frontend' ),
40
  'css' => '',
41
  'type' => 'select',
42
  'orderby' => 'name',
43
  'order' => 'ASC',
44
  'exclude_type' => 'exclude',
45
+ 'exclude' => [],
46
  'woo_attr' => 'no',
47
  'woo_attr_vis' => 'no',
48
+ 'options' => [],
49
  'wpuf_cond' => $this->conditionals,
50
+ 'wpuf_visibility' => $this->get_default_visibility_prop(),
51
+ ],
52
+ [
53
  'input_type' => 'textarea',
54
  'template' => 'post_content',
55
  'required' => 'yes',
66
  'insert_image' => 'yes',
67
  'word_restriction' => '',
68
  'wpuf_cond' => $this->conditionals,
69
+ 'wpuf_visibility' => $this->get_default_visibility_prop(),
70
+ ],
71
+ [
72
  'input_type' => 'image_upload',
73
  'template' => 'featured_image',
74
  'count' => '1',
81
  'css' => '',
82
  'max_size' => '1024',
83
  'wpuf_cond' => $this->conditionals,
84
+ 'wpuf_visibility' => $this->get_default_visibility_prop(),
85
+ ],
86
+ [
87
  'input_type' => 'textarea',
88
  'template' => 'post_excerpt',
89
  'required' => 'no',
98
  'default' => '',
99
  'rich' => 'no',
100
  'wpuf_cond' => $this->conditionals,
101
+ 'wpuf_visibility' => $this->get_default_visibility_prop(),
102
+ ],
103
+ [
104
  'input_type' => 'text',
105
  'template' => 'post_tags',
106
  'required' => 'no',
113
  'default' => '',
114
  'size' => '40',
115
  'wpuf_cond' => $this->conditionals,
116
+ 'wpuf_visibility' => $this->get_default_visibility_prop(),
117
+ ],
118
+ ];
119
 
120
+ $this->form_settings = [
121
  'post_type' => 'post',
122
  'post_status' => 'publish',
123
  'default_cat' => '-1',
126
  'redirect_to' => 'post',
127
  'comment_status' => 'open',
128
  'submit_text' => __( 'Create Post', 'wp-user-frontend' ),
129
+ 'submit_button_cond' => [
130
  'condition_status' => 'no',
131
  'cond_logic' => 'any',
132
+ 'conditions' => [
133
+ [
134
  'name' => '',
135
  'operator' => '=',
136
+ 'option' => '',
137
+ ],
138
+ ],
139
+ ],
140
  'edit_post_status' => 'publish',
141
  'edit_redirect_to' => 'same',
142
  'update_message' => __( 'Post has been updated successfully. <a target="_blank" href="%link%">View post</a>', 'wp-user-frontend' ),
143
  'edit_url' => '',
144
  'update_text' => __( 'Update Post', 'wp-user-frontend' ),
145
  'form_template' => __CLASS__,
146
+ 'notification' => [
147
  'new' => 'on',
148
  'new_to' => get_option( 'admin_email' ),
149
  'new_subject' => 'New post has been created',
170
  Author: %author%
171
  Post URL: %permalink%
172
  Edit URL: %editlink%',
173
+ ],
174
+ ];
175
  }
176
  }
class/render-form.php CHANGED
@@ -2,17 +2,20 @@
2
 
3
  /**
4
  * Handles form generaton and posting for add/edit post in frontend
5
- *
6
- * @package WP User Frontend
7
  */
8
  class WPUF_Render_Form {
 
 
 
 
 
9
 
10
- static $meta_key = 'wpuf_form';
11
- static $separator = ' | ';
12
- static $config_id = '_wpuf_form_id';
13
  private $form_condition_key = 'wpuf_cond';
 
14
  private static $_instance;
 
15
  private $field_count = 0;
 
16
  public $multiform_start = 0;
17
 
18
  public static function init() {
@@ -28,11 +31,11 @@ class WPUF_Render_Form {
28
  *
29
  * @param string $error
30
  */
31
- function send_error( $error ) {
32
- echo json_encode( array(
33
  'success' => false,
34
- 'error' => $error
35
- ) );
36
 
37
  die();
38
  }
@@ -40,20 +43,23 @@ class WPUF_Render_Form {
40
  /**
41
  * Search on multi dimentional array
42
  *
43
- * @param array $array
44
- * @param string $key name of key
45
  * @param string $value the value to search
 
46
  * @return array
47
  */
48
- function search( $array, $key, $value ) {
49
- $results = array();
50
 
51
  if ( is_array( $array ) ) {
52
- if ( isset( $array[$key] ) && $array[$key] == $value )
53
  $results[] = $array;
 
54
 
55
- foreach ($array as $subarray)
56
  $results = array_merge( $results, $this->search( $subarray, $key, $value ) );
 
57
  }
58
 
59
  return $results;
@@ -64,15 +70,20 @@ class WPUF_Render_Form {
64
  *
65
  * @return void
66
  */
67
- function validate_rs_captcha() {
68
- $rs_captcha_input = isset( $_POST['rs_captcha'] ) ? $_POST['rs_captcha'] : '';
69
- $rs_captcha_file = isset( $_POST['rs_captcha_val'] ) ? $_POST['rs_captcha_val'] : '';
 
 
 
 
 
 
70
 
71
  if ( class_exists( 'ReallySimpleCaptcha' ) ) {
72
  $captcha_instance = new ReallySimpleCaptcha();
73
 
74
  if ( !$captcha_instance->check( $rs_captcha_file, $rs_captcha_input ) ) {
75
-
76
  $this->send_error( __( 'Really Simple Captcha validation failed', 'wp-user-frontend' ) );
77
  } else {
78
  // validation success, remove the files
@@ -86,61 +97,65 @@ class WPUF_Render_Form {
86
  *
87
  * @return void
88
  */
89
- function validate_re_captcha( $no_captcha = '', $invisible = '' ) {
 
 
 
 
 
90
  // need to check if invisible reCaptcha need library or we can do it here.
91
  // ref: https://shareurcodes.com/blog/google%20invisible%20recaptcha%20integration%20with%20php
92
- $site_key = wpuf_get_option( 'recaptcha_public', 'wpuf_general' );
93
- $private_key = wpuf_get_option( 'recaptcha_private', 'wpuf_general' );
94
- if ( $no_captcha == 1 && 0 == $invisible ) {
 
95
 
 
96
  if ( !class_exists( 'WPUF_ReCaptcha' ) ) {
97
  require_once WPUF_ROOT . '/lib/recaptchalib_noCaptcha.php';
98
  }
99
 
100
- $response = null;
101
- $reCaptcha = new WPUF_ReCaptcha($private_key);
102
 
103
  $resp = $reCaptcha->verifyResponse(
104
- $_SERVER["REMOTE_ADDR"],
105
- $_POST["g-recaptcha-response"]
106
- );
107
 
108
  if ( !$resp->success ) {
109
  $this->send_error( __( 'noCaptcha reCAPTCHA validation failed', 'wp-user-frontend' ) );
110
  }
111
-
112
  } elseif ( $no_captcha == 0 && 0 == $invisible ) {
 
 
113
 
114
- $recap_challenge = isset( $_POST['recaptcha_challenge_field'] ) ? $_POST['recaptcha_challenge_field'] : '';
115
- $recap_response = isset( $_POST['recaptcha_response_field'] ) ? $_POST['recaptcha_response_field'] : '';
116
-
117
- $resp = recaptcha_check_answer( $private_key, $_SERVER["REMOTE_ADDR"], $recap_challenge, $recap_response );
118
 
119
  if ( !$resp->is_valid ) {
120
  $this->send_error( __( 'reCAPTCHA validation failed', 'wp-user-frontend' ) );
121
  }
122
-
123
  } elseif ( $no_captcha == 0 && 1 == $invisible ) {
124
-
125
  $response = null;
126
- $recaptcha = $_POST['g-recaptcha-response'];
127
- $object = new Invisible_Recaptcha( $site_key , $private_key );
128
 
129
  $response = $object->verifyResponse( $recaptcha );
130
 
131
- if ( isset( $response['success'] ) and $response['success'] != true) {
132
  $this->send_error( __( 'Invisible reCAPTCHA validation failed', 'wp-user-frontend' ) );
133
  }
134
  }
135
-
136
  }
137
 
138
  /**
139
  * Guess a suitable username for registration based on email address
 
140
  * @param string $email email address
 
141
  * @return string username
142
  */
143
- function guess_username( $email ) {
144
  // username from email address
145
  $username = sanitize_user( substr( $email, 0, strpos( $email, '@' ) ) );
146
 
@@ -151,6 +166,7 @@ class WPUF_Render_Form {
151
  // try to add some random number in username
152
  // and may be we got our username
153
  $username .= rand( 1, 199 );
 
154
  if ( !username_exists( $username ) ) {
155
  return $username;
156
  }
@@ -160,15 +176,16 @@ class WPUF_Render_Form {
160
  * Get input meta fields separated as post vars, taxonomy and meta vars
161
  *
162
  * @param int $form_id form id
 
163
  * @return array
164
  */
165
  public static function get_input_fields( $form_id ) {
166
  $form_vars = wpuf_get_form_fields( $form_id );
167
 
168
- $ignore_lists = array('section_break', 'html');
169
- $post_vars = $meta_vars = $taxonomy_vars = array();
170
 
171
- foreach ($form_vars as $key => $value) {
172
 
173
  // ignore section break and HTML input type
174
  if ( in_array( $value['input_type'], $ignore_lists ) ) {
@@ -194,7 +211,7 @@ class WPUF_Render_Form {
194
  }
195
  }
196
 
197
- return array($post_vars, $taxonomy_vars, $meta_vars);
198
  }
199
 
200
  public static function prepare_meta_fields( $meta_vars ) {
@@ -202,24 +219,31 @@ class WPUF_Render_Form {
202
  // skip files, put in a key => value paired array for later executation
203
  // process repeatable fields separately
204
  // if the input is array type, implode with separator in a field
 
205
 
206
- $files = array();
207
- $meta_key_value = array();
208
- $multi_repeated = array(); //multi repeated fields will in sotre duplicated meta key
209
-
210
- foreach ($meta_vars as $key => $value) {
211
 
 
 
 
 
 
 
 
212
  switch ( $value['input_type'] ) {
213
 
214
  // put files in a separate array, we'll process it later
215
  case 'file_upload':
216
  case 'image_upload':
217
 
218
- $files[] = array(
219
  'name' => $value['name'],
220
- 'value' => isset( $_POST['wpuf_files'][$value['name']] ) ? $_POST['wpuf_files'][$value['name']] : array(),
221
- 'count' => $value['count']
222
- );
 
223
  break;
224
 
225
  case 'repeat':
@@ -228,21 +252,20 @@ class WPUF_Render_Form {
228
  if ( isset( $value['multiple'] ) && $value['multiple'] == 'true' ) {
229
 
230
  // if there's any items in the array, process it
231
- if ( $_POST[$value['name']] ) {
232
-
233
- $ref_arr = array();
234
  $cols = count( $value['columns'] );
235
- $first = array_shift( array_values( $_POST[$value['name']] ) ); //first element
236
  $rows = count( $first );
237
 
238
  // loop through columns
239
- for ($i = 0; $i < $rows; $i++) {
240
 
241
  // loop through the rows and store in a temp array
242
- $temp = array();
243
- for ($j = 0; $j < $cols; $j++) {
244
 
245
- $temp[] = $_POST[$value['name']][$j][$i];
 
246
  }
247
 
248
  // store all fields in a row with self::$separator separated
@@ -255,15 +278,15 @@ class WPUF_Render_Form {
255
  }
256
  }
257
  } else {
258
- $meta_key_value[$value['name']] = implode( self::$separator, $_POST[$value['name']] );
259
  }
260
 
261
  break;
262
 
263
  case 'address':
264
 
265
- if ( isset( $_POST[ $value['name'] ] ) && is_array( $_POST[ $value['name'] ] ) ) {
266
- foreach ( $_POST[ $value['name'] ] as $address_field => $field_value ) {
267
  $meta_key_value[ $value['name'] ][ $address_field ] = sanitize_text_field( $field_value );
268
  }
269
  }
@@ -275,55 +298,54 @@ class WPUF_Render_Form {
275
  case 'number':
276
  case 'date':
277
 
278
- $meta_key_value[$value['name']] = sanitize_text_field( trim( $_POST[$value['name']] ) );
279
 
280
  break;
281
 
282
  case 'textarea':
283
 
284
- $meta_key_value[$value['name']] = wp_kses_post( $_POST[$value['name']] );
285
 
286
  break;
287
 
288
  case 'map':
289
- $data = array();
290
- $map_field_data = sanitize_text_field( trim( $_POST[$value['name']] ) );
291
 
292
  if ( !empty( $map_field_data ) ) {
293
- list($data['address'], $data['lat'], $data['lng']) = explode(" || ", $map_field_data);
294
- $meta_key_value[$value['name']] = $data;
295
  }
296
  break;
297
 
298
  default:
299
  // if it's an array, implode with this->separator
300
- if ( is_array( $_POST[$value['name']] ) ) {
301
  $acf_compatibility = wpuf_get_option( 'wpuf_compatibility_acf', 'wpuf_general', 'no' );
302
 
303
  if ( $value['input_type'] == 'address' ) {
304
- $meta_key_value[$value['name']] = $_POST[$value['name']];
305
  } elseif ( !empty( $acf_compatibility ) && $acf_compatibility == 'yes' ) {
306
- $meta_key_value[$value['name']] = maybe_serialize( $_POST[$value['name']] );
307
  } else {
308
- $meta_key_value[$value['name']] = implode( self::$separator, $_POST[$value['name']] );
309
  }
310
  } else {
311
- $meta_key_value[$value['name']] = trim( $_POST[$value['name']] );
312
  }
313
 
314
  break;
315
  }
316
-
317
  } //end foreach
318
 
319
- return array($meta_key_value, $multi_repeated, $files);
320
  }
321
 
322
- function guest_fields( $form_settings ) {
323
  ?>
324
  <li class="el-name">
325
  <div class="wpuf-label">
326
- <label><?php echo $form_settings['name_label']; ?> <span class="required">*</span></label>
327
  </div>
328
 
329
  <div class="wpuf-fields">
@@ -333,7 +355,7 @@ class WPUF_Render_Form {
333
 
334
  <li class="el-email">
335
  <div class="wpuf-label">
336
- <label><?php echo $form_settings['email_label']; ?> <span class="required">*</span></label>
337
  </div>
338
 
339
  <div class="wpuf-fields">
@@ -349,17 +371,18 @@ class WPUF_Render_Form {
349
  * @param int $form_id
350
  * @param int $post_id
351
  */
352
- function render_form( $form_id, $post_id = NULL ) {
353
-
354
  $form_status = get_post_status( $form_id );
355
 
356
- if ( ! $form_status ) {
357
- echo '<div class="wpuf-message">' . __( 'Your selected form is no longer available.', 'wp-user-frontend' ) . '</div>';
 
358
  return;
359
  }
360
 
361
  if ( $form_status != 'publish' ) {
362
- echo '<div class="wpuf-message">' . __( "Please make sure you've published your form.", 'wp-user-frontend' ) . '</div>';
 
363
  return;
364
  }
365
 
@@ -375,16 +398,17 @@ class WPUF_Render_Form {
375
  wp_enqueue_style( 'wpuf-' . $layout );
376
  }
377
 
378
- if ( ! is_user_logged_in() && $form_settings['guest_post'] != 'true' ) {
379
- echo '<div class="wpuf-message">' . $form_settings['message_restrict'] . '</div>';
 
380
  return;
381
  }
382
 
383
  if ( $form_vars ) {
384
  ?>
385
- <form class="wpuf-form-add wpuf-form-<?php echo $layout; ?> <?php echo ($layout == 'layout1') ? $theme_css : 'wpuf-style'; ?>" action="" method="post">
386
 
387
- <ul class="wpuf-form form-label-<?php echo $label_position; ?>">
388
 
389
  <?php
390
  if ( !$post_id ) {
@@ -393,19 +417,18 @@ class WPUF_Render_Form {
393
  do_action( 'wpuf_edit_post_form_top', $form_id, $post_id, $form_settings );
394
  }
395
 
396
- if ( !is_user_logged_in() && $form_settings['guest_post'] == 'true' && $form_settings['guest_details'] == 'true' ) {
397
- $this->guest_fields( $form_settings );
398
- }
399
 
400
- $this->render_items( $form_vars, $post_id, 'post', $form_id, $form_settings );
401
- $this->submit_button( $form_id, $form_settings, $post_id );
402
 
403
- if ( !$post_id ) {
404
- do_action( 'wpuf_add_post_form_bottom', $form_id, $form_settings );
405
- } else {
406
- do_action( 'wpuf_edit_post_form_bottom', $form_id, $post_id, $form_settings );
407
- }
408
- ?>
409
 
410
  </ul>
411
 
@@ -416,53 +439,49 @@ class WPUF_Render_Form {
416
  do_action( 'wpuf_after_form_render', $form_id );
417
  }
418
 
419
- function render_item_before( $form_field, $post_id ) {
420
- $label_exclude = array('section_break', 'html', 'action_hook', 'toc', 'shortcode');
421
  $el_name = !empty( $form_field['name'] ) ? $form_field['name'] : '';
422
  $class_name = !empty( $form_field['css'] ) ? ' ' . $form_field['css'] : '';
423
  $field_size = !empty( $form_field['width'] ) ? ' field-size-' . $form_field['width'] : '';
424
 
425
- printf( '<li class="wpuf-el %s%s%s" data-label="%s">', $el_name, $class_name, $field_size, $form_field['label'] );
426
 
427
  if ( isset( $form_field['input_type'] ) && !in_array( $form_field['input_type'], $label_exclude ) ) {
428
  $this->label( $form_field, $post_id );
429
  }
430
  }
431
 
432
- function render_item_after( $form_field ) {
433
- echo '</li>';
434
  }
435
 
436
- function conditional_logic( $form_field, $form_id ) {
437
-
438
- $cond_inputs = $form_field['wpuf_cond'];
439
  $cond_inputs['condition_status'] = isset( $cond_inputs['condition_status'] ) ? $cond_inputs['condition_status'] : '';
440
 
441
- if ( $cond_inputs['condition_status'] == 'yes') {
442
  $cond_inputs['type'] = $form_field['input_type'];
443
  $cond_inputs['name'] = $form_field['name'];
444
  $cond_inputs['form_id'] = $form_id;
445
  $condition = json_encode( $cond_inputs );
446
-
447
  } else {
448
  $condition = '';
449
  }
450
 
451
  //taxnomy name create unique
452
  if ( $form_field['input_type'] == 'taxonomy' ) {
453
- $cond_inputs['name'] = $form_field['name'] . '_' . $form_field['type'] .'_'. $form_field['id'];
454
  $condition = json_encode( $cond_inputs );
455
  }
456
 
457
  //for section break
458
  if ( $form_field['input_type'] == 'section_break' ) {
459
- $cond_inputs['name'] = $form_field['name'] .'_'. $form_field['id'];
460
  $condition = json_encode( $cond_inputs );
461
- }
462
-
463
- ?>
464
  <script type="text/javascript">
465
- wpuf_conditional_items.push(<?php echo $condition; ?>);
466
  </script>
467
  <?php
468
  }
@@ -470,15 +489,13 @@ class WPUF_Render_Form {
470
  /**
471
  * Render form items
472
  *
473
- * @param array $form_vars
474
  * @param int|null $post_id
475
- * @param string $type type of the form. post or user
476
  */
477
- function render_items( $form_vars, $post_id, $type = 'post', $form_id, $form_settings, $cond_inputs = array() ) {
478
-
479
- $edit_ignore = array( 'really_simple_captcha' );
480
- $hidden_fields = array();
481
- ?>
482
  <script type="text/javascript">
483
  if ( typeof wpuf_conditional_items === 'undefined' ) {
484
  wpuf_conditional_items = [];
@@ -501,33 +518,31 @@ class WPUF_Render_Form {
501
  if ( isset( $form_settings['enable_multistep'] ) && $form_settings['enable_multistep'] == 'yes' ) {
502
  $ms_ac_txt_color = isset( $form_settings['ms_ac_txt_color'] ) ? $form_settings['ms_ac_txt_color'] : '#ffffff';
503
  $ms_active_bgcolor = isset( $form_settings['ms_active_bgcolor'] ) ? $form_settings['ms_active_bgcolor'] : '#00a0d2';
504
- $ms_bgcolor = isset( $form_settings['ms_bgcolor'] ) ? $form_settings['ms_bgcolor'] : '#E4E4E4';
505
-
506
- ?>
507
  <style type="text/css">
508
  .wpuf-form .wpuf-multistep-progressbar ul.wpuf-step-wizard li,
509
  .wpuf-form .wpuf-multistep-progressbar.ui-progressbar {
510
- background-color: <?php echo $ms_bgcolor; ?>;
511
- background: <?php echo $ms_bgcolor; ?>;
512
  }
513
  .wpuf-form .wpuf-multistep-progressbar ul.wpuf-step-wizard li::after{
514
- border-left-color: <?php echo $ms_bgcolor; ?>;
515
  }
516
  .wpuf-form .wpuf-multistep-progressbar ul.wpuf-step-wizard li.active-step,
517
  .wpuf-form .wpuf-multistep-progressbar .ui-widget-header{
518
- color: <?php echo $ms_ac_txt_color; ?>;
519
- background-color: <?php echo $ms_active_bgcolor; ?>;
520
  }
521
  .wpuf-form .wpuf-multistep-progressbar ul.wpuf-step-wizard li.active-step::after {
522
- border-left-color: <?php echo $ms_active_bgcolor; ?>;
523
  }
524
  .wpuf-form .wpuf-multistep-progressbar.ui-progressbar .wpuf-progress-percentage{
525
- color: <?php echo $ms_ac_txt_color; ?>;
526
  }
527
  </style>
528
- <input type="hidden" name="wpuf_multistep_type" value="<?php echo $form_settings['multistep_progressbar_type'] ?>"/>
529
  <?php
530
- if ( $form_settings['multistep_progressbar_type'] == 'step_by_step' ){
531
  ?>
532
  <!--wpuf-multistep-progressbar-> wpuf_ms_pb-->
533
  <div class="wpuf-multistep-progressbar">
@@ -540,19 +555,16 @@ class WPUF_Render_Form {
540
 
541
  </div>
542
  <?php
543
-
544
  }
545
-
546
  }
547
 
548
- foreach ($form_vars as $key => $form_field) {
549
 
550
  // check field visibility options
551
  if ( array_key_exists( 'wpuf_visibility', $form_field ) ) {
552
-
553
  $visibility_selected = $form_field['wpuf_visibility']['selected'];
554
  $visibility_choices = $form_field['wpuf_visibility']['choices'];
555
- $show_field = false;
556
 
557
  if ( $visibility_selected == 'everyone' ) {
558
  $show_field = true;
@@ -564,29 +576,25 @@ class WPUF_Render_Form {
564
  }
565
 
566
  if ( $visibility_selected == 'logged_in' && is_user_logged_in() ) {
567
-
568
- if ( empty($visibility_choices) ) {
569
  $show_field = true;
570
- }else{
571
  foreach ( $visibility_choices as $key => $choice ) {
572
- if( current_user_can( $choice ) ) {
573
  $show_field = true;
574
  break;
575
  }
576
  continue;
577
  }
578
  }
579
-
580
  }
581
 
582
  if ( $visibility_selected == 'subscribed_users' && is_user_logged_in() ) {
583
-
584
- $user_pack = WPUF_Subscription::init()->get_user_pack(get_current_user_id());
585
 
586
  if ( empty( $visibility_choices ) && !empty( $user_pack ) ) {
587
  $show_field = true;
588
- }elseif( !empty( $user_pack ) && !empty( $visibility_choices ) ) {
589
-
590
  foreach ( $visibility_choices as $pack => $id ) {
591
  if ( $user_pack['pack_id'] == $id ) {
592
  $show_field = true;
@@ -594,9 +602,7 @@ class WPUF_Render_Form {
594
  }
595
  continue;
596
  }
597
-
598
  }
599
-
600
  }
601
 
602
  if ( !$show_field ) {
@@ -621,7 +627,7 @@ class WPUF_Render_Form {
621
 
622
  $this->field_count++;
623
 
624
- switch ($form_field['input_type']) {
625
  case 'text':
626
  $this->text( $form_field, $post_id, $type, $form_id );
627
  $this->conditional_logic( $form_field, $form_id );
@@ -680,7 +686,7 @@ class WPUF_Render_Form {
680
  break;
681
 
682
  case 'html':
683
- $form_field['name'] = 'custom_html_'.str_replace( ' ','_', $form_field['label'] );
684
 
685
  $this->html( $form_field, $form_id );
686
  $this->conditional_logic( $form_field, $form_id );
@@ -706,23 +712,22 @@ class WPUF_Render_Form {
706
  }
707
 
708
  do_action( 'wpuf_render_form_' . $form_field['input_type'], $form_field, $form_id, $post_id, $form_settings );
709
- do_action( 'wpuf_render_pro_' . $form_field['input_type'], $form_field, $post_id, $type, $form_id, $form_settings, 'WPUF_Render_Form', $this, $this->multiform_start, isset( $form_settings['enable_multistep'] )?$form_settings['enable_multistep']:'' );
710
  break;
711
  }
712
 
713
-
714
  $this->render_item_after( $form_field );
715
  } //end foreach
716
 
717
  if ( $hidden_fields ) {
718
- foreach($hidden_fields as $field) {
719
  printf( '<input type="hidden" name="%s" value="%s">', esc_attr( $field['name'] ), esc_attr( $field['meta_value'] ) );
720
  echo "\r\n";
721
  }
722
  }
723
  }
724
 
725
- function submit_button( $form_id, $form_settings, $post_id ) {
726
  ?>
727
  <li class="wpuf-submit">
728
  <div class="wpuf-label">
@@ -730,27 +735,27 @@ class WPUF_Render_Form {
730
  </div>
731
 
732
  <?php wp_nonce_field( 'wpuf_form_add' ); ?>
733
- <input type="hidden" name="form_id" value="<?php echo $form_id; ?>">
734
- <input type="hidden" name="page_id" value="<?php echo get_post() ? get_the_ID() : '0'; ?>">
735
  <input type="hidden" id="del_attach" name="delete_attachments[]">
736
  <input type="hidden" name="action" value="wpuf_submit_post">
737
 
738
  <?php
739
  if ( $post_id ) {
740
- $cur_post = get_post( $post_id );
741
- ?>
742
- <input type="hidden" name="post_id" value="<?php echo $post_id; ?>">
743
  <input type="hidden" name="post_date" value="<?php echo esc_attr( $cur_post->post_date ); ?>">
744
  <input type="hidden" name="comment_status" value="<?php echo esc_attr( $cur_post->comment_status ); ?>">
745
  <input type="hidden" name="post_author" value="<?php echo esc_attr( $cur_post->post_author ); ?>">
746
- <input type="submit" class="wpuf-submit-button" name="submit" value="<?php echo $form_settings['update_text']; ?>" />
747
- <?php } else { ?>
748
- <input type="submit" class="wpuf-submit-button" name="submit" value="<?php echo $form_settings['submit_text']; ?>" />
 
749
  <input type="hidden" name="wpuf_form_status" value="new">
750
  <?php } ?>
751
 
752
  <?php if ( isset( $form_settings['draft_post'] ) && $form_settings['draft_post'] == 'true' ) { ?>
753
- <a href="#" class="btn" id="wpuf-post-draft"><?php _e( 'Save Draft', 'wp-user-frontend' ); ?></a>
754
  <?php } ?>
755
  </li>
756
  <?php
@@ -761,9 +766,8 @@ class WPUF_Render_Form {
761
  *
762
  * @return void
763
  */
764
- function preview_form() {
765
- $form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0;
766
-
767
 
768
  if ( $form_id ) {
769
  ?>
@@ -773,7 +777,7 @@ class WPUF_Render_Form {
773
  <head>
774
  <meta charset="UTF-8">
775
  <title>Form Preview</title>
776
- <link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/frontend-forms.css', dirname( __FILE__ ) ); ?>">
777
 
778
  <style type="text/css">
779
  body {
@@ -794,7 +798,7 @@ class WPUF_Render_Form {
794
  }
795
  </style>
796
 
797
- <script type="text/javascript" src="<?php echo includes_url( 'js/jquery/jquery.js' ); ?>"></script>
798
  </head>
799
  <body>
800
  <div class="container">
@@ -815,9 +819,10 @@ class WPUF_Render_Form {
815
  * Prints required field asterisk
816
  *
817
  * @param array $attr
 
818
  * @return string
819
  */
820
- function required_mark( $attr ) {
821
  if ( isset( $attr['required'] ) && $attr['required'] == 'yes' ) {
822
  return ' <span class="required">*</span>';
823
  }
@@ -827,9 +832,10 @@ class WPUF_Render_Form {
827
  * Prints HTML5 required attribute
828
  *
829
  * @param array $attr
 
830
  * @return string
831
  */
832
- function required_html5( $attr ) {
833
  if ( $attr['required'] == 'yes' ) {
834
  // echo ' required="required"';
835
  }
@@ -839,10 +845,12 @@ class WPUF_Render_Form {
839
  * Print required class name
840
  *
841
  * @param array $attr
 
842
  * @return string
843
  */
844
- function required_class( $attr ) {
845
  return;
 
846
  if ( $attr['required'] == 'yes' ) {
847
  echo ' required';
848
  }
@@ -853,17 +861,16 @@ class WPUF_Render_Form {
853
  *
854
  * @param array $attr
855
  */
856
- function label( $attr, $post_id = 0 ) {
857
- if ( $post_id && $attr['input_type'] == 'password') {
858
  $attr['required'] = 'no';
859
  }
860
- if ( isset( $attr['input_type'] ) && $attr['input_type'] == 'recaptcha' && $attr['recaptcha_type'] == 'invisible_recaptcha') {
861
- return;
862
- }
863
 
864
- ?>
 
 
865
  <div class="wpuf-label">
866
- <label for="<?php echo isset( $attr['name'] ) ? $attr['name'] : 'cls'; ?>"><?php echo $attr['label'] . $this->required_mark( $attr ); ?></label>
867
  </div>
868
  <?php
869
  }
@@ -873,12 +880,11 @@ class WPUF_Render_Form {
873
  *
874
  * @param array $attr
875
  */
876
- function help_text( $attr ) {
877
  if ( empty( $attr['help'] ) ) {
878
  return;
879
- }
880
- ?>
881
- <span class="wpuf-help"><?php echo stripslashes( $attr['help'] ); ?></span>
882
  <?php
883
  }
884
 
@@ -886,9 +892,10 @@ class WPUF_Render_Form {
886
  * Check if its a meta field
887
  *
888
  * @param array $attr
889
- * @return boolean
 
890
  */
891
- function is_meta( $attr ) {
892
  if ( isset( $attr['is_meta'] ) && $attr['is_meta'] == 'yes' ) {
893
  return true;
894
  }
@@ -899,13 +906,14 @@ class WPUF_Render_Form {
899
  /**
900
  * Get a meta value
901
  *
902
- * @param int $object_id user_ID or post_ID
903
  * @param string $meta_key
904
- * @param string $type post or user
905
- * @param bool $single
 
906
  * @return string
907
  */
908
- function get_meta( $object_id, $meta_key, $type = 'post', $single = true ) {
909
  if ( !$object_id ) {
910
  return '';
911
  }
@@ -917,23 +925,22 @@ class WPUF_Render_Form {
917
  return get_user_meta( $object_id, $meta_key, $single );
918
  }
919
 
920
- function get_user_data( $user_id, $field ) {
921
  return get_user_by( 'id', $user_id )->$field;
922
  }
923
 
924
  /**
925
  * Prints a text field
926
  *
927
- * @param array $attr
928
  * @param int|null $post_id
929
  */
930
- function text( $attr, $post_id, $type = 'post', $form_id = null ) {
931
  // checking for user profile username
932
  $username = false;
933
  $taxonomy = false;
934
 
935
  if ( $post_id ) {
936
-
937
  if ( $this->is_meta( $attr ) ) {
938
  $value = $this->get_meta( $post_id, $attr['name'], $type );
939
  } else {
@@ -941,18 +948,20 @@ class WPUF_Render_Form {
941
  // applicable for post tags
942
  if ( $type == 'post' && $attr['name'] == 'tags' ) {
943
  $post_tags = wp_get_post_tags( $post_id );
944
- $tagsarray = array();
945
- foreach ($post_tags as $tag) {
 
946
  $tagsarray[] = $tag->name;
947
  }
948
 
949
- $value = implode( ', ', $tagsarray );
950
  $taxonomy = true;
951
  } elseif ( $type == 'post' ) {
952
  $value = get_post_field( $attr['name'], $post_id );
953
  } elseif ( $type == 'user' ) {
954
- $name = $attr['name'];
955
  $value = get_user_by( 'id', $post_id )->$name;
 
956
  if ( $attr['name'] == 'user_login' ) {
957
  $username = true;
958
  }
@@ -964,12 +973,11 @@ class WPUF_Render_Form {
964
  if ( $type == 'post' && $attr['name'] == 'tags' ) {
965
  $taxonomy = true;
966
  }
967
- }
968
-
969
- ?>
970
 
971
  <div class="wpuf-fields">
972
- <input class="textfield<?php echo $this->required_class( $attr ); echo ' wpuf_'.$attr['name'].'_'.$form_id; ?>" id="<?php echo $attr['name'].'_'.$form_id; ?>" type="text" data-required="<?php echo $attr['required'] ?>" data-type="text"<?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="<?php echo esc_attr( $value ) ?>" size="<?php echo esc_attr( $attr['size'] ) ?>" <?php echo $username ? 'disabled' : ''; ?> />
 
973
  <span class="wpuf-wordlimit-message wpuf-help"></span>
974
  <?php $this->help_text( $attr ); ?>
975
 
@@ -990,41 +998,39 @@ class WPUF_Render_Form {
990
  }
991
  }
992
 
993
-
994
  /**
995
  * Function to check word restriction
996
  *
997
  * @param $word_nums number of words allowed
998
  */
999
- function check_word_restriction_func($word_nums, $rich_text, $field_name) {
1000
  // bail out if it is dashboard
1001
  if ( is_admin() ) {
1002
  return;
1003
- }
1004
- ?>
1005
  <script type="text/javascript">
1006
  ;(function($) {
1007
  $(document).ready( function(){
1008
- WP_User_Frontend.editorLimit.bind(<?php printf( '%d, "%s", "%s"', $word_nums, $field_name, $rich_text ); ?>);
1009
  });
1010
  })(jQuery);
1011
  </script>
1012
  <?php
1013
-
1014
  }
1015
 
1016
  /**
1017
  * Prints a textarea field
1018
- * @param array $attr
 
1019
  * @param int|null $post_id
1020
  */
1021
- function textarea( $attr, $post_id, $type, $form_id ) {
1022
  $req_class = ( $attr['required'] == 'yes' ) ? 'required' : 'rich-editor';
 
1023
  if ( $post_id ) {
1024
  if ( $this->is_meta( $attr ) ) {
1025
  $value = $this->get_meta( $post_id, $attr['name'], $type, true );
1026
  } else {
1027
-
1028
  if ( $type == 'post' ) {
1029
  $value = get_post_field( $attr['name'], $post_id );
1030
  } else {
@@ -1033,27 +1039,26 @@ class WPUF_Render_Form {
1033
  }
1034
  } else {
1035
  $value = $attr['default'];
1036
- }
1037
- ?>
1038
 
1039
- <?php if ( in_array( $attr['rich'], array( 'yes', 'teeny' ) ) ) { ?>
1040
- <div class="wpuf-fields wpuf-rich-validation <?php printf( 'wpuf_%s_%s', $attr['name'], $form_id ); ?>" data-type="rich" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-id="<?php echo esc_attr( $attr['name'] ) . '_' . $form_id; ?>" data-name="<?php echo esc_attr( $attr['name'] ); ?>">
1041
  <?php } else { ?>
1042
  <div class="wpuf-fields">
1043
  <?php } ?>
1044
 
1045
  <?php if ( isset( $attr['insert_image'] ) && $attr['insert_image'] == 'yes' ) { ?>
1046
  <div id="wpuf-insert-image-container">
1047
- <a class="wpuf-button wpuf-insert-image" id="wpuf-insert-image_<?php echo $form_id; ?>" href="#" data-form_id="<?php echo $form_id; ?>">
1048
  <span class="wpuf-media-icon"></span>
1049
- <?php _e( 'Insert Photo', 'wp-user-frontend' ); ?>
1050
  </a>
1051
  </div>
1052
 
1053
  <script type="text/javascript">
1054
  ;(function($) {
1055
  $(document).ready( function(){
1056
- WP_User_Frontend.insertImage('wpuf-insert-image_<?php echo $form_id; ?>', '<?php echo $form_id; ?>');
1057
  });
1058
  })(jQuery);
1059
  </script>
@@ -1061,47 +1066,45 @@ class WPUF_Render_Form {
1061
 
1062
  <?php
1063
  $form_settings = wpuf_get_form_settings( $form_id );
1064
- $layout = isset( $form_settings['form_layout'] ) ? $form_settings['form_layout'] : 'layout1';
1065
- $textarea_id = $attr['name'] ? $attr['name'] . '_' . $form_id : 'textarea_' . $this->field_count;
1066
- $content_css = includes_url()."js/tinymce/skins/wordpress/wp-content.css";
1067
 
1068
- if ( $attr['rich'] == 'yes' ) {
1069
- $editor_settings = array(
1070
  'textarea_rows' => $attr['rows'],
1071
  'quicktags' => false,
1072
  'media_buttons' => false,
1073
  'editor_class' => $req_class,
1074
  'textarea_name' => $attr['name'],
1075
- 'tinymce' => array(
1076
- 'content_css' => $content_css.", ". WPUF_ASSET_URI . '/css/frontend-form/' . $layout . '.css'
1077
- )
1078
- );
1079
-
1080
- $editor_settings = apply_filters( 'wpuf_textarea_editor_args' , $editor_settings );
1081
- wp_editor( $value, $textarea_id, $editor_settings );
1082
-
1083
- } elseif( $attr['rich'] == 'teeny' ) {
1084
-
1085
- $editor_settings = array(
1086
  'textarea_rows' => $attr['rows'],
1087
  'quicktags' => false,
1088
  'media_buttons' => false,
1089
  'teeny' => true,
1090
  'editor_class' => $req_class,
1091
  'textarea_name' => $attr['name'],
1092
- 'tinymce' => array(
1093
- 'content_css' => $content_css.", ". WPUF_ASSET_URI . '/css/frontend-form/' . $layout . '.css'
1094
- )
1095
- );
1096
 
1097
- $editor_settings = apply_filters( 'wpuf_textarea_editor_args' , $editor_settings );
1098
- wp_editor( $value, $textarea_id, $editor_settings );
1099
-
1100
- } else {
1101
- ?>
1102
- <textarea class="textareafield<?php echo $this->required_class( $attr ); ?> <?php echo ' wpuf_'.$attr['name'].'_'.$form_id; ?>" id="<?php echo $attr['name'] . '_' . $form_id; ?>" name="<?php echo $attr['name']; ?>" data-required="<?php echo $attr['required'] ?>" data-type="textarea"<?php $this->required_html5( $attr ); ?> placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" rows="<?php echo $attr['rows']; ?>" cols="<?php echo $attr['cols']; ?>"><?php echo esc_textarea( $value ) ?></textarea>
1103
  <span class="wpuf-wordlimit-message wpuf-help"></span>
1104
- <?php } ?>
 
1105
  <?php $this->help_text( $attr ); ?>
1106
  </div>
1107
  <?php
@@ -1111,55 +1114,51 @@ class WPUF_Render_Form {
1111
  }
1112
  }
1113
 
1114
-
1115
  /**
1116
  * Prints a select or multiselect field
1117
  *
1118
- * @param array $attr
1119
- * @param bool $multiselect
1120
  * @param int|null $post_id
1121
  */
1122
- function select( $attr, $multiselect = false, $post_id, $type, $form_id = null ) {
1123
  if ( $post_id ) {
1124
  $selected = $this->get_meta( $post_id, $attr['name'], $type );
1125
 
1126
  if ( $multiselect ) {
1127
  if ( is_serialized( $selected ) ) {
1128
- $selected = maybe_unserialize( $selected );
1129
  } elseif ( is_array( $selected ) ) {
1130
- $selected = $selected;
1131
  } else {
1132
  $selected = explode( self::$separator, $selected );
1133
  }
1134
  }
1135
  } else {
1136
  $selected = isset( $attr['selected'] ) ? $attr['selected'] : '';
1137
- $selected = $multiselect ? ( is_array( $selected ) ? $selected : array() ) : $selected;
1138
  }
1139
 
1140
  $name = $multiselect ? $attr['name'] . '[]' : $attr['name'];
1141
  $multi = $multiselect ? ' multiple="multiple"' : '';
1142
  $data_type = $multiselect ? 'multiselect' : 'select';
1143
- $css = $multiselect ? ' class="multiselect wpuf_'. $attr['name'] .'_'. $form_id.'"' : '';
1144
- ?>
1145
 
1146
  <div class="wpuf-fields">
1147
- <select <?php echo $css; ?> class="<?php echo 'wpuf_'. $attr['name'] .'_'. $form_id; ?>" name="<?php echo $name; ?>"<?php echo $multi; ?> data-required="<?php echo $attr['required'] ?>" data-type="<?php echo $data_type; ?>"<?php $this->required_html5( $attr ); ?>>
1148
 
1149
  <?php if ( !empty( $attr['first'] ) ) { ?>
1150
- <option value=""><?php echo $attr['first']; ?></option>
1151
  <?php } ?>
1152
 
1153
  <?php
1154
  if ( $attr['options'] && count( $attr['options'] ) > 0 ) {
1155
- foreach ($attr['options'] as $value => $option) {
1156
- $current_select = $multiselect ? selected( in_array( $value, $selected ), true, false ) : selected( $selected, $value, false );
1157
- ?>
1158
- <option value="<?php echo esc_attr( $value ); ?>"<?php echo $current_select; ?>><?php echo $option; ?></option>
1159
  <?php
1160
  }
1161
- }
1162
- ?>
1163
  </select>
1164
  <?php $this->help_text( $attr ); ?>
1165
  </div>
@@ -1169,31 +1168,30 @@ class WPUF_Render_Form {
1169
  /**
1170
  * Prints a radio field
1171
  *
1172
- * @param array $attr
1173
  * @param int|null $post_id
1174
  */
1175
- function radio( $attr, $post_id, $type, $form_id ) {
1176
  $selected = isset( $attr['selected'] ) ? $attr['selected'] : '';
 
1177
  if ( $post_id ) {
1178
  $selected = $this->get_meta( $post_id, $attr['name'], $type, true );
1179
- }
1180
- ?>
1181
 
1182
- <div class="wpuf-fields" data-required="<?php echo $attr['required'] ?>" data-type="radio">
1183
 
1184
  <?php
1185
  if ( $attr['options'] && count( $attr['options'] ) > 0 ) {
1186
- foreach ($attr['options'] as $value => $option) {
1187
  ?>
1188
 
1189
  <label <?php echo $attr['inline'] == 'yes' ? 'class="wpuf-radio-inline"' : 'class="wpuf-radio-block"'; ?>>
1190
- <input name="<?php echo $attr['name']; ?>" class="<?php echo 'wpuf_'.$attr['name']. '_'. $form_id; ?>" type="radio" value="<?php echo esc_attr( $value ); ?>"<?php checked( $selected, $value ); ?> />
1191
- <?php echo $option; ?>
1192
  </label>
1193
  <?php
1194
  }
1195
- }
1196
- ?>
1197
 
1198
  <?php $this->help_text( $attr ); ?>
1199
  </div>
@@ -1204,43 +1202,37 @@ class WPUF_Render_Form {
1204
  /**
1205
  * Prints a checkbox field
1206
  *
1207
- * @param array $attr
1208
  * @param int|null $post_id
1209
  */
1210
- function checkbox( $attr, $post_id, $type, $form_id ) {
1211
- $selected = isset( $attr['selected'] ) ? $attr['selected'] : array();
1212
-
1213
 
1214
  if ( $post_id ) {
1215
  if ( $value = $this->get_meta( $post_id, $attr['name'], $type, true ) ) {
1216
  if ( is_serialized( $value ) ) {
1217
- $selected = maybe_unserialize( $value );
1218
  } elseif ( is_array( $value ) ) {
1219
- $selected = $value;
1220
  } else {
1221
  $selected = explode( self::$separator, $value );
1222
  }
1223
  }
1224
- }
1225
 
1226
- ?>
1227
-
1228
- <div class="wpuf-fields" data-required="<?php echo $attr['required'] ?>" data-type="radio">
1229
 
1230
  <?php
1231
  if ( $attr['options'] && count( $attr['options'] ) > 0 ) {
1232
-
1233
- foreach ($attr['options'] as $value => $option) {
1234
-
1235
  ?>
1236
  <label <?php echo $attr['inline'] == 'yes' ? 'class="wpuf-checkbox-inline"' : 'class="wpuf-checkbox-block"'; ?>>
1237
- <input type="checkbox" class="<?php echo 'wpuf_'.$attr['name']. '_'. $form_id; ?>" name="<?php echo $attr['name']; ?>[]" value="<?php echo esc_attr( $value ); ?>"<?php echo in_array( $value, $selected ) ? ' checked="checked"' : ''; ?> />
1238
- <?php echo $option; ?>
1239
  </label>
1240
  <?php
1241
  }
1242
- }
1243
- ?>
1244
 
1245
  <?php $this->help_text( $attr ); ?>
1246
 
@@ -1252,11 +1244,10 @@ class WPUF_Render_Form {
1252
  /**
1253
  * Prints a url field
1254
  *
1255
- * @param array $attr
1256
  * @param int|null $post_id
1257
  */
1258
- function url( $attr, $post_id, $type, $form_id ) {
1259
-
1260
  if ( $post_id ) {
1261
  if ( $this->is_meta( $attr ) ) {
1262
  $value = $this->get_meta( $post_id, $attr['name'], $type, true );
@@ -1266,11 +1257,10 @@ class WPUF_Render_Form {
1266
  }
1267
  } else {
1268
  $value = $attr['default'];
1269
- }
1270
- ?>
1271
 
1272
  <div class="wpuf-fields">
1273
- <input id="wpuf-<?php echo $attr['name']; ?>" type="url" class="url <?php echo ' wpuf_'.$attr['name'].'_'.$form_id; ?>" data-required="<?php echo $attr['required'] ?>" data-type="text"<?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="<?php echo esc_attr( $value ) ?>" size="<?php echo esc_attr( $attr['size'] ) ?>" />
1274
  <?php $this->help_text( $attr ); ?>
1275
  </div>
1276
 
@@ -1280,10 +1270,10 @@ class WPUF_Render_Form {
1280
  /**
1281
  * Prints a email field
1282
  *
1283
- * @param array $attr
1284
  * @param int|null $post_id
1285
  */
1286
- function email( $attr, $post_id, $type = 'post', $form_id ) {
1287
  if ( $post_id ) {
1288
  if ( $this->is_meta( $attr ) ) {
1289
  $value = $this->get_meta( $post_id, $attr['name'], $type, true );
@@ -1293,11 +1283,10 @@ class WPUF_Render_Form {
1293
  }
1294
  } else {
1295
  $value = $attr['default'];
1296
- }
1297
- ?>
1298
 
1299
  <div class="wpuf-fields">
1300
- <input id="wpuf-<?php echo $attr['name']; ?>" type="email" class="email <?php echo ' wpuf_'.$attr['name'].'_'.$form_id; ?>" data-required="<?php echo $attr['required'] ?>" data-type="email" <?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="<?php echo esc_attr( $value ) ?>" size="<?php echo esc_attr( $attr['size'] ) ?>" />
1301
  <?php $this->help_text( $attr ); ?>
1302
  </div>
1303
 
@@ -1309,17 +1298,16 @@ class WPUF_Render_Form {
1309
  *
1310
  * @param array $attr
1311
  */
1312
- function password( $attr, $post_id, $type, $form_id ) {
1313
  if ( $post_id ) {
1314
  $attr['required'] = 'no';
1315
  }
1316
 
1317
  $repeat_pass = ( $attr['repeat_pass'] == 'yes' ) ? true : false;
1318
- $pass_strength = ( $attr['pass_strength'] == 'yes' ) ? true : false;
1319
- ?>
1320
 
1321
  <div class="wpuf-fields">
1322
- <input id="<?php echo $attr['name'].'_'.$form_id .'_1'; ?>" type="password" class="password <?php echo ' wpuf_'.$attr['name'].'_'.$form_id; ?>" data-required="<?php echo $attr['required'] ?>" data-type="password"<?php $this->required_html5( $attr ); ?> data-repeat="<?php echo $repeat_pass ? 'true' : 'false'; ?>" name="pass1" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="" size="<?php echo esc_attr( $attr['size'] ) ?>" />
1323
  <?php $this->help_text( $attr ); ?>
1324
  </div>
1325
 
@@ -1327,48 +1315,46 @@ class WPUF_Render_Form {
1327
  if ( $repeat_pass ) {
1328
  $field_size = !empty( $attr['width'] ) ? ' field-size-' . $attr['width'] : '';
1329
 
1330
- echo '</li>';
1331
- echo '<li class="wpuf-el password-repeat ' . $field_size . '" data-label="' . esc_attr( __('Confirm Password', 'wp-user-frontend') ) . '">';
1332
 
1333
- $this->label( array('name' => 'pass2', 'label' => $attr['re_pass_label'], 'required' => $post_id ? 'no' : 'yes') );
1334
- ?>
1335
 
1336
  <div class="wpuf-fields">
1337
- <input id="<?php echo $attr['name'].'_'.$form_id .'_2'; ?>" type="password" class="password <?php echo ' wpuf_'.$attr['name'].'_'.$form_id; ?>" data-required="<?php echo $attr['required'] ?>" data-type="confirm_password"<?php $this->required_html5( $attr ); ?> name="pass2" value="" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" size="<?php echo esc_attr( $attr['size'] ) ?>" />
1338
  </div>
1339
 
1340
  <?php
1341
  }
1342
 
1343
  if ( $pass_strength ) {
1344
- echo '</li>';
1345
- echo '<li>';
1346
 
1347
  wp_enqueue_script( 'zxcvbn' );
1348
- wp_enqueue_script( 'password-strength-meter' );
1349
- ?>
1350
  <div class="wpuf-label">
1351
  &nbsp;
1352
  </div>
1353
 
1354
  <div class="wpuf-fields">
1355
- <div class="pass-strength-result" id="pass-strength-result_<?php echo $form_id; ?>" style="display: block"><?php _e( 'Strength indicator', 'wp-user-frontend' ); ?></div>
1356
  </div>
1357
 
1358
  <script type="text/javascript">
1359
  jQuery(function($) {
1360
  function check_pass_strength() {
1361
- var pass1 = $("#<?php echo $attr['name'].'_'.$form_id .'_1'; ?>").val(),
1362
- pass2 = $("#<?php echo $attr['name'].'_'.$form_id .'_2'; ?>").val(),
1363
  strength;
1364
 
1365
  if ( typeof pass2 === undefined ) {
1366
  pass2 = pass1;
1367
  }
1368
 
1369
- $("#pass-strength-result_<?php echo $form_id; ?>").removeClass('short bad good strong');
1370
  if (!pass1) {
1371
- $("#pass-strength-result_<?php echo $form_id; ?>").html(pwsL10n.empty);
1372
  return;
1373
  }
1374
 
@@ -1376,47 +1362,44 @@ class WPUF_Render_Form {
1376
 
1377
  switch (strength) {
1378
  case 2:
1379
- $("#pass-strength-result_<?php echo $form_id; ?>").addClass('bad').html(pwsL10n.bad);
1380
  break;
1381
  case 3:
1382
- $("#pass-strength-result_<?php echo $form_id; ?>").addClass('good').html(pwsL10n.good);
1383
  break;
1384
  case 4:
1385
- $("#pass-strength-result_<?php echo $form_id; ?>").addClass('strong').html(pwsL10n.strong);
1386
  break;
1387
  case 5:
1388
- $("#pass-strength-result_<?php echo $form_id; ?>").addClass('short').html(pwsL10n.mismatch);
1389
  break;
1390
  default:
1391
- $("#pass-strength-result_<?php echo $form_id; ?>").addClass('short').html(pwsL10n['short']);
1392
  }
1393
  }
1394
 
1395
- $("#<?php echo $attr['name'].'_'.$form_id .'_1'; ?>").val('').keyup(check_pass_strength);
1396
- $("#<?php echo $attr['name'].'_'.$form_id .'_2'; ?>").val('').keyup(check_pass_strength);
1397
- $("#pass-strength-result_<?php echo $form_id; ?>").show();
1398
  });
1399
  </script>
1400
  <?php
1401
  }
1402
-
1403
  }
1404
 
1405
-
1406
- function taxnomy_select( $terms, $attr ) {
1407
-
1408
  $selected = $terms ? $terms : '';
1409
  $required = sprintf( 'data-required="%s" data-type="select"', $attr['required'] );
1410
  $taxonomy = $attr['name'];
1411
- $class = ' wpuf_'.$attr['name'].'_'.$selected;
1412
  $exclude_type = isset( $attr['exclude_type'] ) ? $attr['exclude_type'] : 'exclude';
1413
  $exclude = isset( $attr['exclude'] ) ? $attr['exclude'] : '';
1414
 
1415
  if ( $exclude_type == 'child_of' && !empty( $exclude ) ) {
1416
- $exclude = $exclude[0];
1417
  }
1418
 
1419
- $tax_args = array(
1420
  'show_option_none' => __( '-- Select --', 'wp-user-frontend' ),
1421
  'hierarchical' => 1,
1422
  'hide_empty' => 0,
@@ -1426,103 +1409,98 @@ class WPUF_Render_Form {
1426
  'taxonomy' => $taxonomy,
1427
  'echo' => 0,
1428
  'title_li' => '',
1429
- 'class' => 'cat-ajax '. $taxonomy . $class,
1430
  $exclude_type => $exclude,
1431
  'selected' => $selected,
1432
  'depth' => 1,
1433
- 'child_of' => isset( $attr['parent_cat'] ) ? $attr['parent_cat'] : ''
1434
- );
1435
 
1436
  $tax_args = apply_filters( 'wpuf_taxonomy_checklist_args', $tax_args );
1437
 
1438
  $select = wp_dropdown_categories( $tax_args );
1439
 
1440
- echo str_replace( '<select', '<select ' . $required, $select );
1441
- $attr = array(
1442
  'required' => $attr['required'],
1443
  'name' => $attr['name'],
1444
  'exclude_type' => $attr['exclude_type'],
1445
- 'exclude' => isset( $attr['exclude'] ) ? $attr['exclude'] : '',
1446
  'orderby' => $attr['orderby'],
1447
  'order' => $attr['order'],
1448
  'name' => $attr['name'],
1449
  //'last_term_id' => isset( $attr['parent_cat'] ) ? $attr['parent_cat'] : '',
1450
  //'term_id' => $selected
1451
- );
1452
- $attr = apply_filters( 'wpuf_taxonomy_checklist_args', $attr );
1453
- ?>
1454
- <span data-taxonomy=<?php echo json_encode( $attr ); ?>></span>
1455
  <?php
1456
  }
1457
 
1458
  /**
1459
  * Prints a taxonomy field
1460
  *
1461
- * @param array $attr
1462
  * @param int|null $post_id
1463
  */
1464
- function taxonomy( $attr, $post_id, $form_id ) {
1465
-
1466
- $exclude_type = isset( $attr['exclude_type'] ) ? $attr['exclude_type'] : 'exclude';
1467
  // $exclude = $attr['exclude'];
1468
- $exclude = isset( $attr['exclude'] ) ? $attr['exclude'] : '';
1469
-
1470
 
1471
  if ( $exclude_type == 'child_of' ) {
1472
- $exclude = $exclude[0];
1473
  }
1474
 
1475
  $taxonomy = $attr['name'];
1476
- $class = ' wpuf_'.$attr['name'].'_'.$form_id;
1477
  $current_user = get_current_user_id();
1478
 
1479
- $terms = array();
 
1480
  if ( $post_id && $attr['type'] == 'text' ) {
1481
- $terms = wp_get_post_terms( $post_id, $taxonomy, array('fields' => 'names') );
1482
- } elseif( $post_id ) {
1483
- $terms = wp_get_post_terms( $post_id, $taxonomy, array('fields' => 'ids') );
1484
  }
1485
 
1486
- if ( ! taxonomy_exists( $taxonomy ) ) {
1487
- echo '<br><div class="wpuf-message">' . __( 'This field is no longer available.', 'wp-user-frontend' ) . '</div>';
 
1488
  return;
1489
  }
1490
 
1491
- $div_class = 'wpuf_' . $attr['name'] . '_' . $attr['type'] . '_' . $attr['id'] . '_' . $form_id;
1492
- ?>
1493
 
1494
 
1495
  <?php if ( $attr['type'] == 'checkbox' ) { ?>
1496
- <div class="wpuf-fields <?php echo $div_class; ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="tax-checkbox">
1497
  <?php } else { ?>
1498
- <div class="wpuf-fields <?php echo $div_class; ?>">
1499
  <?php } ?>
1500
 
1501
  <?php
1502
- switch ($attr['type']) {
1503
  case 'ajax':
1504
- $class = ' wpuf_'.$attr['name'].'_'.$form_id;
1505
  ?>
1506
- <div class="category-wrap <?php echo $class; ?>">
1507
  <?php
1508
 
1509
  if ( !count( $terms ) ) {
1510
-
1511
  ?>
1512
  <div id="lvl0" level="0">
1513
  <?php $this->taxnomy_select( null, $attr, $form_id ); ?>
1514
  </div>
1515
  <?php
1516
  } else {
1517
-
1518
  $level = 0;
1519
  asort( $terms );
1520
  $last_term_id = end( $terms );
1521
 
1522
- foreach( $terms as $term_id) {
1523
- $class = ( $last_term_id != $term_id ) ? 'hasChild' : '';
1524
- ?>
1525
- <div id="lvl<?php echo $level; ?>" level="<?php echo $level; ?>" >
1526
  <?php $this->taxnomy_select( $term_id, $attr ); ?>
1527
  </div>
1528
  <?php
@@ -1536,11 +1514,12 @@ class WPUF_Render_Form {
1536
  <span class="loading"></span>
1537
  <?php
1538
  break;
 
1539
  case 'select':
1540
  $selected = $terms ? $terms[0] : '';
1541
  $required = sprintf( 'data-required="%s" data-type="select"', $attr['required'] );
1542
- $tax_args = array(
1543
- 'show_option_none' => isset ( $attr['first'] ) ? $attr['first'] : '--select--',
1544
  'hierarchical' => 1,
1545
  'hide_empty' => 0,
1546
  'orderby' => isset( $attr['orderby'] ) ? $attr['orderby'] : 'name',
@@ -1552,20 +1531,20 @@ class WPUF_Render_Form {
1552
  'class' => $taxonomy . $class,
1553
  $exclude_type => $exclude,
1554
  'selected' => $selected,
1555
- );
1556
 
1557
  $tax_args = apply_filters( 'wpuf_taxonomy_checklist_args', $tax_args );
1558
 
1559
  $select = wp_dropdown_categories( $tax_args );
1560
 
1561
- echo str_replace( '<select', '<select ' . $required, $select );
1562
  break;
1563
 
1564
  case 'multiselect':
1565
- $selected = $terms ? $terms : array();
1566
  $required = sprintf( 'data-required="%s" data-type="multiselect"', $attr['required'] );
1567
  $walker = new WPUF_Walker_Category_Multi();
1568
- $tax_args = array(
1569
  // 'show_option_none' => __( '-- Select --', 'wpuf' ),
1570
  'hierarchical' => 1,
1571
  'hide_empty' => 0,
@@ -1579,14 +1558,14 @@ class WPUF_Render_Form {
1579
  'class' => $taxonomy . ' multiselect' . $class,
1580
  $exclude_type => $exclude,
1581
  'selected' => $selected,
1582
- 'walker' => $walker
1583
- );
1584
 
1585
  $tax_args = apply_filters( 'wpuf_taxonomy_checklist_args', $tax_args );
1586
 
1587
  $select = wp_dropdown_categories( $tax_args );
1588
 
1589
- echo str_replace( '<select', '<select multiple="multiple" ' . $required, $select );
1590
  break;
1591
 
1592
  case 'checkbox':
@@ -1596,12 +1575,12 @@ class WPUF_Render_Form {
1596
  case 'text':
1597
  ?>
1598
 
1599
- <input class="textfield<?php echo $this->required_class( $attr ); ?>" id="<?php echo $attr['name']; ?>" type="text" data-required="<?php echo $attr['required'] ?>" data-type="text"<?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" value="<?php echo esc_attr( implode( ', ', $terms ) ); ?>" size="40" />
1600
 
1601
  <script type="text/javascript">
1602
  ;(function($) {
1603
  $(document).ready( function(){
1604
- $('#<?php echo $attr['name']; ?>').suggest( wpuf_frontend.ajaxurl + '?action=wpuf-ajax-tag-search&tax=<?php echo $attr['name']; ?>', { delay: 500, minchars: 2, multiple: true, multipleSep: ', ' } );
1605
  });
1606
  })(jQuery);
1607
  </script>
@@ -1610,10 +1589,9 @@ class WPUF_Render_Form {
1610
  break;
1611
 
1612
  default:
1613
- # code...
1614
  break;
1615
- }
1616
- ?>
1617
  <?php $this->help_text( $attr ); ?>
1618
  </div>
1619
 
@@ -1626,10 +1604,10 @@ class WPUF_Render_Form {
1626
  *
1627
  * @param array $attr
1628
  */
1629
- function html( $attr, $form_id ) {
1630
  ?>
1631
- <div class="wpuf-fields <?php echo ' wpuf_'.$attr['name'].'_'.$form_id; ?>">
1632
- <?php echo $attr['html']; ?>
1633
  </div>
1634
  <?php
1635
  }
@@ -1637,11 +1615,10 @@ class WPUF_Render_Form {
1637
  /**
1638
  * Prints a image upload field
1639
  *
1640
- * @param array $attr
1641
  * @param int|null $post_id
1642
  */
1643
- function image_upload( $attr, $post_id, $type, $form_id ) {
1644
-
1645
  $has_featured_image = false;
1646
  $has_images = false;
1647
  $has_avatar = false;
@@ -1652,7 +1629,7 @@ class WPUF_Render_Form {
1652
  $images = $this->get_meta( $post_id, $attr['name'], $type, false );
1653
 
1654
  if ( $images ) {
1655
- if( is_serialized( $images[0] ) ) {
1656
  $images = maybe_unserialize( $images[0] );
1657
  }
1658
 
@@ -1663,51 +1640,49 @@ class WPUF_Render_Form {
1663
 
1664
  $has_images = true;
1665
  } else {
1666
-
1667
  if ( $type == 'post' ) {
1668
  // it's a featured image then
1669
  $thumb_id = get_post_thumbnail_id( $post_id );
1670
 
1671
  if ( $thumb_id ) {
1672
  $has_featured_image = true;
1673
- $featured_image = WPUF_Upload::attach_html( $thumb_id, 'featured_image' );
1674
  }
1675
  } else {
1676
  // it must be a user avatar
1677
- $has_avatar = true;
1678
  $featured_image = get_avatar( $post_id );
1679
  }
1680
  }
1681
  }
1682
- $button_label = empty( $attr['button_label'] ) ? __( 'Select Image', 'wp-user-frontend' ) : $attr['button_label'];
1683
- ?>
1684
 
1685
  <div class="wpuf-fields">
1686
- <div id="wpuf-<?php echo $unique_id; ?>-upload-container">
1687
- <div class="wpuf-attachment-upload-filelist" data-type="file" data-required="<?php echo $attr['required']; ?>">
1688
- <a id="wpuf-<?php echo $unique_id; ?>-pickfiles" data-form_id="<?php echo $form_id; ?>" class="button file-selector <?php echo ' wpuf_' . $attr['name'] . '_' . $form_id; ?>" href="#"><?php echo $button_label ?></a>
1689
 
1690
  <ul class="wpuf-attachment-list thumbnails">
1691
  <?php
1692
  if ( $has_featured_image ) {
1693
- echo $featured_image;
1694
  }
1695
 
1696
- if ( $has_avatar ) {
1697
- $avatar = get_user_meta( $post_id, 'user_avatar', true );
1698
- if ( $avatar ) {
1699
- echo '<li>'.$featured_image;
1700
- printf( '<br><a href="#" data-confirm="%s" class="btn btn-danger btn-small wpuf-button button wpuf-delete-avatar">%s</a>', __( 'Are you sure?', 'wp-user-frontend' ), __( 'Delete', 'wp-user-frontend' ) );
1701
- echo '</li>';
1702
- }
1703
- }
1704
 
1705
- if ( $has_images ) {
1706
- foreach ($images as $attach_id) {
1707
- echo WPUF_Upload::attach_html( $attach_id, $attr['name'] );
1708
- }
1709
- }
1710
- ?>
 
 
 
 
 
 
1711
  </ul>
1712
  </div>
1713
  </div><!-- .container -->
@@ -1719,26 +1694,25 @@ class WPUF_Render_Form {
1719
  <script type="text/javascript">
1720
  ;(function($) {
1721
  $(document).ready( function(){
1722
- var uploader = new WPUF_Uploader('wpuf-<?php echo $unique_id; ?>-pickfiles', 'wpuf-<?php echo $unique_id; ?>-upload-container', <?php echo $attr['count']; ?>, '<?php echo $attr['name']; ?>', 'jpg,jpeg,gif,png,bmp', <?php echo $attr['max_size'] ?>);
1723
  wpuf_plupload_items.push(uploader);
1724
  });
1725
  })(jQuery);
1726
  </script>
1727
  <?php
1728
-
1729
  }
1730
 
1731
  /**
1732
  * Prints a section break
1733
  *
1734
- * @param array $attr
1735
  * @param int|null $post_id
1736
  */
1737
- function section_break( $attr, $post_id, $form_id ) {
1738
  ?>
1739
- <div class="wpuf-section-wrap <?php echo ' wpuf_'.$attr['name'].'_'.$attr['id'].'_'.$form_id; ?>">
1740
- <h2 class="wpuf-section-title"><?php echo $attr['label']; ?></h2>
1741
- <div class="wpuf-section-details"><?php echo $attr['description']; ?></div>
1742
  </div>
1743
  <?php
1744
  }
@@ -1749,21 +1723,21 @@ class WPUF_Render_Form {
1749
  * @param array $attr
1750
  */
1751
  public static function recaptcha( $attr, $post_id, $form_id ) {
1752
-
1753
  if ( $post_id ) {
1754
  return;
1755
  }
1756
  $enable_no_captcha = $enable_invisible_recaptcha = '';
1757
- if ( isset ( $attr['recaptcha_type'] ) ) {
 
1758
  $enable_invisible_recaptcha = $attr['recaptcha_type'] == 'invisible_recaptcha' ? true : false;
1759
- $enable_no_captcha = $attr['recaptcha_type'] == 'enable_no_captcha' ? true : false;
1760
  }
1761
 
1762
  if ( $enable_invisible_recaptcha ) { ?>
1763
  <script src="https://www.google.com/recaptcha/api.js?onload=wpufreCaptchaLoaded&render=explicit&hl=en" async defer></script>
1764
  <script>
1765
  jQuery(document).ready(function($) {
1766
- jQuery('[name="submit"]').removeClass('wpuf-submit-button').addClass('g-recaptcha').attr('data-sitekey', '<?php echo wpuf_get_option( 'recaptcha_public', 'wpuf_general' ); ?>');
1767
 
1768
  $(document).on('click','.g-recaptcha', function(e){
1769
  e.preventDefault();
@@ -1785,13 +1759,12 @@ class WPUF_Render_Form {
1785
  jQuery('[name="submit"]').removeClass('g-recaptcha').addClass('wpuf-submit-button');
1786
  }
1787
  </script>
1788
- <!-- <input type="submit" class="g-recaptcha" data-sitekey=<?php echo wpuf_get_option( 'recaptcha_public', 'wpuf_general' ); ?> data-callback="onSubmit"> -->
1789
- <div type="submit" id='recaptcha' class="g-recaptcha" data-sitekey=<?php echo wpuf_get_option( 'recaptcha_public', 'wpuf_general' ); ?> data-callback="onSubmit" data-size="invisible"></div>
1790
  <?php } else { ?>
1791
- <div class="wpuf-fields <?php echo ' wpuf_'.$attr['name'].'_'.$form_id; ?>">
1792
- <?php echo recaptcha_get_html( wpuf_get_option( 'recaptcha_public', 'wpuf_general' ), $enable_no_captcha, null, is_ssl() ); ?>
1793
  </div>
1794
  <?php }
1795
  }
1796
-
1797
  }
2
 
3
  /**
4
  * Handles form generaton and posting for add/edit post in frontend
 
 
5
  */
6
  class WPUF_Render_Form {
7
+ public static $meta_key = 'wpuf_form';
8
+
9
+ public static $separator = ' | ';
10
+
11
+ public static $config_id = '_wpuf_form_id';
12
 
 
 
 
13
  private $form_condition_key = 'wpuf_cond';
14
+
15
  private static $_instance;
16
+
17
  private $field_count = 0;
18
+
19
  public $multiform_start = 0;
20
 
21
  public static function init() {
31
  *
32
  * @param string $error
33
  */
34
+ public function send_error( $error ) {
35
+ echo json_encode( [
36
  'success' => false,
37
+ 'error' => $error,
38
+ ] );
39
 
40
  die();
41
  }
43
  /**
44
  * Search on multi dimentional array
45
  *
46
+ * @param array $array
47
+ * @param string $key name of key
48
  * @param string $value the value to search
49
+ *
50
  * @return array
51
  */
52
+ public function search( $array, $key, $value ) {
53
+ $results = [];
54
 
55
  if ( is_array( $array ) ) {
56
+ if ( isset( $array[$key] ) && $array[$key] == $value ) {
57
  $results[] = $array;
58
+ }
59
 
60
+ foreach ( $array as $subarray ) {
61
  $results = array_merge( $results, $this->search( $subarray, $key, $value ) );
62
+ }
63
  }
64
 
65
  return $results;
70
  *
71
  * @return void
72
  */
73
+ public function validate_rs_captcha() {
74
+ $nonce = isset( $_REQUEST['wpuf-login-nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['wpuf-login-nonce'] ) ) : '';
75
+
76
+ if ( isset( $nonce) && ! wp_verify_nonce( $nonce, 'wpuf_login_action' ) ) {
77
+ return ;
78
+ }
79
+
80
+ $rs_captcha_input = isset( $_POST['rs_captcha'] ) ? sanitize_text_field( wp_unslash( $_POST['rs_captcha'] ) ) : '';
81
+ $rs_captcha_file = isset( $_POST['rs_captcha_val'] ) ? sanitize_text_field( wp_unslash( $_POST['rs_captcha_val'] ) ) : '';
82
 
83
  if ( class_exists( 'ReallySimpleCaptcha' ) ) {
84
  $captcha_instance = new ReallySimpleCaptcha();
85
 
86
  if ( !$captcha_instance->check( $rs_captcha_file, $rs_captcha_input ) ) {
 
87
  $this->send_error( __( 'Really Simple Captcha validation failed', 'wp-user-frontend' ) );
88
  } else {
89
  // validation success, remove the files
97
  *
98
  * @return void
99
  */
100
+ public function validate_re_captcha( $no_captcha = '', $invisible = '' ) {
101
+ $nonce = isset( $_REQUEST['wpuf-login-nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['wpuf-login-nonce'] ) ) : '';
102
+
103
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'wpuf_login_action' ) ) {
104
+ return ;
105
+ }
106
  // need to check if invisible reCaptcha need library or we can do it here.
107
  // ref: https://shareurcodes.com/blog/google%20invisible%20recaptcha%20integration%20with%20php
108
+ $site_key = wpuf_get_option( 'recaptcha_public', 'wpuf_general' );
109
+ $private_key = wpuf_get_option( 'recaptcha_private', 'wpuf_general' );
110
+ $rremote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
111
+ $g_recaptcha_response = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : '';
112
 
113
+ if ( $no_captcha == 1 && 0 == $invisible ) {
114
  if ( !class_exists( 'WPUF_ReCaptcha' ) ) {
115
  require_once WPUF_ROOT . '/lib/recaptchalib_noCaptcha.php';
116
  }
117
 
118
+ $response = null;
119
+ $reCaptcha = new WPUF_ReCaptcha( $private_key );
120
 
121
  $resp = $reCaptcha->verifyResponse(
122
+ $rremote_addr,
123
+ $g_recaptcha_response
124
+ );
125
 
126
  if ( !$resp->success ) {
127
  $this->send_error( __( 'noCaptcha reCAPTCHA validation failed', 'wp-user-frontend' ) );
128
  }
 
129
  } elseif ( $no_captcha == 0 && 0 == $invisible ) {
130
+ $recap_challenge = isset( $_POST['recaptcha_challenge_field'] ) ? sanitize_text_field( wp_unslash( $_POST['recaptcha_challenge_field'] ) ) : '';
131
+ $recap_response = isset( $_POST['recaptcha_response_field'] ) ? sanitize_text_field( wp_unslash( $_POST['recaptcha_response_field'] ) ) : '';
132
 
133
+ $resp = recaptcha_check_answer( $private_key, $rremote_addr, $recap_challenge, $recap_response );
 
 
 
134
 
135
  if ( !$resp->is_valid ) {
136
  $this->send_error( __( 'reCAPTCHA validation failed', 'wp-user-frontend' ) );
137
  }
 
138
  } elseif ( $no_captcha == 0 && 1 == $invisible ) {
 
139
  $response = null;
140
+ $recaptcha = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : '';
141
+ $object = new Invisible_Recaptcha( $site_key, $private_key );
142
 
143
  $response = $object->verifyResponse( $recaptcha );
144
 
145
+ if ( isset( $response['success'] ) and $response['success'] != true ) {
146
  $this->send_error( __( 'Invisible reCAPTCHA validation failed', 'wp-user-frontend' ) );
147
  }
148
  }
 
149
  }
150
 
151
  /**
152
  * Guess a suitable username for registration based on email address
153
+ *
154
  * @param string $email email address
155
+ *
156
  * @return string username
157
  */
158
+ public function guess_username( $email ) {
159
  // username from email address
160
  $username = sanitize_user( substr( $email, 0, strpos( $email, '@' ) ) );
161
 
166
  // try to add some random number in username
167
  // and may be we got our username
168
  $username .= rand( 1, 199 );
169
+
170
  if ( !username_exists( $username ) ) {
171
  return $username;
172
  }
176
  * Get input meta fields separated as post vars, taxonomy and meta vars
177
  *
178
  * @param int $form_id form id
179
+ *
180
  * @return array
181
  */
182
  public static function get_input_fields( $form_id ) {
183
  $form_vars = wpuf_get_form_fields( $form_id );
184
 
185
+ $ignore_lists = ['section_break', 'html'];
186
+ $post_vars = $meta_vars = $taxonomy_vars = [];
187
 
188
+ foreach ( $form_vars as $key => $value ) {
189
 
190
  // ignore section break and HTML input type
191
  if ( in_array( $value['input_type'], $ignore_lists ) ) {
211
  }
212
  }
213
 
214
+ return [$post_vars, $taxonomy_vars, $meta_vars];
215
  }
216
 
217
  public static function prepare_meta_fields( $meta_vars ) {
219
  // skip files, put in a key => value paired array for later executation
220
  // process repeatable fields separately
221
  // if the input is array type, implode with separator in a field
222
+ check_ajax_referer( 'wpuf_form_add' );
223
 
224
+ $files = [];
225
+ $meta_key_value = [];
226
+ $multi_repeated = []; //multi repeated fields will in sotre duplicated meta key
 
 
227
 
228
+ foreach ( $meta_vars as $key => $value ) {
229
+ $value_name = isset( $_POST[$value['name']] ) ? sanitize_text_field( wp_unslash( $_POST[$value['name']] ) ) : '';
230
+ if ( isset( $_POST['wpuf_files'][$value['name']] ) ) {
231
+ $wpuf_files = isset( $_POST['wpuf_files'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_files'][$value['name']] ) ) : [];
232
+ } else {
233
+ $wpuf_files = [];
234
+ }
235
  switch ( $value['input_type'] ) {
236
 
237
  // put files in a separate array, we'll process it later
238
  case 'file_upload':
239
  case 'image_upload':
240
 
241
+ $files[] = [
242
  'name' => $value['name'],
243
+ // 'value' => isset( $wpuf_files[$value['name']] ) ? $wpuf_files[$value['name']] : [],
244
+ 'value' => isset( $wpuf_files ) ? $wpuf_files : [],
245
+ 'count' => $value['count'],
246
+ ];
247
  break;
248
 
249
  case 'repeat':
252
  if ( isset( $value['multiple'] ) && $value['multiple'] == 'true' ) {
253
 
254
  // if there's any items in the array, process it
255
+ if ( $value_name ) {
256
+ $ref_arr = [];
 
257
  $cols = count( $value['columns'] );
258
+ $first = array_shift( array_values( $value_name ) ); //first element
259
  $rows = count( $first );
260
 
261
  // loop through columns
262
+ for ( $i = 0; $i < $rows; $i++ ) {
263
 
264
  // loop through the rows and store in a temp array
265
+ $temp = [];
 
266
 
267
+ for ( $j = 0; $j < $cols; $j++ ) {
268
+ $temp[] = $value_name[$j][$i];
269
  }
270
 
271
  // store all fields in a row with self::$separator separated
278
  }
279
  }
280
  } else {
281
+ $meta_key_value[$value['name']] = implode( self::$separator, $value_name );
282
  }
283
 
284
  break;
285
 
286
  case 'address':
287
 
288
+ if ( is_array( $value_name ) ) {
289
+ foreach ( $value_name as $address_field => $field_value ) {
290
  $meta_key_value[ $value['name'] ][ $address_field ] = sanitize_text_field( $field_value );
291
  }
292
  }
298
  case 'number':
299
  case 'date':
300
 
301
+ $meta_key_value[$value['name']] = sanitize_text_field( trim( $value_name ) );
302
 
303
  break;
304
 
305
  case 'textarea':
306
 
307
+ $meta_key_value[$value['name']] = wp_kses_post( $value_name );
308
 
309
  break;
310
 
311
  case 'map':
312
+ $data = [];
313
+ $map_field_data = sanitize_text_field( trim( $value_name ) );
314
 
315
  if ( !empty( $map_field_data ) ) {
316
+ list( $data['address'], $data['lat'], $data['lng'] ) = explode( ' || ', $map_field_data );
317
+ $meta_key_value[$value['name']] = $data;
318
  }
319
  break;
320
 
321
  default:
322
  // if it's an array, implode with this->separator
323
+ if ( is_array( $value_name ) ) {
324
  $acf_compatibility = wpuf_get_option( 'wpuf_compatibility_acf', 'wpuf_general', 'no' );
325
 
326
  if ( $value['input_type'] == 'address' ) {
327
+ $meta_key_value[$value['name']] = $value_name;
328
  } elseif ( !empty( $acf_compatibility ) && $acf_compatibility == 'yes' ) {
329
+ $meta_key_value[$value['name']] = maybe_serialize( $value_name );
330
  } else {
331
+ $meta_key_value[$value['name']] = implode( self::$separator, $value_name );
332
  }
333
  } else {
334
+ $meta_key_value[$value['name']] = trim( $value_name );
335
  }
336
 
337
  break;
338
  }
 
339
  } //end foreach
340
 
341
+ return [$meta_key_value, $multi_repeated, $files];
342
  }
343
 
344
+ public function guest_fields( $form_settings ) {
345
  ?>
346
  <li class="el-name">
347
  <div class="wpuf-label">
348
+ <label><?php echo esc_attr( $form_settings['name_label'] ); ?> <span class="required">*</span></label>
349
  </div>
350
 
351
  <div class="wpuf-fields">
355
 
356
  <li class="el-email">
357
  <div class="wpuf-label">
358
+ <label><?php echo esc_attr( $form_settings['email_label'] ); ?> <span class="required">*</span></label>
359
  </div>
360
 
361
  <div class="wpuf-fields">
371
  * @param int $form_id
372
  * @param int $post_id
373
  */
374
+ public function render_form( $form_id, $post_id = null ) {
 
375
  $form_status = get_post_status( $form_id );
376
 
377
+ if ( !$form_status ) {
378
+ echo wp_kses_post( '<div class="wpuf-message">' . __( 'Your selected form is no longer available.', 'wp-user-frontend' ) . '</div>' );
379
+
380
  return;
381
  }
382
 
383
  if ( $form_status != 'publish' ) {
384
+ echo wp_kses_post( '<div class="wpuf-message">' . __( "Please make sure you've published your form.", 'wp-user-frontend' ) . '</div>' );
385
+
386
  return;
387
  }
388
 
398
  wp_enqueue_style( 'wpuf-' . $layout );
399
  }
400
 
401
+ if ( !is_user_logged_in() && $form_settings['guest_post'] != 'true' ) {
402
+ echo wp_kses_post( '<div class="wpuf-message">' . $form_settings['message_restrict'] . '</div>' );
403
+
404
  return;
405
  }
406
 
407
  if ( $form_vars ) {
408
  ?>
409
+ <form class="wpuf-form-add wpuf-form-<?php echo esc_attr( $layout ); ?> <?php echo ( $layout == 'layout1' ) ? esc_attr( $theme_css ) : 'wpuf-style'; ?>" action="" method="post">
410
 
411
+ <ul class="wpuf-form form-label-<?php echo esc_attr( $label_position ); ?>">
412
 
413
  <?php
414
  if ( !$post_id ) {
417
  do_action( 'wpuf_edit_post_form_top', $form_id, $post_id, $form_settings );
418
  }
419
 
420
+ if ( !is_user_logged_in() && $form_settings['guest_post'] == 'true' && $form_settings['guest_details'] == 'true' ) {
421
+ $this->guest_fields( $form_settings );
422
+ }
423
 
424
+ $this->render_items( $form_vars, $post_id, 'post', $form_id, $form_settings );
425
+ $this->submit_button( $form_id, $form_settings, $post_id );
426
 
427
+ if ( !$post_id ) {
428
+ do_action( 'wpuf_add_post_form_bottom', $form_id, $form_settings );
429
+ } else {
430
+ do_action( 'wpuf_edit_post_form_bottom', $form_id, $post_id, $form_settings );
431
+ } ?>
 
432
 
433
  </ul>
434
 
439
  do_action( 'wpuf_after_form_render', $form_id );
440
  }
441
 
442
+ public function render_item_before( $form_field, $post_id ) {
443
+ $label_exclude = ['section_break', 'html', 'action_hook', 'toc', 'shortcode'];
444
  $el_name = !empty( $form_field['name'] ) ? $form_field['name'] : '';
445
  $class_name = !empty( $form_field['css'] ) ? ' ' . $form_field['css'] : '';
446
  $field_size = !empty( $form_field['width'] ) ? ' field-size-' . $form_field['width'] : '';
447
 
448
+ printf( '<li class="wpuf-el %s%s%s" data-label="%s">', esc_attr( $el_name ), esc_attr( $class_name ), esc_attr( $field_size ),esc_attr( $form_field['label'] ) );
449
 
450
  if ( isset( $form_field['input_type'] ) && !in_array( $form_field['input_type'], $label_exclude ) ) {
451
  $this->label( $form_field, $post_id );
452
  }
453
  }
454
 
455
+ public function render_item_after( $form_field ) {
456
+ echo wp_kses_post( '</li>' );
457
  }
458
 
459
+ public function conditional_logic( $form_field, $form_id ) {
460
+ $cond_inputs = $form_field['wpuf_cond'];
 
461
  $cond_inputs['condition_status'] = isset( $cond_inputs['condition_status'] ) ? $cond_inputs['condition_status'] : '';
462
 
463
+ if ( $cond_inputs['condition_status'] == 'yes' ) {
464
  $cond_inputs['type'] = $form_field['input_type'];
465
  $cond_inputs['name'] = $form_field['name'];
466
  $cond_inputs['form_id'] = $form_id;
467
  $condition = json_encode( $cond_inputs );
 
468
  } else {
469
  $condition = '';
470
  }
471
 
472
  //taxnomy name create unique
473
  if ( $form_field['input_type'] == 'taxonomy' ) {
474
+ $cond_inputs['name'] = $form_field['name'] . '_' . $form_field['type'] . '_' . $form_field['id'];
475
  $condition = json_encode( $cond_inputs );
476
  }
477
 
478
  //for section break
479
  if ( $form_field['input_type'] == 'section_break' ) {
480
+ $cond_inputs['name'] = $form_field['name'] . '_' . $form_field['id'];
481
  $condition = json_encode( $cond_inputs );
482
+ } ?>
 
 
483
  <script type="text/javascript">
484
+ wpuf_conditional_items.push(<?php echo esc_html( $condition ); ?>);
485
  </script>
486
  <?php
487
  }
489
  /**
490
  * Render form items
491
  *
492
+ * @param array $form_vars
493
  * @param int|null $post_id
494
+ * @param string $type type of the form. post or user
495
  */
496
+ public function render_items( $form_vars, $post_id, $type = 'post', $form_id, $form_settings, $cond_inputs = [] ) {
497
+ $edit_ignore = [ 'really_simple_captcha' ];
498
+ $hidden_fields = []; ?>
 
 
499
  <script type="text/javascript">
500
  if ( typeof wpuf_conditional_items === 'undefined' ) {
501
  wpuf_conditional_items = [];
518
  if ( isset( $form_settings['enable_multistep'] ) && $form_settings['enable_multistep'] == 'yes' ) {
519
  $ms_ac_txt_color = isset( $form_settings['ms_ac_txt_color'] ) ? $form_settings['ms_ac_txt_color'] : '#ffffff';
520
  $ms_active_bgcolor = isset( $form_settings['ms_active_bgcolor'] ) ? $form_settings['ms_active_bgcolor'] : '#00a0d2';
521
+ $ms_bgcolor = isset( $form_settings['ms_bgcolor'] ) ? $form_settings['ms_bgcolor'] : '#E4E4E4'; ?>
 
 
522
  <style type="text/css">
523
  .wpuf-form .wpuf-multistep-progressbar ul.wpuf-step-wizard li,
524
  .wpuf-form .wpuf-multistep-progressbar.ui-progressbar {
525
+ background-color: <?php echo esc_html( $ms_bgcolor ); ?>;
526
+ background: <?php echo esc_html( $ms_bgcolor ); ?>;
527
  }
528
  .wpuf-form .wpuf-multistep-progressbar ul.wpuf-step-wizard li::after{
529
+ border-left-color: <?php echo esc_html( $ms_bgcolor ); ?>;
530
  }
531
  .wpuf-form .wpuf-multistep-progressbar ul.wpuf-step-wizard li.active-step,
532
  .wpuf-form .wpuf-multistep-progressbar .ui-widget-header{
533
+ color: <?php echo esc_html( $ms_ac_txt_color ); ?>;
534
+ background-color: <?php echo esc_html( $ms_active_bgcolor ); ?>;
535
  }
536
  .wpuf-form .wpuf-multistep-progressbar ul.wpuf-step-wizard li.active-step::after {
537
+ border-left-color: <?php echo esc_html( $ms_active_bgcolor ); ?>;
538
  }
539
  .wpuf-form .wpuf-multistep-progressbar.ui-progressbar .wpuf-progress-percentage{
540
+ color: <?php echo esc_html( $ms_ac_txt_color ); ?>;
541
  }
542
  </style>
543
+ <input type="hidden" name="wpuf_multistep_type" value="<?php echo esc_attr( $form_settings['multistep_progressbar_type'] ); ?>"/>
544
  <?php
545
+ if ( $form_settings['multistep_progressbar_type'] == 'step_by_step' ) {
546
  ?>
547
  <!--wpuf-multistep-progressbar-> wpuf_ms_pb-->
548
  <div class="wpuf-multistep-progressbar">
555
 
556
  </div>
557
  <?php
 
558
  }
 
559
  }
560
 
561
+ foreach ( $form_vars as $key => $form_field ) {
562
 
563
  // check field visibility options
564
  if ( array_key_exists( 'wpuf_visibility', $form_field ) ) {
 
565
  $visibility_selected = $form_field['wpuf_visibility']['selected'];
566
  $visibility_choices = $form_field['wpuf_visibility']['choices'];
567
+ $show_field = false;
568
 
569
  if ( $visibility_selected == 'everyone' ) {
570
  $show_field = true;
576
  }
577
 
578
  if ( $visibility_selected == 'logged_in' && is_user_logged_in() ) {
579
+ if ( empty( $visibility_choices ) ) {
 
580
  $show_field = true;
581
+ } else {
582
  foreach ( $visibility_choices as $key => $choice ) {
583
+ if ( current_user_can( $choice ) ) {
584
  $show_field = true;
585
  break;
586
  }
587
  continue;
588
  }
589
  }
 
590
  }
591
 
592
  if ( $visibility_selected == 'subscribed_users' && is_user_logged_in() ) {
593
+ $user_pack = WPUF_Subscription::init()->get_user_pack( get_current_user_id() );
 
594
 
595
  if ( empty( $visibility_choices ) && !empty( $user_pack ) ) {
596
  $show_field = true;
597
+ } elseif ( !empty( $user_pack ) && !empty( $visibility_choices ) ) {
 
598
  foreach ( $visibility_choices as $pack => $id ) {
599
  if ( $user_pack['pack_id'] == $id ) {
600
  $show_field = true;
602
  }
603
  continue;
604
  }
 
605
  }
 
606
  }
607
 
608
  if ( !$show_field ) {
627
 
628
  $this->field_count++;
629
 
630
+ switch ( $form_field['input_type'] ) {
631
  case 'text':
632
  $this->text( $form_field, $post_id, $type, $form_id );
633
  $this->conditional_logic( $form_field, $form_id );
686
  break;
687
 
688
  case 'html':
689
+ $form_field['name'] = 'custom_html_' . str_replace( ' ', '_', $form_field['label'] );
690
 
691
  $this->html( $form_field, $form_id );
692
  $this->conditional_logic( $form_field, $form_id );
712
  }
713
 
714
  do_action( 'wpuf_render_form_' . $form_field['input_type'], $form_field, $form_id, $post_id, $form_settings );
715
+ do_action( 'wpuf_render_pro_' . $form_field['input_type'], $form_field, $post_id, $type, $form_id, $form_settings, 'WPUF_Render_Form', $this, $this->multiform_start, isset( $form_settings['enable_multistep'] ) ? $form_settings['enable_multistep'] : '' );
716
  break;
717
  }
718
 
 
719
  $this->render_item_after( $form_field );
720
  } //end foreach
721
 
722
  if ( $hidden_fields ) {
723
+ foreach ( $hidden_fields as $field ) {
724
  printf( '<input type="hidden" name="%s" value="%s">', esc_attr( $field['name'] ), esc_attr( $field['meta_value'] ) );
725
  echo "\r\n";
726
  }
727
  }
728
  }
729
 
730
+ public function submit_button( $form_id, $form_settings, $post_id ) {
731
  ?>
732
  <li class="wpuf-submit">
733
  <div class="wpuf-label">
735
  </div>
736
 
737
  <?php wp_nonce_field( 'wpuf_form_add' ); ?>
738
+ <input type="hidden" name="form_id" value="<?php echo esc_attr( $form_id ); ?>">
739
+ <input type="hidden" name="page_id" value="<?php echo get_post() ? esc_attr( get_the_ID() ) : '0'; ?>">
740
  <input type="hidden" id="del_attach" name="delete_attachments[]">
741
  <input type="hidden" name="action" value="wpuf_submit_post">
742
 
743
  <?php
744
  if ( $post_id ) {
745
+ $cur_post = get_post( $post_id ); ?>
746
+ <input type="hidden" name="post_id" value="<?php echo esc_attr( $post_id ); ?>">
 
747
  <input type="hidden" name="post_date" value="<?php echo esc_attr( $cur_post->post_date ); ?>">
748
  <input type="hidden" name="comment_status" value="<?php echo esc_attr( $cur_post->comment_status ); ?>">
749
  <input type="hidden" name="post_author" value="<?php echo esc_attr( $cur_post->post_author ); ?>">
750
+ <input type="submit" class="wpuf-submit-button" name="submit" value="<?php echo esc_attr( $form_settings['update_text'] ); ?>" />
751
+ <?php
752
+ } else { ?>
753
+ <input type="submit" class="wpuf-submit-button" name="submit" value="<?php echo esc_attr( $form_settings['submit_text'] ); ?>" />
754
  <input type="hidden" name="wpuf_form_status" value="new">
755
  <?php } ?>
756
 
757
  <?php if ( isset( $form_settings['draft_post'] ) && $form_settings['draft_post'] == 'true' ) { ?>
758
+ <a href="#" class="btn" id="wpuf-post-draft"><?php esc_html_e( 'Save Draft', 'wp-user-frontend' ); ?></a>
759
  <?php } ?>
760
  </li>
761
  <?php
766
  *
767
  * @return void
768
  */
769
+ public function preview_form() {
770
+ $form_id = isset( $_GET['form_id'] ) ? intval( wp_unslash( $_GET['form_id'] ) ) : 0;
 
771
 
772
  if ( $form_id ) {
773
  ?>
777
  <head>
778
  <meta charset="UTF-8">
779
  <title>Form Preview</title>
780
+ <link rel="stylesheet" href="<?php echo esc_url( plugins_url( 'assets/css/frontend-forms.css', __DIR__ ) ); ?>">
781
 
782
  <style type="text/css">
783
  body {
798
  }
799
  </style>
800
 
801
+ <script type="text/javascript" src="<?php echo esc_url( includes_url( 'js/jquery/jquery.js' ) ); ?>"></script>
802
  </head>
803
  <body>
804
  <div class="container">
819
  * Prints required field asterisk
820
  *
821
  * @param array $attr
822
+ *
823
  * @return string
824
  */
825
+ public function required_mark( $attr ) {
826
  if ( isset( $attr['required'] ) && $attr['required'] == 'yes' ) {
827
  return ' <span class="required">*</span>';
828
  }
832
  * Prints HTML5 required attribute
833
  *
834
  * @param array $attr
835
+ *
836
  * @return string
837
  */
838
+ public function required_html5( $attr ) {
839
  if ( $attr['required'] == 'yes' ) {
840
  // echo ' required="required"';
841
  }
845
  * Print required class name
846
  *
847
  * @param array $attr
848
+ *
849
  * @return string
850
  */
851
+ public function required_class( $attr ) {
852
  return;
853
+
854
  if ( $attr['required'] == 'yes' ) {
855
  echo ' required';
856
  }
861
  *
862
  * @param array $attr
863
  */
864
+ public function label( $attr, $post_id = 0 ) {
865
+ if ( $post_id && $attr['input_type'] == 'password' ) {
866
  $attr['required'] = 'no';
867
  }
 
 
 
868
 
869
+ if ( isset( $attr['input_type'] ) && $attr['input_type'] == 'recaptcha' && $attr['recaptcha_type'] == 'invisible_recaptcha' ) {
870
+ return;
871
+ } ?>
872
  <div class="wpuf-label">
873
+ <label for="<?php echo isset( $attr['name'] ) ? esc_attr( $attr['name'] ) : 'cls'; ?>"><?php echo esc_attr( $attr['label'] ) . esc_attr( $this->required_mark( $attr ) ); ?></label>
874
  </div>
875
  <?php
876
  }
880
  *
881
  * @param array $attr
882
  */
883
+ public function help_text( $attr ) {
884
  if ( empty( $attr['help'] ) ) {
885
  return;
886
+ } ?>
887
+ <span class="wpuf-help"><?php echo esc_html( stripslashes( $attr['help'] ) ); ?></span>
 
888
  <?php
889
  }
890
 
892
  * Check if its a meta field
893
  *
894
  * @param array $attr
895
+ *
896
+ * @return bool
897
  */
898
+ public function is_meta( $attr ) {
899
  if ( isset( $attr['is_meta'] ) && $attr['is_meta'] == 'yes' ) {
900
  return true;
901
  }
906
  /**
907
  * Get a meta value
908
  *
909
+ * @param int $object_id user_ID or post_ID
910
  * @param string $meta_key
911
+ * @param string $type post or user
912
+ * @param bool $single
913
+ *
914
  * @return string
915
  */
916
+ public function get_meta( $object_id, $meta_key, $type = 'post', $single = true ) {
917
  if ( !$object_id ) {
918
  return '';
919
  }
925
  return get_user_meta( $object_id, $meta_key, $single );
926
  }
927
 
928
+ public function get_user_data( $user_id, $field ) {
929
  return get_user_by( 'id', $user_id )->$field;
930
  }
931
 
932
  /**
933
  * Prints a text field
934
  *
935
+ * @param array $attr
936
  * @param int|null $post_id
937
  */
938
+ public function text( $attr, $post_id, $type = 'post', $form_id = null ) {
939
  // checking for user profile username
940
  $username = false;
941
  $taxonomy = false;
942
 
943
  if ( $post_id ) {
 
944
  if ( $this->is_meta( $attr ) ) {
945
  $value = $this->get_meta( $post_id, $attr['name'], $type );
946
  } else {
948
  // applicable for post tags
949
  if ( $type == 'post' && $attr['name'] == 'tags' ) {
950
  $post_tags = wp_get_post_tags( $post_id );
951
+ $tagsarray = [];
952
+
953
+ foreach ( $post_tags as $tag ) {
954
  $tagsarray[] = $tag->name;
955
  }
956
 
957
+ $value = implode( ', ', $tagsarray );
958
  $taxonomy = true;
959
  } elseif ( $type == 'post' ) {
960
  $value = get_post_field( $attr['name'], $post_id );
961
  } elseif ( $type == 'user' ) {
962
+ $name = $attr['name'];
963
  $value = get_user_by( 'id', $post_id )->$name;
964
+
965
  if ( $attr['name'] == 'user_login' ) {
966
  $username = true;
967
  }
973
  if ( $type == 'post' && $attr['name'] == 'tags' ) {
974
  $taxonomy = true;
975
  }
976
+ } ?>
 
 
977
 
978
  <div class="wpuf-fields">
979
+ <input class="textfield<?php echo esc_attr( $this->required_class( $attr ) );
980
+ echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" type="text" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="text"<?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="<?php echo esc_attr( $value ); ?>" size="<?php echo esc_attr( $attr['size'] ); ?>" <?php echo esc_attr( $username ) ? 'disabled' : ''; ?> />
981
  <span class="wpuf-wordlimit-message wpuf-help"></span>
982
  <?php $this->help_text( $attr ); ?>
983
 
998
  }
999
  }
1000
 
 
1001
  /**
1002
  * Function to check word restriction
1003
  *
1004
  * @param $word_nums number of words allowed
1005
  */
1006
+ public function check_word_restriction_func( $word_nums, $rich_text, $field_name ) {
1007
  // bail out if it is dashboard
1008
  if ( is_admin() ) {
1009
  return;
1010
+ } ?>
 
1011
  <script type="text/javascript">
1012
  ;(function($) {
1013
  $(document).ready( function(){
1014
+ WP_User_Frontend.editorLimit.bind(<?php printf( '%d, "%s", "%s"', esc_attr( $word_nums ), esc_attr( $field_name ), esc_attr( $rich_text ) ); ?>);
1015
  });
1016
  })(jQuery);
1017
  </script>
1018
  <?php
 
1019
  }
1020
 
1021
  /**
1022
  * Prints a textarea field
1023
+ *
1024
+ * @param array $attr
1025
  * @param int|null $post_id
1026
  */
1027
+ public function textarea( $attr, $post_id, $type, $form_id ) {
1028
  $req_class = ( $attr['required'] == 'yes' ) ? 'required' : 'rich-editor';
1029
+
1030
  if ( $post_id ) {
1031
  if ( $this->is_meta( $attr ) ) {
1032
  $value = $this->get_meta( $post_id, $attr['name'], $type, true );
1033
  } else {
 
1034
  if ( $type == 'post' ) {
1035
  $value = get_post_field( $attr['name'], $post_id );
1036
  } else {
1039
  }
1040
  } else {
1041
  $value = $attr['default'];
1042
+ } ?>
 
1043
 
1044
+ <?php if ( in_array( $attr['rich'], [ 'yes', 'teeny' ] ) ) { ?>
1045
+ <div class="wpuf-fields wpuf-rich-validation <?php printf( 'wpuf_%s_%s', esc_attr( $attr['name'] ), esc_attr( $form_id ) ); ?>" data-type="rich" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-name="<?php echo esc_attr( $attr['name'] ); ?>">
1046
  <?php } else { ?>
1047
  <div class="wpuf-fields">
1048
  <?php } ?>
1049
 
1050
  <?php if ( isset( $attr['insert_image'] ) && $attr['insert_image'] == 'yes' ) { ?>
1051
  <div id="wpuf-insert-image-container">
1052
+ <a class="wpuf-button wpuf-insert-image" id="wpuf-insert-image_<?php echo esc_attr( $form_id ); ?>" href="#" data-form_id="<?php echo esc_attr( $form_id ); ?>">
1053
  <span class="wpuf-media-icon"></span>
1054
+ <?php esc_html_e( 'Insert Photo', 'wp-user-frontend' ); ?>
1055
  </a>
1056
  </div>
1057
 
1058
  <script type="text/javascript">
1059
  ;(function($) {
1060
  $(document).ready( function(){
1061
+ WP_User_Frontend.insertImage('wpuf-insert-image_<?php echo esc_attr( $form_id ); ?>', '<?php echo esc_attr( $form_id ); ?>');
1062
  });
1063
  })(jQuery);
1064
  </script>
1066
 
1067
  <?php
1068
  $form_settings = wpuf_get_form_settings( $form_id );
1069
+ $layout = isset( $form_settings['form_layout'] ) ? $form_settings['form_layout'] : 'layout1';
1070
+ $textarea_id = $attr['name'] ? $attr['name'] . '_' . $form_id : 'textarea_' . $this->field_count;
1071
+ $content_css = includes_url() . 'js/tinymce/skins/wordpress/wp-content.css';
1072
 
1073
+ if ( $attr['rich'] == 'yes' ) {
1074
+ $editor_settings = [
1075
  'textarea_rows' => $attr['rows'],
1076
  'quicktags' => false,
1077
  'media_buttons' => false,
1078
  'editor_class' => $req_class,
1079
  'textarea_name' => $attr['name'],
1080
+ 'tinymce' => [
1081
+ 'content_css' => $content_css . ', ' . WPUF_ASSET_URI . '/css/frontend-form/' . $layout . '.css',
1082
+ ],
1083
+ ];
1084
+
1085
+ $editor_settings = apply_filters( 'wpuf_textarea_editor_args', $editor_settings );
1086
+ wp_editor( $value, $textarea_id, $editor_settings );
1087
+ } elseif ( $attr['rich'] == 'teeny' ) {
1088
+ $editor_settings = [
 
 
1089
  'textarea_rows' => $attr['rows'],
1090
  'quicktags' => false,
1091
  'media_buttons' => false,
1092
  'teeny' => true,
1093
  'editor_class' => $req_class,
1094
  'textarea_name' => $attr['name'],
1095
+ 'tinymce' => [
1096
+ 'content_css' => $content_css . ', ' . WPUF_ASSET_URI . '/css/frontend-form/' . $layout . '.css',
1097
+ ],
1098
+ ];
1099
 
1100
+ $editor_settings = apply_filters( 'wpuf_textarea_editor_args', $editor_settings );
1101
+ wp_editor( $value, $textarea_id, $editor_settings );
1102
+ } else {
1103
+ ?>
1104
+ <textarea class="textareafield<?php echo esc_attr( $this->required_class( $attr ) ); ?> <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" name="<?php echo esc_attr( $attr['name'] ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="textarea"<?php $this->required_html5( $attr ); ?> placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" rows="<?php echo esc_attr( $attr['rows'] ); ?>" cols="<?php echo esc_attr( $attr['cols'] ); ?>"><?php echo esc_textarea( $value ); ?></textarea>
 
1105
  <span class="wpuf-wordlimit-message wpuf-help"></span>
1106
+ <?php
1107
+ } ?>
1108
  <?php $this->help_text( $attr ); ?>
1109
  </div>
1110
  <?php
1114
  }
1115
  }
1116
 
 
1117
  /**
1118
  * Prints a select or multiselect field
1119
  *
1120
+ * @param array $attr
1121
+ * @param bool $multiselect
1122
  * @param int|null $post_id
1123
  */
1124
+ public function select( $attr, $multiselect = false, $post_id, $type, $form_id = null ) {
1125
  if ( $post_id ) {
1126
  $selected = $this->get_meta( $post_id, $attr['name'], $type );
1127
 
1128
  if ( $multiselect ) {
1129
  if ( is_serialized( $selected ) ) {
1130
+ $selected = maybe_unserialize( $selected );
1131
  } elseif ( is_array( $selected ) ) {
1132
+ $selected = $selected;
1133
  } else {
1134
  $selected = explode( self::$separator, $selected );
1135
  }
1136
  }
1137
  } else {
1138
  $selected = isset( $attr['selected'] ) ? $attr['selected'] : '';
1139
+ $selected = $multiselect ? ( is_array( $selected ) ? $selected : [] ) : $selected;
1140
  }
1141
 
1142
  $name = $multiselect ? $attr['name'] . '[]' : $attr['name'];
1143
  $multi = $multiselect ? ' multiple="multiple"' : '';
1144
  $data_type = $multiselect ? 'multiselect' : 'select';
1145
+ $css = $multiselect ? ' class="multiselect wpuf_' . $attr['name'] . '_' . $form_id . '"' : ''; ?>
 
1146
 
1147
  <div class="wpuf-fields">
1148
+ <select <?php echo esc_attr( $css ); ?> class="<?php echo 'wpuf_' . esc_attr( $attr['name'] ) . '_' .esc_attr( $form_id ); ?>" name="<?php echo esc_attr( $name ); ?>"<?php echo esc_attr( $multi ); ?> data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="<?php echo esc_attr($data_type ); ?>"<?php esc_attr( $this->required_html5( $attr ) ); ?>>
1149
 
1150
  <?php if ( !empty( $attr['first'] ) ) { ?>
1151
+ <option value=""><?php echo esc_attr( $attr['first'] ); ?></option>
1152
  <?php } ?>
1153
 
1154
  <?php
1155
  if ( $attr['options'] && count( $attr['options'] ) > 0 ) {
1156
+ foreach ( $attr['options'] as $value => $option ) {
1157
+ $current_select = $multiselect ? selected( in_array( $value, $selected ), true, false ) : selected( $selected, $value, false ); ?>
1158
+ <option value="<?php echo esc_attr( $value ); ?>"<?php echo esc_attr( $current_select ); ?>><?php echo esc_html( $option ); ?></option>
 
1159
  <?php
1160
  }
1161
+ } ?>
 
1162
  </select>
1163
  <?php $this->help_text( $attr ); ?>
1164
  </div>
1168
  /**
1169
  * Prints a radio field
1170
  *
1171
+ * @param array $attr
1172
  * @param int|null $post_id
1173
  */
1174
+ public function radio( $attr, $post_id, $type, $form_id ) {
1175
  $selected = isset( $attr['selected'] ) ? $attr['selected'] : '';
1176
+
1177
  if ( $post_id ) {
1178
  $selected = $this->get_meta( $post_id, $attr['name'], $type, true );
1179
+ } ?>
 
1180
 
1181
+ <div class="wpuf-fields" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="radio">
1182
 
1183
  <?php
1184
  if ( $attr['options'] && count( $attr['options'] ) > 0 ) {
1185
+ foreach ( $attr['options'] as $value => $option ) {
1186
  ?>
1187
 
1188
  <label <?php echo $attr['inline'] == 'yes' ? 'class="wpuf-radio-inline"' : 'class="wpuf-radio-block"'; ?>>
1189
+ <input name="<?php echo esc_attr( $attr['name'] ); ?>" class="<?php echo 'wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" type="radio" value="<?php echo esc_attr( $value ); ?>"<?php checked( $selected, $value ); ?> />
1190
+ <?php echo esc_html( $option ); ?>
1191
  </label>
1192
  <?php
1193
  }
1194
+ } ?>
 
1195
 
1196
  <?php $this->help_text( $attr ); ?>
1197
  </div>
1202
  /**
1203
  * Prints a checkbox field
1204
  *
1205
+ * @param array $attr
1206
  * @param int|null $post_id
1207
  */
1208
+ public function checkbox( $attr, $post_id, $type, $form_id ) {
1209
+ $selected = isset( $attr['selected'] ) ? $attr['selected'] : [];
 
1210
 
1211
  if ( $post_id ) {
1212
  if ( $value = $this->get_meta( $post_id, $attr['name'], $type, true ) ) {
1213
  if ( is_serialized( $value ) ) {
1214
+ $selected = maybe_unserialize( $value );
1215
  } elseif ( is_array( $value ) ) {
1216
+ $selected = $value;
1217
  } else {
1218
  $selected = explode( self::$separator, $value );
1219
  }
1220
  }
1221
+ } ?>
1222
 
1223
+ <div class="wpuf-fields" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="radio">
 
 
1224
 
1225
  <?php
1226
  if ( $attr['options'] && count( $attr['options'] ) > 0 ) {
1227
+ foreach ( $attr['options'] as $value => $option ) {
 
 
1228
  ?>
1229
  <label <?php echo $attr['inline'] == 'yes' ? 'class="wpuf-checkbox-inline"' : 'class="wpuf-checkbox-block"'; ?>>
1230
+ <input type="checkbox" class="<?php echo 'wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" name="<?php echo esc_attr( $attr['name'] ); ?>[]" value="<?php echo esc_attr( $value ); ?>"<?php echo in_array( $value, $selected ) ? ' checked="checked"' : ''; ?> />
1231
+ <?php echo esc_html( $option ); ?>
1232
  </label>
1233
  <?php
1234
  }
1235
+ } ?>
 
1236
 
1237
  <?php $this->help_text( $attr ); ?>
1238
 
1244
  /**
1245
  * Prints a url field
1246
  *
1247
+ * @param array $attr
1248
  * @param int|null $post_id
1249
  */
1250
+ public function url( $attr, $post_id, $type, $form_id ) {
 
1251
  if ( $post_id ) {
1252
  if ( $this->is_meta( $attr ) ) {
1253
  $value = $this->get_meta( $post_id, $attr['name'], $type, true );
1257
  }
1258
  } else {
1259
  $value = $attr['default'];
1260
+ } ?>
 
1261
 
1262
  <div class="wpuf-fields">
1263
+ <input id="wpuf-<?php echo esc_attr( $attr['name'] ); ?>" type="url" class="url <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="text"<?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="<?php echo esc_attr( $value ); ?>" size="<?php echo esc_attr( $attr['size'] ); ?>" />
1264
  <?php $this->help_text( $attr ); ?>
1265
  </div>
1266
 
1270
  /**
1271
  * Prints a email field
1272
  *
1273
+ * @param array $attr
1274
  * @param int|null $post_id
1275
  */
1276
+ public function email( $attr, $post_id, $type = 'post', $form_id ) {
1277
  if ( $post_id ) {
1278
  if ( $this->is_meta( $attr ) ) {
1279
  $value = $this->get_meta( $post_id, $attr['name'], $type, true );
1283
  }
1284
  } else {
1285
  $value = $attr['default'];
1286
+ } ?>
 
1287
 
1288
  <div class="wpuf-fields">
1289
+ <input id="wpuf-<?php echo esc_attr( $attr['name'] ); ?>" type="email" class="email <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="email" <?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="<?php echo esc_attr( $value ); ?>" size="<?php echo esc_attr( $attr['size'] ); ?>" />
1290
  <?php $this->help_text( $attr ); ?>
1291
  </div>
1292
 
1298
  *
1299
  * @param array $attr
1300
  */
1301
+ public function password( $attr, $post_id, $type, $form_id ) {
1302
  if ( $post_id ) {
1303
  $attr['required'] = 'no';
1304
  }
1305
 
1306
  $repeat_pass = ( $attr['repeat_pass'] == 'yes' ) ? true : false;
1307
+ $pass_strength = ( $attr['pass_strength'] == 'yes' ) ? true : false; ?>
 
1308
 
1309
  <div class="wpuf-fields">
1310
+ <input id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_1'; ?>" type="password" class="password <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="password"<?php $this->required_html5( $attr ); ?> data-repeat="<?php echo esc_attr( $repeat_pass ) ? 'true' : 'false'; ?>" name="pass1" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="" size="<?php echo esc_attr( $attr['size'] ); ?>" />
1311
  <?php $this->help_text( $attr ); ?>
1312
  </div>
1313
 
1315
  if ( $repeat_pass ) {
1316
  $field_size = !empty( $attr['width'] ) ? ' field-size-' . $attr['width'] : '';
1317
 
1318
+ echo wp_kses_post( '</li>' );
1319
+ echo wp_kses_post( '<li class="wpuf-el password-repeat ' . $field_size . '" data-label="' . esc_attr( __( 'Confirm Password', 'wp-user-frontend' ) ) . '">' );
1320
 
1321
+ $this->label( ['name' => 'pass2', 'label' => $attr['re_pass_label'], 'required' => $post_id ? 'no' : 'yes'] ); ?>
 
1322
 
1323
  <div class="wpuf-fields">
1324
+ <input id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_2'; ?>" type="password" class="password <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="confirm_password"<?php $this->required_html5( $attr ); ?> name="pass2" value="" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" size="<?php echo esc_attr( $attr['size'] ); ?>" />
1325
  </div>
1326
 
1327
  <?php
1328
  }
1329
 
1330
  if ( $pass_strength ) {
1331
+ echo wp_kses_post( '</li>' );
1332
+ echo wp_kses_post( '<li>' );
1333
 
1334
  wp_enqueue_script( 'zxcvbn' );
1335
+ wp_enqueue_script( 'password-strength-meter' ); ?>
 
1336
  <div class="wpuf-label">
1337
  &nbsp;
1338
  </div>
1339
 
1340
  <div class="wpuf-fields">
1341
+ <div class="pass-strength-result" id="pass-strength-result_<?php echo esc_attr( $form_id ); ?>" style="display: block"><?php esc_html_e( 'Strength indicator', 'wp-user-frontend' ); ?></div>
1342
  </div>
1343
 
1344
  <script type="text/javascript">
1345
  jQuery(function($) {
1346
  function check_pass_strength() {
1347
+ var pass1 = $("#<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_1'; ?>").val(),
1348
+ pass2 = $("#<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_2'; ?>").val(),
1349
  strength;
1350
 
1351
  if ( typeof pass2 === undefined ) {
1352
  pass2 = pass1;
1353
  }
1354
 
1355
+ $("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").removeClass('short bad good strong');
1356
  if (!pass1) {
1357
+ $("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").html(pwsL10n.empty);
1358
  return;
1359
  }
1360
 
1362
 
1363
  switch (strength) {
1364
  case 2:
1365
+ $("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('bad').html(pwsL10n.bad);
1366
  break;
1367
  case 3:
1368
+ $("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('good').html(pwsL10n.good);
1369
  break;
1370
  case 4:
1371
+ $("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('strong').html(pwsL10n.strong);
1372
  break;
1373
  case 5:
1374
+ $("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('short').html(pwsL10n.mismatch);
1375
  break;
1376
  default:
1377
+ $("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('short').html(pwsL10n['short']);
1378
  }
1379
  }
1380
 
1381
+ $("#<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_1'; ?>").val('').keyup(check_pass_strength);
1382
+ $("#<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_2'; ?>").val('').keyup(check_pass_strength);
1383
+ $("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").show();
1384
  });
1385
  </script>
1386
  <?php
1387
  }
 
1388
  }
1389
 
1390
+ public function taxnomy_select( $terms, $attr ) {
 
 
1391
  $selected = $terms ? $terms : '';
1392
  $required = sprintf( 'data-required="%s" data-type="select"', $attr['required'] );
1393
  $taxonomy = $attr['name'];
1394
+ $class = ' wpuf_' . $attr['name'] . '_' . $selected;
1395
  $exclude_type = isset( $attr['exclude_type'] ) ? $attr['exclude_type'] : 'exclude';
1396
  $exclude = isset( $attr['exclude'] ) ? $attr['exclude'] : '';
1397
 
1398
  if ( $exclude_type == 'child_of' && !empty( $exclude ) ) {
1399
+ $exclude = $exclude[0];
1400
  }
1401
 
1402
+ $tax_args = [
1403
  'show_option_none' => __( '-- Select --', 'wp-user-frontend' ),
1404
  'hierarchical' => 1,
1405
  'hide_empty' => 0,
1409
  'taxonomy' => $taxonomy,
1410
  'echo' => 0,
1411
  'title_li' => '',
1412
+ 'class' => 'cat-ajax ' . $taxonomy . $class,
1413
  $exclude_type => $exclude,
1414
  'selected' => $selected,
1415
  'depth' => 1,
1416
+ 'child_of' => isset( $attr['parent_cat'] ) ? $attr['parent_cat'] : '',
1417
+ ];
1418
 
1419
  $tax_args = apply_filters( 'wpuf_taxonomy_checklist_args', $tax_args );
1420
 
1421
  $select = wp_dropdown_categories( $tax_args );
1422
 
1423
+ echo wp_kses_post( str_replace( '<select', '<select ' . $required, $select ) );
1424
+ $attr = [
1425
  'required' => $attr['required'],
1426
  'name' => $attr['name'],
1427
  'exclude_type' => $attr['exclude_type'],
1428
+ 'exclude' => isset( $attr['exclude'] ) ? $attr['exclude'] : '',
1429
  'orderby' => $attr['orderby'],
1430
  'order' => $attr['order'],
1431
  'name' => $attr['name'],
1432
  //'last_term_id' => isset( $attr['parent_cat'] ) ? $attr['parent_cat'] : '',
1433
  //'term_id' => $selected
1434
+ ];
1435
+ $attr = apply_filters( 'wpuf_taxonomy_checklist_args', $attr ); ?>
1436
+ <span data-taxonomy=<?php echo esc_attr( json_encode( $attr ) ); ?>></span>
 
1437
  <?php
1438
  }
1439
 
1440
  /**
1441
  * Prints a taxonomy field
1442
  *
1443
+ * @param array $attr
1444
  * @param int|null $post_id
1445
  */
1446
+ public function taxonomy( $attr, $post_id, $form_id ) {
1447
+ $exclude_type = isset( $attr['exclude_type'] ) ? esc_attr( $attr['exclude_type'] ) : 'exclude';
 
1448
  // $exclude = $attr['exclude'];
1449
+ $exclude = isset( $attr['exclude'] ) ? esc_attr( $attr['exclude'] ) : '';
 
1450
 
1451
  if ( $exclude_type == 'child_of' ) {
1452
+ $exclude = $exclude[0];
1453
  }
1454
 
1455
  $taxonomy = $attr['name'];
1456
+ $class = ' wpuf_' . $attr['name'] . '_' . $form_id;
1457
  $current_user = get_current_user_id();
1458
 
1459
+ $terms = [];
1460
+
1461
  if ( $post_id && $attr['type'] == 'text' ) {
1462
+ $terms = wp_get_post_terms( $post_id, $taxonomy, ['fields' => 'names'] );
1463
+ } elseif ( $post_id ) {
1464
+ $terms = wp_get_post_terms( $post_id, $taxonomy, ['fields' => 'ids'] );
1465
  }
1466
 
1467
+ if ( !taxonomy_exists( $taxonomy ) ) {
1468
+ echo wp_kses_post( '<br><div class="wpuf-message">' . __( 'This field is no longer available.', 'wp-user-frontend' ) . '</div>' );
1469
+
1470
  return;
1471
  }
1472
 
1473
+ $div_class = 'wpuf_' . $attr['name'] . '_' . $attr['type'] . '_' . $attr['id'] . '_' . $form_id; ?>
 
1474
 
1475
 
1476
  <?php if ( $attr['type'] == 'checkbox' ) { ?>
1477
+ <div class="wpuf-fields <?php echo esc_attr( $div_class ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="tax-checkbox">
1478
  <?php } else { ?>
1479
+ <div class="wpuf-fields <?php echo esc_attr( $div_class ); ?>">
1480
  <?php } ?>
1481
 
1482
  <?php
1483
+ switch ( $attr['type'] ) {
1484
  case 'ajax':
1485
+ $class = ' wpuf_' . $attr['name'] . '_' . $form_id;
1486
  ?>
1487
+ <div class="category-wrap <?php echo esc_attr( $class ); ?>">
1488
  <?php
1489
 
1490
  if ( !count( $terms ) ) {
 
1491
  ?>
1492
  <div id="lvl0" level="0">
1493
  <?php $this->taxnomy_select( null, $attr, $form_id ); ?>
1494
  </div>
1495
  <?php
1496
  } else {
 
1497
  $level = 0;
1498
  asort( $terms );
1499
  $last_term_id = end( $terms );
1500
 
1501
+ foreach ( $terms as $term_id ) {
1502
+ $class = ( $last_term_id != $term_id ) ? 'hasChild' : ''; ?>
1503
+ <div id="lvl<?php echo esc_attr( $level ); ?>" level="<?php echo esc_attr( $level ); ?>" >
 
1504
  <?php $this->taxnomy_select( $term_id, $attr ); ?>
1505
  </div>
1506
  <?php
1514
  <span class="loading"></span>
1515
  <?php
1516
  break;
1517
+
1518
  case 'select':
1519
  $selected = $terms ? $terms[0] : '';
1520
  $required = sprintf( 'data-required="%s" data-type="select"', $attr['required'] );
1521
+ $tax_args = [
1522
+ 'show_option_none' => isset( $attr['first'] ) ? $attr['first'] : '--select--',
1523
  'hierarchical' => 1,
1524
  'hide_empty' => 0,
1525
  'orderby' => isset( $attr['orderby'] ) ? $attr['orderby'] : 'name',
1531
  'class' => $taxonomy . $class,
1532
  $exclude_type => $exclude,
1533
  'selected' => $selected,
1534
+ ];
1535
 
1536
  $tax_args = apply_filters( 'wpuf_taxonomy_checklist_args', $tax_args );
1537
 
1538
  $select = wp_dropdown_categories( $tax_args );
1539
 
1540
+ echo wp_kses_post( str_replace( '<select', '<select ' . $required, $select ) );
1541
  break;
1542
 
1543
  case 'multiselect':
1544
+ $selected = $terms ? $terms : [];
1545
  $required = sprintf( 'data-required="%s" data-type="multiselect"', $attr['required'] );
1546
  $walker = new WPUF_Walker_Category_Multi();
1547
+ $tax_args = [
1548
  // 'show_option_none' => __( '-- Select --', 'wpuf' ),
1549
  'hierarchical' => 1,
1550
  'hide_empty' => 0,
1558
  'class' => $taxonomy . ' multiselect' . $class,
1559
  $exclude_type => $exclude,
1560
  'selected' => $selected,
1561
+ 'walker' => $walker,
1562
+ ];
1563
 
1564
  $tax_args = apply_filters( 'wpuf_taxonomy_checklist_args', $tax_args );
1565
 
1566
  $select = wp_dropdown_categories( $tax_args );
1567
 
1568
+ echo wp_kses_post( str_replace( '<select', '<select multiple="multiple" ' . $required, $select ) );
1569
  break;
1570
 
1571
  case 'checkbox':
1575
  case 'text':
1576
  ?>
1577
 
1578
+ <input class="textfield<?php echo esc_attr( $this->required_class( $attr ) ); ?>" id="<?php echo esc_attr( $attr['name'] ); ?>" type="text" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="text"<?php esc_attr( $this->required_html5( $attr ) ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" value="<?php echo esc_attr( implode( ', ', $terms ) ); ?>" size="40" />
1579
 
1580
  <script type="text/javascript">
1581
  ;(function($) {
1582
  $(document).ready( function(){
1583
+ $('#<?php echo esc_attr( $attr['name'] ); ?>').suggest( wpuf_frontend.ajaxurl + '?action=wpuf-ajax-tag-search&tax=<?php echo esc_attr( $attr['name'] ); ?>', { delay: 500, minchars: 2, multiple: true, multipleSep: ', ' } );
1584
  });
1585
  })(jQuery);
1586
  </script>
1589
  break;
1590
 
1591
  default:
1592
+ // code...
1593
  break;
1594
+ } ?>
 
1595
  <?php $this->help_text( $attr ); ?>
1596
  </div>
1597
 
1604
  *
1605
  * @param array $attr
1606
  */
1607
+ public function html( $attr, $form_id ) {
1608
  ?>
1609
+ <div class="wpuf-fields <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>">
1610
+ <?php echo esc_html( $attr['html'] ); ?>
1611
  </div>
1612
  <?php
1613
  }
1615
  /**
1616
  * Prints a image upload field
1617
  *
1618
+ * @param array $attr
1619
  * @param int|null $post_id
1620
  */
1621
+ public function image_upload( $attr, $post_id, $type, $form_id ) {
 
1622
  $has_featured_image = false;
1623
  $has_images = false;
1624
  $has_avatar = false;
1629
  $images = $this->get_meta( $post_id, $attr['name'], $type, false );
1630
 
1631
  if ( $images ) {
1632
+ if ( is_serialized( $images[0] ) ) {
1633
  $images = maybe_unserialize( $images[0] );
1634
  }
1635
 
1640
 
1641
  $has_images = true;
1642
  } else {
 
1643
  if ( $type == 'post' ) {
1644
  // it's a featured image then
1645
  $thumb_id = get_post_thumbnail_id( $post_id );
1646
 
1647
  if ( $thumb_id ) {
1648
  $has_featured_image = true;
1649
+ $featured_image = WPUF_Upload::attach_html( $thumb_id, 'featured_image' );
1650
  }
1651
  } else {
1652
  // it must be a user avatar
1653
+ $has_avatar = true;
1654
  $featured_image = get_avatar( $post_id );
1655
  }
1656
  }
1657
  }
1658
+ $button_label = empty( $attr['button_label'] ) ? __( 'Select Image', 'wp-user-frontend' ) : $attr['button_label']; ?>
 
1659
 
1660
  <div class="wpuf-fields">
1661
+ <div id="wpuf-<?php echo esc_attr( $unique_id ); ?>-upload-container">
1662
+ <div class="wpuf-attachment-upload-filelist" data-type="file" data-required="<?php echo esc_attr( $attr['required'] ); ?>">
1663
+ <a id="wpuf-<?php echo esc_attr( $unique_id ); ?>-pickfiles" data-form_id="<?php echo esc_attr( $form_id ); ?>" class="button file-selector <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" href="#"><?php echo esc_attr( $button_label ); ?></a>
1664
 
1665
  <ul class="wpuf-attachment-list thumbnails">
1666
  <?php
1667
  if ( $has_featured_image ) {
1668
+ echo esc_attr( $featured_image );
1669
  }
1670
 
1671
+ if ( $has_avatar ) {
1672
+ $avatar = get_user_meta( $post_id, 'user_avatar', true );
 
 
 
 
 
 
1673
 
1674
+ if ( $avatar ) {
1675
+ echo wp_kses_post( '<li>' . $featured_image );
1676
+ printf( '<br><a href="#" data-confirm="%s" class="btn btn-danger btn-small wpuf-button button wpuf-delete-avatar">%s</a>', esc_html( __( 'Are you sure?', 'wp-user-frontend' ) ),esc_html( __( 'Delete', 'wp-user-frontend' ) ) );
1677
+ echo wp_kses_post( '</li>' );
1678
+ }
1679
+ }
1680
+
1681
+ if ( $has_images ) {
1682
+ foreach ( $images as $attach_id ) {
1683
+ echo esc_attr( WPUF_Upload::attach_html( $attach_id, $attr['name'] ) );
1684
+ }
1685
+ } ?>
1686
  </ul>
1687
  </div>
1688
  </div><!-- .container -->
1694
  <script type="text/javascript">
1695
  ;(function($) {
1696
  $(document).ready( function(){
1697
+ var uploader = new WPUF_Uploader('wpuf-<?php echo esc_attr( $unique_id ); ?>-pickfiles', 'wpuf-<?php echo esc_attr( $unique_id ); ?>-upload-container', <?php echo esc_attr( $attr['count'] ); ?>, '<?php echo esc_attr( $attr['name'] ); ?>', 'jpg,jpeg,gif,png,bmp', <?php echo esc_attr( $attr['max_size'] ); ?>);
1698
  wpuf_plupload_items.push(uploader);
1699
  });
1700
  })(jQuery);
1701
  </script>
1702
  <?php
 
1703
  }
1704
 
1705
  /**
1706
  * Prints a section break
1707
  *
1708
+ * @param array $attr
1709
  * @param int|null $post_id
1710
  */
1711
+ public function section_break( $attr, $post_id, $form_id ) {
1712
  ?>
1713
+ <div class="wpuf-section-wrap <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $attr['id'] ) . '_' . esc_attr( $form_id ); ?>">
1714
+ <h2 class="wpuf-section-title"><?php echo esc_attr( $attr['label'] ); ?></h2>
1715
+ <div class="wpuf-section-details"><?php echo esc_attr( $attr['description'] ); ?></div>
1716
  </div>
1717
  <?php
1718
  }
1723
  * @param array $attr
1724
  */
1725
  public static function recaptcha( $attr, $post_id, $form_id ) {
 
1726
  if ( $post_id ) {
1727
  return;
1728
  }
1729
  $enable_no_captcha = $enable_invisible_recaptcha = '';
1730
+
1731
+ if ( isset( $attr['recaptcha_type'] ) ) {
1732
  $enable_invisible_recaptcha = $attr['recaptcha_type'] == 'invisible_recaptcha' ? true : false;
1733
+ $enable_no_captcha = $attr['recaptcha_type'] == 'enable_no_captcha' ? true : false;
1734
  }
1735
 
1736
  if ( $enable_invisible_recaptcha ) { ?>
1737
  <script src="https://www.google.com/recaptcha/api.js?onload=wpufreCaptchaLoaded&render=explicit&hl=en" async defer></script>
1738
  <script>
1739
  jQuery(document).ready(function($) {
1740
+ jQuery('[name="submit"]').removeClass('wpuf-submit-button').addClass('g-recaptcha').attr('data-sitekey', '<?php echo esc_html( wpuf_get_option( 'recaptcha_public', 'wpuf_general' ) ); ?>');
1741
 
1742
  $(document).on('click','.g-recaptcha', function(e){
1743
  e.preventDefault();
1759
  jQuery('[name="submit"]').removeClass('g-recaptcha').addClass('wpuf-submit-button');
1760
  }
1761
  </script>
1762
+
1763
+ <div type="submit" id='recaptcha' class="g-recaptcha" data-sitekey=<?php echo esc_attr( wpuf_get_option( 'recaptcha_public', 'wpuf_general' ) ); ?> data-callback="onSubmit" data-size="invisible"></div>
1764
  <?php } else { ?>
1765
+ <div class="wpuf-fields <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>">
1766
+ <?php echo esc_html( recaptcha_get_html( wpuf_get_option( 'recaptcha_public', 'wpuf_general' ), $enable_no_captcha, null, is_ssl() ) ); ?>
1767
  </div>
1768
  <?php }
1769
  }
 
1770
  }
class/subscription.php CHANGED
@@ -4,44 +4,42 @@
4
  * WPUF subscription manager
5
  *
6
  * @since 0.2
 
7
  * @author Tareq Hasan
8
- * @package WP User Frontend
9
  */
10
  class WPUF_Subscription {
11
 
12
  private static $_instance;
13
 
14
- function __construct() {
15
-
16
- add_action( 'init', array($this, 'register_post_type') );
17
- add_filter( 'wpuf_add_post_args', array($this, 'set_pending'), 10, 4 );
18
- add_filter( 'wpuf_add_post_redirect', array($this, 'post_redirect'), 10, 4 );
19
 
20
- add_filter( 'wpuf_addpost_notice', array($this, 'force_pack_notice'), 20, 3 );
21
- add_filter( 'wpuf_can_post', array($this, 'force_pack_permission'), 20, 3 );
22
- add_action( 'wpuf_add_post_form_top', array($this, 'add_post_info'), 10, 2 );
23
 
24
- add_action( 'wpuf_add_post_after_insert', array($this, 'monitor_new_post'), 10, 3 );
25
- add_action( 'wpuf_draft_post_after_insert', array($this, 'monitor_new_draft_post'), 10, 3 );
26
- add_action( 'wpuf_payment_received', array($this, 'payment_received'), 10, 2 );
27
 
28
- add_shortcode( 'wpuf_sub_info', array($this, 'subscription_info') );
29
- add_shortcode( 'wpuf_sub_pack', array($this, 'subscription_packs') );
30
 
31
- add_action( 'save_post', array( $this, 'save_form_meta' ), 10, 2 );
32
- add_filter( 'enter_title_here', array( $this, 'change_default_title' ) );
33
- add_action( 'admin_enqueue_scripts', array( $this, 'subscription_script' ) );
34
 
35
- add_action( 'user_register', array( $this,'after_registration' ), 10, 1 );
36
 
37
- add_action( 'register_form',array( $this, 'register_form') );
38
- add_action( 'wpuf_add_post_form_top',array( $this, 'register_form') );
39
- add_filter( 'wpuf_user_register_redirect', array( $this, 'subs_redirect_pram' ), 10, 5 );
40
 
41
- add_filter( 'template_redirect', array( $this, 'user_subscription_cancel' ) );
42
-
43
- add_action( 'wpuf_draft_post_after_insert', array( $this, 'reset_user_subscription_data' ), 10, 4 );
44
 
 
45
  }
46
 
47
  /**
@@ -52,13 +50,13 @@ class WPUF_Subscription {
52
  public static function subscriber_cancel( $user_id, $pack_id ) {
53
  global $wpdb;
54
 
55
- $sql = $wpdb->prepare( "SELECT transaction_id FROM " . $wpdb->prefix . "wpuf_transaction
56
- WHERE user_id = %d AND pack_id = %d LIMIT 1", $user_id, $pack_id );
57
  $result = $wpdb->get_row( $sql );
58
 
59
  $transaction_id = $result ? $result->transaction_id : 0;
60
 
61
- $wpdb->update( $wpdb->prefix.'wpuf_subscribers', array( 'subscribtion_status' => 'cancel' ), array( 'user_id' => $user_id, 'subscribtion_id' => $pack_id, 'transaction_id' => $transaction_id ) );
62
  }
63
 
64
  /**
@@ -68,32 +66,35 @@ class WPUF_Subscription {
68
  */
69
  public function user_subscription_cancel() {
70
  if ( isset( $_POST['wpuf_cancel_subscription'] ) ) {
 
 
 
 
 
71
 
72
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpuf-sub-cancel' ) ) {
73
- wp_die( __( 'Nonce failure', 'wp-user-frontend' ) );
74
  }
75
 
76
- $current_pack = self::get_user_pack( $_POST['user_id'] );
77
 
78
- $gateway = ( $_POST['gateway'] == 'bank/manual' ) ? 'bank' : sanitize_text_field( $_POST['gateway'] );
79
 
80
  if ( 'bank' == $gateway || 'no' == $current_pack['recurring'] ) {
81
- $this->update_user_subscription_meta( $_POST['user_id'], 'Cancel' );
82
  } else {
83
  do_action( "wpuf_cancel_subscription_{$gateway}", $_POST );
84
  }
85
 
86
- $this::subscriber_cancel( $_POST['user_id'], $current_pack['pack_id'] );
87
-
88
- wp_redirect( $_SERVER['REQUEST_URI'] );
89
 
 
90
  }
91
  }
92
 
93
-
94
  public static function init() {
95
  if ( !self::$_instance ) {
96
- self::$_instance = new self;
97
  }
98
 
99
  return self::$_instance;
@@ -104,35 +105,44 @@ class WPUF_Subscription {
104
  *
105
  * @since 2.2
106
  *
107
- * @param array $response
108
- * @param int $user_id
109
- * @param array $userdata
110
- * @param int $form_id
111
- * @param array $form_settings
 
112
  * @return array
113
  */
114
- function subs_redirect_pram( $response, $user_id, $userdata, $form_id, $form_settings ) {
115
- if ( ! isset( $_POST['wpuf_sub'] ) || $_POST['wpuf_sub'] != 'yes' ) {
116
- return $response;
117
- }
118
 
119
- if ( ! isset( $_POST['pack_id'] ) || empty( $_POST['pack_id'] ) ) {
120
- return $response;
121
- }
122
 
123
- $pack = $this->get_subscription( $_POST['pack_id'] );
124
- $billing_amount = ( $pack->meta_value['billing_amount'] >= 0 && !empty( $pack->meta_value['billing_amount'] ) ) ? $pack->meta_value['billing_amount'] : false;
125
 
126
- if ( $billing_amount !== false ) {
127
- $pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
128
- $redirect = add_query_arg( array('action' => 'wpuf_pay', 'user_id' => $user_id, 'type' => 'pack', 'pack_id' => (int) $_POST['pack_id'] ), get_permalink( $pay_page ) );
129
 
130
- $response['redirect_to'] = $redirect;
131
- $response['show_message'] = false;
132
- }
133
 
134
- return $response;
135
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
  /**
138
  * Insert hidden field on the register form based on selected package
@@ -141,19 +151,20 @@ class WPUF_Subscription {
141
  *
142
  * @return void
143
  */
144
- function register_form() {
145
- if ( !isset( $_GET['type'] ) || $_GET['type'] != 'wpuf_sub' ) {
 
 
 
146
  return;
147
  }
148
 
149
- if ( !isset( $_GET['pack_id'] ) || empty( $_GET['pack_id'] ) ) {
150
  return;
151
  }
152
-
153
- $pack_id = (int) $_GET['pack_id'];
154
  ?>
155
  <input type="hidden" name="wpuf_sub" value="yes" />
156
- <input type="hidden" name="pack_id" value="<?php echo $pack_id; ?>" />
157
 
158
  <?php
159
  }
@@ -163,20 +174,27 @@ class WPUF_Subscription {
163
  *
164
  * @since 2.2
165
  *
166
- * @param int $user_id
 
167
  * @return void
168
  */
169
- function after_registration( $user_id ) {
 
 
 
 
 
 
170
 
171
- if ( !isset( $_POST['wpuf_sub'] ) || $_POST['wpuf_sub'] != 'yes' ) {
 
172
  return $user_id;
173
  }
174
 
175
- if ( !isset( $_POST['pack_id'] ) || empty( $_POST['pack_id'] ) ) {
176
  return $user_id;
177
  }
178
 
179
- $pack_id = isset( $_POST['pack_id'] ) ? intval( $_POST['pack_id'] ) : 0;
180
  $pack = $this->get_subscription( $pack_id );
181
  $billing_amount = ( $pack->meta_value['billing_amount'] >= 0 && !empty( $pack->meta_value['billing_amount'] ) ) ? $pack->meta_value['billing_amount'] : false;
182
 
@@ -185,7 +203,7 @@ class WPUF_Subscription {
185
  wpuf_get_user( $user_id )->subscription()->add_free_pack( $user_id, $pack_id );
186
  } else {
187
  $pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
188
- $redirect = add_query_arg( array( 'action' => 'wpuf_pay', 'type' => 'pack', 'pack_id' => (int) $pack_id ), get_permalink( $pay_page ) );
189
  }
190
  }
191
 
@@ -194,8 +212,8 @@ class WPUF_Subscription {
194
  *
195
  * @since 2.2
196
  */
197
- function subscription_script() {
198
- wp_enqueue_script( 'wpuf-subscriptions', WPUF_ASSET_URI . '/js/subscriptions.js', array('jquery'), false, true );
199
  }
200
 
201
  /**
@@ -203,19 +221,18 @@ class WPUF_Subscription {
203
  *
204
  * @return array
205
  */
206
- function get_subscriptions( $args = array() ) {
207
- $defaults = array(
208
  'post_type' => 'wpuf_subscription',
209
  'posts_per_page' => -1,
210
  'post_status' => 'publish',
 
211
 
212
- );
213
-
214
- $args = wp_parse_args($args, $defaults);
215
  $posts = get_posts( $args );
216
 
217
  if ( $posts ) {
218
- foreach ($posts as $key => $post) {
219
  $post->meta_value = $this->get_subscription_meta( $post->ID, $posts );
220
  }
221
  }
@@ -228,12 +245,12 @@ class WPUF_Subscription {
228
  *
229
  * @since 2.2
230
  *
231
- * @param int $subscription_id
232
- * @param \WP_Post $pack_post
 
233
  * @return array
234
  */
235
- public static function get_subscription_meta( $subscription_id, $pack_post = null ) {
236
-
237
  $meta['post_content'] = isset( $pack_post->post_content ) ? $pack_post->post_content : '';
238
  $meta['post_title'] = isset( $pack_post->post_title ) ? $pack_post->post_title : '';
239
  $meta['billing_amount'] = get_post_meta( $subscription_id, '_billing_amount', true );
@@ -262,9 +279,10 @@ class WPUF_Subscription {
262
  * Get all post types
263
  *
264
  * @since 2.2
 
265
  * @return array
266
  */
267
- function get_all_post_type() {
268
  $post_types = get_post_types();
269
 
270
  unset(
@@ -279,7 +297,7 @@ class WPUF_Subscription {
279
  $post_types['custom_css'],
280
  $post_types['customize_changeset'],
281
  $post_types['oembed_cache']
282
- );
283
 
284
  return apply_filters( 'wpuf_posts_type', $post_types );
285
  }
@@ -287,10 +305,11 @@ class WPUF_Subscription {
287
  /**
288
  * Post type name placeholder text
289
  *
290
- * @param string $title
 
291
  * @return string
292
  */
293
- function change_default_title( $title ) {
294
  $screen = get_current_screen();
295
 
296
  if ( 'wpuf_subscription' == $screen->post_type ) {
@@ -303,24 +322,27 @@ class WPUF_Subscription {
303
  /**
304
  * Save form data
305
  *
306
- * @param int $post_ID
307
- * @param \WP_Post $post
 
308
  * @return void
309
  */
310
- function save_form_meta( $subscription_id, $post ) {
311
 
312
- $post_data = $_POST;
313
 
314
- if ( !isset( $post_data['billing_amount'] ) ) {
315
  return;
316
  }
317
 
318
- if ( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'subs_meta_box_nonce' ) ) {
 
319
  return;
320
  }
321
 
322
- // Is the user allowed to edit the post or page?
323
- if ( ! current_user_can( 'edit_post', $post->ID ) ) {
 
324
  return;
325
  }
326
 
@@ -335,11 +357,11 @@ class WPUF_Subscription {
335
  update_post_meta( $subscription_id, '_trial_duration', $post_data['trial_duration'] );
336
  update_post_meta( $subscription_id, '_trial_duration_type', $post_data['trial_duration_type'] );
337
  update_post_meta( $subscription_id, '_post_type_name', $post_data['post_type_name'] );
338
- update_post_meta( $subscription_id, '_enable_post_expiration', ( isset($post_data['post_expiration_settings']['enable_post_expiration']) ? $post_data['post_expiration_settings']['enable_post_expiration']:'' ) );
339
  update_post_meta( $subscription_id, '_post_expiration_time', $post_data['post_expiration_settings']['expiration_time_value'] . ' ' . $post_data['post_expiration_settings']['expiration_time_type'] );
340
- update_post_meta( $subscription_id, '_expired_post_status', ( isset($post_data['post_expiration_settings']['expired_post_status']) ? $post_data['post_expiration_settings']['expired_post_status']:'' ) );
341
- update_post_meta( $subscription_id, '_enable_mail_after_expired', ( isset($post_data['post_expiration_settings']['enable_mail_after_expired']) ? $post_data['post_expiration_settings']['enable_mail_after_expired']:'' ) );
342
- update_post_meta( $subscription_id, '_post_expiration_message', ( isset($post_data['post_expiration_settings']['post_expiration_message']) ? $post_data['post_expiration_settings']['post_expiration_message']:'' ) );
343
  do_action( 'wpuf_update_subscription_pack', $subscription_id, $post_data );
344
  }
345
 
@@ -348,20 +370,19 @@ class WPUF_Subscription {
348
  *
349
  * @return void
350
  */
351
- function register_post_type() {
352
-
353
  $capability = wpuf_admin_role();
354
 
355
- register_post_type( 'wpuf_subscription', array(
356
  'label' => __( 'Subscription', 'wp-user-frontend' ),
357
  'public' => false,
358
  'show_ui' => true,
359
  'show_in_menu' => false,
360
  'hierarchical' => false,
361
  'query_var' => false,
362
- 'supports' => array( 'title' ),
363
  'capability_type' => 'post',
364
- 'capabilities' => array(
365
  'publish_posts' => $capability,
366
  'edit_posts' => $capability,
367
  'edit_others_posts' => $capability,
@@ -371,8 +392,8 @@ class WPUF_Subscription {
371
  'edit_post' => $capability,
372
  'delete_post' => $capability,
373
  'read_post' => $capability,
374
- ),
375
- 'labels' => array(
376
  'name' => __( 'Subscription', 'wp-user-frontend' ),
377
  'singular_name' => __( 'Subscription', 'wp-user-frontend' ),
378
  'menu_name' => __( 'Subscription', 'wp-user-frontend' ),
@@ -387,8 +408,8 @@ class WPUF_Subscription {
387
  'not_found' => __( 'No Subscription Found', 'wp-user-frontend' ),
388
  'not_found_in_trash' => __( 'No Subscription Found in Trash', 'wp-user-frontend' ),
389
  'parent' => __( 'Parent Subscription', 'wp-user-frontend' ),
390
- ),
391
- ) );
392
  }
393
 
394
  /**
@@ -399,32 +420,39 @@ class WPUF_Subscription {
399
  *
400
  * @return void
401
  */
402
- function update_paypal_subscr_payment() {
403
- if ( !isset( $_POST['txn_type'] ) && $_POST['txn_type'] != 'subscr_payment' ) {
 
 
 
 
 
404
  return;
405
  }
406
 
407
- if ( strtolower( $_POST['payment_status'] ) != 'completed' ) {
408
  return;
409
  }
410
 
411
  $pack = $this->get_subscription( $pack_id );
412
- $payer = json_decode( stripcslashes( $_POST['custom'] ) );
413
 
414
  $this->update_user_subscription_meta( $payer->payer_id, $pack );
415
- }
416
 
417
  /**
418
  * Get a subscription row from database
419
  *
420
  * @global object $wpdb
 
421
  * @param int $sub_id subscription pack id
 
422
  * @return object|bool
423
  */
424
  public static function get_subscription( $sub_id ) {
425
  $pack = get_post( $sub_id );
426
 
427
- if ( ! $pack ) {
428
  return false;
429
  }
430
 
@@ -437,10 +465,10 @@ class WPUF_Subscription {
437
  * Set the new post status if charging is active
438
  *
439
  * @param string $postdata
 
440
  * @return string
441
  */
442
- function set_pending( $postdata, $form_id, $form_settings, $form_vars ) {
443
-
444
  $form = new WPUF_Form( $form_id );
445
  $payment_options = $form->is_charging_enabled();
446
  $force_pack = $form->is_enabled_force_pack();
@@ -450,12 +478,11 @@ class WPUF_Subscription {
450
  $current_pack = $current_user->subscription()->current_pack();
451
  $has_post = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
452
 
453
-
454
- if ( $payment_options && $force_pack && !is_wp_error( $current_pack ) && $fallback_cost && !$has_post ) {
455
  $postdata['post_status'] = 'pending';
456
  }
457
 
458
- if ( $payment_options && !$force_pack && ( $pay_per_post || ( $fallback_cost && !$has_post ))) {
459
  $postdata['post_status'] = 'pending';
460
  }
461
 
@@ -467,9 +494,10 @@ class WPUF_Subscription {
467
  *
468
  * @global object $userdata
469
  * @global object $wpdb
 
470
  * @param int $post_id
471
  */
472
- function monitor_new_post( $post_id, $form_id, $form_settings ) {
473
  global $wpdb, $userdata;
474
  $post = get_post( $post_id );
475
 
@@ -487,8 +515,7 @@ class WPUF_Subscription {
487
  $current_pack = $current_user->subscription()->current_pack();
488
  $has_post = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
489
 
490
- if ( $force_pack && ! is_wp_error( $current_pack ) && $has_post ) {
491
-
492
  $sub_info = self::get_user_pack( $userdata->ID );
493
  $post_type = isset( $form_settings['post_type'] ) ? $form_settings['post_type'] : 'post';
494
  $count = isset( $sub_info['posts'][$post_type] ) ? intval( $sub_info['posts'][$post_type] ) : 0;
@@ -509,16 +536,13 @@ class WPUF_Subscription {
509
 
510
  //meta added to make post have flag if post is published
511
  update_post_meta( $post_id, 'wpuf_post_status', 'published' );
512
-
513
-
514
- } elseif ( $pay_per_post || ($force_pack && $fallback_cost && !$has_post) ) {
515
  //there is some error and it needs payment
516
  //add a uniqid to track the post easily
517
  $order_id = uniqid( rand( 10, 1000 ), false );
518
  update_post_meta( $post_id, '_wpuf_order_id', $order_id, true );
519
  update_post_meta( $post_id, '_wpuf_payment_status', 'pending' );
520
  }
521
-
522
  }
523
 
524
  /**
@@ -526,16 +550,17 @@ class WPUF_Subscription {
526
  *
527
  * @global object $userdata
528
  * @global object $wpdb
 
529
  * @param int $post_id
530
  */
531
- function monitor_new_draft_post( $post_id, $form_id, $form_settings ) {
532
-
533
  global $wpdb, $userdata;
534
 
535
  // bail out if charging is not enabled
536
  $charging_enabled = '';
537
  $form = new WPUF_Form( $form_id );
538
  $payment_options = $form->is_charging_enabled();
 
539
  if ( !$payment_options || !is_user_logged_in() ) {
540
  $charging_enabled = 'no';
541
  } else {
@@ -550,18 +575,17 @@ class WPUF_Subscription {
550
  $order_id = uniqid( rand( 10, 1000 ), false );
551
  update_post_meta( $post_id, '_wpuf_order_id', $order_id, true );
552
  }
553
-
554
  }
555
 
556
  /**
557
  * Redirect to payment page after new post
558
  *
559
  * @param string $str
560
- * @param type $post_id
 
561
  * @return string
562
  */
563
- function post_redirect( $response, $post_id, $form_id, $form_settings ) {
564
-
565
  $form = new WPUF_Form( $form_id );
566
  $payment_options = $form->is_charging_enabled();
567
  $force_pack = $form->is_enabled_force_pack();
@@ -578,21 +602,23 @@ class WPUF_Subscription {
578
  // check if there is a order ID
579
  if ( $order_id || ( $payment_options && $fallback_cost ) ) {
580
  $response['show_message'] = false;
581
- $response['redirect_to'] = add_query_arg( array(
582
  'action' => 'wpuf_pay',
583
  'type' => 'post',
584
- 'post_id' => $post_id
585
- ), get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) ) );
586
  }
 
587
  if ( !$force_pack && $ppp_cost_enabled ) {
588
  $response['show_message'] = false;
589
- $response['redirect_to'] = add_query_arg( array(
590
  'action' => 'wpuf_pay',
591
  'type' => 'post',
592
- 'post_id' => $post_id
593
- ), get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) ) );
594
  }
595
  }
 
596
  return $response;
597
  }
598
 
@@ -601,22 +627,19 @@ class WPUF_Subscription {
601
  *
602
  * @param array $info payment info
603
  */
604
- function payment_received( $info, $recurring ) {
605
  if ( $info['post_id'] ) {
606
  $order_id = get_post_meta( $info['post_id'], '_wpuf_order_id', true );
607
 
608
  $this->handle_post_publish( $order_id );
609
-
610
- } else if ( $info['pack_id'] ) {
611
-
612
  if ( $recurring ) {
613
  $profile_id = $info['profile_id'];
614
- }else{
615
  $profile_id = isset( $info['user_id'] ) ? $info['user_id'] : null;
616
  }
617
 
618
  wpuf_get_user( $info['user_id'] )->subscription()->add_pack( $info['pack_id'], $profile_id, $recurring, $info['status'] );
619
-
620
  }
621
  }
622
 
@@ -639,7 +662,7 @@ class WPUF_Subscription {
639
  *
640
  * if data = 0, means 'unlimited'
641
  *
642
- * @param int $user_id
643
  * @param array $data
644
  */
645
  public static function update_user_subscription_meta( $user_id, $user_meta ) {
@@ -664,7 +687,7 @@ class WPUF_Subscription {
664
  *
665
  * @param int $post_id
666
  */
667
- function handle_post_publish( $order_id ) {
668
  $post = self::post_by_orderid( $order_id );
669
 
670
  if ( $post ) {
@@ -681,9 +704,10 @@ class WPUF_Subscription {
681
  * Maintain post status from the form settings
682
  *
683
  * @since 2.1.9
 
684
  * @param int $post_id
685
  */
686
- function set_post_status( $post_id ) {
687
  $post_status = 'publish';
688
  $form_id = get_post_meta( $post_id, '_wpuf_form_id', true );
689
 
@@ -692,10 +716,10 @@ class WPUF_Subscription {
692
  $post_status = $form_settings['post_status'];
693
  }
694
 
695
- $update_post = array(
696
  'ID' => $post_id,
697
- 'post_status' => $post_status
698
- );
699
 
700
  wp_update_post( $update_post );
701
  }
@@ -705,32 +729,37 @@ class WPUF_Subscription {
705
  *
706
  * @global type $userdata
707
  */
708
- function subscription_info() {
709
  // _deprecated_function( __FUNCTION__, '2.6.0', 'wpuf_get_user()->subscription()->pack_info( $form_id );' );
710
  // wpuf_get_user()->subscription()->pack_info( $form_id );
711
  $sections = wpuf_get_account_sections();
712
- do_action( "wpuf_account_content_subscription", $sections, 'subscription' );
713
  }
714
 
715
  /**
716
  * Show the subscription packs that are built
717
  * from admin Panel
718
  */
719
- function subscription_packs( $atts = null ) {
720
  //$cost_per_post = isset( $form_settings['pay_per_post_cost'] ) ? $form_settings['pay_per_post_cost'] : 0;
721
 
722
- $defaults = array(
 
 
 
 
 
723
  'include' => '',
724
  'exclude' => '',
725
  'order' => '',
726
- 'orderby' => ''
727
- );
728
 
729
- $arranged = array();
730
  $args = wp_parse_args( $atts, $defaults );
731
 
732
- if ( $args['include'] != "" ) {
733
- $pack_order = explode(',', $args['include']);
734
  } else {
735
  $args['order'] = isset( $args['order'] ) ? $args['order'] : 'ASC';
736
  }
@@ -741,16 +770,16 @@ class WPUF_Subscription {
741
 
742
  ob_start();
743
 
744
- if ( isset( $_GET['action'] ) && $_GET['action'] == 'wpuf_paypal_success' ) {
745
- printf( '<h1>%1$s</h1><p>%2$s</p>', __( 'Payment is complete', 'wp-user-frontend' ), __( 'Congratulations, your payment has been completed!', 'wp-user-frontend' ) );
746
  }
747
 
748
- if ( isset( $_GET['pack_msg'] ) && $_GET['pack_msg'] == 'buy_pack' ) {
749
- _e('Please buy a subscription pack to post', 'wp-user-frontend' );
750
  }
751
 
752
- if ( isset( $_GET['ppp_msg'] ) && $_GET['ppp_msg'] == 'pay_per_post' ) {
753
- _e('Please buy a subscription pack to post', 'wp-user-frontend' );
754
  }
755
 
756
  $current_pack = self::get_user_pack( get_current_user_id() );
@@ -760,49 +789,47 @@ class WPUF_Subscription {
760
  !empty( $current_pack['pack_id'] ) &&
761
  isset( $current_pack['status'] ) &&
762
  $current_pack['status'] == 'completed'
763
- ) {
764
  global $wpdb;
765
 
766
- $user_id = get_current_user_id();
767
  $payment_gateway = $wpdb->get_var( "SELECT payment_type FROM {$wpdb->prefix}wpuf_transaction WHERE user_id = {$user_id} AND status = 'completed' ORDER BY created DESC" );
768
 
769
- $payment_gateway = strtolower( $payment_gateway );
770
- ?>
771
 
772
- <?php _e( '<p><i>You have a subscription pack activated. </i></p>', 'wp-user-frontend' ); ?>
773
- <?php echo sprintf( __( "<p><i>Pack name: %s </i></p>", "wp-user-frontend" ), get_the_title( $current_pack['pack_id'] ) ); ?>
774
 
775
- <?php _e( '<p><i>To cancel the pack, press the following cancel button</i></p>', 'wp-user-frontend' ); ?>
776
 
777
  <form action="" id="wpuf_cancel_subscription" method="post">
778
  <?php wp_nonce_field( 'wpuf-sub-cancel' ); ?>
779
- <input type="hidden" name="user_id" value="<?php echo get_current_user_id(); ?>">
780
- <input type="hidden" name="gateway" value="<?php echo $payment_gateway; ?>">
781
  <input type="hidden" name="wpuf_cancel_subscription" value="Cancel">
782
- <input type="submit" name="wpuf_user_subscription_cancel" class="btn btn-sm btn-danger" value="<?php _e( 'Cancel', 'wp-user-frontend' ); ?>">
783
  </form>
784
  <?php
785
  }
786
 
787
- wpuf_load_template( 'subscriptions/listing.php', apply_filters( 'wpuf_subscription_listing_args', array(
788
  'subscription' => $this,
789
  'args' => $args,
790
  'packs' => $packs,
791
  'pack_order' => isset( $pack_order ) ? $pack_order : '',
792
  'details_meta' => $details_meta,
793
- 'current_pack' => $current_pack
794
- ) ) );
795
 
796
  $contents = ob_get_clean();
797
 
798
  return apply_filters( 'wpuf_subscription_packs', $contents, $packs );
799
  }
800
 
801
- function get_details_meta_value() {
802
-
803
  $meta['payment_page'] = get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
804
- $meta['onclick'] = '';
805
- $meta['symbol'] = wpuf_get_currency( 'symbol' );
806
 
807
  return $meta;
808
  }
@@ -814,13 +841,13 @@ class WPUF_Subscription {
814
  *
815
  *@return string $labels[$cycle_period]
816
  */
817
- function get_cycle_label( $cycle_period, $cycle_number ) {
818
- $labels = array(
819
  'day' => _n( 'Day', 'Days', $cycle_number, 'wp-user-frontend' ),
820
  'week' => _n( 'Week', 'Weeks', $cycle_number, 'wp-user-frontend' ),
821
  'month' => _n( 'Month', 'Months', $cycle_number, 'wp-user-frontend' ),
822
- 'year' => _n( 'Year', 'Years', $cycle_number, 'wp-user-frontend' )
823
- );
824
 
825
  return apply_filters( 'wpuf_subscription_cycle_label', $labels[$cycle_period] );
826
  }
@@ -831,10 +858,9 @@ class WPUF_Subscription {
831
  * @param $pack
832
  * @param $details_meta
833
  * @param string $current_pack_id
834
- * @param bool $coupon_status
835
  */
836
- function pack_details( $pack, $details_meta, $current_pack_id = '', $coupon_status = false ) {
837
-
838
  if ( function_exists( 'wpuf_prices_include_tax' ) ) {
839
  $price_with_tax = wpuf_prices_include_tax();
840
  }
@@ -843,7 +869,7 @@ class WPUF_Subscription {
843
 
844
  if ( $user_id != 0 ) {
845
  $user_pack_meta = '_wpuf_subscription_pack';
846
- $pack_details = get_user_meta( $user_id, $user_pack_meta, true);
847
 
848
  if ( !empty( $pack_details ) ) {
849
  $current_pack_status = isset( $pack_details['status'] ) ? $pack_details['status'] : '';
@@ -851,52 +877,52 @@ class WPUF_Subscription {
851
  }
852
 
853
  $billing_amount = ( $pack->meta_value['billing_amount'] >= 0 && !empty( $pack->meta_value['billing_amount'] ) ) ? $pack->meta_value['billing_amount'] : '0.00';
854
- $trial_des = '';
855
- $recurring_des = '<div class="wpuf-pack-cycle wpuf-nullamount-hide">' . __( 'One time payment', 'wp-user-frontend' ) . '</div>';
856
 
857
  if ( isset( $price_with_tax ) && $price_with_tax ) {
858
- $billing_amount = apply_filters( 'wpuf_payment_amount', $billing_amount);
859
  }
860
 
861
  if ( $billing_amount && $pack->meta_value['recurring_pay'] == 'yes' ) {
862
- $recurring_des = sprintf( __('Every', 'wp-user-frontend').' %s %s', $pack->meta_value['billing_cycle_number'], $this->get_cycle_label( $pack->meta_value['cycle_period'], $pack->meta_value['billing_cycle_number'] ), $pack->meta_value['trial_duration_type'] );
863
- $recurring_des .= !empty( $pack->meta_value['billing_limit'] ) ? sprintf( ', '.__('for', 'wp-user-frontend').' %s '.__( 'installments', 'wp-user-frontend' ), $pack->meta_value['billing_limit'] ) : '';
864
- $recurring_des = '<div class="wpuf-pack-cycle wpuf-nullamount-hide">'.$recurring_des.'</div>';
865
  }
866
 
867
  if ( $billing_amount && $pack->meta_value['recurring_pay'] == 'yes' && $pack->meta_value['trial_status'] == 'yes' ) {
868
- $duration = _n( $pack->meta_value['trial_duration_type'], $pack->meta_value['trial_duration_type'].'s', $pack->meta_value['trial_duration'], 'wp-user-frontend' );
869
- $trial_des = sprintf( __( 'Trial available for first %s %s','wp-user-frontend' ), $pack->meta_value['trial_duration'], $duration );
870
  }
871
 
872
- $label = wpuf_get_option( 'logged_in_label','wpuf_subscription_settings', false );
873
- $button_name = $label ? $label : __('Buy Now', 'wp-user-frontend');
874
 
875
- if ( ! is_user_logged_in() ) {
876
- $label = wpuf_get_option( 'logged_out_label','wpuf_subscription_settings', false );
877
  $button_name = $label ? $label : __( 'Sign Up', 'wp-user-frontend' );
878
- } else if ( $billing_amount == '0.00' ) {
879
- $label = wpuf_get_option( 'free_label','wpuf_subscription_settings', false );
880
  $button_name = $label ? $label : __( 'Free', 'wp-user-frontend' );
881
  }
882
 
883
- $query_args = array(
884
- 'action' => 'register',
885
- 'type' => 'wpuf_sub',
886
  'pack_id' => $pack->ID,
887
- );
888
  $query_url = wp_registration_url();
889
 
890
  if ( $coupon_status === false && is_user_logged_in() ) {
891
- $query_args = array(
892
- 'action' => 'wpuf_pay',
893
- 'type' => 'pack',
894
- 'pack_id' => $pack->ID
895
- );
896
  $query_url = $details_meta['payment_page'];
897
  }
898
 
899
- wpuf_load_template( 'subscriptions/pack-details.php', apply_filters( 'wpuf_subscription_pack_details_args', array(
900
  'pack' => $pack,
901
  'billing_amount' => $billing_amount,
902
  'details_meta' => $details_meta,
@@ -908,13 +934,13 @@ class WPUF_Subscription {
908
  'button_name' => $button_name,
909
  'query_args' => $query_args,
910
  'query_url' => $query_url,
911
- ) ) );
912
  }
913
 
914
  /**
915
  * Show a info message when posting if payment is enabled
916
  */
917
- function add_post_info( $form_id, $form_settings ) {
918
  $form = new WPUF_Form( $form_id );
919
  $pay_per_post = $form->is_enabled_pay_per_post();
920
  $pay_per_post_cost = (float) $form->get_pay_per_post_cost();
@@ -938,27 +964,25 @@ class WPUF_Subscription {
938
  $pay_per_post_cost = apply_filters( 'wpuf_payment_amount', $pay_per_post_cost );
939
  }
940
 
941
- $text = sprintf( __( 'There is a <strong>%s</strong> charge to add a new post.', 'wp-user-frontend' ), wpuf_format_price( $pay_per_post_cost ));
942
 
943
- echo apply_filters( 'wpuf_ppp_notice', $text, $form_id, $form_settings );
944
- ?>
945
  </div>
946
  <?php
947
- } elseif ( self::has_user_error( $form_settings ) || ( $payment_enabled && $force_pack && !is_wp_error( $current_pack ) && !$current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) ) {
948
  ?>
949
  <div class="wpuf-info">
950
  <?php
951
- $form = new WPUF_Form( $form_id );
952
- $fallback_cost = (int )$form->get_subs_fallback_cost();
953
 
954
  if ( isset( $price_with_tax ) && $price_with_tax ) {
955
- $fallback_cost = apply_filters( 'wpuf_payment_amount', $fallback_cost );
956
  }
957
 
958
- $text = sprintf( __( 'Your Subscription pack exhausted. There is a <strong>%s</strong> charge to add a new post.', 'wp-user-frontend' ), wpuf_format_price( $fallback_cost ));
959
 
960
- echo apply_filters( 'wpuf_ppp_notice', $text, $form_id, $form_settings );
961
- ?>
962
  </div>
963
  <?php
964
  }
@@ -980,24 +1004,25 @@ class WPUF_Subscription {
980
  return $rows;
981
  }
982
 
983
- $results = array();
984
- foreach ( $rows as $row) {
 
985
  if ( !in_array( $row->user_id, $results ) ) {
986
  $results[] = $row->user_id;
987
  }
988
  }
989
 
990
- $users = get_users( array( 'include' => $results ) );
 
991
  return $users;
992
  }
993
 
994
- function force_pack_notice( $text, $id, $form_settings ) {
995
-
996
  $form = new WPUF_Form( $id );
997
 
998
  $force_pack = $form->is_enabled_force_pack();
999
 
1000
- if ( $force_pack && self::has_user_error($form_settings) ) {
1001
  $pack_page = get_permalink( wpuf_get_option( 'subscription_page', 'wpuf_payment' ) );
1002
 
1003
  $text = sprintf( __( 'You must <a href="%s">purchase a pack</a> before posting', 'wp-user-frontend' ), $pack_page );
@@ -1006,20 +1031,18 @@ class WPUF_Subscription {
1006
  return apply_filters( 'wpuf_pack_notice', $text, $id, $form_settings );
1007
  }
1008
 
1009
- function force_pack_permission( $perm, $id, $form_settings ) {
1010
-
1011
- $form = new WPUF_Form( $id );
1012
- $force_pack = $form->is_enabled_force_pack();
1013
- $pay_per_post = $form->is_enabled_pay_per_post();
1014
  $fallback_enabled = $form->is_enabled_fallback_cost();
1015
  $fallback_cost = $form->get_subs_fallback_cost();
1016
 
1017
- $current_user = wpuf_get_user();
1018
- $current_pack = $current_user->subscription()->current_pack();
1019
  $has_post_count = isset( $form_settings['post_type'] ) ? $current_user->subscription()->has_post_count( $form_settings['post_type'] ) : false;
1020
 
1021
  if ( is_user_logged_in() ) {
1022
-
1023
  if ( wpuf_get_user()->post_locked() ) {
1024
  return 'no';
1025
  } else {
@@ -1030,9 +1053,9 @@ class WPUF_Subscription {
1030
  } else {
1031
  //if charging is enabled
1032
  if ( $force_pack ) {
1033
- if ( ! is_wp_error( $current_pack ) ) {
1034
  // current pack has no error
1035
- if ( ! $fallback_enabled ) {
1036
  //fallback cost enabled
1037
  if ( !$current_user->subscription()->current_pack_id() ) {
1038
  return 'no';
@@ -1053,12 +1076,12 @@ class WPUF_Subscription {
1053
  return 'no';
1054
  }
1055
  }
 
1056
  if ( !$force_pack && $pay_per_post ) {
1057
  return 'yes';
1058
  }
1059
  }
1060
  }
1061
-
1062
  }
1063
 
1064
  if ( !is_user_logged_in() && isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' ) {
@@ -1066,25 +1089,25 @@ class WPUF_Subscription {
1066
  if ( $force_pack ) {
1067
  return 'no';
1068
  }
 
1069
  if ( !$force_pack && $pay_per_post ) {
1070
  return 'yes';
1071
  } elseif ( !$force_pack && !$pay_per_post ) {
1072
  return 'no';
1073
  }
1074
- }
1075
- else {
1076
  return 'yes';
1077
  }
1078
  }
1079
 
1080
  return $perm;
1081
-
1082
  }
1083
 
1084
  /**
1085
  * Checks against the user, if he is valid for posting new post
1086
  *
1087
  * @global object $userdata
 
1088
  * @return bool
1089
  */
1090
  public static function has_user_error( $form_settings = null ) {
@@ -1101,7 +1124,8 @@ class WPUF_Subscription {
1101
  *
1102
  * @param int $user_id
1103
  * @param int $pack_id
1104
- * @return boolean
 
1105
  */
1106
  public static function has_used_free_pack( $user_id, $pack_id ) {
1107
  // _deprecated_function( __FUNCTION__, '2.6.0', 'wpuf_get_user( $user_id )->subscription()->used_free_pack( $pack_id );' );
@@ -1123,16 +1147,16 @@ class WPUF_Subscription {
1123
  wpuf_get_user( $user_id )->subscription()->add_free_pack( $user_id, $pack_id );
1124
  }
1125
 
1126
- function packdropdown( $packs, $selected = '' ) {
1127
- $packs = isset( $packs ) ? $packs : array();
1128
- foreach( $packs as $key => $pack ) {
 
1129
  ?>
1130
- <option value="<?php echo $pack->ID; ?>" <?php selected( $selected, $pack->ID ); ?>><?php echo $pack->post_title; ?></option>
1131
  <?php
1132
  }
1133
  }
1134
 
1135
-
1136
  /**
1137
  * Reset the post count of a subscription of a user
1138
  *
@@ -1147,7 +1171,6 @@ class WPUF_Subscription {
1147
  // _deprecated_function( __FUNCTION__, '2.6.0', 'wpuf_get_user()->subscription()->reset_subscription_data( $post_id, $form_id, $form_settings, $form_vars );' );
1148
 
1149
  wpuf_get_user()->subscription()->reset_subscription_data( $post_id, $form_id, $form_settings, $form_vars );
1150
-
1151
  }
1152
 
1153
  /**
@@ -1156,11 +1179,11 @@ class WPUF_Subscription {
1156
  * @since 2.5.9
1157
  *
1158
  * @param $post_id
 
1159
  * @return string
1160
  */
1161
-
1162
  public function get_payment_status( $post_id ) {
1163
- return get_post_meta( $post_id, '_wpuf_payment_status', true);
1164
  }
1165
 
1166
  /**
@@ -1169,20 +1192,19 @@ class WPUF_Subscription {
1169
  * @since 2.8.8
1170
  *
1171
  * @param $post_id
 
1172
  * @return void
1173
  */
1174
-
1175
  public function insert_free_pack_subscribers( $pack_id, $userdata ) {
1176
  global $wpdb;
1177
 
1178
  $subscription = wpuf()->subscription->get_subscription( $pack_id );
1179
- if ( $userdata->id && $subscription ) {
1180
 
1181
- $user_sub = WPUF_Subscription::get_user_pack( $userdata->id );
 
1182
  $post_expiration_time = wpuf_date2mysql( $user_sub['expire'] );
1183
 
1184
-
1185
- $table_data = array(
1186
  'user_id' => $userdata->id,
1187
  'name' => $userdata->user->data->display_name,
1188
  'subscribtion_id' => $pack_id,
@@ -1191,10 +1213,9 @@ class WPUF_Subscription {
1191
  'transaction_id' => 'free',
1192
  'starts_from' => date( 'd-m-Y' ),
1193
  'expire' => empty( $post_expiration_time ) ? 'recurring' : $post_expiration_time,
1194
- );
1195
 
1196
  $wpdb->insert( $wpdb->prefix . 'wpuf_subscribers', $table_data );
1197
  }
1198
  }
1199
-
1200
  }
4
  * WPUF subscription manager
5
  *
6
  * @since 0.2
7
+ *
8
  * @author Tareq Hasan
 
9
  */
10
  class WPUF_Subscription {
11
 
12
  private static $_instance;
13
 
14
+ public function __construct() {
15
+ add_action( 'init', [$this, 'register_post_type'] );
16
+ add_filter( 'wpuf_add_post_args', [$this, 'set_pending'], 10, 4 );
17
+ add_filter( 'wpuf_add_post_redirect', [$this, 'post_redirect'], 10, 4 );
 
18
 
19
+ add_filter( 'wpuf_addpost_notice', [$this, 'force_pack_notice'], 20, 3 );
20
+ add_filter( 'wpuf_can_post', [$this, 'force_pack_permission'], 20, 3 );
21
+ add_action( 'wpuf_add_post_form_top', [$this, 'add_post_info'], 10, 2 );
22
 
23
+ add_action( 'wpuf_add_post_after_insert', [$this, 'monitor_new_post'], 10, 3 );
24
+ add_action( 'wpuf_draft_post_after_insert', [$this, 'monitor_new_draft_post'], 10, 3 );
25
+ add_action( 'wpuf_payment_received', [$this, 'payment_received'], 10, 2 );
26
 
27
+ add_shortcode( 'wpuf_sub_info', [$this, 'subscription_info'] );
28
+ add_shortcode( 'wpuf_sub_pack', [$this, 'subscription_packs'] );
29
 
30
+ add_action( 'save_post', [ $this, 'save_form_meta' ], 10, 2 );
31
+ add_filter( 'enter_title_here', [ $this, 'change_default_title' ] );
32
+ add_action( 'admin_enqueue_scripts', [ $this, 'subscription_script' ] );
33
 
34
+ add_action( 'user_register', [ $this, 'after_registration' ], 10, 1 );
35
 
36
+ add_action( 'register_form', [ $this, 'register_form'] );
37
+ add_action( 'wpuf_add_post_form_top', [ $this, 'register_form'] );
38
+ add_filter( 'wpuf_user_register_redirect', [ $this, 'subs_redirect_pram' ], 10, 5 );
39
 
40
+ add_filter( 'template_redirect', [ $this, 'user_subscription_cancel' ] );
 
 
41
 
42
+ add_action( 'wpuf_draft_post_after_insert', [ $this, 'reset_user_subscription_data' ], 10, 4 );
43
  }
44
 
45
  /**
50
  public static function subscriber_cancel( $user_id, $pack_id ) {
51
  global $wpdb;
52
 
53
+ $sql = $wpdb->prepare( 'SELECT transaction_id FROM ' . $wpdb->prefix . 'wpuf_transaction
54
+ WHERE user_id = %d AND pack_id = %d LIMIT 1', $user_id, $pack_id );
55
  $result = $wpdb->get_row( $sql );
56
 
57
  $transaction_id = $result ? $result->transaction_id : 0;
58
 
59
+ $wpdb->update( $wpdb->prefix . 'wpuf_subscribers', [ 'subscribtion_status' => 'cancel' ], [ 'user_id' => $user_id, 'subscribtion_id' => $pack_id, 'transaction_id' => $transaction_id ] );
60
  }
61
 
62
  /**
66
  */
67
  public function user_subscription_cancel() {
68
  if ( isset( $_POST['wpuf_cancel_subscription'] ) ) {
69
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
70
+ $user_id = isset( $_POST['user_id'] ) ? intval( wp_unslash( $_POST['user_id'] ) ) : 0;
71
+ $gateway = isset( $_POST['gateway'] ) ? intval( wp_unslash( $_POST['gateway'] ) ) : 0;
72
+ $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
73
+
74
 
75
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf-sub-cancel' ) ) {
76
+ return ;
77
  }
78
 
79
+ $current_pack = self::get_user_pack( $user_id );
80
 
81
+ $gateway = ( $gateway == 'bank/manual' ) ? 'bank' : $gateway;
82
 
83
  if ( 'bank' == $gateway || 'no' == $current_pack['recurring'] ) {
84
+ $this->update_user_subscription_meta( $user_id, 'Cancel' );
85
  } else {
86
  do_action( "wpuf_cancel_subscription_{$gateway}", $_POST );
87
  }
88
 
89
+ $this::subscriber_cancel( $user_id, $current_pack['pack_id'] );
 
 
90
 
91
+ wp_redirect( $request_uri );
92
  }
93
  }
94
 
 
95
  public static function init() {
96
  if ( !self::$_instance ) {
97
+ self::$_instance = new self();
98
  }
99
 
100
  return self::$_instance;
105
  *
106
  * @since 2.2
107
  *
108
+ * @param array $response
109
+ * @param int $user_id
110
+ * @param array $userdata
111
+ * @param int $form_id
112
+ * @param array $form_settings
113
+ *
114
  * @return array
115
  */
116
+ public function subs_redirect_pram( $response, $user_id, $userdata, $form_id, $form_settings ) {
117
+ if ( ! isset( $_POST['_wpnonce'] ) || ! isset( $_POST['action'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'wpuf_form_add' ) ) {
 
 
118
 
119
+ }
 
 
120
 
121
+ $wpuf_sub = isset( $_POST['wpuf_sub'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_sub'] ) ) : '';
122
+ $pack_id = isset( $_POST['pack_id'] ) ? sanitize_text_field( wp_unslash( $_POST['pack_id'] ) ) : '';
123
 
 
 
 
124
 
125
+ if ( $wpuf_sub != 'yes' ) {
126
+ return $response;
127
+ }
128
 
129
+ if ( empty( $pack_id ) ) {
130
+ return $response;
131
+ }
132
+
133
+ $pack = $this->get_subscription( $pack_id );
134
+ $billing_amount = ( $pack->meta_value['billing_amount'] >= 0 && !empty( $pack->meta_value['billing_amount'] ) ) ? $pack->meta_value['billing_amount'] : false;
135
+
136
+ if ( $billing_amount !== false ) {
137
+ $pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
138
+ $redirect = add_query_arg( ['action' => 'wpuf_pay', 'user_id' => $user_id, 'type' => 'pack', 'pack_id' => (int) $pack_id, get_permalink( $pay_page ) ]);
139
+
140
+ $response['redirect_to'] = $redirect;
141
+ $response['show_message'] = false;
142
+ }
143
+
144
+ return $response;
145
+ }
146
 
147
  /**
148
  * Insert hidden field on the register form based on selected package
151
  *
152
  * @return void
153
  */
154
+ public function register_form() {
155
+ $type = isset( $_GET['type'] ) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : '';
156
+ $pack_id = isset( $_GET['pack_id'] ) ? intval( wp_unslash( $_GET['pack_id'] ) ) : 0;
157
+
158
+ if ( $type != 'wpuf_sub' ) {
159
  return;
160
  }
161
 
162
+ if ( empty( $pack_id ) ) {
163
  return;
164
  }
 
 
165
  ?>
166
  <input type="hidden" name="wpuf_sub" value="yes" />
167
+ <input type="hidden" name="pack_id" value="<?php echo esc_attr( $pack_id ); ?>" />
168
 
169
  <?php
170
  }
174
  *
175
  * @since 2.2
176
  *
177
+ * @param int $user_id
178
+ *
179
  * @return void
180
  */
181
+ public function after_registration( $user_id ) {
182
+ if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( '_wpnonce' ) ) {
183
+
184
+ }
185
+
186
+ $wpuf_sub = isset( $_POST['wpuf_sub'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_sub'] ) ) : '';
187
+ $pack_id = isset( $_POST['pack_id'] ) ? intval( wp_unslash( $_POST['pack_id'] ) ) : 0;
188
 
189
+
190
+ if ( $wpuf_sub != 'yes' ) {
191
  return $user_id;
192
  }
193
 
194
+ if ( empty( $pack_id ) ) {
195
  return $user_id;
196
  }
197
 
 
198
  $pack = $this->get_subscription( $pack_id );
199
  $billing_amount = ( $pack->meta_value['billing_amount'] >= 0 && !empty( $pack->meta_value['billing_amount'] ) ) ? $pack->meta_value['billing_amount'] : false;
200
 
203
  wpuf_get_user( $user_id )->subscription()->add_free_pack( $user_id, $pack_id );
204
  } else {
205
  $pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
206
+ $redirect = add_query_arg( [ 'action' => 'wpuf_pay', 'type' => 'pack', 'pack_id' => (int) $pack_id ], get_permalink( $pay_page ) );
207
  }
208
  }
209
 
212
  *
213
  * @since 2.2
214
  */
215
+ public function subscription_script() {
216
+ wp_enqueue_script( 'wpuf-subscriptions', WPUF_ASSET_URI . '/js/subscriptions.js', ['jquery'], false, true );
217
  }
218
 
219
  /**
221
  *
222
  * @return array
223
  */
224
+ public function get_subscriptions( $args = [] ) {
225
+ $defaults = [
226
  'post_type' => 'wpuf_subscription',
227
  'posts_per_page' => -1,
228
  'post_status' => 'publish',
229
+ ];
230
 
231
+ $args = wp_parse_args( $args, $defaults );
 
 
232
  $posts = get_posts( $args );
233
 
234
  if ( $posts ) {
235
+ foreach ( $posts as $key => $post ) {
236
  $post->meta_value = $this->get_subscription_meta( $post->ID, $posts );
237
  }
238
  }
245
  *
246
  * @since 2.2
247
  *
248
+ * @param int $subscription_id
249
+ * @param \WP_Post $pack_post
250
+ *
251
  * @return array
252
  */
253
+ public static function get_subscription_meta( $subscription_id, $pack_post = null ) {
 
254
  $meta['post_content'] = isset( $pack_post->post_content ) ? $pack_post->post_content : '';
255
  $meta['post_title'] = isset( $pack_post->post_title ) ? $pack_post->post_title : '';
256
  $meta['billing_amount'] = get_post_meta( $subscription_id, '_billing_amount', true );
279
  * Get all post types
280
  *
281
  * @since 2.2
282
+ *
283
  * @return array
284
  */
285
+ public function get_all_post_type() {
286
  $post_types = get_post_types();
287
 
288
  unset(
297
  $post_types['custom_css'],
298
  $post_types['customize_changeset'],
299
  $post_types['oembed_cache']
300
+ );
301
 
302
  return apply_filters( 'wpuf_posts_type', $post_types );
303
  }
305
  /**
306
  * Post type name placeholder text
307
  *
308
+ * @param string $title
309
+ *
310
  * @return string
311
  */
312
+ public function change_default_title( $title ) {
313
  $screen = get_current_screen();
314
 
315
  if ( 'wpuf_subscription' == $screen->post_type ) {
322
  /**
323
  * Save form data
324
  *
325
+ * @param int $post_ID
326
+ * @param \WP_Post $post
327
+ *
328
  * @return void
329
  */
330
+ public function save_form_meta( $subscription_id, $post ) {
331
 
332
+ $nonce = isset( $_POST['meta_box_nonce'] ) ? sanitize_key( wp_unslash( $_POST['meta_box_nonce'] ) ) : '';
333
 
334
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'subs_meta_box_nonce' ) ) {
335
  return;
336
  }
337
 
338
+ // Is the user allowed to edit the post or page?
339
+ if ( !current_user_can( 'edit_post', $post->ID ) ) {
340
  return;
341
  }
342
 
343
+ $post_data = wp_unslash( $_POST );
344
+
345
+ if ( !isset( $post_data['billing_amount'] ) ) {
346
  return;
347
  }
348
 
357
  update_post_meta( $subscription_id, '_trial_duration', $post_data['trial_duration'] );
358
  update_post_meta( $subscription_id, '_trial_duration_type', $post_data['trial_duration_type'] );
359
  update_post_meta( $subscription_id, '_post_type_name', $post_data['post_type_name'] );
360
+ update_post_meta( $subscription_id, '_enable_post_expiration', ( isset( $post_data['post_expiration_settings']['enable_post_expiration'] ) ? $post_data['post_expiration_settings']['enable_post_expiration'] : '' ) );
361
  update_post_meta( $subscription_id, '_post_expiration_time', $post_data['post_expiration_settings']['expiration_time_value'] . ' ' . $post_data['post_expiration_settings']['expiration_time_type'] );
362
+ update_post_meta( $subscription_id, '_expired_post_status', ( isset( $post_data['post_expiration_settings']['expired_post_status'] ) ? $post_data['post_expiration_settings']['expired_post_status'] : '' ) );
363
+ update_post_meta( $subscription_id, '_enable_mail_after_expired', ( isset( $post_data['post_expiration_settings']['enable_mail_after_expired'] ) ? $post_data['post_expiration_settings']['enable_mail_after_expired'] : '' ) );
364
+ update_post_meta( $subscription_id, '_post_expiration_message', ( isset( $post_data['post_expiration_settings']['post_expiration_message'] ) ? $post_data['post_expiration_settings']['post_expiration_message'] : '' ) );
365
  do_action( 'wpuf_update_subscription_pack', $subscription_id, $post_data );
366
  }
367
 
370
  *
371
  * @return void
372
  */
373
+ public function register_post_type() {
 
374
  $capability = wpuf_admin_role();
375
 
376
+ register_post_type( 'wpuf_subscription', [
377
  'label' => __( 'Subscription', 'wp-user-frontend' ),
378
  'public' => false,
379
  'show_ui' => true,
380
  'show_in_menu' => false,
381
  'hierarchical' => false,
382
  'query_var' => false,
383
+ 'supports' => [ 'title' ],
384
  'capability_type' => 'post',
385
+ 'capabilities' => [
386
  'publish_posts' => $capability,
387
  'edit_posts' => $capability,
388
  'edit_others_posts' => $capability,
392
  'edit_post' => $capability,
393
  'delete_post' => $capability,
394
  'read_post' => $capability,
395
+ ],
396
+ 'labels' => [
397
  'name' => __( 'Subscription', 'wp-user-frontend' ),
398
  'singular_name' => __( 'Subscription', 'wp-user-frontend' ),
399
  'menu_name' => __( 'Subscription', 'wp-user-frontend' ),
408
  'not_found' => __( 'No Subscription Found', 'wp-user-frontend' ),
409
  'not_found_in_trash' => __( 'No Subscription Found in Trash', 'wp-user-frontend' ),
410
  'parent' => __( 'Parent Subscription', 'wp-user-frontend' ),
411
+ ],
412
+ ] );
413
  }
414
 
415
  /**
420
  *
421
  * @return void
422
  */
423
+ /*public function update_paypal_subscr_payment() {
424
+ $txn_type = isset( $_POST['txn_type'] ) ? sanitize_text_field( wp_unslash( $_POST['txn_type'] ) ) : '';
425
+ $payment_status = isset( $_POST['payment_status'] ) ? sanitize_text_field( wp_unslash( $_POST['payment_status'] ) ) : '';
426
+
427
+ $custom = isset( $_POST['custom'] ) ? sanitize_text_field( wp_unslash( $_POST['custom'] ) ) : '';
428
+
429
+ if ( $txn_type != 'subscr_payment' ) {
430
  return;
431
  }
432
 
433
+ if ( strtolower( $payment_status ) != 'completed' ) {
434
  return;
435
  }
436
 
437
  $pack = $this->get_subscription( $pack_id );
438
+ $payer = json_decode( stripcslashes( $custom ) );
439
 
440
  $this->update_user_subscription_meta( $payer->payer_id, $pack );
441
+ } */
442
 
443
  /**
444
  * Get a subscription row from database
445
  *
446
  * @global object $wpdb
447
+ *
448
  * @param int $sub_id subscription pack id
449
+ *
450
  * @return object|bool
451
  */
452
  public static function get_subscription( $sub_id ) {
453
  $pack = get_post( $sub_id );
454
 
455
+ if ( !$pack ) {
456
  return false;
457
  }
458
 
465
  * Set the new post status if charging is active
466
  *
467
  * @param string $postdata
468
+ *
469
  * @return string
470
  */
471
+ public function set_pending( $postdata, $form_id, $form_settings, $form_vars ) {
 
472
  $form = new WPUF_Form( $form_id );
473
  $payment_options = $form->is_charging_enabled();
474
  $force_pack = $form->is_enabled_force_pack();
478
  $current_pack = $current_user->subscription()->current_pack();
479
  $has_post = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
480
 
481
+ if ( $payment_options && $force_pack && !is_wp_error( $current_pack ) && $fallback_cost && !$has_post ) {
 
482
  $postdata['post_status'] = 'pending';
483
  }
484
 
485
+ if ( $payment_options && !$force_pack && ( $pay_per_post || ( $fallback_cost && !$has_post ) ) ) {
486
  $postdata['post_status'] = 'pending';
487
  }
488
 
494
  *
495
  * @global object $userdata
496
  * @global object $wpdb
497
+ *
498
  * @param int $post_id
499
  */
500
+ public function monitor_new_post( $post_id, $form_id, $form_settings ) {
501
  global $wpdb, $userdata;
502
  $post = get_post( $post_id );
503
 
515
  $current_pack = $current_user->subscription()->current_pack();
516
  $has_post = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
517
 
518
+ if ( $force_pack && !is_wp_error( $current_pack ) && $has_post ) {
 
519
  $sub_info = self::get_user_pack( $userdata->ID );
520
  $post_type = isset( $form_settings['post_type'] ) ? $form_settings['post_type'] : 'post';
521
  $count = isset( $sub_info['posts'][$post_type] ) ? intval( $sub_info['posts'][$post_type] ) : 0;
536
 
537
  //meta added to make post have flag if post is published
538
  update_post_meta( $post_id, 'wpuf_post_status', 'published' );
539
+ } elseif ( $pay_per_post || ( $force_pack && $fallback_cost && !$has_post ) ) {
 
 
540
  //there is some error and it needs payment
541
  //add a uniqid to track the post easily
542
  $order_id = uniqid( rand( 10, 1000 ), false );
543
  update_post_meta( $post_id, '_wpuf_order_id', $order_id, true );
544
  update_post_meta( $post_id, '_wpuf_payment_status', 'pending' );
545
  }
 
546
  }
547
 
548
  /**
550
  *
551
  * @global object $userdata
552
  * @global object $wpdb
553
+ *
554
  * @param int $post_id
555
  */
556
+ public function monitor_new_draft_post( $post_id, $form_id, $form_settings ) {
 
557
  global $wpdb, $userdata;
558
 
559
  // bail out if charging is not enabled
560
  $charging_enabled = '';
561
  $form = new WPUF_Form( $form_id );
562
  $payment_options = $form->is_charging_enabled();
563
+
564
  if ( !$payment_options || !is_user_logged_in() ) {
565
  $charging_enabled = 'no';
566
  } else {
575
  $order_id = uniqid( rand( 10, 1000 ), false );
576
  update_post_meta( $post_id, '_wpuf_order_id', $order_id, true );
577
  }
 
578
  }
579
 
580
  /**
581
  * Redirect to payment page after new post
582
  *
583
  * @param string $str
584
+ * @param type $post_id
585
+ *
586
  * @return string
587
  */
588
+ public function post_redirect( $response, $post_id, $form_id, $form_settings ) {
 
589
  $form = new WPUF_Form( $form_id );
590
  $payment_options = $form->is_charging_enabled();
591
  $force_pack = $form->is_enabled_force_pack();
602
  // check if there is a order ID
603
  if ( $order_id || ( $payment_options && $fallback_cost ) ) {
604
  $response['show_message'] = false;
605
+ $response['redirect_to'] = add_query_arg( [
606
  'action' => 'wpuf_pay',
607
  'type' => 'post',
608
+ 'post_id' => $post_id,
609
+ ], get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) ) );
610
  }
611
+
612
  if ( !$force_pack && $ppp_cost_enabled ) {
613
  $response['show_message'] = false;
614
+ $response['redirect_to'] = add_query_arg( [
615
  'action' => 'wpuf_pay',
616
  'type' => 'post',
617
+ 'post_id' => $post_id,
618
+ ], get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) ) );
619
  }
620
  }
621
+
622
  return $response;
623
  }
624
 
627
  *
628
  * @param array $info payment info
629
  */
630
+ public function payment_received( $info, $recurring ) {
631
  if ( $info['post_id'] ) {
632
  $order_id = get_post_meta( $info['post_id'], '_wpuf_order_id', true );
633
 
634
  $this->handle_post_publish( $order_id );
635
+ } elseif ( $info['pack_id'] ) {
 
 
636
  if ( $recurring ) {
637
  $profile_id = $info['profile_id'];
638
+ } else {
639
  $profile_id = isset( $info['user_id'] ) ? $info['user_id'] : null;
640
  }
641
 
642
  wpuf_get_user( $info['user_id'] )->subscription()->add_pack( $info['pack_id'], $profile_id, $recurring, $info['status'] );
 
643
  }
644
  }
645
 
662
  *
663
  * if data = 0, means 'unlimited'
664
  *
665
+ * @param int $user_id
666
  * @param array $data
667
  */
668
  public static function update_user_subscription_meta( $user_id, $user_meta ) {
687
  *
688
  * @param int $post_id
689
  */
690
+ public function handle_post_publish( $order_id ) {
691
  $post = self::post_by_orderid( $order_id );
692
 
693
  if ( $post ) {
704
  * Maintain post status from the form settings
705
  *
706
  * @since 2.1.9
707
+ *
708
  * @param int $post_id
709
  */
710
+ public function set_post_status( $post_id ) {
711
  $post_status = 'publish';
712
  $form_id = get_post_meta( $post_id, '_wpuf_form_id', true );
713
 
716
  $post_status = $form_settings['post_status'];
717
  }
718
 
719
+ $update_post = [
720
  'ID' => $post_id,
721
+ 'post_status' => $post_status,
722
+ ];
723
 
724
  wp_update_post( $update_post );
725
  }
729
  *
730
  * @global type $userdata
731
  */
732
+ public function subscription_info() {
733
  // _deprecated_function( __FUNCTION__, '2.6.0', 'wpuf_get_user()->subscription()->pack_info( $form_id );' );
734
  // wpuf_get_user()->subscription()->pack_info( $form_id );
735
  $sections = wpuf_get_account_sections();
736
+ do_action( 'wpuf_account_content_subscription', $sections, 'subscription' );
737
  }
738
 
739
  /**
740
  * Show the subscription packs that are built
741
  * from admin Panel
742
  */
743
+ public function subscription_packs( $atts = null ) {
744
  //$cost_per_post = isset( $form_settings['pay_per_post_cost'] ) ? $form_settings['pay_per_post_cost'] : 0;
745
 
746
+ $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
747
+ $pack_msg = isset( $_GET['pack_msg'] ) ? sanitize_text_field( wp_unslash( $_GET['pack_msg'] ) ) : '';
748
+ $ppp_msg = isset( $_GET['ppp_msg'] ) ? sanitize_text_field( wp_unslash( $_GET['ppp_msg'] ) ) : '';
749
+
750
+
751
+ $defaults = [
752
  'include' => '',
753
  'exclude' => '',
754
  'order' => '',
755
+ 'orderby' => '',
756
+ ];
757
 
758
+ $arranged = [];
759
  $args = wp_parse_args( $atts, $defaults );
760
 
761
+ if ( $args['include'] != '' ) {
762
+ $pack_order = explode( ',', $args['include'] );
763
  } else {
764
  $args['order'] = isset( $args['order'] ) ? $args['order'] : 'ASC';
765
  }
770
 
771
  ob_start();
772
 
773
+ if ( $action == 'wpuf_paypal_success' ) {
774
+ printf( '<h1>%1$s</h1><p>%2$s</p>', esc_html( __( 'Payment is complete', 'wp-user-frontend' ) ), esc_html( __( 'Congratulations, your payment has been completed!', 'wp-user-frontend' ) ) );
775
  }
776
 
777
+ if ( $pack_msg == 'buy_pack' ) {
778
+ esc_html_e( 'Please buy a subscription pack to post', 'wp-user-frontend' );
779
  }
780
 
781
+ if ( $ppp_msg == 'pay_per_post' ) {
782
+ esc_html_e( 'Please buy a subscription pack to post', 'wp-user-frontend' );
783
  }
784
 
785
  $current_pack = self::get_user_pack( get_current_user_id() );
789
  !empty( $current_pack['pack_id'] ) &&
790
  isset( $current_pack['status'] ) &&
791
  $current_pack['status'] == 'completed'
792
+ ) {
793
  global $wpdb;
794
 
795
+ $user_id = get_current_user_id();
796
  $payment_gateway = $wpdb->get_var( "SELECT payment_type FROM {$wpdb->prefix}wpuf_transaction WHERE user_id = {$user_id} AND status = 'completed' ORDER BY created DESC" );
797
 
798
+ $payment_gateway = strtolower( $payment_gateway ); ?>
 
799
 
800
+ <?php echo wp_kses_post( __('<p><i>You have a subscription pack activated. </i></p>', 'wp-user-frontend' ) ); ?>
801
+ <?php echo sprintf( wp_kses_post( __( '<p><i>Pack name: %s </i></p>', 'wp-user-frontend' ) ), esc_html( get_the_title( $current_pack['pack_id'] ) ) ); ?>
802
 
803
+ <?php wp_kses_post('<p><i>' . __( 'To cancel the pack, press the following cancel button', 'wp-user-frontend' ) . '</i></p>', 'wp-user-frontend' ); ?>
804
 
805
  <form action="" id="wpuf_cancel_subscription" method="post">
806
  <?php wp_nonce_field( 'wpuf-sub-cancel' ); ?>
807
+ <input type="hidden" name="user_id" value="<?php echo esc_attr( get_current_user_id() ); ?>">
808
+ <input type="hidden" name="gateway" value="<?php echo esc_attr( $payment_gateway ); ?>">
809
  <input type="hidden" name="wpuf_cancel_subscription" value="Cancel">
810
+ <input type="submit" name="wpuf_user_subscription_cancel" class="btn btn-sm btn-danger" value="<?php esc_html_e( 'Cancel', 'wp-user-frontend' ); ?>">
811
  </form>
812
  <?php
813
  }
814
 
815
+ wpuf_load_template( 'subscriptions/listing.php', apply_filters( 'wpuf_subscription_listing_args', [
816
  'subscription' => $this,
817
  'args' => $args,
818
  'packs' => $packs,
819
  'pack_order' => isset( $pack_order ) ? $pack_order : '',
820
  'details_meta' => $details_meta,
821
+ 'current_pack' => $current_pack,
822
+ ] ) );
823
 
824
  $contents = ob_get_clean();
825
 
826
  return apply_filters( 'wpuf_subscription_packs', $contents, $packs );
827
  }
828
 
829
+ public function get_details_meta_value() {
 
830
  $meta['payment_page'] = get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
831
+ $meta['onclick'] = '';
832
+ $meta['symbol'] = wpuf_get_currency( 'symbol' );
833
 
834
  return $meta;
835
  }
841
  *
842
  *@return string $labels[$cycle_period]
843
  */
844
+ public function get_cycle_label( $cycle_period, $cycle_number ) {
845
+ $labels = [
846
  'day' => _n( 'Day', 'Days', $cycle_number, 'wp-user-frontend' ),
847
  'week' => _n( 'Week', 'Weeks', $cycle_number, 'wp-user-frontend' ),
848
  'month' => _n( 'Month', 'Months', $cycle_number, 'wp-user-frontend' ),
849
+ 'year' => _n( 'Year', 'Years', $cycle_number, 'wp-user-frontend' ),
850
+ ];
851
 
852
  return apply_filters( 'wpuf_subscription_cycle_label', $labels[$cycle_period] );
853
  }
858
  * @param $pack
859
  * @param $details_meta
860
  * @param string $current_pack_id
861
+ * @param bool $coupon_status
862
  */
863
+ public function pack_details( $pack, $details_meta, $current_pack_id = '', $coupon_status = false ) {
 
864
  if ( function_exists( 'wpuf_prices_include_tax' ) ) {
865
  $price_with_tax = wpuf_prices_include_tax();
866
  }
869
 
870
  if ( $user_id != 0 ) {
871
  $user_pack_meta = '_wpuf_subscription_pack';
872
+ $pack_details = get_user_meta( $user_id, $user_pack_meta, true );
873
 
874
  if ( !empty( $pack_details ) ) {
875
  $current_pack_status = isset( $pack_details['status'] ) ? $pack_details['status'] : '';
877
  }
878
 
879
  $billing_amount = ( $pack->meta_value['billing_amount'] >= 0 && !empty( $pack->meta_value['billing_amount'] ) ) ? $pack->meta_value['billing_amount'] : '0.00';
880
+ $trial_des = '';
881
+ $recurring_des = '<div class="wpuf-pack-cycle wpuf-nullamount-hide">' . __( 'One time payment', 'wp-user-frontend' ) . '</div>';
882
 
883
  if ( isset( $price_with_tax ) && $price_with_tax ) {
884
+ $billing_amount = apply_filters( 'wpuf_payment_amount', $billing_amount );
885
  }
886
 
887
  if ( $billing_amount && $pack->meta_value['recurring_pay'] == 'yes' ) {
888
+ $recurring_des = sprintf( __( 'Every', 'wp-user-frontend' ) . ' %s %s', $pack->meta_value['billing_cycle_number'], $this->get_cycle_label( $pack->meta_value['cycle_period'], $pack->meta_value['billing_cycle_number'] ), $pack->meta_value['trial_duration_type'] );
889
+ $recurring_des .= !empty( $pack->meta_value['billing_limit'] ) ? sprintf( ', ' . __( 'for', 'wp-user-frontend' ) . ' %s ' . __( 'installments', 'wp-user-frontend' ), $pack->meta_value['billing_limit'] ) : '';
890
+ $recurring_des = '<div class="wpuf-pack-cycle wpuf-nullamount-hide">' . $recurring_des . '</div>';
891
  }
892
 
893
  if ( $billing_amount && $pack->meta_value['recurring_pay'] == 'yes' && $pack->meta_value['trial_status'] == 'yes' ) {
894
+ $duration = _n( $pack->meta_value['trial_duration_type'], $pack->meta_value['trial_duration_type'] . 's', $pack->meta_value['trial_duration'], 'wp-user-frontend' );
895
+ $trial_des = sprintf( __( 'Trial available for first %s %s', 'wp-user-frontend' ), $pack->meta_value['trial_duration'], $duration );
896
  }
897
 
898
+ $label = wpuf_get_option( 'logged_in_label', 'wpuf_subscription_settings', false );
899
+ $button_name = $label ? $label : __( 'Buy Now', 'wp-user-frontend' );
900
 
901
+ if ( !is_user_logged_in() ) {
902
+ $label = wpuf_get_option( 'logged_out_label', 'wpuf_subscription_settings', false );
903
  $button_name = $label ? $label : __( 'Sign Up', 'wp-user-frontend' );
904
+ } elseif ( $billing_amount == '0.00' ) {
905
+ $label = wpuf_get_option( 'free_label', 'wpuf_subscription_settings', false );
906
  $button_name = $label ? $label : __( 'Free', 'wp-user-frontend' );
907
  }
908
 
909
+ $query_args = [
910
+ 'action' => 'register',
911
+ 'type' => 'wpuf_sub',
912
  'pack_id' => $pack->ID,
913
+ ];
914
  $query_url = wp_registration_url();
915
 
916
  if ( $coupon_status === false && is_user_logged_in() ) {
917
+ $query_args = [
918
+ 'action' => 'wpuf_pay',
919
+ 'type' => 'pack',
920
+ 'pack_id' => $pack->ID,
921
+ ];
922
  $query_url = $details_meta['payment_page'];
923
  }
924
 
925
+ wpuf_load_template( 'subscriptions/pack-details.php', apply_filters( 'wpuf_subscription_pack_details_args', [
926
  'pack' => $pack,
927
  'billing_amount' => $billing_amount,
928
  'details_meta' => $details_meta,
934
  'button_name' => $button_name,
935
  'query_args' => $query_args,
936
  'query_url' => $query_url,
937
+ ] ) );
938
  }
939
 
940
  /**
941
  * Show a info message when posting if payment is enabled
942
  */
943
+ public function add_post_info( $form_id, $form_settings ) {
944
  $form = new WPUF_Form( $form_id );
945
  $pay_per_post = $form->is_enabled_pay_per_post();
946
  $pay_per_post_cost = (float) $form->get_pay_per_post_cost();
964
  $pay_per_post_cost = apply_filters( 'wpuf_payment_amount', $pay_per_post_cost );
965
  }
966
 
967
+ $text = sprintf( __( 'There is a <strong>%s</strong> charge to add a new post.', 'wp-user-frontend' ), wpuf_format_price( $pay_per_post_cost ) );
968
 
969
+ echo wp_kses_post( apply_filters( 'wpuf_ppp_notice', $text, $form_id, $form_settings ) ); ?>
 
970
  </div>
971
  <?php
972
+ } elseif ( self::has_user_error( $form_settings ) || ( $payment_enabled && $force_pack && !is_wp_error( $current_pack ) && !$current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) ) {
973
  ?>
974
  <div class="wpuf-info">
975
  <?php
976
+ $form = new WPUF_Form( $form_id );
977
+ $fallback_cost = (int) $form->get_subs_fallback_cost();
978
 
979
  if ( isset( $price_with_tax ) && $price_with_tax ) {
980
+ $fallback_cost = apply_filters( 'wpuf_payment_amount', $fallback_cost );
981
  }
982
 
983
+ $text = sprintf( __( 'Your Subscription pack is exhausted. There is a <strong>%s</strong> charge to add a new post.', 'wp-user-frontend' ), wpuf_format_price( $fallback_cost ) );
984
 
985
+ echo wp_kses_post( apply_filters( 'wpuf_ppp_notice', wp_kses_post( $text ), esc_html( $form_id ), $form_settings ) ); ?>
 
986
  </div>
987
  <?php
988
  }
1004
  return $rows;
1005
  }
1006
 
1007
+ $results = [];
1008
+
1009
+ foreach ( $rows as $row ) {
1010
  if ( !in_array( $row->user_id, $results ) ) {
1011
  $results[] = $row->user_id;
1012
  }
1013
  }
1014
 
1015
+ $users = get_users( [ 'include' => $results ] );
1016
+
1017
  return $users;
1018
  }
1019
 
1020
+ public function force_pack_notice( $text, $id, $form_settings ) {
 
1021
  $form = new WPUF_Form( $id );
1022
 
1023
  $force_pack = $form->is_enabled_force_pack();
1024
 
1025
+ if ( $force_pack && self::has_user_error( $form_settings ) ) {
1026
  $pack_page = get_permalink( wpuf_get_option( 'subscription_page', 'wpuf_payment' ) );
1027
 
1028
  $text = sprintf( __( 'You must <a href="%s">purchase a pack</a> before posting', 'wp-user-frontend' ), $pack_page );
1031
  return apply_filters( 'wpuf_pack_notice', $text, $id, $form_settings );
1032
  }
1033
 
1034
+ public function force_pack_permission( $perm, $id, $form_settings ) {
1035
+ $form = new WPUF_Form( $id );
1036
+ $force_pack = $form->is_enabled_force_pack();
1037
+ $pay_per_post = $form->is_enabled_pay_per_post();
 
1038
  $fallback_enabled = $form->is_enabled_fallback_cost();
1039
  $fallback_cost = $form->get_subs_fallback_cost();
1040
 
1041
+ $current_user = wpuf_get_user();
1042
+ $current_pack = $current_user->subscription()->current_pack();
1043
  $has_post_count = isset( $form_settings['post_type'] ) ? $current_user->subscription()->has_post_count( $form_settings['post_type'] ) : false;
1044
 
1045
  if ( is_user_logged_in() ) {
 
1046
  if ( wpuf_get_user()->post_locked() ) {
1047
  return 'no';
1048
  } else {
1053
  } else {
1054
  //if charging is enabled
1055
  if ( $force_pack ) {
1056
+ if ( !is_wp_error( $current_pack ) ) {
1057
  // current pack has no error
1058
+ if ( !$fallback_enabled ) {
1059
  //fallback cost enabled
1060
  if ( !$current_user->subscription()->current_pack_id() ) {
1061
  return 'no';
1076
  return 'no';
1077
  }
1078
  }
1079
+
1080
  if ( !$force_pack && $pay_per_post ) {
1081
  return 'yes';
1082
  }
1083
  }
1084
  }
 
1085
  }
1086
 
1087
  if ( !is_user_logged_in() && isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' ) {
1089
  if ( $force_pack ) {
1090
  return 'no';
1091
  }
1092
+
1093
  if ( !$force_pack && $pay_per_post ) {
1094
  return 'yes';
1095
  } elseif ( !$force_pack && !$pay_per_post ) {
1096
  return 'no';
1097
  }
1098
+ } else {
 
1099
  return 'yes';
1100
  }
1101
  }
1102
 
1103
  return $perm;
 
1104
  }
1105
 
1106
  /**
1107
  * Checks against the user, if he is valid for posting new post
1108
  *
1109
  * @global object $userdata
1110
+ *
1111
  * @return bool
1112
  */
1113
  public static function has_user_error( $form_settings = null ) {
1124
  *
1125
  * @param int $user_id
1126
  * @param int $pack_id
1127
+ *
1128
+ * @return bool
1129
  */
1130
  public static function has_used_free_pack( $user_id, $pack_id ) {
1131
  // _deprecated_function( __FUNCTION__, '2.6.0', 'wpuf_get_user( $user_id )->subscription()->used_free_pack( $pack_id );' );
1147
  wpuf_get_user( $user_id )->subscription()->add_free_pack( $user_id, $pack_id );
1148
  }
1149
 
1150
+ public function packdropdown( $packs, $selected = '' ) {
1151
+ $packs = isset( $packs ) ? $packs : [];
1152
+
1153
+ foreach ( $packs as $key => $pack ) {
1154
  ?>
1155
+ <option value="<?php echo esc_attr( $pack->ID ); ?>" <?php selected( $selected, $pack->ID ); ?>><?php echo esc_attr( $pack->post_title ); ?></option>
1156
  <?php
1157
  }
1158
  }
1159
 
 
1160
  /**
1161
  * Reset the post count of a subscription of a user
1162
  *
1171
  // _deprecated_function( __FUNCTION__, '2.6.0', 'wpuf_get_user()->subscription()->reset_subscription_data( $post_id, $form_id, $form_settings, $form_vars );' );
1172
 
1173
  wpuf_get_user()->subscription()->reset_subscription_data( $post_id, $form_id, $form_settings, $form_vars );
 
1174
  }
1175
 
1176
  /**
1179
  * @since 2.5.9
1180
  *
1181
  * @param $post_id
1182
+ *
1183
  * @return string
1184
  */
 
1185
  public function get_payment_status( $post_id ) {
1186
+ return get_post_meta( $post_id, '_wpuf_payment_status', true );
1187
  }
1188
 
1189
  /**
1192
  * @since 2.8.8
1193
  *
1194
  * @param $post_id
1195
+ *
1196
  * @return void
1197
  */
 
1198
  public function insert_free_pack_subscribers( $pack_id, $userdata ) {
1199
  global $wpdb;
1200
 
1201
  $subscription = wpuf()->subscription->get_subscription( $pack_id );
 
1202
 
1203
+ if ( $userdata->id && $subscription ) {
1204
+ $user_sub = WPUF_Subscription::get_user_pack( $userdata->id );
1205
  $post_expiration_time = wpuf_date2mysql( $user_sub['expire'] );
1206
 
1207
+ $table_data = [
 
1208
  'user_id' => $userdata->id,
1209
  'name' => $userdata->user->data->display_name,
1210
  'subscribtion_id' => $pack_id,
1213
  'transaction_id' => 'free',
1214
  'starts_from' => date( 'd-m-Y' ),
1215
  'expire' => empty( $post_expiration_time ) ? 'recurring' : $post_expiration_time,
1216
+ ];
1217
 
1218
  $wpdb->insert( $wpdb->prefix . 'wpuf_subscribers', $table_data );
1219
  }
1220
  }
 
1221
  }
class/transactions-list-table.php CHANGED
@@ -1,19 +1,20 @@
1
  <?php
2
 
3
- if ( ! class_exists( 'WP_List_Table' ) ) {
4
  require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
  }
6
 
7
  class WPUF_Transactions_List_Table extends WP_List_Table {
 
8
  /**
9
  * Constructor.
10
  */
11
  public function __construct() {
12
- parent::__construct( array(
13
  'singular' => __( 'transaction', 'wp-user-frontend' ),
14
  'plural' => __( 'transactions', 'wp-user-frontend' ),
15
- 'ajax' => false
16
- ) );
17
  }
18
 
19
  /**
@@ -26,7 +27,7 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
26
  public function column_cb( $item ) {
27
  return sprintf(
28
  '<input type="checkbox" name="bulk-items[]" value="%s" />', $item->id
29
- );
30
  }
31
 
32
  /**
@@ -35,7 +36,7 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
35
  * @return array
36
  */
37
  public function get_columns() {
38
- $columns = array(
39
  'cb' => '<input type="checkbox" />',
40
  'id' => __( 'ID', 'wp-user-frontend' ),
41
  'status' => __( 'Status', 'wp-user-frontend' ),
@@ -49,7 +50,7 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
49
  'payer_email' => __( 'Email', 'wp-user-frontend' ),
50
  'transaction_id' => __( 'Trans ID', 'wp-user-frontend' ),
51
  'created' => __( 'Date', 'wp-user-frontend' ),
52
- );
53
 
54
  return $columns;
55
  }
@@ -60,11 +61,11 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
60
  * @return array
61
  */
62
  public function get_sortable_columns() {
63
- $sortable_columns = array(
64
- 'id' => array( 'id', false ),
65
- 'status' => array( 'status', false ),
66
- 'created' => array( 'created', false ),
67
- );
68
 
69
  return $sortable_columns;
70
  }
@@ -75,16 +76,16 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
75
  * @return array
76
  */
77
  public function get_views() {
78
- $status_links = array();
79
  $base_link = admin_url( 'admin.php?page=wpuf_transaction' );
80
 
81
- $transactions_count = wpuf_get_transactions( array( 'count' => true ) );
82
- $transactions_pending_count = wpuf_get_pending_transactions( array( 'count' => true ) );
83
 
84
- $status = isset( $_REQUEST['status'] ) ? sanitize_text_field( $_REQUEST['status'] ) : 'all';
85
 
86
- $status_links['all'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( array( 'status' => 'all' ), $base_link ), ( $status == 'all' ) ? 'current' : '', __( 'All', 'wp-user-frontend' ), $transactions_count );
87
- $status_links['pending'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( array( 'status' => 'pending' ), $base_link ), ( $status == 'pending' ) ? 'current' : '', __( 'Pending', 'wp-user-frontend' ), $transactions_pending_count );
88
 
89
  return $status_links;
90
  }
@@ -102,18 +103,21 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
102
  $delete_nonce = wp_create_nonce( 'wpuf-delete-transaction' );
103
  $title = '<strong>#' . $id . '</strong>';
104
 
105
- if ( isset( $_REQUEST['status'] ) && $_REQUEST['status'] == 'pending' ) {
 
 
 
106
  $accept_nonce = wp_create_nonce( 'wpuf-accept-transaction' );
107
  $reject_nonce = wp_create_nonce( 'wpuf-reject-transaction' );
108
 
109
- $actions = array(
110
- 'accept' => sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s">%s</a>', esc_attr( $_REQUEST['page'] ), 'accept', absint( $id ), $accept_nonce, __( 'Accept', 'wp-user-frontend' ) ),
111
- 'reject' => sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s">%s</a>', esc_attr( $_REQUEST['page'] ), 'reject', absint( $id ), $reject_nonce, __( 'Reject', 'wp-user-frontend' ) )
112
- );
113
  } else {
114
- $actions = array(
115
- 'delete' => sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s">%s</a>', esc_attr( $_REQUEST['page'] ), 'delete', absint( $id ), $delete_nonce, __( 'Delete', 'wp-user-frontend' ) )
116
- );
117
  }
118
 
119
  return $title . $this->row_actions( $actions );
@@ -122,35 +126,42 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
122
  /**
123
  * Define each column of the table.
124
  *
125
- * @param array $item
126
- * @param string $column_name
127
  *
128
  * @return mixed
129
  */
130
  public function column_default( $item, $column_name ) {
131
-
132
- switch( $column_name ) {
133
  case 'status':
134
  return ( $item->status == 'completed' ) ? '<span class="wpuf-status-completed" title="Completed"></span>' : '<span class="wpuf-status-processing" title="Processing"></span>';
 
135
  case 'user':
136
- $user = get_user_by( 'id', $item->user_id );
137
- $post_author_id = get_post_field( 'post_author', $item->post_id ) ;
138
- $post_author = get_the_author_meta( 'nickname', $post_author_id);
139
- return ! empty( $user ) ? sprintf( '<a href="%s">%s</a>', admin_url( 'user-edit.php?user_id=' . $item->user_id ), $user->user_nicename ) : $post_author ;
 
 
140
  case 'cost':
141
  return wpuf_format_price( $item->cost );
 
142
  case 'tax':
143
  return wpuf_format_price( $item->tax );
 
144
  case 'post_id':
145
- return ! empty( $item->post_id ) ? sprintf( '<a href="%s">%s</a>', admin_url( 'post.php?post=' . $item->post_id . '&action=edit' ), $item->post_id ) : '-';
 
146
  case 'pack_id':
147
- return ! empty( $item->pack_id ) ? sprintf( '<a href="%s">%s</a>', admin_url( 'post.php?post=' . $item->pack_id . '&action=edit' ), $item->pack_id ) : '-';
 
148
  case 'payer':
149
- return ! empty( $item->payer_first_name ) ? $item->payer_first_name . ' ' . $item->payer_last_name : '-';
 
150
  case 'created':
151
- return ! empty( $item->created ) ? date( 'd-m-Y', strtotime( $item->created ) ) : '-';
152
  default:
153
- return ! empty( $item->{$column_name} ) ? $item->{$column_name} : '-';
154
  break;
155
  }
156
  }
@@ -161,7 +172,7 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
161
  * @return void
162
  */
163
  public function no_items() {
164
- _e( 'No transactions found.', 'wp-user-frontend' );
165
  }
166
 
167
  /**
@@ -170,16 +181,17 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
170
  * @return array
171
  */
172
  public function get_bulk_actions() {
 
173
 
174
- if ( isset( $_REQUEST['status'] ) && $_REQUEST['status'] == 'pending' ) {
175
- $actions = array(
176
  'bulk-accept' => __( 'Accept', 'wp-user-frontend' ),
177
  'bulk-reject' => __( 'Reject', 'wp-user-frontend' ),
178
- );
179
  } else {
180
- $actions = array(
181
  'bulk-delete' => __( 'Delete', 'wp-user-frontend' ),
182
- );
183
  }
184
 
185
  return $actions;
@@ -194,18 +206,18 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
194
  $per_page = $this->get_items_per_page( 'transactions_per_page', 20 );
195
  $current_page = $this->get_pagenum();
196
 
197
- $status = isset( $_REQUEST['status'] ) ? sanitize_text_field( $_REQUEST['status'] ) : 'all';
198
 
199
  if ( $status == 'pending' ) {
200
- $total_items = wpuf_get_pending_transactions( array( 'count' => true ) );
201
  } else {
202
- $total_items = wpuf_get_transactions( array( 'count' => true ) );
203
  }
204
 
205
- $this->set_pagination_args( array(
206
  'total_items' => $total_items,
207
  'per_page' => $per_page,
208
- ) );
209
 
210
  $this->_column_headers = $this->get_column_info();
211
 
@@ -219,8 +231,8 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
219
  ];
220
 
221
  if ( isset( $_REQUEST['orderby'] ) && isset( $_REQUEST['order'] ) ) {
222
- $args['orderby'] = $_REQUEST['orderby'];
223
- $args['order'] = $_REQUEST['order'] ;
224
  }
225
 
226
  if ( $status == 'pending' ) {
@@ -241,16 +253,19 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
241
  $page_url = menu_page_url( 'wpuf_transaction', false );
242
 
243
  // Delete Transaction
244
- if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'delete' )
245
- || ( isset( $_REQUEST['action2'] ) && $_REQUEST['action2'] == 'delete' )
246
- ) {
247
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpuf-delete-transaction' ) ) {
 
 
 
248
  return false;
249
  }
250
 
251
- $id = absint( esc_sql( $_REQUEST['id'] ) );
252
 
253
- $wpdb->delete( $wpdb->prefix . 'wpuf_transaction', array( 'id' => $id ), array( '%d' ) );
254
 
255
  // Redirect
256
  wp_redirect( $page_url );
@@ -258,19 +273,19 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
258
  }
259
 
260
  // Delete Transactions
261
- if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'bulk-delete' )
262
- || ( isset( $_REQUEST['action2'] ) && $_REQUEST['action2'] == 'bulk-delete' )
263
- ) {
264
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-transactions' ) ) {
265
  return false;
266
  }
267
 
268
- $ids = esc_sql( $_REQUEST['bulk-items'] );
 
 
269
 
270
  foreach ( $ids as $id ) {
271
  $id = absint( $id );
272
 
273
- $wpdb->delete( $wpdb->prefix . 'wpuf_transaction', array( 'id' => $id ), array( '%d' ) );
274
  }
275
 
276
  // Redirect
@@ -279,14 +294,12 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
279
  }
280
 
281
  // Reject Transaction
282
- if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'reject' )
283
- || ( isset( $_REQUEST['action2'] ) && $_REQUEST['action2'] == 'reject' )
284
- ) {
285
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpuf-reject-transaction' ) ) {
286
  return false;
287
  }
288
 
289
- $id = absint( esc_sql( $_REQUEST['id'] ) );
290
  $info = get_post_meta( $id, '_data', true );
291
  $gateway = $info['post_data']['wpuf_payment_method'];
292
 
@@ -299,14 +312,12 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
299
  }
300
 
301
  // Reject Transactions
302
- if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'bulk-reject' )
303
- || ( isset( $_REQUEST['action2'] ) && $_REQUEST['action2'] == 'bulk-reject' )
304
- ) {
305
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-transactions' ) ) {
306
  return false;
307
  }
308
-
309
- $ids = esc_sql( $_REQUEST['bulk-items'] );
310
 
311
  foreach ( $ids as $id ) {
312
  $id = absint( $id );
@@ -324,18 +335,16 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
324
  }
325
 
326
  // Accept Transaction
327
- if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'accept' )
328
- || ( isset( $_REQUEST['action2'] ) && $_REQUEST['action2'] == 'accept' )
329
- ) {
330
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpuf-accept-transaction' ) ) {
331
  return false;
332
  }
333
 
334
- if ( ! current_user_can( 'manage_options' ) ) {
335
  return;
336
  }
337
 
338
- $id = absint( $_REQUEST['id'] );
339
  $info = get_post_meta( $id, '_data', true );
340
 
341
  if ( $info ) {
@@ -352,11 +361,12 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
352
  }
353
 
354
  $payer_address = '';
 
355
  if ( wpuf_get_option( 'show_address', 'wpuf_address_options', false ) ) {
356
  $payer_address = wpuf_get_user_address();
357
  }
358
 
359
- $transaction = array(
360
  'user_id' => $info['user_info']['id'],
361
  'status' => 'completed',
362
  'subtotal' => $info['subtotal'],
@@ -370,8 +380,8 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
370
  'payer_email' => $info['user_info']['email'],
371
  'payment_type' => 'Bank/Manual',
372
  'transaction_id' => $id,
373
- 'created' => current_time( 'mysql' )
374
- );
375
 
376
  do_action( 'wpuf_gateway_bank_order_complete', $transaction, $id );
377
 
@@ -381,7 +391,7 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
381
 
382
  if ( $coupon_id ) {
383
  $pre_usage = get_post_meta( $coupon_id, '_coupon_used', true );
384
- $pre_usage = (empty( $pre_usage )) ? 0 : $pre_usage;
385
  $new_use = $pre_usage + 1;
386
 
387
  update_post_meta( $coupon_id, '_coupon_used', $new_use );
@@ -395,18 +405,17 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
395
  }
396
 
397
  // Bulk Accept Transaction
398
- if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'bulk-accept' )
399
- || ( isset( $_REQUEST['action2'] ) && $_REQUEST['action2'] == 'bulk-accept' )
400
- ) {
401
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-transactions' ) ) {
402
  return false;
403
  }
404
 
405
- if ( ! current_user_can( 'manage_options' ) ) {
406
  return;
407
  }
408
 
409
- $ids = esc_sql( $_REQUEST['bulk-items'] );
 
410
 
411
  foreach ( $ids as $id ) {
412
  $id = absint( $id );
@@ -426,7 +435,7 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
426
  break;
427
  }
428
 
429
- $transaction = array(
430
  'user_id' => $info['user_info']['id'],
431
  'status' => 'completed',
432
  'subtotal' => $info['subtotal'],
@@ -439,8 +448,8 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
439
  'payer_email' => $info['user_info']['email'],
440
  'payment_type' => 'Bank/Manual',
441
  'transaction_id' => $id,
442
- 'created' => current_time( 'mysql' )
443
- );
444
 
445
  do_action( 'wpuf_gateway_bank_order_complete', $transaction, $id );
446
 
@@ -452,7 +461,5 @@ class WPUF_Transactions_List_Table extends WP_List_Table {
452
  wp_redirect( $page_url );
453
  exit;
454
  }
455
-
456
  }
457
-
458
  }
1
  <?php
2
 
3
+ if ( !class_exists( 'WP_List_Table' ) ) {
4
  require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
  }
6
 
7
  class WPUF_Transactions_List_Table extends WP_List_Table {
8
+
9
  /**
10
  * Constructor.
11
  */
12
  public function __construct() {
13
+ parent::__construct( [
14
  'singular' => __( 'transaction', 'wp-user-frontend' ),
15
  'plural' => __( 'transactions', 'wp-user-frontend' ),
16
+ 'ajax' => false,
17
+ ] );
18
  }
19
 
20
  /**
27
  public function column_cb( $item ) {
28
  return sprintf(
29
  '<input type="checkbox" name="bulk-items[]" value="%s" />', $item->id
30
+ );
31
  }
32
 
33
  /**
36
  * @return array
37
  */
38
  public function get_columns() {
39
+ $columns = [
40
  'cb' => '<input type="checkbox" />',
41
  'id' => __( 'ID', 'wp-user-frontend' ),
42
  'status' => __( 'Status', 'wp-user-frontend' ),
50
  'payer_email' => __( 'Email', 'wp-user-frontend' ),
51
  'transaction_id' => __( 'Trans ID', 'wp-user-frontend' ),
52
  'created' => __( 'Date', 'wp-user-frontend' ),
53
+ ];
54
 
55
  return $columns;
56
  }
61
  * @return array
62
  */
63
  public function get_sortable_columns() {
64
+ $sortable_columns = [
65
+ 'id' => [ 'id', false ],
66
+ 'status' => [ 'status', false ],
67
+ 'created' => [ 'created', false ],
68
+ ];
69
 
70
  return $sortable_columns;
71
  }
76
  * @return array
77
  */
78
  public function get_views() {
79
+ $status_links = [];
80
  $base_link = admin_url( 'admin.php?page=wpuf_transaction' );
81
 
82
+ $transactions_count = wpuf_get_transactions( [ 'count' => true ] );
83
+ $transactions_pending_count = wpuf_get_pending_transactions( [ 'count' => true ] );
84
 
85
+ $status = isset( $_REQUEST['status'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) : 'all';
86
 
87
+ $status_links['all'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( [ 'status' => 'all' ], $base_link ), ( $status == 'all' ) ? 'current' : '', __( 'All', 'wp-user-frontend' ), $transactions_count );
88
+ $status_links['pending'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( [ 'status' => 'pending' ], $base_link ), ( $status == 'pending' ) ? 'current' : '', __( 'Pending', 'wp-user-frontend' ), $transactions_pending_count );
89
 
90
  return $status_links;
91
  }
103
  $delete_nonce = wp_create_nonce( 'wpuf-delete-transaction' );
104
  $title = '<strong>#' . $id . '</strong>';
105
 
106
+ $status = isset( $_REQUEST['status'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) : '';
107
+ $page = isset( $_REQUEST['page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) : '';
108
+
109
+ if ( $status == 'pending' ) {
110
  $accept_nonce = wp_create_nonce( 'wpuf-accept-transaction' );
111
  $reject_nonce = wp_create_nonce( 'wpuf-reject-transaction' );
112
 
113
+ $actions = [
114
+ 'accept' => sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s">%s</a>', esc_attr( $page ), 'accept', absint( $id ), $accept_nonce, __( 'Accept', 'wp-user-frontend' ) ),
115
+ 'reject' => sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s">%s</a>', esc_attr( $page ), 'reject', absint( $id ), $reject_nonce, __( 'Reject', 'wp-user-frontend' ) ),
116
+ ];
117
  } else {
118
+ $actions = [
119
+ 'delete' => sprintf( '<a href="?page=%s&action=%s&id=%d&_wpnonce=%s">%s</a>', esc_attr( $page ), 'delete', absint( $id ), $delete_nonce, __( 'Delete', 'wp-user-frontend' ) ),
120
+ ];
121
  }
122
 
123
  return $title . $this->row_actions( $actions );
126
  /**
127
  * Define each column of the table.
128
  *
129
+ * @param array $item
130
+ * @param string $column_name
131
  *
132
  * @return mixed
133
  */
134
  public function column_default( $item, $column_name ) {
135
+ switch ( $column_name ) {
 
136
  case 'status':
137
  return ( $item->status == 'completed' ) ? '<span class="wpuf-status-completed" title="Completed"></span>' : '<span class="wpuf-status-processing" title="Processing"></span>';
138
+
139
  case 'user':
140
+ $user = get_user_by( 'id', $item->user_id );
141
+ $post_author_id = get_post_field( 'post_author', $item->post_id );
142
+ $post_author = get_the_author_meta( 'nickname', $post_author_id );
143
+
144
+ return !empty( $user ) ? sprintf( '<a href="%s">%s</a>', admin_url( 'user-edit.php?user_id=' . $item->user_id ), $user->user_nicename ) : $post_author;
145
+
146
  case 'cost':
147
  return wpuf_format_price( $item->cost );
148
+
149
  case 'tax':
150
  return wpuf_format_price( $item->tax );
151
+
152
  case 'post_id':
153
+ return !empty( $item->post_id ) ? sprintf( '<a href="%s">%s</a>', admin_url( 'post.php?post=' . $item->post_id . '&action=edit' ), $item->post_id ) : '-';
154
+
155
  case 'pack_id':
156
+ return !empty( $item->pack_id ) ? sprintf( '<a href="%s">%s</a>', admin_url( 'post.php?post=' . $item->pack_id . '&action=edit' ), $item->pack_id ) : '-';
157
+
158
  case 'payer':
159
+ return !empty( $item->payer_first_name ) ? $item->payer_first_name . ' ' . $item->payer_last_name : '-';
160
+
161
  case 'created':
162
+ return !empty( $item->created ) ? date( 'd-m-Y', strtotime( $item->created ) ) : '-';
163
  default:
164
+ return !empty( $item->{$column_name} ) ? $item->{$column_name} : '-';
165
  break;
166
  }
167
  }
172
  * @return void
173
  */
174
  public function no_items() {
175
+ esc_html_e( 'No transactions found.', 'wp-user-frontend' );
176
  }
177
 
178
  /**
181
  * @return array
182
  */
183
  public function get_bulk_actions() {
184
+ $status = isset( $_REQUEST['status'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) : '';
185
 
186
+ if ( $status == 'pending' ) {
187
+ $actions = [
188
  'bulk-accept' => __( 'Accept', 'wp-user-frontend' ),
189
  'bulk-reject' => __( 'Reject', 'wp-user-frontend' ),
190
+ ];
191
  } else {
192
+ $actions = [
193
  'bulk-delete' => __( 'Delete', 'wp-user-frontend' ),
194
+ ];
195
  }
196
 
197
  return $actions;
206
  $per_page = $this->get_items_per_page( 'transactions_per_page', 20 );
207
  $current_page = $this->get_pagenum();
208
 
209
+ $status = isset( $_REQUEST['status'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) : 'all';
210
 
211
  if ( $status == 'pending' ) {
212
+ $total_items = wpuf_get_pending_transactions( [ 'count' => true ] );
213
  } else {
214
+ $total_items = wpuf_get_transactions( [ 'count' => true ] );
215
  }
216
 
217
+ $this->set_pagination_args( [
218
  'total_items' => $total_items,
219
  'per_page' => $per_page,
220
+ ] );
221
 
222
  $this->_column_headers = $this->get_column_info();
223
 
231
  ];
232
 
233
  if ( isset( $_REQUEST['orderby'] ) && isset( $_REQUEST['order'] ) ) {
234
+ $args['orderby'] = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) );
235
+ $args['order'] = sanitize_text_field( wp_unslash( $_REQUEST['order'] ) );
236
  }
237
 
238
  if ( $status == 'pending' ) {
253
  $page_url = menu_page_url( 'wpuf_transaction', false );
254
 
255
  // Delete Transaction
256
+ $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : '';
257
+ $action2 = isset( $_REQUEST['action2'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action2'] ) ) : '';
258
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
259
+ $id = isset( $_REQUEST['id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : '';
260
+
261
+ if ( $action == 'delete' || $action2 == 'delete' ) {
262
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf-delete-transaction' ) ) {
263
  return false;
264
  }
265
 
266
+ $id = absint( esc_sql( $id ) );
267
 
268
+ $wpdb->delete( $wpdb->prefix . 'wpuf_transaction', [ 'id' => $id ], [ '%d' ] );
269
 
270
  // Redirect
271
  wp_redirect( $page_url );
273
  }
274
 
275
  // Delete Transactions
276
+ if ( $action == 'bulk-delete' || $action2 == 'bulk-delete' ) {
277
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'bulk-transactions' ) ) {
 
 
278
  return false;
279
  }
280
 
281
+ $bulk_items = isset( $_REQUEST['bulk-items'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['bulk-items'] ) ) : [];
282
+
283
+ $ids = esc_sql( $bulk_items );
284
 
285
  foreach ( $ids as $id ) {
286
  $id = absint( $id );
287
 
288
+ $wpdb->delete( $wpdb->prefix . 'wpuf_transaction', [ 'id' => $id ], [ '%d' ] );
289
  }
290
 
291
  // Redirect
294
  }
295
 
296
  // Reject Transaction
297
+ if ( $action == 'reject' || $action2 == 'reject' ) {
298
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf-reject-transaction' ) ) {
 
 
299
  return false;
300
  }
301
 
302
+ $id = isset( $_REQUEST['id'] ) ? intval( wp_unslash( $_REQUEST['id'] ) ) : 0;
303
  $info = get_post_meta( $id, '_data', true );
304
  $gateway = $info['post_data']['wpuf_payment_method'];
305
 
312
  }
313
 
314
  // Reject Transactions
315
+ if ( $action == 'bulk-reject' || $action2 == 'bulk-reject' ) {
316
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'bulk-transactions' ) ) {
 
 
317
  return false;
318
  }
319
+ $bulk_items = isset( $_REQUEST['bulk-items'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['bulk-items'] ) ) : [];
320
+ $ids = esc_sql( $bulk_items );
321
 
322
  foreach ( $ids as $id ) {
323
  $id = absint( $id );
335
  }
336
 
337
  // Accept Transaction
338
+ if ( $action == 'accept' || $action2 == 'accept' ) {
339
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf-accept-transaction' ) ) {
 
 
340
  return false;
341
  }
342
 
343
+ if ( !current_user_can( 'manage_options' ) ) {
344
  return;
345
  }
346
 
347
+ $id = isset( $_REQUEST['id'] ) ? intval( wp_unslash( $_REQUEST['id'] ) ) : 0 ;
348
  $info = get_post_meta( $id, '_data', true );
349
 
350
  if ( $info ) {
361
  }
362
 
363
  $payer_address = '';
364
+
365
  if ( wpuf_get_option( 'show_address', 'wpuf_address_options', false ) ) {
366
  $payer_address = wpuf_get_user_address();
367
  }
368
 
369
+ $transaction = [
370
  'user_id' => $info['user_info']['id'],
371
  'status' => 'completed',
372
  'subtotal' => $info['subtotal'],
380
  'payer_email' => $info['user_info']['email'],
381
  'payment_type' => 'Bank/Manual',
382
  'transaction_id' => $id,
383
+ 'created' => current_time( 'mysql' ),
384
+ ];
385
 
386
  do_action( 'wpuf_gateway_bank_order_complete', $transaction, $id );
387
 
391
 
392
  if ( $coupon_id ) {
393
  $pre_usage = get_post_meta( $coupon_id, '_coupon_used', true );
394
+ $pre_usage = ( empty( $pre_usage ) ) ? 0 : $pre_usage;
395
  $new_use = $pre_usage + 1;
396
 
397
  update_post_meta( $coupon_id, '_coupon_used', $new_use );
405
  }
406
 
407
  // Bulk Accept Transaction
408
+ if ( $action == 'bulk-accept' || $action2 == 'bulk-accept' ) {
409
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'bulk-transactions' ) ) {
 
 
410
  return false;
411
  }
412
 
413
+ if ( !current_user_can( 'manage_options' ) ) {
414
  return;
415
  }
416
 
417
+ $bulk_items = isset( $_REQUEST['bulk-items'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['bulk-items'] ) ) : [];
418
+ $ids = esc_sql( $bulk_items );
419
 
420
  foreach ( $ids as $id ) {
421
  $id = absint( $id );
435
  break;
436
  }
437
 
438
+ $transaction = [
439
  'user_id' => $info['user_info']['id'],
440
  'status' => 'completed',
441
  'subtotal' => $info['subtotal'],
448
  'payer_email' => $info['user_info']['email'],
449
  'payment_type' => 'Bank/Manual',
450
  'transaction_id' => $id,
451
+ 'created' => current_time( 'mysql' ),
452
+ ];
453
 
454
  do_action( 'wpuf_gateway_bank_order_complete', $transaction, $id );
455
 
461
  wp_redirect( $page_url );
462
  exit;
463
  }
 
464
  }
 
465
  }
class/upload.php CHANGED
@@ -4,20 +4,18 @@
4
  * Attachment Uploader class
5
  *
6
  * @since 1.0
7
- * @package wpuf
8
  */
9
  class WPUF_Upload {
10
 
11
- function __construct() {
 
 
12
 
13
- add_action( 'wp_ajax_wpuf_upload_file', array($this, 'upload_file') );
14
- add_action( 'wp_ajax_nopriv_wpuf_upload_file', array($this, 'upload_file') );
15
 
16
- add_action( 'wp_ajax_wpuf_file_del', array($this, 'delete_file') );
17
- add_action( 'wp_ajax_nopriv_wpuf_file_del', array($this, 'delete_file') );
18
-
19
- add_action( 'wp_ajax_wpuf_insert_image', array( $this, 'insert_image' ) );
20
- add_action( 'wp_ajax_nopriv_wpuf_insert_image', array( $this, 'insert_image' ) );
21
  }
22
 
23
  /**
@@ -25,27 +23,30 @@ class WPUF_Upload {
25
  *
26
  * @return void
27
  */
28
- function validate_nonce() {
29
- $nonce = isset( $_GET['nonce'] ) ? $_GET['nonce'] : '';
30
 
31
- if ( ! wp_verify_nonce( $nonce, 'wpuf-upload-nonce' ) ) {
32
- die( 'error' );
33
  }
34
  }
35
 
36
- function upload_file( $image_only = false ) {
37
- $this->validate_nonce();
 
 
 
 
38
 
39
  // a valid request will have a form ID
40
- $form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : false;
41
 
42
- if ( ! $form_id ) {
43
  die( 'error' );
44
  }
45
 
46
  // check if guest post enabled for guests
47
- if ( ! is_user_logged_in() ) {
48
-
49
  $guest_post = false;
50
  $form_settings = wpuf_get_form_settings( $form_id );
51
 
@@ -63,28 +64,29 @@ class WPUF_Upload {
63
  $guest_post = true;
64
  }
65
 
66
- if ( ! $guest_post ) {
67
  die( 'error' );
68
  }
69
  }
70
 
71
- $upload = array(
72
- 'name' => $_FILES['wpuf_file']['name'],
73
- 'type' => $_FILES['wpuf_file']['type'],
74
- 'tmp_name' => $_FILES['wpuf_file']['tmp_name'],
75
- 'error' => $_FILES['wpuf_file']['error'],
76
- 'size' => $_FILES['wpuf_file']['size']
77
- );
 
 
78
 
79
- header('Content-Type: text/html; charset=' . get_option('blog_charset'));
80
 
81
  $attach = $this->handle_upload( $upload );
82
 
83
  if ( $attach['success'] ) {
 
84
 
85
- $response = array( 'success' => true );
86
-
87
- if ($image_only) {
88
  $image_size = wpuf_get_option( 'insert_photo_size', 'wpuf_frontend_posting', 'thumbnail' );
89
  $image_type = wpuf_get_option( 'insert_photo_type', 'wpuf_frontend_posting', 'link' );
90
 
@@ -93,17 +95,39 @@ class WPUF_Upload {
93
  } else {
94
  $response['html'] = wp_get_attachment_image( $attach['attach_id'], $image_size );
95
  }
96
-
97
  } else {
98
  $response['html'] = $this->attach_html( $attach['attach_id'] );
99
  }
100
 
101
- echo $response['html'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  } else {
103
- echo $attach['error'];
104
  }
105
 
106
-
107
  // $response = array('success' => false, 'message' => $attach['error']);
108
  // echo json_encode( $response );
109
  exit;
@@ -113,47 +137,47 @@ class WPUF_Upload {
113
  * Generic function to upload a file
114
  *
115
  * @param string $field_name file input field name
 
116
  * @return bool|int attachment id on success, bool false instead
117
  */
118
- function handle_upload( $upload_data ) {
119
-
120
- $uploaded_file = wp_handle_upload( $upload_data, array('test_form' => false) );
121
 
122
  // If the wp_handle_upload call returned a local path for the image
123
  if ( isset( $uploaded_file['file'] ) ) {
124
- $file_loc = $uploaded_file['file'];
125
  $file_name = basename( $upload_data['name'] );
126
  $file_type = wp_check_filetype( $file_name );
127
 
128
- $attachment = array(
129
  'post_mime_type' => $file_type['type'],
130
- 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_name ) ),
131
- 'post_content' => '',
132
- 'post_status' => 'inherit'
133
- );
134
 
135
- $attach_id = wp_insert_attachment( $attachment, $file_loc );
136
  $attach_data = wp_generate_attachment_metadata( $attach_id, $file_loc );
137
  wp_update_attachment_metadata( $attach_id, $attach_data );
138
 
139
- return array('success' => true, 'attach_id' => $attach_id);
140
  }
141
 
142
- return array('success' => false, 'error' => $uploaded_file['error']);
143
  }
144
 
145
- public static function attach_html( $attach_id, $type = NULL ) {
146
  if ( !$type ) {
147
- $type = isset( $_GET['type'] ) ? $_GET['type'] : 'image';
148
  }
149
 
150
  $attachment = get_post( $attach_id );
151
 
152
- if ( ! $attachment ) {
153
  return;
154
  }
155
 
156
- if (wp_attachment_is_image( $attach_id)) {
157
  $image = wp_get_attachment_image_src( $attach_id, 'thumbnail' );
158
  $image = $image[0];
159
  } else {
@@ -181,10 +205,10 @@ class WPUF_Upload {
181
  return $html;
182
  }
183
 
184
- function delete_file() {
185
  check_ajax_referer( 'wpuf_nonce', 'nonce' );
186
 
187
- $attach_id = isset( $_POST['attach_id'] ) ? intval( $_POST['attach_id'] ) : 0;
188
  $attachment = get_post( $attach_id );
189
 
190
  //post author or editor role
@@ -195,15 +219,14 @@ class WPUF_Upload {
195
  exit;
196
  }
197
 
198
- function associate_file( $attach_id, $post_id ) {
199
- wp_update_post( array(
200
- 'ID' => $attach_id,
201
- 'post_parent' => $post_id
202
- ) );
203
  }
204
 
205
- function insert_image() {
206
  $this->upload_file( true );
207
  }
208
-
209
  }
4
  * Attachment Uploader class
5
  *
6
  * @since 1.0
 
7
  */
8
  class WPUF_Upload {
9
 
10
+ public function __construct() {
11
+ add_action( 'wp_ajax_wpuf_upload_file', [$this, 'upload_file'] );
12
+ add_action( 'wp_ajax_nopriv_wpuf_upload_file', [$this, 'upload_file'] );
13
 
14
+ add_action( 'wp_ajax_wpuf_file_del', [$this, 'delete_file'] );
15
+ add_action( 'wp_ajax_nopriv_wpuf_file_del', [$this, 'delete_file'] );
16
 
17
+ add_action( 'wp_ajax_wpuf_insert_image', [ $this, 'insert_image' ] );
18
+ add_action( 'wp_ajax_nopriv_wpuf_insert_image', [ $this, 'insert_image' ] );
 
 
 
19
  }
20
 
21
  /**
23
  *
24
  * @return void
25
  */
26
+ public function validate_nonce() {
27
+ $nonce = isset( $_GET['nonce'] ) ? sanitize_key( wp_unslash( $_GET['nonce'] ) ) : '';
28
 
29
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf-upload-nonce' ) ) {
30
+ return ;
31
  }
32
  }
33
 
34
+ public function upload_file( $image_only = false ) {
35
+ $nonce = isset( $_GET['nonce'] ) ? sanitize_key( wp_unslash( $_GET['nonce'] ) ) : '';
36
+
37
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf-upload-nonce' ) ) {
38
+ return ;
39
+ }
40
 
41
  // a valid request will have a form ID
42
+ $form_id = isset( $_POST['form_id'] ) ? intval( wp_unslash( $_POST['form_id'] ) ) : false;
43
 
44
+ if ( !$form_id ) {
45
  die( 'error' );
46
  }
47
 
48
  // check if guest post enabled for guests
49
+ if ( !is_user_logged_in() ) {
 
50
  $guest_post = false;
51
  $form_settings = wpuf_get_form_settings( $form_id );
52
 
64
  $guest_post = true;
65
  }
66
 
67
+ if ( !$guest_post ) {
68
  die( 'error' );
69
  }
70
  }
71
 
72
+ $wpuf_file = isset( $_FILES['wpuf_file'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_FILES['wpuf_file'] ) ) : [];
73
+
74
+ $upload = [
75
+ 'name' => $wpuf_file['name'],
76
+ 'type' => $wpuf_file['type'],
77
+ 'tmp_name' => $wpuf_file['tmp_name'],
78
+ 'error' => $wpuf_file['error'],
79
+ 'size' => $wpuf_file['size'],
80
+ ];
81
 
82
+ header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
83
 
84
  $attach = $this->handle_upload( $upload );
85
 
86
  if ( $attach['success'] ) {
87
+ $response = [ 'success' => true ];
88
 
89
+ if ( $image_only ) {
 
 
90
  $image_size = wpuf_get_option( 'insert_photo_size', 'wpuf_frontend_posting', 'thumbnail' );
91
  $image_type = wpuf_get_option( 'insert_photo_type', 'wpuf_frontend_posting', 'link' );
92
 
95
  } else {
96
  $response['html'] = wp_get_attachment_image( $attach['attach_id'], $image_size );
97
  }
 
98
  } else {
99
  $response['html'] = $this->attach_html( $attach['attach_id'] );
100
  }
101
 
102
+ echo wp_kses( $response['html'], [
103
+ 'li' => [
104
+ 'class' => []
105
+ ],
106
+ 'div' => [
107
+ 'class' => []
108
+ ],
109
+ 'img' => [
110
+ 'src' => [],
111
+ 'alt' => [],
112
+ ],
113
+ 'input' => [
114
+ 'type' => [],
115
+ 'name' => [],
116
+ 'value' => [],
117
+ ],
118
+ 'a' => [
119
+ 'href' => [],
120
+ 'class' => [],
121
+ 'data-attach_id' => [],
122
+ ],
123
+ 'span' => [
124
+ 'class' => []
125
+ ]
126
+ ]);
127
  } else {
128
+ echo wp_kses_post( $attach['error'] );
129
  }
130
 
 
131
  // $response = array('success' => false, 'message' => $attach['error']);
132
  // echo json_encode( $response );
133
  exit;
137
  * Generic function to upload a file
138
  *
139
  * @param string $field_name file input field name
140
+ *
141
  * @return bool|int attachment id on success, bool false instead
142
  */
143
+ public function handle_upload( $upload_data ) {
144
+ $uploaded_file = wp_handle_upload( $upload_data, ['test_form' => false] );
 
145
 
146
  // If the wp_handle_upload call returned a local path for the image
147
  if ( isset( $uploaded_file['file'] ) ) {
148
+ $file_loc = $uploaded_file['file'];
149
  $file_name = basename( $upload_data['name'] );
150
  $file_type = wp_check_filetype( $file_name );
151
 
152
+ $attachment = [
153
  'post_mime_type' => $file_type['type'],
154
+ 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_name ) ),
155
+ 'post_content' => '',
156
+ 'post_status' => 'inherit',
157
+ ];
158
 
159
+ $attach_id = wp_insert_attachment( $attachment, $file_loc );
160
  $attach_data = wp_generate_attachment_metadata( $attach_id, $file_loc );
161
  wp_update_attachment_metadata( $attach_id, $attach_data );
162
 
163
+ return ['success' => true, 'attach_id' => $attach_id];
164
  }
165
 
166
+ return ['success' => false, 'error' => $uploaded_file['error']];
167
  }
168
 
169
+ public static function attach_html( $attach_id, $type = null ) {
170
  if ( !$type ) {
171
+ $type = isset( $_GET['type'] ) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : 'image';
172
  }
173
 
174
  $attachment = get_post( $attach_id );
175
 
176
+ if ( !$attachment ) {
177
  return;
178
  }
179
 
180
+ if ( wp_attachment_is_image( $attach_id ) ) {
181
  $image = wp_get_attachment_image_src( $attach_id, 'thumbnail' );
182
  $image = $image[0];
183
  } else {
205
  return $html;
206
  }
207
 
208
+ public function delete_file() {
209
  check_ajax_referer( 'wpuf_nonce', 'nonce' );
210
 
211
+ $attach_id = isset( $_POST['attach_id'] ) ? intval( wp_unslash( $_POST['attach_id'] ) ) : 0;
212
  $attachment = get_post( $attach_id );
213
 
214
  //post author or editor role
219
  exit;
220
  }
221
 
222
+ public function associate_file( $attach_id, $post_id ) {
223
+ wp_update_post( [
224
+ 'ID' => $attach_id,
225
+ 'post_parent' => $post_id,
226
+ ] );
227
  }
228
 
229
+ public function insert_image() {
230
  $this->upload_file( true );
231
  }
 
232
  }
includes/class-acf.php CHANGED
@@ -6,38 +6,39 @@
6
  class WPUF_ACF_Compatibility {
7
 
8
  public $id = 'acf';
 
9
  public $title = 'Advanced Custom Fields';
10
 
11
- function __construct() {
12
- add_action( 'admin_notices', array( $this, 'maybe_show_notice' ) );
13
 
14
- add_action( 'wp_ajax_wpuf_dismiss_notice_' . $this->id, array( $this, 'dismiss_notice' ) );
15
- add_action( 'wp_ajax_wpuf_compatibility_' . $this->id, array( $this, 'maybe_compatible' ) );
16
- add_action( 'wp_ajax_wpuf_migrate_' . $this->id, array( $this, 'migrate_cf_data' ) );
17
- }
18
 
19
  /**
20
  * See if ACF plugin exists
21
  *
22
- * @return boolean
23
  */
24
- public function plugin_exists() {
25
- return class_exists( 'acf' );
26
- }
27
 
28
  /**
29
  * If the prompt is dismissed
30
  *
31
- * @return boolean
32
  */
33
  public function is_dismissed() {
34
  return 'yes' == get_option( 'wpuf_dismiss_notice_' . $this->id );
35
  }
36
 
37
  /**
38
- * Check if
39
  *
40
- * @return boolean
41
  */
42
  public function is_compatible() {
43
  return 'yes' == wpuf_get_option( 'wpuf_compatibility_' . $this->id, 'wpuf_general', 'no' );
@@ -46,7 +47,7 @@ class WPUF_ACF_Compatibility {
46
  /**
47
  * Check if
48
  *
49
- * @return boolean
50
  */
51
  public function is_migrated() {
52
  return 'yes' == get_option( 'wpuf_migrate_' . $this->id );
@@ -93,15 +94,15 @@ class WPUF_ACF_Compatibility {
93
 
94
  if ( $meta == 'yes' && ( $field_type == 'checkbox' || $field_type == 'multiselect' ) ) {
95
  $meta_key = $attr['name'];
96
-
97
- $args = array(
98
  'post_type' => $post_type,
99
  'meta_key' => '_wpuf_form_id',
100
- );
101
- $posts = get_posts( $args );
102
 
103
  if ( !empty( $posts ) ) {
104
- foreach ($posts as $post) {
105
  $post_id = $post->ID;
106
  $separator = '| ';
107
  $meta_value = get_post_meta( $post_id, $meta_key );
@@ -126,16 +127,17 @@ class WPUF_ACF_Compatibility {
126
  }
127
 
128
  /**
129
- * Get all post form
130
  *
131
  *@return array
132
  */
133
  public function get_post_forms() {
134
- $args = array(
135
  'post_type' => 'wpuf_forms',
136
  'post_status' => 'publish',
137
- );
138
- return $form_posts = get_posts( $args );
 
139
  }
140
 
141
  /**
@@ -149,42 +151,40 @@ class WPUF_ACF_Compatibility {
149
  wp_send_json_success();
150
  }
151
 
152
- /**
153
  * Show notice if the plugin found
154
  *
155
  * @return void
156
  */
157
  public function maybe_show_notice() {
158
- if ( ! $this->plugin_exists() ) {
159
  return;
160
  }
161
 
162
  if ( $this->is_dismissed() || $this->is_compatible() || $this->is_migrated() || !current_user_can( 'manage_options' ) ) {
163
  return;
164
- }
165
-
166
- ?>
167
  <div class="notice notice-info">
168
- <p><strong><?php printf( __( '%s Detected', 'wp-user-frontend' ), $this->title ); ?></strong></p>
169
- <p><?php printf( __( 'Hey, looks like you have <strong>%s</strong> installed. What do you want to do with WPUF?', 'wp-user-frontend' ), $this->title ); ?></p>
170
- <p><i><strong style="color:#46b450;">Compatible: </strong><?php printf( __( 'It will update compatibility option only, so existing custom fields data format will not change.', 'wp-user-frontend' ) ); ?></i></p>
171
- <p><i><strong style="color:#46b450;">Compatible & Migrate: </strong><?php printf( __( 'It will update existing custom fields data to ACF format and update compatibility option too.', 'wp-user-frontend' ) ); ?></i></p>
172
 
173
  <p>
174
- <a href="#" class="button button-primary" id="wpuf-compatible-<?php echo $this->id ;?>"><?php _e( 'Compatible', 'wp-user-frontend' ); ?></a>
175
- <a href="#" class="button button-primary" id="wpuf-migrate-<?php echo $this->id ;?>"><?php _e( 'Compatible & Migrate', 'wp-user-frontend' ); ?></a>
176
- <a href="#" class="button" id="wpuf-dismiss-<?php echo $this->id ;?>"><?php _e( 'No Thanks', 'wp-user-frontend' ); ?></a>
177
  </p>
178
  </div>
179
 
180
  <script type="text/javascript">
181
  jQuery(function($) {
182
- $('.notice').on('click', 'a#wpuf-compatible-<?php echo $this->id ;?>', function(e) {
183
  e.preventDefault();
184
 
185
  var self = $(this);
186
  self.addClass('updating-message');
187
- wp.ajax.send('wpuf_compatibility_<?php echo $this->id ;?>', {
188
  success: function() {
189
  var html = '<p><strong>Compatible Option Updated</strong></p>';
190
 
@@ -199,16 +199,16 @@ class WPUF_ACF_Compatibility {
199
 
200
  complete: function() {
201
  self.removeClass('updating-message');
202
- }
203
  });
204
  });
205
 
206
- $('.notice').on('click', 'a#wpuf-migrate-<?php echo $this->id ;?>', function(e) {
207
  e.preventDefault();
208
 
209
  var self = $(this);
210
  self.addClass('updating-message');
211
- wp.ajax.send('wpuf_migrate_<?php echo $this->id ;?>', {
212
  success: function() {
213
  var html = '<p><strong>Compatible option and existing custom fields data updated</strong></p>';
214
 
@@ -223,20 +223,20 @@ class WPUF_ACF_Compatibility {
223
 
224
  complete: function() {
225
  self.removeClass('updating-message');
226
- }
227
  });
228
  });
229
 
230
- $('.notice').on('click', '#wpuf-dismiss-<?php echo $this->id ;?>', function(e) {
231
  e.preventDefault();
232
 
233
  $(this).closest('.notice').remove();
234
- wp.ajax.send('wpuf_dismiss_notice_<?php echo $this->id ;?>');
235
  });
236
 
237
  });
238
  </script>
239
-
240
  <?php
241
  }
242
- }
6
  class WPUF_ACF_Compatibility {
7
 
8
  public $id = 'acf';
9
+
10
  public $title = 'Advanced Custom Fields';
11
 
12
+ public function __construct() {
13
+ add_action( 'admin_notices', [ $this, 'maybe_show_notice' ] );
14
 
15
+ add_action( 'wp_ajax_wpuf_dismiss_notice_' . $this->id, [ $this, 'dismiss_notice' ] );
16
+ add_action( 'wp_ajax_wpuf_compatibility_' . $this->id, [ $this, 'maybe_compatible' ] );
17
+ add_action( 'wp_ajax_wpuf_migrate_' . $this->id, [ $this, 'migrate_cf_data' ] );
18
+ }
19
 
20
  /**
21
  * See if ACF plugin exists
22
  *
23
+ * @return bool
24
  */
25
+ public function plugin_exists() {
26
+ return class_exists( 'acf' );
27
+ }
28
 
29
  /**
30
  * If the prompt is dismissed
31
  *
32
+ * @return bool
33
  */
34
  public function is_dismissed() {
35
  return 'yes' == get_option( 'wpuf_dismiss_notice_' . $this->id );
36
  }
37
 
38
  /**
39
+ * Check if
40
  *
41
+ * @return bool
42
  */
43
  public function is_compatible() {
44
  return 'yes' == wpuf_get_option( 'wpuf_compatibility_' . $this->id, 'wpuf_general', 'no' );
47
  /**
48
  * Check if
49
  *
50
+ * @return bool
51
  */
52
  public function is_migrated() {
53
  return 'yes' == get_option( 'wpuf_migrate_' . $this->id );
94
 
95
  if ( $meta == 'yes' && ( $field_type == 'checkbox' || $field_type == 'multiselect' ) ) {
96
  $meta_key = $attr['name'];
97
+
98
+ $args = [
99
  'post_type' => $post_type,
100
  'meta_key' => '_wpuf_form_id',
101
+ ];
102
+ $posts = get_posts( $args );
103
 
104
  if ( !empty( $posts ) ) {
105
+ foreach ( $posts as $post ) {
106
  $post_id = $post->ID;
107
  $separator = '| ';
108
  $meta_value = get_post_meta( $post_id, $meta_key );
127
  }
128
 
129
  /**
130
+ * Get all post form
131
  *
132
  *@return array
133
  */
134
  public function get_post_forms() {
135
+ $args = [
136
  'post_type' => 'wpuf_forms',
137
  'post_status' => 'publish',
138
+ ];
139
+
140
+ return $form_posts = get_posts( $args );
141
  }
142
 
143
  /**
151
  wp_send_json_success();
152
  }
153
 
154
+ /**
155
  * Show notice if the plugin found
156
  *
157
  * @return void
158
  */
159
  public function maybe_show_notice() {
160
+ if ( !$this->plugin_exists() ) {
161
  return;
162
  }
163
 
164
  if ( $this->is_dismissed() || $this->is_compatible() || $this->is_migrated() || !current_user_can( 'manage_options' ) ) {
165
  return;
166
+ } ?>
 
 
167
  <div class="notice notice-info">
168
+ <p><strong><?php printf( esc_html( __( '%s Detected', 'wp-user-frontend' ) ), esc_html( $this->title ) ); ?></strong></p>
169
+ <p><?php printf( wp_kses_post( __( 'Hey, looks like you have <strong>%s</strong> installed. What do you want to do with WPUF?', 'wp-user-frontend' ) ), esc_html( $this->title ) ); ?></p>
170
+ <p><i><strong style="color:#46b450;">Compatible: </strong><?php printf( esc_html( __( 'It will update compatibility option only, so existing custom fields data format will not change.', 'wp-user-frontend' ) ) ); ?></i></p>
171
+ <p><i><strong style="color:#46b450;">Compatible & Migrate: </strong><?php printf( esc_html( __( 'It will update existing custom fields data to ACF format and update compatibility option too.', 'wp-user-frontend' ) ) ); ?></i></p>
172
 
173
  <p>
174
+ <a href="#" class="button button-primary" id="wpuf-compatible-<?php echo esc_attr( $this->id ); ?>"><?php esc_html_e( 'Compatible', 'wp-user-frontend' ); ?></a>
175
+ <a href="#" class="button button-primary" id="wpuf-migrate-<?php echo esc_attr( $this->id ); ?>"><?php esc_html_e( 'Compatible & Migrate', 'wp-user-frontend' ); ?></a>
176
+ <a href="#" class="button" id="wpuf-dismiss-<?php echo esc_attr( $this->id ); ?>"><?php esc_html_e( 'No Thanks', 'wp-user-frontend' ); ?></a>
177
  </p>
178
  </div>
179
 
180
  <script type="text/javascript">
181
  jQuery(function($) {
182
+ $('.notice').on('click', 'a#wpuf-compatible-<?php echo esc_attr( $this->id ); ?>', function(e) {
183
  e.preventDefault();
184
 
185
  var self = $(this);
186
  self.addClass('updating-message');
187
+ wp.ajax.send('wpuf_compatibility_<?php echo esc_attr( $this->id ); ?>', {
188
  success: function() {
189
  var html = '<p><strong>Compatible Option Updated</strong></p>';
190
 
199
 
200
  complete: function() {
201
  self.removeClass('updating-message');
202
+ }
203
  });
204
  });
205
 
206
+ $('.notice').on('click', 'a#wpuf-migrate-<?php echo esc_attr( $this->id ); ?>', function(e) {
207
  e.preventDefault();
208
 
209
  var self = $(this);
210
  self.addClass('updating-message');
211
+ wp.ajax.send('wpuf_migrate_<?php echo esc_attr( $this->id ); ?>', {
212
  success: function() {
213
  var html = '<p><strong>Compatible option and existing custom fields data updated</strong></p>';
214
 
223
 
224
  complete: function() {
225
  self.removeClass('updating-message');
226
+ }
227
  });
228
  });
229
 
230
+ $('.notice').on('click', '#wpuf-dismiss-<?php echo esc_attr( $this->id ); ?>', function(e) {
231
  e.preventDefault();
232
 
233
  $(this).closest('.notice').remove();
234
+ wp.ajax.send('wpuf_dismiss_notice_<?php echo esc_attr( $this->id ); ?>');
235
  });
236
 
237
  });
238
  </script>
239
+
240
  <?php
241
  }
242
+ }
includes/class-billing-address.php CHANGED
@@ -1,16 +1,14 @@
1
  <?php
2
 
3
- /*
4
  * Ajax Address Form Class
5
- *
6
  */
7
-
8
  class WPUF_Ajax_Address_Form {
9
 
10
  public function __construct() {
11
- add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_scripts' ) );
12
- add_action( 'wp_ajax_wpuf_address_ajax_action', array( $this, 'ajax_form_action' ), 10, 1 );
13
- add_action( 'wp_ajax_nopriv_wpuf_address_ajax_action', array( $this, 'ajax_form_action' ), 10, 1 );
14
  }
15
 
16
  /**
@@ -18,6 +16,7 @@ class WPUF_Ajax_Address_Form {
18
  */
19
  public function register_plugin_scripts() {
20
  global $post;
 
21
  $pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
22
 
23
  if ( wpuf_get_option( 'load_script', 'wpuf_general', 'on' ) == 'on' ) {
@@ -31,8 +30,8 @@ class WPUF_Ajax_Address_Form {
31
  * Load billing scripts
32
  */
33
  public function plugin_scripts() {
34
- wp_enqueue_script( 'wpuf-ajax-script', plugins_url( 'assets/js/billing-address.js', dirname( __FILE__ ) ), array('jquery'), false );
35
- wp_localize_script( 'wpuf-ajax-script', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'fill_notice' => __( 'Some Required Fields are not filled!', 'wp-user-frontend' ) ) ) ;
36
  }
37
 
38
  /**
@@ -51,8 +50,19 @@ class WPUF_Ajax_Address_Form {
51
  $required_class = 'bill_required';
52
  $req_div = '<span class="required">*</span>';
53
 
54
- $country_req = ''; $country_hide = ''; $state_req = ''; $state_hide = ''; $add1_req = ''; $add1_hide = '';
55
- $add2_req = ''; $add2_hide = ''; $city_req = ''; $city_hide = ''; $zip_req = ''; $zip_hide = ''; $required = '';
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  if ( $show_country == 'hidden' ) {
58
  $show_state = 'hidden';
@@ -62,35 +72,46 @@ class WPUF_Ajax_Address_Form {
62
  case 'required':
63
  $country_required = true;
64
  break;
 
65
  case 'hidden':
66
  $country_hide = 'display: none;';
 
67
  default:
68
  break;
69
  }
 
70
  switch ( $show_state ) {
71
  case 'required':
72
  $state_required = true;
73
  break;
 
74
  case 'hidden':
75
  $state_hide = 'display: none;';
 
76
  default:
77
  break;
78
  }
 
79
  switch ( $show_add1 ) {
80
  case 'required':
81
  $address1_required = true;
82
  break;
 
83
  case 'hidden':
84
  $add1_hide = 'display: none;';
 
85
  default:
86
  break;
87
  }
 
88
  switch ( $show_add2 ) {
89
  case 'required':
90
  $address2_required = true;
91
  break;
 
92
  case 'hidden':
93
  $add2_hide = 'display: none;';
 
94
  default:
95
  break;
96
  }
@@ -98,8 +119,10 @@ class WPUF_Ajax_Address_Form {
98
  case 'required':
99
  $city_required = true;
100
  break;
 
101
  case 'hidden':
102
  $city_hide = 'display: none;';
 
103
  default:
104
  break;
105
  }
@@ -107,8 +130,10 @@ class WPUF_Ajax_Address_Form {
107
  case 'required':
108
  $zip_required = true;
109
  break;
 
110
  case 'hidden':
111
  $zip_hide = 'display: none;';
 
112
  default:
113
  break;
114
  }
@@ -117,87 +142,88 @@ class WPUF_Ajax_Address_Form {
117
  ?>
118
 
119
  <form class="wpuf-form form-label-above" id="wpuf-ajax-address-form" action="" method="post">
 
 
120
  <table id="wpuf-address-country-state" class="wp-list-table widefat">
121
  <tr>
122
- <td class="<?php echo isset( $country_required ) ? $required_class : null; ?>" style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $country_hide; ?>">
123
- <label><?php _e( "Country", "wp-user-frontend" ); ?><?php echo isset( $country_required ) ? $req_div : null; ?></label>
124
  <br>
125
  <?php
126
- if (function_exists('wpuf_get_tax_rates')) {
127
  $rates = wpuf_get_tax_rates();
128
  }
129
- $cs = new CountryState();
130
- $states = array();
131
- $selected = array();
132
- $base_addr = get_option('wpuf_base_country_state', false);
133
-
134
- $selected['country'] = !(empty($address_fields['country'])) ? $address_fields['country'] : $base_addr['country'];
135
-
136
- echo wpuf_select(array(
137
- 'options' => $cs->countries(),
138
- 'name' => 'wpuf_biiling_country',
139
- 'selected' => $selected['country'],
140
- 'show_option_all' => false,
 
141
  'show_option_none' => false,
142
- 'id' => 'wpuf_biiling_country',
143
- 'class' => 'wpuf_biiling_country',
144
- 'chosen' => false,
145
- 'placeholder' => __('Choose a country', 'wp-user-frontend')
146
- ));
147
- ?>
148
  </td>
149
- <td class="<?php echo isset( $state_required ) ? $required_class : null; ?>" style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $state_hide;?>">
150
- <label><?php _e( "State/Province/Region", "wp-user-frontend" ); ?><?php echo isset( $state_required ) ? $req_div : null; ?></label>
151
  <br>
152
  <?php
153
- $states = $cs->getStates($selected['country']);
154
- $selected['state'] = !(empty($address_fields['state'])) ? $address_fields['state'] : $base_addr['state'];
155
- echo wpuf_select(array(
156
- 'options' => $states,
157
- 'name' => 'wpuf_biiling_state',
158
- 'selected' => $selected['state'],
159
- 'show_option_all' => false,
160
  'show_option_none' => false,
161
- 'id' => 'wpuf_biiling_state',
162
- 'class' => 'wpuf_biiling_state',
163
- 'chosen' => false,
164
- 'placeholder' => __('Choose a state', 'wp-user-frontend')
165
- ));
166
- ?>
167
  </td>
168
- <td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $add1_hide;?>">
169
- <div class="wpuf-label"><?php _e('Address Line 1 ', 'wp-user-frontend'); ?><?php echo isset( $address1_required ) ? $req_div : null; ?></div>
170
  <div class="wpuf-fields">
171
- <input type="text" class="input <?php echo isset( $address1_required ) ? $required_class : null; ?>" name="wpuf_biiling_add_line_1"
172
  id="wpuf_biiling_add_line_1"
173
- value="<?php echo $address_fields['add_line_1']; ?>"/>
174
  </div>
175
  </td>
176
- <td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $add2_hide;?>">
177
- <div class="wpuf-label"><?php _e('Address Line 2 ', 'wp-user-frontend'); ?><?php echo isset( $address2_required ) ? $req_div : null; ?></div>
178
  <div class="wpuf-fields">
179
- <input type="text" class="input <?php echo isset( $address2_required ) ? $required_class : null; ?>" name="wpuf_biiling_add_line_2"
180
  id="wpuf_biiling_add_line_2"
181
- value="<?php echo $address_fields['add_line_2']; ?>"/>
182
  </div>
183
  </td>
184
- <td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $city_hide; ?>">
185
- <div class="wpuf-label"><?php _e('City', 'wp-user-frontend'); ?><?php echo isset( $city_required ) ? $req_div : null; ?></div>
186
  <div class="wpuf-fields">
187
- <input type="text" class="input <?php echo isset( $city_required ) ? $required_class : null; ?>" name="wpuf_biiling_city" id="wpuf_biiling_city"
188
- value="<?php echo $address_fields['city']; ?>"/>
189
  </div>
190
  </td>
191
- <td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $zip_hide; ?>">
192
- <div class="wpuf-label"><?php _e('Postal Code/ZIP', 'wp-user-frontend'); ?><?php echo isset( $zip_required ) ? $req_div : null; ?></div>
193
  <div class="wpuf-fields">
194
- <input type="text" class="input <?php echo isset( $zip_required ) ? $required_class : null; ?>" name="wpuf_biiling_zip_code" id="wpuf_biiling_zip_code"
195
- value="<?php echo $address_fields['zip_code']; ?>"/>
196
  </div>
197
  </td>
198
- <td class="<?php echo $required; ?>" class="wpuf-submit" style="display:none;">
199
  <input type="submit" class="wpuf-btn" name="submit" id="wpuf-account-update-billing_address"
200
- value="<?php _e('Update Billing Address', 'wp-user-frontend'); ?>"/>
201
  </td>
202
  </tr>
203
 
@@ -209,41 +235,49 @@ class WPUF_Ajax_Address_Form {
209
  }
210
  }
211
 
212
-
213
  /**
214
  * Ajax Form action
215
  */
216
  public function ajax_form_action() {
217
- if (isset($_POST)) {
218
- parse_str($_POST["data"], $_POST);
 
 
 
 
 
 
 
219
 
220
  $user_id = get_current_user_id();
221
 
222
- $address_fields = array();
223
 
224
- if ( isset( $_POST['wpuf_biiling_add_line_1'] )
225
- && isset( $_POST['wpuf_biiling_city'] )
226
- && isset( $_POST['wpuf_biiling_state'] )
227
- && isset( $_POST['wpuf_biiling_zip_code'] )
228
- && isset( $_POST['wpuf_biiling_country'] ) ) {
229
 
230
- $address_fields = array(
231
- 'add_line_1' => $_POST['wpuf_biiling_add_line_1'],
232
- 'add_line_2' => $_POST['wpuf_biiling_add_line_2'],
233
- 'city' => $_POST['wpuf_biiling_city'],
234
- 'state' => $_POST['wpuf_biiling_state'],
235
- 'zip_code' => $_POST['wpuf_biiling_zip_code'],
236
- 'country' => $_POST['wpuf_biiling_country']
237
- );
 
 
 
 
 
238
 
239
  update_user_meta( $user_id, 'wpuf_address_fields', $address_fields );
240
 
241
  $msg = '<div class="wpuf-success">' . __( 'Billing address is updated.', 'wp-user-frontend' ) . '</div>';
242
 
243
- echo $msg;
244
  exit();
245
  }
246
  }
247
  }
248
-
249
  }
1
  <?php
2
 
3
+ /**
4
  * Ajax Address Form Class
 
5
  */
 
6
  class WPUF_Ajax_Address_Form {
7
 
8
  public function __construct() {
9
+ add_action( 'wp_enqueue_scripts', [ $this, 'register_plugin_scripts' ] );
10
+ add_action( 'wp_ajax_wpuf_address_ajax_action', [ $this, 'ajax_form_action' ], 10, 1 );
11
+ add_action( 'wp_ajax_nopriv_wpuf_address_ajax_action', [ $this, 'ajax_form_action' ], 10, 1 );
12
  }
13
 
14
  /**
16
  */
17
  public function register_plugin_scripts() {
18
  global $post;
19
+
20
  $pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
21
 
22
  if ( wpuf_get_option( 'load_script', 'wpuf_general', 'on' ) == 'on' ) {
30
  * Load billing scripts
31
  */
32
  public function plugin_scripts() {
33
+ wp_enqueue_script( 'wpuf-ajax-script', plugins_url( 'assets/js/billing-address.js', __DIR__ ), ['jquery'], false );
34
+ wp_localize_script( 'wpuf-ajax-script', 'ajax_object', [ 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'fill_notice' => __( 'Some Required Fields are not filled!', 'wp-user-frontend' ) ] );
35
  }
36
 
37
  /**
50
  $required_class = 'bill_required';
51
  $req_div = '<span class="required">*</span>';
52
 
53
+ $country_req = '';
54
+ $country_hide = '';
55
+ $state_req = '';
56
+ $state_hide = '';
57
+ $add1_req = '';
58
+ $add1_hide = '';
59
+ $add2_req = '';
60
+ $add2_hide = '';
61
+ $city_req = '';
62
+ $city_hide = '';
63
+ $zip_req = '';
64
+ $zip_hide = '';
65
+ $required = '';
66
 
67
  if ( $show_country == 'hidden' ) {
68
  $show_state = 'hidden';
72
  case 'required':
73
  $country_required = true;
74
  break;
75
+
76
  case 'hidden':
77
  $country_hide = 'display: none;';
78
+ // no break
79
  default:
80
  break;
81
  }
82
+
83
  switch ( $show_state ) {
84
  case 'required':
85
  $state_required = true;
86
  break;
87
+
88
  case 'hidden':
89
  $state_hide = 'display: none;';
90
+ // no break
91
  default:
92
  break;
93
  }
94
+
95
  switch ( $show_add1 ) {
96
  case 'required':
97
  $address1_required = true;
98
  break;
99
+
100
  case 'hidden':
101
  $add1_hide = 'display: none;';
102
+ // no break
103
  default:
104
  break;
105
  }
106
+
107
  switch ( $show_add2 ) {
108
  case 'required':
109
  $address2_required = true;
110
  break;
111
+
112
  case 'hidden':
113
  $add2_hide = 'display: none;';
114
+ // no break
115
  default:
116
  break;
117
  }
119
  case 'required':
120
  $city_required = true;
121
  break;
122
+
123
  case 'hidden':
124
  $city_hide = 'display: none;';
125
+ // no break
126
  default:
127
  break;
128
  }
130
  case 'required':
131
  $zip_required = true;
132
  break;
133
+
134
  case 'hidden':
135
  $zip_hide = 'display: none;';
136
+ // no break
137
  default:
138
  break;
139
  }
142
  ?>
143
 
144
  <form class="wpuf-form form-label-above" id="wpuf-ajax-address-form" action="" method="post">
145
+ <?php wp_nonce_field( 'wpuf-ajax-address' ); ?>
146
+
147
  <table id="wpuf-address-country-state" class="wp-list-table widefat">
148
  <tr>
149
+ <td class="<?php echo isset( $country_required ) ? esc_attr( $required_class ) : null; ?>" style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo esc_attr( $country_hide ); ?>">
150
+ <label><?php esc_html_e( 'Country', 'wp-user-frontend' ); ?><?php echo isset( $country_required ) ? esc_attr( $req_div ) : null; ?></label>
151
  <br>
152
  <?php
153
+ if ( function_exists( 'wpuf_get_tax_rates' ) ) {
154
  $rates = wpuf_get_tax_rates();
155
  }
156
+
157
+ $cs = new CountryState();
158
+ $states = [];
159
+ $selected = [];
160
+ $base_addr = get_option( 'wpuf_base_country_state', false );
161
+
162
+ $selected['country'] = !( empty( $address_fields['country'] ) ) ? $address_fields['country'] : $base_addr['country'];
163
+
164
+ echo wp_kses_post( wpuf_select( [
165
+ 'options' => $cs->countries(),
166
+ 'name' => 'wpuf_biiling_country',
167
+ 'selected' => $selected['country'],
168
+ 'show_option_all' => false,
169
  'show_option_none' => false,
170
+ 'id' => 'wpuf_biiling_country',
171
+ 'class' => 'wpuf_biiling_country',
172
+ 'chosen' => false,
173
+ 'placeholder' => __( 'Choose a country', 'wp-user-frontend' ),
174
+ ] ) ); ?>
 
175
  </td>
176
+ <td class="<?php echo isset( $state_required ) ? esc_attr( $required_class ) : null; ?>" style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo esc_attr( $state_hide ); ?>">
177
+ <label><?php esc_html_e( 'State/Province/Region', 'wp-user-frontend' ); ?><?php echo isset( $state_required ) ? esc_attr( $req_div ) : null; ?></label>
178
  <br>
179
  <?php
180
+ $states = $cs->getStates( $selected['country'] );
181
+ $selected['state'] = !( empty( $address_fields['state'] ) ) ? $address_fields['state'] : $base_addr['state'];
182
+ echo wp_kses_post( wpuf_select( [
183
+ 'options' => $states,
184
+ 'name' => 'wpuf_biiling_state',
185
+ 'selected' => $selected['state'],
186
+ 'show_option_all' => false,
187
  'show_option_none' => false,
188
+ 'id' => 'wpuf_biiling_state',
189
+ 'class' => 'wpuf_biiling_state',
190
+ 'chosen' => false,
191
+ 'placeholder' => __( 'Choose a state', 'wp-user-frontend' ),
192
+ ] ) ); ?>
 
193
  </td>
194
+ <td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo esc_attr( $add1_hide ); ?>">
195
+ <div class="wpuf-label"><?php esc_html_e( 'Address Line 1 ', 'wp-user-frontend' ); ?><?php echo isset( $address1_required ) ? esc_attr( $req_div ) : null; ?></div>
196
  <div class="wpuf-fields">
197
+ <input type="text" class="input <?php echo isset( $address1_required ) ? esc_attr( $required_class ) : null; ?>" name="wpuf_biiling_add_line_1"
198
  id="wpuf_biiling_add_line_1"
199
+ value="<?php echo esc_attr( $address_fields['add_line_1'] ); ?>"/>
200
  </div>
201
  </td>
202
+ <td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo esc_attr( $add2_hide ); ?>">
203
+ <div class="wpuf-label"><?php esc_html_e( 'Address Line 2 ', 'wp-user-frontend' ); ?><?php echo isset( $address2_required ) ? esc_attr( $req_div ) : null; ?></div>
204
  <div class="wpuf-fields">
205
+ <input type="text" class="input <?php echo isset( $address2_required ) ? esc_attr( $required_class ) : null; ?>" name="wpuf_biiling_add_line_2"
206
  id="wpuf_biiling_add_line_2"
207
+ value="<?php echo esc_attr( $address_fields['add_line_2'] ); ?>"/>
208
  </div>
209
  </td>
210
+ <td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo esc_attr( $city_hide ); ?>">
211
+ <div class="wpuf-label"><?php esc_html_e( 'City', 'wp-user-frontend' ); ?><?php echo isset( $city_required ) ? esc_attr( $req_div ) : null; ?></div>
212
  <div class="wpuf-fields">
213
+ <input type="text" class="input <?php echo isset( $city_required ) ? esc_attr( $required_class ) : null; ?>" name="wpuf_biiling_city" id="wpuf_biiling_city"
214
+ value="<?php echo esc_attr( $address_fields['city'] ); ?>"/>
215
  </div>
216
  </td>
217
+ <td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo esc_attr( $zip_hide ); ?>">
218
+ <div class="wpuf-label"><?php esc_html_e( 'Postal Code/ZIP', 'wp-user-frontend' ); ?><?php echo isset( $zip_required ) ? esc_attr( $req_div ) : null; ?></div>
219
  <div class="wpuf-fields">
220
+ <input type="text" class="input <?php echo isset( $zip_required ) ? esc_attr( $required_class ) : null; ?>" name="wpuf_biiling_zip_code" id="wpuf_biiling_zip_code"
221
+ value="<?php echo esc_attr( $address_fields['zip_code'] ); ?>"/>
222
  </div>
223
  </td>
224
+ <td class="<?php echo esc_attr( $required ); ?>" class="wpuf-submit" style="display:none;">
225
  <input type="submit" class="wpuf-btn" name="submit" id="wpuf-account-update-billing_address"
226
+ value="<?php esc_html_e( 'Update Billing Address', 'wp-user-frontend' ); ?>"/>
227
  </td>
228
  </tr>
229
 
235
  }
236
  }
237
 
 
238
  /**
239
  * Ajax Form action
240
  */
241
  public function ajax_form_action() {
242
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
243
+
244
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'wpuf-ajax-address' ) ) {
245
+ return ;
246
+ }
247
+
248
+ if ( isset( $_POST ) ) {
249
+ $post_data = isset( $_POST['data'] ) ? sanitize_text_field( wp_unslash( $_POST['data'] ) ) : '';
250
+ parse_str( $post_data, $_POST );
251
 
252
  $user_id = get_current_user_id();
253
 
254
+ $address_fields = [];
255
 
256
+ $add_line_1 = isset( $_POST['wpuf_biiling_add_line_1'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_biiling_add_line_1'] ) ) : '';
257
+ $add_line_2 = isset( $_POST['wpuf_biiling_add_line_2'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_biiling_add_line_2'] ) ) : '';
258
+ $city = isset( $_POST['wpuf_biiling_city'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_biiling_city'] ) ) : '';
 
 
259
 
260
+ $state = isset( $_POST['wpuf_biiling_state'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_biiling_state'] ) ) : '';
261
+ $zip_code = isset( $_POST['wpuf_biiling_state'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_biiling_state'] ) ) : '';
262
+ $country = isset( $_POST['wpuf_biiling_country'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_biiling_country'] ) ) : '';
263
+
264
+ if ( $add_line_1 && $city && $state && $zip_code && $country ) {
265
+ $address_fields = [
266
+ 'add_line_1' => $add_line_1,
267
+ 'add_line_2' => $add_line_2,
268
+ 'city' => $city,
269
+ 'state' => $state,
270
+ 'zip_code' => $zip_code,
271
+ 'country' => $country,
272
+ ];
273
 
274
  update_user_meta( $user_id, 'wpuf_address_fields', $address_fields );
275
 
276
  $msg = '<div class="wpuf-success">' . __( 'Billing address is updated.', 'wp-user-frontend' ) . '</div>';
277
 
278
+ echo wp_kses_post( $msg );
279
  exit();
280
  }
281
  }
282
  }
 
283
  }
includes/class-customizer.php CHANGED
@@ -3,23 +3,21 @@
3
  * WPUF_Customizer_Options class
4
  *
5
  * @since 2.8.9
6
- *
7
  */
8
-
9
- class WPUF_Customizer_Options{
10
 
11
  /**
12
  * Class constructor
13
  */
14
  public function __construct() {
15
- add_action( 'customize_register', array( $this, 'customizer_options' ) );
16
- add_action( 'wp_head', array( $this, 'save_customizer_options' ) );
17
  }
18
 
19
  public function save_customizer_options() {
20
- $address_options = array();
21
 
22
- $fields = array(
23
  'show_address' => __( 'Show Billing Address', 'wp-user-frontend' ),
24
  'country' => __( 'Country', 'wp-user-frontend' ),
25
  'state' => __( 'State/Province/Region', 'wp-user-frontend' ),
@@ -27,15 +25,14 @@ class WPUF_Customizer_Options{
27
  'address_2' => __( 'Address line 2', 'wp-user-frontend' ),
28
  'city' => __( 'City', 'wp-user-frontend' ),
29
  'zip' => __( 'Postal Code/ZIP', 'wp-user-frontend' ),
30
- );
 
31
  foreach ( $fields as $field => $label ) {
32
- $settings_name = 'wpuf_address_' . $field . '_settings';
33
  $address_options[$field] = get_theme_mod( $settings_name );
34
  }
35
 
36
- update_option( 'wpuf_address_options', $address_options );
37
-
38
- ?>
39
  <style>
40
 
41
  </style>
@@ -46,25 +43,25 @@ class WPUF_Customizer_Options{
46
 
47
  /* Add WPUF Panel to Customizer */
48
 
49
- $wp_customize->add_panel( 'wpuf_panel', array(
50
- 'title' => __( 'WP User Frontend', 'wp-user-frontend' ),
51
  'description' => __( 'Customize WPUF Settings', 'wp-user-frontend' ),
52
- 'priority' => 25,
53
- ) );
54
 
55
  /* WPUF Billing Address Customizer */
56
  $wp_customize->add_section(
57
  'wpuf_billing_address',
58
- array(
59
  'title' => __( 'Billing Address', 'wp-user-frontend' ),
60
  'priority' => 20,
61
  'panel' => 'wpuf_panel',
62
  'description' => __( 'These options let you change the appearance of the billing address.', 'wp-user-frontend' ),
63
- )
64
- );
65
 
66
  // Billing Address field controls.
67
- $fields = array(
68
  'show_address' => __( 'Show Billing Address', 'wp-user-frontend' ),
69
  'country' => __( 'Country', 'wp-user-frontend' ),
70
  'state' => __( 'State/Province/Region', 'wp-user-frontend' ),
@@ -72,44 +69,45 @@ class WPUF_Customizer_Options{
72
  'address_2' => __( 'Address line 2', 'wp-user-frontend' ),
73
  'city' => __( 'City', 'wp-user-frontend' ),
74
  'zip' => __( 'Postal Code/ZIP', 'wp-user-frontend' ),
75
- );
 
76
  foreach ( $fields as $field => $label ) {
77
  $wp_customize->add_setting(
78
  'wpuf_address_' . $field . '_settings',
79
- array(
80
  'type' => 'theme_mod',
81
  'section' => 'wpuf_billing_address',
82
- )
83
- );
 
84
  if ( $field == 'show_address' ) {
85
  $wp_customize->add_control(
86
  'wpuf_address_' . $field . '_control',
87
- array(
88
  /* Translators: %s field name. */
89
  'label' => sprintf( __( '%s field', 'wp-user-frontend' ), $label ),
90
  'section' => 'wpuf_billing_address',
91
  'settings' => 'wpuf_address_' . $field . '_settings',
92
  'type' => 'checkbox',
93
- )
94
- );
95
  } else {
96
  $wp_customize->add_control(
97
  'wpuf_address_' . $field . '_control',
98
- array(
99
  /* Translators: %s field name. */
100
  'label' => sprintf( __( '%s field', 'wp-user-frontend' ), $label ),
101
  'section' => 'wpuf_billing_address',
102
  'settings' => 'wpuf_address_' . $field . '_settings',
103
  'type' => 'select',
104
- 'choices' => array(
105
  'hidden' => __( 'Hidden', 'wp-user-frontend' ),
106
  'optional' => __( 'Optional', 'wp-user-frontend' ),
107
  'required' => __( 'Required', 'wp-user-frontend' ),
108
- ),
109
- )
110
- );
111
  }
112
  }
113
-
114
  }
115
  }
3
  * WPUF_Customizer_Options class
4
  *
5
  * @since 2.8.9
 
6
  */
7
+ class WPUF_Customizer_Options {
 
8
 
9
  /**
10
  * Class constructor
11
  */
12
  public function __construct() {
13
+ add_action( 'customize_register', [ $this, 'customizer_options' ] );
14
+ add_action( 'wp_head', [ $this, 'save_customizer_options' ] );
15
  }
16
 
17
  public function save_customizer_options() {
18
+ $address_options = [];
19
 
20
+ $fields = [
21
  'show_address' => __( 'Show Billing Address', 'wp-user-frontend' ),
22
  'country' => __( 'Country', 'wp-user-frontend' ),
23
  'state' => __( 'State/Province/Region', 'wp-user-frontend' ),
25
  'address_2' => __( 'Address line 2', 'wp-user-frontend' ),
26
  'city' => __( 'City', 'wp-user-frontend' ),
27
  'zip' => __( 'Postal Code/ZIP', 'wp-user-frontend' ),
28
+ ];
29
+
30
  foreach ( $fields as $field => $label ) {
31
+ $settings_name = 'wpuf_address_' . $field . '_settings';
32
  $address_options[$field] = get_theme_mod( $settings_name );
33
  }
34
 
35
+ update_option( 'wpuf_address_options', $address_options ); ?>
 
 
36
  <style>
37
 
38
  </style>
43
 
44
  /* Add WPUF Panel to Customizer */
45
 
46
+ $wp_customize->add_panel( 'wpuf_panel', [
47
+ 'title' => __( 'WP User Frontend', 'wp-user-frontend' ),
48
  'description' => __( 'Customize WPUF Settings', 'wp-user-frontend' ),
49
+ 'priority' => 25,
50
+ ] );
51
 
52
  /* WPUF Billing Address Customizer */
53
  $wp_customize->add_section(
54
  'wpuf_billing_address',
55
+ [
56
  'title' => __( 'Billing Address', 'wp-user-frontend' ),
57
  'priority' => 20,
58
  'panel' => 'wpuf_panel',
59
  'description' => __( 'These options let you change the appearance of the billing address.', 'wp-user-frontend' ),
60
+ ]
61
+ );
62
 
63
  // Billing Address field controls.
64
+ $fields = [
65
  'show_address' => __( 'Show Billing Address', 'wp-user-frontend' ),
66
  'country' => __( 'Country', 'wp-user-frontend' ),
67
  'state' => __( 'State/Province/Region', 'wp-user-frontend' ),
69
  'address_2' => __( 'Address line 2', 'wp-user-frontend' ),
70
  'city' => __( 'City', 'wp-user-frontend' ),
71
  'zip' => __( 'Postal Code/ZIP', 'wp-user-frontend' ),
72
+ ];
73
+
74
  foreach ( $fields as $field => $label ) {
75
  $wp_customize->add_setting(
76
  'wpuf_address_' . $field . '_settings',
77
+ [
78
  'type' => 'theme_mod',
79
  'section' => 'wpuf_billing_address',
80
+ ]
81
+ );
82
+
83
  if ( $field == 'show_address' ) {
84
  $wp_customize->add_control(
85
  'wpuf_address_' . $field . '_control',
86
+ [
87
  /* Translators: %s field name. */
88
  'label' => sprintf( __( '%s field', 'wp-user-frontend' ), $label ),
89
  'section' => 'wpuf_billing_address',
90
  'settings' => 'wpuf_address_' . $field . '_settings',
91
  'type' => 'checkbox',
92
+ ]
93
+ );
94
  } else {
95
  $wp_customize->add_control(
96
  'wpuf_address_' . $field . '_control',
97
+ [
98
  /* Translators: %s field name. */
99
  'label' => sprintf( __( '%s field', 'wp-user-frontend' ), $label ),
100
  'section' => 'wpuf_billing_address',
101
  'settings' => 'wpuf_address_' . $field . '_settings',
102
  'type' => 'select',
103
+ 'choices' => [
104
  'hidden' => __( 'Hidden', 'wp-user-frontend' ),
105
  'optional' => __( 'Optional', 'wp-user-frontend' ),
106
  'required' => __( 'Required', 'wp-user-frontend' ),
107
+ ],
108
+ ]
109
+ );
110
  }
111
  }
 
112
  }
113
  }
includes/class-dokan-integration.php CHANGED
@@ -1,171 +1,164 @@
1
  <?php
2
 
3
- if ( ! class_exists( 'WPUF_Dokan_Integration' ) ) :
4
-
5
- /**
6
- *
7
- * WPUF Dokan Integration Class
8
- *
9
- * @since 2.7
10
- */
11
- class WPUF_Dokan_Integration{
12
-
13
- function __construct() {
14
-
15
- add_filter( 'dokan_get_dashboard_nav', array($this, 'add_wpuf_posts_page' ) );
16
- add_action( 'dokan_load_custom_template', array( $this, 'load_wpuf_posts_template' ) );
17
- add_filter( 'dokan_query_var_filter', array( $this, 'register_wpuf_posts_queryvar' ) );
18
- add_filter( 'dokan_settings_fields', array( $this, 'dokan_wpuf_settings' ) );
19
- add_filter( 'wpuf_edit_post_link', array( $this, 'generate_edit_post_link' ) );
20
-
21
- }
22
-
23
- /**
24
- * Insert new URL's to the dashboard navigation bar
25
- *
26
- * @param array $urls
27
- *
28
- * @since 2.7
29
- *
30
- * @return array
31
- */
32
- public function add_wpuf_posts_page( $urls ) {
33
- $access = dokan_get_option( 'allow_wpuf_post', 'dokan_general' );
34
-
35
- if ( $access == 'on' ) {
36
- $urls['posts'] = array(
37
- 'title' => __( 'Posts', 'wp-user-frontend'),
38
- 'icon' => '<i class="fa fa-wordpress"></i>',
39
- 'url' => dokan_get_navigation_url( 'posts' ),
40
- 'pos' => 56
41
- );
42
- }
43
-
44
- return $urls;
45
- }
46
-
47
- /**
48
- * Load posts template
49
- *
50
- * @param array $query_vars
51
- *
52
- * @since 2.7
53
- *
54
- * @return void
55
- */
56
- public function load_wpuf_posts_template( $query_vars ) {
57
-
58
- if ( isset( $query_vars['posts'] ) ) {
59
- require_once WPUF_ROOT . '/templates/dokan/posts.php';
60
- }
61
-
62
- }
63
-
64
- /**
65
- * Register WPUF query var
66
- *
67
- * @param array $query_vars
68
- *
69
- * @since 2.7
70
- *
71
- * @return void
72
- */
73
- public function register_wpuf_posts_queryvar( $query_vars ) {
74
- $query_vars[] = 'posts';
75
-
76
- return $query_vars;
77
- }
78
-
79
- /**
80
- * Dokan settings for WPUF integration
81
- *
82
- * @param array $settings_fields
83
- *
84
- * @since 2.7
85
- *
86
- * @return array $settings_fields
87
- */
88
- public function dokan_wpuf_settings( $settings_fields ) {
89
-
90
- $settings_fields['dokan_general']['allow_wpuf_post'] = array(
91
- 'name' => 'allow_wpuf_post',
92
- 'label' => __( 'Allow Post', 'wp-user-frontend' ),
93
- 'desc' => __( 'Allow Vendors to submit post from dashboard area', 'wp-user-frontend' ),
94
- 'type' => 'checkbox',
95
- 'default' => 'off'
96
- );
97
-
98
- $settings_fields['dokan_general']['wpuf_post_forms'] = array(
99
- 'name' => 'wpuf_post_forms',
100
- 'label' => __( 'Select Post Form', 'wp-user-frontend' ),
101
- 'desc' => __( 'Select a post form that will show on the vendor dashboard.', 'wp-user-frontend' ),
102
- 'type' => 'select',
103
- 'options' => $this->get_post_forms(),
104
- 'default' => 'seller'
105
- );
106
-
107
- return $settings_fields;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  }
109
-
110
- /**
111
- * Get all the post forms
112
- *
113
- * @param str $post_type
114
- *
115
- * @since 2.7
116
- *
117
- * @return array $post_forms
118
- */
119
- public function get_post_forms( $post_type='post') {
120
- $post_forms = array();
121
-
122
- $args = array(
123
- 'post_type' => 'wpuf_forms',
124
- 'post_status' => 'publish',
125
- 'numberposts' => -1,
126
- );
127
-
128
- $form_posts = get_posts( $args );
129
-
130
- foreach ($form_posts as $form) {
131
- $form_settings = wpuf_get_form_settings($form->ID);
132
- $form_post_type = isset( $form_settings['post_type'] ) ? $form_settings['post_type'] : '';
133
-
134
- if ( $form_post_type == $post_type ) {
135
- $post_forms[$form->ID] = $form->post_title;
136
- }
137
- }
138
-
139
- return $post_forms;
140
- }
141
-
142
- /**
143
- * Generate edit post link
144
- *
145
- * @param str $url
146
- *
147
- * @since 2.7
148
- *
149
- * @return str $url
150
- */
151
- public function generate_edit_post_link( $url ) {
152
- global $post;
153
-
154
- $posts_page_url = dokan_get_navigation_url( 'posts' );
155
- $dashboard = (int) dokan_get_option( 'dashboard', 'dokan_pages' );
156
-
157
- if ( is_page( $dashboard ) ) {
158
- $url = add_query_arg(
159
- array(
160
- 'action' => 'edit-post',
161
- 'pid' => $post->ID
162
- ),
163
- $posts_page_url );
164
- }
165
-
166
- return $url;
167
- }
168
-
169
  }
170
-
171
- endif;
1
  <?php
2
 
3
+ if ( !class_exists( 'WPUF_Dokan_Integration' ) ) {
4
+
5
+ /**
6
+ * WPUF Dokan Integration Class
7
+ *
8
+ * @since 2.7
9
+ */
10
+ class WPUF_Dokan_Integration {
11
+
12
+ public function __construct() {
13
+ add_filter( 'dokan_get_dashboard_nav', [$this, 'add_wpuf_posts_page' ] );
14
+ add_action( 'dokan_load_custom_template', [ $this, 'load_wpuf_posts_template' ] );
15
+ add_filter( 'dokan_query_var_filter', [ $this, 'register_wpuf_posts_queryvar' ] );
16
+ add_filter( 'dokan_settings_fields', [ $this, 'dokan_wpuf_settings' ] );
17
+ add_filter( 'wpuf_edit_post_link', [ $this, 'generate_edit_post_link' ] );
18
+ }
19
+
20
+ /**
21
+ * Insert new URL's to the dashboard navigation bar
22
+ *
23
+ * @param array $urls
24
+ *
25
+ * @since 2.7
26
+ *
27
+ * @return array
28
+ */
29
+ public function add_wpuf_posts_page( $urls ) {
30
+ $access = dokan_get_option( 'allow_wpuf_post', 'dokan_general' );
31
+
32
+ if ( $access == 'on' ) {
33
+ $urls['posts'] = [
34
+ 'title' => __( 'Posts', 'wp-user-frontend' ),
35
+ 'icon' => '<i class="fa fa-wordpress"></i>',
36
+ 'url' => dokan_get_navigation_url( 'posts' ),
37
+ 'pos' => 56,
38
+ ];
39
+ }
40
+
41
+ return $urls;
42
+ }
43
+
44
+ /**
45
+ * Load posts template
46
+ *
47
+ * @param array $query_vars
48
+ *
49
+ * @since 2.7
50
+ *
51
+ * @return void
52
+ */
53
+ public function load_wpuf_posts_template( $query_vars ) {
54
+ if ( isset( $query_vars['posts'] ) ) {
55
+ require_once WPUF_ROOT . '/templates/dokan/posts.php';
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Register WPUF query var
61
+ *
62
+ * @param array $query_vars
63
+ *
64
+ * @since 2.7
65
+ *
66
+ * @return void
67
+ */
68
+ public function register_wpuf_posts_queryvar( $query_vars ) {
69
+ $query_vars[] = 'posts';
70
+
71
+ return $query_vars;
72
+ }
73
+
74
+ /**
75
+ * Dokan settings for WPUF integration
76
+ *
77
+ * @param array $settings_fields
78
+ *
79
+ * @since 2.7
80
+ *
81
+ * @return array $settings_fields
82
+ */
83
+ public function dokan_wpuf_settings( $settings_fields ) {
84
+ $settings_fields['dokan_general']['allow_wpuf_post'] = [
85
+ 'name' => 'allow_wpuf_post',
86
+ 'label' => __( 'Allow Post', 'wp-user-frontend' ),
87
+ 'desc' => __( 'Allow Vendors to submit post from dashboard area', 'wp-user-frontend' ),
88
+ 'type' => 'checkbox',
89
+ 'default' => 'off',
90
+ ];
91
+
92
+ $settings_fields['dokan_general']['wpuf_post_forms'] = [
93
+ 'name' => 'wpuf_post_forms',
94
+ 'label' => __( 'Select Post Form', 'wp-user-frontend' ),
95
+ 'desc' => __( 'Select a post form that will show on the vendor dashboard.', 'wp-user-frontend' ),
96
+ 'type' => 'select',
97
+ 'options' => $this->get_post_forms(),
98
+ 'default' => 'seller',
99
+ ];
100
+
101
+ return $settings_fields;
102
+ }
103
+
104
+ /**
105
+ * Get all the post forms
106
+ *
107
+ * @param string $post_type
108
+ *
109
+ * @since 2.7
110
+ *
111
+ * @return array $post_forms
112
+ */
113
+ public function get_post_forms( $post_type='post' ) {
114
+ $post_forms = [];
115
+
116
+ $args = [
117
+ 'post_type' => 'wpuf_forms',
118
+ 'post_status' => 'publish',
119
+ 'numberposts' => -1,
120
+ ];
121
+
122
+ $form_posts = get_posts( $args );
123
+
124
+ foreach ( $form_posts as $form ) {
125
+ $form_settings = wpuf_get_form_settings( $form->ID );
126
+ $form_post_type = isset( $form_settings['post_type'] ) ? $form_settings['post_type'] : '';
127
+
128
+ if ( $form_post_type == $post_type ) {
129
+ $post_forms[$form->ID] = $form->post_title;
130
+ }
131
+ }
132
+
133
+ return $post_forms;
134
+ }
135
+
136
+ /**
137
+ * Generate edit post link
138
+ *
139
+ * @param string $url
140
+ *
141
+ * @since 2.7
142
+ *
143
+ * @return string $url
144
+ */
145
+ public function generate_edit_post_link( $url ) {
146
+ global $post;
147
+
148
+ $posts_page_url = dokan_get_navigation_url( 'posts' );
149
+ $dashboard = (int) dokan_get_option( 'dashboard', 'dokan_pages' );
150
+
151
+ if ( is_page( $dashboard ) ) {
152
+ $url = add_query_arg(
153
+ [
154
+ 'action' => 'edit-post',
155
+ 'pid' => $post->ID,
156
+ ],
157
+ $posts_page_url
158
+ );
159
+ }
160
+
161
+ return $url;
162
+ }
163
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  }
 
 
includes/class-field-manager.php CHANGED
@@ -7,26 +7,21 @@
7
  */
8
  class WPUF_Field_Manager {
9
 
10
-
11
  /**
12
  * The fields
13
  *
14
  * @var array
15
- *
16
  */
17
- private $fields = array();
18
 
19
  /**
20
  * WP post types
21
  *
22
  * @var string
23
  */
24
- private $wp_post_types = array();
25
-
26
-
27
-
28
- function __construct() {
29
 
 
30
  }
31
 
32
  /**
@@ -35,8 +30,7 @@ class WPUF_Field_Manager {
35
  * @return array
36
  */
37
  public function get_fields() {
38
-
39
- if ( ! empty( $this->fields ) ) {
40
  return $this->fields;
41
  }
42
 
@@ -45,8 +39,6 @@ class WPUF_Field_Manager {
45
  return $this->fields;
46
  }
47
 
48
-
49
-
50
  /**
51
  * Add Post Field Type
52
  *
@@ -54,11 +46,8 @@ class WPUF_Field_Manager {
54
  *
55
  * @return void
56
  */
57
-
58
  public function add_field_settings( $field_settings ) {
59
-
60
  if ( class_exists( 'WPUF_Field_Contract' ) ) {
61
-
62
  require_once WPUF_ROOT . '/includes/fields/class-field-post-title.php';
63
  require_once WPUF_ROOT . '/includes/fields/class-field-post-content.php';
64
  require_once WPUF_ROOT . '/includes/fields/class-field-post-tags.php';
@@ -66,67 +55,57 @@ class WPUF_Field_Manager {
66
  require_once WPUF_ROOT . '/includes/fields/class-field-post-taxonomy.php';
67
  require_once WPUF_ROOT . '/includes/fields/class-field-featured-image.php';
68
 
69
- $field_settings['post_title'] = new WPUF_Form_Field_Post_Title();
70
- $field_settings['post_content'] = new WPUF_Form_Field_Post_Content();
71
- $field_settings['post_excerpt'] = new WPUF_Form_Field_Post_Excerpt();
72
  $field_settings['featured_image'] = new WPUF_Form_Field_Featured_Image();
73
 
74
-
75
- $taxonomy_templates = array();
76
 
77
  foreach ( $this->wp_post_types as $post_type => $taxonomies ) {
78
-
79
- if ( ! empty( $taxonomies ) ) {
80
-
81
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
82
  if ( 'post_tag' === $tax_name ) {
83
  // $taxonomy_templates['post_tag'] = self::post_tags();
84
  $taxonomy_templates['post_tags'] = new WPUF_Form_Field_Post_Tags();
85
-
86
  } else {
87
  // $taxonomy_templates[ $tax_name ] = self::taxonomy_template( $tax_name, $taxonomy );
88
  // $taxonomy_templates[ 'taxonomy' ] = new WPUF_Form_Field_Post_Taxonomy($tax_name, $taxonomy);
89
- $taxonomy_templates[ $tax_name ] = new WPUF_Form_Field_Post_Taxonomy($tax_name, $taxonomy);
90
  }
91
  }
92
-
93
  }
94
-
95
  }
96
 
97
  $field_settings = array_merge( $field_settings, $taxonomy_templates );
98
-
99
  }
100
 
101
  return $field_settings;
102
  }
103
 
104
-
105
  /**
106
  * Register the field types
107
  *
108
  * @return void
109
  */
110
  private function register_field_types() {
111
-
112
- require_once dirname( __FILE__ ) . '/fields/class-abstract-fields.php';
113
- require_once dirname( __FILE__ ) . '/fields/class-field-text.php';
114
- require_once dirname( __FILE__ ) . '/fields/class-field-email.php';
115
- require_once dirname( __FILE__ ) . '/fields/class-field-textarea.php';
116
- require_once dirname( __FILE__ ) . '/fields/class-field-checkbox.php';
117
- require_once dirname( __FILE__ ) . '/fields/class-field-radio.php';
118
- require_once dirname( __FILE__ ) . '/fields/class-field-dropdown.php';
119
- require_once dirname( __FILE__ ) . '/fields/class-field-multidropdown.php';
120
- require_once dirname( __FILE__ ) . '/fields/class-field-url.php';
121
- require_once dirname( __FILE__ ) . '/fields/class-field-column.php';
122
- require_once dirname( __FILE__ ) . '/fields/class-field-sectionbreak.php';
123
- require_once dirname( __FILE__ ) . '/fields/class-field-html.php';
124
- require_once dirname( __FILE__ ) . '/fields/class-field-hidden.php';
125
- require_once dirname( __FILE__ ) . '/fields/class-field-image.php';
126
- require_once dirname( __FILE__ ) . '/fields/class-field-recaptcha.php';
127
-
128
-
129
- $fields = array(
130
  'text_field' => new WPUF_Form_Field_Text(),
131
  'email_address' => new WPUF_Form_Field_Email(),
132
  'textarea_field' => new WPUF_Form_Field_Textarea(),
@@ -141,29 +120,26 @@ class WPUF_Field_Manager {
141
  'custom_hidden_field' => new WPUF_Form_Field_Hidden(),
142
  'image_upload' => new WPUF_Form_Field_Image(),
143
  'recaptcha' => new WPUF_Form_Field_reCaptcha(),
144
- );
145
 
146
  $this->fields = apply_filters( 'wpuf-form-fields', $fields );
147
  }
148
 
149
-
150
  /**
151
  * Get field groups
152
  *
153
  * @return array
154
  */
155
  public function get_field_groups() {
156
-
157
- $before_custom_fields = apply_filters( 'wpuf-form-fields-section-before', array() );
158
  $groups = array_merge( $before_custom_fields, $this->get_custom_fields() );
159
  $groups = array_merge( $groups, $this->get_others_fields() );
160
- $after_custom_fields = apply_filters( 'wpuf-form-fields-section-after', array() );
161
  $groups = array_merge( $groups, $after_custom_fields );
162
 
163
  return $groups;
164
  }
165
 
166
-
167
  /**
168
  * Custom field section
169
  *
@@ -174,19 +150,19 @@ class WPUF_Field_Manager {
174
  private function get_custom_fields() {
175
 
176
  // $fields = apply_filters( 'wpuf-form-builder-fields-custom-fields', array(
177
- $fields = apply_filters( 'wpuf-form-fields-custom-fields', array(
178
  'text_field', 'textarea_field', 'dropdown_field', 'multiple_select',
179
  'radio_field', 'checkbox_field', 'website_url', 'email_address',
180
- 'custom_hidden_field', 'image_upload'
181
- ) );
182
 
183
- return array(
184
- array(
185
  'title' => __( 'Custom Fields', 'wp-user-frontend' ),
186
  'id' => 'custom-fields',
187
- 'fields' => $fields
188
- )
189
- );
190
  }
191
 
192
  /**
@@ -197,36 +173,32 @@ class WPUF_Field_Manager {
197
  * @return array
198
  */
199
  private function get_others_fields() {
 
 
 
200
 
201
- $fields = apply_filters( 'wpuf-form-fields-others-fields', array(
202
- 'column_field', 'section_break', 'custom_html', 'recaptcha'
203
- ) );
204
-
205
- return array(
206
- array(
207
  'title' => __( 'Others', 'wp-user-frontend' ),
208
  'id' => 'others',
209
- 'fields' => $fields
210
- )
211
- );
212
  }
213
 
214
-
215
  /**
216
  * Get fields JS setting for the form builder
217
  *
218
  * @return array
219
  */
220
  public function get_js_settings() {
221
-
222
  $fields = $this->get_fields();
223
 
224
- $js_array = array();
225
 
226
  if ( $fields ) {
227
  foreach ( $fields as $type => $object ) {
228
  if ( is_object( $object ) ) {
229
-
230
  $js_array[ $type ] = $object->get_js_settings();
231
  }
232
  }
@@ -238,118 +210,104 @@ class WPUF_Field_Manager {
238
  /**
239
  * Render the form fields
240
  *
241
- * @param array $fields
242
- * @param integer $form_id
243
- * @param array $atts
244
- * @param string $type
245
- * @param int $post_id
246
  *
247
  * @return void
248
  */
249
- public function render_fields( $fields, $form_id, $atts = array(), $type = 'post' , $post_id = null ) {
250
-
251
- if ( ! $fields ) {
252
  return;
253
  }
254
 
255
  $fields = apply_filters( 'wpuf_render_fields', $fields, $form_id );
256
 
257
  foreach ( $fields as $field ) {
258
-
259
- if ( ! $field_object = $this->field_exists( $field['template'] ) ) {
260
-
261
  if ( defined( 'WP_DEBUG' && WP_DEBUG ) ) {
262
- echo '<h4 style="color: red;"><em>' . $field['template'] . '</em> field not found.</h4>';
263
  }
264
 
265
  continue;
266
  }
267
 
268
- if( $this->check_field_visibility( $field ) ) {
269
-
270
  if ( is_object( $field_object ) ) {
271
- $field_object->render( $field, $form_id,$type , $post_id );
272
  $field_object->conditional_logic( $field, $form_id );
273
  }
274
  }
275
-
276
  }
277
  }
278
 
279
  /**
280
  * Check field Visibility
281
  *
282
- * @param array $form_field
283
  *
284
- * @return boolean
285
  **/
286
  public function check_field_visibility( &$form_field ) {
287
-
288
  $show_field = true;
289
 
290
  // check field visibility options
291
  if ( array_key_exists( 'wpuf_visibility', $form_field ) ) {
 
 
 
292
 
293
- $visibility_selected = $form_field['wpuf_visibility']['selected'];
294
- $visibility_choices = $form_field['wpuf_visibility']['choices'];
295
- $show_field = false;
296
 
297
- if ( $visibility_selected == 'everyone' ) {
298
- $show_field = true;
299
- }
 
300
 
301
- if ( $visibility_selected == 'hidden' ) {
302
- $form_field['css'] .= 'wpuf_hidden_field';
303
  $show_field = true;
304
- }
305
-
306
- if ( $visibility_selected == 'logged_in' && is_user_logged_in() ) {
307
-
308
- if ( empty( $visibility_choices ) ) {
309
- $show_field = true;
310
- } else {
311
- foreach ( $visibility_choices as $key => $choice ) {
312
- if ( current_user_can( $choice ) ) {
313
- $show_field = true;
314
- break;
315
- }
316
- continue;
317
  }
 
318
  }
319
  }
 
320
 
321
- if ( $visibility_selected == 'subscribed_users' && is_user_logged_in() ) {
322
-
323
- $user_pack = WPUF_Subscription::init()->get_user_pack(get_current_user_id());
324
-
325
- if ( empty( $visibility_choices ) && !empty( $user_pack ) ) {
326
- $show_field = true;
327
- } elseif ( !empty( $user_pack ) && !empty( $visibility_choices ) ) {
328
 
329
- foreach ( $visibility_choices as $pack => $id ) {
330
- if ( $user_pack['pack_id'] == $id ) {
331
- $show_field = true;
332
- break;
333
- }
334
- continue;
 
335
  }
336
-
337
  }
338
-
339
  }
340
-
341
  }
342
 
343
  return $show_field;
344
  }
345
 
346
-
347
  /**
348
  * Check if a field exists
349
  *
350
- * @param string $field_type
351
  *
352
- * @return boolean
353
  */
354
  public function field_exists( $field_type ) {
355
  if ( array_key_exists( $field_type, $this->get_fields() ) ) {
7
  */
8
  class WPUF_Field_Manager {
9
 
 
10
  /**
11
  * The fields
12
  *
13
  * @var array
 
14
  */
15
+ private $fields = [];
16
 
17
  /**
18
  * WP post types
19
  *
20
  * @var string
21
  */
22
+ private $wp_post_types = [];
 
 
 
 
23
 
24
+ public function __construct() {
25
  }
26
 
27
  /**
30
  * @return array
31
  */
32
  public function get_fields() {
33
+ if ( !empty( $this->fields ) ) {
 
34
  return $this->fields;
35
  }
36
 
39
  return $this->fields;
40
  }
41
 
 
 
42
  /**
43
  * Add Post Field Type
44
  *
46
  *
47
  * @return void
48
  */
 
49
  public function add_field_settings( $field_settings ) {
 
50
  if ( class_exists( 'WPUF_Field_Contract' ) ) {
 
51
  require_once WPUF_ROOT . '/includes/fields/class-field-post-title.php';
52
  require_once WPUF_ROOT . '/includes/fields/class-field-post-content.php';
53
  require_once WPUF_ROOT . '/includes/fields/class-field-post-tags.php';
55
  require_once WPUF_ROOT . '/includes/fields/class-field-post-taxonomy.php';
56
  require_once WPUF_ROOT . '/includes/fields/class-field-featured-image.php';
57
 
58
+ $field_settings['post_title'] = new WPUF_Form_Field_Post_Title();
59
+ $field_settings['post_content'] = new WPUF_Form_Field_Post_Content();
60
+ $field_settings['post_excerpt'] = new WPUF_Form_Field_Post_Excerpt();
61
  $field_settings['featured_image'] = new WPUF_Form_Field_Featured_Image();
62
 
63
+ $taxonomy_templates = [];
 
64
 
65
  foreach ( $this->wp_post_types as $post_type => $taxonomies ) {
66
+ if ( !empty( $taxonomies ) ) {
 
 
67
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
68
  if ( 'post_tag' === $tax_name ) {
69
  // $taxonomy_templates['post_tag'] = self::post_tags();
70
  $taxonomy_templates['post_tags'] = new WPUF_Form_Field_Post_Tags();
 
71
  } else {
72
  // $taxonomy_templates[ $tax_name ] = self::taxonomy_template( $tax_name, $taxonomy );
73
  // $taxonomy_templates[ 'taxonomy' ] = new WPUF_Form_Field_Post_Taxonomy($tax_name, $taxonomy);
74
+ $taxonomy_templates[ $tax_name ] = new WPUF_Form_Field_Post_Taxonomy( $tax_name, $taxonomy );
75
  }
76
  }
 
77
  }
 
78
  }
79
 
80
  $field_settings = array_merge( $field_settings, $taxonomy_templates );
 
81
  }
82
 
83
  return $field_settings;
84
  }
85
 
 
86
  /**
87
  * Register the field types
88
  *
89
  * @return void
90
  */
91
  private function register_field_types() {
92
+ require_once __DIR__ . '/fields/class-abstract-fields.php';
93
+ require_once __DIR__ . '/fields/class-field-text.php';
94
+ require_once __DIR__ . '/fields/class-field-email.php';
95
+ require_once __DIR__ . '/fields/class-field-textarea.php';
96
+ require_once __DIR__ . '/fields/class-field-checkbox.php';
97
+ require_once __DIR__ . '/fields/class-field-radio.php';
98
+ require_once __DIR__ . '/fields/class-field-dropdown.php';
99
+ require_once __DIR__ . '/fields/class-field-multidropdown.php';
100
+ require_once __DIR__ . '/fields/class-field-url.php';
101
+ require_once __DIR__ . '/fields/class-field-column.php';
102
+ require_once __DIR__ . '/fields/class-field-sectionbreak.php';
103
+ require_once __DIR__ . '/fields/class-field-html.php';
104
+ require_once __DIR__ . '/fields/class-field-hidden.php';
105
+ require_once __DIR__ . '/fields/class-field-image.php';
106
+ require_once __DIR__ . '/fields/class-field-recaptcha.php';
107
+
108
+ $fields = [
 
 
109
  'text_field' => new WPUF_Form_Field_Text(),
110
  'email_address' => new WPUF_Form_Field_Email(),
111
  'textarea_field' => new WPUF_Form_Field_Textarea(),
120
  'custom_hidden_field' => new WPUF_Form_Field_Hidden(),
121
  'image_upload' => new WPUF_Form_Field_Image(),
122
  'recaptcha' => new WPUF_Form_Field_reCaptcha(),
123
+ ];
124
 
125
  $this->fields = apply_filters( 'wpuf-form-fields', $fields );
126
  }
127
 
 
128
  /**
129
  * Get field groups
130
  *
131
  * @return array
132
  */
133
  public function get_field_groups() {
134
+ $before_custom_fields = apply_filters( 'wpuf-form-fields-section-before', [] );
 
135
  $groups = array_merge( $before_custom_fields, $this->get_custom_fields() );
136
  $groups = array_merge( $groups, $this->get_others_fields() );
137
+ $after_custom_fields = apply_filters( 'wpuf-form-fields-section-after', [] );
138
  $groups = array_merge( $groups, $after_custom_fields );
139
 
140
  return $groups;
141
  }
142
 
 
143
  /**
144
  * Custom field section
145
  *
150
  private function get_custom_fields() {
151
 
152
  // $fields = apply_filters( 'wpuf-form-builder-fields-custom-fields', array(
153
+ $fields = apply_filters( 'wpuf-form-fields-custom-fields', [
154
  'text_field', 'textarea_field', 'dropdown_field', 'multiple_select',
155
  'radio_field', 'checkbox_field', 'website_url', 'email_address',
156
+ 'custom_hidden_field', 'image_upload',
157
+ ] );
158
 
159
+ return [
160
+ [
161
  'title' => __( 'Custom Fields', 'wp-user-frontend' ),
162
  'id' => 'custom-fields',
163
+ 'fields' => $fields,
164
+ ],
165
+ ];
166
  }
167
 
168
  /**
173
  * @return array
174
  */
175
  private function get_others_fields() {
176
+ $fields = apply_filters( 'wpuf-form-fields-others-fields', [
177
+ 'column_field', 'section_break', 'custom_html', 'recaptcha',
178
+ ] );
179
 
180
+ return [
181
+ [
 
 
 
 
182
  'title' => __( 'Others', 'wp-user-frontend' ),
183
  'id' => 'others',
184
+ 'fields' => $fields,
185
+ ],
186
+ ];
187
  }
188
 
 
189
  /**
190
  * Get fields JS setting for the form builder
191
  *
192
  * @return array
193
  */
194
  public function get_js_settings() {
 
195
  $fields = $this->get_fields();
196
 
197
+ $js_array = [];
198
 
199
  if ( $fields ) {
200
  foreach ( $fields as $type => $object ) {
201
  if ( is_object( $object ) ) {
 
202
  $js_array[ $type ] = $object->get_js_settings();
203
  }
204
  }
210
  /**
211
  * Render the form fields
212
  *
213
+ * @param array $fields
214
+ * @param int $form_id
215
+ * @param array $atts
216
+ * @param string $type
217
+ * @param int $post_id
218
  *
219
  * @return void
220
  */
221
+ public function render_fields( $fields, $form_id, $atts = [], $type = 'post', $post_id = null ) {
222
+ if ( !$fields ) {
 
223
  return;
224
  }
225
 
226
  $fields = apply_filters( 'wpuf_render_fields', $fields, $form_id );
227
 
228
  foreach ( $fields as $field ) {
229
+ if ( !$field_object = $this->field_exists( $field['template'] ) ) {
 
 
230
  if ( defined( 'WP_DEBUG' && WP_DEBUG ) ) {
231
+ echo wp_kses_post( '<h4 style="color: red;"><em>' . $field['template'] . '</em> field not found.</h4>' );
232
  }
233
 
234
  continue;
235
  }
236
 
237
+ if ( $this->check_field_visibility( $field ) ) {
 
238
  if ( is_object( $field_object ) ) {
239
+ $field_object->render( $field, $form_id, $type, $post_id );
240
  $field_object->conditional_logic( $field, $form_id );
241
  }
242
  }
 
243
  }
244
  }
245
 
246
  /**
247
  * Check field Visibility
248
  *
249
+ * @param array $form_field
250
  *
251
+ * @return bool
252
  **/
253
  public function check_field_visibility( &$form_field ) {
 
254
  $show_field = true;
255
 
256
  // check field visibility options
257
  if ( array_key_exists( 'wpuf_visibility', $form_field ) ) {
258
+ $visibility_selected = $form_field['wpuf_visibility']['selected'];
259
+ $visibility_choices = $form_field['wpuf_visibility']['choices'];
260
+ $show_field = false;
261
 
262
+ if ( $visibility_selected == 'everyone' ) {
263
+ $show_field = true;
264
+ }
265
 
266
+ if ( $visibility_selected == 'hidden' ) {
267
+ $form_field['css'] .= 'wpuf_hidden_field';
268
+ $show_field = true;
269
+ }
270
 
271
+ if ( $visibility_selected == 'logged_in' && is_user_logged_in() ) {
272
+ if ( empty( $visibility_choices ) ) {
273
  $show_field = true;
274
+ } else {
275
+ foreach ( $visibility_choices as $key => $choice ) {
276
+ if ( current_user_can( $choice ) ) {
277
+ $show_field = true;
278
+ break;
 
 
 
 
 
 
 
 
279
  }
280
+ continue;
281
  }
282
  }
283
+ }
284
 
285
+ if ( $visibility_selected == 'subscribed_users' && is_user_logged_in() ) {
286
+ $user_pack = WPUF_Subscription::init()->get_user_pack( get_current_user_id() );
 
 
 
 
 
287
 
288
+ if ( empty( $visibility_choices ) && !empty( $user_pack ) ) {
289
+ $show_field = true;
290
+ } elseif ( !empty( $user_pack ) && !empty( $visibility_choices ) ) {
291
+ foreach ( $visibility_choices as $pack => $id ) {
292
+ if ( $user_pack['pack_id'] == $id ) {
293
+ $show_field = true;
294
+ break;
295
  }
296
+ continue;
297
  }
 
298
  }
299
+ }
300
  }
301
 
302
  return $show_field;
303
  }
304
 
 
305
  /**
306
  * Check if a field exists
307
  *
308
+ * @param string $field_type
309
  *
310
+ * @return bool
311
  */
312
  public function field_exists( $field_type ) {
313
  if ( array_key_exists( $field_type, $this->get_fields() ) ) {
includes/class-form-manager.php CHANGED
@@ -19,23 +19,23 @@ class WPUF_Form_Manager {
19
  /**
20
  * Get forms
21
  *
22
- * @param array $args
23
  *
24
  * @return array
25
  */
26
- public function get_forms( $args = array() ) {
27
- $forms_array = array(
28
- 'forms' => array(),
29
- 'meta' => array(
30
  'total' => 0,
31
- 'pages' => 0
32
- )
33
- );
34
- $defaults = array(
35
- 'post_type' => 'wpuf_forms',
36
- 'post_status' => array( 'publish', 'draft', 'pending' ),
37
- 'posts_per_page' => -1
38
- );
39
 
40
  $args = wp_parse_args( $args, $defaults );
41
 
@@ -57,7 +57,7 @@ class WPUF_Form_Manager {
57
  /**
58
  * Get a single form
59
  *
60
- * @param integer|WP_Post $form
61
  *
62
  * @return \WPUF_Form
63
  */
@@ -68,31 +68,31 @@ class WPUF_Form_Manager {
68
  /**
69
  * Create a form
70
  *
71
- * @param string $form_name
72
- * @param array $fields
73
  *
74
- * @return integer|WP_Error
75
  */
76
- public function create( $form_name, $fields = array() ) {
77
- $form_id = wp_insert_post( array(
78
  'post_title' => $form_name,
79
  'post_type' => 'wpuf_forms',
80
- 'post_status' => 'publish'
81
- ) );
82
 
83
  if ( is_wp_error( $form_id ) ) {
84
  return $form_id;
85
  }
86
 
87
  if ( $fields ) {
88
- foreach ( $fields as $order => $field) {
89
- $args = array(
90
  'post_type' => 'wpuf_input',
91
  'post_parent' => $form_id,
92
  'post_status' => 'publish',
93
  'post_content' => maybe_serialize( wp_unslash( $field ) ),
94
- 'menu_order' => $order
95
- );
96
 
97
  wp_insert_post( $args );
98
  }
@@ -104,8 +104,8 @@ class WPUF_Form_Manager {
104
  /**
105
  * Delete a form with it's input fields
106
  *
107
- * @param integer $form_id
108
- * @param boolean $force
109
  *
110
  * @return void
111
  */
@@ -116,11 +116,11 @@ class WPUF_Form_Manager {
116
 
117
  // delete form inputs as WP doesn't know the relationship
118
  $wpdb->delete( $wpdb->posts,
119
- array(
120
  'post_parent' => $form_id,
121
- 'post_type' => 'wpuf_input'
122
- )
123
- );
124
  }
125
 
126
  /**
@@ -130,8 +130,7 @@ class WPUF_Form_Manager {
130
  *
131
  * @return int New duplicated form id
132
  */
133
- function duplicate( $_form_id ) {
134
-
135
- return wpuf_duplicate_form( $_form_id ) ;
136
  }
137
  }
19
  /**
20
  * Get forms
21
  *
22
+ * @param array $args
23
  *
24
  * @return array
25
  */
26
+ public function get_forms( $args = [] ) {
27
+ $forms_array = [
28
+ 'forms' => [],
29
+ 'meta' => [
30
  'total' => 0,
31
+ 'pages' => 0,
32
+ ],
33
+ ];
34
+ $defaults = [
35
+ 'post_type' => 'wpuf_forms',
36
+ 'post_status' => [ 'publish', 'draft', 'pending' ],
37
+ 'posts_per_page' => -1,
38
+ ];
39
 
40
  $args = wp_parse_args( $args, $defaults );
41
 
57
  /**
58
  * Get a single form
59
  *
60
+ * @param int|WP_Post $form
61
  *
62
  * @return \WPUF_Form
63
  */
68
  /**
69
  * Create a form
70
  *
71
+ * @param string $form_name
72
+ * @param array $fields
73
  *
74
+ * @return int|WP_Error
75
  */
76
+ public function create( $form_name, $fields = [] ) {
77
+ $form_id = wp_insert_post( [
78
  'post_title' => $form_name,
79
  'post_type' => 'wpuf_forms',
80
+ 'post_status' => 'publish',
81
+ ] );
82
 
83
  if ( is_wp_error( $form_id ) ) {
84
  return $form_id;
85
  }
86
 
87
  if ( $fields ) {
88
+ foreach ( $fields as $order => $field ) {
89
+ $args = [
90
  'post_type' => 'wpuf_input',
91
  'post_parent' => $form_id,
92
  'post_status' => 'publish',
93
  'post_content' => maybe_serialize( wp_unslash( $field ) ),
94
+ 'menu_order' => $order,
95
+ ];
96
 
97
  wp_insert_post( $args );
98
  }
104
  /**
105
  * Delete a form with it's input fields
106
  *
107
+ * @param int $form_id
108
+ * @param bool $force
109
  *
110
  * @return void
111
  */
116
 
117
  // delete form inputs as WP doesn't know the relationship
118
  $wpdb->delete( $wpdb->posts,
119
+ [
120
  'post_parent' => $form_id,
121
+ 'post_type' => 'wpuf_input',
122
+ ]
123
+ );
124
  }
125
 
126
  /**
130
  *
131
  * @return int New duplicated form id
132
  */
133
+ public function duplicate( $_form_id ) {
134
+ return wpuf_duplicate_form( $_form_id );
 
135
  }
136
  }
includes/class-form-preview.php CHANGED
@@ -19,7 +19,7 @@ class WPUF_Form_Preview {
19
  /**
20
  * Form id
21
  *
22
- * @var integer
23
  */
24
  private $form_id;
25
 
@@ -30,38 +30,37 @@ class WPUF_Form_Preview {
30
  */
31
  private $is_preview = true;
32
 
33
- function __construct() {
34
-
35
- if ( ! isset( $_GET['wpuf_preview'] ) && empty( $_GET['wpuf'] ) ) {
36
  return;
37
  }
38
 
39
  $this->form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0;
40
 
41
- add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
42
- add_filter( 'template_include', array( $this, 'template_include' ) );
43
 
44
- add_filter( 'the_title', array( $this, 'the_title' ) );
45
- add_filter( 'the_content', array( $this, 'the_content' ) );
46
- add_filter( 'get_the_excerpt', array( $this, 'the_content' ) );
47
  add_filter( 'post_thumbnail_html', '__return_empty_string' );
48
  }
49
 
50
  /**
51
  * Set the page title
52
  *
53
- * @param string $title
54
  *
55
  * @return string
56
  */
57
  public function the_title( $title ) {
58
- if ( ! in_the_loop() ) {
59
  return $title;
60
  }
61
 
62
  $form = new WPUF_Form( $this->form_id );
63
 
64
- if ( ! $form ) {
65
  return $title;
66
  }
67
 
@@ -73,21 +72,19 @@ class WPUF_Form_Preview {
73
  /**
74
  * Set the content of the page
75
  *
76
- * @param string $content
77
  *
78
  * @return string
79
  */
80
  public function the_content( $content ) {
81
-
82
  if ( $this->is_preview ) {
83
-
84
- if ( ! is_user_logged_in() ) {
85
  return __( 'You must be logged in to preview this form.', 'wp-user-frontend' );
86
  }
87
 
88
  $viewing_capability = apply_filters( 'wpuf_preview_form_cap', 'edit_posts' ); // at least has to be contributor
89
 
90
- if ( ! current_user_can( $viewing_capability ) ) {
91
  return __( 'Sorry, you are not eligible to preview this form.', 'wp-user-frontend' );
92
  }
93
  }
@@ -98,7 +95,7 @@ class WPUF_Form_Preview {
98
  /**
99
  * Set the posts to one
100
  *
101
- * @param WP_Query $query
102
  *
103
  * @return void
104
  */
@@ -113,7 +110,7 @@ class WPUF_Form_Preview {
113
  *
114
  * @return string
115
  */
116
- function template_include() {
117
- return locate_template( array( 'page.php', 'single.php', 'index.php' ) );
118
  }
119
  }
19
  /**
20
  * Form id
21
  *
22
+ * @var int
23
  */
24
  private $form_id;
25
 
30
  */
31
  private $is_preview = true;
32
 
33
+ public function __construct() {
34
+ if ( !isset( $_GET['wpuf_preview'] ) && empty( $_GET['wpuf'] ) ) {
 
35
  return;
36
  }
37
 
38
  $this->form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0;
39
 
40
+ add_action( 'pre_get_posts', [ $this, 'pre_get_posts' ] );
41
+ add_filter( 'template_include', [ $this, 'template_include' ] );
42
 
43
+ add_filter( 'the_title', [ $this, 'the_title' ] );
44
+ add_filter( 'the_content', [ $this, 'the_content' ] );
45
+ add_filter( 'get_the_excerpt', [ $this, 'the_content' ] );
46
  add_filter( 'post_thumbnail_html', '__return_empty_string' );
47
  }
48
 
49
  /**
50
  * Set the page title
51
  *
52
+ * @param string $title
53
  *
54
  * @return string
55
  */
56
  public function the_title( $title ) {
57
+ if ( !in_the_loop() ) {
58
  return $title;
59
  }
60
 
61
  $form = new WPUF_Form( $this->form_id );
62
 
63
+ if ( !$form ) {
64
  return $title;
65
  }
66
 
72
  /**
73
  * Set the content of the page
74
  *
75
+ * @param string $content
76
  *
77
  * @return string
78
  */
79
  public function the_content( $content ) {
 
80
  if ( $this->is_preview ) {
81
+ if ( !is_user_logged_in() ) {
 
82
  return __( 'You must be logged in to preview this form.', 'wp-user-frontend' );
83
  }
84
 
85
  $viewing_capability = apply_filters( 'wpuf_preview_form_cap', 'edit_posts' ); // at least has to be contributor
86
 
87
+ if ( !current_user_can( $viewing_capability ) ) {
88
  return __( 'Sorry, you are not eligible to preview this form.', 'wp-user-frontend' );
89
  }
90
  }
95
  /**
96
  * Set the posts to one
97
  *
98
+ * @param WP_Query $query
99
  *
100
  * @return void
101
  */
110
  *
111
  * @return string
112
  */
113
+ public function template_include() {
114
+ return locate_template( [ 'page.php', 'single.php', 'index.php' ] );
115
  }
116
  }
includes/class-form.php CHANGED
@@ -5,7 +5,7 @@ class WPUF_Form {
5
  /**
6
  * The form ID
7
  *
8
- * @var integer
9
  */
10
  public $id;
11
 
@@ -13,20 +13,14 @@ class WPUF_Form {
13
  * Form fields
14
  *
15
  * @var array
16
- */
17
-
18
- public $form_fields = array();
19
-
20
 
21
  public function __construct( $form ) {
22
-
23
  if ( is_numeric( $form ) ) {
24
-
25
  $this->id = $form;
26
  $this->data = get_post( $form );
27
-
28
- } elseif ( is_a( $form, 'WP_Post' )) {
29
-
30
  $this->id = $form->ID;
31
  $this->data = $form;
32
  }
@@ -48,17 +42,18 @@ class WPUF_Form {
48
  */
49
  public function get_settings() {
50
  $form_settings = wpuf_get_form_settings( $this->id );
51
- return $form_settings;
52
 
 
53
  }
54
 
55
  /**
56
  * Get guest post settings
57
  *
58
- * @return boolean
59
  */
60
  public function guest_post() {
61
  $settings = $this->get_settings();
 
62
  if ( isset( $settings['guest_post'] ) && $settings['guest_post'] == 'true' ) {
63
  return true;
64
  }
@@ -69,7 +64,7 @@ class WPUF_Form {
69
  /**
70
  * Check if payment is enabled
71
  *
72
- * @return boolean
73
  */
74
  public function is_charging_enabled() {
75
  $settings = $this->get_settings();
@@ -84,7 +79,7 @@ class WPUF_Form {
84
  /**
85
  * Check if pay per post is enabled
86
  *
87
- * @return boolean
88
  */
89
  public function is_enabled_pay_per_post() {
90
  $settings = $this->get_settings();
@@ -99,7 +94,7 @@ class WPUF_Form {
99
  /**
100
  * Check if subscription pack is forced
101
  *
102
- * @return boolean
103
  */
104
  public function is_enabled_force_pack() {
105
  $settings = $this->get_settings();
@@ -114,7 +109,7 @@ class WPUF_Form {
114
  /**
115
  * Get pay per cost amount
116
  *
117
- * @return integer
118
  */
119
  public function get_pay_per_post_cost() {
120
  $settings = $this->get_settings();
@@ -129,7 +124,7 @@ class WPUF_Form {
129
  /**
130
  * Check if fallback cost after subscription pack expiration is enabled
131
  *
132
- * @return boolean
133
  */
134
  public function is_enabled_fallback_cost() {
135
  $settings = $this->get_settings();
@@ -144,7 +139,7 @@ class WPUF_Form {
144
  /**
145
  * Get the fallback cost amount
146
  *
147
- * @return integer
148
  */
149
  public function get_subs_fallback_cost() {
150
  $settings = $this->get_settings();
@@ -159,139 +154,118 @@ class WPUF_Form {
159
  /**
160
  * Check if the form submission is open
161
  *
162
- * @param object $form
163
- * @param array $form_settings
164
- * @param array $atts
165
- * @param string $type
166
- * @param int $post_id
167
  *
168
  * @return array
169
  */
170
  public function is_submission_open( $form, $form_settings ) {
171
-
172
  $info = '';
173
-
174
  $user_can_post = 'yes';
175
-
176
  $current_user = wpuf_get_user();
177
-
178
  $guest_post_enabled = $this->guest_post();
179
 
180
-
181
- if(isset( $this->form_settings['message_restrict'] ) && !$guest_post_enabled && ! is_user_logged_in() ) {
182
  $user_can_post = 'no';
183
- $info = $this->form_settings['message_restrict'];
184
  }
185
 
186
  if ( $this->is_charging_enabled() ) {
187
-
188
  $pay_per_post = $this->is_enabled_pay_per_post();
189
-
190
  $pay_per_post_cost = (float) $this->get_pay_per_post_cost();
191
-
192
  $force_pack = $this->is_enabled_force_pack();
193
-
194
  $fallback_enabled = $this->is_enabled_fallback_cost();
195
-
196
  $fallback_cost = $this->get_subs_fallback_cost();
197
-
198
  $has_post_count = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
199
 
200
  // guest post payment checking
201
- if ( ! is_user_logged_in() && isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' ) {
202
 
203
  //if ( $form->is_charging_enabled() ) {
204
 
205
- if ( $force_pack ) {
206
- $user_can_post = 'no';
207
- $info = 'You need to buy a pack to post in this form.';
208
- } elseif ( $pay_per_post && !$force_pack ) {
209
- $user_can_post = 'yes';
210
- // $info = sprintf( __( 'There is a <strong>%s</strong> charge to add a new post.', 'wpuf' ), wpuf_format_price( $pay_per_post_cost ));
211
- // echo '<div class="wpuf-info">' . apply_filters( 'wpuf_ppp_notice', $info, $id, $form_settings ) . '</div>';
212
- } else {
213
- $user_can_post = 'no';
214
- $info = sprintf( __( 'Payment type not selected for this form. Please contact admin.', 'wp-user-frontend' ));
215
- }
216
 
217
  // } else {
218
  // $user_can_post = 'yes';
219
  // }
220
-
221
  } else {
222
  // regular payment checking
223
  if ( $force_pack && is_user_logged_in() ) {
224
- $current_pack = $current_user->subscription()->current_pack();
225
 
226
- if ( ! is_wp_error( $current_pack ) ) {
227
- // user has valid post count
228
- if ( $has_post_count ) {
 
 
 
229
  $user_can_post = 'yes';
230
  } else {
231
- if ( $fallback_enabled && !$has_post_count ) {
232
- $user_can_post = 'yes';
233
- } else {
234
- $user_can_post = 'no';
235
- $info = __('Post Limit Exceeded for your purchased subscription pack.', 'wp-user-frontend');
236
- }
237
  }
238
- } else {
239
- $user_can_post = 'no';
240
- $info = $current_pack->get_error_message();
241
  }
 
 
 
 
242
  } elseif ( $pay_per_post && is_user_logged_in() && !$current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) {
243
-
244
  $user_can_post = 'yes';
245
  // $info = sprintf( __( 'There is a <strong>%s</strong> charge to add a new post.', 'wpuf' ), wpuf_format_price( $pay_per_post_cost ));
246
  // echo '<div class="wpuf-info">' . apply_filters( 'wpuf_ppp_notice', $info, $id, $form_settings ) . '</div>';
247
-
248
  } elseif ( !$pay_per_post && !$current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) {
249
-
250
  $user_can_post = 'no';
251
- $info = sprintf( __( 'Payment type not selected for this form. Please contact admin.', 'wp-user-frontend' ));
252
-
253
  } else {
254
  $user_can_post = 'no';
 
255
  if ( !is_user_logged_in() ) {
256
  $info = $form_settings['message_restrict'];
257
  } else {
258
- $info = sprintf( __( 'Payment type not selected for this form. Please contact admin.', 'wp-user-frontend' ));
259
  }
260
-
261
  }
262
  }
263
  } else {
264
- if ( isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' && ! is_user_logged_in() ) {
265
  $user_can_post = 'yes';
266
  }
267
  }
268
 
269
- return array($user_can_post,$info);
270
  }
271
 
272
-
273
  /**
274
  * prepare_entries
275
  *
276
  * @return array
277
  */
278
  public function prepare_entries() {
279
-
280
  $fields = wpuf()->fields->get_fields();
281
-
282
  $form_fields = $this->get_fields();
 
283
 
284
- $entry_fields = array();
285
-
286
- $ignore_list = apply_filters('wpuf_entry_ignore_list', array('recaptcha'));
287
-
288
- foreach ($form_fields as $field) {
289
 
 
290
  if ( in_array( $field['template'], $ignore_list ) ) {
291
  continue;
292
  }
293
 
294
- if ( ! array_key_exists( $field['template'], $fields ) ) {
295
  continue;
296
  }
297
 
@@ -307,8 +281,7 @@ class WPUF_Form {
307
  * Get all form fields of this form
308
  *
309
  * @return array
310
- */
311
-
312
  public function get_fields() {
313
 
314
  // return if already fetched
@@ -316,52 +289,50 @@ class WPUF_Form {
316
  return $this->form_fields;
317
  }
318
 
319
- $fields = get_children(array(
320
  'post_parent' => $this->id,
321
  'post_status' => 'publish',
322
  'post_type' => 'wpuf_input',
323
  'numberposts' => '-1',
324
  'orderby' => 'menu_order',
325
  'order' => 'ASC',
326
- ));
327
 
328
- $form_fields = array();
329
 
330
  foreach ( $fields as $key => $content ) {
331
-
332
  $field = maybe_unserialize( $content->post_content );
333
 
334
  if ( empty( $field['template'] ) ) {
335
  continue;
336
  }
337
 
338
-
339
  $field['id'] = $content->ID;
340
 
341
  // Add inline property for radio and checkbox fields
342
- $inline_supported_fields = apply_filters( 'wpuf_inline_supported_fields_list', array( 'radio_field', 'checkbox_field' ) );
343
- if ( in_array( $field['template'] , $inline_supported_fields ) ) {
344
- if ( ! isset( $field['inline'] ) ) {
 
345
  $field['inline'] = 'no';
346
  }
347
  }
348
 
349
  // Add 'selected' property
350
- $option_based_fields = apply_filters( 'wpuf_option_based_fields_list', array( 'dropdown_field', 'multiple_select', 'radio_field', 'checkbox_field' ) );
351
- if ( in_array( $field['template'] , $option_based_fields ) ) {
352
- if ( ! isset( $field['selected'] ) ) {
353
 
 
 
354
  if ( 'dropdown_field' === $field['template'] || 'radio_field' === $field['template'] ) {
355
  $field['selected'] = '';
356
  } else {
357
- $field['selected'] = array();
358
  }
359
-
360
  }
361
  }
362
 
363
  // Add 'multiple' key for template:repeat
364
- if ( 'repeat_field' === $field['template'] && ! isset( $field['multiple'] ) ) {
365
  $field['multiple'] = '';
366
  }
367
 
@@ -373,8 +344,7 @@ class WPUF_Form {
373
 
374
  // $form_fields[] = apply_filters( 'wpuf-get-form-field', $field );
375
 
376
- $form_fields[] = apply_filters( 'wpuf-get-form-fields', $field );
377
-
378
  }
379
 
380
  // $this->form_fields = apply_filters( 'wpuf-get-form-fields', $form_fields );
@@ -383,5 +353,4 @@ class WPUF_Form {
383
 
384
  return $form_fields;
385
  }
386
-
387
  }
5
  /**
6
  * The form ID
7
  *
8
+ * @var int
9
  */
10
  public $id;
11
 
13
  * Form fields
14
  *
15
  * @var array
16
+ */
17
+ public $form_fields = [];
 
 
18
 
19
  public function __construct( $form ) {
 
20
  if ( is_numeric( $form ) ) {
 
21
  $this->id = $form;
22
  $this->data = get_post( $form );
23
+ } elseif ( is_a( $form, 'WP_Post' ) ) {
 
 
24
  $this->id = $form->ID;
25
  $this->data = $form;
26
  }
42
  */
43
  public function get_settings() {
44
  $form_settings = wpuf_get_form_settings( $this->id );
 
45
 
46
+ return $form_settings;
47
  }
48
 
49
  /**
50
  * Get guest post settings
51
  *
52
+ * @return bool
53
  */
54
  public function guest_post() {
55
  $settings = $this->get_settings();
56
+
57
  if ( isset( $settings['guest_post'] ) && $settings['guest_post'] == 'true' ) {
58
  return true;
59
  }
64
  /**
65
  * Check if payment is enabled
66
  *
67
+ * @return bool
68
  */
69
  public function is_charging_enabled() {
70
  $settings = $this->get_settings();
79
  /**
80
  * Check if pay per post is enabled
81
  *
82
+ * @return bool
83
  */
84
  public function is_enabled_pay_per_post() {
85
  $settings = $this->get_settings();
94
  /**
95
  * Check if subscription pack is forced
96
  *
97
+ * @return bool
98
  */
99
  public function is_enabled_force_pack() {
100
  $settings = $this->get_settings();
109
  /**
110
  * Get pay per cost amount
111
  *
112
+ * @return int
113
  */
114
  public function get_pay_per_post_cost() {
115
  $settings = $this->get_settings();
124
  /**
125
  * Check if fallback cost after subscription pack expiration is enabled
126
  *
127
+ * @return bool
128
  */
129
  public function is_enabled_fallback_cost() {
130
  $settings = $this->get_settings();
139
  /**
140
  * Get the fallback cost amount
141
  *
142
+ * @return int
143
  */
144
  public function get_subs_fallback_cost() {
145
  $settings = $this->get_settings();
154
  /**
155
  * Check if the form submission is open
156
  *
157
+ * @param object $form
158
+ * @param array $form_settings
159
+ * @param array $atts
160
+ * @param string $type
161
+ * @param int $post_id
162
  *
163
  * @return array
164
  */
165
  public function is_submission_open( $form, $form_settings ) {
 
166
  $info = '';
 
167
  $user_can_post = 'yes';
 
168
  $current_user = wpuf_get_user();
 
169
  $guest_post_enabled = $this->guest_post();
170
 
171
+ if ( isset( $this->form_settings['message_restrict'] ) && !$guest_post_enabled && !is_user_logged_in() ) {
 
172
  $user_can_post = 'no';
173
+ $info = $this->form_settings['message_restrict'];
174
  }
175
 
176
  if ( $this->is_charging_enabled() ) {
 
177
  $pay_per_post = $this->is_enabled_pay_per_post();
 
178
  $pay_per_post_cost = (float) $this->get_pay_per_post_cost();
 
179
  $force_pack = $this->is_enabled_force_pack();
 
180
  $fallback_enabled = $this->is_enabled_fallback_cost();
 
181
  $fallback_cost = $this->get_subs_fallback_cost();
 
182
  $has_post_count = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
183
 
184
  // guest post payment checking
185
+ if ( !is_user_logged_in() && isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' ) {
186
 
187
  //if ( $form->is_charging_enabled() ) {
188
 
189
+ if ( $force_pack ) {
190
+ $user_can_post = 'no';
191
+ $info = 'You need to buy a pack to post in this form.';
192
+ } elseif ( $pay_per_post && !$force_pack ) {
193
+ $user_can_post = 'yes';
194
+ // $info = sprintf( __( 'There is a <strong>%s</strong> charge to add a new post.', 'wpuf' ), wpuf_format_price( $pay_per_post_cost ));
195
+ // echo '<div class="wpuf-info">' . apply_filters( 'wpuf_ppp_notice', $info, $id, $form_settings ) . '</div>';
196
+ } else {
197
+ $user_can_post = 'no';
198
+ $info = sprintf( __( 'Payment type not selected for this form. Please contact admin.', 'wp-user-frontend' ) );
199
+ }
200
 
201
  // } else {
202
  // $user_can_post = 'yes';
203
  // }
 
204
  } else {
205
  // regular payment checking
206
  if ( $force_pack && is_user_logged_in() ) {
207
+ $current_pack = $current_user->subscription()->current_pack();
208
 
209
+ if ( !is_wp_error( $current_pack ) ) {
210
+ // user has valid post count
211
+ if ( $has_post_count ) {
212
+ $user_can_post = 'yes';
213
+ } else {
214
+ if ( $fallback_enabled && !$has_post_count ) {
215
  $user_can_post = 'yes';
216
  } else {
217
+ $user_can_post = 'no';
218
+ $info = __( 'Post Limit Exceeded for your purchased subscription pack.', 'wp-user-frontend' );
 
 
 
 
219
  }
 
 
 
220
  }
221
+ } else {
222
+ $user_can_post = 'no';
223
+ $info = $current_pack->get_error_message();
224
+ }
225
  } elseif ( $pay_per_post && is_user_logged_in() && !$current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) {
 
226
  $user_can_post = 'yes';
227
  // $info = sprintf( __( 'There is a <strong>%s</strong> charge to add a new post.', 'wpuf' ), wpuf_format_price( $pay_per_post_cost ));
228
  // echo '<div class="wpuf-info">' . apply_filters( 'wpuf_ppp_notice', $info, $id, $form_settings ) . '</div>';
 
229
  } elseif ( !$pay_per_post && !$current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) {
 
230
  $user_can_post = 'no';
231
+ $info = sprintf( __( 'Payment type not selected for this form. Please contact admin.', 'wp-user-frontend' ) );
 
232
  } else {
233
  $user_can_post = 'no';
234
+
235
  if ( !is_user_logged_in() ) {
236
  $info = $form_settings['message_restrict'];
237
  } else {
238
+ $info = sprintf( __( 'Payment type not selected for this form. Please contact admin.', 'wp-user-frontend' ) );
239
  }
 
240
  }
241
  }
242
  } else {
243
+ if ( isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' && !is_user_logged_in() ) {
244
  $user_can_post = 'yes';
245
  }
246
  }
247
 
248
+ return [$user_can_post, $info];
249
  }
250
 
 
251
  /**
252
  * prepare_entries
253
  *
254
  * @return array
255
  */
256
  public function prepare_entries() {
 
257
  $fields = wpuf()->fields->get_fields();
 
258
  $form_fields = $this->get_fields();
259
+ $entry_fields = [];
260
 
261
+ $ignore_list = apply_filters( 'wpuf_entry_ignore_list', ['recaptcha'] );
 
 
 
 
262
 
263
+ foreach ( $form_fields as $field ) {
264
  if ( in_array( $field['template'], $ignore_list ) ) {
265
  continue;
266
  }
267
 
268
+ if ( !array_key_exists( $field['template'], $fields ) ) {
269
  continue;
270
  }
271
 
281
  * Get all form fields of this form
282
  *
283
  * @return array
284
+ */
 
285
  public function get_fields() {
286
 
287
  // return if already fetched
289
  return $this->form_fields;
290
  }
291
 
292
+ $fields = get_children( [
293
  'post_parent' => $this->id,
294
  'post_status' => 'publish',
295
  'post_type' => 'wpuf_input',
296
  'numberposts' => '-1',
297
  'orderby' => 'menu_order',
298
  'order' => 'ASC',
299
+ ] );
300
 
301
+ $form_fields = [];
302
 
303
  foreach ( $fields as $key => $content ) {
 
304
  $field = maybe_unserialize( $content->post_content );
305
 
306
  if ( empty( $field['template'] ) ) {
307
  continue;
308
  }
309
 
 
310
  $field['id'] = $content->ID;
311
 
312
  // Add inline property for radio and checkbox fields
313
+ $inline_supported_fields = apply_filters( 'wpuf_inline_supported_fields_list', [ 'radio_field', 'checkbox_field' ] );
314
+
315
+ if ( in_array( $field['template'], $inline_supported_fields ) ) {
316
+ if ( !isset( $field['inline'] ) ) {
317
  $field['inline'] = 'no';
318
  }
319
  }
320
 
321
  // Add 'selected' property
322
+ $option_based_fields = apply_filters( 'wpuf_option_based_fields_list', [ 'dropdown_field', 'multiple_select', 'radio_field', 'checkbox_field' ] );
 
 
323
 
324
+ if ( in_array( $field['template'], $option_based_fields ) ) {
325
+ if ( !isset( $field['selected'] ) ) {
326
  if ( 'dropdown_field' === $field['template'] || 'radio_field' === $field['template'] ) {
327
  $field['selected'] = '';
328
  } else {
329
+ $field['selected'] = [];
330
  }
 
331
  }
332
  }
333
 
334
  // Add 'multiple' key for template:repeat
335
+ if ( 'repeat_field' === $field['template'] && !isset( $field['multiple'] ) ) {
336
  $field['multiple'] = '';
337
  }
338
 
344
 
345
  // $form_fields[] = apply_filters( 'wpuf-get-form-field', $field );
346
 
347
+ $form_fields[] = apply_filters( 'wpuf-get-form-fields', $field );
 
348
  }
349
 
350
  // $this->form_fields = apply_filters( 'wpuf-get-form-fields', $form_fields );
353
 
354
  return $form_fields;
355
  }
 
356
  }
includes/class-frontend-form-post.php CHANGED
@@ -1,27 +1,29 @@
1
  <?php
2
 
3
- class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
4
-
5
  private static $_instance;
 
6
  private $post_expiration_date = 'wpuf-post_expiration_date';
 
7
  private $expired_post_status = 'wpuf-expired_post_status';
 
8
  private $post_expiration_message = 'wpuf-post_expiration_message';
9
 
10
- public function __construct() {
11
- add_shortcode( 'wpuf_form', array( $this, 'add_post_shortcode'));
12
- add_shortcode( 'wpuf_edit', array( $this, 'edit_post_shortcode' ) );
13
  // ajax requests
14
- add_action( 'wp_ajax_wpuf_form_preview', array( $this, 'preview_form' ) );
15
- add_action( 'wp_ajax_wpuf_submit_post', array( $this, 'submit_post' ) );
16
- add_action( 'wp_ajax_nopriv_wpuf_submit_post', array( $this, 'submit_post' ) );
17
- add_action( 'wp_ajax_make_media_embed_code', array( $this, 'make_media_embed_code' ) );
18
- add_action( 'wp_ajax_nopriv_make_media_embed_code', array( $this, 'make_media_embed_code' ) );
19
  // // guest post hook
20
- add_action( 'init', array( $this, 'publish_guest_post' ) );
21
  // draft
22
- add_action( 'wp_ajax_wpuf_draft_post', array( $this, 'draft_post' ) );
23
  // form preview
24
- add_action( 'wp_ajax_wpuf_form_preview', array( $this, 'preview_form' ) );
25
  $this->set_wp_post_types();
26
  }
27
 
@@ -29,12 +31,13 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
29
  * Edit post shortcode handler
30
  *
31
  * @param array $atts
 
32
  * @return
33
  **/
34
- function edit_post_shortcode( $atts ) {
35
- add_filter( 'wpuf-form-fields', array( $this, 'add_field_settings'));
36
 
37
- extract( shortcode_atts( array( 'id' => 0 ), $atts ) );
38
  ob_start();
39
 
40
  global $userdata;
@@ -42,12 +45,13 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
42
  ob_start();
43
 
44
  if ( !is_user_logged_in() ) {
45
- echo '<div class="wpuf-message">' . __( 'You are not logged in', 'wp-user-frontend' ) . '</div>';
46
- wp_login_form();
 
47
  return;
48
  }
49
 
50
- $post_id = isset( $_GET['pid'] ) ? intval( $_GET['pid'] ) : 0;
51
 
52
  if ( !$post_id ) {
53
  return '<div class="wpuf-info">' . __( 'Invalid post', 'wp-user-frontend' ) . '</div>';
@@ -60,7 +64,7 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
60
  return '<div class="wpuf-info">' . apply_filters( 'wpuf_edit_post_lock_user_notice', __( 'Your edit access for this post has been locked by an administrator.', 'wp-user-frontend' ) ) . '</div>';
61
  }
62
 
63
- if ( !empty( $edit_post_lock_time ) && $edit_post_lock_time < time() ) {
64
  return '<div class="wpuf-info">' . apply_filters( 'wpuf_edit_post_lock_expire_notice', __( 'Your allocated time for editing this post has been expired.', 'wp-user-frontend' ) ) . '</div>';
65
  }
66
 
@@ -68,6 +72,7 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
68
  if ( wpuf_get_user()->edit_post_lock_reason() ) {
69
  return '<div class="wpuf-info">' . wpuf_get_user()->edit_post_lock_reason() . '</div>';
70
  }
 
71
  return '<div class="wpuf-info">' . apply_filters( 'wpuf_user_edit_post_lock_notice', __( 'Your post edit access has been locked by an administrator.', 'wp-user-frontend' ) ) . '</div>';
72
  }
73
 
@@ -110,13 +115,15 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
110
  return '<div class="wpuf-info">' . __( 'You can\'t edit a post while in pending mode.', 'wp-user-frontend' );
111
  }
112
 
113
- if ( isset( $_GET['msg'] ) && $_GET['msg'] == 'post_updated' ) {
114
- echo '<div class="wpuf-success">';
115
- echo str_replace( '%link%', get_permalink( $post_id ), $this->form_settings['update_message'] );
116
- echo '</div>';
 
 
117
  }
118
 
119
- $this->render_form( $form_id,$post_id,$atts,$form);
120
 
121
  $content = ob_get_contents();
122
 
@@ -125,22 +132,28 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
125
  return $content;
126
  }
127
 
128
-
129
-
130
  public static function init() {
131
  if ( !self::$_instance ) {
132
- self::$_instance = new self;
133
  }
 
134
  return self::$_instance;
135
  }
136
 
137
-
138
  /**
139
  * this will embed media to the editor
140
- */
141
- function make_media_embed_code() {
142
- if ( $embed_code = wp_oembed_get( $_POST['content'] ) ) {
143
- echo $embed_code;
 
 
 
 
 
 
 
 
144
  } else {
145
  echo '';
146
  }
@@ -151,34 +164,34 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
151
  * Draft Post
152
  */
153
  public function draft_post() {
154
-
155
  check_ajax_referer( 'wpuf_form_add' );
156
- add_filter( 'wpuf-form-fields', array( $this, 'add_field_settings'));
157
  @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
158
 
159
- $form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0;
160
  $form = new WPUF_Form( $form_id );
161
  $this->form_settings = $form->get_settings();
162
  $this->form_fields = $form->get_fields();
163
  $pay_per_post = $form->is_enabled_pay_per_post();
164
 
165
- list( $post_vars, $taxonomy_vars, $meta_vars ) =$this->get_input_fields($this->form_fields);
166
 
167
  $entry_fields = $form->prepare_entries();
168
- $post_content = isset( $_POST[ 'post_content' ] ) ? $_POST[ 'post_content' ] : '';
169
 
170
- $postarr = array(
171
  'post_type' => $this->form_settings['post_type'],
172
  'post_status' => wpuf_get_draft_post_status( $this->form_settings ),
173
  'post_author' => get_current_user_id(),
174
- 'post_title' => isset( $_POST['post_title'] ) ? trim( $_POST['post_title'] ) : '',
175
  'post_content' => $post_content,
176
- 'post_excerpt' => isset( $_POST['post_excerpt'] ) ? trim( $_POST['post_excerpt'] ) : '',
177
- );
 
 
178
 
179
- if ( isset( $_POST['category'] ) && ( $_POST['category'] !='' && $_POST['category'] !='0' && $_POST['category'][0] !='-1' ) ) {
180
- $category = $_POST['category'];
181
- $postarr['post_category'] = is_array( $category ) ? $category : array( $category );
182
  }
183
 
184
  // set default post category if it's not been set yet and if post type supports
@@ -186,18 +199,18 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
186
  if ( is_array( $this->form_settings['default_cat'] ) ) {
187
  $postarr['post_category'] = $this->form_settings['default_cat'];
188
  } else {
189
- $postarr['post_category'] = array( $this->form_settings['default_cat'] );
190
  }
191
  }
192
 
193
  if ( isset( $_POST['tags'] ) ) {
194
- $postarr['tags_input'] = explode( ',', $_POST['tags'] );
195
  }
196
 
197
  // if post_id is passed, we update the post
198
  if ( isset( $_POST['post_id'] ) ) {
199
  $is_update = true;
200
- $postarr['ID'] = $_POST['post_id'];
201
  $postarr['comment_status'] = 'open';
202
  }
203
 
@@ -207,7 +220,6 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
207
  wpuf_frontend_post_revision( $post_id, $this->form_settings );
208
 
209
  if ( $post_id ) {
210
-
211
  self::update_post_meta( $meta_vars, $post_id );
212
 
213
  // set the post form_id for later usage
@@ -222,62 +234,62 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
222
 
223
  // if pay per post is enabled then update payment status as pending
224
  if ( $pay_per_post ) {
225
- update_post_meta ( $post_id, '_wpuf_payment_status', 'pending' );
226
  }
227
 
228
- if(!empty($taxonomy_vars)) {
229
- $this->set_custom_taxonomy($post_id,$taxonomy_vars);
230
  }
231
  }
232
 
233
- //used to add code to run when the post is going to draft
234
  do_action( 'wpuf_draft_post_after_insert', $post_id, $form_id, $this->form_settings, $this->form_fields );
235
 
236
  wpuf_clear_buffer();
237
 
238
- echo json_encode( array(
239
  'post_id' => $post_id,
240
- 'action' => $_POST['action'],
241
  'date' => current_time( 'mysql' ),
242
  'post_author' => get_current_user_id(),
243
  'comment_status' => get_option( 'default_comment_status' ),
244
- 'url' => add_query_arg( 'preview', 'true', get_permalink( $post_id ) )
245
- ) );
246
 
247
  exit;
248
  }
249
 
250
-
251
  /**
252
  * New/Edit post submit handler
253
  *
254
  * @return void
255
  */
256
- function submit_post() {
257
-
258
  check_ajax_referer( 'wpuf_form_add' );
259
- add_filter( 'wpuf-form-fields', array( $this, 'add_field_settings'));
260
  @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
261
 
262
- $form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0;
263
  $form = new WPUF_Form( $form_id );
264
  $this->form_settings = $form->get_settings();
265
  $this->form_fields = $form->get_fields();
266
  $guest_mode = isset( $this->form_settings['guest_post'] ) ? $this->form_settings['guest_post'] : '';
267
- $guest_verify = isset( $this->form_settings['guest_email_verify'] ) ? $this->form_settings['guest_email_verify'] : 'false' ;
268
- $attachments_to_delete = isset( $_POST['delete_attachments'] ) ? $_POST['delete_attachments'] : array();
269
 
270
  foreach ( $attachments_to_delete as $attach_id ) {
271
  wp_delete_attachment( $attach_id, true );
272
  }
273
 
274
- list( $post_vars, $taxonomy_vars, $meta_vars ) =$this->get_input_fields($this->form_fields);
275
 
276
  if ( !isset( $_POST['post_id'] ) ) {
277
  $has_limit = ( isset( $this->form_settings['limit_entries'] ) && $this->form_settings['limit_entries'] == 'true' ) ? true : false;
 
278
  if ( $has_limit ) {
279
  $limit = (int) !empty( $this->form_settings['limit_number'] ) ? $this->form_settings['limit_number'] : 0;
280
  $form_entries = wpuf_form_posts_count( $form_id );
 
281
  if ( $limit && $limit <= $form_entries ) {
282
  $this->send_error( $this->form_settings['limit_message'] );
283
  }
@@ -288,16 +300,16 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
288
  $is_update = false;
289
  $post_author = null;
290
  $default_post_author = wpuf_get_option( 'default_post_owner', 'wpuf_frontend_posting', 1 );
291
- $post_author = $this->wpuf_get_post_user();
292
 
293
- $postarr = array(
294
  'post_type' => $this->form_settings['post_type'],
295
  'post_status' => isset( $this->form_settings['post_status'] ) ? $this->form_settings['post_status'] : 'publish',
296
  'post_author' => $post_author,
297
- 'post_title' => isset( $_POST['post_title'] ) ? trim( $_POST['post_title'] ) : '',
298
- 'post_content' => isset( $_POST['post_content'] ) ? trim( $_POST['post_content'] ) : '',
299
- 'post_excerpt' => isset( $_POST['post_excerpt'] ) ? trim( $_POST['post_excerpt'] ) : '',
300
- );
301
 
302
  // $charging_enabled = wpuf_get_option( 'charge_posting', 'wpuf_payment' );
303
  $charging_enabled = '';
@@ -321,25 +333,29 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
321
  if ( isset( $_POST['wpuf_is_publish_time'] ) ) {
322
  if ( isset( $_POST[$_POST['wpuf_is_publish_time']] ) && !empty( $_POST[$_POST['wpuf_is_publish_time']] ) ) {
323
  // $postarr['post_date'] = date( 'Y-m-d H:i:s', strtotime( str_replace( array( ':', '/' ), '-', $_POST[$_POST['wpuf_is_publish_time']] ) ) );
324
- $date_time = explode(" ", trim($_POST[$_POST['wpuf_is_publish_time']]) );
325
- if ( !empty ( $date_time[0] ) ) {
326
- $timestamp = strtotime( str_replace( array( '/' ), '-', $date_time[0] ) );
 
327
  }
328
- if ( !empty ( $date_time[1] ) ) {
329
- $time = explode(':', $date_time[1] );
330
- $seconds = ( $time[0] * 60 * 60 ) + ($time[1] * 60);
 
331
  $timestamp = $timestamp + $seconds;
332
  }
333
  $postarr['post_date'] = date( 'Y-m-d H:i:s', $timestamp );
334
  }
335
  }
336
 
337
- if ( isset( $_POST['category'] ) && ( $_POST['category'] !='' && $_POST['category'] !='0' && $_POST['category'][0] !='-1' ) ) {
338
- $category = $_POST['category'];
 
 
339
 
340
  if ( !is_array( $category ) && is_string( $category ) ) {
341
  $category_strings = explode( ',', $category );
342
- $cat_ids = array();
343
 
344
  foreach ( $category_strings as $key => $each_cat_string ) {
345
  $cat_ids[] = get_cat_ID( trim( $each_cat_string ) );
@@ -351,26 +367,27 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
351
  }
352
 
353
  if ( isset( $_POST['tags'] ) ) {
354
- $postarr['tags_input'] = explode( ',', $_POST['tags'] );
355
  }
356
 
357
  // if post_id is passed, we update the post
358
  if ( isset( $_POST['post_id'] ) ) {
 
359
  $is_update = true;
360
- $postarr['ID'] = $_POST['post_id'];
361
- $postarr['post_date'] = $_POST['post_date'];
362
- $postarr['comment_status'] = $_POST['comment_status'];
363
- $postarr['post_author'] = $_POST['post_author'];
364
- $postarr['post_parent'] = get_post_field( 'post_parent', $_POST['post_id'] );
365
 
366
- $menu_order = get_post_field('menu_order', $_POST['post_id']);
367
 
368
- if (!empty($menu_order)) {
369
  $postarr['menu_order'] = $menu_order;
370
  }
371
 
372
  if ( $this->form_settings['edit_post_status'] == '_nochange' ) {
373
- $postarr['post_status'] = get_post_field( 'post_status', $_POST['post_id'] );
374
  } else {
375
  $postarr['post_status'] = $this->form_settings['edit_post_status'];
376
  }
@@ -383,7 +400,8 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
383
  // check the form status, it might be already a draft
384
  // in that case, it already has the post_id field
385
  // so, WPUF's add post action/filters won't work for new posts
386
- if ( isset( $_POST['wpuf_form_status'] ) && $_POST['wpuf_form_status'] == 'new' ) {
 
387
  $is_update = false;
388
  }
389
 
@@ -392,7 +410,7 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
392
  if ( is_array( $this->form_settings['default_cat'] ) ) {
393
  $postarr['post_category'] = $this->form_settings['default_cat'];
394
  } else {
395
- $postarr['post_category'] = array( $this->form_settings['default_cat'] );
396
  }
397
  }
398
 
@@ -402,6 +420,7 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
402
  } else {
403
  $error = apply_filters( 'wpuf_add_post_validate', '' );
404
  }
 
405
  if ( !empty( $error ) ) {
406
  $this->send_error( $error );
407
  }
@@ -428,8 +447,7 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
428
  }
429
  }
430
 
431
- if ( $post_id ) {
432
-
433
  self::update_post_meta( $meta_vars, $post_id );
434
  // set the post form_id for later usage
435
  update_post_meta( $post_id, self::$config_id, $form_id );
@@ -454,7 +472,7 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
454
  if ( $images->length ) {
455
  foreach ( $images as $img ) {
456
  $url = $img->getAttribute( 'src' );
457
- $url = str_replace( array( '"', "'", "\\" ), '', $url );
458
  $attachment_id = wpuf_get_attachment_id_from_url( $url );
459
 
460
  if ( $attachment_id ) {
@@ -463,28 +481,32 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
463
  }
464
  }
465
  }
466
- if(!empty($taxonomy_vars)) {
467
- $this->set_custom_taxonomy($post_id,$taxonomy_vars);
 
468
  }
469
- $response = $this->send_mail_for_guest($charging_enabled,$post_id,$form_id,$is_update,$post_author,$meta_vars);
470
  wpuf_clear_buffer();
471
  wp_send_json( $response );
472
-
473
  }
474
  $this->send_error( __( 'Something went wrong', 'wp-user-frontend' ) );
475
  }
476
 
477
-
478
  public function wpuf_get_post_user() {
 
 
 
 
 
 
479
  $default_post_author = wpuf_get_option( 'default_post_owner', 'wpuf_frontend_posting', 1 );
480
 
481
  if ( !is_user_logged_in() ) {
482
-
483
  if ( isset( $this->form_settings['guest_post'] ) && $this->form_settings['guest_post'] == 'true' && $this->form_settings['guest_details'] == 'true' ) {
 
484
 
485
- $guest_name = trim( $_POST['guest_name'] );
486
-
487
- $guest_email = trim( $_POST['guest_email'] );
488
 
489
  // is valid email?
490
  if ( !is_email( $guest_email ) ) {
@@ -496,13 +518,12 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
496
 
497
  if ( $user ) {
498
  // $post_author = $user->ID;
499
- wp_send_json( array(
500
  'success' => false,
501
  'error' => __( "You already have an account in our site. Please login to continue.\n\nClicking 'OK' will redirect you to the login page and you will lose the form data.\nClick 'Cancel' to stay at this page.", 'wp-user-frontend' ),
502
  'type' => 'login',
503
- 'redirect_to' => wp_login_url( get_permalink( $_POST['page_id'] ) )
504
- ) );
505
-
506
  } else {
507
 
508
  // user not found, lets register him
@@ -520,7 +541,6 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
520
  // if its a success and no errors found
521
 
522
  if ( $user_id && !is_wp_error( $user_id ) ) {
523
-
524
  update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
525
 
526
  if ( class_exists( 'Theme_My_Login_Custom_Email' ) ) {
@@ -530,18 +550,16 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
530
  }
531
 
532
  // update display name to full name
533
- wp_update_user( array( 'ID' => $user_id, 'display_name' => $guest_name ) );
534
 
535
  $post_author = $user_id;
536
-
537
  } else {
538
  //something went wrong creating the user, set post author to the default author
539
  $post_author = $default_post_author;
540
  }
541
-
542
  }
543
 
544
- // guest post is enabled and details are off
545
  } elseif ( isset( $this->form_settings['guest_post'] ) && $this->form_settings['guest_post'] == 'true' && $this->form_settings['guest_details'] == 'false' ) {
546
  $post_author = $default_post_author;
547
  } elseif ( isset( $this->form_settings['guest_post'] ) && $this->form_settings['guest_post'] != 'true' ) {
@@ -550,18 +568,15 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
550
 
551
  // the user must be logged in already
552
  } elseif ( isset( $this->form_settings['role_base'] ) && $this->form_settings['role_base'] == 'true' ) {
553
-
554
  $current_user = wp_get_current_user();
555
 
556
  if ( !in_array( $current_user->roles[0], $this->form_settings['roles'] ) ) {
557
  $this->send_error( __( 'You do not have sufficient permissions to access this form.', 'wp-user-frontend' ) );
558
  }
559
-
560
  } else {
561
  $post_author = get_current_user_id();
562
  }
563
 
564
-
565
  return $post_author;
566
  }
567
 
@@ -572,46 +587,50 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
572
  * @return string
573
  */
574
 
575
- function add_post_shortcode( $atts ) {
576
- add_filter( 'wpuf-form-fields', array( $this, 'add_field_settings'));
577
- extract( shortcode_atts( array( 'id' => 0 ), $atts ) );
578
  ob_start();
579
- $form = new WPUF_Form( $id );
580
- $this->form_fields = $form->get_fields();
581
- $this->form_settings = $form->get_settings();
582
- list($user_can_post,$info) = $form->is_submission_open($form ,$this->form_settings);
583
- $info = apply_filters( 'wpuf_addpost_notice', $info, $id, $this->form_settings );
584
- $user_can_post = apply_filters( 'wpuf_can_post', $user_can_post, $id, $this->form_settings );
 
585
  if ( $user_can_post == 'yes' ) {
586
- $this->render_form( $id,null,$atts,$form);
587
  } else {
588
- echo '<div class="wpuf-info">' . $info . '</div>';
589
  }
590
  $content = ob_get_contents();
591
  ob_end_clean();
 
592
  return $content;
593
  }
594
 
595
  public static function update_post_meta( $meta_vars, $post_id ) {
596
-
597
  // prepare the meta vars
598
  list( $meta_key_value, $multi_repeated, $files ) = self::prepare_meta_fields( $meta_vars );
599
-
600
  // set featured image if there's any
601
- if ( isset( $_POST['wpuf_files']['featured_image'] ) ) {
602
- $attachment_id = $_POST['wpuf_files']['featured_image'][0];
 
 
603
 
604
  wpuf_associate_attachment( $attachment_id, $post_id );
605
  set_post_thumbnail( $post_id, $attachment_id );
606
 
607
- $file_data = isset( $_POST['wpuf_files_data'][$attachment_id] ) ? $_POST['wpuf_files_data'][$attachment_id] : false;
 
608
  if ( $file_data ) {
609
- $args = array(
610
  'ID' => $attachment_id,
611
  'post_title' => $file_data['title'],
612
  'post_content' => $file_data['desc'],
613
  'post_excerpt' => $file_data['caption'],
614
- );
615
  wpuf_update_post( $args );
616
 
617
  update_post_meta( $attachment_id, '_wp_attachment_image_alt', $file_data['title'] );
@@ -668,14 +687,15 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
668
  //add_post_meta( $post_id, $file_input['name'], $attachment_id );
669
 
670
  // file title, caption, desc update
671
- $file_data = isset( $_POST['wpuf_files_data'][$attachment_id] ) ? $_POST['wpuf_files_data'][$attachment_id] : false;
 
672
  if ( $file_data ) {
673
- $args = array(
674
  'ID' => $attachment_id,
675
  'post_title' => $file_data['title'],
676
  'post_content' => $file_data['desc'],
677
  'post_excerpt' => $file_data['caption'],
678
- );
679
  wpuf_update_post( $args );
680
 
681
  update_post_meta( $attachment_id, '_wp_attachment_image_alt', $file_data['title'] );
@@ -685,14 +705,14 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
685
  }
686
  }
687
 
688
- function prepare_mail_body( $content, $user_id, $post_id ) {
689
  $user = get_user_by( 'id', $user_id );
690
  $post = get_post( $post_id );
691
 
692
- $post_field_search = array( '%post_title%', '%post_content%', '%post_excerpt%', '%tags%', '%category%',
693
- '%author%', '%author_email%', '%author_bio%', '%sitename%', '%siteurl%', '%permalink%', '%editlink%' );
694
 
695
- $post_field_replace = array(
696
  $post->post_title,
697
  $post->post_content,
698
  $post->post_excerpt,
@@ -700,12 +720,12 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
700
  get_the_term_list( $post_id, 'category', '', ', ' ),
701
  $user->display_name,
702
  $user->user_email,
703
- ($user->description) ? $user->description : 'not available',
704
  get_bloginfo( 'name' ),
705
  home_url(),
706
  get_permalink( $post_id ),
707
- admin_url( 'post.php?action=edit&post=' . $post_id )
708
- );
709
 
710
  $content = str_replace( $post_field_search, $post_field_replace, $content );
711
 
@@ -719,10 +739,12 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
719
  $new_value = implode( '; ', $value );
720
 
721
  $original_value = '';
722
- $meta_val = '';
 
723
  if ( count( $value ) > 1 ) {
724
  $isFirst = true;
725
- foreach ($value as $val) {
 
726
  if ( $isFirst ) {
727
  if ( get_post_mime_type( (int) $val ) ) {
728
  $meta_val = wp_get_attachment_url( $val );
@@ -737,13 +759,14 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
737
  $meta_val = $meta_val . ', ' . $val;
738
  }
739
  }
 
740
  if ( get_post_mime_type( (int) $val ) ) {
741
  $meta_val = $meta_val . ',' . wp_get_attachment_url( $val );
742
  } else {
743
  $meta_val = $meta_val . ',' . $val;
744
  }
745
  }
746
- $original_value = $original_value . $meta_val ;
747
  } else {
748
  if ( get_post_mime_type( (int) $new_value ) ) {
749
  $original_value = wp_get_attachment_url( $new_value );
@@ -759,14 +782,17 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
759
  return $content;
760
  }
761
 
762
- function woo_attribute( $taxonomy ) {
763
- return array(
 
 
 
764
  'name' => $taxonomy['name'],
765
- 'value' => $_POST[$taxonomy['name']],
766
  'is_visible' => $taxonomy['woo_attr_vis'] == 'yes' ? 1 : 0,
767
  'is_variation' => 0,
768
- 'is_taxonomy' => 1
769
- );
770
  }
771
 
772
  /**
@@ -774,14 +800,15 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
774
  *
775
  * @since 2.5.8
776
  */
777
-
778
- function publish_guest_post () {
779
-
780
- if ( isset($_GET['post_msg']) && $_GET['post_msg'] == 'verified' ) {
781
-
782
- $response = array();
783
- $post_id = wpuf_decryption( $_GET['p_id'] );
784
- $form_id = wpuf_decryption( $_GET['f_id'] );
 
785
  $form_settings = wpuf_get_form_settings( $form_id );
786
  $post_author_id = get_post_field( 'post_author', $post_id );
787
  $payment_status = new WPUF_Subscription();
@@ -790,14 +817,13 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
790
  $force_pack = $form->is_enabled_force_pack();
791
 
792
  if ( $form->is_charging_enabled() && $pay_per_post ) {
793
- if ( ($payment_status->get_payment_status( $post_id ) ) == 'pending') {
794
-
795
  $response['show_message'] = true;
796
- $response['redirect_to'] = add_query_arg( array(
797
  'action' => 'wpuf_pay',
798
  'type' => 'post',
799
- 'post_id' => $post_id
800
- ), get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) ) );
801
 
802
  wp_redirect( $response['redirect_to'] );
803
  wpuf_clear_buffer();
@@ -805,96 +831,90 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
805
  }
806
  } else {
807
  $p_status = get_post_status( $post_id );
 
808
  if ( $p_status ) {
809
- wp_update_post(array(
810
- 'ID' => $post_id,
811
- 'post_status' => isset( $form_settings['post_status'] ) ? $form_settings['post_status'] : 'publish'
812
- ));
813
- echo "<div class='wpuf-success' style='text-align:center'>" . __( 'Email successfully verified. Please Login.', 'wp-user-frontend' ) ."</div>";
814
  }
815
-
816
  }
817
  }
818
  }
819
 
820
- function wpuf_user_subscription_pack( $form_settings, $post_id=null ) {
821
 
822
  // if user has a subscription pack
823
  $user_wpuf_subscription_pack = get_user_meta( get_current_user_id(), '_wpuf_subscription_pack', true );
824
 
825
  if ( !empty( $user_wpuf_subscription_pack ) && isset( $user_wpuf_subscription_pack['_enable_post_expiration'] )
826
  && isset( $user_wpuf_subscription_pack['expire'] ) && strtotime( $user_wpuf_subscription_pack['expire'] ) >= time() ) {
827
-
828
- $expire_date = date( 'Y-m-d', strtotime( "+" . $user_wpuf_subscription_pack['_post_expiration_time'] ) );
829
  update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
830
  // save post status after expiration
831
  $expired_post_status = $user_wpuf_subscription_pack['_expired_post_status'];
832
  update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
833
- // if mail active
834
  if ( isset( $user_wpuf_subscription_pack['_enable_mail_after_expired'] ) && $user_wpuf_subscription_pack['_enable_mail_after_expired'] == 'on' ) {
835
- $wpuf_user = wpuf_get_user();
836
- $user_subscription = new WPUF_User_Subscription( $wpuf_user );
837
- $post_expiration_message = $user_subscription->get_subscription_exp_msg( $user_wpuf_subscription_pack['pack_id'] );
838
- update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
839
  }
840
  } elseif ( !empty( $user_wpuf_subscription_pack ) && isset( $user_wpuf_subscription_pack['expire'] ) && strtotime( $user_wpuf_subscription_pack['expire'] ) <= time() ) {
841
-
842
  if ( isset( $form_settings['expiration_settings']['enable_post_expiration'] ) ) {
843
-
844
- $expire_date = date( 'Y-m-d', strtotime( "+" . $form_settings['expiration_settings']['expiration_time_value'] . ' ' . $form_settings['expiration_settings']['expiration_time_type'] . "" ) );
845
 
846
  update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
847
  // save post status after expiration
848
  $expired_post_status = $form_settings['expiration_settings']['expired_post_status'];
849
- update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
850
- // if mail active
851
  if ( isset( $form_settings['expiration_settings']['enable_mail_after_expired'] ) && $form_settings['expiration_settings']['enable_mail_after_expired'] == 'on' ) {
852
  $post_expiration_message = $form_settings['expiration_settings']['post_expiration_message'];
853
  update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
854
  }
855
  }
856
  } elseif ( empty( $user_wpuf_subscription_pack ) || $user_wpuf_subscription_pack == 'Cancel' || $user_wpuf_subscription_pack == 'cancel' ) {
857
- if ( isset( $form_settings['expiration_settings']['enable_post_expiration'] ) ) {
858
- $expire_date = date( 'Y-m-d', strtotime( "+" . $form_settings['expiration_settings']['expiration_time_value'] . ' ' . $form_settings['expiration_settings']['expiration_time_type'] . "" ) );
859
- update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
860
- // save post status after expiration
861
- $expired_post_status = $form_settings['expiration_settings']['expired_post_status'];
862
- update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
863
- // if mail active
864
- if ( isset( $form_settings['expiration_settings']['enable_mail_after_expired'] ) && $form_settings['expiration_settings']['enable_mail_after_expired'] == 'on' ) {
865
- $post_expiration_message = $form_settings['expiration_settings']['post_expiration_message'];
866
- update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
867
- }
868
  }
 
869
  }
870
  }
871
 
872
-
873
  public function send_mail_for_guest( $charging_enabled, $post_id, $form_id, $is_update, $post_author, $meta_vars ) {
874
  global $wp;
875
-
876
  $show_message = false;
877
  $redirect_to = false;
878
- $response = array();
 
879
 
880
  if ( $is_update ) {
881
-
882
  if ( $this->form_settings['edit_redirect_to'] == 'page' ) {
883
  $redirect_to = get_permalink( $this->form_settings['edit_page_id'] );
884
  } elseif ( $this->form_settings['edit_redirect_to'] == 'url' ) {
885
  $redirect_to = $this->form_settings['edit_url'];
886
  } elseif ( $this->form_settings['edit_redirect_to'] == 'same' ) {
887
- $redirect_to = add_query_arg( array(
888
  'pid' => $post_id,
889
  '_wpnonce' => wp_create_nonce( 'wpuf_edit' ),
890
- 'msg' => 'post_updated'
891
- ), get_permalink( $_POST['page_id'] ) );
892
  } else {
893
  $redirect_to = get_permalink( $post_id );
894
  }
895
-
896
  } else {
897
-
898
  if ( $this->form_settings['redirect_to'] == 'page' ) {
899
  $redirect_to = get_permalink( $this->form_settings['page_id'] );
900
  } elseif ( $this->form_settings['redirect_to'] == 'url' ) {
@@ -904,37 +924,36 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
904
  } else {
905
  $redirect_to = get_permalink( $post_id );
906
  }
907
-
908
  }
909
 
910
- $response = array(
911
  'success' => true,
912
  'redirect_to' => $redirect_to,
913
  'show_message' => $show_message,
914
- 'message' => $this->form_settings['message']
915
- );
916
 
917
  $guest_mode = isset( $this->form_settings['guest_post'] ) ? $this->form_settings['guest_post'] : '';
918
- $guest_verify = isset( $this->form_settings['guest_email_verify'] ) ? $this->form_settings['guest_email_verify'] : 'false' ;
919
 
920
- if ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() && $charging_enabled != 'yes') {
921
- $post_id_encoded = wpuf_encryption( $post_id ) ;
922
- $form_id_encoded = wpuf_encryption( $form_id ) ;
923
 
924
- wpuf_send_mail_to_guest ( $post_id_encoded, $form_id_encoded, 'no', 1 );
925
 
926
  $response['show_message'] = true;
927
  $response['redirect_to'] = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
928
  $response['message'] = __( 'Thank you for posting on our site. We have sent you an confirmation email. Please check your inbox!', 'wp-user-frontend' );
929
  } elseif ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() && $charging_enabled == 'yes' ) {
930
- $post_id_encoded = wpuf_encryption( $post_id ) ;
931
- $form_id_encoded = wpuf_encryption( $form_id ) ;
932
  $response['show_message'] = true;
933
  $response['redirect_to'] = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
934
  $response['message'] = __( 'Thank you for posting on our site. We have sent you an confirmation email. Please check your inbox!', 'wp-user-frontend' );
935
 
936
- update_post_meta ( $post_id, '_wpuf_payment_status', 'pending' );
937
- wpuf_send_mail_to_guest ( $post_id_encoded, $form_id_encoded, 'yes', 2 );
938
  }
939
 
940
  if ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() ) {
@@ -977,5 +996,4 @@ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form{
977
 
978
  return $response;
979
  }
980
-
981
  }
1
  <?php
2
 
3
+ class WPUF_Frontend_Form extends WPUF_Frontend_Render_Form {
 
4
  private static $_instance;
5
+
6
  private $post_expiration_date = 'wpuf-post_expiration_date';
7
+
8
  private $expired_post_status = 'wpuf-expired_post_status';
9
+
10
  private $post_expiration_message = 'wpuf-post_expiration_message';
11
 
12
+ public function __construct() {
13
+ add_shortcode( 'wpuf_form', [ $this, 'add_post_shortcode'] );
14
+ add_shortcode( 'wpuf_edit', [ $this, 'edit_post_shortcode' ] );
15
  // ajax requests
16
+ add_action( 'wp_ajax_wpuf_form_preview', [ $this, 'preview_form' ] );
17
+ add_action( 'wp_ajax_wpuf_submit_post', [ $this, 'submit_post' ] );
18
+ add_action( 'wp_ajax_nopriv_wpuf_submit_post', [ $this, 'submit_post' ] );
19
+ add_action( 'wp_ajax_make_media_embed_code', [ $this, 'make_media_embed_code' ] );
20
+ add_action( 'wp_ajax_nopriv_make_media_embed_code', [ $this, 'make_media_embed_code' ] );
21
  // // guest post hook
22
+ add_action( 'init', [ $this, 'publish_guest_post' ] );
23
  // draft
24
+ add_action( 'wp_ajax_wpuf_draft_post', [ $this, 'draft_post' ] );
25
  // form preview
26
+ add_action( 'wp_ajax_wpuf_form_preview', [ $this, 'preview_form' ] );
27
  $this->set_wp_post_types();
28
  }
29
 
31
  * Edit post shortcode handler
32
  *
33
  * @param array $atts
34
+ *
35
  * @return
36
  **/
37
+ public function edit_post_shortcode( $atts ) {
38
+ add_filter( 'wpuf-form-fields', [ $this, 'add_field_settings'] );
39
 
40
+ extract( shortcode_atts( [ 'id' => 0 ], $atts ) );
41
  ob_start();
42
 
43
  global $userdata;
45
  ob_start();
46
 
47
  if ( !is_user_logged_in() ) {
48
+ echo wp_kses_post( '<div class="wpuf-message">' . __( 'You are not logged in', 'wp-user-frontend' ) . '</div>',
49
+ wp_login_form() );
50
+
51
  return;
52
  }
53
 
54
+ $post_id = isset( $_GET['pid'] ) ? intval( wp_unslash( $_GET['pid'] ) ) : 0;
55
 
56
  if ( !$post_id ) {
57
  return '<div class="wpuf-info">' . __( 'Invalid post', 'wp-user-frontend' ) . '</div>';
64
  return '<div class="wpuf-info">' . apply_filters( 'wpuf_edit_post_lock_user_notice', __( 'Your edit access for this post has been locked by an administrator.', 'wp-user-frontend' ) ) . '</div>';
65
  }
66
 
67
+ if ( !empty( $edit_post_lock_time ) && $edit_post_lock_time < time() ) {
68
  return '<div class="wpuf-info">' . apply_filters( 'wpuf_edit_post_lock_expire_notice', __( 'Your allocated time for editing this post has been expired.', 'wp-user-frontend' ) ) . '</div>';
69
  }
70
 
72
  if ( wpuf_get_user()->edit_post_lock_reason() ) {
73
  return '<div class="wpuf-info">' . wpuf_get_user()->edit_post_lock_reason() . '</div>';
74
  }
75
+
76
  return '<div class="wpuf-info">' . apply_filters( 'wpuf_user_edit_post_lock_notice', __( 'Your post edit access has been locked by an administrator.', 'wp-user-frontend' ) ) . '</div>';
77
  }
78
 
115
  return '<div class="wpuf-info">' . __( 'You can\'t edit a post while in pending mode.', 'wp-user-frontend' );
116
  }
117
 
118
+ $msg = isset( $_GET['msg'] ) ? sanitize_text_field( wp_unslash( $_GET['msg'] ) ) : '';
119
+
120
+ if ( $msg == 'post_updated' ) {
121
+ echo wp_kses_post( '<div class="wpuf-success">' );
122
+ echo wp_kses_post( str_replace( '%link%', get_permalink( $post_id ), $this->form_settings['update_message'] ) );
123
+ echo wp_kses_post( '</div>' );
124
  }
125
 
126
+ $this->render_form( $form_id, $post_id, $atts, $form );
127
 
128
  $content = ob_get_contents();
129
 
132
  return $content;
133
  }
134
 
 
 
135
  public static function init() {
136
  if ( !self::$_instance ) {
137
+ self::$_instance = new self();
138
  }
139
+
140
  return self::$_instance;
141
  }
142
 
 
143
  /**
144
  * this will embed media to the editor
145
+ */
146
+ public function make_media_embed_code() {
147
+ $nonce = isset( $_GET['nonce'] ) ? sanitize_key( wp_unslash( $_GET['nonce'] ) ) : '';
148
+
149
+ if ( isset( $nonce ) && !wp_verify_nonce( $nonce, 'wpuf-upload-nonce' ) ) {
150
+ return ;
151
+ }
152
+
153
+ $content = isset( $_POST['content'] ) ? sanitize_text_field( wp_unslash( $_POST['content'] ) ) : '';
154
+
155
+ if ( $embed_code = wp_oembed_get( $content ) ) {
156
+ echo esc_html( $embed_code );
157
  } else {
158
  echo '';
159
  }
164
  * Draft Post
165
  */
166
  public function draft_post() {
 
167
  check_ajax_referer( 'wpuf_form_add' );
168
+ add_filter( 'wpuf-form-fields', [ $this, 'add_field_settings'] );
169
  @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
170
 
171
+ $form_id = isset( $_POST['form_id'] ) ? intval( wp_unslash( $_POST['form_id'] ) ) : 0;
172
  $form = new WPUF_Form( $form_id );
173
  $this->form_settings = $form->get_settings();
174
  $this->form_fields = $form->get_fields();
175
  $pay_per_post = $form->is_enabled_pay_per_post();
176
 
177
+ list( $post_vars, $taxonomy_vars, $meta_vars ) =$this->get_input_fields( $this->form_fields );
178
 
179
  $entry_fields = $form->prepare_entries();
180
+ $post_content = isset( $_POST[ 'post_content' ] ) ? sanitize_text_field( wp_unslash( $_POST[ 'post_content' ] ) ) : '';
181
 
182
+ $postarr = [
183
  'post_type' => $this->form_settings['post_type'],
184
  'post_status' => wpuf_get_draft_post_status( $this->form_settings ),
185
  'post_author' => get_current_user_id(),
186
+ 'post_title' => isset( $_POST['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['post_title'] ) ) : '',
187
  'post_content' => $post_content,
188
+ 'post_excerpt' => isset( $_POST['post_excerpt'] ) ? sanitize_text_field( wp_unslash( $_POST['post_excerpt'] ) ) : '',
189
+ ];
190
+
191
+ $category = isset( $_POST['category'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['category'] ) ) : '';
192
 
193
+ if ( $category != '' && $category != '0' && $category[0] != '-1' ) {
194
+ $postarr['post_category'] = is_array( $category ) ? $category : [ $category ];
 
195
  }
196
 
197
  // set default post category if it's not been set yet and if post type supports
199
  if ( is_array( $this->form_settings['default_cat'] ) ) {
200
  $postarr['post_category'] = $this->form_settings['default_cat'];
201
  } else {
202
+ $postarr['post_category'] = [ $this->form_settings['default_cat'] ];
203
  }
204
  }
205
 
206
  if ( isset( $_POST['tags'] ) ) {
207
+ $postarr['tags_input'] = explode( ',', array_map( 'sanitize_text_field', wp_unslash( $_POST['tags'] ) ) );
208
  }
209
 
210
  // if post_id is passed, we update the post
211
  if ( isset( $_POST['post_id'] ) ) {
212
  $is_update = true;
213
+ $postarr['ID'] = intval( wp_unslash( $_POST['post_id'] ) );
214
  $postarr['comment_status'] = 'open';
215
  }
216
 
220
  wpuf_frontend_post_revision( $post_id, $this->form_settings );
221
 
222
  if ( $post_id ) {
 
223
  self::update_post_meta( $meta_vars, $post_id );
224
 
225
  // set the post form_id for later usage
234
 
235
  // if pay per post is enabled then update payment status as pending
236
  if ( $pay_per_post ) {
237
+ update_post_meta( $post_id, '_wpuf_payment_status', 'pending' );
238
  }
239
 
240
+ if ( !empty( $taxonomy_vars ) ) {
241
+ $this->set_custom_taxonomy( $post_id, $taxonomy_vars );
242
  }
243
  }
244
 
245
+ //used to add code to run when the post is going to draft
246
  do_action( 'wpuf_draft_post_after_insert', $post_id, $form_id, $this->form_settings, $this->form_fields );
247
 
248
  wpuf_clear_buffer();
249
 
250
+ echo json_encode( [
251
  'post_id' => $post_id,
252
+ 'action' => isset( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '',
253
  'date' => current_time( 'mysql' ),
254
  'post_author' => get_current_user_id(),
255
  'comment_status' => get_option( 'default_comment_status' ),
256
+ 'url' => add_query_arg( 'preview', 'true', get_permalink( $post_id ) ),
257
+ ] );
258
 
259
  exit;
260
  }
261
 
 
262
  /**
263
  * New/Edit post submit handler
264
  *
265
  * @return void
266
  */
267
+ public function submit_post() {
 
268
  check_ajax_referer( 'wpuf_form_add' );
269
+ add_filter( 'wpuf-form-fields', [ $this, 'add_field_settings'] );
270
  @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
271
 
272
+ $form_id = isset( $_POST['form_id'] ) ? intval( wp_unslash( $_POST['form_id'] ) ) : 0;
273
  $form = new WPUF_Form( $form_id );
274
  $this->form_settings = $form->get_settings();
275
  $this->form_fields = $form->get_fields();
276
  $guest_mode = isset( $this->form_settings['guest_post'] ) ? $this->form_settings['guest_post'] : '';
277
+ $guest_verify = isset( $this->form_settings['guest_email_verify'] ) ? $this->form_settings['guest_email_verify'] : 'false';
278
+ $attachments_to_delete = isset( $_POST['delete_attachments'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['delete_attachments'] ) ) : [];
279
 
280
  foreach ( $attachments_to_delete as $attach_id ) {
281
  wp_delete_attachment( $attach_id, true );
282
  }
283
 
284
+ list( $post_vars, $taxonomy_vars, $meta_vars ) =$this->get_input_fields( $this->form_fields );
285
 
286
  if ( !isset( $_POST['post_id'] ) ) {
287
  $has_limit = ( isset( $this->form_settings['limit_entries'] ) && $this->form_settings['limit_entries'] == 'true' ) ? true : false;
288
+
289
  if ( $has_limit ) {
290
  $limit = (int) !empty( $this->form_settings['limit_number'] ) ? $this->form_settings['limit_number'] : 0;
291
  $form_entries = wpuf_form_posts_count( $form_id );
292
+
293
  if ( $limit && $limit <= $form_entries ) {
294
  $this->send_error( $this->form_settings['limit_message'] );
295
  }
300
  $is_update = false;
301
  $post_author = null;
302
  $default_post_author = wpuf_get_option( 'default_post_owner', 'wpuf_frontend_posting', 1 );
303
+ $post_author = $this->wpuf_get_post_user();
304
 
305
+ $postarr = [
306
  'post_type' => $this->form_settings['post_type'],
307
  'post_status' => isset( $this->form_settings['post_status'] ) ? $this->form_settings['post_status'] : 'publish',
308
  'post_author' => $post_author,
309
+ 'post_title' => isset( $_POST['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['post_title'] ) ) : '',
310
+ 'post_content' => isset( $_POST['post_content'] ) ? sanitize_text_field( wp_unslash( $_POST['post_content'] ) ) : '',
311
+ 'post_excerpt' => isset( $_POST['post_excerpt'] ) ? sanitize_text_field( wp_unslash( $_POST['post_excerpt'] ) ) : '',
312
+ ];
313
 
314
  // $charging_enabled = wpuf_get_option( 'charge_posting', 'wpuf_payment' );
315
  $charging_enabled = '';
333
  if ( isset( $_POST['wpuf_is_publish_time'] ) ) {
334
  if ( isset( $_POST[$_POST['wpuf_is_publish_time']] ) && !empty( $_POST[$_POST['wpuf_is_publish_time']] ) ) {
335
  // $postarr['post_date'] = date( 'Y-m-d H:i:s', strtotime( str_replace( array( ':', '/' ), '-', $_POST[$_POST['wpuf_is_publish_time']] ) ) );
336
+ $date_time = explode( ' ', sanitize_text_field( wp_unslash( ( $_POST[$_POST['wpuf_is_publish_time']] ) ) ) );
337
+
338
+ if ( !empty( $date_time[0] ) ) {
339
+ $timestamp = strtotime( str_replace( [ '/' ], '-', $date_time[0] ) );
340
  }
341
+
342
+ if ( !empty( $date_time[1] ) ) {
343
+ $time = explode( ':', $date_time[1] );
344
+ $seconds = ( $time[0] * 60 * 60 ) + ( $time[1] * 60 );
345
  $timestamp = $timestamp + $seconds;
346
  }
347
  $postarr['post_date'] = date( 'Y-m-d H:i:s', $timestamp );
348
  }
349
  }
350
 
351
+ $category = isset( $_POST['category'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['category'] ) ) : '';
352
+
353
+ if ( $category != '' && $category != '0' && $category[0] != '-1' ) {
354
+
355
 
356
  if ( !is_array( $category ) && is_string( $category ) ) {
357
  $category_strings = explode( ',', $category );
358
+ $cat_ids = [];
359
 
360
  foreach ( $category_strings as $key => $each_cat_string ) {
361
  $cat_ids[] = get_cat_ID( trim( $each_cat_string ) );
367
  }
368
 
369
  if ( isset( $_POST['tags'] ) ) {
370
+ $postarr['tags_input'] = explode( ',', sanitize_text_field( wp_unslash( $_POST['tags'] ) ) );
371
  }
372
 
373
  // if post_id is passed, we update the post
374
  if ( isset( $_POST['post_id'] ) ) {
375
+ $post_id = intval( wp_unslash( $_POST['post_id'] ) );
376
  $is_update = true;
377
+ $postarr['ID'] = $post_id;
378
+ $postarr['post_date'] = isset( $_POST['post_date'] ) ? sanitize_text_field( wp_unslash( $_POST['post_date'] ) ) : '';
379
+ $postarr['comment_status'] = isset( $_POST['comment_status'] ) ? sanitize_text_field( wp_unslash( $_POST['comment_status'] ) ) : '';
380
+ $postarr['post_author'] = isset( $_POST['post_author'] ) ? sanitize_text_field( wp_unslash( $_POST['post_author'] ) ) : '';
381
+ $postarr['post_parent'] = get_post_field( 'post_parent', $post_id );
382
 
383
+ $menu_order = get_post_field( 'menu_order', $post_id );
384
 
385
+ if ( !empty( $menu_order ) ) {
386
  $postarr['menu_order'] = $menu_order;
387
  }
388
 
389
  if ( $this->form_settings['edit_post_status'] == '_nochange' ) {
390
+ $postarr['post_status'] = get_post_field( 'post_status', $post_id );
391
  } else {
392
  $postarr['post_status'] = $this->form_settings['edit_post_status'];
393
  }
400
  // check the form status, it might be already a draft
401
  // in that case, it already has the post_id field
402
  // so, WPUF's add post action/filters won't work for new posts
403
+ $wpuf_form_status = isset( $_POST['wpuf_form_status'] ) ? sanitize_text_field( wp_unslash( $_POST['wpuf_form_status'] ) ) : '';
404
+ if ( $wpuf_form_status == 'new' ) {
405
  $is_update = false;
406
  }
407
 
410
  if ( is_array( $this->form_settings['default_cat'] ) ) {
411
  $postarr['post_category'] = $this->form_settings['default_cat'];
412
  } else {
413
+ $postarr['post_category'] = [ $this->form_settings['default_cat'] ];
414
  }
415
  }
416
 
420
  } else {
421
  $error = apply_filters( 'wpuf_add_post_validate', '' );
422
  }
423
+
424
  if ( !empty( $error ) ) {
425
  $this->send_error( $error );
426
  }
447
  }
448
  }
449
 
450
+ if ( $post_id ) {
 
451
  self::update_post_meta( $meta_vars, $post_id );
452
  // set the post form_id for later usage
453
  update_post_meta( $post_id, self::$config_id, $form_id );
472
  if ( $images->length ) {
473
  foreach ( $images as $img ) {
474
  $url = $img->getAttribute( 'src' );
475
+ $url = str_replace( [ '"', "'", '\\' ], '', $url );
476
  $attachment_id = wpuf_get_attachment_id_from_url( $url );
477
 
478
  if ( $attachment_id ) {
481
  }
482
  }
483
  }
484
+
485
+ if ( !empty( $taxonomy_vars ) ) {
486
+ $this->set_custom_taxonomy( $post_id, $taxonomy_vars );
487
  }
488
+ $response = $this->send_mail_for_guest( $charging_enabled, $post_id, $form_id, $is_update, $post_author, $meta_vars );
489
  wpuf_clear_buffer();
490
  wp_send_json( $response );
 
491
  }
492
  $this->send_error( __( 'Something went wrong', 'wp-user-frontend' ) );
493
  }
494
 
 
495
  public function wpuf_get_post_user() {
496
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
497
+
498
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'wpuf_form_add' ) ) {
499
+ return ;
500
+ }
501
+
502
  $default_post_author = wpuf_get_option( 'default_post_owner', 'wpuf_frontend_posting', 1 );
503
 
504
  if ( !is_user_logged_in() ) {
 
505
  if ( isset( $this->form_settings['guest_post'] ) && $this->form_settings['guest_post'] == 'true' && $this->form_settings['guest_details'] == 'true' ) {
506
+ $guest_name = isset( $_POST['guest_name'] ) ? sanitize_text_field( wp_unslash( $_POST['guest_name'] ) ) : '';
507
 
508
+ $guest_email = isset( $_POST['guest_email'] ) ? sanitize_email( wp_unslash( $_POST['guest_email'] ) ) : '';
509
+ $page_id = isset( $_POST['page_id'] ) ? sanitize_text_field( wp_unslash( $_POST['page_id'] ) ) : '';
 
510
 
511
  // is valid email?
512
  if ( !is_email( $guest_email ) ) {
518
 
519
  if ( $user ) {
520
  // $post_author = $user->ID;
521
+ wp_send_json( [
522
  'success' => false,
523
  'error' => __( "You already have an account in our site. Please login to continue.\n\nClicking 'OK' will redirect you to the login page and you will lose the form data.\nClick 'Cancel' to stay at this page.", 'wp-user-frontend' ),
524
  'type' => 'login',
525
+ 'redirect_to' => wp_login_url( get_permalink( $page_id ) ),
526
+ ] );
 
527
  } else {
528
 
529
  // user not found, lets register him
541
  // if its a success and no errors found
542
 
543
  if ( $user_id && !is_wp_error( $user_id ) ) {
 
544
  update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
545
 
546
  if ( class_exists( 'Theme_My_Login_Custom_Email' ) ) {
550
  }
551
 
552
  // update display name to full name
553
+ wp_update_user( [ 'ID' => $user_id, 'display_name' => $guest_name ] );
554
 
555
  $post_author = $user_id;
 
556
  } else {
557
  //something went wrong creating the user, set post author to the default author
558
  $post_author = $default_post_author;
559
  }
 
560
  }
561
 
562
+ // guest post is enabled and details are off
563
  } elseif ( isset( $this->form_settings['guest_post'] ) && $this->form_settings['guest_post'] == 'true' && $this->form_settings['guest_details'] == 'false' ) {
564
  $post_author = $default_post_author;
565
  } elseif ( isset( $this->form_settings['guest_post'] ) && $this->form_settings['guest_post'] != 'true' ) {
568
 
569
  // the user must be logged in already
570
  } elseif ( isset( $this->form_settings['role_base'] ) && $this->form_settings['role_base'] == 'true' ) {
 
571
  $current_user = wp_get_current_user();
572
 
573
  if ( !in_array( $current_user->roles[0], $this->form_settings['roles'] ) ) {
574
  $this->send_error( __( 'You do not have sufficient permissions to access this form.', 'wp-user-frontend' ) );
575
  }
 
576
  } else {
577
  $post_author = get_current_user_id();
578
  }
579
 
 
580
  return $post_author;
581
  }
582
 
587
  * @return string
588
  */
589
 
590
+ public function add_post_shortcode( $atts ) {
591
+ add_filter( 'wpuf-form-fields', [ $this, 'add_field_settings'] );
592
+ extract( shortcode_atts( [ 'id' => 0 ], $atts ) );
593
  ob_start();
594
+ $form = new WPUF_Form( $id );
595
+ $this->form_fields = $form->get_fields();
596
+ $this->form_settings = $form->get_settings();
597
+ list( $user_can_post, $info ) = $form->is_submission_open( $form, $this->form_settings );
598
+ $info = apply_filters( 'wpuf_addpost_notice', $info, $id, $this->form_settings );
599
+ $user_can_post = apply_filters( 'wpuf_can_post', $user_can_post, $id, $this->form_settings );
600
+
601
  if ( $user_can_post == 'yes' ) {
602
+ $this->render_form( $id, null, $atts, $form );
603
  } else {
604
+ echo wp_kses_post( '<div class="wpuf-info">' . $info . '</div>' );
605
  }
606
  $content = ob_get_contents();
607
  ob_end_clean();
608
+
609
  return $content;
610
  }
611
 
612
  public static function update_post_meta( $meta_vars, $post_id ) {
613
+ check_ajax_referer( 'wpuf_form_add' );
614
  // prepare the meta vars
615
  list( $meta_key_value, $multi_repeated, $files ) = self::prepare_meta_fields( $meta_vars );
 
616
  // set featured image if there's any
617
+ $wpuf_files = isset( $_POST['wpuf_files'] ) ? wp_unslash( $_POST['wpuf_files'] ) : [];
618
+
619
+ if ( isset( $wpuf_files['featured_image'] ) ) {
620
+ $attachment_id = $wpuf_files['featured_image'][0];
621
 
622
  wpuf_associate_attachment( $attachment_id, $post_id );
623
  set_post_thumbnail( $post_id, $attachment_id );
624
 
625
+ $file_data = isset( $wpuf_files[$attachment_id] ) ? $wpuf_files[$attachment_id] : false;
626
+
627
  if ( $file_data ) {
628
+ $args = [
629
  'ID' => $attachment_id,
630
  'post_title' => $file_data['title'],
631
  'post_content' => $file_data['desc'],
632
  'post_excerpt' => $file_data['caption'],
633
+ ];
634
  wpuf_update_post( $args );
635
 
636
  update_post_meta( $attachment_id, '_wp_attachment_image_alt', $file_data['title'] );
687
  //add_post_meta( $post_id, $file_input['name'], $attachment_id );
688
 
689
  // file title, caption, desc update
690
+ $file_data = isset( $wpuf_files[$attachment_id] ) ? $wpuf_files[$attachment_id] : false;
691
+
692
  if ( $file_data ) {
693
+ $args = [
694
  'ID' => $attachment_id,
695
  'post_title' => $file_data['title'],
696
  'post_content' => $file_data['desc'],
697
  'post_excerpt' => $file_data['caption'],
698
+ ];
699
  wpuf_update_post( $args );
700
 
701
  update_post_meta( $attachment_id, '_wp_attachment_image_alt', $file_data['title'] );
705
  }
706
  }
707
 
708
+ public function prepare_mail_body( $content, $user_id, $post_id ) {
709
  $user = get_user_by( 'id', $user_id );
710
  $post = get_post( $post_id );
711
 
712
+ $post_field_search = [ '%post_title%', '%post_content%', '%post_excerpt%', '%tags%', '%category%',
713
+ '%author%', '%author_email%', '%author_bio%', '%sitename%', '%siteurl%', '%permalink%', '%editlink%', ];
714
 
715
+ $post_field_replace = [
716
  $post->post_title,
717
  $post->post_content,
718
  $post->post_excerpt,
720
  get_the_term_list( $post_id, 'category', '', ', ' ),
721
  $user->display_name,
722
  $user->user_email,
723
+ ( $user->description ) ? $user->description : 'not available',
724
  get_bloginfo( 'name' ),
725
  home_url(),
726
  get_permalink( $post_id ),
727
+ admin_url( 'post.php?action=edit&post=' . $post_id ),
728
+ ];
729
 
730
  $content = str_replace( $post_field_search, $post_field_replace, $content );
731
 
739
  $new_value = implode( '; ', $value );
740
 
741
  $original_value = '';
742
+ $meta_val = '';
743
+
744
  if ( count( $value ) > 1 ) {
745
  $isFirst = true;
746
+
747
+ foreach ( $value as $val ) {
748
  if ( $isFirst ) {
749
  if ( get_post_mime_type( (int) $val ) ) {
750
  $meta_val = wp_get_attachment_url( $val );
759
  $meta_val = $meta_val . ', ' . $val;
760
  }
761
  }
762
+
763
  if ( get_post_mime_type( (int) $val ) ) {
764
  $meta_val = $meta_val . ',' . wp_get_attachment_url( $val );
765
  } else {
766
  $meta_val = $meta_val . ',' . $val;
767
  }
768
  }
769
+ $original_value = $original_value . $meta_val;
770
  } else {
771
  if ( get_post_mime_type( (int) $new_value ) ) {
772
  $original_value = wp_get_attachment_url( $new_value );
782
  return $content;
783
  }
784
 
785
+ public function woo_attribute( $taxonomy ) {
786
+ check_ajax_referer( 'wpuf_form_add' );
787
+ $taxonomy_name = isset( $_POST[$taxonomy['name']] ) ? sanitize_text_field( wp_unslash( $_POST[$taxonomy['name']] ) ) : '';
788
+
789
+ return [
790
  'name' => $taxonomy['name'],
791
+ 'value' => $taxonomy_name,
792
  'is_visible' => $taxonomy['woo_attr_vis'] == 'yes' ? 1 : 0,
793
  'is_variation' => 0,
794
+ 'is_taxonomy' => 1,
795
+ ];
796
  }
797
 
798
  /**
800
  *
801
  * @since 2.5.8
802
  */
803
+ public function publish_guest_post() {
804
+ $post_msg = isset( $_GET['post_msg'] ) ? sanitize_text_field( wp_unslash( $_GET['post_msg'] ) ) : '';
805
+ $pid = isset( $_GET['p_id'] ) ? sanitize_text_field( wp_unslash( $_GET['p_id'] ) ) : '';
806
+ $fid = isset( $_GET['f_id'] ) ? sanitize_text_field( wp_unslash( $_GET['f_id'] ) ) : '';
807
+
808
+ if ( $post_msg == 'verified' ) {
809
+ $response = [];
810
+ $post_id = wpuf_decryption( $pid );
811
+ $form_id = wpuf_decryption( $fid );
812
  $form_settings = wpuf_get_form_settings( $form_id );
813
  $post_author_id = get_post_field( 'post_author', $post_id );
814
  $payment_status = new WPUF_Subscription();
817
  $force_pack = $form->is_enabled_force_pack();
818
 
819
  if ( $form->is_charging_enabled() && $pay_per_post ) {
820
+ if ( ( $payment_status->get_payment_status( $post_id ) ) == 'pending' ) {
 
821
  $response['show_message'] = true;
822
+ $response['redirect_to'] = add_query_arg( [
823
  'action' => 'wpuf_pay',
824
  'type' => 'post',
825
+ 'post_id' => $post_id,
826
+ ], get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) ) );
827
 
828
  wp_redirect( $response['redirect_to'] );
829
  wpuf_clear_buffer();
831
  }
832
  } else {
833
  $p_status = get_post_status( $post_id );
834
+
835
  if ( $p_status ) {
836
+ wp_update_post( [
837
+ 'ID' => $post_id,
838
+ 'post_status' => isset( $form_settings['post_status'] ) ? $form_settings['post_status'] : 'publish',
839
+ ] );
840
+ echo wp_kses_post( "<div class='wpuf-success' style='text-align:center'>" . __( 'Email successfully verified. Please Login.', 'wp-user-frontend' ) . '</div>' );
841
  }
 
842
  }
843
  }
844
  }
845
 
846
+ public function wpuf_user_subscription_pack( $form_settings, $post_id=null ) {
847
 
848
  // if user has a subscription pack
849
  $user_wpuf_subscription_pack = get_user_meta( get_current_user_id(), '_wpuf_subscription_pack', true );
850
 
851
  if ( !empty( $user_wpuf_subscription_pack ) && isset( $user_wpuf_subscription_pack['_enable_post_expiration'] )
852
  && isset( $user_wpuf_subscription_pack['expire'] ) && strtotime( $user_wpuf_subscription_pack['expire'] ) >= time() ) {
853
+ $expire_date = date( 'Y-m-d', strtotime( '+' . $user_wpuf_subscription_pack['_post_expiration_time'] ) );
 
854
  update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
855
  // save post status after expiration
856
  $expired_post_status = $user_wpuf_subscription_pack['_expired_post_status'];
857
  update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
858
+ // if mail active
859
  if ( isset( $user_wpuf_subscription_pack['_enable_mail_after_expired'] ) && $user_wpuf_subscription_pack['_enable_mail_after_expired'] == 'on' ) {
860
+ $wpuf_user = wpuf_get_user();
861
+ $user_subscription = new WPUF_User_Subscription( $wpuf_user );
862
+ $post_expiration_message = $user_subscription->get_subscription_exp_msg( $user_wpuf_subscription_pack['pack_id'] );
863
+ update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
864
  }
865
  } elseif ( !empty( $user_wpuf_subscription_pack ) && isset( $user_wpuf_subscription_pack['expire'] ) && strtotime( $user_wpuf_subscription_pack['expire'] ) <= time() ) {
 
866
  if ( isset( $form_settings['expiration_settings']['enable_post_expiration'] ) ) {
867
+ $expire_date = date( 'Y-m-d', strtotime( '+' . $form_settings['expiration_settings']['expiration_time_value'] . ' ' . $form_settings['expiration_settings']['expiration_time_type'] . '' ) );
 
868
 
869
  update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
870
  // save post status after expiration
871
  $expired_post_status = $form_settings['expiration_settings']['expired_post_status'];
872
+ update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
873
+ // if mail active
874
  if ( isset( $form_settings['expiration_settings']['enable_mail_after_expired'] ) && $form_settings['expiration_settings']['enable_mail_after_expired'] == 'on' ) {
875
  $post_expiration_message = $form_settings['expiration_settings']['post_expiration_message'];
876
  update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
877
  }
878
  }
879
  } elseif ( empty( $user_wpuf_subscription_pack ) || $user_wpuf_subscription_pack == 'Cancel' || $user_wpuf_subscription_pack == 'cancel' ) {
880
+ if ( isset( $form_settings['expiration_settings']['enable_post_expiration'] ) ) {
881
+ $expire_date = date( 'Y-m-d', strtotime( '+' . $form_settings['expiration_settings']['expiration_time_value'] . ' ' . $form_settings['expiration_settings']['expiration_time_type'] . '' ) );
882
+ update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
883
+ // save post status after expiration
884
+ $expired_post_status = $form_settings['expiration_settings']['expired_post_status'];
885
+ update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
886
+ // if mail active
887
+ if ( isset( $form_settings['expiration_settings']['enable_mail_after_expired'] ) && $form_settings['expiration_settings']['enable_mail_after_expired'] == 'on' ) {
888
+ $post_expiration_message = $form_settings['expiration_settings']['post_expiration_message'];
889
+ update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
 
890
  }
891
+ }
892
  }
893
  }
894
 
 
895
  public function send_mail_for_guest( $charging_enabled, $post_id, $form_id, $is_update, $post_author, $meta_vars ) {
896
  global $wp;
897
+ check_ajax_referer( 'wpuf_form_add' );
898
  $show_message = false;
899
  $redirect_to = false;
900
+ $response = [];
901
+ $page_id = isset( $_POST['page_id'] ) ? intval( wp_unslash( $_POST['page_id'] ) ) : '';
902
 
903
  if ( $is_update ) {
 
904
  if ( $this->form_settings['edit_redirect_to'] == 'page' ) {
905
  $redirect_to = get_permalink( $this->form_settings['edit_page_id'] );
906
  } elseif ( $this->form_settings['edit_redirect_to'] == 'url' ) {
907
  $redirect_to = $this->form_settings['edit_url'];
908
  } elseif ( $this->form_settings['edit_redirect_to'] == 'same' ) {
909
+ $redirect_to = add_query_arg( [
910
  'pid' => $post_id,
911
  '_wpnonce' => wp_create_nonce( 'wpuf_edit' ),
912
+ 'msg' => 'post_updated',
913
+ ], get_permalink( $page_id ) );
914
  } else {
915
  $redirect_to = get_permalink( $post_id );
916
  }
 
917
  } else {
 
918
  if ( $this->form_settings['redirect_to'] == 'page' ) {
919
  $redirect_to = get_permalink( $this->form_settings['page_id'] );
920
  } elseif ( $this->form_settings['redirect_to'] == 'url' ) {
924
  } else {
925
  $redirect_to = get_permalink( $post_id );
926
  }
 
927
  }
928
 
929
+ $response = [
930
  'success' => true,
931
  'redirect_to' => $redirect_to,
932
  'show_message' => $show_message,
933
+ 'message' => $this->form_settings['message'],
934
+ ];
935
 
936
  $guest_mode = isset( $this->form_settings['guest_post'] ) ? $this->form_settings['guest_post'] : '';
937
+ $guest_verify = isset( $this->form_settings['guest_email_verify'] ) ? $this->form_settings['guest_email_verify'] : 'false';
938
 
939
+ if ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() && $charging_enabled != 'yes' ) {
940
+ $post_id_encoded = wpuf_encryption( $post_id );
941
+ $form_id_encoded = wpuf_encryption( $form_id );
942
 
943
+ wpuf_send_mail_to_guest( $post_id_encoded, $form_id_encoded, 'no', 1 );
944
 
945
  $response['show_message'] = true;
946
  $response['redirect_to'] = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
947
  $response['message'] = __( 'Thank you for posting on our site. We have sent you an confirmation email. Please check your inbox!', 'wp-user-frontend' );
948
  } elseif ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() && $charging_enabled == 'yes' ) {
949
+ $post_id_encoded = wpuf_encryption( $post_id );
950
+ $form_id_encoded = wpuf_encryption( $form_id );
951
  $response['show_message'] = true;
952
  $response['redirect_to'] = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
953
  $response['message'] = __( 'Thank you for posting on our site. We have sent you an confirmation email. Please check your inbox!', 'wp-user-frontend' );
954
 
955
+ update_post_meta( $post_id, '_wpuf_payment_status', 'pending' );
956
+ wpuf_send_mail_to_guest( $post_id_encoded, $form_id_encoded, 'yes', 2 );
957
  }
958
 
959
  if ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() ) {
996
 
997
  return $response;
998
  }
 
999
  }
includes/class-frontend-render-form.php CHANGED
@@ -1,29 +1,36 @@
1
  <?php
2
 
3
- class WPUF_Frontend_Render_Form{
4
-
5
  private static $_instance;
6
- static $meta_key = 'wpuf_form';
7
- static $separator = ' | ';
8
- static $config_id = '_wpuf_form_id';
 
 
 
 
9
  private $form_condition_key = 'wpuf_cond';
 
10
  private $field_count = 0;
 
11
  public $multiform_start = 0;
12
 
13
- public $wp_post_types = array();
14
- public $form_fields = array();
15
- public $form_settings = array();
 
 
16
 
17
  /**
18
  * Send json error message
19
  *
20
  * @param string $error
21
  */
22
- function send_error( $error ) {
23
- echo json_encode( array(
24
  'success' => false,
25
- 'error' => $error
26
- ) );
27
 
28
  die();
29
  }
@@ -31,20 +38,23 @@ class WPUF_Frontend_Render_Form{
31
  /**
32
  * Search on multi dimentional array
33
  *
34
- * @param array $array
35
- * @param string $key name of key
36
  * @param string $value the value to search
 
37
  * @return array
38
- */
39
- function search( $array, $key, $value ) {
40
- $results = array();
41
 
42
  if ( is_array( $array ) ) {
43
- if ( isset( $array[$key] ) && $array[$key] == $value )
44
  $results[] = $array;
 
45
 
46
- foreach ($array as $subarray)
47
  $results = array_merge( $results, $this->search( $subarray, $key, $value ) );
 
48
  }
49
 
50
  return $results;
@@ -54,16 +64,21 @@ class WPUF_Frontend_Render_Form{
54
  * Really simple captcha validation
55
  *
56
  * @return void
57
- */
58
- function validate_rs_captcha() {
59
- $rs_captcha_input = isset( $_POST['rs_captcha'] ) ? $_POST['rs_captcha'] : '';
60
- $rs_captcha_file = isset( $_POST['rs_captcha_val'] ) ? $_POST['rs_captcha_val'] : '';
 
 
 
 
 
 
61
 
62
  if ( class_exists( 'ReallySimpleCaptcha' ) ) {
63
  $captcha_instance = new ReallySimpleCaptcha();
64
 
65
  if ( !$captcha_instance->check( $rs_captcha_file, $rs_captcha_input ) ) {
66
-
67
  $this->send_error( __( 'Really Simple Captcha validation failed', 'wp-user-frontend' ) );
68
  } else {
69
  // validation success, remove the files
@@ -77,60 +92,60 @@ class WPUF_Frontend_Render_Form{
77
  *
78
  * @return void
79
  */
80
- function validate_re_captcha( $no_captcha = '', $invisible = '' ) {
81
  // need to check if invisible reCaptcha need library or we can do it here.
82
  // ref: https://shareurcodes.com/blog/google%20invisible%20recaptcha%20integration%20with%20php
83
- $site_key = wpuf_get_option( 'recaptcha_public', 'wpuf_general' );
84
- $private_key = wpuf_get_option( 'recaptcha_private', 'wpuf_general' );
85
- if ( $no_captcha == 1 && 0 == $invisible ) {
 
 
 
86
 
 
87
  if ( !class_exists( 'WPUF_ReCaptcha' ) ) {
88
  require_once WPUF_ROOT . '/lib/recaptchalib_noCaptcha.php';
89
  }
90
 
91
- $response = null;
92
- $reCaptcha = new WPUF_ReCaptcha($private_key);
93
 
94
  $resp = $reCaptcha->verifyResponse(
95
- $_SERVER["REMOTE_ADDR"],
96
- $_POST["g-recaptcha-response"]
97
- );
98
 
99
  if ( !$resp->success ) {
100
  $this->send_error( __( 'noCaptcha reCAPTCHA validation failed', 'wp-user-frontend' ) );
101
  }
102
-
103
  } elseif ( $no_captcha == 0 && 0 == $invisible ) {
 
 
104
 
105
- $recap_challenge = isset( $_POST['recaptcha_challenge_field'] ) ? $_POST['recaptcha_challenge_field'] : '';
106
- $recap_response = isset( $_POST['recaptcha_response_field'] ) ? $_POST['recaptcha_response_field'] : '';
107
-
108
- $resp = recaptcha_check_answer( $private_key, $_SERVER["REMOTE_ADDR"], $recap_challenge, $recap_response );
109
 
110
  if ( !$resp->is_valid ) {
111
  $this->send_error( __( 'reCAPTCHA validation failed', 'wp-user-frontend' ) );
112
  }
113
-
114
  } elseif ( $no_captcha == 0 && 1 == $invisible ) {
115
-
116
  $response = null;
117
- $recaptcha = $_POST['g-recaptcha-response'];
118
- $object = new Invisible_Recaptcha( $site_key , $private_key );
119
 
120
  $response = $object->verifyResponse( $recaptcha );
121
 
122
- if ( isset( $response['success'] ) and $response['success'] != true) {
123
  $this->send_error( __( 'Invisible reCAPTCHA validation failed', 'wp-user-frontend' ) );
124
  }
125
  }
126
-
127
  }
128
 
129
  /**
130
  * render submit button
131
- * @param [type] $form_id [description]
132
- * @param [type] $form_settings [description]
133
- * @param [type] $post_id [description]
 
134
  */
135
  public function submit_button( $form_id, $form_settings, $post_id = null ) { ?>
136
 
@@ -140,8 +155,8 @@ class WPUF_Frontend_Render_Form{
140
  </div>
141
 
142
  <?php wp_nonce_field( 'wpuf_form_add' ); ?>
143
- <input type="hidden" name="form_id" value="<?php echo $form_id; ?>">
144
- <input type="hidden" name="page_id" value="<?php echo get_post() ? get_the_ID() : '0'; ?>">
145
  <input type="hidden" id="del_attach" name="delete_attachments[]">
146
  <input type="hidden" name="action" value="wpuf_submit_post">
147
 
@@ -149,19 +164,19 @@ class WPUF_Frontend_Render_Form{
149
 
150
  <?php
151
  if ( $post_id ) {
152
- $cur_post = get_post( $post_id );
153
- ?>
154
- <input type="hidden" name="post_id" value="<?php echo $post_id; ?>">
155
  <input type="hidden" name="post_date" value="<?php echo esc_attr( $cur_post->post_date ); ?>">
156
  <input type="hidden" name="comment_status" value="<?php echo esc_attr( $cur_post->comment_status ); ?>">
157
  <input type="hidden" name="post_author" value="<?php echo esc_attr( $cur_post->post_author ); ?>">
158
- <input type="submit" class="wpuf-submit-button wpuf_submit_<?php echo $form_id; ?>" name="submit" value="<?php echo $form_settings['update_text']; ?>" />
159
- <?php } else { ?>
160
- <input type="submit" class="wpuf-submit-button wpuf_submit_<?php echo $form_id; ?>" name="submit" value="<?php echo $form_settings['submit_text']; ?>" />
 
161
  <?php } ?>
162
 
163
  <?php if ( isset( $form_settings['draft_post'] ) && $form_settings['draft_post'] == 'true' ) { ?>
164
- <a href="#" class="btn" id="wpuf-post-draft"><?php _e( 'Save Draft', 'wp-user-frontend' ); ?></a>
165
  <?php } ?>
166
  </li>
167
 
@@ -170,13 +185,14 @@ class WPUF_Frontend_Render_Form{
170
 
171
  /**
172
  * guest post field
173
- * @param [type] $form_settings [description]
 
174
  */
175
  public function guest_fields( $form_settings ) {
176
  ?>
177
  <li class="el-name">
178
  <div class="wpuf-label">
179
- <label><?php echo $form_settings['name_label']; ?> <span class="required">*</span></label>
180
  </div>
181
 
182
  <div class="wpuf-fields">
@@ -186,7 +202,7 @@ class WPUF_Frontend_Render_Form{
186
 
187
  <li class="el-email">
188
  <div class="wpuf-label">
189
- <label><?php echo $form_settings['email_label']; ?> <span class="required">*</span></label>
190
  </div>
191
 
192
  <div class="wpuf-fields">
@@ -201,9 +217,8 @@ class WPUF_Frontend_Render_Form{
201
  *
202
  * @return void
203
  */
204
- function preview_form() {
205
- $form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0;
206
-
207
 
208
  if ( $form_id ) {
209
  ?>
@@ -213,7 +228,7 @@ class WPUF_Frontend_Render_Form{
213
  <head>
214
  <meta charset="UTF-8">
215
  <title>Form Preview</title>
216
- <link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/frontend-forms.css', dirname( __FILE__ ) ); ?>">
217
 
218
  <style type="text/css">
219
  body {
@@ -234,11 +249,11 @@ class WPUF_Frontend_Render_Form{
234
  }
235
  </style>
236
 
237
- <script type="text/javascript" src="<?php echo includes_url( 'js/jquery/jquery.js' ); ?>"></script>
238
  </head>
239
  <body>
240
  <div class="container">
241
- <?php $this->render_form( $form_id, null,null,null); ?>
242
  </div>
243
  </body>
244
  </html>
@@ -253,45 +268,48 @@ class WPUF_Frontend_Render_Form{
253
 
254
  /**
255
  * render form
256
- * @param [type] $form_id [description]
257
- * @param [type] $post_id [description]
258
- * @param array $atts [description]
259
- * @param [type] $form [description]
 
260
  */
261
- function render_form( $form_id, $post_id = NULL, $atts = array(), $form = NULL) {
 
262
 
263
- $form_status = get_post_status( $form_id );
 
264
 
265
- if ( ! $form_status ) {
266
- echo '<div class="wpuf-message">' . __( 'Your selected form is no longer available.', 'wp-user-frontend' ) . '</div>';
267
- return;
268
- }
269
 
270
- if ( $form_status != 'publish' ) {
271
- echo '<div class="wpuf-message">' . __( "Please make sure you've published your form.", 'wp-user-frontend' ) . '</div>';
272
- return;
273
- }
274
 
275
- $label_position = isset( $this->form_settings['label_position'] ) ? $this->form_settings['label_position'] : 'left';
 
276
 
277
- $layout = isset( $this->form_settings['form_layout'] ) ? $this->form_settings['form_layout'] : 'layout1';
278
 
279
- $theme_css = isset( $this->form_settings['use_theme_css'] ) ? $this->form_settings['use_theme_css'] : 'wpuf-style';
280
 
281
- do_action( 'wpuf_before_form_render', $form_id);
282
 
283
- if ( !empty( $layout ) ) {
284
- wp_enqueue_style( 'wpuf-' . $layout );
285
- }
286
 
287
- if ( ! is_user_logged_in() && $this->form_settings['guest_post'] != 'true' ) {
288
- echo '<div class="wpuf-message">' . $this->form_settings['message_restrict'] . '</div>';
289
- return;
290
- }
291
 
292
- if($this->form_fields) { ?>
 
293
 
294
- <form class="wpuf-form-add wpuf-form-<?php echo $layout; ?> <?php echo ($layout == 'layout1') ? $theme_css : 'wpuf-style'; ?>" action="" method="post">
 
 
 
 
 
295
 
296
 
297
  <script type="text/javascript">
@@ -308,7 +326,7 @@ class WPUF_Frontend_Render_Form{
308
  }
309
  </script>
310
 
311
- <ul class="wpuf-form form-label-<?php echo $label_position; ?>">
312
 
313
  <?php
314
 
@@ -324,11 +342,9 @@ class WPUF_Frontend_Render_Form{
324
  $this->guest_fields( $this->form_settings );
325
  }
326
 
 
327
 
328
- wpuf()->fields->render_fields( $this->form_fields, $form_id, $atts , $type = 'post', $post_id );
329
-
330
-
331
- $this->submit_button( $form_id, $this->form_settings,$post_id);
332
 
333
  if ( !$post_id ) {
334
  do_action( 'wpuf_add_post_form_bottom', $form_id, $this->form_settings );
@@ -346,16 +362,15 @@ class WPUF_Frontend_Render_Form{
346
 
347
  } //endif
348
 
349
- do_action( 'wpuf_after_form_render', $form_id );
350
-
351
  }
352
 
353
  /**
354
  * add post field setting on form builder
 
355
  * @param array $field_settings
356
  */
357
  public function add_field_settings( $field_settings ) {
358
-
359
  if ( class_exists( 'WPUF_Field_Contract' ) ) {
360
  require_once WPUF_ROOT . '/includes/fields/class-field-post-title.php';
361
  require_once WPUF_ROOT . '/includes/fields/class-field-post-content.php';
@@ -364,48 +379,41 @@ class WPUF_Frontend_Render_Form{
364
  require_once WPUF_ROOT . '/includes/fields/class-field-post-taxonomy.php';
365
  require_once WPUF_ROOT . '/includes/fields/class-field-featured-image.php';
366
 
367
- $field_settings['post_title'] = new WPUF_Form_Field_Post_Title();
368
- $field_settings['post_content'] = new WPUF_Form_Field_Post_Content();
369
- $field_settings['post_excerpt'] = new WPUF_Form_Field_Post_Excerpt();
370
  $field_settings['featured_image'] = new WPUF_Form_Field_Featured_Image();
371
 
372
- $taxonomy_templates = array();
373
 
374
  foreach ( $this->wp_post_types as $post_type => $taxonomies ) {
375
-
376
- if ( ! empty( $taxonomies ) ) {
377
-
378
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
379
  if ( 'post_tag' === $tax_name ) {
380
  // $taxonomy_templates['post_tag'] = self::post_tags();
381
  $taxonomy_templates['post_tags'] = new WPUF_Form_Field_Post_Tags();
382
-
383
  } else {
384
  // $taxonomy_templates[ $tax_name ] = self::taxonomy_template( $tax_name, $taxonomy );
385
- $taxonomy_templates[ 'taxonomy' ] = new WPUF_Form_Field_Post_Taxonomy($tax_name, $taxonomy);
386
-
387
  }
388
  }
389
-
390
  }
391
-
392
  }
393
 
394
  $field_settings = array_merge( $field_settings, $taxonomy_templates );
395
-
396
  }
397
 
398
  return $field_settings;
399
-
400
  }
401
 
402
-
403
  /**
404
  * Guess a suitable username for registration based on email address
 
405
  * @param string $email email address
 
406
  * @return string username
407
  */
408
- function guess_username( $email ) {
409
  // username from email address
410
  $username = sanitize_user( substr( $email, 0, strpos( $email, '@' ) ) );
411
 
@@ -416,6 +424,7 @@ class WPUF_Frontend_Render_Form{
416
  // try to add some random number in username
417
  // and may be we got our username
418
  $username .= rand( 1, 199 );
 
419
  if ( !username_exists( $username ) ) {
420
  return $username;
421
  }
@@ -427,34 +436,32 @@ class WPUF_Frontend_Render_Form{
427
  * @since 2.5
428
  *
429
  * @return void
430
- */
431
- public function set_wp_post_types( ) {
432
-
433
- $args = array( '_builtin' => true );
434
 
435
  $wpuf_post_types = wpuf_get_post_types( $args );
436
 
437
- $ignore_taxonomies = apply_filters( 'wpuf-ignore-taxonomies', array(
438
- 'post_format'
439
- ) );
440
 
441
  foreach ( $wpuf_post_types as $post_type ) {
442
-
443
- $this->wp_post_types[ $post_type ] = array();
444
 
445
  $taxonomies = get_object_taxonomies( $post_type, 'object' );
446
 
447
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
448
- if ( ! in_array( $tax_name, $ignore_taxonomies ) ) {
449
- $this->wp_post_types[ $post_type ][ $tax_name ] = array(
450
  'title' => $taxonomy->label,
451
- 'hierarchical' => $taxonomy->hierarchical
452
- );
453
 
454
- $this->wp_post_types[ $post_type ][ $tax_name ]['terms'] = get_terms( array(
455
- 'taxonomy' => $tax_name,
456
- 'hide_empty' => false
457
- ) );
458
  }
459
  }
460
  }
@@ -462,22 +469,24 @@ class WPUF_Frontend_Render_Form{
462
 
463
  /**
464
  * get Input fields
465
- * @param array $form_vars
 
 
466
  * @return array
467
  */
468
  public function get_input_fields( $form_vars ) {
469
- $ignore_lists = array('section_break', 'html');
470
- $post_vars = $meta_vars = $taxonomy_vars = array();
471
 
472
- foreach ($form_vars as $key => $value) {
473
  // get column field input fields
474
  if ( $value['input_type'] == 'column_field' ) {
475
  $inner_fields = $value['inner_fields'];
476
 
477
- foreach ($inner_fields as $column_key => $column_fields) {
478
- if (!empty($column_fields)) {
479
  // ignore section break and HTML input type
480
- foreach ($column_fields as $column_field_key => $column_field) {
481
  if ( in_array( $column_field['input_type'], $ignore_lists ) ) {
482
  continue;
483
  }
@@ -529,90 +538,91 @@ class WPUF_Frontend_Render_Form{
529
  }
530
  }
531
 
532
- return array($post_vars, $taxonomy_vars, $meta_vars);
533
  }
534
 
535
  /**
536
  * set custom taxonomy
537
- * @param int $post_id
538
- * @param array $taxonomy_vars
 
539
  */
540
- public function set_custom_taxonomy( $post_id,$taxonomy_vars ) {
541
 
 
542
  // save any custom taxonomies
543
- $woo_attr = array();
544
 
545
- foreach ($taxonomy_vars as $taxonomy ) {
 
 
 
546
 
547
- if(isset($_POST[$taxonomy['name']] ) && ( $_POST[$taxonomy['name']] !='' ) ) {
 
 
548
 
 
549
  if ( is_object_in_taxonomy( $this->form_settings['post_type'], $taxonomy['name'] ) ) {
 
 
 
 
 
550
 
551
- $tax = $_POST[$taxonomy['name']];
552
-
553
- // if it's not an array, make it one
554
- if ( !is_array( $tax ) ) {
555
- $tax = array( $tax );
556
- }
557
-
558
- if ( $taxonomy['type'] == 'text' ) {
559
 
560
- $hierarchical = array_map( 'trim', array_map( 'strip_tags', explode( ',', $_POST[$taxonomy['name']] ) ) );
561
 
562
- wp_set_object_terms( $post_id, $hierarchical, $taxonomy['name'] );
 
 
 
 
 
 
563
 
564
  // woocommerce check
565
- if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
566
- $woo_attr[sanitize_title( $taxonomy['name'] )] = $this->woo_attribute( $taxonomy );
567
  }
568
  } else {
 
 
569
 
570
- if ( is_taxonomy_hierarchical( $taxonomy['name'] ) ) {
571
- wp_set_post_terms( $post_id, $_POST[$taxonomy['name']], $taxonomy['name'] );
572
 
573
- // woocommerce check
574
- if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
575
- $woo_attr[sanitize_title( $taxonomy['name'] )] = $this->woo_attribute( $taxonomy );
576
- }
577
- } else {
578
- if ( $tax ) {
579
- $non_hierarchical = array();
580
-
581
- foreach ( $tax as $value ) {
582
- $term = get_term_by( 'id', $value, $taxonomy['name'] );
583
- if ( $term && !is_wp_error( $term ) ) {
584
- $non_hierarchical[] = $term->name;
585
- }
586
  }
 
587
 
588
- wp_set_post_terms( $post_id, $non_hierarchical, $taxonomy['name'] );
589
-
590
- // woocommerce check
591
- if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
592
- $woo_attr[sanitize_title( $taxonomy['name'] )] = $this->woo_attribute( $taxonomy );
593
- }
594
 
 
 
 
595
  }
596
- } // hierarchical
597
- } // is text
598
- } // is object tax
599
- } // isset tax
 
600
 
601
  else {
602
-
603
- if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'no' && !empty( $_POST[$taxonomy['name']] ) ) {
604
-
605
  if ( is_object_in_taxonomy( $this->form_settings['post_type'], $taxonomy['name'] ) ) {
606
-
607
- foreach ($this->form_settings['default_cat'] as $value) {
608
  $term = get_term( $value );
609
- wp_set_post_terms( $post_id, $value , $term->taxonomy);
610
  }
611
  // wp_set_post_terms( $post_id, $form_settings['default_cat'], $taxonomy['name'] );
612
  }
613
  }
614
  }
615
- }
616
 
617
  // if a woocommerce attribute
618
  if ( $woo_attr ) {
@@ -624,7 +634,9 @@ class WPUF_Frontend_Render_Form{
624
 
625
  /**
626
  * prepare meta fields
627
- * @param array $meta_vars
 
 
628
  * @return array
629
  */
630
  public static function prepare_meta_fields( $meta_vars ) {
@@ -632,12 +644,25 @@ class WPUF_Frontend_Render_Form{
632
  // skip files, put in a key => value paired array for later executation
633
  // process repeatable fields separately
634
  // if the input is array type, implode with separator in a field
 
635
 
636
- $files = array();
637
- $meta_key_value = array();
638
- $multi_repeated = array(); //multi repeated fields will in sotre duplicated meta key
639
 
640
- foreach ($meta_vars as $key => $value) {
 
 
 
 
 
 
 
 
 
 
 
 
641
 
642
  switch ( $value['input_type'] ) {
643
 
@@ -645,11 +670,12 @@ class WPUF_Frontend_Render_Form{
645
  case 'file_upload':
646
  case 'image_upload':
647
 
648
- $files[] = array(
649
  'name' => $value['name'],
650
- 'value' => isset( $_POST['wpuf_files'][$value['name']] ) ? $_POST['wpuf_files'][$value['name']] : array(),
651
- 'count' => $value['count']
652
- );
 
653
  break;
654
 
655
  case 'repeat':
@@ -658,21 +684,20 @@ class WPUF_Frontend_Render_Form{
658
  if ( isset( $value['multiple'] ) && $value['multiple'] == 'true' ) {
659
 
660
  // if there's any items in the array, process it
661
- if ( $_POST[$value['name']] ) {
662
-
663
- $ref_arr = array();
664
  $cols = count( $value['columns'] );
665
- $first = array_shift( array_values( $_POST[$value['name']] ) ); //first element
666
  $rows = count( $first );
667
 
668
  // loop through columns
669
- for ($i = 0; $i < $rows; $i++) {
670
 
671
  // loop through the rows and store in a temp array
672
- $temp = array();
673
- for ($j = 0; $j < $cols; $j++) {
674
 
675
- $temp[] = $_POST[$value['name']][$j][$i];
 
676
  }
677
 
678
  // store all fields in a row with self::$separator separated
@@ -685,15 +710,15 @@ class WPUF_Frontend_Render_Form{
685
  }
686
  }
687
  } else {
688
- $meta_key_value[$value['name']] = implode( self::$separator, $_POST[$value['name']] );
689
  }
690
 
691
  break;
692
 
693
  case 'address':
694
 
695
- if ( isset( $_POST[ $value['name'] ] ) && is_array( $_POST[ $value['name'] ] ) ) {
696
- foreach ( $_POST[ $value['name'] ] as $address_field => $field_value ) {
697
  $meta_key_value[ $value['name'] ][ $address_field ] = sanitize_text_field( $field_value );
698
  }
699
  }
@@ -705,82 +730,86 @@ class WPUF_Frontend_Render_Form{
705
  case 'number':
706
  case 'date':
707
 
708
- $meta_key_value[$value['name']] = sanitize_text_field( trim( $_POST[$value['name']] ) );
709
 
710
  break;
711
 
712
  case 'textarea':
713
 
714
- $meta_key_value[$value['name']] = wp_kses_post( $_POST[$value['name']] );
715
 
716
  break;
717
 
718
  case 'map':
719
- $data = array();
720
- $map_field_data = sanitize_text_field( trim( $_POST[$value['name']] ) );
721
 
722
  if ( !empty( $map_field_data ) ) {
723
- list($data['address'], $data['lat'], $data['lng']) = explode(" || ", $map_field_data);
724
- $meta_key_value[$value['name']] = $data;
725
  }
726
  break;
727
 
728
  default:
729
  // if it's an array, implode with this->separator
730
- if ( !empty( $_POST[ $value['name'] ] ) && is_array( $_POST[$value['name']] ) ) {
731
  $acf_compatibility = wpuf_get_option( 'wpuf_compatibility_acf', 'wpuf_general', 'no' );
732
 
733
  if ( $value['input_type'] == 'address' ) {
734
- $meta_key_value[$value['name']] = $_POST[$value['name']];
735
  } elseif ( !empty( $acf_compatibility ) && $acf_compatibility == 'yes' ) {
736
- $meta_key_value[$value['name']] = $_POST[$value['name']];
737
  } else {
738
- $meta_key_value[$value['name']] = implode( self::$separator, $_POST[$value['name']] );
739
  }
740
- } else if ( !empty( $_POST[ $value['name'] ] ) ) {
741
- $meta_key_value[$value['name']] = trim( $_POST[$value['name']] );
742
  } else {
743
- $meta_key_value[$value['name']] = trim( $_POST[$value['name']] );
744
  }
745
 
746
  break;
747
  }
748
-
749
  } //end foreach
750
- return array($meta_key_value, $multi_repeated, $files);
751
  }
752
 
753
-
754
  /**
755
  * checking recaptcha
756
- * @param [type] $post_vars [description]
 
 
757
  * @return void
758
  */
759
  public function on_edit_no_check_recaptcha( $post_vars ) {
 
 
760
  // search if rs captcha is there
761
  if ( $this->search( $post_vars, 'input_type', 'really_simple_captcha' ) ) {
762
  $this->validate_rs_captcha();
763
  }
764
- $no_captcha = $invisible_captcha = $recaptcha_type = '';
765
  $check_recaptcha = $this->search( $post_vars, 'input_type', 'recaptcha' );
 
766
  if ( !empty( $check_recaptcha ) ) {
767
  $recaptcha_type = $check_recaptcha[0]['recaptcha_type'];
768
  }
769
  // check recaptcha
770
  if ( $check_recaptcha ) {
771
- if ( isset ( $_POST["g-recaptcha-response"] ) ) {
772
- if ( empty( $_POST['g-recaptcha-response'] ) && $check_recaptcha[0]['recaptcha_type'] !== 'invisible_recaptcha') {
773
  $this->send_error( __( 'Empty reCaptcha Field', 'wp-user-frontend' ) );
774
  }
 
775
  if ( $recaptcha_type == 'enable_no_captcha' ) {
776
- $no_captcha = 1;
777
  $invisible_captcha = 0;
778
  } elseif ( $recaptcha_type == 'invisible_recaptcha' ) {
779
  $invisible_captcha = 1;
780
- $no_captcha = 0;
781
  } else {
782
  $invisible_captcha = 0;
783
- $no_captcha = 0;
784
  }
785
  }
786
  $this->validate_re_captcha( $no_captcha, $invisible_captcha );
1
  <?php
2
 
3
+ class WPUF_Frontend_Render_Form {
 
4
  private static $_instance;
5
+
6
+ public static $meta_key = 'wpuf_form';
7
+
8
+ public static $separator = ' | ';
9
+
10
+ public static $config_id = '_wpuf_form_id';
11
+
12
  private $form_condition_key = 'wpuf_cond';
13
+
14
  private $field_count = 0;
15
+
16
  public $multiform_start = 0;
17
 
18
+ public $wp_post_types = [];
19
+
20
+ public $form_fields = [];
21
+
22
+ public $form_settings = [];
23
 
24
  /**
25
  * Send json error message
26
  *
27
  * @param string $error
28
  */
29
+ public function send_error( $error ) {
30
+ echo json_encode( [
31
  'success' => false,
32
+ 'error' => $error,
33
+ ] );
34
 
35
  die();
36
  }
38
  /**
39
  * Search on multi dimentional array
40
  *
41
+ * @param array $array
42
+ * @param string $key name of key
43
  * @param string $value the value to search
44
+ *
45
  * @return array
46
+ */
47
+ public function search( $array, $key, $value ) {
48
+ $results = [];
49
 
50
  if ( is_array( $array ) ) {
51
+ if ( isset( $array[$key] ) && $array[$key] == $value ) {
52
  $results[] = $array;
53
+ }
54
 
55
+ foreach ( $array as $subarray ) {
56
  $results = array_merge( $results, $this->search( $subarray, $key, $value ) );
57
+ }
58
  }
59
 
60
  return $results;
64
  * Really simple captcha validation
65
  *
66
  * @return void
67
+ */
68
+ public function validate_rs_captcha() {
69
+ $nonce = isset( $_REQUEST['wpuf-login-nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['wpuf-login-nonce'] ) ) : '';
70
+
71
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'wpuf_login_action' ) ) {
72
+ return ;
73
+ }
74
+
75
+ $rs_captcha_input = isset( $_POST['rs_captcha'] ) ? sanitize_text_field( wp_unslash( $_POST['rs_captcha'] ) ) : '';
76
+ $rs_captcha_file = isset( $_POST['rs_captcha_val'] ) ? sanitize_text_field( wp_unslash( $_POST['rs_captcha_val'] ) ) : '';
77
 
78
  if ( class_exists( 'ReallySimpleCaptcha' ) ) {
79
  $captcha_instance = new ReallySimpleCaptcha();
80
 
81
  if ( !$captcha_instance->check( $rs_captcha_file, $rs_captcha_input ) ) {
 
82
  $this->send_error( __( 'Really Simple Captcha validation failed', 'wp-user-frontend' ) );
83
  } else {
84
  // validation success, remove the files
92
  *
93
  * @return void
94
  */
95
+ public function validate_re_captcha( $no_captcha = '', $invisible = '' ) {
96
  // need to check if invisible reCaptcha need library or we can do it here.
97
  // ref: https://shareurcodes.com/blog/google%20invisible%20recaptcha%20integration%20with%20php
98
+ check_ajax_referer( 'wpuf_form_add' );
99
+
100
+ $site_key = wpuf_get_option( 'recaptcha_public', 'wpuf_general' );
101
+ $private_key = wpuf_get_option( 'recaptcha_private', 'wpuf_general' );
102
+ $remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
103
+ $g_recaptcha_response = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : '';
104
 
105
+ if ( $no_captcha == 1 && 0 == $invisible ) {
106
  if ( !class_exists( 'WPUF_ReCaptcha' ) ) {
107
  require_once WPUF_ROOT . '/lib/recaptchalib_noCaptcha.php';
108
  }
109
 
110
+ $response = null;
111
+ $reCaptcha = new WPUF_ReCaptcha( $private_key );
112
 
113
  $resp = $reCaptcha->verifyResponse(
114
+ $remote_addr,
115
+ $g_recaptcha_response
116
+ );
117
 
118
  if ( !$resp->success ) {
119
  $this->send_error( __( 'noCaptcha reCAPTCHA validation failed', 'wp-user-frontend' ) );
120
  }
 
121
  } elseif ( $no_captcha == 0 && 0 == $invisible ) {
122
+ $recap_challenge = isset( $_POST['recaptcha_challenge_field'] ) ? sanitize_text_field( wp_unslash( $_POST['recaptcha_challenge_field'] ) ): '';
123
+ $recap_response = isset( $_POST['recaptcha_response_field'] ) ? sanitize_text_field( wp_unslash( $_POST['recaptcha_response_field'] ) ) : '';
124
 
125
+ $resp = recaptcha_check_answer( $private_key, $remote_addr, $recap_challenge, $recap_response );
 
 
 
126
 
127
  if ( !$resp->is_valid ) {
128
  $this->send_error( __( 'reCAPTCHA validation failed', 'wp-user-frontend' ) );
129
  }
 
130
  } elseif ( $no_captcha == 0 && 1 == $invisible ) {
 
131
  $response = null;
132
+ $recaptcha = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : '';
133
+ $object = new Invisible_Recaptcha( $site_key, $private_key );
134
 
135
  $response = $object->verifyResponse( $recaptcha );
136
 
137
+ if ( isset( $response['success'] ) and $response['success'] != true ) {
138
  $this->send_error( __( 'Invisible reCAPTCHA validation failed', 'wp-user-frontend' ) );
139
  }
140
  }
 
141
  }
142
 
143
  /**
144
  * render submit button
145
+ *
146
+ * @param [type] $form_id [description]
147
+ * @param [type] $form_settings [description]
148
+ * @param [type] $post_id [description]
149
  */
150
  public function submit_button( $form_id, $form_settings, $post_id = null ) { ?>
151
 
155
  </div>
156
 
157
  <?php wp_nonce_field( 'wpuf_form_add' ); ?>
158
+ <input type="hidden" name="form_id" value="<?php echo esc_attr( $form_id ); ?>">
159
+ <input type="hidden" name="page_id" value="<?php echo get_post( $post_id ) ? esc_attr( get_the_ID() ) : '0'; ?>">
160
  <input type="hidden" id="del_attach" name="delete_attachments[]">
161
  <input type="hidden" name="action" value="wpuf_submit_post">
162
 
164
 
165
  <?php
166
  if ( $post_id ) {
167
+ $cur_post = get_post( $post_id ); ?>
168
+ <input type="hidden" name="post_id" value="<?php echo esc_attr( $post_id ); ?>">
 
169
  <input type="hidden" name="post_date" value="<?php echo esc_attr( $cur_post->post_date ); ?>">
170
  <input type="hidden" name="comment_status" value="<?php echo esc_attr( $cur_post->comment_status ); ?>">
171
  <input type="hidden" name="post_author" value="<?php echo esc_attr( $cur_post->post_author ); ?>">
172
+ <input type="submit" class="wpuf-submit-button wpuf_submit_<?php echo esc_attr( $form_id ); ?>" name="submit" value="<?php echo esc_attr( $form_settings['update_text'] ); ?>" />
173
+ <?php
174
+ } else { ?>
175
+ <input type="submit" class="wpuf-submit-button wpuf_submit_<?php echo esc_attr( $form_id ); ?>" name="submit" value="<?php echo esc_attr( $form_settings['submit_text'] ); ?>" />
176
  <?php } ?>
177
 
178
  <?php if ( isset( $form_settings['draft_post'] ) && $form_settings['draft_post'] == 'true' ) { ?>
179
+ <a href="#" class="btn" id="wpuf-post-draft"><?php esc_html_e( 'Save Draft', 'wp-user-frontend' ); ?></a>
180
  <?php } ?>
181
  </li>
182
 
185
 
186
  /**
187
  * guest post field
188
+ *
189
+ * @param [type] $form_settings [description]
190
  */
191
  public function guest_fields( $form_settings ) {
192
  ?>
193
  <li class="el-name">
194
  <div class="wpuf-label">
195
+ <label><?php echo esc_html( $form_settings['name_label'] ); ?> <span class="required">*</span></label>
196
  </div>
197
 
198
  <div class="wpuf-fields">
202
 
203
  <li class="el-email">
204
  <div class="wpuf-label">
205
+ <label><?php echo esc_html( $form_settings['email_label'] ); ?> <span class="required">*</span></label>
206
  </div>
207
 
208
  <div class="wpuf-fields">
217
  *
218
  * @return void
219
  */
220
+ public function preview_form() {
221
+ $form_id = isset( $_GET['form_id'] ) ? intval( wp_unslash( $_GET['form_id'] ) ) : 0;
 
222
 
223
  if ( $form_id ) {
224
  ?>
228
  <head>
229
  <meta charset="UTF-8">
230
  <title>Form Preview</title>
231
+ <link rel="stylesheet" href="<?php echo esc_attr( plugins_url( 'assets/css/frontend-forms.css', __DIR__ ) ); ?>">
232
 
233
  <style type="text/css">
234
  body {
249
  }
250
  </style>
251
 
252
+ <script type="text/javascript" src="<?php echo esc_url( includes_url( 'js/jquery/jquery.js' ) ); ?>"></script>
253
  </head>
254
  <body>
255
  <div class="container">
256
+ <?php $this->render_form( $form_id, null, null, null ); ?>
257
  </div>
258
  </body>
259
  </html>
268
 
269
  /**
270
  * render form
271
+ *
272
+ * @param [type] $form_id [description]
273
+ * @param [type] $post_id [description]
274
+ * @param array $atts [description]
275
+ * @param [type] $form [description]
276
  */
277
+ public function render_form( $form_id, $post_id = null, $atts = [], $form = null ) {
278
+ $form_status = get_post_status( $form_id );
279
 
280
+ if ( !$form_status ) {
281
+ echo wp_kses_post( '<div class="wpuf-message">' . __( 'Your selected form is no longer available.', 'wp-user-frontend' ) . '</div>' );
282
 
283
+ return;
284
+ }
 
 
285
 
286
+ if ( $form_status != 'publish' ) {
287
+ echo wp_kses_post( '<div class="wpuf-message">' . __( "Please make sure you've published your form.", 'wp-user-frontend' ) . '</div>' );
 
 
288
 
289
+ return;
290
+ }
291
 
292
+ $label_position = isset( $this->form_settings['label_position'] ) ? $this->form_settings['label_position'] : 'left';
293
 
294
+ $layout = isset( $this->form_settings['form_layout'] ) ? $this->form_settings['form_layout'] : 'layout1';
295
 
296
+ $theme_css = isset( $this->form_settings['use_theme_css'] ) ? $this->form_settings['use_theme_css'] : 'wpuf-style';
297
 
298
+ do_action( 'wpuf_before_form_render', $form_id );
 
 
299
 
300
+ if ( !empty( $layout ) ) {
301
+ wp_enqueue_style( 'wpuf-' . $layout );
302
+ }
 
303
 
304
+ if ( !is_user_logged_in() && $this->form_settings['guest_post'] != 'true' ) {
305
+ echo wp_kses_post( '<div class="wpuf-message">' . $this->form_settings['message_restrict'] . '</div>' );
306
 
307
+ return;
308
+ }
309
+
310
+ if ( $this->form_fields ) { ?>
311
+
312
+ <form class="wpuf-form-add wpuf-form-<?php echo esc_attr( $layout ); ?> <?php echo ( $layout == 'layout1' ) ? esc_html( $theme_css ) : 'wpuf-style'; ?>" action="" method="post">
313
 
314
 
315
  <script type="text/javascript">
326
  }
327
  </script>
328
 
329
+ <ul class="wpuf-form form-label-<?php echo esc_attr( $label_position ); ?>">
330
 
331
  <?php
332
 
342
  $this->guest_fields( $this->form_settings );
343
  }
344
 
345
+ wpuf()->fields->render_fields( $this->form_fields, $form_id, $atts, $type = 'post', $post_id );
346
 
347
+ $this->submit_button( $form_id, $this->form_settings, $post_id );
 
 
 
348
 
349
  if ( !$post_id ) {
350
  do_action( 'wpuf_add_post_form_bottom', $form_id, $this->form_settings );
362
 
363
  } //endif
364
 
365
+ do_action( 'wpuf_after_form_render', $form_id );
 
366
  }
367
 
368
  /**
369
  * add post field setting on form builder
370
+ *
371
  * @param array $field_settings
372
  */
373
  public function add_field_settings( $field_settings ) {
 
374
  if ( class_exists( 'WPUF_Field_Contract' ) ) {
375
  require_once WPUF_ROOT . '/includes/fields/class-field-post-title.php';
376
  require_once WPUF_ROOT . '/includes/fields/class-field-post-content.php';
379
  require_once WPUF_ROOT . '/includes/fields/class-field-post-taxonomy.php';
380
  require_once WPUF_ROOT . '/includes/fields/class-field-featured-image.php';
381
 
382
+ $field_settings['post_title'] = new WPUF_Form_Field_Post_Title();
383
+ $field_settings['post_content'] = new WPUF_Form_Field_Post_Content();
384
+ $field_settings['post_excerpt'] = new WPUF_Form_Field_Post_Excerpt();
385
  $field_settings['featured_image'] = new WPUF_Form_Field_Featured_Image();
386
 
387
+ $taxonomy_templates = [];
388
 
389
  foreach ( $this->wp_post_types as $post_type => $taxonomies ) {
390
+ if ( !empty( $taxonomies ) ) {
 
 
391
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
392
  if ( 'post_tag' === $tax_name ) {
393
  // $taxonomy_templates['post_tag'] = self::post_tags();
394
  $taxonomy_templates['post_tags'] = new WPUF_Form_Field_Post_Tags();
 
395
  } else {
396
  // $taxonomy_templates[ $tax_name ] = self::taxonomy_template( $tax_name, $taxonomy );
397
+ $taxonomy_templates[ 'taxonomy' ] = new WPUF_Form_Field_Post_Taxonomy( $tax_name, $taxonomy );
 
398
  }
399
  }
 
400
  }
 
401
  }
402
 
403
  $field_settings = array_merge( $field_settings, $taxonomy_templates );
 
404
  }
405
 
406
  return $field_settings;
 
407
  }
408
 
 
409
  /**
410
  * Guess a suitable username for registration based on email address
411
+ *
412
  * @param string $email email address
413
+ *
414
  * @return string username
415
  */
416
+ public function guess_username( $email ) {
417
  // username from email address
418
  $username = sanitize_user( substr( $email, 0, strpos( $email, '@' ) ) );
419
 
424
  // try to add some random number in username
425
  // and may be we got our username
426
  $username .= rand( 1, 199 );
427
+
428
  if ( !username_exists( $username ) ) {
429
  return $username;
430
  }
436
  * @since 2.5
437
  *
438
  * @return void
439
+ */
440
+ public function set_wp_post_types() {
441
+ $args = [ '_builtin' => true ];
 
442
 
443
  $wpuf_post_types = wpuf_get_post_types( $args );
444
 
445
+ $ignore_taxonomies = apply_filters( 'wpuf-ignore-taxonomies', [
446
+ 'post_format',
447
+ ] );
448
 
449
  foreach ( $wpuf_post_types as $post_type ) {
450
+ $this->wp_post_types[ $post_type ] = [];
 
451
 
452
  $taxonomies = get_object_taxonomies( $post_type, 'object' );
453
 
454
  foreach ( $taxonomies as $tax_name => $taxonomy ) {
455
+ if ( !in_array( $tax_name, $ignore_taxonomies ) ) {
456
+ $this->wp_post_types[ $post_type ][ $tax_name ] = [
457
  'title' => $taxonomy->label,
458
+ 'hierarchical' => $taxonomy->hierarchical,
459
+ ];
460
 
461
+ $this->wp_post_types[ $post_type ][ $tax_name ]['terms'] = get_terms( [
462
+ 'taxonomy' => $tax_name,
463
+ 'hide_empty' => false,
464
+ ] );
465
  }
466
  }
467
  }
469
 
470
  /**
471
  * get Input fields
472
+ *
473
+ * @param array $form_vars
474
+ *
475
  * @return array
476
  */
477
  public function get_input_fields( $form_vars ) {
478
+ $ignore_lists = ['section_break', 'html'];
479
+ $post_vars = $meta_vars = $taxonomy_vars = [];
480
 
481
+ foreach ( $form_vars as $key => $value ) {
482
  // get column field input fields
483
  if ( $value['input_type'] == 'column_field' ) {
484
  $inner_fields = $value['inner_fields'];
485
 
486
+ foreach ( $inner_fields as $column_key => $column_fields ) {
487
+ if ( !empty( $column_fields ) ) {
488
  // ignore section break and HTML input type
489
+ foreach ( $column_fields as $column_field_key => $column_field ) {
490
  if ( in_array( $column_field['input_type'], $ignore_lists ) ) {
491
  continue;
492
  }
538
  }
539
  }
540
 
541
+ return [$post_vars, $taxonomy_vars, $meta_vars];
542
  }
543
 
544
  /**
545
  * set custom taxonomy
546
+ *
547
+ * @param int $post_id
548
+ * @param array $taxonomy_vars
549
  */
550
+ public function set_custom_taxonomy( $post_id, $taxonomy_vars ) {
551
 
552
+ check_ajax_referer( 'wpuf_form_add' );
553
  // save any custom taxonomies
554
+ $woo_attr = [];
555
 
556
+ foreach ( $taxonomy_vars as $taxonomy ) {
557
+ if ( isset( $_POST[$taxonomy['name']] ) && is_array( $_POST[$taxonomy['name']] ) ) {
558
+ $taxonomy_name = array_map( 'sanitize_text_field', wp_unslash( $_POST[$taxonomy['name']] ) );
559
+ }
560
 
561
+ if ( isset( $_POST[$taxonomy['name']] ) && !is_array( $_POST[$taxonomy['name']] ) ) {
562
+ $taxonomy_name = sanitize_text_field( wp_unslash( $_POST[$taxonomy['name']] ) );
563
+ }
564
 
565
+ if ( $taxonomy_name != '' ) {
566
  if ( is_object_in_taxonomy( $this->form_settings['post_type'], $taxonomy['name'] ) ) {
567
+ $tax = $taxonomy_name;
568
+ // if it's not an array, make it one
569
+ if ( !is_array( $tax ) ) {
570
+ $tax = [ $tax ];
571
+ }
572
 
573
+ if ( $taxonomy['type'] == 'text' ) {
574
+ $hierarchical = array_map( 'trim', array_map( 'strip_tags', explode( ',', $taxonomy_name ) ) );
 
 
 
 
 
 
575
 
576
+ wp_set_object_terms( $post_id, $hierarchical, $taxonomy['name'] );
577
 
578
+ // woocommerce check
579
+ if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $taxonomy_name ) ) {
580
+ $woo_attr[$taxonomy['name']] = $this->woo_attribute( $taxonomy );
581
+ }
582
+ } else {
583
+ if ( is_taxonomy_hierarchical( $taxonomy['name'] ) ) {
584
+ wp_set_post_terms( $post_id, $taxonomy_name, $taxonomy['name'] );
585
 
586
  // woocommerce check
587
+ if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $taxonomy_name ) ) {
588
+ $woo_attr[$taxonomy['name']] = $this->woo_attribute( $taxonomy );
589
  }
590
  } else {
591
+ if ( $tax ) {
592
+ $non_hierarchical = [];
593
 
594
+ foreach ( $tax as $value ) {
595
+ $term = get_term_by( 'id', $value, $taxonomy['name'] );
596
 
597
+ if ( $term && !is_wp_error( $term ) ) {
598
+ $non_hierarchical[] = $term->name;
 
 
 
 
 
 
 
 
 
 
 
599
  }
600
+ }
601
 
602
+ wp_set_post_terms( $post_id, $non_hierarchical, $taxonomy['name'] );
 
 
 
 
 
603
 
604
+ // woocommerce check
605
+ if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
606
+ $woo_attr[$taxonomy['name']] = $this->woo_attribute( $taxonomy );
607
  }
608
+ }
609
+ } // hierarchical
610
+ } // is text
611
+ } // is object tax
612
+ } // isset tax
613
 
614
  else {
615
+ if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'no' && !empty( $taxonomy_name ) ) {
 
 
616
  if ( is_object_in_taxonomy( $this->form_settings['post_type'], $taxonomy['name'] ) ) {
617
+ foreach ( $this->form_settings['default_cat'] as $value ) {
 
618
  $term = get_term( $value );
619
+ wp_set_post_terms( $post_id, $value, $term->taxonomy );
620
  }
621
  // wp_set_post_terms( $post_id, $form_settings['default_cat'], $taxonomy['name'] );
622
  }
623
  }
624
  }
625
+ }
626
 
627
  // if a woocommerce attribute
628
  if ( $woo_attr ) {
634
 
635
  /**
636
  * prepare meta fields
637
+ *
638
+ * @param array $meta_vars
639
+ *
640
  * @return array
641
  */
642
  public static function prepare_meta_fields( $meta_vars ) {
644
  // skip files, put in a key => value paired array for later executation
645
  // process repeatable fields separately
646
  // if the input is array type, implode with separator in a field
647
+ check_ajax_referer( 'wpuf_form_add' );
648
 
649
+ $files = [];
650
+ $meta_key_value = [];
651
+ $multi_repeated = []; //multi repeated fields will in sotre duplicated meta key
652
 
653
+ foreach ( $meta_vars as $key => $value ) {
654
+ // $wpuf_files = isset( $_POST['wpuf_files'] ) ? wp_unslash( $_POST['wpuf_files'] ) : [];
655
+ if( isset( $_POST[$value['name']] ) && is_array( $_POST[$value['name']] ) ) {
656
+ $value_name = isset( $_POST[$value['name']] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST[$value['name']] ) ): '';
657
+ } else {
658
+ $value_name = isset( $_POST[$value['name']] ) ? sanitize_text_field( wp_unslash( $_POST[$value['name']] ) ): '';
659
+ }
660
+
661
+ if ( isset( $_POST['wpuf_files'][$value['name']] ) ) {
662
+ $wpuf_files = isset( $_POST['wpuf_files'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['wpuf_files'][$value['name']] ) ) : [];
663
+ } else {
664
+ $wpuf_files = [];
665
+ }
666
 
667
  switch ( $value['input_type'] ) {
668
 
670
  case 'file_upload':
671
  case 'image_upload':
672
 
673
+ $files[] = [
674
  'name' => $value['name'],
675
+ // 'value' => $wpuf_files[$value['name']],
676
+ 'value' => isset( $wpuf_files ) ? $wpuf_files : [],
677
+ 'count' => $value['count'],
678
+ ];
679
  break;
680
 
681
  case 'repeat':
684
  if ( isset( $value['multiple'] ) && $value['multiple'] == 'true' ) {
685
 
686
  // if there's any items in the array, process it
687
+ if ( $value_name ) {
688
+ $ref_arr = [];
 
689
  $cols = count( $value['columns'] );
690
+ $first = array_shift( array_values( $value_name ) ); //first element
691
  $rows = count( $first );
692
 
693
  // loop through columns
694
+ for ( $i = 0; $i < $rows; $i++ ) {
695
 
696
  // loop through the rows and store in a temp array
697
+ $temp = [];
 
698
 
699
+ for ( $j = 0; $j < $cols; $j++ ) {
700
+ $temp[] = $value_name[$j][$i];
701
  }
702
 
703
  // store all fields in a row with self::$separator separated
710
  }
711
  }
712
  } else {
713
+ $meta_key_value[$value['name']] = implode( self::$separator, $value_name );
714
  }
715
 
716
  break;
717
 
718
  case 'address':
719
 
720
+ if ( is_array( $value_name ) ) {
721
+ foreach ( $value_name as $address_field => $field_value ) {
722
  $meta_key_value[ $value['name'] ][ $address_field ] = sanitize_text_field( $field_value );
723
  }
724
  }
730
  case 'number':
731
  case 'date':
732
 
733
+ $meta_key_value[$value['name']] = $value_name;
734
 
735
  break;
736
 
737
  case 'textarea':
738
 
739
+ $meta_key_value[$value['name']] = wp_kses_post( $value_name );
740
 
741
  break;
742
 
743
  case 'map':
744
+ $data = [];
745
+ $map_field_data = $value_name;
746
 
747
  if ( !empty( $map_field_data ) ) {
748
+ list( $data['address'], $data['lat'], $data['lng'] ) = explode( ' || ', $map_field_data );
749
+ $meta_key_value[$value['name']] = $data;
750
  }
751
  break;
752
 
753
  default:
754
  // if it's an array, implode with this->separator
755
+ if ( !empty( $value_name ) && is_array( $value_name ) ) {
756
  $acf_compatibility = wpuf_get_option( 'wpuf_compatibility_acf', 'wpuf_general', 'no' );
757
 
758
  if ( $value['input_type'] == 'address' ) {
759
+ $meta_key_value[$value['name']] = $value_name;
760
  } elseif ( !empty( $acf_compatibility ) && $acf_compatibility == 'yes' ) {
761
+ $meta_key_value[$value['name']] = $value_name;
762
  } else {
763
+ $meta_key_value[$value['name']] = implode( self::$separator, $value_name );
764
  }
765
+ } elseif ( !empty( $value_name ) ) {
766
+ $meta_key_value[$value['name']] = trim( $value_name );
767
  } else {
768
+ $meta_key_value[$value['name']] = trim( $value_name );
769
  }
770
 
771
  break;
772
  }
 
773
  } //end foreach
774
+ return [$meta_key_value, $multi_repeated, $files];
775
  }
776
 
 
777
  /**
778
  * checking recaptcha
779
+ *
780
+ * @param [type] $post_vars [description]
781
+ *
782
  * @return void
783
  */
784
  public function on_edit_no_check_recaptcha( $post_vars ) {
785
+
786
+ check_ajax_referer( 'wpuf_form_add' );
787
  // search if rs captcha is there
788
  if ( $this->search( $post_vars, 'input_type', 'really_simple_captcha' ) ) {
789
  $this->validate_rs_captcha();
790
  }
791
+ $no_captcha = $invisible_captcha = $recaptcha_type = '';
792
  $check_recaptcha = $this->search( $post_vars, 'input_type', 'recaptcha' );
793
+
794
  if ( !empty( $check_recaptcha ) ) {
795
  $recaptcha_type = $check_recaptcha[0]['recaptcha_type'];
796
  }
797
  // check recaptcha
798
  if ( $check_recaptcha ) {
799
+ if ( isset( $_POST['g-recaptcha-response'] ) ) {
800
+ if ( empty( $_POST['g-recaptcha-response'] ) && $check_recaptcha[0]['recaptcha_type'] !== 'invisible_recaptcha' ) {
801
  $this->send_error( __( 'Empty reCaptcha Field', 'wp-user-frontend' ) );
802
  }
803
+
804
  if ( $recaptcha_type == 'enable_no_captcha' ) {
805
+ $no_captcha = 1;
806
  $invisible_captcha = 0;
807
  } elseif ( $recaptcha_type == 'invisible_recaptcha' ) {
808
  $invisible_captcha = 1;
809
+ $no_captcha = 0;
810
  } else {
811
  $invisible_captcha = 0;
812
+ $no_captcha = 0;
813
  }
814
  }
815
  $this->validate_re_captcha( $no_captcha, $invisible_captcha );
includes/class-gutenblock.php CHANGED
@@ -1,4 +1,6 @@
1
- <?php if ( ! defined( 'ABSPATH' ) ) exit;
 
 
2
  /**
3
  * Adds WPUF block
4
  */
@@ -9,66 +11,66 @@ class WPUF_Form_Block {
9
  public function __construct() {
10
  //Enqueue the Dashicons script as they are not loading
11
  //when wpuf_form shortcode exists in admin pages.
12
- add_action( 'admin_enqueue_scripts', array( $this, 'load_dashicons' ) );
13
  // wait for Gutenberg to enqueue it's block assets
14
- add_action( 'enqueue_block_editor_assets', array( $this, 'wpuf_form_block' ), 10 );
15
  // load the preview information and form
16
- add_action( 'wp_head', array( $this, 'load_preview_data' ) );
17
  }
18
 
19
- function load_dashicons() {
20
- // load dashicons & editor style as they are not loading when wpuf_form shortcode exists in admin pages.
21
- wp_register_style( 'wpuf_dashicons', includes_url() . 'css/dashicons.css', false, '1.0.0' );
22
- wp_enqueue_style( 'wpuf_dashicons' );
23
  }
24
 
25
- function wpuf_form_block() {
26
  $js_dir = WPUF_ASSET_URI . '/js/admin/';
27
  $css_dir = WPUF_ASSET_URI . '/css/admin/';
28
 
29
  // Once we have Gutenberg block javascript, we can enqueue our assets
30
- wp_register_script(
31
  'wpuf-forms-block',
32
  $js_dir . 'gutenblock.js',
33
- array( 'wp-blocks', 'wp-editor', 'wp-components', 'wp-i18n', 'wp-element', 'underscore' )
34
- );
35
 
36
- wp_register_style(
37
  'wpuf-forms-block-style',
38
  $css_dir . 'gutenblock.css',
39
- array( 'wp-edit-blocks' )
40
- );
41
- wp_register_style(
42
  'wpuf-forms-block-editor',
43
  $css_dir . 'gutenblock-editor.css',
44
- array( 'wp-edit-blocks', 'wpuf-forms-block-style' )
45
- );
46
 
47
- /**
48
  * we need to get our forms so that the block can build a dropdown
49
  * with the forms
50
  * */
51
  wp_enqueue_script( 'wpuf-forms-block' );
52
 
53
- $forms = array();
54
- $all_forms = wpuf()->forms->get_forms( array( 'post_status' => 'publish' ) );
55
 
56
- foreach( $all_forms['forms'] as $form ){
57
- $forms[] = array (
58
  'value' => $form->id,
59
  'label' => $form->get_title(),
60
- );
61
  }
62
 
63
  $block_logo = WPUF_ASSET_URI . '/images/icon-128x128.png';
64
  $thumbnail_logo = WPUF_ASSET_URI . '/images/icon-128x128.png';
65
 
66
- wp_localize_script( 'wpuf-forms-block', 'wpufBlock', array(
67
  'forms' => $forms,
68
  'siteUrl' => get_home_url(),
69
  'block_logo' => $block_logo,
70
- 'thumbnail_logo' => $thumbnail_logo
71
- ) );
72
  wp_enqueue_style( 'wpuf-forms-block-style' );
73
  wp_enqueue_style( 'wpuf-forms-block-editor' );
74
  }
@@ -77,10 +79,9 @@ class WPUF_Form_Block {
77
  $js_dir = WPUF_ASSET_URI . '/js/admin/';
78
 
79
  // check for preview and iframe get parameters
80
- if( isset( $_GET[ 'wpuf_preview' ] ) && isset( $_GET[ 'wpuf_iframe' ] ) ){
81
  $form_id = intval( $_GET[ 'wpuf_preview' ] );
82
- // Style below: update width and height for particular form
83
- ?>
84
  <style media="screen">
85
  #wpadminbar {
86
  display: none;
@@ -105,17 +106,17 @@ class WPUF_Form_Block {
105
  <?php
106
 
107
  // register our script to target the form iFrame in page builder
108
- wp_register_script(
109
  'wpuf-block-setup',
110
  $js_dir . 'blockFrameSetup.js',
111
- array( 'underscore', 'jquery' )
112
- );
113
 
114
- wp_localize_script( 'wpuf-block-setup', 'wpufBlockSetup', array(
115
- 'form_id' => $form_id
116
- ) );
117
 
118
  wp_enqueue_script( 'wpuf-block-setup' );
119
  }
120
  }
121
- }
1
+ <?php if ( !defined( 'ABSPATH' ) ) {
2
+ exit;
3
+ }
4
  /**
5
  * Adds WPUF block
6
  */
11
  public function __construct() {
12
  //Enqueue the Dashicons script as they are not loading
13
  //when wpuf_form shortcode exists in admin pages.
14
+ add_action( 'admin_enqueue_scripts', [ $this, 'load_dashicons' ] );
15
  // wait for Gutenberg to enqueue it's block assets
16
+ add_action( 'enqueue_block_editor_assets', [ $this, 'wpuf_form_block' ], 10 );
17
  // load the preview information and form
18
+ add_action( 'wp_head', [ $this, 'load_preview_data' ] );
19
  }
20
 
21
+ public function load_dashicons() {
22
+ // load dashicons & editor style as they are not loading when wpuf_form shortcode exists in admin pages.
23
+ wp_register_style( 'wpuf_dashicons', includes_url() . 'css/dashicons.css', false, '1.0.0' );
24
+ wp_enqueue_style( 'wpuf_dashicons' );
25
  }
26
 
27
+ public function wpuf_form_block() {
28
  $js_dir = WPUF_ASSET_URI . '/js/admin/';
29
  $css_dir = WPUF_ASSET_URI . '/css/admin/';
30
 
31
  // Once we have Gutenberg block javascript, we can enqueue our assets
32
+ wp_register_script(
33
  'wpuf-forms-block',
34
  $js_dir . 'gutenblock.js',
35
+ [ 'wp-blocks', 'wp-editor', 'wp-components', 'wp-i18n', 'wp-element', 'underscore' ]
36
+ );
37
 
38
+ wp_register_style(
39
  'wpuf-forms-block-style',
40
  $css_dir . 'gutenblock.css',
41
+ [ 'wp-edit-blocks' ]
42
+ );
43
+ wp_register_style(
44
  'wpuf-forms-block-editor',
45
  $css_dir . 'gutenblock-editor.css',
46
+ [ 'wp-edit-blocks', 'wpuf-forms-block-style' ]
47
+ );
48
 
49
+ /*
50
  * we need to get our forms so that the block can build a dropdown
51
  * with the forms
52
  * */
53
  wp_enqueue_script( 'wpuf-forms-block' );
54
 
55
+ $forms = [];
56
+ $all_forms = wpuf()->forms->get_forms( [ 'post_status' => 'publish' ] );
57
 
58
+ foreach ( $all_forms['forms'] as $form ) {
59
+ $forms[] = [
60
  'value' => $form->id,
61
  'label' => $form->get_title(),
62
+ ];
63
  }
64
 
65
  $block_logo = WPUF_ASSET_URI . '/images/icon-128x128.png';
66
  $thumbnail_logo = WPUF_ASSET_URI . '/images/icon-128x128.png';
67
 
68
+ wp_localize_script( 'wpuf-forms-block', 'wpufBlock', [
69
  'forms' => $forms,
70
  'siteUrl' => get_home_url(),
71
  'block_logo' => $block_logo,
72
+ 'thumbnail_logo' => $thumbnail_logo,
73
+ ] );
74
  wp_enqueue_style( 'wpuf-forms-block-style' );
75
  wp_enqueue_style( 'wpuf-forms-block-editor' );
76
  }
79
  $js_dir = WPUF_ASSET_URI . '/js/admin/';
80
 
81
  // check for preview and iframe get parameters
82
+ if ( isset( $_GET[ 'wpuf_preview' ] ) && isset( $_GET[ 'wpuf_iframe' ] ) ) {
83
  $form_id = intval( $_GET[ 'wpuf_preview' ] );
84
+ // Style below: update width and height for particular form ?>
 
85
  <style media="screen">
86
  #wpadminbar {
87
  display: none;
106
  <?php
107
 
108
  // register our script to target the form iFrame in page builder
109
+ wp_register_script(
110
  'wpuf-block-setup',
111
  $js_dir . 'blockFrameSetup.js',
112
+ [ 'underscore', 'jquery' ]
113
+ );
114
 
115
+ wp_localize_script( 'wpuf-block-setup', 'wpufBlockSetup', [
116
+ 'form_id' => $form_id,
117
+ ] );
118
 
119
  wp_enqueue_script( 'wpuf-block-setup' );
120
  }
121
  }
122
+ }
includes/class-installer.php CHANGED
@@ -13,13 +13,12 @@ class WPUF_Installer {
13
  * @return void
14
  */
15
  public function install() {
16
-
17
  $this->create_tables();
18
  $this->schedule_events();
19
 
20
  $installed = get_option( 'wpuf_installed' );
21
 
22
- if ( ! $installed ) {
23
  update_option( 'wpuf_installed', time() );
24
  }
25
 
@@ -40,16 +39,16 @@ class WPUF_Installer {
40
  $collate = '';
41
 
42
  if ( $wpdb->has_cap( 'collation' ) ) {
43
- if ( ! empty($wpdb->charset ) ) {
44
  $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
45
  }
46
 
47
- if ( ! empty($wpdb->collate ) ) {
48
  $collate .= " COLLATE $wpdb->collate";
49
  }
50
  }
51
 
52
- $table_schema = array(
53
  "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}wpuf_transaction` (
54
  `id` int(11) NOT NULL AUTO_INCREMENT,
55
  `user_id` bigint(20) DEFAULT NULL,
@@ -86,9 +85,10 @@ class WPUF_Installer {
86
  PRIMARY KEY (`id`),
87
  key `user_id` (`user_id`)
88
  ) $collate;",
89
- );
90
 
91
  require_once ABSPATH . 'wp-admin/includes/upgrade.php';
 
92
  foreach ( $table_schema as $table ) {
93
  dbDelta( $table );
94
  }
@@ -102,5 +102,4 @@ class WPUF_Installer {
102
  public function schedule_events() {
103
  wp_schedule_event( time(), 'daily', 'wpuf_remove_expired_post_hook' );
104
  }
105
-
106
  }
13
  * @return void
14
  */
15
  public function install() {
 
16
  $this->create_tables();
17
  $this->schedule_events();
18
 
19
  $installed = get_option( 'wpuf_installed' );
20
 
21
+ if ( !$installed ) {
22
  update_option( 'wpuf_installed', time() );
23
  }
24
 
39
  $collate = '';
40
 
41
  if ( $wpdb->has_cap( 'collation' ) ) {
42
+ if ( !empty( $wpdb->charset ) ) {
43
  $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
44
  }
45
 
46
+ if ( !empty( $wpdb->collate ) ) {
47
  $collate .= " COLLATE $wpdb->collate";
48
  }
49
  }
50
 
51
+ $table_schema = [
52
  "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}wpuf_transaction` (
53
  `id` int(11) NOT NULL AUTO_INCREMENT,
54
  `user_id` bigint(20) DEFAULT NULL,
85
  PRIMARY KEY (`id`),
86
  key `user_id` (`user_id`)
87
  ) $collate;",
88
+ ];
89
 
90
  require_once ABSPATH . 'wp-admin/includes/upgrade.php';
91
+
92
  foreach ( $table_schema as $table ) {
93
  dbDelta( $table );
94
  }
102
  public function schedule_events() {
103
  wp_schedule_event( time(), 'daily', 'wpuf_remove_expired_post_hook' );
104
  }
 
105
  }
includes/class-list-table-subscribers.php CHANGED
@@ -1,24 +1,24 @@
1
  <?php
2
 
3
- if ( ! class_exists ( 'WP_List_Table' ) ) {
4
  require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
  }
6
 
7
  /**
8
  * List table class
9
  */
10
- class WPUF_List_Table_Subscribers extends \WP_List_Table {
11
 
12
- function __construct() {
13
- parent::__construct( array(
14
  'singular' => 'subscriber',
15
  'plural' => 'subscribers',
16
- 'ajax' => false
17
- ) );
18
  }
19
 
20
- function get_table_classes() {
21
- return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
22
  }
23
 
24
  /**
@@ -26,8 +26,8 @@ class WPUF_List_Table_Subscribers extends \WP_List_Table {
26
  *
27
  * @return void
28
  */
29
- function no_items() {
30
- _e( 'No subscribers found', 'wp-user-frontend' );
31
  }
32
 
33
  /**
@@ -35,8 +35,8 @@ class WPUF_List_Table_Subscribers extends \WP_List_Table {
35
  *
36
  * @return array
37
  */
38
- function get_columns() {
39
- $columns = array(
40
  'cb' => '<input type="checkbox" />',
41
  'id' => __( 'User ID', 'wp-user-frontend' ),
42
  'name' => __( 'User Name', 'wp-user-frontend' ),
@@ -46,34 +46,42 @@ class WPUF_List_Table_Subscribers extends \WP_List_Table {
46
  'transaction_id' => __( 'Transaction ID', 'wp-user-frontend' ),
47
  'starts_from' => __( 'Starts from', 'wp-user-frontend' ),
48
  'expire' => __( 'Expire date', 'wp-user-frontend' ),
49
- );
 
50
  return $columns;
51
  }
52
 
53
  /**
54
  * Default column values if no callback found
55
  *
56
- * @param object $item
57
- * @param string $column_name
58
  *
59
  * @return string
60
  */
61
- function column_default( $item, $column_name ) {
62
  switch ( $column_name ) {
63
  case 'id':
64
  return $item->user_id;
 
65
  case 'name':
66
  return $item->name;
 
67
  case 'subscription_id':
68
  return $item->subscribtion_id;
 
69
  case 'status':
70
  return $item->subscribtion_status;
 
71
  case 'gateway':
72
  return $item->gateway;
 
73
  case 'transaction_id':
74
  return $item->transaction_id;
 
75
  case 'starts_from':
76
  return $item->starts_from;
 
77
  case 'expire':
78
  return $item->expire;
79
 
@@ -87,10 +95,10 @@ class WPUF_List_Table_Subscribers extends \WP_List_Table {
87
  *
88
  * @return array
89
  */
90
- function get_sortable_columns() {
91
- $sortable_columns = array(
92
- 'id' => array( 'id', true ),
93
- );
94
 
95
  return $sortable_columns;
96
  }
@@ -98,14 +106,15 @@ class WPUF_List_Table_Subscribers extends \WP_List_Table {
98
  /**
99
  * Render the checkbox column
100
  *
101
- * @param object $item
102
  *
103
  * @return string
104
  */
105
- function column_cb($item) {
 
106
  return sprintf(
107
- '<input type="checkbox" name="subscriber_id[]" value="%d" />', $_REQUEST['post_ID']
108
- );
109
  }
110
 
111
  /**
@@ -115,17 +124,18 @@ class WPUF_List_Table_Subscribers extends \WP_List_Table {
115
  */
116
  public function get_views() {
117
  $status_links = [];
118
- $base_link = admin_url( 'admin.php?page=wpuf_subscribers&pack='.$_REQUEST['post_ID'] );
 
119
 
120
- $subscribers_count = count( $users = WPUF_Subscription::init()->subscription_pack_users( $_REQUEST['post_ID'] ) );
121
- $subscriptions_active_count = count( $users = WPUF_Subscription::init()->subscription_pack_users( $_REQUEST['post_ID'] ) );
122
- $subscriptions_cancle_count = count( $users = WPUF_Subscription::init()->subscription_pack_users( $_REQUEST['post_ID'] ) );
123
 
124
- $status = isset( $_REQUEST['status'] ) ? sanitize_text_field( $_REQUEST['status'] ) : 'all';
125
 
126
- $status_links['all'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( array( 'status' => 'all' ), $base_link ), ( $status == 'all' ) ? 'current' : '', __( 'All', 'wp-user-frontend' ), $subscribers_count );
127
- $status_links['Completed'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( array( 'status' => 'Completed' ), $base_link ), ( $status == 'pending' ) ? 'current' : '', __( 'Completed', 'wp-user-frontend' ), $subscriptions_active_count );
128
- $status_links['Cancel'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( array( 'status' => 'Cancel' ), $base_link ), ( $status == 'Cancel' ) ? 'current' : '', __( 'Cancel', 'wp-user-frontend' ), $subscriptions_cancle_count );
129
 
130
  return $status_links;
131
  }
@@ -135,39 +145,44 @@ class WPUF_List_Table_Subscribers extends \WP_List_Table {
135
  *
136
  * @return void
137
  */
138
- function prepare_items() {
139
  global $wpdb;
140
 
141
  $columns = $this->get_columns();
142
- $hidden = array( );
143
  $sortable = $this->get_sortable_columns();
144
- $this->_column_headers = array( $columns, $hidden, $sortable );
145
 
146
  $per_page = 20;
147
  $current_page = $this->get_pagenum();
148
- $offset = ( $current_page -1 ) * $per_page;
149
- $this->page_status = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : '2';
150
 
151
  // only ncessary because we have sample data
152
- $args = array(
153
  'offset' => $offset,
154
  'number' => $per_page,
155
- );
156
 
157
  if ( isset( $_REQUEST['orderby'] ) && isset( $_REQUEST['order'] ) ) {
158
- $args['orderby'] = $_REQUEST['orderby'];
159
- $args['order'] = $_REQUEST['order'] ;
160
  }
161
 
 
 
 
 
162
  $sql = 'SELECT * FROM ' . $wpdb->prefix . 'wpuf_subscribers';
163
- $sql .= isset( $_REQUEST['post_ID'] ) ? ' WHERE subscribtion_id = ' . $_REQUEST['post_ID'] : '';
164
- $sql .= isset( $_REQUEST['status'] ) ? ' AND subscribtion_status = "' . sanitize_text_field( $_REQUEST['status'] ) . '"' : '';
 
165
 
166
  $this->items = $wpdb->get_results( $sql, OBJECT );
167
 
168
- $this->set_pagination_args( array(
169
  'total_items' => count( $this->items ),
170
- 'per_page' => $per_page
171
- ) );
172
  }
173
  }
1
  <?php
2
 
3
+ if ( !class_exists( 'WP_List_Table' ) ) {
4
  require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
  }
6
 
7
  /**
8
  * List table class
9
  */
10
+ class WPUF_List_Table_Subscribers extends WP_List_Table {
11
 
12
+ public function __construct() {
13
+ parent::__construct( [
14
  'singular' => 'subscriber',
15
  'plural' => 'subscribers',
16
+ 'ajax' => false,
17
+ ] );
18
  }
19
 
20
+ public function get_table_classes() {
21
+ return [ 'widefat', 'fixed', 'striped', $this->_args['plural'] ];
22
  }
23
 
24
  /**
26
  *
27
  * @return void
28
  */
29
+ public function no_items() {
30
+ esc_html_e( 'No subscribers found', 'wp-user-frontend' );
31
  }
32
 
33
  /**
35
  *
36
  * @return array
37
  */
38
+ public function get_columns() {
39
+ $columns = [
40
  'cb' => '<input type="checkbox" />',
41
  'id' => __( 'User ID', 'wp-user-frontend' ),
42
  'name' => __( 'User Name', 'wp-user-frontend' ),
46
  'transaction_id' => __( 'Transaction ID', 'wp-user-frontend' ),
47
  'starts_from' => __( 'Starts from', 'wp-user-frontend' ),
48
  'expire' => __( 'Expire date', 'wp-user-frontend' ),
49
+ ];
50
+
51
  return $columns;
52
  }
53
 
54
  /**
55
  * Default column values if no callback found
56
  *
57
+ * @param object $item
58
+ * @param string $column_name
59
  *
60
  * @return string
61
  */
62
+ public function column_default( $item, $column_name ) {
63
  switch ( $column_name ) {
64
  case 'id':
65
  return $item->user_id;
66
+
67
  case 'name':
68
  return $item->name;
69
+
70
  case 'subscription_id':
71
  return $item->subscribtion_id;
72
+
73
  case 'status':
74
  return $item->subscribtion_status;
75
+
76
  case 'gateway':
77
  return $item->gateway;
78
+
79
  case 'transaction_id':
80
  return $item->transaction_id;
81
+
82
  case 'starts_from':
83
  return $item->starts_from;
84
+
85
  case 'expire':
86
  return $item->expire;
87
 
95
  *
96
  * @return array
97
  */
98
+ public function get_sortable_columns() {
99
+ $sortable_columns = [
100
+ 'id' => [ 'id', true ],
101
+ ];
102
 
103
  return $sortable_columns;
104
  }
106
  /**
107
  * Render the checkbox column
108
  *
109
+ * @param object $item
110
  *
111
  * @return string
112
  */
113
+ public function column_cb( $item ) {
114
+ $post_ID = isset( $_REQUEST['post_ID'] ) ? intval( wp_unslash( $_REQUEST['post_ID'] ) ) : 0;
115
  return sprintf(
116
+ '<input type="checkbox" name="subscriber_id[]" value="%d" />', $post_ID
117
+ );
118
  }
119
 
120
  /**
124
  */
125
  public function get_views() {
126
  $status_links = [];
127
+ $post_ID = isset( $_REQUEST['post_ID'] ) ? intval( wp_unslash( $_REQUEST['post_ID'] ) ) : 0;
128
+ $base_link = admin_url( 'admin.php?page=wpuf_subscribers&pack=' . $post_ID );
129
 
130
+ $subscribers_count = count( $users = WPUF_Subscription::init()->subscription_pack_users( $post_ID ) );
131
+ $subscriptions_active_count = count( $users = WPUF_Subscription::init()->subscription_pack_users( $post_ID ) );
132
+ $subscriptions_cancle_count = count( $users = WPUF_Subscription::init()->subscription_pack_users( $post_ID ) );
133
 
134
+ $status = isset( $_REQUEST['status'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) : 'all';
135
 
136
+ $status_links['all'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( [ 'status' => 'all' ], $base_link ), ( $status == 'all' ) ? 'current' : '', __( 'All', 'wp-user-frontend' ), $subscribers_count );
137
+ $status_links['Completed'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( [ 'status' => 'Completed' ], $base_link ), ( $status == 'pending' ) ? 'current' : '', __( 'Completed', 'wp-user-frontend' ), $subscriptions_active_count );
138
+ $status_links['Cancel'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', add_query_arg( [ 'status' => 'Cancel' ], $base_link ), ( $status == 'Cancel' ) ? 'current' : '', __( 'Cancel', 'wp-user-frontend' ), $subscriptions_cancle_count );
139
 
140
  return $status_links;
141
  }
145
  *
146
  * @return void
147
  */
148
+ public function prepare_items() {
149
  global $wpdb;
150
 
151
  $columns = $this->get_columns();
152
+ $hidden = [ ];
153
  $sortable = $this->get_sortable_columns();
154
+ $this->_column_headers = [ $columns, $hidden, $sortable ];
155
 
156
  $per_page = 20;
157
  $current_page = $this->get_pagenum();
158
+ $offset = ( $current_page - 1 ) * $per_page;
159
+ $this->page_status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '2';
160
 
161
  // only ncessary because we have sample data
162
+ $args = [
163
  'offset' => $offset,
164
  'number' => $per_page,
165
+ ];
166
 
167
  if ( isset( $_REQUEST['orderby'] ) && isset( $_REQUEST['order'] ) ) {
168
+ $args['orderby'] = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ) ;
169
+ $args['order'] = sanitize_text_field( wp_unslash( $_REQUEST['order'] ) );
170
  }
171
 
172
+ $post_ID = isset( $_REQUEST['post_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post_ID'] ) ) : '';
173
+ $status = isset( $_REQUEST['status'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) : '';
174
+
175
+
176
  $sql = 'SELECT * FROM ' . $wpdb->prefix . 'wpuf_subscribers';
177
+ $sql .= isset( $_REQUEST['post_ID'] ) ? ' WHERE subscribtion_id = ' . sanitize_text_field( wp_unslash( $_REQUEST['post_ID'] ) ) : '';
178
+
179
+ $sql .= isset( $_REQUEST['status'] ) ? ' AND subscribtion_status = "' . sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) . '"' : '';
180
 
181
  $this->items = $wpdb->get_results( $sql, OBJECT );
182
 
183
+ $this->set_pagination_args( [
184
  'total_items' => count( $this->items ),
185
+ 'per_page' => $per_page,
186
+ ] );
187
  }
188
  }
includes/class-login-widget.php CHANGED
@@ -1,354 +1,356 @@
1
- <?php
2
-
3
- /**
4
- * Ajax Login and Forgot password handler class
5
- *
6
- * @since 2.8
7
- */
8
-
9
- class WPUF_Login_Widget extends WP_Widget {
10
-
11
- function __construct() {
12
-
13
- parent::__construct(
14
- 'WPUF_Login_Widget',
15
- __('WPUF Ajax Login', 'wp-user-frontend'),
16
- array( 'description' => __( 'Ajax Login widget for WP User Frontend', 'wp-user-frontend' ), )
17
- );
18
-
19
- add_action( 'wp_ajax_nopriv_wpuf_ajax_login', array( $this, 'ajax_login' ) );
20
- add_action( 'wp_ajax_nopriv_wpuf_lost_password', array( $this, 'ajax_reset_pass' ) );
21
- add_action( 'wp_ajax_wpuf_ajax_logout', array( $this, 'ajax_logout' ) );
22
- }
23
-
24
- /**
25
- * Ajax Login function
26
- *
27
- * @return void
28
- */
29
- public function ajax_login() {
30
-
31
- $user_login = trim( $_POST['log'] );
32
- $user_pass = trim( $_POST['pwd'] );
33
- $rememberme = isset( $_POST['rememberme'] ) ? $_POST['rememberme'] : false;
34
-
35
- if ( empty( $user_login ) || empty( $user_pass ) ) {
36
- wp_send_json_error( array( 'message'=> __( 'Please fill all form fields', 'wp-user-frontend') ) );
37
- } else {
38
- $user = wp_signon( array('user_login' => $user_login, 'user_password' => $user_pass), false );
39
-
40
- if ( is_wp_error($user) ) {
41
- wp_send_json_error( array( 'message'=> $user->get_error_message() ) );
42
- } else {
43
- wp_send_json_success( array( 'message'=> __( 'Login successful!', 'wp-user-frontend' ) ) );
44
- }
45
- }
46
- wp_set_auth_cookie( $user->ID, $rememberme );
47
- }
48
-
49
- /**
50
- * Ajax Logout function
51
- *
52
- * @return void
53
- */
54
- public function ajax_logout() {
55
-
56
- wp_logout();
57
- wp_send_json_success( array( 'message'=> __( 'Logout successful!', 'wp-user-frontend' ) ) );
58
- }
59
-
60
- /**
61
- * Ajax password reset function
62
- *
63
- * @return void
64
- */
65
- function ajax_reset_pass() {
66
-
67
- $username_or_email = trim( $_POST['user_login'] );
68
-
69
- // Check if input variables are empty
70
- if ( empty( $username_or_email ) ) {
71
- wp_send_json_error( array( 'error' => true, 'message'=> __( 'Please fill all form fields', 'wp-user-frontend' ) ) );
72
- } else {
73
- $username = is_email( $username_or_email ) ? sanitize_email( $username_or_email ) : sanitize_user( $username_or_email );
74
-
75
- $user_forgotten = $this->ajax_lostpassword_retrieve( $username );
76
-
77
- if ( is_wp_error( $user_forgotten ) ) {
78
- $lostpass_error_messages = $user_forgotten->errors;
79
-
80
- $display_errors = '';
81
- foreach ( $lostpass_error_messages as $error ) {
82
- $display_errors .= '<p>'.$error[0].'</p>';
83
- }
84
-
85
- wp_send_json_error( array( 'message' => $display_errors ) );
86
- } else {
87
- wp_send_json_success( array( 'message' => __( 'Password has been reset. Please check your email.', 'wp-user-frontend' ) ) );
88
- }
89
- }
90
- }
91
-
92
- /**
93
- * Password retrieve function
94
- *
95
- * @return mixed
96
- */
97
- private function ajax_lostpassword_retrieve( $user_input ) {
98
- global $wpdb, $wp_hasher;
99
-
100
- $errors = new WP_Error();
101
-
102
- if ( empty( $user_input ) ) {
103
- $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or email address.', 'wp-user-frontend'));
104
- } elseif ( strpos( $user_input, '@' ) ) {
105
- $user_data = get_user_by( 'email', trim( $user_input ) );
106
- if ( empty( $user_data ) )
107
- $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.', 'wp-user-frontend'));
108
- } else {
109
- $login = trim($user_input);
110
- $user_data = get_user_by('login', $login);
111
- }
112
-
113
- /**
114
- * Fires before errors are returned from a password reset request.
115
- */
116
- do_action( 'lostpassword_post', $errors );
117
-
118
- if ( $errors->get_error_code() )
119
- return $errors;
120
-
121
- if ( !$user_data ) {
122
- $errors->add( 'invalidcombo', __( '<strong>ERROR</strong>: Invalid username or email.', 'wp-user-frontend' ) );
123
- return $errors;
124
- }
125
-
126
- // Redefining user_login ensures we return the right case in the email.
127
- $user_login = $user_data->user_login;
128
- $user_email = $user_data->user_email;
129
- $key = get_password_reset_key( $user_data );
130
-
131
- if ( is_wp_error( $key ) ) {
132
- return $key;
133
- }
134
-
135
- $message = __('Someone has requested a password reset for the following account:', 'wp-user-frontend') . "\r\n\r\n";
136
- $message .= network_home_url( '/' ) . "\r\n\r\n";
137
- $message .= sprintf(__('Username: %s', 'wp-user-frontend'), $user_login) . "\r\n\r\n";
138
- $message .= __('If this was a mistake, just ignore this email and nothing will happen.', 'wp-user-frontend') . "\r\n\r\n";
139
- $message .= __('To reset your password, visit the following address:', 'wp-user-frontend') . "\r\n\r\n";
140
- $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
141
-
142
- $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
143
-
144
- $title = sprintf( __('[%s] Password Reset', 'wp-user-frontend'), $blogname );
145
-
146
- $title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
147
-
148
- $message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
149
-
150
- if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
151
- $errors->add('mailfailed', __('<strong>ERROR</strong>: The email could not be sent.Possible reason: your host may have disabled the mail() function.', 'wp-user-frontend'));
152
-
153
- return true;
154
- }
155
-
156
- /**
157
- * Display Ajax Login widget
158
- *
159
- * @return void
160
- */
161
- public function widget( $args, $instance ) {
162
-
163
- wp_enqueue_script( 'wpuf_ajax_login' );
164
-
165
- $title = apply_filters( 'widget_title', $instance['title'] );
166
- $log_in_header = apply_filters( 'widget_text_content', $instance['log_in_header'] );
167
- $pwd_reset_header = apply_filters( 'widget_text_content', $instance['pwd_reset_header'] );
168
- $uname_label = apply_filters( 'widget_text', $instance['uname_label'] );
169
- $pwd_label = apply_filters( 'widget_text', $instance['pwd_label'] );
170
- $remember_label = apply_filters( 'widget_text', $instance['remember_label'] );
171
- $log_in_label = apply_filters( 'widget_text', $instance['log_in_label'] );
172
- $pass_reset_label = apply_filters( 'widget_text', $instance['pass_reset_label'] );
173
-
174
- echo $args['before_widget'];
175
-
176
- if ( ! empty( $title ) ) {
177
- echo $args['before_title'] . $title . $args['after_title'];
178
- }
179
-
180
- if ( is_user_logged_in() ) {
181
- $user_id = get_current_user_id();
182
- echo get_avatar( $user_id, 24 );
183
- }
184
-
185
- $login_args = array(
186
- 'form_id' => 'wpuf_ajax_login_form',
187
- 'label_username' => $uname_label,
188
- 'label_password' => $pwd_label,
189
- 'label_remember' => $remember_label,
190
- 'label_log_in' => $log_in_label
191
- );
192
- ?>
193
- <div class="login-widget-container">
194
- <?php
195
- if( ! is_user_logged_in() ) { ?>
196
-
197
- <!-- Login form -->
198
- <div class="wpuf-ajax-login-form">
199
- <div class="wpuf-ajax-errors"></div>
200
-
201
- <p><?php echo $log_in_header; ?></p>
202
-
203
- <?php
204
- wp_login_form( $login_args );
205
- if ( get_option( 'users_can_register' ) ) {
206
- $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register', 'wp-user-frontend' ) );
207
- echo $registration_url;
208
- echo apply_filters( 'login_link_separator', ' | ' );
209
- }?>
210
- <a href="#wpuf-ajax-lost-pw-url" id="wpuf-ajax-lost-pw-url"><?php _e( 'Lost your password?', 'wp-user-frontend' ); ?></a>
211
- </div>
212
-
213
- <!-- Lost Password form -->
214
- <div class="wpuf-ajax-reset-password-form">
215
- <form id="wpuf_ajax_reset_pass_form" action="<?php echo home_url( '/' ); ?>" method="POST">
216
- <div class="wpuf-ajax-message"> <?php echo $pwd_reset_header; ?></div>
217
- <p>
218
- <label for="wpuf-user_login"><?php _e( 'Username or E-mail:', 'wp-user-frontend' ); ?></label>
219
- <input type="text" name="user_login" id="wpuf-user_login" class="input" value="" size="20" />
220
- </p>
221
-
222
- <?php do_action( 'lostpassword_form' ); ?>
223
-
224
- <p class="submit">
225
- <input type="submit" name="wp-submit" id="wp-submit" value="<?php echo $pass_reset_label; ?>" />
226
- <input type="hidden" name="redirect_to" value="<?php echo WPUF_Simple_Login::get_posted_value( 'redirect_to' ); ?>" />
227
- <input type="hidden" name="wpuf_reset_password" value="true" />
228
- <input type="hidden" name="action" value="lost_password" />
229
-
230
- <?php wp_nonce_field( 'wpuf_lost_pass' ); ?>
231
- </p>
232
- </form>
233
- <div id="ajax-lp-section">
234
- <a href="#wpuf-ajax-login-url" id="wpuf-ajax-login-url"> <?php _e( 'Login', 'wp-user-frontend' ); ?> </a>
235
- <?php
236
- if ( get_option( 'users_can_register' ) ) {
237
- echo apply_filters( 'login_link_separator', ' | ' );
238
- $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register', 'wp-user-frontend' ) );
239
- echo $registration_url;
240
- }
241
- ?>
242
- </div>
243
- </div>
244
- <?php } else { ?>
245
- <div class="wpuf-ajax-logout">
246
- <a id="logout-url" href="#logout"><?php echo __('Log out', 'wp-user-frontend') ?></a>
247
- </div>
248
- <?php } ?>
249
- </div>
250
-
251
- <?php
252
- echo $args['after_widget'];
253
- }
254
-
255
- /**
256
- * Ajax Login widget backend
257
- *
258
- * @return void
259
- */
260
- public function form( $instance ) {
261
-
262
- $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : __( 'WPUF Login Widget', 'wp-user-frontend' );
263
- $log_in_header = isset( $instance[ 'log_in_header' ] ) ? $instance[ 'log_in_header' ] : __( 'Username or Email Address', 'wp-user-frontend' );
264
- $pwd_reset_header = isset( $instance[ 'pwd_reset_header' ] ) ? $instance[ 'pwd_reset_header' ] : __( 'Please enter your username or email address. You will receive a link to create a new password via email', 'wp-user-frontend' );
265
- $uname_label = isset( $instance[ 'uname_label' ] ) ? $instance[ 'uname_label' ] : __( 'Username', 'wp-user-frontend' );
266
- $pwd_label = isset( $instance[ 'pwd_label' ] ) ? $instance[ 'pwd_label' ] : __( 'Password', 'wp-user-frontend' );
267
- $remember_label = isset( $instance[ 'remember_label' ] ) ? $instance[ 'remember_label' ] : __( 'Remember Me', 'wp-user-frontend' );
268
- $log_in_label = isset( $instance[ 'log_in_label' ] ) ? $instance[ 'log_in_label' ] : __( 'Log In', 'wp-user-frontend' );
269
- $pass_reset_label = isset( $instance[ 'pass_reset_label' ] ) ? $instance[ 'pass_reset_label' ] : __( 'Reset Password', 'wp-user-frontend' );
270
- ?>
271
-
272
- <p>
273
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'wp-user-frontend' ); ?></label>
274
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
275
- </p>
276
- <p>
277
- <label for="<?php echo $this->get_field_id( 'log_in_header' ); ?>"><?php _e( 'Log-in Text:', 'wp-user-frontend' ); ?></label>
278
- <input class="widefat" id="<?php echo $this->get_field_id( 'log_in_header' ); ?>" name="<?php echo $this->get_field_name( 'log_in_header' ); ?>" type="textarea" value="<?php echo esc_attr( $log_in_header ); ?>" />
279
- </p>
280
- <p>
281
- <label for="<?php echo $this->get_field_id( 'uname_label' ); ?>"><?php _e( 'Username Label:', 'wp-user-frontend' ); ?></label>
282
- <input class="widefat" id="<?php echo $this->get_field_id( 'uname_label' ); ?>" name="<?php echo $this->get_field_name( 'uname_label' ); ?>" type="text" value="<?php echo esc_attr( $uname_label ); ?>" />
283
- </p>
284
- <p>
285
- <label for="<?php echo $this->get_field_id( 'pwd_label' ); ?>"><?php _e( 'Password Label:', 'wp-user-frontend' ); ?></label>
286
- <input class="widefat" id="<?php echo $this->get_field_id( 'pwd_label' ); ?>" name="<?php echo $this->get_field_name( 'pwd_label' ); ?>" type="text" value="<?php echo esc_attr( $pwd_label ); ?>" />
287
- </p>
288
- <p>
289
- <label for="<?php echo $this->get_field_id( 'remember_label' ); ?>"><?php _e( 'Remember Me Label:', 'wp-user-frontend' ); ?></label>
290
- <input class="widefat" id="<?php echo $this->get_field_id( 'remember_label' ); ?>" name="<?php echo $this->get_field_name( 'remember_label' ); ?>" type="text" value="<?php echo esc_attr( $remember_label ); ?>" />
291
- </p>
292
- <label for="<?php echo $this->get_field_id( 'log_in_label' ); ?>"><?php _e( 'Log In Label:', 'wp-user-frontend' ); ?></label>
293
- <input class="widefat" id="<?php echo $this->get_field_id( 'log_in_label' ); ?>" name="<?php echo $this->get_field_name( 'log_in_label' ); ?>" type="text" value="<?php echo esc_attr( $log_in_label ); ?>" />
294
- </p>
295
- <p>
296
- <label for="<?php echo $this->get_field_id( 'pwd_reset_header' ); ?>"><?php _e( 'Password Reset Text:', 'wp-user-frontend' ); ?></label>
297
- <input class="widefat" id="<?php echo $this->get_field_id( 'pwd_reset_header' ); ?>" name="<?php echo $this->get_field_name( 'pwd_reset_header' ); ?>" type="textarea" value="<?php echo esc_attr( $pwd_reset_header ); ?>" />
298
- </p>
299
- <p>
300
- <label for="<?php echo $this->get_field_id( 'pass_reset_label' ); ?>"><?php _e( 'Password Reset Label:', 'wp-user-frontend' ); ?></label>
301
- <input class="widefat" id="<?php echo $this->get_field_id( 'pass_reset_label' ); ?>" name="<?php echo $this->get_field_name( 'pass_reset_label' ); ?>" type="text" value="<?php echo esc_attr( $pass_reset_label ); ?>" />
302
- </p>
303
- <?php
304
- }
305
-
306
- /**
307
- * Updating widget replacing old instances with new
308
- *
309
- * @return $instance
310
- */
311
- public function update( $new_instance, $old_instance ) {
312
-
313
- $instance = array();
314
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
315
- $instance['log_in_header'] = ( ! empty( $new_instance['log_in_header'] ) ) ? strip_tags( $new_instance['log_in_header'] ) : '';
316
- $instance['pwd_reset_header'] = ( ! empty( $new_instance['pwd_reset_header'] ) ) ? strip_tags( $new_instance['pwd_reset_header'] ) : '';
317
- $instance['uname_label'] = ( ! empty( $new_instance['uname_label'] ) ) ? strip_tags( $new_instance['uname_label'] ) : '';
318
- $instance['pwd_label'] = ( ! empty( $new_instance['pwd_label'] ) ) ? strip_tags( $new_instance['pwd_label'] ) : '';
319
- $instance['remember_label'] = ( ! empty( $new_instance['remember_label'] ) ) ? strip_tags( $new_instance['remember_label'] ) : '';
320
- $instance['log_in_label'] = ( ! empty( $new_instance['log_in_label'] ) ) ? strip_tags( $new_instance['log_in_label'] ) : '';
321
- $instance['pass_reset_label'] = ( ! empty( $new_instance['pass_reset_label'] ) ) ? strip_tags( $new_instance['pass_reset_label'] ) : '';
322
-
323
- return $instance;
324
- }
325
-
326
- }
327
-
328
-
329
- /**
330
- * Register WPUF_Login_Widget widget
331
- *
332
- * @return void
333
- */
334
- function wpuf_register_ajax_login_widget() {
335
-
336
- register_widget( 'WPUF_Login_Widget' );
337
- }
338
- add_action( 'widgets_init', 'wpuf_register_ajax_login_widget' );
339
-
340
-
341
- /**
342
- * Registers widget scripts
343
- *
344
- * @return void
345
- */
346
- function wpuf_register_login_scripts() {
347
-
348
- wp_register_script( 'wpuf_ajax_login', WPUF_ASSET_URI . '/js/wpuf-login-widget.js', array( 'jquery' ), false, true );
349
-
350
- wp_localize_script( 'wpuf_ajax_login', 'wpuf_ajax', array(
351
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
352
- ));
353
- }
354
- add_action( 'wp_enqueue_scripts', 'wpuf_register_login_scripts' );
1
+ <?php
2
+
3
+ /**
4
+ * Ajax Login and Forgot password handler class
5
+ *
6
+ * @since 2.8
7
+ */
8
+ class WPUF_Login_Widget extends WP_Widget {
9
+
10
+ public function __construct() {
11
+ parent::__construct(
12
+ 'WPUF_Login_Widget',
13
+ __( 'WPUF Ajax Login', 'wp-user-frontend' ),
14
+ [ 'description' => __( 'Ajax Login widget for WP User Frontend', 'wp-user-frontend' )]
15
+ );
16
+
17
+ add_action( 'wp_ajax_nopriv_wpuf_ajax_login', [ $this, 'ajax_login' ] );
18
+ add_action( 'wp_ajax_nopriv_wpuf_lost_password', [ $this, 'ajax_reset_pass' ] );
19
+ add_action( 'wp_ajax_wpuf_ajax_logout', [ $this, 'ajax_logout' ] );
20
+ }
21
+
22
+ /**
23
+ * Ajax Login function
24
+ *
25
+ * @return void
26
+ */
27
+ public function ajax_login() {
28
+ $user_login = isset( $_POST['log'] ) ? sanitize_text_field( wp_unslash( $_POST['log'] ) ) : '';
29
+ $user_pass = isset( $_POST['pwd'] ) ? sanitize_text_field( wp_unslash( $_POST['pwd'] ) ) : '';
30
+ $rememberme = isset( $_POST['rememberme'] ) ? sanitize_text_field( wp_unslash( $_POST['rememberme'] ) ) : false;
31
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
32
+
33
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce , 'wpuf_lost_pass' ) ) {
34
+ return ;
35
+ }
36
+
37
+ if ( empty( $user_login ) || empty( $user_pass ) ) {
38
+ wp_send_json_error( [ 'message'=> __( 'Please fill all form fields', 'wp-user-frontend' ) ] );
39
+ } else {
40
+ $user = wp_signon( ['user_login' => $user_login, 'user_password' => $user_pass], false );
41
+
42
+ if ( is_wp_error( $user ) ) {
43
+ wp_send_json_error( [ 'message'=> $user->get_error_message() ] );
44
+ } else {
45
+ wp_send_json_success( [ 'message'=> __( 'Login successful!', 'wp-user-frontend' ) ] );
46
+ }
47
+ }
48
+ wp_set_auth_cookie( $user->ID, $rememberme );
49
+ }
50
+
51
+ /**
52
+ * Ajax Logout function
53
+ *
54
+ * @return void
55
+ */
56
+ public function ajax_logout() {
57
+ wp_logout();
58
+ wp_send_json_success( [ 'message'=> __( 'Logout successful!', 'wp-user-frontend' ) ] );
59
+ }
60
+
61
+ /**
62
+ * Ajax password reset function
63
+ *
64
+ * @return void
65
+ */
66
+ public function ajax_reset_pass() {
67
+ $username_or_email = isset( $_POST['user_login'] ) ? sanitize_text_field( wp_unslash( $_POST['user_login'] ) ) : '';
68
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
69
+
70
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'wpuf_lost_pass' ) ) {
71
+ return ;
72
+ }
73
+
74
+ // Check if input variables are empty
75
+ if ( empty( $username_or_email ) ) {
76
+ wp_send_json_error( [ 'error' => true, 'message'=> __( 'Please fill all form fields', 'wp-user-frontend' ) ] );
77
+ } else {
78
+ $username = is_email( $username_or_email ) ? sanitize_email( $username_or_email ) : sanitize_user( $username_or_email );
79
+
80
+ $user_forgotten = $this->ajax_lostpassword_retrieve( $username );
81
+
82
+ if ( is_wp_error( $user_forgotten ) ) {
83
+ $lostpass_error_messages = $user_forgotten->errors;
84
+
85
+ $display_errors = '';
86
+
87
+ foreach ( $lostpass_error_messages as $error ) {
88
+ $display_errors .= '<p>' . $error[0] . '</p>';
89
+ }
90
+
91
+ wp_send_json_error( [ 'message' => $display_errors ] );
92
+ } else {
93
+ wp_send_json_success( [ 'message' => __( 'Password has been reset. Please check your email.', 'wp-user-frontend' ) ] );
94
+ }
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Password retrieve function
100
+ *
101
+ * @return mixed
102
+ */
103
+ private function ajax_lostpassword_retrieve( $user_input ) {
104
+ global $wpdb, $wp_hasher;
105
+
106
+ $errors = new WP_Error();
107
+
108
+ if ( empty( $user_input ) ) {
109
+ $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Enter a username or email address.', 'wp-user-frontend' ) );
110
+ } elseif ( strpos( $user_input, '@' ) ) {
111
+ $user_data = get_user_by( 'email', trim( $user_input ) );