'."\n"; } if ( $pagenow == "post.php" || ( isset( $_GET['post_type'] ) && $_GET['post_type'] == "newsletter" ) ) { //edit : added all this "$code" related lines $alo_em_cf = alo_easymail_get_custom_fields(); $code = ''; echo $code; wp_enqueue_script( 'json2' ); wp_enqueue_script( 'jquery', false, array( 'json2' ) ); wp_enqueue_script( 'thickbox' ); wp_enqueue_script( 'alo-easymail-smartupdater', ALO_EM_PLUGIN_URL . '/inc/smartupdater.js', array('jquery'), '3.2.00' ); //wp_enqueue_script( 'alo-easymail-backend-recipients-list', ALO_EM_PLUGIN_URL . '/inc/alo-easymail-backend-recipients-list.js' ); wp_enqueue_style( 'alo-easymail-backend-css', ALO_EM_PLUGIN_URL.'/inc/alo-easymail-backend.css' ); wp_enqueue_script ( 'jquery-ui-dialog' ); wp_enqueue_script ( 'jquery-ui-resizable' ); wp_enqueue_script ( 'jquery-ui-draggable' ); wp_enqueue_style ( 'wp-jquery-ui-dialog'); wp_enqueue_script( 'alo-easymail-backend', ALO_EM_PLUGIN_URL . '/inc/alo-easymail-backend.js', array( 'jquery' ) ); wp_localize_script( 'alo-easymail-backend', 'easymailJs', alo_em_localize_admin_script() ); } } add_action('admin_print_scripts', 'alo_em_add_admin_script' ); function alo_em_localize_admin_script () { global $post, $pagenow, $current_screen; $post_id = ( $post ) ? $post->ID : false; $screen_id = ( $current_screen ) ? $current_screen->id : false; return array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'pluginPath' => ALO_EM_PLUGIN_URL."/", 'postID' => $post_id, 'pagenow' => $pagenow, 'screenID' => $screen_id, 'reportPopupTitle' => esc_js( __("Newsletter report", "alo-easymail") ), 'subscribersPopupTitle' => esc_js( __("Newsletter subscribers creation", "alo-easymail") ), 'themePreviewUrl' => alo_easymail_get_themes_url(), 'nonce' => wp_create_nonce( 'alo-easymail' ), 'errGeneric' => esc_js( __("Error during operation.", "alo-easymail") ), 'errEmailNotValid' => esc_js( __("The e-email address is not correct", "alo-easymail") ), 'errNameIsBlank' => esc_js( __("The name field is empty", "alo-easymail") ), 'errEmailAlreadySubscribed'=> esc_js( __("There is already a subscriber with this e-email address", "alo-easymail") ), 'confirmDelSubscriber'=> esc_js( __("Do you really want to DELETE this subscriber?", "alo-easymail") ), 'confirmDelSubscriberAndUnsubscribe'=> esc_js( __("Do you really want to DELETE this subscriber?", "alo-easymail").' '. __("The email address will be added to the list of who unsubscribed", "alo-easymail") .": ". __("so you cannot add or import these email addresses using the tools in admin pages", "alo-easymail") ), 'txtClose' => esc_js( __("close", "alo-easymail") ), 'titleRecListModal' => esc_js( __( 'Create list of recipients', "alo-easymail") ), 'txt_success_added' => esc_js( __( 'Recipients successfully added', "alo-easymail" ) ), 'txt_success_sent' => esc_js( __( 'Newsletter successfully sent to recipients', "alo-easymail" ) ), ); } /** * Add CSS on Admin panel */ function alo_em_add_admin_styles () { global $post, $pagenow; if ( $pagenow == "post.php" || ( isset( $_GET['post_type'] ) && $_GET['post_type'] == "newsletter" ) ) { wp_enqueue_style( 'alo-easymail-backend-css', ALO_EM_PLUGIN_URL.'/inc/alo-easymail-backend.css' ); wp_enqueue_style( 'thickbox' ); } } add_action( "admin_print_styles", 'alo_em_add_admin_styles' ); /** * Add menu pages */ function alo_em_add_admin_menu() { if ( current_user_can('manage_newsletter_subscribers') ) { add_submenu_page( 'edit.php?post_type=newsletter', __("Subscribers", "alo-easymail"), __("Subscribers", "alo-easymail"), 'manage_newsletter_subscribers', 'alo-easymail/pages/alo-easymail-admin-subscribers.php' ); add_action( 'load-alo-easymail/pages/alo-easymail-admin-subscribers.php', 'alo_em_contextual_help_tabs' ); } if ( current_user_can('manage_newsletter_options') ) { add_submenu_page( 'edit.php?post_type=newsletter', __("Settings"), __("Settings"), 'manage_newsletter_options', 'alo-easymail/pages/alo-easymail-admin-options.php' ); add_action( 'load-alo-easymail/pages/alo-easymail-admin-options.php', 'alo_em_contextual_help_tabs' ); } add_action( 'load-edit.php', 'alo_em_contextual_help_tabs' ); add_action( 'load-post-new.php', 'alo_em_contextual_help_tabs' ); } add_action('admin_menu', 'alo_em_add_admin_menu'); /* * Add some links on the plugin page */ function alo_em_add_plugin_links($links, $file) { if ( $file == 'alo-easymail/alo-easymail.php' ) { $links[] = 'Guide'; $links[] = 'Faq'; $links[] = 'News'; $links[] = 'Forum'; } return $links; } add_filter( 'plugin_row_meta', 'alo_em_add_plugin_links', 10, 2 ); /** * Return data for Subscriber edit inline */ function alo_em_ajax_alo_easymail_subscriber_edit_inline () { check_ajax_referer( "alo-easymail" ); $subscriber = $_POST['subscriber']; $row_index = $_POST['row_index']; $inline_action = $_POST['inline_action']; if ( $subscriber && current_user_can( "manage_newsletter_subscribers" )) { $mailinglists = alo_em_get_mailinglists( 'admin,public' ); $languages = alo_em_get_all_languages ( true ); switch ( $inline_action ) { case 'save': // save data and return html row, red-only mode $subscriber_obj = alo_em_get_subscriber_by_id( $subscriber ); $_POST = array_map( 'strip_tags', $_POST ); $_POST = array_map( 'stripslashes_deep', $_POST ); $new_name = ( isset( $_POST['new_name'] ) ) ? trim ( $_POST['new_name'] ) : false ; $new_email = ( isset( $_POST['new_email'] ) && is_email( trim ( $_POST['new_email'] ) ) ) ? trim ( $_POST['new_email'] ) : false; $new_active = ( isset( $_POST['new_active'] ) && is_numeric( $_POST['new_active'] ) ) ? $_POST['new_active'] : 0; $new_lang = ( isset( $_POST['new_lang'] ) && in_array( $_POST['new_lang'], $languages) ) ? $_POST['new_lang'] : ""; $new_lists = ( isset( $_POST['new_lists'] ) ) ? trim( $_POST['new_lists'] ) : false; $fields = array(); // to be saved //edit : added the following foreach and its content $alo_em_cf = alo_easymail_get_custom_fields(); if ($alo_em_cf) { foreach( $alo_em_cf as $key => $value ){ $var_name = "new_".$key; //$fields[$key] = ( isset( $_POST[$var_name] ) ) ? stripslashes( trim ( $_POST[$var_name] ) ): false; //$fields[$key] = false; if ( !empty( $_POST[$var_name] ) ) { switch ( $value['input_type'] ) { case "checkbox": $fields[$key] = 1; break; default: $fields[$key] = sanitize_text_field( trim ( $_POST[$var_name] ) ); } } else { switch ( $value['input_type'] ) { case "checkbox": $fields[$key] = 0; break; default: $fields[$key] = false; } } } } /* if ( !$new_name ) { echo "-error-name-is-empty"; break; } */ // Check if a subscriber with this email already exists $already = ( alo_em_is_subscriber ( $new_email ) ) ? alo_em_is_subscriber ( $new_email ) : false; if ( $already && $already != $subscriber && $subscriber_obj->email != $new_email ) { echo "-error-email-already-subscribed"; break; // Last check before save } else if ( $new_email ) { //$fields['old_email'] = $subscriber_obj->email; //edit : added all this line $fields['email'] = $new_email; //edit : added all this line $fields['name'] = $new_name; //edit : added all this line alo_em_update_subscriber_by_email ( $subscriber_obj->email, $fields, $new_active, $new_lang, false ); //edit : orig : alo_em_update_subscriber_by_email ( $subscriber_obj->email, $new_email, $new_name, $new_active, $new_lang ); $new_lists = explode ( ",", rtrim ( $new_lists, "," ) ); if ( is_array( $mailinglists ) ) : foreach ( $mailinglists as $mailinglist => $val ) : if ( in_array ( $mailinglist, $new_lists ) ) { alo_em_add_subscriber_to_list ( $subscriber, $mailinglist ); } else { alo_em_delete_subscriber_from_list ( $subscriber, $mailinglist ); } endforeach; endif; echo alo_em_get_subscriber_table_row ( $subscriber, $row_index, false, $mailinglists, $languages ); } else { echo "-error-email-is-not-valid"; } break; case 'delete': // If required, add email in unsubscribed db table if ( isset($_POST['to_unsubscribe']) && $_POST['to_unsubscribe'] == 1 ) { $subscriber_obj = alo_em_get_subscriber_by_id( $subscriber ); alo_em_add_email_in_unsubscribed ( $subscriber_obj->email ); } // Delete the subscriber if ( alo_em_delete_subscriber_by_id ( $subscriber ) ) { echo "-ok-deleted"; break; } else { echo "-1"; // error break; } echo alo_em_get_subscriber_table_row ( $subscriber, $row_index, false, $mailinglists, $languages ); case 'cancel': // return html row, red-only mode echo alo_em_get_subscriber_table_row ( $subscriber, $row_index, false, $mailinglists, $languages ); break; case 'edit': default: // return html row, edit mode echo alo_em_get_subscriber_table_row ( $subscriber, $row_index, true, $mailinglists, $languages ); } } die(); } add_action('wp_ajax_alo_easymail_subscriber_edit_inline', 'alo_em_ajax_alo_easymail_subscriber_edit_inline'); /** * Add a dashboard widget */ function alo_em_dashboard_widget_function() { global $wpdb; echo "

