diff --git a/constant-contact-forms.php b/constant-contact-forms.php index ad5a7e0d5..b750c5074 100644 --- a/constant-contact-forms.php +++ b/constant-contact-forms.php @@ -45,7 +45,7 @@ * @param string $class_name Name of the class being requested. * @return null */ -function constant_contact_autoload_classes( string $class_name ) { +function constant_contact_autoload_classes( string $class_name ): null { if ( ! str_starts_with( $class_name, 'ConstantContact_' ) ) { return null; } @@ -114,6 +114,8 @@ class Constant_Contact { /** * Singleton instance of plugin. * + * @todo Leave off the class delcaration. It's causing fatal errors. + * * @since 1.0.0 * @var Constant_Contact */ @@ -590,11 +592,19 @@ public function ajax_save_clear_first_form() { public function __get( $field ) { return match ( $field ) { 'version' => self::VERSION, - 'basename', 'path', 'url' => $this->$field, default => throw new Exception( 'Invalid ' . __CLASS__ . ' property: ' . $field ), }; } + /** + * Basename getter + * @since NEXT + * @return string + */ + public function get_basename(): string { + return $this->basename; + } + /** * Admin getter * @since 2.11.0 diff --git a/includes/class-admin-pages.php b/includes/class-admin-pages.php index 57e4c8468..9b36764e5 100644 --- a/includes/class-admin-pages.php +++ b/includes/class-admin-pages.php @@ -21,17 +21,19 @@ class ConstantContact_Admin_Pages { * Parent plugin class. * * @since 1.0.0 - * @var object + * + * @var Constant_Contact */ - protected $plugin; + protected Constant_Contact $plugin; /** * Constructor. * * @since 1.0.0 - * @param object $plugin Plugin parent. + * + * @param Constant_Contact $plugin Plugin parent. */ - public function __construct( $plugin ) { + public function __construct( Constant_Contact $plugin ) { $this->plugin = $plugin; $this->hooks(); } @@ -41,7 +43,7 @@ public function __construct( $plugin ) { * * @since 1.0.0 */ - public function hooks() { + public function hooks(): void { add_action( 'admin_enqueue_scripts', [ $this, 'styles' ] ); } @@ -50,7 +52,7 @@ public function hooks() { * * @since 1.0.0 */ - public function styles() { + public function styles(): void { wp_enqueue_style( 'constant-contact-forms-admin' ); wp_enqueue_script( 'ctct_form' ); } @@ -60,7 +62,7 @@ public function styles() { * * @since 1.0.0 */ - public function about_page() { + public function about_page(): void { $auth_link = ''; $new_link = ''; @@ -139,8 +141,8 @@ public function about_page() {
- - + +
@@ -170,7 +172,7 @@ public function about_page() { * * @since 1.0.1 */ - public function license_page() { + public function license_page(): void { $license_text = $this->plugin->get_license_text(); ?>

diff --git a/includes/class-admin.php b/includes/class-admin.php index 9d5fcb898..d44e9983b 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -55,7 +55,7 @@ class ConstantContact_Admin { * @since 1.0.0 * @var object */ - protected $plugin; + protected Constant_Contact $plugin; /** * Parent plugin class. @@ -63,7 +63,7 @@ class ConstantContact_Admin { * @since 1.0.0 * @var object */ - protected $basename; + protected string $basename; /** * The parent menu page slug. @@ -92,7 +92,7 @@ public function __construct( Constant_Contact $plugin, string $basename ) { * * @since 1.0.0 */ - public function hooks() { + public function hooks(): void { add_action( 'current_screen', [ $this, 'current_screen' ] ); add_action( 'admin_init', [ $this, 'init' ] ); @@ -104,7 +104,7 @@ public function hooks() { add_filter( 'manage_ctct_lists_posts_columns', [ $this, 'set_custom_lists_columns' ] ); add_action( 'manage_ctct_lists_posts_custom_column', [ $this, 'custom_lists_columns' ], 10, 2 ); - add_filter( 'plugin_action_links_' . $this->basename, [ $this, 'add_social_links' ] ); + add_filter( 'plugin_action_links_' . $this->basename, [ $this, 'add_custom_links' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'scripts' ] ); } @@ -117,7 +117,7 @@ public function hooks() { * @since 1.11.0 * @author Darren Cooney */ - public function current_screen( WP_Screen $screen ) { + public function current_screen( WP_Screen $screen ): void { if ( constant_contact()->is_constant_contact() ) { add_action( 'in_admin_header', [ $this, 'admin_page_toolbar' ] ); } @@ -131,7 +131,7 @@ public function current_screen( WP_Screen $screen ) { * @since 1.11.0 * @author Darren Cooney */ - public function admin_page_toolbar() { + public function admin_page_toolbar(): void { global $submenu, $submenu_file, $plugin_page; @@ -215,7 +215,7 @@ public function admin_page_toolbar() { echo wp_kses( '', [ 'ul' => [] ] ); } ?> - + @@ -227,7 +227,7 @@ public function admin_page_toolbar() { * * @since 1.0.0 */ - public function init() { + public function init(): void { register_setting( $this->key, $this->key ); } @@ -236,7 +236,7 @@ public function init() { * * @since 1.0.0 */ - public function add_options_page() { + public function add_options_page(): void { add_submenu_page( $this->parent_menu_slug, @@ -270,7 +270,7 @@ public function add_options_page() { * * @since 1.0.0 */ - public function admin_page_display() { + public function admin_page_display(): void { /** * Fires before the Constant Contact admin page display. @@ -321,12 +321,12 @@ public function admin_page_display() { * * @since 1.0.0 * - * @throws Exception Throws an exception if the field is invalid. - * * @param string $field Field to retrieve. - * @return mixed Field value or exception is thrown. + * + * @return mixed Field value or exception is thrown. + * @throws Exception Throws an exception if the field is invalid. */ - public function __get( $field ) { + public function __get( string $field ) { $field = esc_attr( $field ); @@ -370,7 +370,7 @@ public function set_custom_columns( array $columns ) : array { * * @return void */ - public function custom_columns( string $column, int $post_id ) { + public function custom_columns( string $column, int $post_id ): void { $post_id = absint( $post_id ); if ( ! $post_id ) { @@ -511,7 +511,7 @@ public function set_custom_lists_columns( array $columns ) : array { * * @return void */ - public function custom_lists_columns( string $column, int $post_id ) { + public function custom_lists_columns( string $column, int $post_id ): void { $post_id = absint( $post_id ); @@ -544,11 +544,7 @@ public function custom_lists_columns( string $column, int $post_id ) { * * @return array */ - public function add_social_links( $links ): array { - - if ( ! is_array( $links ) ) { - return $links; - } + public function add_custom_links( array $links ): array { $add_links[] = $this->get_admin_link( esc_html__( 'Settings', 'constant-contact-forms' ), 'settings_general' ); @@ -608,7 +604,7 @@ public function get_admin_link( string $text, string $link_slug = '', $add_form * @param array $extra_localizations Optional. An array of arrays of `[ $handle, $name, $data ]` passed to wp_localize_script. * @return void */ - public function scripts( $extra_localizations = [] ) { + public function scripts( $extra_localizations = [] ): void { global $pagenow; @@ -662,9 +658,6 @@ public function scripts( $extra_localizations = [] ) { wp_enqueue_script( 'ctct_form' ); } - $current_screen = get_current_screen(); - $is_block = is_object( $current_screen ) ? $current_screen->is_block_editor : true; - /** * Filters the allowed pages to enqueue the ctct_form script on. * @@ -721,15 +714,3 @@ public function get_associated_list_by_id( string $list_id ) { return []; } } - -/** - * Wrapper function around cmb2_get_option. - * - * @since 1.0.0 - * - * @param string $key Options array key. - * @return mixed Option value. - */ -function constantcontact_get_option( $key = '' ) { - return cmb2_get_option( constant_contact()->get_admin()->key, $key ); -} diff --git a/includes/class-api-utility.php b/includes/class-api-utility.php index 03bfe093d..5daa4673d 100644 --- a/includes/class-api-utility.php +++ b/includes/class-api-utility.php @@ -172,7 +172,7 @@ public function obfuscate_api_data_item( string $data_item ): string { * @param string $access_token * @return array */ - public function parse_access_token_data( string $access_token ) { + public function parse_access_token_data( string $access_token ): array { if ( empty( $access_token ) ) { return []; } diff --git a/includes/class-api.php b/includes/class-api.php index 86bd3a2f3..62b00e0f1 100644 --- a/includes/class-api.php +++ b/includes/class-api.php @@ -67,41 +67,6 @@ class ConstantContact_API { */ private string $last_error = ''; - /** - * Body value. - * @since 2.0.0 - * @var string - */ - private string $body = ''; - - /** - * Host value. - * @since 2.0.0 - * @var string - */ - private string $host = ''; - - /** - * Status code for a request - * @since 2.0.0 - * @var int - */ - private int $status_code = 200; - - /** - * Session callback value. - * @since 2.0.0 - * @var null - */ - private $session_callback = null; - - /** - * PKCE - * @since 2.0.0 - * @var bool - */ - public bool $PKCE = true; - /** * Scopes for authorization usage. * @since 2.0.0 @@ -159,10 +124,13 @@ public function __construct( object $plugin ) { } /** + * Init * * @since 1.0.0 + * + * @throws Exception */ - public function ctct_init() { + public function ctct_init(): bool { // Early exit for heartbeat API. if ( ! empty( $_POST['action'] ) && 'heartbeat' === sanitize_text_field( $_POST['action'] ) ) { @@ -220,6 +188,8 @@ public function ctct_init() { update_option( 'ctct_access_token_timestamp', time() ); } } + + return true; } /** @@ -227,9 +197,11 @@ public function ctct_init() { * * @since 1.0.0 * - * @return object ConstantContact_API. + * @throws Exception + * + * @return object ConstantContact_Client. */ - public function cc() { + public function cc(): ConstantContact_Client { return new ConstantContact_Client( $this->get_api_token() ); } @@ -238,9 +210,11 @@ public function cc() { * * @since 1.0.0 * + * @throws Exception + * * @return string Access API token. */ - public function get_api_token() { + public function get_api_token(): string { $token = ''; // Fetch current access token, expired or not. @@ -283,10 +257,11 @@ public function get_api_token() { /** * Exchange an authorization code for an access token. - * Make this call by passing in the code present when the account owner is redirected back to you. - * The response will contain an 'access_token' and 'refresh_token' * - * @param array of get parameters passed to redirect URL + * The API response will contain an 'access_token' and 'refresh_token' + * + * @throws Exception + * @return bool */ public function acquire_access_token(): bool { @@ -323,7 +298,6 @@ public function acquire_access_token(): bool { $parsed_code_state = array_values( $parsed_code_state ); if ( empty( $parsed_code_state[0] ) || empty( $parsed_code_state[1] ) ) { - $this->status_code = 0; $this->last_error = 'Invalid state or auth code'; add_filter( 'constant_contact_force_logging', '__return_true' ); constant_contact_maybe_log_it( 'Error: ', $this->last_error ); @@ -337,7 +311,6 @@ public function acquire_access_token(): bool { $expected_state = get_option( 'CtctConstantContactState' ); if ( ( $state ?? 'undefined' ) != $expected_state ) { - $this->status_code = 0; $this->last_error = 'state is not correct'; add_filter( 'constant_contact_force_logging', '__return_true' ); constant_contact_maybe_log_it( 'Error: ', $this->last_error ); @@ -405,11 +378,13 @@ public function acquire_access_token(): bool { /** * Refresh the access token. + * + * @since 2.0.0 + * * @return array * @throws Exception - * @since 2.0.0 */ - public function refresh_token() { + public function refresh_token(): array { $status = []; $failures = (int) get_option( 'ctct_refresh_failures', 0 ); @@ -479,7 +454,7 @@ public function refresh_token() { // Distinguish between a definitive auth failure and a transient error. // Only require manual reconnect for invalid_grant (revoked/expired refresh // token) or after 5 consecutive failures of any kind. - if ( false !== strpos( $this->last_error, 'invalid_grant' ) ) { + if ( str_contains( $this->last_error, 'invalid_grant' ) ) { add_filter( 'constant_contact_force_logging', '__return_true' ); constant_contact_maybe_log_it( 'Refresh Token:', 'Refresh token revoked (invalid_grant). Manual reconnect required.' ); constant_contact_set_needs_manual_reconnect( 'true' ); @@ -515,8 +490,11 @@ public function refresh_token() { * Generate the URL an account owner would use to allow your app * to access their account. * After visiting the URL, the account owner is prompted to log in and allow your app to access their account. - * They are then redirected to your redirect URL with the authorization code appended as a query parameter. e.g.: - * http://localhost:8888/?code={authorization_code} + * + * They are then redirected to your redirect URL with the authorization code appended as a query parameter. e.g.: http://localhost:8888/?code={authorization_code} + * + * @throws Exception + * @return string */ public function get_authorization_url(): string { @@ -556,8 +534,10 @@ public function get_authorization_url(): string { /** * Set our authorization headers. - * @return string[] + * * @since 2.0.0 + * + * @return array */ private function set_authorization(): array { @@ -567,9 +547,7 @@ private function set_authorization(): array { // Base64 encode it $credentials = base64_encode( $auth ); // Create and set the Authorization header to use the encoded credentials - $headers = [ 'Authorization: Basic ' . $credentials, 'cache-control: no-cache' ]; - - return $headers; + return [ 'Authorization: Basic ' . $credentials, 'cache-control: no-cache' ]; } /** @@ -577,16 +555,12 @@ private function set_authorization(): array { * * @since 1.0.0 * - * @return boolean If connected. + * @throws Exception + * + * @return bool If connected. */ - public function is_connected() { - static $token = null; - - if ( constant_contact()->get_connect()->e_get( '_ctct_access_token' ) ) { - $token = constant_contact()->get_connect()->e_get( '_ctct_access_token' ) ? true : false; - } - - return $token; + public function is_connected(): bool { + return (bool) constant_contact()->get_connect()->e_get( '_ctct_access_token' ); } /** @@ -606,7 +580,6 @@ private function exec( $url, $options, $request_type = '' ): bool { $response = wp_safe_remote_post( $url, $options ); $this->last_error = ''; - $this->status_code = 0; add_filter( 'constant_contact_force_logging', '__return_true' ); @@ -650,7 +623,7 @@ private function exec( $url, $options, $request_type = '' ): bool { constant_contact()->get_connect()->e_set( '_ctct_refresh_token', $data['refresh_token'] ); constant_contact()->get_connect()->e_set( '_ctct_expires_in', (string) $data['expires_in'] ); - $this->access_token = $data['access_token'] ?? ''; + $this->access_token = $data['access_token']; $this->refresh_token = $data['refresh_token'] ?? ''; $this->expires_in = $data['expires_in'] ?? ''; @@ -674,7 +647,6 @@ private function exec( $url, $options, $request_type = '' ): bool { return isset( $data['access_token'], $data['refresh_token'] ); } } else { - $this->status_code = 0; $this->last_error = $response->get_error_message(); add_filter( 'constant_contact_force_logging', '__return_true' ); constant_contact_maybe_log_it( 'Error: ', $this->last_error ); @@ -689,8 +661,9 @@ private function exec( $url, $options, $request_type = '' ): bool { * @since 1.0.0 * * @return array Current connected ctct account info. + * @throws Exception */ - public function get_account_info() { + public function get_account_info(): array { if ( ! $this->is_connected() ) { return []; @@ -750,8 +723,9 @@ public function get_account_info() { * @since 1.0.0 * * @return array Current connect ctct account contacts. + * @throws Exception */ - public function get_contacts() { + public function get_contacts(): array { if ( ! $this->is_connected() ) { return []; } @@ -799,14 +773,16 @@ public function get_contacts() { * request body to determine if it should create an new contact or update * an existing contact. * + * @since 1.0.0 + * @since 1.3.0 Added $form_id parameter + * * @param array $new_contact New contact data. * @param int $form_id ID of the form being processed. * * @return array Current connect contact. - * @since 1.3.0 Added $form_id parameter. - * @since 1.0.0 + * @throws Exception */ - public function add_contact( $new_contact = [], $form_id = 0 ) { + public function add_contact( array $new_contact = [], int $form_id = 0 ): array { if ( ! isset( $new_contact['email'] ) ) { return []; @@ -894,13 +870,13 @@ public function add_contact( $new_contact = [], $form_id = 0 ) { * @since 1.3.0 Added $form_id parameter. * * @param string|array $list List name(s). + * @param string $email Email to be used. * @param array $user_data User data. - * @param string $email email to be updated. * @param string $form_id Form ID being processed. * * @return mixed Response from API. */ - public function create_update_contact( $list, $email, $user_data, $form_id ) { + public function create_update_contact( $list, $email, $user_data, $form_id ): mixed { $contact = []; $contact['email_address'] = sanitize_text_field( $email ); @@ -1040,7 +1016,7 @@ public function set_contact_properties( $contact, $user_data, $form_id, $updated $new_custom_field = ''; $contact['custom_fields'] = []; // @todo Fix me. - if ( false !== strpos( $original, 'custom___' ) && $should_include ) { + if ( str_contains( $original, 'custom___' ) && $should_include ) { $custom_field_name .= $custom_field['name'] . ': '; } @@ -1093,10 +1069,12 @@ public function set_contact_properties( $contact, $user_data, $form_id, $updated * * @since 1.0.0 * + * @throws Exception + * * @param bool $force_skip_cache Whether or not to skip cache. * @return array Current connect ctct lists. */ - public function get_lists( bool $force_skip_cache = false ) { + public function get_lists( bool $force_skip_cache = false ): array { if ( ! $this->is_connected() ) { return []; @@ -1164,9 +1142,9 @@ public function get_lists( bool $force_skip_cache = false ) { * @param string $old_ids_string Comma separated list of old (v2 API) list ids. * @param bool $force_skip_cache Whether or not to skip cache. * - * @return array API v2 to v3 List ID cross references. + * @return false|array API v2 to v3 List ID cross references. */ - public function get_v2_list_id_x_refs( string $old_ids_string, bool $force_skip_cache = false ) { + public function get_v2_list_id_x_refs( string $old_ids_string, bool $force_skip_cache = false ): false|array { if ( ! $this->is_connected() ) { return []; @@ -1208,10 +1186,12 @@ public function get_v2_list_id_x_refs( string $old_ids_string, bool $force_skip_ * * @since 1.0.0 * + * @throws Exception + * * @param string $id List ID. - * @return mixed + * @return array|false */ - public function get_list( string $id ) { + public function get_list( string $id ): array|false { if ( ! esc_attr( $id ) ) { return []; @@ -1264,10 +1244,12 @@ public function get_list( string $id ) { * * @since 1.0.0 * - * @param array $new_list API data for new list. + * @throws Exception + * + * @param array $new_list API data for new list. * @return array Current connect ctct lists. */ - public function add_list( $new_list = [] ) { + public function add_list( array $new_list = [] ): array { if ( empty( $new_list ) ) { return []; @@ -1329,7 +1311,7 @@ public function add_list( $new_list = [] ) { } catch ( Exception $ex ) { $error = new stdClass(); $error->error_key = get_class( $ex ); - $error->error_message = $ex->xdebug_message; + $error->error_message = $ex->getMessage(); add_filter( 'constant_contact_force_logging', '__return_true' ); constant_contact_forms_maybe_set_exception_notice( $ex ); @@ -1347,10 +1329,12 @@ public function add_list( $new_list = [] ) { * * @since 1.0.0 * + * @throws Exception + * * @param array $updated_list api data for list. * @return array current connect ctct list */ - public function update_list( array $updated_list = [] ) { + public function update_list( array $updated_list = [] ): array { $return_list = false; @@ -1403,10 +1387,12 @@ public function update_list( array $updated_list = [] ) { * * @since 1.0.0 * + * @throws Exception + * * @param array $updated_list API data for list. * @return mixed Current connect ctct list. */ - public function delete_list( array $updated_list = [] ) { + public function delete_list( array $updated_list = [] ): mixed { if ( ! isset( $updated_list['id'] ) ) { return false; @@ -1449,7 +1435,7 @@ public function delete_list( array $updated_list = [] ) { * @since 2022-10-24 * @return string Settings tab URL. */ - public function get_settings_link( $settings_tab = 'ctct_options_settings_general' ) { + public function get_settings_link( $settings_tab = 'ctct_options_settings_general' ): string { return add_query_arg( [ @@ -1465,17 +1451,12 @@ public function get_settings_link( $settings_tab = 'ctct_options_settings_genera * * @since 1.0.0 * + * @throws Exception + * * @param bool $as_parts If true return an array. - * @return mixed + * @return string|array */ - public function get_disclosure_info( $as_parts = false ) { - /* - * [ - * [name] => Business Name - * [address] => 555 Business Place Ln., Beverly Hills, CA, 90210 - * ] - */ - + public function get_disclosure_info( bool $as_parts = false ): string|array { static $address_fields = [ 'address_line1', 'address_line2', 'address_line3', 'city', 'state_code', 'postal_code' ]; // Grab disclosure info from the API. @@ -1526,6 +1507,7 @@ public function get_disclosure_info( $as_parts = false ) { * Generate code_verifier and code_challenge for rfc7636 PKCE. * https://datatracker.ietf.org/doc/html/rfc7636#appendix-B * + * @throws Exception * @return array [code_verifier, code_challenge]. */ private function code_challenge( ?string $code_verifier = null ): array { @@ -1547,52 +1529,21 @@ private function code_challenge( ?string $code_verifier = null ): array { return [ $code, constant_contact()->get_api_utility()->base64url_encode( pack( 'H*', hash( 'sha256', $code ) ) ) ]; } - /** - * Handle user session details. - * - * Not used. - * - * @since 2.0.0 - * - * @param string $key - * @param string|null $value - * - * @return mixed|string - */ - public function session( string $key, ?string $value ) { - if ( $this->session_callback ) { - return call_user_func( $this->session_callback, $key, $value ); - } - if ( null === $value ) { - $value = get_user_meta( $this->this_user_id, $key, true ); - delete_user_meta( $this->this_user_id, $key, $value ); - - return $value; - } - - update_user_meta( $this->this_user_id, $key, $value ); - - return $value; - } - /** * Check if a submission has note data in place. * * @since 2.0.0 * * @param array $submission_data Array of form data. + * * @return bool */ - private function has_note( $submission_data ) { - if ( ! is_array( $submission_data ) ) { - return false; - } - + private function has_note( array $submission_data ): bool { $keys = array_keys( $submission_data ); $has_text_area = false; foreach( $keys as $key ) { if ( - false !== strpos( $key, 'custom_text_area' ) && + str_contains( $key, 'custom_text_area' ) && ! empty( $submission_data[ $key ]['val'] ) ) { $has_text_area = true; @@ -1610,10 +1561,10 @@ private function has_note( $submission_data ) { * @param $submission_data * @return string */ - private function get_note_content( $submission_data ) { + private function get_note_content( $submission_data ): string { $note = ''; foreach ( $submission_data as $key => $data ) { - if ( false !== strpos( $key, 'custom_text_area' ) ) { + if ( str_contains( $key, 'custom_text_area' ) ) { $note .= $data['val']; break; } @@ -1629,7 +1580,7 @@ private function get_note_content( $submission_data ) { * @param string $type API request type. * @param array $request The request. */ - public function log_missed_api_request( string $type, array $request ) { + public function log_missed_api_request( string $type, array $request ): void { $missed_api_requests = get_option( 'ctct_missed_api_requests', [] ); $missed_api_requests[][ $type ] = $request; update_option( 'ctct_missed_api_requests', $missed_api_requests ); @@ -1642,7 +1593,7 @@ public function log_missed_api_request( string $type, array $request ) { * * @since 2.3.0 */ - public function clear_missed_api_requests() { + public function clear_missed_api_requests(): void { // @TODO Make this compatible with other interactions besides just contact adds. // For now we can focus on just contact. @@ -1698,7 +1649,7 @@ public function clear_missed_api_requests() { * * @param int $form_id Form ID to use. */ - protected function api_errors_admin_email( int $form_id = 0 ) { + protected function api_errors_admin_email( int $form_id = 0 ): void { $send_to_addresses[] = get_option( 'admin_email' ); if ( $form_id ) { $custom = get_post_meta( $form_id, '_ctct_email_settings', true ); @@ -1715,7 +1666,7 @@ protected function api_errors_admin_email( int $form_id = 0 ) { $content = sprintf( $content, sprintf( - '', + '', get_bloginfo( 'url' ) ), $title, @@ -1747,7 +1698,7 @@ protected function api_errors_admin_email( int $form_id = 0 ) { * * @return string */ - public function set_email_type() { + public function set_email_type(): string { return 'text/html'; } } diff --git a/includes/class-attached-lists-field.php b/includes/class-attached-lists-field.php index 0e3988eb4..bf394630e 100644 --- a/includes/class-attached-lists-field.php +++ b/includes/class-attached-lists-field.php @@ -8,7 +8,7 @@ class ConstantContact_Attached_Lists_Field { /** * Current version number */ - const VERSION = '1.0.0'; + const string VERSION = '1.0.0'; /** * CMB2_Field object @@ -39,7 +39,7 @@ public function __construct() { * Add a CMB custom field to allow for the selection of multiple posts * attached to a single page. */ - public function render( $field, $escaped_value, $object_id, $object_type, $field_type ) { + public function render( $field, $escaped_value, $object_id, $object_type, $field_type ): void { self::setup_scripts(); $this->field = $field; $this->do_type_label = false; @@ -189,7 +189,7 @@ public function render( $field, $escaped_value, $object_id, $object_type, $field * @return void * @since 2.6.0 */ - protected function display_retrieved( $objects, $attached ) { + protected function display_retrieved( $objects, $attached ): void { $count = 0; // Loop through our posts as list items @@ -213,7 +213,7 @@ protected function display_retrieved( $objects, $attached ) { * @return array * @since 2.6.0 */ - protected function display_attached( $attached_lists ) { + protected function display_attached( $attached_lists ): array { $ids = []; // Remove any empty values @@ -243,7 +243,7 @@ protected function display_attached( $attached_lists ) { return $ids; } - protected function get_object_by_list_id( $list_id ) { + protected function get_object_by_list_id( $list_id ): WP_Post|null|false { if ( $this->doing_search() ) { return false; } @@ -272,7 +272,7 @@ protected function get_object_by_list_id( $list_id ) { * @return void * @since 2.6.0 */ - public function list_item( $object, $li_class, $icon_class = 'dashicons-plus' ) { + public function list_item( $object, $li_class, $icon_class = 'dashicons-plus' ): void { // Build our list item printf( '
  • %3$s
  • ', @@ -286,12 +286,13 @@ public function list_item( $object, $li_class, $icon_class = 'dashicons-plus' ) /** * Get ID for the object. * + * @since 2.6.0 + * * @param mixed $object Post or User * - * @return int The object ID. - * @since 2.6.0 + * @return int The object ID. */ - public function get_id( $object ) { + public function get_id( $object ): int { return $object->ID; } @@ -307,7 +308,7 @@ public function get_list_id_by_object( $object ) { * @return mixed Post or User if found. * @since 2.6.0 */ - public function get_object( $id ) { + public function get_object( $id ): WP_Post|false { return get_post( absint( $id ) ); } @@ -320,7 +321,7 @@ public function get_object( $id ) { * @return array Array of attached object ids. * @since 2.6.0 */ - public function get_all_objects( $args, $attached = [] ) { + public function get_all_objects( $args, $attached = [] ): array { $objects = $this->get_objects( $args ); $attached_objects = []; @@ -352,14 +353,14 @@ public function get_all_objects( $args, $attached = [] ) { * @return array Array of results. * @since 2.6.0 */ - public function get_objects( $args ) { + public function get_objects( $args ): array { return call_user_func( 'get_posts', $args ); } /** * Enqueue admin scripts for our attached posts field */ - protected static function setup_scripts() { + protected static function setup_scripts(): void { static $once = false; $url = constant_contact::url() . 'assets/js/'; @@ -393,7 +394,7 @@ protected static function setup_scripts() { /** * Add the find posts div via a hook so we can relocate it manually */ - public function add_find_posts_div() { + public function add_find_posts_div(): void { // `find_posts_div` -> Outputs the modal window used for attaching media to posts or pages in the media-listing screen. add_action( 'wp_footer', 'find_posts_div' ); } @@ -421,7 +422,7 @@ public function sanitize( $sanitized_val, $val ) { * @return void * @since 2.6.0 */ - public function ajax_find_posts() { + public function ajax_find_posts(): void { if ( $this->doing_search() ) { add_action( 'pre_get_posts', [ $this, 'modify_query' ] ); } @@ -435,7 +436,7 @@ public function ajax_find_posts() { * @return void * @since 2.6.0 */ - public function modify_query( $query ) { + public function modify_query( $query ): void { $types = $_POST['search_types']; $types = is_array( $types ) ? array_map( 'esc_attr', $types ) : esc_attr( $types ); $query->set( 'post_type', $types ); @@ -464,7 +465,7 @@ public function modify_query( $query ) { * @since 2.6.0 * @return bool */ - protected function doing_search() { + protected function doing_search(): bool { if ( defined( 'DOING_AJAX' ) && DOING_AJAX diff --git a/includes/class-beaver-builder.php b/includes/class-beaver-builder.php index 061be50c3..ab67c75db 100644 --- a/includes/class-beaver-builder.php +++ b/includes/class-beaver-builder.php @@ -21,18 +21,18 @@ class ConstantContact_Beaver_Builder { * Parent plugin class. * * @since 1.11.0 - * @var object + * @var Constant_Contact */ - protected $plugin; + protected Constant_Contact $plugin; /** * Constructor. * * @since 1.11.0 * - * @param object $plugin Parent plugin. + * @param Constant_Contact $plugin Parent plugin. */ - public function __construct( $plugin ) { + public function __construct( Constant_Contact $plugin ) { $this->plugin = $plugin; if ( class_exists( 'FLBuilder' ) ) { add_action( 'init', [ $this, 'register_bb_modules' ] ); @@ -44,7 +44,7 @@ public function __construct( $plugin ) { * * @since 1.10.0 */ - public function register_bb_modules() { + public function register_bb_modules(): void { FLBuilder::register_module( 'CCForm', [ diff --git a/includes/class-block.php b/includes/class-block.php index 41bf33461..a6979faf0 100644 --- a/includes/class-block.php +++ b/includes/class-block.php @@ -21,18 +21,18 @@ class ConstantContact_Block { * Parent plugin class. * * @since 1.5.0 - * @var object + * @var Constant_Contact */ - protected object $plugin; + protected Constant_Contact $plugin; /** * Constructor. * * @since 1.5.0 * - * @param object $plugin Parent plugin. + * @param Constant_Contact $plugin Parent plugin. */ - public function __construct( object $plugin ) { + public function __construct( Constant_Contact $plugin ) { $this->plugin = $plugin; add_action( 'init', [ $this, 'register_blocks' ] ); @@ -44,7 +44,7 @@ public function __construct( object $plugin ) { * @author Eric Fuller * @since 1.5.0 */ - public function register_blocks() { + public function register_blocks(): void { register_block_type( plugin_dir_path( dirname( __FILE__ ) ) . 'build', [ 'render_callback' => [ $this, 'display_single_contact_form' ] ] @@ -60,7 +60,7 @@ public function register_blocks() { * @param array $attributes The block attributes. * @return string */ - public function display_single_contact_form( array $attributes ) : string { + public function display_single_contact_form( array $attributes ): string { if ( empty( $attributes['selectedForm'] ) ) { return wpautop( esc_html__( 'Select a form to see a preview', 'constant-contact-forms' ) ); } diff --git a/includes/class-builder-fields.php b/includes/class-builder-fields.php index b45b62a57..447ace2a1 100644 --- a/includes/class-builder-fields.php +++ b/includes/class-builder-fields.php @@ -70,7 +70,7 @@ public function __construct( object $plugin ) { * * @since 1.0.0 */ - public function init() { + public function init(): void { add_action( 'init', [ $this, 'hooks' ] ); add_action( 'init', [ $this, 'init_field_defaults' ] ); } @@ -80,7 +80,7 @@ public function init() { * * @since 1.0.0 */ - public function hooks() { + public function hooks(): void { global $pagenow; if ( ! $pagenow ) { @@ -122,7 +122,7 @@ public function hooks() { * * @since 1.6.0 */ - public function init_field_defaults() { + public function init_field_defaults():void { $this->defaults['fields'] = [ 'email' => [ @@ -208,7 +208,7 @@ public function init_field_defaults() { * * @since 1.6.0 */ - public function add_placeholders_to_js() { + public function add_placeholders_to_js(): void { wp_add_inline_script( 'ctct_form', 'const ctct_admin_placeholders = ' . json_encode( $this->filtered['placeholders'] ), 'before' ); } @@ -217,7 +217,7 @@ public function add_placeholders_to_js() { * * @since 1.0.0 */ - public function constant_contact_list_metabox() { + public function constant_contact_list_metabox(): void { $list_metabox = new_cmb2_box( [ @@ -239,7 +239,7 @@ public function constant_contact_list_metabox() { [ 'name' => esc_html__( 'No Lists Found', 'constant-contact-forms' ), 'desc' => sprintf( - '
    %s', + '%2$s', esc_url( admin_url( 'edit.php?post_type=ctct_lists' ) ), esc_html__( 'Create a List', 'constant-contact-forms' ) ), @@ -284,7 +284,7 @@ public function constant_contact_list_metabox() { * * @since 1.0.0 */ - public function description_metabox() { + public function description_metabox(): void { $description_metabox = new_cmb2_box( [ @@ -325,7 +325,7 @@ public function description_metabox() { * * @since 1.0.0 */ - public function opt_ins_metabox() { + public function opt_ins_metabox(): void { $options_metabox = new_cmb2_box( [ @@ -429,7 +429,7 @@ public function opt_ins_metabox() { * * @since 1.4.0 */ - public function custom_form_css_metabox() { + public function custom_form_css_metabox(): void { $custom_css_metabox = new_cmb2_box( [ 'id' => 'ctct_1_custom_form_css_metabox', @@ -562,7 +562,7 @@ public function custom_form_css_metabox() { * * @since 1.4.0 */ - public function custom_input_css_metabox() { + public function custom_input_css_metabox(): void { $custom_css_metabox = new_cmb2_box( [ 'id' => 'ctct_1_custom_input_css_metabox', @@ -694,16 +694,16 @@ public function custom_input_css_metabox() { * * @param object $options_metabox CMB2 options metabox object. */ - public function show_optin_connected_fields( object $options_metabox ) { + public function show_optin_connected_fields( object $options_metabox ): void { $overall_description = sprintf( - '

    %s %s

    ', + '

    %1$s %2$s

    ', esc_html__( 'Enabling this option will require users to check a box to be added to your list.', 'constant-contact-forms' ), sprintf( - '%s', + '%2$s', 'https://knowledgebase.constantcontact.com/email-digital-marketing/articles/KnowledgeBase/18260-Add-email-opt-in-to-a-WordPress-Form-created-with-the-Constant-Contact-plugin', esc_html__( 'Learn more', 'constant-contact-forms' ) ) @@ -729,7 +729,7 @@ public function show_optin_connected_fields( object $options_metabox ) { * * @param object $options_metabox CMB2 options metabox object. */ - public function show_enable_show_checkbox_field( object $options_metabox ) { + public function show_enable_show_checkbox_field( object $options_metabox ): void { $description = esc_html__( 'Add a checkbox so subscribers can opt-in to your email list.', 'constant-contact-forms' ); $description .= '
    '; @@ -752,7 +752,7 @@ public function show_enable_show_checkbox_field( object $options_metabox ) { * * @param object $options_metabox CMB2 options metabox object. */ - public function show_affirmation_field( object $options_metabox ) { + public function show_affirmation_field( object $options_metabox ): void { $business_name = get_bloginfo( 'name' ); $business_name = ( $business_name ) ?: esc_html__( 'Your Business Name', 'constant-contact-forms' ); @@ -773,7 +773,7 @@ public function show_affirmation_field( object $options_metabox ) { * * @since 1.0.0 */ - public function fields_metabox() { + public function fields_metabox(): void { $fields_metabox = new_cmb2_box( [ @@ -872,16 +872,18 @@ public function fields_metabox() { * * @since 2.0.0 * + * @throws Exception + * * @param array $field_args * @param CMB2_Field $field */ - public function unique_label_messaging( array $field_args, CMB2_Field $field ) { + public function unique_label_messaging( array $field_args, CMB2_Field $field ): void { printf( - '

    %s

    ', + '

    %1$s

    ', esc_html__( '"Custom Text Field" labels are used for custom fields and need to be unique.', 'constant-contact-forms' ) ); printf( - '

    %s

    ', + '

    %1$s

    ', sprintf( // translators: Placeholders are for html link markup. esc_html__( 'Custom fields created within Constant Contact with field type "%1$sdate field%2$s" are not supported.', 'constant-contact-forms' ), @@ -915,7 +917,7 @@ public function unique_label_messaging( array $field_args, CMB2_Field $field ) { * * @since 1.1.0 */ - public function generated_shortcode() { + public function generated_shortcode(): void { $generated = new_cmb2_box( [ 'id' => 'ctct_2_generated_metabox', @@ -945,7 +947,7 @@ public function generated_shortcode() { * * @since 1.4.0 */ - public function email_settings() { + public function email_settings(): void { $email_settings = new_cmb2_box( [ @@ -982,7 +984,7 @@ public function email_settings() { * * @since 2.3.0 */ - public function address_settings() { + public function address_settings(): void { $address_settings = new_cmb2_box( [ @@ -1038,7 +1040,7 @@ public function address_settings() { * @param CMB2 $cmb * @return bool */ - public function show_address_metabox( CMB2 $cmb ) : bool { + public function show_address_metabox( CMB2 $cmb ): bool { $data = get_post_meta( $cmb->object_id(), 'custom_fields_group', true ); if ( empty( $data ) ) { return false; @@ -1056,7 +1058,7 @@ public function show_address_metabox( CMB2 $cmb ) : bool { * * @return array */ - public function get_individual_address_fields() : array { + public function get_individual_address_fields(): array { return [ 'country' => esc_html__( 'Country', 'constant-contact-forms' ), 'street' => esc_html__( 'Street', 'constant-contact-forms' ), @@ -1071,7 +1073,7 @@ public function get_individual_address_fields() : array { * * @since 1.5.0 */ - public function add_css_reset_metabox() { + public function add_css_reset_metabox(): void { $reset_css_metabox = new_cmb2_box( [ @@ -1103,7 +1105,7 @@ public function add_css_reset_metabox() { * * @param object $field The CMB2 field object. */ - public function render_reset_css_button( object $field ) { + public function render_reset_css_button( object $field ): void { ?>