WordPress Admin Notice Dismissal - php

I'm currently building a WordPress Plugin, and in this plugin I need a WordPress admin notification. I was able to create the admin notification, however when I dismiss it, on the next reload of the page it shows up again. How do I get this to not display once a user has dismissed it?
function admin_notice_eagle_daily() {
$displayVar = '<b>EAGLE Display Reminder:</b>'; ?>
<div class="notice notice-success is-dismissible">
<p><?php _e($displayVar, 'sample-eagle-text-domain'); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'admin_notice_daily' );

Related

How to make popup on the WooCommerce listing page

I am making a WooCommerce website where I want to have a pop-up when someone clicks on apply now button. There I want to have two fields 1) All the class(custom field) that product has. 2) Kids that the current logged in user has.
And there would be Add to Cart button which would add the item inside the cart.
I have successfully been able to get those on my product page. I am using toolset https://toolset.com to create my product listing page and single product page.
This is my code for a single product list (Template View)
<div class="school">
<div class="top">
<div class="image">
[types field="logo"][/types]
</div>
<div class="city">
<img src="link_to_img">
[types field="city"][/types]
</div>
</div>
<div class="middle">
<p>[wpv-post-title]</p>
</div>
<div class="bottom">
[wpv-post-read-more]
<button class="applynow" href="#">Apply Now</button>
</div>
</div>
Also this is the code to render those fields 1 & 2 in the popup. I am using this in my single product page.
function iconic_output_engraving_field() {
global $product;
$classes = get_post_meta($product->get_id(),'wpcf-classes-opened-for-admission',array('show_name' => 'true'));
print_r("<label>Select Class</label>");
print_r("<select name='class'>");
print_r("<option disabled selected value> -- Select a Class -- </option>");
foreach ($classes as $class) {
print_r( "<option value='".$class[0]."'>".$class[0]."</option>");
}
print_r("</select>");
$args = array(
'id' => 1538,
);
echo render_view( $args );
}
add_action( 'woocommerce_before_add_to_cart_button', 'iconic_output_engraving_field', 10 );
How can I pass the id through the button, so that I can create a template which loads up with correct data and Add to Cart button.
https://wordpress.org/plugins/easy-login-woocommerce/
This plugin does what you're looking for, BUT it uses wp_user_login or some other function that you would need to change.
Basically, download, check the code of the plugin, your answer should be there.
Plugin is to create a popup when a button is clicked, plugin uses it to login/register, but you could edit to do whatever.

How to alter css class once found in chrome console

Not sure how best to title this. I have a button that creates a modal popup for a job application form in WP Job Manager. I wish to duplicate this button on the same page which I have done, however my new button not only creates the modal but also loads the same application form on the page itself at the same time, this is not intended. The popup/modal is using Magnific Popup. Using Chrome console I found the issue that my new button is using a class without 'mfp-hide' at the end of it whereas the first button does have this.
By adding mfp-hide to the end of the class for that button in the Chrome console I solve the issue - the modal then loads correctly and the modal content does not load on the page. My issue is how/where to allocate a new class with mfp-hide at the end of it in my files. I am used to modifying class properties in child themes but not sure how to add this property/replace the class type. If you look here https://boolerang.co.uk/job/birch-creative-limited-permanent-full-stack-developer/ for example and right click inspect the top apply button then do the same with the lower apply button you can see the missing 'mfp-hide' on the lower. Clicking the lower button will show the problem.
In content-single-job_listing.php I added this to generate the second button:
<?php if ( candidates_can_apply() ) : ?>
<?php get_job_manager_template( 'job-application.php' ); ?>
<?php endif; ?>
job-application.php contains:
<?php if ( $apply = get_the_job_application_method() ) :
wp_enqueue_script( 'wp-job-manager-job-application' );
?>
<div class="job_application application">
<?php do_action( 'job_application_start', $apply ); ?>
<input type="button" class="application_button button" value="<?php
esc_attr_e( 'Apply for job', 'wp-job-manager' ); ?>" />
<div class="application_details">
<?php
/**
* job_manager_application_details_email or
job_manager_application_details_url hook
*/
do_action( 'job_manager_application_details_' . $apply->type,
$apply );
?>
</div>
<?php do_action( 'job_application_end', $apply ); ?>
</div>
<?php endif; ?>
The Chrome console for the original button shows:
<div class="application_details modal mfp-hide" id="apply-overlay"
style="display: block;">
<form class="job-manager-application-form job-manager-form" method="post"
enctype="multipart/form-data" action="https://boolerang.co.uk/job/birch-
creative-limited-permanent-full-stack-developer/">
I wish to change the class associated with the lower button to include the 'mfp-hide' which the Magnific Popup says is required in their documentation to have the desired effect. I don't know which file I need to alter to do this as it's not the button class which would be much easier. Any suggestions of where to edit to get this included would be much appreciated.

How to display user city and state, and profile picture in wordpress

