/home/techb158/public_html/wp-content/plugins/optinmonster/OMAPI
Edit: /home/techb158/public_html/wp-content/plugins/optinmonster/OMAPI/Pages.php (18019B)
base = OMAPI::get_instance();
}
/**
* Setup any hooks.
*
* @since 2.0.0
*/
public function setup() {
add_filter( 'admin_title', array( $this, 'store_admin_title' ), 999999, 2 );
add_filter( 'admin_body_class', array( $this, 'admin_body_classes' ) );
}
/**
* Stores the admin title tag format to be used in JS.
*
* @since 2.0.0
*
* @param string $admin_title The admin title.
* @param string $title The title.
*
* @return string The admin title.
*/
public function store_admin_title( $admin_title, $title ) {
$this->title_tag = str_replace( $title, '{replaceme}', $admin_title );
return $admin_title;
}
/**
* Returns an array of our registered pages.
* If we need more pages, add them to this array
*
* @return array Array of page objects.
*/
public function get_registered_pages() {
if ( empty( $this->pages ) ) {
$bfcmitem = $this->should_show_bfcf_menu_item();
// Add BFCM item to pages array for redirect handling, but mark it to skip auto-registration
// since it's registered manually in Menu.php to control position.
if ( $bfcmitem ) {
$bfcmitem['skip_auto_register'] = true;
$this->pages['optin-monster-bfcm'] = $bfcmitem;
}
$this->pages['optin-monster-campaigns'] = array(
'name' => __( 'Campaigns', 'optin-monster-api' ),
'app' => true,
'callback' => array( $this, 'render_app_loading_page' ),
);
$this->pages['optin-monster-templates'] = array(
'name' => __( 'Templates', 'optin-monster-api' ),
'app' => true,
'callback' => array( $this, 'render_app_loading_page' ),
);
$this->pages['optin-monster-playbooks'] = array(
'name' => __( 'Playbooks', 'optin-monster-api' ),
'app' => true,
'callback' => array( $this, 'render_app_loading_page' ),
);
$this->pages['optin-monster-monsterleads'] = array(
'name' => __( 'Subscribers', 'optin-monster-api' ),
'app' => true,
'callback' => array( $this, 'render_app_loading_page' ),
);
$this->pages['optin-monster-integrations'] = array(
'name' => __( 'Integrations', 'optin-monster-api' ),
'app' => true,
'callback' => array( $this, 'render_app_loading_page' ),
);
$this->pages['optin-monster-trustpulse'] = array(
'name' => __( 'TrustPulse', 'optin-monster-api' ),
);
$this->pages['optin-monster-settings'] = array(
'name' => __( 'Settings', 'optin-monster-api' ),
'app' => true,
'callback' => array( $this, 'render_app_loading_page' ),
);
$this->pages['optin-monster-personalization'] = array(
'name' => __( 'Personalization', 'optin-monster-api' ),
'app' => true,
'callback' => array( $this, 'render_app_loading_page' ),
);
$this->pages['optin-monster-university'] = array(
'name' => __( 'University', 'optin-monster-api' ),
'app' => true,
'callback' => array( $this, 'render_app_loading_page' ),
);
$this->pages['optin-monster-about'] = array(
'name' => __( 'About Us', 'optin-monster-api' ),
'app' => true,
'callback' => array( $this, 'render_app_loading_page' ),
);
// If user upgradeable, add an upgrade link to menu.
if ( $this->base->can_show_upgrade() ) {
$this->pages['optin-monster-upgrade'] = array(
'name' => 'vbp_pro' === $this->base->get_level()
? esc_html__( 'Upgrade to Growth', 'optin-monster-api' )
: esc_html__( 'Upgrade to Pro', 'optin-monster-api' ),
'redirect' => esc_url_raw( OMAPI_Urls::upgrade( 'pluginMenu' ) ),
// Only highlight if we don't have a bfcm item to highlight.
'highlight' => ! $bfcmitem,
'callback' => '__return_null',
);
add_filter( 'om_add_inline_script', array( $this, 'add_upgrade_url_to_js' ), 10, 2 );
}
foreach ( $this->pages as $slug => $page ) {
$this->pages[ $slug ]['slug'] = $slug;
}
}
return $this->pages;
}
/**
* Should we show the Black Friday menu item.
*
* @since 2.11.0
*
* @return bool|array
*/
public function should_show_bfcf_menu_item() {
$timezone = new DateTimeZone( 'America/New_York' );
$now = new DateTime( 'now', $timezone );
$year = $now->format( 'Y' );
// Get Thanksgiving as a DateTime object in ET timezone with explicit year.
$thanksgiving = new DateTime( "fourth Thursday of November {$year}", $timezone );
// Create date objects by cloning and modifying in ET timezone.
$promo_start = clone $thanksgiving;
$promo_start->modify( '-3 days' )->setTime( 9, 0, 0 );
$bf_end = clone $thanksgiving;
$bf_end->modify( '+3 days' )->setTime( 23, 59, 59 );
$cm_start = clone $thanksgiving;
$cm_start->modify( '+4 days' )->setTime( 0, 0, 0 );
$cm_end = clone $thanksgiving;
$cm_end->modify( '+8 days' )->setTime( 23, 59, 59 );
// Check if we're in Black Friday window (Monday before Thanksgiving to Sunday after).
$is_bf_window = $now >= $promo_start && $now <= $bf_end;
// Check if we're in Cyber Monday window (Monday after BF to Friday).
$is_cm_window = $now >= $cm_start && $now <= $cm_end;
if ( $is_bf_window || $is_cm_window ) {
$url = OMAPI_Urls::marketing(
'pricing',
array(
'utm_medium' => 'pluginMenu',
'utm_campaign' => "BF{$year}",
)
);
if ( OMAPI_ApiKey::has_credentials() ) {
$url = OMAPI_Urls::upgrade(
'pluginMenu',
'',
'',
array(
'utm_campaign' => "BF{$year}",
'feature' => false,
)
);
}
return array(
'name' => esc_html__( 'BFCM 60% OFF!', 'optin-monster-api' ),
'alternate-name' => $is_cm_window
? esc_html__( 'Cyber Monday Sale!', 'optin-monster-api' )
: esc_html__( 'Black Friday Sale!', 'optin-monster-api' ),
'redirect' => esc_url_raw( $url ),
'callback' => '__return_null',
'highlight' => true,
'bfcm-highlight' => true,
);
}
$green_monday = strtotime( 'second Monday of December' );
$is_gm_window = OMAPI_Utils::date_within(
$now,
gmdate( 'Y-m-d 10:00:00', $green_monday ),
gmdate( 'Y-m-d 23:59:59', $green_monday )
);
if ( $is_gm_window ) {
$url = OMAPI_Urls::marketing(
'pricing-wp/',
array(
'utm_medium' => 'pluginMenu',
'utm_campaign' => "BF{$year}",
)
);
if ( OMAPI_ApiKey::has_credentials() && ! $this->base->is_lite_user() ) {
$url = OMAPI_Urls::upgrade(
'pluginMenu',
'',
'',
array(
'utm_campaign' => "BF{$year}",
'feature' => false,
)
);
}
return array(
'name' => esc_html__( 'Green Monday!', 'optin-monster-api' ),
'redirect' => esc_url_raw( $url ),
'callback' => '__return_null',
'highlight' => true,
);
}
return false;
}
/**
* Add the menu upgrade url to the data sento to the global JS file.
*
* @since 2.4.0
*
* @param array $data Array of data for JS.
* @param string $handle The script handle.
*
* @return $data Array of data for JS.
*/
public function add_upgrade_url_to_js( $data, $handle ) {
if ( $this->base->plugin_slug . '-global' === $handle ) {
$data['upgradeUrl'] = esc_url_raw( OMAPI_Urls::upgrade( 'pluginMenu' ) );
}
return $data;
}
/**
* Returns an array of our registered JS app pages.
*
* @return array Array of page objects.
*/
public function get_registered_app_pages() {
return wp_list_filter( $this->get_registered_pages(), array( 'app' => true ) );
}
/**
* Whether given page slug is one of our registered JS app pages.
*
* @param string $page_slug Page slug.
*
* @return boolean
*/
public function is_registered_app_page( $page_slug ) {
$pages = wp_list_pluck( $this->get_registered_app_pages(), 'slug' );
$pages[] = 'optin-monster-api-settings';
$pages[] = 'optin-monster-dashboard';
return in_array( $page_slug, $pages, true );
}
/**
* Registers our submenu pages
*
* @param string $parent_page_name The Parent Page Name.
*
* @return array Array of hook ids.
*/
public function register_submenu_pages( $parent_page_name ) {
$pages = $this->get_registered_pages();
$hooks = array();
foreach ( $pages as $page ) {
// Skip pages marked for manual registration.
if ( ! empty( $page['skip_auto_register'] ) ) {
continue;
}
if ( ! empty( $page['callback'] ) ) {
$parent_slug = $parent_page_name;
if ( ! empty( $page['hidden'] ) ) {
$parent_slug .= '-hidden';
}
$menu_title = ! empty( $page['menu'] ) ? $page['menu'] : $page['name'];
if ( $this->maybe_add_new_badge( $page ) ) {
$menu_title .= '