Example #1
0
/**
 * External Menu Item Links
 */
function bnfw_menu_item_links()
{
    global $submenu;
    if (current_user_can('manage_options')) {
        $doc_url = 'https://betternotificationsforwp.com/documentation/';
        $store_url = 'https://betternotificationsforwp.com/store/';
        if (bnfw_is_tracking_allowed()) {
            $doc_url .= '?utm_source=WP%20Admin%20Submenu%20Item%20-%20"Documentation"&utm_medium=referral';
            $store_url .= '?utm_source=WP%20Admin%20Submenu%20Item%20-%20"Add-on"&utm_medium=referral';
        }
        // Documentation Link
        $submenu['edit.php?post_type=bnfw_notification'][500] = array('<div id="bnfw-menu-item-documentation" style="color: #73daeb;">Documentation</div>', 'manage_options', $doc_url);
        // Add-ons Link
        $submenu['edit.php?post_type=bnfw_notification'][600] = array('<div id="bnfw-menu-item-addons" style="color: #ff6f59;">Add-ons</div>', 'manage_options', $store_url);
    }
}
    /**
     * Render the settings meta box.
     *
     * @since 1.0
     *
     * @param WP_Post $post
     */
    public function render_settings_meta_box($post)
    {
        wp_nonce_field(self::POST_TYPE, self::POST_TYPE . '_nonce');
        $setting = $this->read_settings($post->ID);
        ?>
		<table class="form-table">
			<tbody>
			<tr valign="top">
				<th scope="row">
					<label for="notification"><?php 
        esc_html_e('Notification For', 'bnfw');
        ?>
</label>
				</th>
				<td>
					<select name="notification" id="notification" class="select2"
					        data-placeholder="Select the notification type" style="width:75%">
						<optgroup label="WordPress Defaults">
							<option
								value="new-comment" <?php 
        selected('new-comment', $setting['notification']);
        ?>
><?php 
        esc_html_e('New Comment / Awaiting Moderation', 'bnfw');
        ?>
</option>
							<option
								value="new-trackback" <?php 
        selected('new-trackback', $setting['notification']);
        ?>
><?php 
        esc_html_e('New Trackback', 'bnfw');
        ?>
</option>
							<option
								value="new-pingback" <?php 
        selected('new-pingback', $setting['notification']);
        ?>
><?php 
        esc_html_e('New Pingback', 'bnfw');
        ?>
</option>
							<option
								value="admin-password" <?php 
        selected('admin-password', $setting['notification']);
        ?>
><?php 
        esc_html_e('Lost Password - For Admin', 'bnfw');
        ?>
</option>
							<option
								value="admin-user" <?php 
        selected('admin-user', $setting['notification']);
        ?>
><?php 
        esc_html_e('New User Registration - For Admin', 'bnfw');
        ?>
</option>
							<option
								value="password-changed" <?php 
        selected('password-changed', $setting['notification']);
        ?>
><?php 
        esc_html_e('User Password Changed', 'bnfw');
        ?>
</option>
							<option
								value="email-changed" <?php 
        selected('email-changed', $setting['notification']);
        ?>
><?php 
        esc_html_e('User Email Changed', 'bnfw');
        ?>
</option>
							<option
								value="core-updated" <?php 
        selected('core-updated', $setting['notification']);
        ?>
><?php 
        esc_html_e('WordPress Core Automatic Background Updates', 'bnfw');
        ?>
</option>
						</optgroup>
						<optgroup label="Transactional">
							<option
								value="user-password" <?php 
        selected('user-password', $setting['notification']);
        ?>
><?php 
        esc_html_e('Lost Password - For User', 'bnfw');
        ?>
</option>
							<option
								value="new-user" <?php 
        selected('new-user', $setting['notification']);
        ?>
><?php 
        esc_html_e('New User Registration - For User', 'bnfw');
        ?>
</option>
							<option
								value="welcome-email" <?php 
        selected('welcome-email', $setting['notification']);
        ?>
><?php 
        esc_html_e('New User - Post-registration Email', 'bnfw');
        ?>
</option>
							<option
								value="admin-role" <?php 
        selected('admin-role', $setting['notification']);
        ?>
><?php 
        esc_html_e('User Role Changed - For Admin', 'bnfw');
        ?>
</option>
							<option
								value="user-role" <?php 
        selected('user-role', $setting['notification']);
        ?>
><?php 
        esc_html_e('User Role Changed - For User', 'bnfw');
        ?>
</option>
							<option
								value="reply-comment" <?php 
        selected('reply-comment', $setting['notification']);
        ?>
><?php 
        esc_html_e('Comment Reply', 'bnfw');
        ?>
</option>
						</optgroup>
						<optgroup label="Posts">
							<option
								value="new-post" <?php 
        selected('new-post', $setting['notification']);
        ?>
><?php 
        esc_html_e('New Post Published', 'bnfw');
        ?>
</option>
							<option
								value="update-post" <?php 
        selected('update-post', $setting['notification']);
        ?>
><?php 
        esc_html_e('Post Updated', 'bnfw');
        ?>
</option>
							<option
								value="pending-post" <?php 
        selected('pending-post', $setting['notification']);
        ?>
><?php 
        esc_html_e('Post Pending Review', 'bnfw');
        ?>
</option>
							<option
								value="private-post" <?php 
        selected('private-post', $setting['notification']);
        ?>
><?php 
        esc_html_e('New Private Post', 'bnfw');
        ?>
</option>
							<option
								value="future-post" <?php 
        selected('future-post', $setting['notification']);
        ?>
><?php 
        esc_html_e('Post Scheduled', 'bnfw');
        ?>
</option>
							<option
								value="newterm-category" <?php 
        selected('newterm-category', $setting['notification']);
        ?>
><?php 
        esc_html_e('New Category', 'bnfw');
        ?>
</option>
							<option
								value="newterm-post_tag" <?php 
        selected('newterm-post_tag', $setting['notification']);
        ?>
><?php 
        esc_html_e('New Tag', 'bnfw');
        ?>
</option>
							<?php 
        do_action('bnfw_after_notification_options', 'post', 'Post', $setting);
        ?>
						</optgroup>
						<optgroup label="Page">
							<option
								value="new-page" <?php 
        selected('new-page', $setting['notification']);
        ?>
><?php 
        esc_html_e('New Page Published', 'bnfw');
        ?>
</option>
							<option
								value="update-page" <?php 
        selected('update-page', $setting['notification']);
        ?>
><?php 
        esc_html_e('Page Updated', 'bnfw');
        ?>
</option>
							<option
								value="pending-page" <?php 
        selected('pending-page', $setting['notification']);
        ?>
><?php 
        esc_html_e('Page Pending Review', 'bnfw');
        ?>
</option>
							<option
								value="private-page" <?php 
        selected('private-page', $setting['notification']);
        ?>
><?php 
        esc_html_e('New Private Page', 'bnfw');
        ?>
</option>
							<option
								value="future-page" <?php 
        selected('future-page', $setting['notification']);
        ?>
><?php 
        esc_html_e('Page Scheduled', 'bnfw');
        ?>
</option>
							<option
								value="comment-page" <?php 
        selected('comment-page', $setting['notification']);
        ?>
><?php 
        esc_html_e('Page - New Comment', 'bnfw');
        ?>
</option>
							<option
								value="commentreply-page" <?php 
        selected('commentreply-page', $setting['notification']);
        ?>
><?php 
        esc_html_e('Page - Comment Reply', 'bnfw');
        ?>
</option>
							<?php 
        do_action('bnfw_after_notification_options', 'page', 'Page', $setting);
        ?>
						</optgroup>
						<?php 
        $types = get_post_types(array('public' => true, '_builtin' => false), 'names');
        foreach ($types as $type) {
            if ($type != self::POST_TYPE) {
                $post_obj = get_post_type_object($type);
                $label = $post_obj->labels->singular_name;
                ?>
								<optgroup
									label="<?php 
                esc_attr(printf("%s - '%s'", esc_html__('Custom Post Type', 'bnfw'), $label));
                ?>
">
									<option
										value="new-<?php 
                echo esc_attr($type);
                ?>
" <?php 
                selected('new-' . $type, $setting['notification']);
                ?>
><?php 
                echo esc_html__('New ', 'bnfw'), "'{$label}'";
                ?>
</option>
									<option
										value="update-<?php 
                echo esc_attr($type);
                ?>
" <?php 
                selected('update-' . $type, $setting['notification']);
                ?>
><?php 
                echo "'{$label}' " . esc_html__('Update ', 'bnfw');
                ?>
</option>
									<option
										value="pending-<?php 
                echo esc_attr($type);
                ?>
" <?php 
                selected('pending-' . $type, $setting['notification']);
                ?>
><?php 
                echo "'{$label}' ", esc_html__('Pending Review', 'bnfw');
                ?>
</option>
									<option
										value="private-<?php 
                echo esc_attr($type);
                ?>
" <?php 
                selected('private-' . $type, $setting['notification']);
                ?>
><?php 
                echo esc_html__('New Private ', 'bnfw'), "'{$label}'";
                ?>
</option>
									<option
										value="future-<?php 
                echo esc_attr($type);
                ?>
" <?php 
                selected('future-' . $type, $setting['notification']);
                ?>
><?php 
                echo "'{$label}' ", esc_html__('Scheduled', 'bnfw');
                ?>
</option>
									<option
										value="comment-<?php 
                echo esc_attr($type);
                ?>
" <?php 
                selected('comment-' . $type, $setting['notification']);
                ?>
><?php 
                echo "'{$label}' ", esc_html__('New Comment', 'bnfw');
                ?>
</option>
									<option
										value="commentreply-<?php 
                echo esc_attr($type);
                ?>
" <?php 
                selected('commentreply-' . $type, $setting['notification']);
                ?>
><?php 
                echo "'{$label}' ", esc_html__('Comment Reply', 'bnfw');
                ?>
</option>
									<?php 
                do_action('bnfw_after_notification_options', $type, $label, $setting);
                ?>
								</optgroup>
								<?php 
            }
        }
        $taxs = get_taxonomies(array('public' => true, '_builtin' => false), 'objects');
        if (count($taxs) > 0) {
            ?>
							<optgroup label="<?php 
            esc_html_e('Custom Taxonomy', 'bnfw');
            ?>
">
								<?php 
            foreach ($taxs as $tax) {
                $tax_name = 'newterm-' . $tax->name;
                ?>
									<option
										value="<?php 
                echo esc_attr($tax_name);
                ?>
" <?php 
                selected($tax_name, $setting['notification']);
                ?>
><?php 
                printf("%s '%s'", esc_html__('New', 'bnfw'), $tax->labels->name);
                ?>
</option>
									<?php 
            }
            ?>
							</optgroup>
							<?php 
        }
        ?>
					</select>
				</td>
			</tr>

			<?php 
        do_action('bnfw_after_notification_dropdown', $setting);
        ?>

			<tr valign="top" id="user-password-msg">
				<td>&nbsp;</td>
				<td>
					<div>
						<p style="margin-top: 0;"><?php 
        esc_html_e("This notification doesn't support additional email fields.", 'bnfw');
        ?>
</p>
					</div>
				</td>
			</tr>

			<tr valign="top" id="email-formatting">
				<th>
					<?php 
        esc_html_e('Email Formatting', 'bnfw');
        ?>
				</th>
				<td>
					<label style="margin-right: 20px;">
						<input type="radio" name="email-formatting"
						       value="html" <?php 
        checked('html', $setting['email-formatting']);
        ?>
>
						<?php 
        esc_html_e('HTML Formatting', 'bnfw');
        ?>
					</label>

					<label>
						<input type="radio" name="email-formatting"
						       value="text" <?php 
        checked('text', $setting['email-formatting']);
        ?>
>
						<?php 
        esc_html_e('Plain Text', 'bnfw');
        ?>
					</label>
				</td>
			</tr>

			<tr valign="top" id="toggle-fields">
				<th>
					<?php 
        esc_html_e('Additional Email Fields', 'bnfw');
        ?>
				</th>
				<td>
					<input type="checkbox" id="show-fields" name="show-fields"
					       value="true" <?php 
        checked($setting['show-fields'], 'true', true);
        ?>
>
					<label for="show-fields"><?php 
        esc_html_e('Set "From" Name & Email, Reply To, CC, BCC', 'bnfw');
        ?>
</label>
				</td>
			</tr>

			<tr valign="top" id="email">
				<th scope="row">
					<?php 
        esc_html_e('From Name and Email', 'bnfw');
        ?>
				</th>
				<td>
					<input type="text" name="from-name" value="<?php 
        echo esc_attr($setting['from-name']);
        ?>
"
					       placeholder="Site Name" style="width: 37.35%">
					<input type="email" name="from-email" value="<?php 
        echo esc_attr($setting['from-email']);
        ?>
"
					       placeholder="Admin Email" style="width: 37.3%">
				</td>
			</tr>

			<tr valign="top" id="reply">
				<th scope="row">
					<?php 
        esc_html_e('Reply To', 'bnfw');
        ?>
				</th>
				<td>
					<input type="text" name="reply-name" value="<?php 
        echo esc_attr($setting['reply-name']);
        ?>
"
					       placeholder="Name" style="width: 37.35%">
					<input type="email" name="reply-email" value="<?php 
        echo esc_attr($setting['reply-email']);
        ?>
"
					       placeholder="Email" style="width: 37.3%">
				</td>
			</tr>

			<tr valign="top" id="cc">
				<th scope="row">
					<?php 
        esc_html_e('CC', 'bnfw');
        ?>
				</th>

				<td>
					<select multiple name="cc[]" class="<?php 
        echo sanitize_html_class(bnfw_get_user_select_class());
        ?>
"
					        data-placeholder="Select User Roles / Users" style="width:75%">
						<?php 
        bnfw_render_users_dropdown($setting['cc']);
        ?>
					</select>
				</td>
			</tr>

			<tr valign="top" id="bcc">
				<th scope="row">
					<?php 
        esc_html_e('BCC', 'bnfw');
        ?>
				</th>

				<td>
					<select multiple name="bcc[]" class="<?php 
        echo sanitize_html_class(bnfw_get_user_select_class());
        ?>
"
					        data-placeholder="Select User Roles / Users" style="width:75%">
						<?php 
        bnfw_render_users_dropdown($setting['bcc']);
        ?>
					</select>
				</td>
			</tr>

			<tr valign="top" id="post-author">
				<th></th>
				<td>
					<label>
						<input type="checkbox" id="only-post-author" name="only-post-author"
						       value="true" <?php 
        checked('true', $setting['only-post-author']);
        ?>
>
						<?php 
        esc_html_e('Send this notification to the Author only', 'bnfw');
        ?>
					</label>
				</td>
			</tr>

            <tr valign="top" id="current-user">
                <th></th>
                <td>
                    <label>
                        <input type="checkbox" name="disable-current-user"
                               value="true" <?php 
        checked('true', $setting['disable-current-user']);
        ?>
>
						<?php 
        esc_html_e('Do not send this Notification to the User that triggered it', 'bnfw');
        ?>
                    </label>
                </td>
            </tr>

			<tr valign="top" id="users">
				<th scope="row">
					<?php 
        esc_html_e('Send To', 'bnfw');
        ?>
				</th>
				<td>
					<select multiple id="users-select" name="users[]"
					        class="<?php 
        echo sanitize_html_class(bnfw_get_user_select_class());
        ?>
"
					        data-placeholder="Select User Roles / Users" style="width:75%">
						<?php 
        bnfw_render_users_dropdown($setting['users']);
        ?>
					</select>
				</td>
			</tr>

			<tr valign="top">
				<th scope="row">
					<?php 
        esc_html_e('Subject', 'bnfw');
        ?>
				</th>
				<td>
					<input type="text" name="subject" value="<?php 
        echo esc_attr($setting['subject']);
        ?>
"
					       style="width:75%;">
				</td>
			</tr>

			<tr valign="top">
				<th scope="row">
					<?php 
        esc_html_e('Message Body', 'bnfw');
        ?>
					<div class="wp-ui-text-highlight">
						<p>
							<br/>
							<span
								class="dashicons dashicons-editor-help"></span> <?php 
        esc_html_e('Need some help?', 'bnfw');
        ?>
						</p>
						<?php 
        $doc_url = 'https://betternotificationsforwp.com/documentation/';
        if (bnfw_is_tracking_allowed()) {
            $doc_url .= "?utm_source=WP%20Admin%20Notification%20Editor%20-%20'Documentation'&amp;utm_medium=referral";
        }
        ?>
						<p>
							<a href="<?php 
        echo $doc_url;
        ?>
"
							   target="_blank" class="button-secondary"><?php 
        esc_html_e('Documentation', 'bnfw');
        ?>
</a>
						</p>
						<p>
							<a href="" target="_blank" id="shortcode-help"
							   class="button-secondary"><?php 
        esc_html_e('Shortcode Help', 'bnfw');
        ?>
</a>
						</p>
					</div>
				</th>
				<td>
					<?php 
        wp_editor($setting['message'], 'notification_message', array('media_buttons' => true));
        ?>
					<p> &nbsp; </p>
					<div id="disable-autop">
						<label>
							<input type="checkbox" name="disable-autop"
							       value="true" <?php 
        checked('true', $setting['disable-autop']);
        ?>
>
							<?php 
        esc_html_e('Stop additional paragraph and line break HTML from being inserted into my notifications', 'bnfw');
        ?>
						</label>
					</div>
				</td>
			</tr>

			</tbody>
		</table>
		<?php 
    }