settings_tabs();
?>
settings_render_options_page();
}
public function settings_tabs() {
global $_active_tab;
foreach ( $this->tabs as $name => $label ) {
?>
$field ) {
$field['key'] = $key;
$field['name'] = $key;
$field['prefix'] = 'acff[admin_options]';
$field['value'] = get_option( $field['key'] );
$fields[ $key ] = $field;
}
return array(
'id' => 'fea_admin_' . $tab,
'admin_options' => 1,
'hidden_fields' => array(
'admin_page' => $tab,
),
/* 'form_attributes' => [
'class' => 'fea-admin-options',
], */
'_screen_id' => 'options',
'fields' => $fields,
'submit_value' => __( 'Save Settings', 'frontend-admin' ),
'default_submit_button' => 1,
'update_message' => __( 'Settings Saved', 'frontend-admin' ),
'redirect' => 'current',
'kses' => 0,
'honeypot' => 0,
'no_record' => 1,
);
}
public function settings_render_options_page() {
global $_active_tab, $fea_instance;
if ( 'tools' == $_active_tab ) {
$fea_instance->admin_tools->html();
return;
}
if ( '' || 'welcome' == $_active_tab ) {
?>
%1$s or on whatsapp %3$s', 'frontend-admin' ) ), 'support@dynamiapps.com', esc_url( 'https://api.whatsapp.com/send?phone=972532323950' ), '+972-53-232-3950' ); ?>
tabs as $form_tab => $label ) {
if ( $form_tab == $_active_tab ) {
$form = $this->get_form( $form_tab );
$admin_fields = apply_filters( 'frontend_admin/' . $form_tab . '_fields', array() );
if ( $form ) {
$fea_instance->form_display->render_form( $form );
} else {
if ( in_array( $form_tab, array( 'payments', 'pdf' ) ) ) {
if ( isset( $_POST['action'] ) && $_POST['action'] == 'fea_install_plugin' ) {
$this->install_addon( $form_tab );
} else {
$this->addon_form( $form_tab );
}
}
}
}
}
}
}
public function addon_form( $addon ) {
?>
'user' ) ) );
}
if ( ! get_option( 'frontend_admin_save_submissions' ) ) {
add_option( 'frontend_admin_save_submissions', true );
}
include_once __DIR__ . '/admin-pages/forms/custom-fields.php';
}
public function install_addon( $addon ) {
$args = feadmin_parse_args(
$_POST,
array(
'nonce' => '',
)
);
if ( ! wp_verify_nonce( $args['nonce'], 'frontend-admin-addon' ) ) {
esc_html_e( 'Authentication Error. Please try refreshing the page.', 'frontend-admin' );
}
$addon_zip = 'https://www.dynamiapps.com/wp-content/uploads/frontend-'.$addon.'.zip';
$installed = fea_install_plugin( $addon_zip );
if ( $installed ) {
$addon_slug = fea_addon_slug( 'frontend-admin-' . $addon );
$addon_folder = WP_PLUGIN_DIR . str_replace( '/frontend-' . $addon . '.php', '', $addon_slug );
$fea_folder = WP_PLUGIN_DIR . '/frontend-' . $addon;
if ( ! file_exists( $fea_folder ) ) {
rename( $addon_folder, $fea_folder ); // phpcs:ignore WordPress.WP.AlternativeFunctions.rename_rename, PluginCheck.CodeAnalysis.WriteFile.PluginDirectoryWrite -- renames the folder of the add-on that was just installed; no data is stored in it.
}
$this->addon_form( $addon );
}
}
public function activate_addon() {
if ( empty( $_POST['action'] ) || $_POST['action'] != 'frontend_admin_activate_plugin' ) {
return;
}
$args = feadmin_parse_args(
$_POST,
array(
'nonce' => '',
'addon' => '',
)
);
if ( empty( $args['addon'] ) ) {
return;
}
if ( ! wp_verify_nonce( $args['nonce'], 'frontend-admin-addon' ) ) {
esc_html_e( 'Authentication Error. Please try refreshing the page.', 'frontend-admin' );
}
$addon_slug = fea_addon_slug( 'frontend-admin-' . $args['addon'] );
if ( $addon_slug ) {
if( ! fea_is_plugin_active( $args['addon'] ) ){
activate_plugin( $addon_slug );
}else{
deactivate_plugins( $addon_slug );
}
} else {
esc_html_e( 'Addon Not Found', 'frontend-admin' );
}
wp_redirect(
add_query_arg(
array(
'page' => 'fea-settings',
'tab' => $args['addon'],
),
admin_url()
)
);
}
public function settings_sections() {
include_once __DIR__ . '/admin-pages/submissions/crud.php';
if( class_exists( 'Frontend_Admin_Payments' ) ){
if( FEAP_VERSION < '3.1.2' )
add_action( 'admin_notices', function(){
?>
tabs as $tab => $label ) {
if ( ! in_array( $tab, array( 'welcome', 'payments', 'pdf', 'tools', 'license' ) ) ) {
$file_path = __DIR__ . "/admin-pages/main/$tab.php";
if ( file_exists( $file_path ) ) {
include_once $file_path;
}
}
}
//include_once __DIR__ . '/admin-pages/main/admin-tools.php';
include_once __DIR__ . '/admin-pages/forms/settings.php';
include_once __DIR__ . '/admin-pages/dashboard/settings.php';
do_action( 'frontend_admin/admin_pages' );
}
public function scripts() {
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '-min';
wp_register_style( 'fea-modal', FEA_URL . 'assets/css/modal-min.css', array(), FEA_VERSION );
wp_register_style( 'fea-public', FEA_URL . 'assets/css/frontend-admin' . $min . '.css', array( 'acf-input' ), FEA_VERSION );
wp_register_script( 'fea-modal', FEA_URL . 'assets/js/modal' . $min . '.js', array( 'jquery' ), FEA_VERSION );
wp_register_script( 'fea-public', FEA_URL . 'assets/js/frontend-admin' . $min . '.js', array( 'jquery', 'acf', 'acf-input' ), FEA_VERSION, true );
wp_register_script( 'fea-password-strength', FEA_URL . 'assets/js/password-strength.min.js', array( 'password-strength-meter' ), FEA_VERSION, true );
acf_localize_text( array( 'Passwords Match' => __( 'Passwords Match', 'frontend-admin' ) ) );
add_action( 'admin_init', array( $this, 'activate_addon' ) );
wp_register_style( 'fea-icon', FEA_URL . 'assets/css/icon' . $min . '.css', array(), FEA_VERSION );
wp_register_script( 'fea-copy-code', FEA_URL . 'assets/js/copy-shortcode' . $min . '.js', array( 'jquery' ), FEA_VERSION, true );
wp_register_script( 'fea-form-builder', FEA_URL . 'assets/js/admin' . $min . '.js', array( 'jquery' ), FEA_VERSION, true );
}
public function register_rest_endpoints() {
register_rest_route(
'frontend-admin/v1',
'/frontend-forms',
array(
'methods' => 'GET',
'callback' => array( $this, 'get_forms_list' ),
'permission_callback' => function ( $request ) {
return current_user_can('manage_options');
},
)
);
//acf field groups
register_rest_route(
'frontend-admin/v1',
'/acf-field-groups',
array(
'methods' => 'GET',
'callback' => array( $this, 'get_acf_field_groups' ),
'permission_callback' => function ( $request ) {
return current_user_can('manage_options');
},
)
);
//acf fields
register_rest_route(
'frontend-admin/v1',
'/acf-fields',
array(
'methods' => 'GET',
'callback' => array( $this, 'get_acf_fields' ),
'permission_callback' => function ( $request ) {
return current_user_can('manage_options');
},
)
);
}
public function get_acf_field_groups() {
$field_groups = acf_get_field_groups();
$field_groups_list = [];
if( $field_groups ){
foreach ( $field_groups as $field_group ) {
$field_groups_list[] = [ 'id' => $field_group['key'], 'text' => $field_group['title'] ];
}
}
return $field_groups_list;
}
public function get_acf_fields() {
$field_groups = acf_get_field_groups();
$fields_list = [];
if( $field_groups ){
foreach ( $field_groups as $field_group ) {
//make select2 group
$group_title = $field_group['title'];
$group_children = [];
$fields = acf_get_fields( $field_group['key'] );
if( $fields ){
foreach ( $fields as $field ) {
$group_children[] = [ 'id' => $field['key'], 'text' => $field['label'] ];
}
}
$fields_list[] = [ 'text' => $group_title, 'children' => $group_children ];
}
}
return $fields_list;
}
function get_forms_list() {
$forms = get_posts(
array(
'post_type' => 'admin_form',
'posts_per_page' => '-1',
'post_status' => 'any',
)
);
$forms_list = [];
if( $forms ){
foreach ( $forms as $form ) {
$forms_list[] = [ 'value' => $form->ID, 'label' => $form->post_title ];
}
}
return $forms_list;
}
public function get_page_visibilty_fields(){
$fields = [
'limit_visibilty' => [
'label' => __( 'Limit Visibilty', 'frontend-admin' ),
'type' => 'true_false',
'name' => 'limit_visibilty',
'key' => 'limit_visibilty',
],
'show_for' => [
'label' => __( 'Show For', 'frontend-admin' ),
'type' => 'select',
'choices' => [
'logged_in' => __( 'Logged In', 'frontend-admin' ),
'logged_out' => __( 'Logged Out', 'frontend-admin' ),
'all' => __( 'All', 'frontend-admin' ),
],
'conditional_logic' => [
[
'field' => 'limit_visibilty',
'operator' => '==',
'value' => '1',
],
],
'name' => 'show_for',
'key' => 'show_for',
],
'show_for_roles' => [
'label' => __( 'Show For Roles', 'frontend-admin' ),
'type' => 'select',
'choices' => feadmin_get_user_roles(),
'name' => 'show_for_roles',
'key' => 'show_for_roles',
'conditional_logic' => [
[
'field' => 'limit_visibilty',
'operator' => '==',
'value' => '1',
],
[
'field' => 'show_for',
'operator' => '==',
'value' => 'logged_in',
],
],
'multiple' => true,
'ui' => 1,
],
'redirect_to' => [
'label' => __( 'Redirect To', 'frontend-admin' ),
'type' => 'url',
'name' => 'redirect_to',
'key' => 'redirect_to',
'instructions' => __( 'Enter the URL to redirect to when the page is not visible', 'frontend-admin' ),
'placeholder' => 'https://',
'conditional_logic' => [
[
'field' => 'limit_visibilty',
'operator' => '==',
'value' => '1',
],
],
]
];
return $fields;
}
public function hide_page_metabox( $post ) {
$fields = $this->get_page_visibilty_fields();
$fea_instance = fea_instance();
foreach( $fields as $key => $field ){
$field['prefix'] = 'fea';
$field['post_id'] = $post->ID;
$field['value'] = get_post_meta( $post->ID, 'fea_' . $key, true );
$fea_instance->form_display->render_field_wrap( $field );
}
}
public function update_page_visibilty( $post_id ){
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( ! current_user_can( 'edit_post', $post_id ) ) return;
if ( ! isset( $_POST['fea']['limit_visibilty'] ) ) return;
$fields = $this->get_page_visibilty_fields();
foreach( $fields as $key => $field ){
if( isset( $_POST['fea'][ $field['key'] ] ) ){
update_post_meta( $post_id, 'fea_' . $field['key'], $_POST['fea'][ $field['key'] ] );
}
}
}
public function redirect_users(){
global $post, $fea_limit_visibility;
if( ! isset( $post->ID ) ) return;
$limit_visibilty = get_post_meta( $post->ID, 'fea_limit_visibilty', true );
if( ! $limit_visibilty ) return;
$show_for = get_post_meta( $post->ID, 'fea_show_for', true );
$show_for_roles = get_post_meta( $post->ID, 'fea_show_for_roles', true );
$redirect_to = get_post_meta( $post->ID, 'fea_redirect_to', true );
$fea_limit_visibility = [
'who_can_see' => $show_for,
'by_role' => $show_for_roles
];
if( ! is_singular() ) return;
if( ! $redirect_to ) $redirect_to = home_url();
$is_logged_in = is_user_logged_in();
if( 'logged_in' == $show_for && ! $is_logged_in ){
wp_redirect( $redirect_to );
exit;
}
if( 'logged_out' == $show_for && $is_logged_in ){
wp_redirect( $redirect_to );
exit;
}
if( 'all' == $show_for ) return;
if( 'logged_in' == $show_for&& $is_logged_in ){
if( ! $show_for_roles ) return;
$user = wp_get_current_user();
$user_roles = $user->roles;
$intersect = array_intersect( $user_roles, $show_for_roles );
if( ! $intersect ){
wp_redirect( $redirect_to );
exit;
}
}
}
public function __construct() {
global $fea_instance;
$this->tabs = array(
'welcome' => 'Welcome',
'submissions' => 'Submissions',
'local_avatar' => 'Local Avatar',
'uploads_privacy' => 'Uploads Privacy',
'dashboard' => 'Dashboard',
'apis' => 'APIs',
'csv' => 'CSV',
//'tools' => 'Tools',
);
$this->tabs = apply_filters( 'frontend_admin/admin_tabs', $this->tabs );
$this->settings_sections();
add_action( 'wp_loaded', array( $this, 'scripts' ) );
add_action( 'init', array( $this, 'configs' ) );
add_action( 'admin_menu', array( $this, 'plugin_page' ), 15 );
add_action( 'rest_api_init', array( $this, 'register_rest_endpoints' ) );
//add page options to Show page based on rules
add_action( 'add_meta_boxes', function(){
$post_types = get_post_types( array( 'public' => true ) );
//exclude some post types
$exclude_post_types = array( 'admin_form', 'elementor_library', 'acf-field-group' );
$post_types = array_diff( $post_types, $exclude_post_types );
add_meta_box( 'fea-hide-page', 'Frontend Admin', array( $this, 'hide_page_metabox' ), $post_types, 'side', 'high' );
} );
//update page visibility
add_action( 'save_post', [ $this, 'update_page_visibilty' ] );
//redirect users if page is set to not visible
add_action( 'wp', [ $this, 'redirect_users' ] );
add_filter( 'frontend_admin/forms/get_form', function( $form, $key ){
if( ! $key ) return $form;
$key = explode( 'fea_admin_', $key );
if( isset( $key[1] ) ) return $this->get_form( $key[1] );
return $form;
}, 10, 2 );
}
}
fea_instance()->admin_settings = new Admin_Settings();
endif;