api = new WPVFB_API();
$this->renderer = new WPVFB_Renderer();
}
public function run() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
add_action( 'admin_menu', array( $this, 'register_admin_menu' ) );
add_action( 'rest_api_init', array( $this->api, 'register_routes' ) );
add_shortcode( 'wpvfb', array( $this->renderer, 'render_shortcode' ) );
add_action( 'wp_enqueue_scripts', array( $this->renderer, 'enqueue_head_styles' ) );
// Add-ons hook in here (renderer, API and builder extension points).
do_action( 'wpvfb_loaded', $this->renderer, $this->api );
}
/** @return WPVFB_Renderer */
public function get_renderer() {
return $this->renderer;
}
public function register_admin_menu() {
// Parent menu
add_menu_page(
__( 'EFE Visual Forms', 'efe-visual-forms' ),
__( 'EFE Visual Forms', 'efe-visual-forms' ),
'manage_options',
self::MENU_SLUG,
array( $this, 'render_admin_page' ),
'dashicons-feedback',
30
);
// Submenu: Forms (same slug as parent so it acts as default)
add_submenu_page(
self::MENU_SLUG,
__( 'All Forms', 'efe-visual-forms' ),
__( 'Forms', 'efe-visual-forms' ),
'manage_options',
self::MENU_SLUG,
array( $this, 'render_admin_page' )
);
// Submenu: Entries
add_submenu_page(
self::MENU_SLUG,
__( 'Entries', 'efe-visual-forms' ),
__( 'Entries', 'efe-visual-forms' ),
'manage_options',
self::ENTRIES_SLUG,
array( $this, 'render_admin_page' )
);
}
public function render_admin_page() {
echo '
';
}
public function enqueue_admin_assets( $hook ) {
if ( false === strpos( (string) $hook, self::MENU_SLUG ) && false === strpos( (string) $hook, self::ENTRIES_SLUG ) ) {
return;
}
$css_file = WPVFB_PLUGIN_DIR . 'dist/assets/builder.css';
$js_file = WPVFB_PLUGIN_DIR . 'dist/assets/builder.js';
$css_ver = file_exists( $css_file ) ? filemtime( $css_file ) : WPVFB_VERSION;
$js_ver = file_exists( $js_file ) ? filemtime( $js_file ) : WPVFB_VERSION;
wp_enqueue_style(
'wpvfb-builder-css',
WPVFB_PLUGIN_URL . 'dist/assets/builder.css',
array(),
$css_ver
);
// Font Awesome (same vendored 5.15.4 build as the storefront): field icons, list-item icons and icons inside
// HTML/static content render on the canvas exactly as on the published form.
wp_enqueue_style(
'wpvfb-fontawesome',
WPVFB_PLUGIN_URL . 'assets/vendor/fontawesome/css/all.min.css',
array(),
'5.15.4'
);
// WordPress media library (wp.media) for the image, column and form background editors.
wp_enqueue_media();
wp_enqueue_script(
'wpvfb-builder-js',
WPVFB_PLUGIN_URL . 'dist/assets/builder.js',
array(),
$js_ver,
true
);
wp_localize_script(
'wpvfb-builder-js',
'wpvfbSettings',
apply_filters(
'wpvfb_builder_settings',
array(
'apiUrl' => esc_url_raw( rest_url( WPVFB_API::REST_NAMESPACE ) ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'pluginUrl' => esc_url_raw( WPVFB_PLUGIN_URL ),
// Default recipient for new notifications and the "Send test email" address.
'adminEmail' => sanitize_email( get_option( 'admin_email' ) ),
)
)
);
}
}