I am making a custom profile page for the users on my WordPress site. I have been able to easily display the username of the logged in user. But I am running into a couple issues:
1) I am having a really hard time finding out how to display the logged in user's city and state. This information is stored in Dashboard/Users/'username' under the shipping address section.
2) I cannot figure out how to display the user's profile picture. From what I have read, user profile pictures are stored on Gravatar's servers...
I am displaying this on a left-sidebar...Here is my code so far for displaying the username
sidebar-profile.php
<div id="sidebar-profile" class="sidebar">
<div>
<h4>
<?php
$current_user = wp_get_current_user();
echo $current_user->user_login;
?>
</h4>
</div>
<?php dynamic_sidebar( 'profile' ); ?>
</div>
I have tried a few different things and all have failed to work.
Also, I am a novice web developer so there may be some errors with my approach to displaying these values.
You should be able to grab the users gravatar image with your above code like so:
<div id="sidebar-profile" class="sidebar">
<div>
<h4>
<?php
$current_user = wp_get_current_user();
echo $current_user->user_login;
echo get_avatar( $current_user->user_email, 32 );
?>
</h4>
</div>
<?php dynamic_sidebar( 'profile' ); ?>
</div>
This will display a <img> tag with the gravatar, there is also additional arguments you can use with the get_avatar() function to allow you to customize the output further: https://codex.wordpress.org/Function_Reference/get_avatar
I'm assuming for the city and state of the user you are using WooCommerce, if so then you should be able to grab this information from the users post meta:
$shippingCity = get_post_meta($current_user->ID, 'shipping_city', true);
$shippingState = get_post_meta($current_user->ID, 'shipping_state', true);

Wordpress error "You do not have sufficient permissions to access this page." on adding a theme option page

I am developing a theme setting page for my client. I want to add a theme options page to apply settings but I get Wordpress error "You do not have sufficient permissions to access this page. I think I am using the right code but problem still exists.
Please help me out in figuring where I am wrong
/*
* ADD THEME SETTINGS PAGE
*/
function vc_add_theme_settings_page(){
add_theme_page('Theme Settings','Theme Settings', 'manage_options' , 'vc_theme_page', 'vc_theme_page_display' );
}
add_action('admin_init', 'vc_add_theme_settings_page');
/*
* DISPLAY THEME SETTINGS PAGE
*/
function vc_theme_page_display(){
?>
<div class="wrap">
<h2>Vc Theme Settings Page</h2>
<form action="options.php" method="POST">
<?php settings_fields('vc_section'); ?>
<?php do_settings_sections('vc_theme_page'); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
Order your code at this way:
add_action('admin_menu', 'vc_add_theme_settings_pages');
add_action('admin_head', 'theme_styles');
add_action('admin_init', 'vc_add_theme_settings_page');
function vc_add_theme_settings_page(){
add_theme_page('Theme Settings','Theme Settings', 'edit_theme_options', 'manage_options', 'vc_theme_page_display' );
}
and try change
<?php do_settings_sections('vc_theme_page'); ?>
for
<?php do_settings_sections(__FILE__); ?>
add_action('admin_init', 'vc_add_theme_settings_page'); //instead of this
add_action('admin_menu', 'vc_add_theme_settings_page'); //try this
Hope it will work for you.

Wordpress Membership Plugin Conditional Statement

I have plugin by WPMU that creates a membership system for your wordpress theme. Im trying to make it display a gallery only when a user is a premium member and Im completely lost. My code basicly grabs part of the url and pastes it into variables in my susbscription div to draw the information needed. I need it to check if the user is logged in but Im not sure how to do that. Here is my code, Thanks:
<?php get_header(); ?>
<?php
$url = $_SERVER['REQUEST_URI'];
$url = rtrim($url, '/');
function drawId($url) {
return array_pop(explode('-', $url));
}
?>
<div class="main-container col2-right-layout">
<div class="main">
<p><?php echo drawId($url); ?></p>
<?php get_template_part('loop');?>
<div id="subscription">
<p><?php echo nggcf_get_gallery_field(drawId($url), "Gallery Text"); /* where 1 is the gallery id */ ?></p>
<?php echo do_shortcode('[nggallery id='.drawId($url).']');?>
</div>
</div><!-- .main -->
</div><!-- .main-container col2-right-layout -->
<?php get_footer(); ?>
The following is copied and pasted from the plugin's support forms:
you can try any of the following for your customization needs:
current_user_is_member()
current_user_on_level($level_id)
current_user_on_subscription($sub_id)
And of course, you can get the level_id and sub_id from the respective membership level and subscription lists.
if you want to check if a user is logged in, in wordpress, it is just a condition like this:
if(is_user_logged_in()){
//do you stuff
}
hope this help. read more here
This plugin allows only people that are logged in to your site to use the site:
http://wordpress.org/extend/plugins/private-wp/
Maybe by creating memberships though your admin panel you could target the the user in that way.

Categories