graphicscove
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Configuring staging or developement environmentdefine('WP_ENV', 'development'); // Change to 'staging' or 'production' as needed
Add this to your config.php file (You should have a different one for each environment).
Forum: Fixing WordPress
In reply to: Blocking a website from certain countriesYou can block a country by using cloudflare with your domain, but someone can still access your site with a proxy, vpn or similar which might be something to keep in mind.
Forum: Developing with WordPress
In reply to: prevent the publication of posts with the default categorySorry, I don’t have a WordPress instance loaded up to test at the moment. Perhaps this might work for you:
function prevent_affitti_category_publish($data, $postarr) {
$default_category_slug = 'affitti'; // Your default category slug
$default_category = get_term_by('slug', $default_category_slug, 'category');
if (has_term($default_category->term_id, 'category', $postarr['ID'])) {
wp_die('Error: Posts cannot be published with the default "affitti" category.');
}
return $data;
}
add_filter('wp_insert_post_data', 'prevent_affitti_category_publish', 10, 2);To remove existing posts from the category you’ll need to updated them all on the posts listing in the CMS.
Forum: Developing with WordPress
In reply to: prevent the publication of posts with the default categoryOh right, you didn’t mention you changed the default category name. Try this:
function prevent_default_category_publish($data, $postarr) {
$default_category = 'affitti';
if (has_term($default_category, 'category', $postarr['ID'])) {
wp_die('Error: Posts cannot be published with the default category.');
}
return $data;
}
add_filter('wp_insert_post_data', 'prevent_default_category_publish', 10, 2);You could use this for blocking admin activity during the night, just adjust the times as needed:
function restrict_admin_activity_time() {
$current_hour = current_time('H');
if ($current_hour >= 0 && $current_hour < 6) { // Set the time range (00:00 - 06:00 in this example)
wp_die('Admin activity is restricted during these hours.');
}
}
add_action('admin_init', 'restrict_admin_activity_time');Hopefully that helps, let me know if you require anything else!
Forum: Developing with WordPress
In reply to: create page to display files in a folder based on userSorry, I’m a technical developer. Perhaps you might be able to find a plugin that does similar to avoid having to code, but unfortunately I don’t know of any off the top of my head.
Forum: Developing with WordPress
In reply to: prevent the publication of posts with the default categoryI’m not sure about the “Really Simple Security” plugin posting on its own. It’s possible that your site could have been compromised through other means.
To help prevent uncategorized (default category) posts from being published, you can create a custom function to block this. You can add the following code to your theme’s
functions.php
file:function prevent_default_category_publish($data, $postarr) {
if (in_category('uncategorized', $postarr['ID'])) {
wp_die('Error: Posts cannot be published with the default category.');
}
return $data;
}
add_filter('wp_insert_post_data', 'prevent_default_category_publish', 10, 2);This will stop posts from being published if they’re in the “Uncategorized” category. However, I’d also recommend checking for any vulnerabilities on your site. Update all plugins and themes, and ensure you’re using strong passwords for all accounts, especially admin ones. You might also want to review your site’s access logs for unusual activity.
For added security, consider a plugin like Wordfence or Sucuri to monitor any further suspicious behavior. It might be a good idea to reinstall or verify the integrity of your security plugin as well.
Forum: Developing with WordPress
In reply to: create page to display files in a folder based on userYou’ll need to add the code above to your theme, preferably on a new page template, and then set a page to use that page template.
It sounds like you’re not technical so you might need someone to help build that page into your theme for you as you can’t just copy the above code to a new template file without knowing a bit of PHP.Forum: Fixing WordPress
In reply to: Help Disabling “Services” Archive Page and Editing CPT SEO TitlesThe reason you’re seeing the archive page at
/services/
is that the custom post type “Services” likely has an archive enabled by default, and WordPress is automatically displaying it. To disable the archive, you would need to find where the CPT is registered (most likely in the theme’sfunctions.php
or a related file) and ensure the'has_archive' => false
argument is set when the custom post type is registered.
If you want to keep the archive but modify the SEO titles and descriptions, you can use a plugin like Yoast SEO or Rank Math, which allows you to customize the SEO settings for archives, including CPT archives like “Services.” This should override the default “Services Archive” title and let you input your own custom SEO data.If you prefer not to disable the archive but still want to display your custom page at
/services/
, you could try setting up a redirect from the archive to your custom page using a plugin like Redirection. That way, anyone who visits/services/
will be redirected to your edited page.Hope this helps! Let me know if you need further clarification or run into any issues.
Forum: Developing with WordPress
In reply to: create page to display files in a folder based on userTo create a page that displays files based on the logged-in user, you can try the following –
// Get the current user
$current_user = wp_get_current_user();
$user_folder = $current_user->user_login; // Assuming the folder is named after the username
// Then use the following to get the user files from the folder
$directory = wp_upload_dir()['basedir'] . '/your-upload-folder/' . $user_folder;
$files = scandir($directory);
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
echo '<a href="' . wp_upload_dir()['baseurl'] . '/your-upload-folder/' . $user_folder . '/' . $file . '">' . $file . '</a><br>';
}
}You could then add a form/button next to each result to trigger the delete functionality, but you’ll need to be aware of permissions! Let me know if you need a hand with some demo code for deleting as well.
Forum: Developing with WordPress
In reply to: Show Hide post information Based on term Click@amitsksingh Appologies, I’m typing this without having WordPress set up to test at the moment.
Could you try this instead?<div class="acf-field-container">
<script>
document.addEventListener('DOMContentLoaded', function() {
const selectedTerm = localStorage.getItem('selectedTerm');
if (selectedTerm === 'business-banking') {
document.querySelector('.acf-field-container').innerHTML =<?php the_field('banking_field'); ?>
;
} else if (selectedTerm === 'business-line-of-credit') {
document.querySelector('.acf-field-container').innerHTML =<?php the_field('line_of_credit'); ?>
;
} else if (selectedTerm === 'business-loans') {
document.querySelector('.acf-field-container').innerHTML =<?php the_field('business_loans_field'); ?>
;
}
// Optionally clear the local storage once used
localStorage.removeItem('selectedTerm');
});
</script>
</div>Forum: Developing with WordPress
In reply to: Show Hide post information Based on term Click@amitsksingh Here’s another way to handle this without exposing the
term
in the URL by using javascript:<a href="<?php the_permalink(); ?>" class="term-link" data-term="<?php echo get_queried_object()->slug; ?>">
<?php the_title(); ?>
</a>
<script>
document.addEventListener('DOMContentLoaded', function() {
const termLinks = document.querySelectorAll('.term-link');
termLinks.forEach(link => {
link.addEventListener('click', function(event) {
const term = this.getAttribute('data-term');
localStorage.setItem('selectedTerm', term);
});
});
});
</script>And then on your single page:
<script>
document.addEventListener('DOMContentLoaded', function() {
const selectedTerm = localStorage.getItem('selectedTerm');
if (selectedTerm === 'business-banking') {
<?php the_field('banking_field'); ?>
} else if (selectedTerm === 'business-line-of-credit') {
<?php the_field('line_of_credit'); ?>
} else if (selectedTerm === 'business-loans') {
<?php the_field('business_loans_field'); ?>
}
// Optionally clear the local storage once used
localStorage.removeItem('selectedTerm');
});
</script>Forum: Developing with WordPress
In reply to: Show Hide post information Based on term ClickHey Amit,
You could try adding the taxonomy term to the link like so:<a href="<?php the_permalink(); ?>?term=<?php echo get_queried_object()->slug; ?>">
<?php the_title(); ?>
</a>Then you can get this on your
single-reviews.php
page and conditionally render the fields:$term_slug = isset($_GET['term']) ? sanitize_text_field($_GET['term']) : '';
if ($term_slug === 'business-banking') {
the_field('banking_field');
} elseif ($term_slug === 'business-line-of-credit') {
the_field('line_of_credit');
} elseif ($term_slug === 'business-loans') {
the_field('business_loans_field');
}Hopefully that helps or points you in the right direction!
Forum: Developing with WordPress
In reply to: Block link in comment by user r?lefunction restrict_links_for_role($content, $user_id) {
$user = get_userdata($user_id);
if (in_array('base', $user->roles)) {
if (preg_match('/https?\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/', $content)) {
bp_core_add_message(__('You cannot post links with your current role.'), 'error');
return false; // Prevent post/comment from being saved
}
}
return $content;
}
add_filter('bp_activity_post_content', 'restrict_links_for_role', 10, 2);
add_filter('bp_activity_comment_content', 'restrict_links_for_role', 10, 2);I have this snippet that might be useful to you. It will search links in the comments from a certain user role.
Forum: Fixing WordPress
In reply to: 404 Error When Clicking On My Website URL From FaceBookClicking the link above redirects to your homepage correctly without a 404 error. Can you confirm this is still a problem or if you have already fixed it?
Forum: Fixing WordPress
In reply to: Unknown cron jobsAre you running any plugins that may be related to database optimisation or caching?