' . __( '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' ) . '
',
)
);
}
/**
* Displays the Parse.ly settings screen (options-general.php?page=[SLUG]).
*/
public function display_settings(): void {
// phpcs:ignore WordPress.WP.Capabilities.Undetermined
if ( ! current_user_can( Parsely::CAPABILITY ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wp-parsely' ) );
}
include_once plugin_dir_path( PARSELY_FILE ) . 'views/parsely-settings.php';
}
/**
* Initializes the settings for Parse.ly.
*/
public function initialize_settings(): void {
// Add the option first, to prevent double sanitization of the uninitialized option as reported
// in https://core.trac.wordpress.org/ticket/21989.
// The option will be initialized with the default values.
add_option( Parsely::OPTIONS_KEY, $this->parsely->get_options() );
// All our options are actually stored in one single array to reduce DB queries.
register_setting(
Parsely::OPTIONS_KEY,
Parsely::OPTIONS_KEY,
array(
'type' => 'array',
'sanitize_callback' => array( $this, 'validate_options' ),
)
);
$this->initialize_basic_section();
$this->initialize_recrawl_section();
$this->initialize_advanced_section();
}
/**
* Registers section and settings for Basic section.
*
* @since 3.2.0
*/
private function initialize_basic_section(): void {
$are_credentials_managed = $this->parsely->are_credentials_managed;
$section_key = 'basic-section';
add_settings_section(
$section_key,
__( 'Basic', 'wp-parsely' ),
'__return_null',
Parsely::MENU_SLUG
);
// Site ID.
$field_id = 'apikey';
$field_args = array(
'option_key' => $field_id,
'help_text' => __( 'Your Site ID is typically your own site domain without 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 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,
'filter' => 'wp_parsely_trackable_statuses',
)
);
// 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;
?>
';
echo '' . 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 '
';
}
}
/**
* Prints out the description text, if there is any.
*
* @since 3.1.0
*
* @param Setting_Arguments $args The arguments for the form field. May contain 'help_text'.
*/
private function print_description_text( $args ): void {
echo isset( $args['help_text'] ) ? '
' . 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 in the settings page.
*
* @param Setting_Arguments $args Arguments to print to checkbox tag.
*/
public function print_checkbox_tag( $args ): void {
$options = $this->parsely->get_options();
$name = $args['option_key'];
$value = $options[ $name ];
$id = esc_attr( $name );
$name = Parsely::OPTIONS_KEY . "[$id]";
$yes_text = $args['yes_text'] ?? '';
$is_managed = key_exists( $id, $this->parsely->managed_options );
echo '