How can I alter discussion settings dynamically for certain custom post types - wordpress

I'm looking for a way to alter the behaviour of comments for a custom post type.
Comments for other post types should be allowed without user login – and that's how it's been set up on the admin panel Discussion settings. However for one particular custom post type I want to enforce that users must be logged in to comment on that post type.
I'm guessing that the way to do this is to alter the discussion settings dynamically before calling custom_form() but I can't find any documentation on how to do that.
The other option would be a way to set this setting in the admin panel but only for this custom post-type.
Is either of these things possible?

update_option('comment_registration',true);
custom_form()

Related

Wordpress - form to capture the values for the custom post type

I want to add a new entity named "ideas" having different fields. I want to add this to the admin side, where a logged in user can add/edit new "idea", which can be published/unpublished to the site.
I don't want to edit via php and make things complicated, instead do it from the wp-admin log in front-end. Is there a plugin for this? I need 3-4 such entities to be created, and define fields for each such entity.
New edit:
Custom Post Type is the best option I feel. Can anyone suggest, a free plugin for form to capture the values for the custom post type?
According to this WCK - Custom Fields and Custom Post Types Creator plugin you can achieve this.
WordPress Creation Kit consists of three tools that can help you
create and maintain custom post types, custom taxonomies and most
importantly, custom fields and metaboxes for your posts, pages or
CPT's.
WCK Custom Fields Creator offers an UI for setting up custom meta
boxes with custom fields for your posts, pages or custom post types.
Uses standard custom fields to store data.
WCK Custom Post Type Creator facilitates creating custom post types by
providing an UI for most of the arguments of register_post_type()
function.
WCK Taxonomy Creator allows you to easily create and edit custom
taxonomies for WordPress without any programming knowledge. It
provides an UI for most of the arguments of register_taxonomy()
function.
Hope it helps you.
You can use a combination of two plugins to fit your needs:
The Custom Post Type UI (https://wordpress.org/plugins/custom-post-type-ui/) makes it possible to generate Custom Post Types (like "Posts" or "Pages") and Custom Taxonomies. This is how you can create your entity "ideas" which will show up in the admin menu.
With Advanced Custom Fields (https://wordpress.org/plugins/advanced-custom-fields/) you can define additional content fields for your "ideas"-posttype and others. It also can handle relations between your added custom-post-types
Using the SWIFT Templates as proposed in Touqueer Shafis answer will be sufficient when you only have smaller bits of information to display on the page or if you just want to display archives of your custom-post-types. But you will quickly reach the borders of these templates when it comes to single-pages.
I recommend altering the PHP of your template files manually: you will have more control where and when to display the contents of the custom-post-types and custom-fields you added on your page.
Well, I'm not really gonna give you the answer you want to hear but I want to give you an advice from my own experience.
Using a plugin will make things usually much more complicated than doing it manually. Consider some things:
1) The plugin may not be supported for ever (or long), so if the author decides that he or she wants to be a gardener instead of a developer you're screwed. Unless you want to wrap your head around the plugin code and proceed developing it on your own. This is especially true for "underground"-plugins which are not so popular and/or maintained by a single person. Although I think you CAN rely on the "big" players like "Advanced custom fields"
2) At some point you may find that the plugin you are using doesn't support some sort of customization that you really need and quite a few plugins are built in a way that makes it hard to extend them or break out from the way they work.
So I recommend you to wrap your head around custom taxonomies and post types and just add them with PHP in your functions.php or a custom plugin. It's very very easy (it's really just arrays with arguments). You could use this visual code generator as a starting point:
http://generatewp.com/post-type/
And for adding custom fields I recommend using Advanced custom fields. You won't need any other plugin for backend management customization and it's built in a way that you can even export your custom fields as php so if they ever drop support you still have a good starting point.

How to use custom fields globally in Wordpress?

I'm trying to use the value of one custom field on multiple pages and posts. I'm a newbie to PHP and custom fields so what I'm trying to accomplish could possible be done using a different method.
I have a WPMU setup with all new sites created from a default blog that includes multiple custom post type templates. When users create a new site they are redirected to their site admin dashboard.
Here comes my challenge, I want users to be able to enter information into form fields contained in metabox(es) on their admin dashboard (not post editor) that will be used on the various custom post type templates. For example, a user will need to enter their company name, address, logo, etc.
Depending on the temple, the information entered into the form fields will be used on the frontend of the site. For example, the company logo will be display where the custom field or shortcode is placed on the post template.
I'm having issues using custom fields for this because each custom field is specific to each post. In addition, I'm having issues rendering a form on the admin dashboard for this.
I'm also thinking that custom fields may not be the best way to accomplish my objective because they are usually post specific. I'm really asking for a variable that will be used globally and is static unless the user updates the form.
I'd appreciate any assistance on this.
The options API is what you will need for this:
http://codex.wordpress.org/Options_API
There's also some plugins and frameworks you can use to help such as:
https://wordpress.org/plugins/options-framework/
https://wordpress.org/plugins/redux-framework/