". __("Newsletters scheduled for sending", "alo-easymail").": ". alo_em_count_newsletters_by_status( 'sendable' ) ."

"; $newsletter = alo_em_get_newsletters_in_queue( 1 ); if ( $newsletter ) { echo "

"; echo ''; echo " " . stripslashes ( alo_em___( $newsletter[0]->post_title ) ) ."
"; echo __("Progress", "alo-easymail") .": " . alo_em_newsletter_recipients_percentuage_already_sent( $newsletter[0]->ID ) . " %
" ; echo "".__("Added on", "alo-easymail") . " ". date_i18n( __( 'j M Y @ G:i', "alo-easymail" ), strtotime( $newsletter[0]->post_date ) ) . " - "; echo __("Scheduled by", "alo-easymail") . " ". get_user_meta($newsletter[0]->post_author, 'nickname',true). ""; echo "

"; } else { echo "

". __("There are no newsletters in queue", "alo-easymail") . ".

"; } echo "

". __("Subscribers", "alo-easymail") ."

"; list ( $total, $active, $noactive ) = alo_em_count_subscribers (); if ($total) { echo "

". sprintf( __("There are %d subscribers: %d activated, %d not activated", "alo-easymail"), $total, $active, $noactive ) . ".

"; } else { echo "

". __("No subscribers", "alo-easymail") . ".

"; } if ( current_user_can('administrator') ) { echo "
". __("Updates from plugin developer", "alo-easymail") ."
"; $rss = fetch_feed( 'http://www.eventualo.net/blog/category/alo-easymail-newsletter/feed/' ); if ( !is_wp_error( $rss ) ) { $maxitems = $rss->get_item_quantity( 3 ); $rss_items = $rss->get_items(0, $maxitems); echo "