CommercePing.
*
* Every state-changing action is an admin-post handler that checks the
* manage_woocommerce capability and a nonce.
*
* @package OrderPing
*/
defined( 'ABSPATH' ) || exit;
/**
* Registers the menu and the admin-post handlers.
*/
function orderping_settings_register() {
add_action( 'admin_menu', 'orderping_settings_menu' );
add_action( 'admin_init', 'orderping_maybe_activation_redirect' );
add_filter( 'plugin_action_links_' . plugin_basename( ORDERPING_FILE ), 'orderping_plugin_action_links' );
add_action( 'admin_post_orderping_connect', 'orderping_handle_connect' );
add_action( 'admin_post_orderping_complete', 'orderping_handle_complete' );
add_action( 'admin_post_orderping_test_ping', 'orderping_handle_test_ping' );
add_action( 'admin_post_orderping_disconnect', 'orderping_handle_disconnect' );
add_action( 'admin_post_orderping_save_pilot', 'orderping_handle_save_pilot' );
add_action( 'admin_post_orderping_choose_plan', 'orderping_handle_choose_plan' );
orderping_whatsapp_register();
orderping_timing_settings_register();
add_action( 'admin_notices', 'orderping_update_required_notice' );
}
/**
* Activation hook helper: remembers which admin activated the plugin so they alone are sent to the
* settings page once. Network-wide activation is skipped.
*
* @param bool $network_wide Whether activated for the whole network.
*/
function orderping_flag_activation_redirect( $network_wide = false ) {
if ( $network_wide ) {
return;
}
set_transient( ORDERPING_TRANSIENT_ACTIVATED, get_current_user_id(), 60 );
}
/**
* One-time redirect to the settings page after activation. Skipped for bulk activation, AJAX,
* network admin and anyone other than the activating admin.
*/
function orderping_maybe_activation_redirect() {
$user_id = get_transient( ORDERPING_TRANSIENT_ACTIVATED );
if ( false === $user_id ) {
return;
}
if ( wp_doing_ajax() || is_network_admin() ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check for WordPress's own bulk flag.
if ( isset( $_GET['activate-multi'] ) ) {
delete_transient( ORDERPING_TRANSIENT_ACTIVATED );
return;
}
if ( (int) $user_id !== get_current_user_id() || ! current_user_can( 'manage_woocommerce' ) ) {
return;
}
delete_transient( ORDERPING_TRANSIENT_ACTIVATED );
wp_safe_redirect( admin_url( 'admin.php?page=orderping' ) );
exit;
}
/**
* Adds a Settings link first on the Plugins page row.
*
* @param array $links Existing action links.
* @return array
*/
function orderping_plugin_action_links( $links ) {
$settings = '' . esc_html__( 'Settings', 'commerceping' ) . '';
return array_merge( array( 'settings' => $settings ), (array) $links );
}
/**
* Dashboard URL derived from the backend base.
*
* @return string
*/
function orderping_dashboard_url() {
return orderping_backend_url() . '/external/dashboard';
}
/**
* Adds the page under WooCommerce.
*/
function orderping_settings_menu() {
$hook = add_submenu_page(
'woocommerce',
__( 'CommercePing', 'commerceping' ),
__( 'CommercePing', 'commerceping' ),
'manage_woocommerce',
'orderping', // Page slug stays as is: it is part of every settings URL (page=orderping) and the test rigs.
'orderping_settings_render'
);
if ( $hook ) {
add_action( 'admin_print_styles-' . $hook, 'orderping_settings_styles' );
}
}
/**
* Settings page styles, attached to a registered handle (no inline