Support has been upgraded!
The Support Forum is closed. Not to worry! Providing the top quality support you expect and we're known for will continue! We're not ending support, just changing where you submit requests. This will provide you with the best experience possible.
Premium Support
Have you purchased an addon for Connections such as one of our premium templates or extensions with a valid license and you need help?
Please open a Support Ticket in your user account.
Free Support
Are you using the free Connections plugin? Don't worry, you are still very important to us! We are still providing you with the same high quality support that we're known for.
Please open a new support topic in the WordPress support forums for Connections.
Tagged: 8.2.7, cn_address_options, cn_date_options, code snippets, filter
- This topic has 5 replies, 2 voices, and was last updated 8 years, 4 months ago by
Steven Zahm.
-
AuthorPosts
-
05/14/2015 at 9:12 am #334229
George Socha
ParticipantIt would greatly extend the flexibility of Connections if at least some of the options currently defined in class.options.php were instead information drawn from a table in the WordPress database.
Here is an example, to help explain what I mean.
When adding or modifying a connection, I can select from a list of Address Types. That list currently is defined in class.options.php as:
public function getDefaultAddressValues() {
$options = array( 'home' => __( 'Home' , 'connections' ), 'work' => __( 'Work' , 'connections' ), 'school' => __( 'School' , 'connections' ), 'other' => __( 'Other' , 'connections' ) );
I want to use an additional address type, “Headquarters”. To do that, I modify the php page:
public function getDefaultAddressValues() {
$options = array( 'home' => __( 'Home' , 'connections' ), 'work' => __( 'Work' , 'connections' ), 'school' => __( 'School' , 'connections' ), 'headquarters' => __( 'Headquarters' , 'connections' ), 'other' => __( 'Other' , 'connections' ) );
I make similar modifications Date types.
Each time an update of the plugin comes out, I need to revise class.options.php to add back in my changes.
Were you to change the structure so that the plugin drew this the options from one of the tables in the database, instead of from the php page, that would help immensely.
Thanks for the great plugin, templates, and extensions!
05/14/2015 at 10:00 am #334238Steven Zahm
Keymaster@ George
Actually there is a way to do this already ready that is update safe that can be used by templates and extensions that does not add the weight of another db query. First, install the Code Snippets plugin.
Add a new snippet with the following code:
function cn_add_address_types( $options ) { $options['headquarters'] = __( 'Headquarters' , 'connections' ); // You can also remove those you do not require. // Remove the '//' in front of 'unset' to remove the "Other" address type. //unset( $options['other'] ); return $options; } add_filter( 'cn_address_options', 'cn_add_address_types' );
You would add another snippet for the change you need to date types:
function cn_add_date_types( $options ) { $options['new_date_type'] = __( 'New Date Type' , 'connections' ); return $options; } add_filter( 'cn_date_options', 'cn_add_date_types' );
Hope that helps! If you have a moment, I would truly appreciate a review as they really do make a difference! https://wordpress.org/support/view/plugin-reviews/connections
-
This reply was modified 7 years, 1 month ago by
Steven Zahm. Reason: Correct code
05/14/2015 at 11:54 am #334252George Socha
ParticipantI installed the Code Snippets plugin. I tested it to make sure it worked, with a snippet that inserts “It works!” into the admin footer. That worked.
I tried adding the two snippets you suggested, as well as removing the “headquarters” code that I had added to class.options.php.
Neither snippet does anything. When I go to edit a connection, in the Addresses section I do not see “Headquarter” as one of the available address types. In the Dates section I do not see “New Date Type” as one of the available data types. I also trying the instructions for removing the “Other” address type but that did not change anything either.
Any idea what is going wrong?
Thanks.
05/14/2015 at 2:30 pm #334275Steven Zahm
Keymaster@ George
Yeah, a copy/paste error on my part… that trailing comma in the first line of the function should be a semi-colon. Here are corrected snippets:
Address:
function cn_add_address_types( $options ) { $options['headquarters'] = __( 'Headquarters' , 'connections' ); // You can also remove those you do not require. // Remove the '//' in front of 'unset' to remove the "Other" address type. //unset( $options['other'] ); return $options; } add_filter( 'cn_address_options', 'cn_add_address_types' );
Date:
function cn_add_date_types( $options ) { $options['new_date_type'] = __( 'New Date Type' , 'connections' ); return $options; } add_filter( 'cn_date_options', 'cn_add_date_types' );
-
This reply was modified 7 years, 1 month ago by
Steven Zahm. Reason: Correct code
05/14/2015 at 3:11 pm #334295George Socha
ParticipantPerfect! Changing the comma to a semicolon worked. Thanks much.
05/14/2015 at 3:58 pm #334324Steven Zahm
Keymaster@ George
No problem!
-
This reply was modified 7 years, 1 month ago by
-
AuthorPosts
You must be logged in to reply to this topic.