RUNLINE_PAGE ); if ( $bar ) { $args['bar'] = $bar; } return add_query_arg( $args, admin_url( 'admin.php' ) ); } /** * The classic screens of the post type lead to the app. */ function runline_redirect_classic_screens() { global $typenow; $type = $typenow; $bar = 0; // phpcs:disable WordPress.Security.NonceVerification.Recommended -- only reads where to go. if ( isset( $_GET['post'] ) ) { $bar = absint( $_GET['post'] ); $type = get_post_type( $bar ); } elseif ( isset( $_GET['post_type'] ) ) { $type = sanitize_key( $_GET['post_type'] ); } // phpcs:enable if ( RUNLINE_POST_TYPE !== $type ) { return; } if ( 'post-new.php' === $GLOBALS['pagenow'] ) { $bar = 'new'; } wp_safe_redirect( runline_admin_url( $bar ) ); exit; } add_action( 'load-edit.php', 'runline_redirect_classic_screens' ); add_action( 'load-post.php', 'runline_redirect_classic_screens' ); add_action( 'load-post-new.php', 'runline_redirect_classic_screens' ); /** * Public post types for the display rules: name => label. */ function runline_admin_post_types() { $types = array(); foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $type ) { if ( 'attachment' !== $type->name ) { $types[ $type->name ] = $type->labels->name; } } return $types; } function runline_app_page() { echo '

' . esc_html__( 'Loading…', 'runline' ) . '

'; } add_action( 'admin_enqueue_scripts', function ( $hook ) { if ( 'toplevel_page_' . RUNLINE_PAGE !== $hook ) { return; } $asset_file = RUNLINE_DIR . 'build/index.asset.php'; if ( ! file_exists( $asset_file ) ) { return; } $asset = require $asset_file; // The bar itself (CSS + runline.js) for the live preview. runline_register_assets(); wp_enqueue_style( 'runline' ); wp_enqueue_media(); wp_enqueue_script( 'runline-admin', RUNLINE_URL . 'build/index.js', array_merge( $asset['dependencies'], array( 'runline' ) ), $asset['version'], true ); wp_enqueue_style( 'runline-admin', RUNLINE_URL . 'build/style-index.css', array( 'wp-components' ), $asset['version'] ); wp_style_add_data( 'runline-admin', 'rtl', 'replace' ); wp_set_script_translations( 'runline-admin', 'runline', RUNLINE_DIR . 'languages' ); $choices = array(); foreach ( array( 'direction', 'font', 'font_weight', 'position', 'width', 'align', 'cd_place', 'cd_after', 'cd_source', 'mode', 'style', 'source', 'products', 'mobile_layout', 'buyer_name' ) as $key ) { foreach ( runline_choices( $key ) as $value => $label ) { $choices[ $key ][] = array( 'value' => (string) $value, 'label' => $label, ); } } wp_add_inline_script( 'runline-admin', 'window.runlineAdmin = ' . wp_json_encode( array( 'defaults' => runline_default_settings(), 'choices' => $choices, 'fonts' => runline_font_stacks(), 'maxItems' => runline_max_items(), 'ruleTypes' => runline_rules_types(), 'ruleGroups' => runline_rules_groups(), 'postTypes' => runline_admin_post_types(), 'roles' => wp_roles()->get_names(), 'languages' => runline_rules_languages(), 'timezone' => wp_timezone_string(), 'tzOffset' => (int) ( wp_timezone()->getOffset( new DateTime( 'now', wp_timezone() ) ) / 60 ), 'daysFormat' => runline_countdown_days_format(), 'vars' => runline_text_vars(), 'shipping' => array( 'auto' => runline_free_shipping_threshold( runline_default_settings() ), 'fmt' => runline_price_format(), ), 'woo' => class_exists( 'WooCommerce' ), 'stats' => runline_stats_on(), 'homeUrl' => home_url( '/' ), 'adminUrl' => runline_admin_url(), 'settingsUrl' => admin_url( 'admin.php?page=runline-settings' ), 'designs' => runline_designs(), 'categories' => runline_design_categories(), 'lookKeys' => RUNLINE_LOOK_KEYS, 'dayslot' => function_exists( 'runline_dayslot_hint' ) && runline_dayslot_hint() ? RUNLINE_DAYSLOT_URL : '', ) ) . ';', 'before' ); // The list of bars comes with the page, so it shows without waiting. $preload = array_reduce( array( '/' . RUNLINE_REST_NS . '/bars' ), 'rest_preload_api_request', array() ); wp_add_inline_script( 'wp-api-fetch', 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( ' . wp_json_encode( $preload ) . ' ) );', 'after' ); } ); /** * Settings page: things for the whole plugin. */ add_action( 'admin_init', function () { register_setting( 'runline', 'runline_options', array( 'type' => 'array', 'sanitize_callback' => function ( $value ) { return array( 'delete_data' => ! empty( $value['delete_data'] ), 'one_per_place' => ! empty( $value['one_per_place'] ), 'push_header' => ! empty( $value['push_header'] ), 'stats' => ! empty( $value['stats'] ), 'mailchimp_key' => isset( $value['mailchimp_key'] ) ? sanitize_text_field( $value['mailchimp_key'] ) : '', 'mailerlite_key' => isset( $value['mailerlite_key'] ) ? sanitize_text_field( $value['mailerlite_key'] ) : '', 'brevo_key' => isset( $value['brevo_key'] ) ? sanitize_text_field( $value['brevo_key'] ) : '', 'language' => isset( $value['language'] ) && isset( runline_languages()[ $value['language'] ] ) ? $value['language'] : '', ); }, 'default' => array( 'delete_data' => false, 'one_per_place' => false, 'push_header' => false, 'stats' => true, ), ) ); } ); function runline_settings_page() { $options = runline_options(); ?>