hook = (string) add_menu_page(
__( 'Fillaro', 'fillaro' ),
__( 'Fillaro', 'fillaro' ),
$cap,
self::SLUG,
array( $this, 'render' ),
$this->icon(),
31
);
add_submenu_page( self::SLUG, __( 'Forms', 'fillaro' ), __( 'All Forms', 'fillaro' ), $cap, self::SLUG, array( $this, 'render' ) );
add_submenu_page( self::SLUG, __( 'New Form', 'fillaro' ), __( 'New Form', 'fillaro' ), $cap, 'admin.php?page=' . self::SLUG . '#/new' );
add_submenu_page( self::SLUG, __( 'Entries', 'fillaro' ), __( 'Entries', 'fillaro' ), $cap, 'admin.php?page=' . self::SLUG . '#/entries' );
add_submenu_page( self::SLUG, __( 'Settings', 'fillaro' ), __( 'Settings', 'fillaro' ), $cap, 'admin.php?page=' . self::SLUG . '#/settings' );
}
/**
* Mount point for the app.
*/
public function render() {
echo '
';
}
/**
* Load the app on our page only.
*
* @param string $hook Current hook suffix.
*/
public function enqueue( $hook ) {
if ( $hook !== $this->hook ) {
return;
}
$asset = Assets::asset_file( 'admin' );
wp_enqueue_style( 'fillaro-admin', FILLARO_URL . 'build/admin.css', array(), $asset['version'] );
wp_style_add_data( 'fillaro-admin', 'rtl', 'replace' );
/**
* Filters the admin app's script dependencies. Add-ons add their own
* script here so its hooks run before the app renders.
*
* @param string[] $deps Script handles.
*/
$deps = (array) apply_filters( 'fillaro/admin_script_deps', $asset['dependencies'] );
wp_enqueue_script( 'fillaro-admin', FILLARO_URL . 'build/admin.js', $deps, $asset['version'], true );
wp_set_script_translations( 'fillaro-admin', 'fillaro' );
$pages = array();
foreach ( get_pages( array( 'number' => 300 ) ) as $page ) {
$pages[] = array(
'id' => $page->ID,
'title' => $page->post_title,
);
}
wp_add_inline_script(
'fillaro-admin',
'window.fillaroAdmin = ' . wp_json_encode(
/**
* Filters the data handed to the admin app.
*
* @param array $data Data.
*/
apply_filters(
'fillaro/admin_data',
array(
'version' => FILLARO_VERSION,
'presets' => Theme::presets(),
'themeDefaults' => Theme::defaults(),
'settingsDefaults' => FormSchema::default_settings(),
'adminUrl' => admin_url( 'admin.php?page=' . self::SLUG ),
// Not wp_nonce_url(): it HTML-escapes "&", which breaks a URL used from JavaScript.
'exportUrl' => add_query_arg(
array(
'action' => Exporter::ACTION,
'_wpnonce' => wp_create_nonce( Exporter::ACTION ),
),
admin_url( 'admin-post.php' )
),
'previewUrl' => home_url( '/?fillaro_preview=' ),
'adminEmail' => get_option( 'admin_email' ),
'pages' => $pages,
'userName' => wp_get_current_user()->display_name,
'pro' => false,
)
)
) . ';',
'before'
);
}
/**
* Body class for full-bleed layout.
*
* @param string $classes Classes.
* @return string
*/
public function body_class( $classes ) {
$screen = get_current_screen();
if ( $screen && $screen->id === $this->hook ) {
$classes .= ' fillaro-screen';
}
return $classes;
}
/**
* Links on the Plugins screen.
*
* @param array $links Links.
* @return array
*/
public function action_links( $links ) {
array_unshift(
$links,
sprintf( '%s', esc_url( admin_url( 'admin.php?page=' . self::SLUG ) ), esc_html__( 'Forms', 'fillaro' ) )
);
return $links;
}
/**
* Menu icon as a data URI.
*
* @return string
*/
private function icon() {
$svg = '';
return 'data:image/svg+xml;base64,' . base64_encode( $svg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Menu icon data URI.
}
}