register_owned_keys(); } /** * Returns keys for owned settings. * * @since 1.132.0 * * @return array An array of keys for owned settings. */ public function get_owned_keys() { return array( 'publicationID' ); } /** * Gets the default value. * * @since 1.132.0 * * @return array */ protected function get_default() { $defaults = array( 'ownerID' => 0, 'publicationID' => '', 'publicationOnboardingState' => '', 'publicationOnboardingStateChanged' => false, 'productIDs' => array(), 'paymentOption' => '', ); if ( Feature_Flags::enabled( 'rrmModuleV2' ) ) { $defaults = array_merge( $defaults, array( 'snippetMode' => 'post_types', 'postTypes' => array( 'post' ), 'productID' => 'openaccess', ) ); } return $defaults; } /** * Returns keys for view-only settings. * * @since 1.132.0 * * @return array An array of keys for view-only settings. */ public function get_view_only_keys() { $keys = array( 'publicationID', ); if ( Feature_Flags::enabled( 'rrmModuleV2' ) ) { $keys = array_merge( $keys, array( 'snippetMode', 'postTypes', 'paymentOption', ) ); } return $keys; } /** * Gets the callback for sanitizing the setting's value before saving. * * @since 1.132.0 * * @return callable|null */ protected function get_sanitize_callback() { return function ( $option ) { if ( isset( $option['publicationID'] ) ) { if ( ! preg_match( '/^[a-zA-Z0-9_-]+$/', $option['publicationID'] ) ) { $option['publicationID'] = ''; } } if ( isset( $option['publicationOnboardingStateChanged'] ) ) { if ( ! is_bool( $option['publicationOnboardingStateChanged'] ) ) { $option['publicationOnboardingStateChanged'] = false; } } if ( isset( $option['publicationOnboardingState'] ) ) { $valid_onboarding_states = array( self::ONBOARDING_STATE_UNSPECIFIED, self::ONBOARDING_STATE_ACTION_REQUIRED, self::ONBOARDING_STATE_PENDING_VERIFICATION, self::ONBOARDING_STATE_COMPLETE, ); if ( ! in_array( $option['publicationOnboardingState'], $valid_onboarding_states, true ) ) { $option['publicationOnboardingState'] = ''; } } if ( isset( $option['productIDs'] ) ) { if ( ! is_array( $option['productIDs'] ) ) { $option['productIDs'] = array(); } else { $option['productIDs'] = array_values( array_filter( $option['productIDs'], 'is_string' ) ); } } if ( isset( $option['paymentOption'] ) ) { if ( ! is_string( $option['paymentOption'] ) ) { $option['paymentOption'] = ''; } } if ( Feature_Flags::enabled( 'rrmModuleV2' ) ) { if ( isset( $option['snippetMode'] ) ) { $valid_snippet_modes = array( 'post_types', 'per_post', 'sitewide' ); if ( ! in_array( $option['snippetMode'], $valid_snippet_modes, true ) ) { $option['snippetMode'] = 'post_types'; } } if ( isset( $option['postTypes'] ) ) { if ( ! is_array( $option['postTypes'] ) ) { $option['postTypes'] = array( 'post' ); } else { $filtered_post_types = array_values( array_filter( $option['postTypes'], 'is_string' ) ); $option['postTypes'] = ! empty( $filtered_post_types ) ? $filtered_post_types : array( 'post' ); } } if ( isset( $option['productID'] ) ) { if ( ! is_string( $option['productID'] ) ) { $option['productID'] = 'openaccess'; } } } return $option; }; } }