pluginName = $pluginName; $this->version = $version; add_action( 'wp_ajax_wcSearchProducts', [ $this, 'ajaxWcSearchProducts' ] ); add_action( 'wp_ajax_add_wc_condition_group', [ $this, 'ajaxAddWcConditionGroup' ] ); add_action( 'wp_ajax_add_wc_condition', [ $this, 'ajaxAddWcCondition' ] ); add_action( 'wp_ajax_load_wc_condition', [ $this, 'ajaxLoadWcCondition' ] ); add_action( 'admin_init', [ $this, 'activateCampaign' ] ); add_action( 'admin_init', [ $this, 'deactivateCampaign' ] ); add_action( 'admin_init', [ $this, 'resetEvergreenCampaign' ] ); add_action( 'admin_init', [ $this, 'resetAllEvergreenCampaigns' ] ); add_action( 'admin_init', [ $this, 'pluginSettings' ] ); add_filter( 'post_row_actions', [ $this, 'campaignsListRowActions' ] ); add_action( 'admin_menu', [ $this, 'menu' ] ); add_filter( 'bulk_actions-edit-' . HURRYT_POST_TYPE, [ $this, 'campaignsListBulkActions', ] ); add_filter( 'manage_' . HURRYT_POST_TYPE . '_posts_columns', [ $this, 'campaignsListColumns', ] ); add_action( 'manage_' . HURRYT_POST_TYPE . '_posts_custom_column', [ $this, 'countdownListColumnsContent' ], 10, 2 ); add_filter( 'bulk_post_updated_messages', [ $this, 'customBulkPostUpdatedMessages' ], 10, 2 ); add_action( 'admin_menu', [ $this, 'helpTabs' ] ); add_action( 'admin_notices', [ $this, 'resetEvergreenCampaignNotice' ] ); add_action( 'admin_notices', [ $this, 'resetAllEvergreenCampaignNotice' ] ); add_action( 'admin_notices', [ $this, 'countdown_activation_notice' ] ); add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] ); //removeIf(pro) add_filter( 'plugin_action_links_' . HURRYT_BASENAME, [ $this, 'pluginLinks', ] ); //endRemoveIf(pro) } public function admin_footer_text() { $screen = get_current_screen(); if ( $screen->post_type === HURRYT_POST_TYPE ) { include HURRYT_DIR . 'admin/templates/footer-rate-plugin.php'; } } //removeIf(pro) public function pluginLinks( $links ) { $links[] = 'Go Pro'; return $links; } //endRemoveIf(pro) public function countdown_activation_notice() { $post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); $status = filter_input( INPUT_GET, 'hurrytimer_action' ); if ( ! $post_id || ! $status || ! ( $post = get_post( $post_id ) ) ) { return; } if ( $status === "activate-compaign" && ! Utils\Helpers::isPostActive( $post_id ) ) { ?>
[hurrytimer id="' .
$post_id .
'"]';
break;
}
}
public function campaignsListBulkActions( $actions )
{
unset( $actions[ 'edit' ] );
return $actions;
}
public function campaignsListColumns( $columns )
{
$allowed_columns = [];
foreach ( $columns as $column_name => $value ) {
if ( in_array( $column_name, [ 'cb', 'title', 'date' ] ) ) {
$allowed_columns[ $column_name ] = $value;
}
}
$columns = $allowed_columns;
$date = $columns[ 'date' ];
unset( $columns[ 'date' ] );
$columns = array_merge( $columns, [
'status' => __( 'Status', "hurrytimer" ),
'mode' => __( 'Mode', "hurrytimer" ),
'CampaignShortcode' => __( 'CampaignShortcode', "hurrytimer" ),
] );
$columns[ 'date' ] = $date;
return $columns;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueueStyles()
{
$version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : $this->version;
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'iris' );
wp_dequeue_style( 'select2' );
wp_enqueue_style(
"codemirror",
HURRYT_URL . 'assets/css/codemirror.css',
[],
"5.42.2",
'all'
);
wp_enqueue_style(
'hurryt-select2',
HURRYT_URL . 'assets/css/select2.css',
array(),
'4.0.5',
'all'
);
wp_enqueue_style(
'hurryt-base-css',
HURRYT_URL . 'assets/css/base.css',
array(),
$version,
'all'
);
wp_enqueue_style(
$this->pluginName,
HURRYT_URL . 'assets/css/admin.css',
[ 'hurryt-base-css', 'hurryt-select2' ],
$version,
'all'
);
}
public function campaignsListRowActions( $actions )
{
global $post;
if ( $post->post_type === HURRYT_POST_TYPE ) {
unset( $actions[ 'inline hide-if-no-js' ] );
}
return $actions;
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueueScripts()
{
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-tooltip' );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'iris' );
wp_enqueue_script( 'jquery-ui-slider' );
wp_dequeue_script( 'select2' );
wp_enqueue_script(
'hurryt-cookie',
HURRYT_URL . 'assets/js/cookie.min.js',
[],
'2.2.0',
true
);
//removeIf(pro)
wp_enqueue_script(
"jq-modal",
HURRYT_URL . 'assets/js/jquery.modal.min.js',
[ 'jquery' ],
"0.9.1",
true
);
//endRemoveIf(pro)
wp_enqueue_script(
'jq-date-picker-addon',
HURRYT_URL . 'assets/js/timepicker-addon.js',
[ 'jquery-ui-datepicker' ],
'1.6.3',
true
);
wp_enqueue_script(
'hurryt-select2',
HURRYT_URL . 'assets/js/select2.min.js',
[ 'jquery' ],
'4.0.5',
true
);
$deps = [ 'hurryt-cookie', 'jq-date-picker-addon', 'hurryt-select2' ];
wp_enqueue_script(
$this->pluginName,
HURRYT_URL . 'assets/js/admin.js',
$deps,
$this->version,
true
);
wp_localize_script( $this->pluginName, 'hurrytimer_ajax_object', array(
'ajax_nonce' => wp_create_nonce( 'hurryt-admin' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'headline_pos' => [
'above_timer' => C::HEADLINE_POSITION_ABOVE_TIMER,
'below_timer' => C::HEADLINE_POSITION_BELOW_TIMER,
],
'mode' => [
'evergreen' => C::MODE_EVERGREEN,
'regular' => C::MODE_REGULAR,
'recurring' => C::MODE_RECURRING,
],
'browser_tz_offset' => Carbon::now( hurryt_tz() )->getOffset() / 60,
) );
}
public function menu()
{
add_menu_page(
'HurryTimer',
'HurryTimer',
'manage_options',
'hurrytimer',
null,
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94P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40MSwwLDAsMCwyMCw1MGwxMy43LTE0LjQ5LDUsMy45NGEyLjQxLDIuNDEsMCwwLDAsMy4zLS4zMUw2OS41Niw3LjgxbC0xMiwuMzJhMi40MSwyLjQxLDAsMCwwLC4xMyw0LjgyWiIgc3R5bGU9ImZpbGw6IHVybCgjYzk5ODViMWMtYjg3Zi00M2Y1LWFiMzItNWE4ZWZiMzQ1ZDA1KSIvPiAgICAgIDwvZz4gICAgPC9nPiAgPC9nPjwvc3ZnPg==',
$this->get_menu_position( 55, 0.3 )
);
add_submenu_page(
'hurrytimer',
__( 'Add Campaign', 'hurrytimer' ),
__( 'Add Campaign', 'hurrytimer' ),
'manage_options',
'post-new.php?post_type=hurrytimer_countdown'
);
add_submenu_page(
'hurrytimer',
__( 'Settings', 'hurrytimer' ),
__( 'Settings', 'hurrytimer' ),
'manage_options',
'hurrytimer_settings',
[ $this, 'settings' ]
);
}
private function get_menu_position( $start, $increment = 0.3 )
{
$menus_positions = [];
foreach ( $GLOBALS[ 'menu' ] as $key => $menu ) {
$menus_positions[] = $key;
}
if ( ! in_array( $start, $menus_positions ) ) {
return $start;
}
/* the position is already reserved find the closet one */
while ( in_array( $start, $menus_positions ) ) {
$start += $increment;
}
return $start;
}
public function settings()
{
include_once HURRYT_DIR . 'admin/templates/settings.php';
}
public function activateCampaign()
{
if (
isset( $_GET[ 'hurrytimer_action' ] )
&& $_GET[ 'hurrytimer_action' ] === "activate-compaign"
&& isset( $_GET[ '_wpnonce' ] )
&& wp_verify_nonce( $_GET[ '_wpnonce' ], 'activate-compaign' )
) {
$postId = intval( $_GET[ 'post' ] );
wp_update_post( [ 'ID' => $postId, 'post_status' => 'publish' ] );
}
}
function resetEvergreenCampaignNotice()
{
if (
isset( $_GET[ 'hurryt-action' ] )
&& isset( $_GET[ 'hurryt-scope' ] )
&& isset( $_GET[ 'post' ] )
&& $_GET[ 'hurryt-action' ] === "reset-evergreen-compaign"
&& isset( $_GET[ '_wpnonce' ] )
&& wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-evergreen-compaign' )
) {
$scopeText
= $_GET[ 'hurryt-scope' ] === 'admin'
? ' you '
: ' all visitors '; ?>
Don't run actions when editing or previewing a page in the admin area.