Capability required to view Advanced Custom Fields in WordPress

I asked this question over on the WordPress StackExchange but was told it was off-topic for there. I hope it is correct to ask it here instead.
A client has asked that I setup the Contributor role in WordPress so that it can only view/edit/delete their own posts from a CPT called 'members'. I have done this using Justin Tadlock's Members plugin + a small snippet of code since they only want the Contributor's to be able to see their own posts & not others (even if they can't edit them).
Everything is working well except for Advanced Custom Fields. The client is using this to provide extra fields on the 'members' CPT, but unless I give the Contributor role the 'edit_others' capability they are unable to see the fields created by ACF.
Is this an issue with ACF, or with WordPress? I am still fairly new to Roles & Caps and I cannot seem to understand how to change this. If possible I would like the ACF fields to be visible on the 'edit_members' capability.
Add the 'edit_others_posts' to your user role.
I had same problem, and after some trying out different combinations, have found that this capability needs to be enabled.
The problem is not in roles or capabilities, problem is how you limit the edit-posts dashboard for non-administrators. Your if-statement should not be performed on edit-post page, only at post listing page (for example, if you use pre_get_posts to restrict posts editing for admins only, then you must not run this pre_get_posts function at posts.php page).
Also example from ACF support forum.
This issue has been posted a long time ago, but I believe there is still someone facing it at the moment. So I would like to make it easy to understand.
First of all, we have to separate it into two parts.
First, the relationship between user, role, and capability. Let's say, each user has a roles, and each role has capabilities. It is one-to-many relation from top down.
Second, custom post type(CPT), advanced custom field plugin (ACF) and ACF extension plugin.
Each custom post type can be done for a specific capability and all fields under the custom post type has been done by using ACF.
Lastly, not all fields need to appear on every user who has the role that included this capability. Some field need to be appear for just for some specific role which has this capability included. This is where ACF extended plugin step in. It is sound complicate isn't it? Let have a look the chart below.
With acf_permission, you can be able to specific the role for be able to see the field like below.
`[instruction_placement] => label
[hide_on_screen] =>
...
[acfe_permissions] => Array
(
[0] => administrator
[1] => editor
)
...`
This might not fully answer the question but hope it will help to clear how does it work together.
https://www.acf-extended.com/features/field-groups/permissions

dynamically adding unlimited fields to wordpress custom post

does anybody know a plugin for wordpress custom fields that will allow me dynamically add unlimited number of custom field for post in post adding/editing page. for example "Key Features field/child post" of some product which is post itself and must be added dynamically and unlimited while adding parent post.
You could use Gravity Forms and the Gravity Forms and the Gravity Forms Custom Post Type Plugin. Most form controls allow "if..then" logic to be applied. Advanced Custom Fields may also be an option. However, either way you will have to add a custom post type. If you edit post.php then you will lose your changes the next time WP updates.
Start by creating a custom post type with http://generatewp.com/post-type/. I know its not a plug in like you asked for but You might find a way to accomplish the functionality.

WP: writing an admin plugin for managing custom content

A client of mine has a site in wordpress, with one section being a directory of agents that each have different text and videos associated with them.
The client wants to be able to easily add/remove/change these agents from within the wordpress admin interface. There will be anywhere from 50-75 of these agents, so doing each page manually is not very attractive.
We currently have 3 agents added as posts, and i understand that we can store additional information inside the post itself, so that is not a problem. What we would like to create is a simpler way of managing those pages where the content cannot be changed by the maintainer, and the additional fields on the post are hard coded so there would be no room for user error.
What i am interested in is if anyone has done something similar in the past and can share their approach and experience, or if anyone can point me in the right direction as to how i can accomplish this and what i need to be aware of.
Thanks.
Yes, Custom Post Types are a perfect fit for your needs. Here are some links to articles explaining them:
http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress
http://www.wpbeginner.com/wp-tutorials/how-to-use-custom-post-types/
http://thinkvitamin.com/dev/create-your-first-wordpress-custom-post-type/
You can use a plugin like Custom Post Type UI or just add the register_post_type() calls to your theme's functions.php file:
http://wordpress.org/extend/plugins/custom-post-type-ui/
Then you can use a plugin like "Simple Fields" to add metaboxes to your Agent post type (although there are numerous plugins offering similar functionality; I'm building one myself!):
http://eskapism.se/code-playground/simple-fields/
Hope this helps...
Have you thought about using custom post types? You could create type called Agent and then each agent would be like a post. That way you could search for specific agents easily in the admin and then go in to the post for each agent to change their details.

Resources