,
* radio_options?: array ' . __( 'The only required setting on this page is the Site ID. All of the other settings are optional.', 'wp-parsely' ) . ' ' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.', 'wp-parsely' ) . 'http(s):// prefixes or trailing / (e.g. mydomain.com).', 'wp-parsely' ),
'label_for' => $field_id,
'optional_args' => array(
'required' => 'required',
'placeholder' => 'mydomain.com',
'disabled' => $are_credentials_managed,
),
);
add_settings_field(
$field_id,
__( 'Site ID (required)', 'wp-parsely' ),
array( $this, 'print_text_tag' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
if ( ! $are_credentials_managed ) {
// API Secret.
$field_id = 'api_secret';
$field_args = array(
'option_key' => $field_id,
'help_text' => __( 'Your API secret is your secret code to access our API. It can be found at dash.parsely.com/yoursitedomain/settings/api (replace yoursitedomain with your domain name, e.g. mydomain.com).
If you haven\'t purchased access to the API and would like to do so, email your account manager or support@parsely.com.', 'wp-parsely' ),
'label_for' => $field_id,
'optional_args' => array(
'type' => 'password',
'is_obfuscated_value' => true,
),
);
add_settings_field(
$field_id,
__( 'API Secret', 'wp-parsely' ),
array( $this, 'print_text_tag' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
}
// Metadata Format.
$field_id = 'meta_type';
$field_args = array(
'title' => __( 'Metadata Format', 'wp-parsely' ),
'option_key' => $field_id,
'help_text' => __( 'Choose the metadata format for our crawlers to access. Most publishers are fine with JSON-LD, but if you prefer to use our proprietary metadata format then you can do so here.', 'wp-parsely' ),
'radio_options' => array(
'json_ld' => 'json_ld',
'repeated_metas' => 'repeated_metas',
),
'label_for' => Parsely::OPTIONS_KEY . "[$field_id]",
'filter' => 'wp_parsely_metadata',
);
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Metadata Format', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
// Logo.
$field_help = __( 'Here you can specify your logo\'s URL by using the "Browse" button or typing the URL manually.', 'wp-parsely' );
$field_id = 'logo';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Logo', 'wp-parsely' ), $field_id ),
array( $this, 'print_media_single_image' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Logo', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'label_for' => $field_id,
'help_text' => $field_help,
)
);
// Track logged-in users.
$field_id = 'track_authenticated_users';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Track Logged-in Users', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Track Logged-in Users', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'radio_options' => array(
'true' => __( 'Yes, track logged-in users.', 'wp-parsely' ),
'false' => __( 'No, do not track logged-in users. I do not want to see the Parse.ly tracking code on my site when browsing while logged in.', 'wp-parsely' ),
),
'help_text' => (
is_multisite() ?
__( ' Note: For WordPress multisite, a user must be logged-in to the current site to be considered logged-in.', 'wp-parsely' ) :
null
),
)
);
// Disable JavaScript.
$field_id = 'disable_javascript';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Disable JavaScript', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Disable JavaScript', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'radio_options' => array(
'true' => __( 'Yes, disable JavaScript tracking. I want to use a separate system for tracking instead of the Parse.ly plugin.', 'wp-parsely' ),
'false' => __( 'No, do not disable JavaScript tracking. I want the Parse.ly plugin to load the tracker.', 'wp-parsely' ),
),
'help_text' => __( 'WARNING: Changing this setting to "Yes" will prevent the plugin from injecting the Parse.ly tracker. Only do so if you are setting the tracker elsewhere (e.g. hardcoded, GTM, another tag manager, etc.).', 'wp-parsely' ),
'filter' => 'wp_parsely_load_js_tracker',
)
);
if ( defined( 'AMP__VERSION' ) ) {
// Disable AMP tracking.
$field_id = 'disable_amp';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Disable AMP Tracking', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Disable AMP Tracking', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'radio_options' => array(
'true' => __( 'Yes, disable Parse.ly tracking on AMP pages. I use a different system for JavaScript tracking on AMP pages.', 'wp-parsely' ),
'false' => __( 'No, do not disable Parse.ly tracking on AMP pages.', 'wp-parsely' ),
),
)
);
}
}
/**
* Registers the Content Helper section and its settings.
*
* @since 3.16.0
*/
private function initialize_content_helper_section(): void {
$section_key = 'content-helper-section';
add_settings_section(
$section_key,
__( 'Content Helper', 'wp-parsely' ),
'__return_null',
Parsely::MENU_SLUG
);
// AI Features.
$field_id = 'content_helper[ai_features_enabled]';
$field_args = array(
'option_key' => $field_id,
'label_for' => $field_id,
'yes_text' => __( 'Enabled', 'wp-parsely' ),
'add_fieldset' => true,
'legend' => __( 'AI Features', 'wp-parsely' ),
);
add_settings_field(
$field_id,
__( 'AI Features', 'wp-parsely' ),
array( $this, 'print_checkbox_tag' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
// Smart Linking.
$field_id = 'content_helper[smart_linking]';
$field_args = array(
'option_key' => $field_id,
'label_for' => $field_id,
'legend' => __( 'Smart Linking', 'wp-parsely' ),
);
add_settings_field(
$field_id,
__( 'Smart Linking', 'wp-parsely' ),
array( $this, 'print_content_helper_ai_feature_section' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
// Title Suggestions.
$field_id = 'content_helper[title_suggestions]';
$field_args = array(
'option_key' => $field_id,
'label_for' => $field_id,
'legend' => __( 'Title Suggestions', 'wp-parsely' ),
);
add_settings_field(
$field_id,
__( 'Title Suggestions', 'wp-parsely' ),
array( $this, 'print_content_helper_ai_feature_section' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
// Excerpt Suggestions.
$field_id = 'content_helper[excerpt_suggestions]';
$field_args = array(
'option_key' => $field_id,
'label_for' => $field_id,
'legend' => __( 'Excerpt Suggestions', 'wp-parsely' ),
'filter' => Excerpt_Suggestions::get_feature_filter_name(),
);
add_settings_field(
$field_id,
__( 'Excerpt Suggestions', 'wp-parsely' ),
array( $this, 'print_content_helper_ai_feature_section' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
// Traffic Boost.
$field_id = 'content_helper[traffic_boost]';
$field_args = array(
'option_key' => $field_id,
'label_for' => $field_id,
'legend' => __( 'Traffic Boost (beta)', 'wp-parsely' ),
);
add_settings_field(
$field_id,
__( 'Traffic Boost (beta)', 'wp-parsely' ),
array( $this, 'print_content_helper_ai_feature_section' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
}
/**
* Registers section and settings for Recrawl section.
*
* @since 3.2.0
*/
private function initialize_recrawl_section(): void {
$section_key = 'recrawl-section';
add_settings_section(
$section_key,
__( 'Recrawl', 'wp-parsely' ),
function (): void {
echo '
' . wp_kses_post( __( 'Important: Changing any of these values below on a site currently tracked with Parse.ly will require reprocessing of your Parse.ly data.', 'wp-parsely' ) ) . '
';
printf(
/* translators: Mailto link */
esc_html__( 'Once you have changed a value and saved, please contact %s to request a recrawl.', 'wp-parsely' ),
wp_kses_post( 'support@parsely.com' )
);
},
Parsely::MENU_SLUG
);
// Allow use of custom taxonomy to populate articleSection in parselyPage; defaults to category.
$field_id = 'track_post_types_as';
$field_help = __( 'By default, Parse.ly only tracks posts and pages. If you want to track other post types, select how you want to track them here.', 'wp-parsely' );
add_settings_field(
$field_id,
__( 'Track Post Types as', 'wp-parsely' ),
array( $this, 'print_track_post_types_table' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Track Post Types as', 'wp-parsely' ),
'option_key' => $field_id,
'help_text' => $field_help,
)
);
// Use full metadata in non-posts.
$field_id = 'full_metadata_in_non_posts';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Use Full Metadata in Non-Posts', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Use Full Metadata in Non-Posts', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'radio_options' => array(
'true' => __( 'Yes, add full metadata to Post Types being tracked as Non-Posts.', 'wp-parsely' ),
'false' => __( 'No, we have code that modifies metadata and that has not been tested for compatibility yet.', 'wp-parsely' ),
),
'help_text' => __( 'Important: This setting will be removed in the future, force-enabling this behavior. If you\'re using any code that modifies metadata in a way that conflicts with this setting when it is enabled, please apply any needed fixes.', 'wp-parsely' ),
)
);
// Content ID Prefix.
$field_id = 'content_id_prefix';
$field_args = array(
'option_key' => $field_id,
'optional_args' => array(
'placeholder' => 'WP-',
),
'help_text' => __( 'If you use more than one content management system (e.g. WordPress and Drupal), you may end up with duplicate content IDs. Adding a Content ID Prefix will ensure the content IDs from WordPress will not conflict with other content management systems. We recommend using "WP-" for your prefix.', 'wp-parsely' ),
'label_for' => $field_id,
);
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Content ID Prefix', 'wp-parsely' ), $field_id ),
array( $this, 'print_text_tag' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
// Use top-level categories.
$field_id = 'use_top_level_cats';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Use Top-Level Categories for Section', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Use Top-Level Categories for Section', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'radio_options' => array(
'true' => __( 'Yes, use the first category assigned to a post as the section name.', 'wp-parsely' ),
'false' => __( 'No, do not use the first category assigned to a post as the section name.', 'wp-parsely' ),
),
'help_text' => __( 'If you choose Yes, and post a story to News > National > Florida, the plugin will use "News" for the section name in your dashboard instead of "Florida".', 'wp-parsely' ),
)
);
// Allow use of custom taxonomy to populate articleSection in parselyPage; defaults to category.
$field_id = 'custom_taxonomy_section';
$field_args = array(
'option_key' => $field_id,
'help_text' => __( 'By default, the section value in your Parse.ly dashboard maps to a post\'s category. You can optionally choose a custom taxonomy, if you\'ve created one, to populate the section value instead.', 'wp-parsely' ),
'select_options' => self::get_section_taxonomies(),
'label_for' => Parsely::OPTIONS_KEY . "[$field_id]",
);
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Use Custom Taxonomy for Section', 'wp-parsely' ), $field_id ),
array( $this, 'print_select_tag' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
// Use categories and custom taxonomies as tags.
$field_id = 'cats_as_tags';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Add Categories to Tags', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Add Categories to Tags', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'radio_options' => array(
'true' => __( 'Yes, add all assigned categories and taxonomies to my tags.', 'wp-parsely' ),
'false' => __( 'No, do not add all assigned categories and taxonomies to my tags.', 'wp-parsely' ),
),
'help_text' => __( 'If you choose Yes, then a post that has been assigned the categories "Business/Tech" and "Business/Social" will automatically include "Business/Tech" and "Business/Social" as tags, too.', 'wp-parsely' ),
)
);
// Lowercase all tags.
$field_id = 'lowercase_tags';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Lowercase All Tags', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Lowercase All Tags', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'radio_options' => array(
'true' => __( 'Yes, use lowercase versions of my tags to correct for potential misspellings.', 'wp-parsely' ),
'false' => __( 'No, do not use lowercase versions of my tags to correct for potential misspellings.', 'wp-parsely' ),
),
)
);
$field_id = 'force_https_canonicals';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Force HTTPS Canonicals', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Force HTTPS Canonicals', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'radio_options' => array(
'true' => __( 'Yes, force https canonical URLs by default.', 'wp-parsely' ),
'false' => __( 'No, I want to use http.', 'wp-parsely' ),
),
'help_text' => __( 'Note: the plugin uses http by default, and this is fine for most publishers. It is unlikely you will have to change this unless directed to do so by a Parse.ly support representative.', 'wp-parsely' ),
)
);
}
/**
* Registers section and settings for Advanced section.
*
* @since 3.2.0
*/
private function initialize_advanced_section(): void {
$are_credentials_managed = $this->parsely->are_credentials_managed;
$section_key = 'advanced-section';
add_settings_section(
$section_key,
__( 'Advanced', 'wp-parsely' ),
'__return_null',
Parsely::MENU_SLUG
);
if ( ! $are_credentials_managed ) {
// Metadata Secret.
$field_id = 'metadata_secret';
$field_args = array(
'option_key' => $field_id,
'help_text' => __( 'Your metadata secret is given to you by Parse.ly support. DO NOT enter anything here unless given to you by Parse.ly support!', 'wp-parsely' ),
'label_for' => $field_id,
'optional_args' => array(
'type' => 'password',
'is_obfuscated_value' => true,
),
);
add_settings_field(
$field_id,
__( 'Metadata Secret', 'wp-parsely' ),
array( $this, 'print_text_tag' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
}
// Disable autotrack.
$field_id = 'disable_autotrack';
add_settings_field(
$field_id,
$this->set_field_label_contents( __( 'Disable Autotracking', 'wp-parsely' ), $field_id ),
array( $this, 'print_radio_tags' ),
Parsely::MENU_SLUG,
$section_key,
array(
'title' => __( 'Disable Autotracking', 'wp-parsely' ), // Passed for legend element.
'option_key' => $field_id,
'radio_options' => array(
'true' => __( 'Yes, disable autotracking. I do not want the tracking code to report an event as soon as the script has finished loading. I plan to implement Dynamic Tracking myself.', 'wp-parsely' ),
'false' => __( 'No, do not disable autotracking. I want to make sure the default behavior of the tracking code is in place. The tracking code should report an event as soon as the script has finished loading.', 'wp-parsely' ),
),
)
);
}
/**
* Shows setting tabs.
*
* @since 3.8.0
*/
public function show_setting_tabs(): void {
global $wp_settings_sections;
?>
' . esc_html( $args['filter'] ) . '' . esc_html__( 'filter hook is in use!', 'wp-parsely' ) . ' ';
echo esc_html__( 'A callback is attached to the filter hook that might interfere and override this setting.', 'wp-parsely' );
echo '
' . wp_kses_post( $args['help_text'] ) . '
' : ''; } /** * Prints out an input text tag. * * @param Setting_Arguments $args The arguments for text tag. */ public function print_text_tag( $args ): void { $options = $this->parsely->get_options(); $name = $args['option_key']; /** * Variable. * * @var string */ $value = $options[ $name ] ?? ''; $optional_args = $args['optional_args'] ?? array(); $id = esc_attr( $name ); $name = Parsely::OPTIONS_KEY . "[$id]"; $is_obfuscated_value = $optional_args['is_obfuscated_value'] ?? false; $value = $is_obfuscated_value ? $this->get_obfuscated_value( $value ) : esc_attr( $value ); $accepted_args = array( 'placeholder', 'required', 'disabled' ); $type = $optional_args['type'] ?? 'text'; $is_managed = key_exists( $id, $this->parsely->managed_options ); echo ''; $this->print_description_text( $args ); } /** * Prints a checkbox tag. * * @since 3.16.0 * * @param Setting_Arguments $args Arguments for the checkbox tag. * @param Parsely_Options|null $options The options to use. */ public function print_checkbox_tag( $args, $options = null ): void { $options = $options ?? $this->parsely->get_options(); $name = $args['option_key']; $has_fieldset = isset( $args['add_fieldset'] ) && true === $args['add_fieldset']; $html_id = rtrim( str_replace( array( '[', ']', '__' ), '_', $name ), '_' ); $html_name = str_replace( 'content_helper', '[content_helper]', Parsely::OPTIONS_KEY . esc_attr( $name ) ); $yes_text = $args['yes_text'] ?? ''; // Get option value. if ( false === strpos( $name, '[' ) ) { $value = $options[ $name ]; } else { $value = Parsely::get_nested_option_value( $name, $options ); } // Fieldset start. if ( $has_fieldset ) { echo ''; } $this->print_description_text( $args ); } /** * Prints a Content Helper AI feature section. * * @since 3.16.0 * * @param Setting_Arguments $args The arguments for the section. */ public function print_content_helper_ai_feature_section( $args ): void { $options = $this->parsely->get_options(); $feature_id = str_replace( array( 'content_helper[', ']' ), '', $args['option_key'] ); // Convert user role settings to make them work in the settings page. $option = &$options['content_helper'][ $feature_id ]; if ( isset( $option['allowed_user_roles'] ) ) { foreach ( $option['allowed_user_roles'] as $role ) { $option['allowed_user_roles'][ $role ] = true; } } // Feature "Enabled" checkbox. $enabled_args = array( 'option_key' => $args['option_key'] . '[enabled]', 'label_for' => $args['option_key'] . '[enabled]', 'yes_text' => __( 'Enabled', 'wp-parsely' ), 'add_fieldset' => true, ); if ( isset( $args['legend'] ) ) { $enabled_args['legend'] = $args['legend']; } $this->print_checkbox_tag( $enabled_args, $options ); // User role permissions fieldset. echo '' . esc_html__( 'User Permissions', 'wp-parsely' ) . '
'; echo ''; $this->print_filter_text( $args ); } /** * Prints out the select tags * * @param Setting_Arguments $args The arguments for the select dropdowns. */ public function print_select_tag( $args ): void { $options = $this->parsely->get_options(); $name = $args['option_key']; $select_options = $args['select_options'] ?? array(); $selected = $options[ $name ] ?? null; $id = esc_attr( $name ); $name = Parsely::OPTIONS_KEY . "[$id]"; $is_managed = key_exists( $id, $this->parsely->managed_options ); echo ''; $this->print_filter_text( $args ); $this->print_description_text( $args ); } /** * Prints the radio buttons. * * @param Setting_Arguments $args The arguments for the radio buttons. */ public function print_radio_tags( $args ): void { $name = $args['option_key']; $id = esc_attr( $name ); $selected = $this->parsely->get_options()[ $name ]; $title = $args['title'] ?? ''; $radio_options = $args['radio_options'] ?? array(); if ( is_bool( $selected ) ) { // Converting boolean to string so that we have string type keys for all cases. $selected = $selected ? 'true' : 'false'; } $is_managed = key_exists( $name, $this->parsely->managed_options ); ?> print_filter_text( $args ); $this->print_description_text( $args ); } /** * Prints out a "single-image browse control" which includes a text input to * store image path and a button to browse for images. * * @param Setting_Arguments $args The arguments for the control. */ public function print_media_single_image( $args ): void { $key = $args['option_key']; $title = $args['title'] ?? ''; /** * Variable. * * @var string */ $input_value = $this->parsely->get_options()[ $key ]; $input_name = Parsely::OPTIONS_KEY . "[$key]"; $button_text = __( 'Browse', 'wp-parsely' ); $is_managed = key_exists( $key, $this->parsely->managed_options ); ?> print_description_text( $args ); } /** * Prints out the post tracking options table. * * @since 3.2.0 * * @param Setting_Arguments $args The arguments used in the output HTML elements. */ public function print_track_post_types_table( $args ): void { $option_key = esc_attr( $args['option_key'] ); $title = $args['title'] ?? ''; /** * Variable. * * @var array