Restricting download buttons so only logged-in users can view the buttons - css

I am building a website (using Wordpress, Neve theme and Elementor Pro) with teaching resources for teachers, under the picture of each resource I want to place a download button with the URL link to download the resource, is it possible to make this download button with the link only accessible to logged-in users using Custom CSS or what would be the easiest way to do this?

In WordPress, you would probably have to use something like this:
.your-button {
display: none;
}
.logged-in .your-button {
display: block;
}
Please notice that the button is only visually hidden and could still be accessed via the dev tools.

It's not safe to use CSS, or anything on the frontend to hide the download button if it's important that for example students cannot get at the resources/answers.
In the backend you can add this where you are creating the button:
if ( is_user_logged_in() ) {
... the code outputting the download button and info ...
}

Related

How do i remove gravatar completely from wordpress?

Hi I'm trying to to remove gravatar completely for my website. I've already disabled gravatar on the discussion page setting of wordpress. However, I'm using a paywall plugin which uses gravatar (called memberful) and its account popup always shows the profile avatar regardless if its disabled or not on the discussion page.
Example:
I think the profile-window is actually an iframe...
To here: https://dylogue.memberful.com/account/subscriptions
Do you have access to this endpoint, or is it created by a script? Changing the general CSS wont help you if you do not have access to inserting css into this endpoint.
The stylesheets are in weird places:
https://d1zgk03a9fsd43.cloudfront.net/assets/reach/style-4556bac86321e164130eb81bc9c1bd3e8ad4f00e3a7f1b803ef1e7e272baf184.css
https://d1zgk03a9fsd43.cloudfront.net/packs/member-bafbfb186fc0b252fb994416a369b793.css
I didn't see the link to create an account and test this, but does this CSS work?
.memberful-account-header img {
display: none;
}
.memberful-account-header hgroup * {
margin-left: 0 !important;
}

OS detection to display different links on WordPress page

I would like for my WordPress post link to refer people to different pages depending on the OS that they are using. For example to download Mac version of software if they are browsing from MacOS.
I saw a tutorial on how to add user OS in function.php file, but i have no idea how to implement function on a specific WP page.
Based on that tutorial you don't need to change page link. On same page you can do that. Like section/button for Mac/windows.
Here how you can do:
Step1: Add the code on your functions.php then you will see on your website under body tag have a specific class if you are form Mac then "osx" or if you are from windows then "windows"
Step2: add class on you Mac section called "osxsection" & for windows section "windowssection"
Step3: Now do the css like this:
// to view the section on Mac
.osx .osxsection {
display: block !important;
}
.osxsection {
display: none;
}
// to view the section on Windows
.windows .windowssection {
display: block !important;
}
.windowssection {
display: none;
}
you can present that CSS code some different way also.
Try that hope it will help you :)

How to disable page's title in wp-admin from being edited?

I have a wp-network installed with users that can create pages in each site.
Each of those pages get a place in the primary menu, and only one user have permission to create all this menu.
I want to create a user only to be able to edit the content of the pages, but not the title.
How can I disable the title of the page to be edited from the admin menu for a specific user, or (far better) for a capability?
I thought only a possibility, that's editing admin css to hide the title textbox, but I have two problems:
I don't like to css-hide things.
I don't know where is the admin css.
I know php, but don't know how to add a css hide to an element for a capability.
You should definitely use CSS to hide the div#titlediv. You'll want the title to show in the markup so the form submission, validation, etc continues to operate smoothly.
Some elements you'll need to know to implement this solution:
current_user_can() is a boolean function that tests if the current logged in user has a capability or role.
You can add style in line via the admin_head action, or using wp_enqueue_style if you'd like to store it in a separate CSS file.
Here is a code snippet that will do the job, place it where you find fit, functions.php in your theme works. I'd put it inside a network activated plugin if you're using different themes in your network:
<?php
add_action('admin_head', 'maybe_modify_admin_css');
function maybe_modify_admin_css() {
if (current_user_can('specific_capability')) {
?>
<style>
div#titlediv {
display: none;
}
</style>
<?php
}
}
?>
I resolved the problem, just if someone comes here using a search engine, I post the solution.
Doing some research, I found the part of the code where the title textbox gets inserted, and I found a function to know if a user has a certain capability.
The file where the title textbox gets added is /wp-admin/edit-form-advanced.php. This is the line before the textbox
if ( post_type_supports($post_type, 'title') )
I changed it to this
if ( post_type_supports($post_type, 'title') and current_user_can('edit_title') )
That way, the textbox is only added when the user has the capability called "edit_title"
When this IF block ends few lines after, I added:
else echo "<h2>".esc_attr( htmlspecialchars( $post->post_title ) )."</h2>";
To see the page title but not to edit it, when the user hasn't got "edit_title" capability.
Then I had already installed a plugin to edit user capabilities and roles, wich help me to create a new capability (edit_title) and assign it to the role I want.

How to change default wordpress logout template?

I am new to wordpress development and now I am stuck.
I need to change style and add some buttons in default wordpress logout template (when i am redirected to http://example.com/wp-login.php?action=logout ).
But the question is where i can find that template?
Thanks in advance.
Regards.
Ivelin Georgiev
Right...
There (unfortunately) isn't a template page for the login page. I'm not sure why this is, maybe its for security or something, I dunno. In any case you can't edit it directly without messing with the wordpress core.
However there are various hooks and actions you can add to in order to do some customisations. Here is some sample code from my own applications:
// this adds stuff to the head. You can add a stylesheet
// if you want, or just css like I have.
add_action("login_head", "cust_login_head");
function cust_login_head()
{
// this just changes the logo
?>
<style>
body.login #login h1 a {
background: url('<?=plugins_url('images/logomed.png',__FILE__)?>') no-repeat scroll center top transparent;
height: 64px;
width: 307px;
margin-left: 10px;
}
</style>
<?php
}
// these change the default links from wordpress to whatever you want
add_filter('login_headertitle', create_function(false, "return 'http://website.com';"));
add_filter('login_headerurl', create_function(false, "return 'http://website.com';"));
Stick that into your functions.php file in your theme to get it to work.
There will be other such methods and hooks you can change and add to, you just need to find them.
Use Themed login plugin - It allows to make login and registration process themeable using site's theme.

How to have a text-only view of a WordPress website in addition to the fully themed view?

I have a client who is interested in having a text-only view of their website available to visitors with accessibility needs. This would be in addition to the usual, fully themed view.
I like what the Kennedy Center did for text-only view, www.kennedy-center.org/text. I like how it appears to the user as a subdirectory, but I am trying to figure out how to accomplish that in WordPress. Two themes? Subdirectory? Session cookie? Intercepting the URL and loading different stylesheets?
Any suggestions or any built-in capability that anyone can suggest?
Thanks...
...Allen
A very fast way to go is to set a cookie and a GET variable.
Basic example:
In function.php:
if (isset($_GET['text'])) {
setcookie("is_text", 'true', time()+60*60*24*365*10,"/");
}
In header.php:
if (isset($_COOKIE['is_text'])||isset($_GET['text'])) {
// text CSS stylesheet
} else {
// standard CSS stylesheet
}
So you can switch the view in every page just by adding ?text to your url.
Try to use Theme Switcher plugin.
See here for the demo: http://www.nkuttler.de/wordpress-plugin/theme-switch-and-preview-plugin/

Resources