ags); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Returns the name of the field. * * @param resource $statement A valid OCI statement identifier. * @param mixed $field Can be the field's index (1-based) or name. * @return string Returns the name as a strings. * @throws Oci8Exception * */ function oci_field_name($statement, $field): string { error_clear_last(); $result = \oci_field_name($statement, $field); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Returns precision of the field. * * For FLOAT columns, precision is nonzero and scale is -127. * If precision is 0, then column is NUMBER. Else it's * NUMBER(precision, scale). * * @param resource $statement A valid OCI statement identifier. * @param mixed $field Can be the field's index (1-based) or name. * @return int Returns the precision as an integers. * @throws Oci8Exception * */ function oci_field_precision($statement, $field): int { error_clear_last(); $result = \oci_field_precision($statement, $field); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Returns the scale of the column with field index. * * For FLOAT columns, precision is nonzero and scale is -127. * If precision is 0, then column is NUMBER. Else it's * NUMBER(precision, scale). * * @param resource $statement A valid OCI statement identifier. * @param mixed $field Can be the field's index (1-based) or name. * @return int Returns the scale as an integers. * @throws Oci8Exception * */ function oci_field_scale($statement, $field): int { error_clear_last(); $result = \oci_field_scale($statement, $field); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Returns the size of a field. * * @param resource $statement A valid OCI statement identifier. * @param mixed $field Can be the field's index (1-based) or name. * @return int Returns the size of a field in bytess. * @throws Oci8Exception * */ function oci_field_size($statement, $field): int { error_clear_last(); $result = \oci_field_size($statement, $field); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Returns Oracle's raw "SQLT" data type of the field. * * If you want a field's type name, then use oci_field_type instead. * * @param resource $statement A valid OCI statement identifier. * @param mixed $field Can be the field's index (1-based) or name. * @return int Returns Oracle's raw data type as a numbers. * @throws Oci8Exception * */ function oci_field_type_raw($statement, $field): int { error_clear_last(); $result = \oci_field_type_raw($statement, $field); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Returns a field's data type name. * * @param resource $statement A valid OCI statement identifier. * @param mixed $field Can be the field's index (1-based) or name. * @return mixed Returns the field data type as a strings. * @throws Oci8Exception * */ function oci_field_type($statement, $field) { error_clear_last(); $result = \oci_field_type($statement, $field); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Frees a descriptor allocated by oci_new_descriptor. * * @param resource $descriptor * @throws Oci8Exception * */ function oci_free_descriptor($descriptor): void { error_clear_last(); $result = \oci_free_descriptor($descriptor); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Frees resources associated with Oracle's cursor or statement, which was * received from as a result of oci_parse or obtained * from Oracle. * * @param resource $statement A valid OCI statement identifier. * @throws Oci8Exception * */ function oci_free_statement($statement): void { error_clear_last(); $result = \oci_free_statement($statement); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Allocates a new collection object. * * @param resource $connection An Oracle connection identifier, returned by * oci_connect or oci_pconnect. * @param string $tdo Should be a valid named type (uppercase). * @param string $schema Should point to the scheme, where the named type was created. The name * of the current user is the default value. * @return \OCI-Collection Returns a new OCICollection object. * @throws Oci8Exception * */ function oci_new_collection($connection, string $tdo, string $schema = null) { error_clear_last(); $result = \oci_new_collection($connection, $tdo, $schema); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Establishes a new connection to an Oracle server and logs on. * * Unlike oci_connect and * oci_pconnect, oci_new_connect * does not cache connections and will always return a brand-new freshly * opened connection handle. This is useful if your application needs * transactional isolation between two sets of queries. * * @param string $username The Oracle user name. * @param string $password The password for username. * @param string $connection_string Contains * the Oracle instance to connect to. It can be * an Easy Connect * string, or a Connect Name from * the tnsnames.ora file, or the name of a local * Oracle instance. * * If not specified, PHP uses * environment variables such as TWO_TASK (on Linux) * or LOCAL (on Windows) * and ORACLE_SID to determine the * Oracle instance to connect to. * * * To use the Easy Connect naming method, PHP must be linked with Oracle * 10g or greater Client libraries. The Easy Connect string for Oracle * 10g is of the form: * [//]host_name[:port][/service_name]. From Oracle * 11g, the syntax is: * [//]host_name[:port][/service_name][:server_type][/instance_name]. * Service names can be found by running the Oracle * utility lsnrctl status on the database server * machine. * * * The tnsnames.ora file can be in the Oracle Net * search path, which * includes $ORACLE_HOME/network/admin * and /etc. Alternatively * set TNS_ADMIN so * that $TNS_ADMIN/tnsnames.ora is read. Make sure * the web daemon has read access to the file. * @param string $character_set Determines * the character set used by the Oracle Client libraries. The character * set does not need to match the character set used by the database. If * it doesn't match, Oracle will do its best to convert data to and from * the database character set. Depending on the character sets this may * not give usable results. Conversion also adds some time overhead. * * If not specified, the * Oracle Client libraries determine a character set from * the NLS_LANG environment variable. * * Passing this parameter can * reduce the time taken to connect. * @param int $session_mode This * parameter is available since version PHP 5 (PECL OCI8 1.1) and accepts the * following values: OCI_DEFAULT, * OCI_SYSOPER and OCI_SYSDBA. * If either OCI_SYSOPER or * OCI_SYSDBA were specified, this function will try * to establish privileged connection using external credentials. * Privileged connections are disabled by default. To enable them you * need to set oci8.privileged_connect * to On. * * * PHP 5.3 (PECL OCI8 1.3.4) introduced the * OCI_CRED_EXT mode value. This tells Oracle to use * External or OS authentication, which must be configured in the * database. The OCI_CRED_EXT flag can only be used * with username of "/" and a empty password. * oci8.privileged_connect * may be On or Off. * * * OCI_CRED_EXT may be combined with the * OCI_SYSOPER or * OCI_SYSDBA modes. * * * OCI_CRED_EXT is not supported on Windows for * security reasons. * @return resource Returns a connection identifier. * @throws Oci8Exception * */ function oci_new_connect(string $username, string $password, string $connection_string = null, string $character_set = null, int $session_mode = null) { error_clear_last(); if ($session_mode !== null) { $result = \oci_new_connect($username, $password, $connection_string, $character_set, $session_mode); } elseif ($character_set !== null) { $result = \oci_new_connect($username, $password, $connection_string, $character_set); } elseif ($connection_string !== null) { $result = \oci_new_connect($username, $password, $connection_string); } else { $result = \oci_new_connect($username, $password); } if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Allocates a new statement handle on the specified connection. * * @param resource $connection An Oracle connection identifier, returned by * oci_connect or oci_pconnect. * @return resource Returns a new statement handle. * @throws Oci8Exception * */ function oci_new_cursor($connection) { error_clear_last(); $result = \oci_new_cursor($connection); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Allocates resources to hold descriptor or LOB locator. * * @param resource $connection An Oracle connection identifier, returned by * oci_connect or oci_pconnect. * @param int $type Valid values for type are: * OCI_DTYPE_FILE, OCI_DTYPE_LOB and * OCI_DTYPE_ROWID. * @return \OCI-Lob Returns a new LOB or FILE descriptor on success, FALSE on error. * @throws Oci8Exception * */ function oci_new_descriptor($connection, int $type = OCI_DTYPE_LOB) { error_clear_last(); $result = \oci_new_descriptor($connection, $type); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Gets the number of columns in the given statement. * * @param resource $statement A valid OCI statement identifier. * @return int Returns the number of columns as an integers. * @throws Oci8Exception * */ function oci_num_fields($statement): int { error_clear_last(); $result = \oci_num_fields($statement); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Gets the number of rows affected during statement execution. * * @param resource $statement A valid OCI statement identifier. * @return int Returns the number of rows affected as an integers. * @throws Oci8Exception * */ function oci_num_rows($statement): int { error_clear_last(); $result = \oci_num_rows($statement); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Prepares sql_text using * connection and returns the statement identifier, * which can be used with oci_bind_by_name, * oci_execute and other functions. * * Statement identifiers can be freed * with oci_free_statement or by setting the * variable to NULL. * * @param resource $connection An Oracle connection identifier, returned by * oci_connect, oci_pconnect, or oci_new_connect. * @param string $sql_text The SQL or PL/SQL statement. * * SQL statements should not end with a * semi-colon (";"). PL/SQL * statements should end with a semi-colon * (";"). * @return resource Returns a statement handle on success. * @throws Oci8Exception * */ function oci_parse($connection, string $sql_text) { error_clear_last(); $result = \oci_parse($connection, $sql_text); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Creates a persistent connection to an Oracle server and logs on. * * Persistent connections are cached and re-used between requests, resulting * in reduced overhead on each page load; a typical PHP application will have * a single persistent connection open against an Oracle server per Apache * child process (or PHP FastCGI/CGI process). See the Persistent Database * Connections section for more information. * * @param string $username The Oracle user name. * @param string $password The password for username. * @param string $connection_string Contains * the Oracle instance to connect to. It can be * an Easy Connect * string, or a Connect Name from * the tnsnames.ora file, or the name of a local * Oracle instance. * * If not specified, PHP uses * environment variables such as TWO_TASK (on Linux) * or LOCAL (on Windows) * and ORACLE_SID to determine the * Oracle instance to connect to. * * * To use the Easy Connect naming method, PHP must be linked with Oracle * 10g or greater Client libraries. The Easy Connect string for Oracle * 10g is of the form: * [//]host_name[:port][/service_name]. From Oracle * 11g, the syntax is: * [//]host_name[:port][/service_name][:server_type][/instance_name]. * Service names can be found by running the Oracle * utility lsnrctl status on the database server * machine. * * * The tnsnames.ora file can be in the Oracle Net * search path, which * includes $ORACLE_HOME/network/admin * and /etc. Alternatively * set TNS_ADMIN so * that $TNS_ADMIN/tnsnames.ora is read. Make sure * the web daemon has read access to the file. * @param string $character_set Determines * the character set used by the Oracle Client libraries. The character * set does not need to match the character set used by the database. If * it doesn't match, Oracle will do its best to convert data to and from * the database character set. Depending on the character sets this may * not give usable results. Conversion also adds some time overhead. * * If not specified, the * Oracle Client libraries determine a character set from * the NLS_LANG environment variable. * * Passing this parameter can * reduce the time taken to connect. * @param int $session_mode This * parameter is available since version PHP 5 (PECL OCI8 1.1) and accepts the * following values: OCI_DEFAULT, * OCI_SYSOPER and OCI_SYSDBA. * If either OCI_SYSOPER or * OCI_SYSDBA were specified, this function will try * to establish privileged connection using external credentials. * Privileged connections are disabled by default. To enable them you * need to set oci8.privileged_connect * to On. * * * PHP 5.3 (PECL OCI8 1.3.4) introduced the * OCI_CRED_EXT mode value. This tells Oracle to use * External or OS authentication, which must be configured in the * database. The OCI_CRED_EXT flag can only be used * with username of "/" and a empty password. * oci8.privileged_connect * may be On or Off. * * * OCI_CRED_EXT may be combined with the * OCI_SYSOPER or * OCI_SYSDBA modes. * * * OCI_CRED_EXT is not supported on Windows for * security reasons. * @return resource Returns a connection identifier. * @throws Oci8Exception * */ function oci_pconnect(string $username, string $password, string $connection_string = null, string $character_set = null, int $session_mode = null) { error_clear_last(); if ($session_mode !== null) { $result = \oci_pconnect($username, $password, $connection_string, $character_set, $session_mode); } elseif ($character_set !== null) { $result = \oci_pconnect($username, $password, $connection_string, $character_set); } elseif ($connection_string !== null) { $result = \oci_pconnect($username, $password, $connection_string); } else { $result = \oci_pconnect($username, $password); } if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Returns the data from field in the current row, * fetched by oci_fetch. * * For details on the data type mapping performed by * the OCI8 extension, see the datatypes * supported by the driver * * @param resource $statement * @param mixed $field Can be either use the column number (1-based) or the column name. * The case of the column name must be the case that Oracle meta data * describes the column as, which is uppercase for columns created * case insensitively. * @return string Returns everything as strings except for abstract types (ROWIDs, LOBs and * FILEs). * @throws Oci8Exception * */ function oci_result($statement, $field): string { error_clear_last(); $result = \oci_result($statement, $field); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Reverts all uncommitted changes for the Oracle * connection and ends the transaction. It * releases all locks held. All Oracle SAVEPOINTS * are erased. * * A transaction begins when the first SQL statement that changes data * is executed with oci_execute using * the OCI_NO_AUTO_COMMIT flag. Further data * changes made by other statements become part of the same * transaction. Data changes made in a transaction are temporary * until the transaction is committed or rolled back. Other users of * the database will not see the changes until they are committed. * * When inserting or updating data, using transactions is recommended * for relational data consistency and for performance reasons. * * @param resource $connection An Oracle connection identifier, returned by * oci_connect, oci_pconnect * or oci_new_connect. * @throws Oci8Exception * */ function oci_rollback($connection): void { error_clear_last(); $result = \oci_rollback($connection); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Returns a string with the Oracle Database version and available options * * @param resource $connection * @return string Returns the version information as a string. * @throws Oci8Exception * */ function oci_server_version($connection): string { error_clear_last(); $result = \oci_server_version($connection); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Sets the action name for Oracle tracing. * * The action name is registered with the database when the next * 'round-trip' from PHP to the database occurs, typically when an SQL * statement is executed. * * The action name can subsequently be queried from database administration * views such as V$SESSION. It can be used for * tracing and monitoring such as with V$SQLAREA * and DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE. * * The value may be retained across persistent connections. * * @param resource $connection An Oracle connection identifier, * returned by oci_connect, oci_pconnect, * or oci_new_connect. * @param string $action_name User chosen string up to 32 bytes long. * @throws Oci8Exception * */ function oci_set_action($connection, string $action_name): void { error_clear_last(); $result = \oci_set_action($connection, $action_name); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Sets a timeout limiting the maxium time a database round-trip using this connection may take. * * Each OCI8 operation may make zero or more calls to Oracle's client * library. These internal calls may then may make zero or more * round-trips to Oracle Database. If any one of those round-trips * takes more than time_out milliseconds, then the * operation is cancelled and an error is returned to the application. * * The time_out value applies to each round-trip * individually, not to the sum of all round-trips. Time spent * processing in PHP OCI8 before or after the completion of each * round-trip is not counted. * * When a call is interrupted, Oracle will attempt to clean up the * connection for reuse. This operation is allowed to run for * another time_out period. Depending on the * outcome of the cleanup, the connection may or may not be reusable. * * When persistent connections are used, the timeout value will be * retained across PHP requests. * * The oci_set_call_timeout function is available * when OCI8 uses Oracle 18 (or later) Client libraries. * * @param resource $connection An Oracle connection identifier, * returned by oci_connect, oci_pconnect, * or oci_new_connect. * @param int $time_out The maximum time in milliseconds that any single round-trip between PHP and Oracle Database may take. * @throws Oci8Exception * */ function oci_set_call_timeout($connection, int $time_out): void { error_clear_last(); $result = \oci_set_call_timeout($connection, $time_out); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Sets the client identifier used by various database components to * identify lightweight application users who authenticate as the same * database user. * * The client identifier is registered with the database when the next * 'round-trip' from PHP to the database occurs, typically when an SQL * statement is executed. * * The identifier can subsequently be queried, for example * with SELECT SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER') * FROM DUAL. Database administration views such * as V$SESSION will also contain the value. It * can be used with DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE * for tracing and can also be used for auditing. * * The value may be retained across page requests that use the same persistent connection. * * @param resource $connection An Oracle connection identifier, * returned by oci_connect, oci_pconnect, * or oci_new_connect. * @param string $client_identifier User chosen string up to 64 bytes long. * @throws Oci8Exception * */ function oci_set_client_identifier($connection, string $client_identifier): void { error_clear_last(); $result = \oci_set_client_identifier($connection, $client_identifier); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Sets the client information for Oracle tracing. * * The client information is registered with the database when the next * 'round-trip' from PHP to the database occurs, typically when an SQL * statement is executed. * * The client information can subsequently be queried from database * administration views such as V$SESSION. * * The value may be retained across persistent connections. * * @param resource $connection An Oracle connection identifier, * returned by oci_connect, oci_pconnect, * or oci_new_connect. * @param string $client_info User chosen string up to 64 bytes long. * @throws Oci8Exception * */ function oci_set_client_info($connection, string $client_info): void { error_clear_last(); $result = \oci_set_client_info($connection, $client_info); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Sets the DBOP for Oracle tracing. * * The database operation name is registered with the database when the next * 'round-trip' from PHP to the database occurs, typically when a SQL * statement is executed. * * The database operation can subsequently be queried from database administration * views such as V$SQL_MONITOR. * * The oci_set_db_operation function is available * when OCI8 uses Oracle 12 (or later) Client libraries and Oracle Database 12 (or later). * * @param resource $connection An Oracle connection identifier, * returned by oci_connect, oci_pconnect, * or oci_new_connect. * @param string $dbop User chosen string. * @throws Oci8Exception * */ function oci_set_db_operation($connection, string $dbop): void { error_clear_last(); $result = \oci_set_db_operation($connection, $dbop); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Sets the database "edition" of objects to be used by a subsequent * connections. * * Oracle Editions allow concurrent versions of applications to run * using the same schema and object names. This is useful for * upgrading live systems. * * Call oci_set_edition before calling * oci_connect, oci_pconnect * or oci_new_connect. * * If an edition is set that is not valid in the database, connection * will fail even if oci_set_edition returns success. * * When using persistent connections, if a connection with the * requested edition setting already exists, it is reused. Otherwise, * a different persistent connection is created * * @param string $edition Oracle Database edition name previously created with the SQL * "CREATE EDITION" command. * @throws Oci8Exception * */ function oci_set_edition(string $edition): void { error_clear_last(); $result = \oci_set_edition($edition); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Sets the module name for Oracle tracing. * * The module name is registered with the database when the next * 'round-trip' from PHP to the database occurs, typically when an SQL * statement is executed. * * The name can subsequently be queried from database administration * views such as V$SESSION. It can be used for * tracing and monitoring such as with V$SQLAREA * and DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE. * * The value may be retained across persistent connections. * * @param resource $connection An Oracle connection identifier, * returned by oci_connect, oci_pconnect, * or oci_new_connect. * @param string $module_name User chosen string up to 48 bytes long. * @throws Oci8Exception * */ function oci_set_module_name($connection, string $module_name): void { error_clear_last(); $result = \oci_set_module_name($connection, $module_name); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Sets the number of rows to be buffered by the Oracle Client * libraries after a successful query call * to oci_execute and for each subsequent * internal fetch request to the database. For queries returning a * large number of rows, performance can be significantly improved by * increasing the prefetch count above the * default oci8.default_prefetch * value. * * Prefetching is Oracle's efficient way of returning more than one * data row from the database in each network request. This can * result in better network and CPU utilization. The buffering of * rows is internal to OCI8 and the behavior of OCI8 fetching * functions is unchanged regardless of the prefetch count. For * example, oci_fetch_row will always return one * row. The prefetch buffer is per-statement and is not used by * re-executed statements or by other connections. * * Call oci_set_prefetch before * calling oci_execute. * * A tuning goal is to set the prefetch value to a reasonable size for * the network and database to handle. For queries returning a very * large number of rows, overall system efficiency might be better if * rows are retrieved from the database in several chunks (i.e set the * prefetch value smaller than the number of rows). This allows the * database to handle other users' statements while the PHP script is * processing the current set of rows. * * Query prefetching was introduced in Oracle 8i. REF CURSOR * prefetching was introduced in Oracle 11gR2 and occurs when PHP is * linked with Oracle 11gR2 (or later) Client libraries. * Nested cursor prefetching was * introduced in Oracle 11gR2 and requires both the Oracle Client * libraries and the database to be version 11gR2 or greater. * * Prefetching is not supported when queries contain LONG or LOB * columns. The prefetch value is ignored and single-row fetches will * be used in all the situations when prefetching is not supported. * * When using Oracle Database 12c, the prefetch * value set by PHP can be overridden by Oracle's * client oraaccess.xml configuration file. Refer * to Oracle documentation for more detail. * * @param resource $statement A valid OCI8 statement * identifier created by oci_parse and executed * by oci_execute, or a REF * CURSOR statement identifier. * @param int $rows The number of rows to be prefetched, >= 0 * @throws Oci8Exception * */ function oci_set_prefetch($statement, int $rows): void { error_clear_last(); $result = \oci_set_prefetch($statement, $rows); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } /** * Returns a keyword identifying the type of the * OCI8 statement. * * @param resource $statement A valid OCI8 statement identifier from oci_parse. * @return string Returns the type of statement as one of the * following strings. * * Statement type * * * * Return String * Notes * * * * * ALTER * * * * BEGIN * * * * CALL * Introduced in PHP 5.2.1 (PECL OCI8 1.2.3) * * * CREATE * * * * DECLARE * * * * DELETE * * * * DROP * * * * INSERT * * * * SELECT * * * * UPDATE * * * * UNKNOW. * @throws Oci8Exception * */ function oci_statement_type($statement): string { error_clear_last(); $result = \oci_statement_type($statement); if ($result === false) { throw Oci8Exception::createFromPhpError(); } return $result; } /** * Unregister the user-defined callback function registered to connection * by oci_register_taf_callback. See * OCI8 Transparent Application Failover (TAF) Support * for information. * * @param resource $connection An Oracle connection identifier. * @throws Oci8Exception * */ function oci_unregister_taf_callback($connection): void { error_clear_last(); $result = \oci_unregister_taf_callback($connection); if ($result === false) { throw Oci8Exception::createFromPhpError(); } } o, bail. if ( ! count( $emails ) ) { return false; } // Facilitate unsetting below without knowing the keys. $emails = array_flip( $emails ); /** * Filters whether to notify comment authors of their comments on their own posts. * * By default, comment authors aren't notified of their comments on their own * posts. This filter allows you to override that. * * @since 3.8.0 * * @param bool $notify Whether to notify the post author of their own comment. * Default false. * @param string $comment_id The comment ID as a numeric string. */ $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); // The comment was left by the author. if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { unset( $emails[ $author->user_email ] ); } // The author moderated a comment on their own post. if ( $author && ! $notify_author && get_current_user_id() == $post->post_author ) { unset( $emails[ $author->user_email ] ); } // The post author is no longer a member of the blog. if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { unset( $emails[ $author->user_email ] ); } // If there's no email to send the comment to, bail, otherwise flip array back around for use below. if ( ! count( $emails ) ) { return false; } else { $emails = array_flip( $emails ); } $switched_locale = switch_to_locale( get_locale() ); $comment_author_domain = ''; if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { $comment_author_domain = gethostbyaddr( $comment->comment_author_IP ); } /* * The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). * We want to reverse this for the plain text arena of emails. */ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); $comment_content = wp_specialchars_decode( $comment->comment_content ); switch ( $comment->comment_type ) { case 'trackback': /* translators: %s: Post title. */ $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */ $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; /* translators: %s: Trackback/pingback/comment author URL. */ $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; /* translators: %s: Comment text. */ $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; $notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n"; /* translators: Trackback notification email subject. 1: Site title, 2: Post title. */ $subject = sprintf( __( '[%1$s] Trackback: "%2$s"' ), $blogname, $post->post_title ); break; case 'pingback': /* translators: %s: Post title. */ $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */ $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; /* translators: %s: Trackback/pingback/comment author URL. */ $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; /* translators: %s: Comment text. */ $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; $notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n"; /* translators: Pingback notification email subject. 1: Site title, 2: Post title. */ $subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title ); break; default: // Comments. /* translators: %s: Post title. */ $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; /* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */ $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; /* translators: %s: Comment author email. */ $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; /* translators: %s: Trackback/pingback/comment author URL. */ $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; if ( $comment->comment_parent && user_can( $post->post_author, 'edit_comment', $comment->comment_parent ) ) { /* translators: Comment moderation. %s: Parent comment edit URL. */ $notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ) . "\r\n"; } /* translators: %s: Comment text. */ $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n"; /* translators: Comment notification email subject. 1: Site title, 2: Post title. */ $subject = sprintf( __( '[%1$s] Comment: "%2$s"' ), $blogname, $post->post_title ); break; } $notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n"; /* translators: %s: Comment URL. */ $notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n"; if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) { if ( EMPTY_TRASH_DAYS ) { /* translators: Comment moderation. %s: Comment action URL. */ $notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; } else { /* translators: Comment moderation. %s: Comment action URL. */ $notify_message .= sprintf( __( 'Delete it: %s' ), admin_url( "comment.php?action=delete&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; } /* translators: Comment moderation. %s: Comment action URL. */ $notify_message .= sprintf( __( 'Spam it: %s' ), admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; } $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', wp_parse_url( network_home_url(), PHP_URL_HOST ) ); if ( '' === $comment->comment_author ) { $from = "From: \"$blogname\" <$wp_email>"; if ( '' !== $comment->comment_author_email ) { $reply_to = "Reply-To: $comment->comment_author_email"; } } else { $from = "From: \"$comment->comment_author\" <$wp_email>"; if ( '' !== $comment->comment_author_email ) { $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; } } $message_headers = "$from\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; if ( isset( $reply_to ) ) { $message_headers .= $reply_to . "\n"; } /** * Filters the comment notification email text. * * @since 1.5.2 * * @param string $notify_message The comment notification email text. * @param string $comment_id Comment ID as a numeric string. */ $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); /** * Filters the comment notification email subject. * * @since 1.5.2 * * @param string $subject The comment notification email subject. * @param string $comment_id Comment ID as a numeric string. */ $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); /** * Filters the comment notification email headers. * * @since 1.5.2 * * @param string $message_headers Headers for the comment notification email. * @param string $comment_id Comment ID as a numeric string. */ $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); foreach ( $emails as $email ) { wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); } if ( $switched_locale ) { restore_previous_locale(); } return true; } endif; if ( ! function_exists( 'wp_notify_moderator' ) ) : /** * Notifies the moderator of the site about a new comment that is awaiting approval. * * @since 1.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * Uses the {@see 'notify_moderator'} filter to determine whether the site moderator * should be notified, overriding the site setting. * * @param int $comment_id Comment ID. * @return true Always returns true. */ function wp_notify_moderator( $comment_id ) { global $wpdb; $maybe_notify = get_option( 'moderation_notify' ); /** * Filters whether to send the site moderator email notifications, overriding the site setting. * * @since 4.4.0 * * @param bool $maybe_notify Whether to notify blog moderator. * @param int $comment_id The ID of the comment for the notification. */ $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); if ( ! $maybe_notify ) { return true; } $comment = get_comment( $comment_id ); $post = get_post( $comment->comment_post_ID ); $user = get_userdata( $post->post_author ); // Send to the administration and to the post author if the author can modify the comment. $emails = array( get_option( 'admin_email' ) ); if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { $emails[] = $user->user_email; } } $switched_locale = switch_to_locale( get_locale() ); $comment_author_domain = ''; if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { $comment_author_domain = gethostbyaddr( $comment->comment_author_IP ); } $comments_waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" ); /* * The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). * We want to reverse this for the plain text arena of emails. */ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); $comment_content = wp_specialchars_decode( $comment->comment_content ); switch ( $comment->comment_type ) { case 'trackback': /* translators: %s: Post title. */ $notify_message = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */ $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; /* translators: %s: Trackback/pingback/comment author URL. */ $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; $notify_message .= __( 'Trackback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; break; case 'pingback': /* translators: %s: Post title. */ $notify_message = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */ $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; /* translators: %s: Trackback/pingback/comment author URL. */ $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; $notify_message .= __( 'Pingback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; break; default: // Comments. /* translators: %s: Post title. */ $notify_message = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; /* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */ $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; /* translators: %s: Comment author email. */ $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; /* translators: %s: Trackback/pingback/comment author URL. */ $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; if ( $comment->comment_parent ) { /* translators: Comment moderation. %s: Parent comment edit URL. */ $notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ) . "\r\n"; } /* translators: %s: Comment text. */ $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; break; } /* translators: Comment moderation. %s: Comment action URL. */ $notify_message .= sprintf( __( 'Approve it: %s' ), admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) ) . "\r\n"; if ( EMPTY_TRASH_DAYS ) { /* translators: Comment moderation. %s: Comment action URL. */ $notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) ) . "\r\n"; } else { /* translators: Comment moderation. %s: Comment action URL. */ $notify_message .= sprintf( __( 'Delete it: %s' ), admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) ) . "\r\n"; } /* translators: Comment moderation. %s: Comment action URL. */ $notify_message .= sprintf( __( 'Spam it: %s' ), admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) ) . "\r\n"; $notify_message .= sprintf( /* translators: Comment moderation. %s: Number of comments awaiting approval. */ _n( 'Currently %s comment is waiting for approval. Please visit the moderation panel:', 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting ), number_format_i18n( $comments_waiting ) ) . "\r\n"; $notify_message .= admin_url( 'edit-comments.php?comment_status=moderated#wpbody-content' ) . "\r\n"; /* translators: Comment moderation notification email subject. 1: Site title, 2: Post title. */ $subject = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title ); $message_headers = ''; /** * Filters the list of recipients for comment moderation emails. * * @since 3.7.0 * * @param string[] $emails List of email addresses to notify for comment moderation. * @param int $comment_id Comment ID. */ $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); /** * Filters the comment moderation email text. * * @since 1.5.2 * * @param string $notify_message Text of the comment moderation email. * @param int $comment_id Comment ID. */ $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); /** * Filters the comment moderation email subject. * * @since 1.5.2 * * @param string $subject Subject of the comment moderation email. * @param int $comment_id Comment ID. */ $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); /** * Filters the comment moderation email headers. * * @since 2.8.0 * * @param string $message_headers Headers for the comment moderation email. * @param int $comment_id Comment ID. */ $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); foreach ( $emails as $email ) { wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); } if ( $switched_locale ) { restore_previous_locale(); } return true; } endif; if ( ! function_exists( 'wp_password_change_notification' ) ) : /** * Notifies the blog admin of a user changing password, normally via email. * * @since 2.7.0 * * @param WP_User $user User object. */ function wp_password_change_notification( $user ) { /* * Send a copy of password change notification to the admin, * but check to see if it's the admin whose password we're changing, and skip this. */ if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { /* translators: %s: User name. */ $message = sprintf( __( 'Password changed for user: %s' ), $user->user_login ) . "\r\n"; /* * The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). * We want to reverse this for the plain text arena of emails. */ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); $wp_password_change_notification_email = array( 'to' => get_option( 'admin_email' ), /* translators: Password change notification email subject. %s: Site title. */ 'subject' => __( '[%s] Password Changed' ), 'message' => $message, 'headers' => '', ); /** * Filters the contents of the password change notification email sent to the site admin. * * @since 4.9.0 * * @param array $wp_password_change_notification_email { * Used to build wp_mail(). * * @type string $to The intended recipient - site admin email address. * @type string $subject The subject of the email. * @type string $message The body of the email. * @type string $headers The headers of the email. * } * @param WP_User $user User object for user whose password was changed. * @param string $blogname The site title. */ $wp_password_change_notification_email = apply_filters( 'wp_password_change_notification_email', $wp_password_change_notification_email, $user, $blogname ); wp_mail( $wp_password_change_notification_email['to'], wp_specialchars_decode( sprintf( $wp_password_change_notification_email['subject'], $blogname ) ), $wp_password_change_notification_email['message'], $wp_password_change_notification_email['headers'] ); } } endif; if ( ! function_exists( 'wp_new_user_notification' ) ) : /** * Emails login credentials to a newly-registered user. * * A new user registration notification is also sent to admin email. * * @since 2.0.0 * @since 4.3.0 The `$plaintext_pass` parameter was changed to `$notify`. * @since 4.3.1 The `$plaintext_pass` parameter was deprecated. `$notify` added as a third parameter. * @since 4.6.0 The `$notify` parameter accepts 'user' for sending notification only to the user created. * * @param int $user_id User ID. * @param null $deprecated Not used (argument deprecated). * @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty * string (admin only), 'user', or 'both' (admin and user). Default empty. */ function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) { if ( null !== $deprecated ) { _deprecated_argument( __FUNCTION__, '4.3.1' ); } // Accepts only 'user', 'admin' , 'both' or default '' as $notify. if ( ! in_array( $notify, array( 'user', 'admin', 'both', '' ), true ) ) { return; } $user = get_userdata( $user_id ); /* * The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). * We want to reverse this for the plain text arena of emails. */ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); /** * Filters whether the admin is notified of a new user registration. * * @since 6.1.0 * * @param bool $send Whether to send the email. Default true. * @param WP_User $user User object for new user. */ $send_notification_to_admin = apply_filters( 'wp_send_new_user_notification_to_admin', true, $user ); if ( 'user' !== $notify && true === $send_notification_to_admin ) { $switched_locale = switch_to_locale( get_locale() ); /* translators: %s: Site title. */ $message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n"; /* translators: %s: User login. */ $message .= sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n"; /* translators: %s: User email address. */ $message .= sprintf( __( 'Email: %s' ), $user->user_email ) . "\r\n"; $wp_new_user_notification_email_admin = array( 'to' => get_option( 'admin_email' ), /* translators: New user registration notification email subject. %s: Site title. */ 'subject' => __( '[%s] New User Registration' ), 'message' => $message, 'headers' => '', ); /** * Filters the contents of the new user notification email sent to the site admin. * * @since 4.9.0 * * @param array $wp_new_user_notification_email_admin { * Used to build wp_mail(). * * @type string $to The intended recipient - site admin email address. * @type string $subject The subject of the email. * @type string $message The body of the email. * @type string $headers The headers of the email. * } * @param WP_User $user User object for new user. * @param string $blogname The site title. */ $wp_new_user_notification_email_admin = apply_filters( 'wp_new_user_notification_email_admin', $wp_new_user_notification_email_admin, $user, $blogname ); wp_mail( $wp_new_user_notification_email_admin['to'], wp_specialchars_decode( sprintf( $wp_new_user_notification_email_admin['subject'], $blogname ) ), $wp_new_user_notification_email_admin['message'], $wp_new_user_notification_email_admin['headers'] ); if ( $switched_locale ) { restore_previous_locale(); } } /** * Filters whether the user is notified of their new user registration. * * @since 6.1.0 * * @param bool $send Whether to send the email. Default true. * @param WP_User $user User object for new user. */ $send_notification_to_user = apply_filters( 'wp_send_new_user_notification_to_user', true, $user ); // `$deprecated` was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification. if ( 'admin' === $notify || true !== $send_notification_to_user || ( empty( $deprecated ) && empty( $notify ) ) ) { return; } $key = get_password_reset_key( $user ); if ( is_wp_error( $key ) ) { return; } $switched_locale = switch_to_user_locale( $user_id ); /* translators: %s: User login. */ $message = sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n"; $message .= __( 'To set your password, visit the following address:' ) . "\r\n\r\n"; $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), 'login' ) . "\r\n\r\n"; $message .= wp_login_url() . "\r\n"; $wp_new_user_notification_email = array( 'to' => $user->user_email, /* translators: Login details notification email subject. %s: Site title. */ 'subject' => __( '[%s] Login Details' ), 'message' => $message, 'headers' => '', ); /** * Filters the contents of the new user notification email sent to the new user. * * @since 4.9.0 * * @param array $wp_new_user_notification_email { * Used to build wp_mail(). * * @type string $to The intended recipient - New user email address. * @type string $subject The subject of the email. * @type string $message The body of the email. * @type string $headers The headers of the email. * } * @param WP_User $user User object for new user. * @param string $blogname The site title. */ $wp_new_user_notification_email = apply_filters( 'wp_new_user_notification_email', $wp_new_user_notification_email, $user, $blogname ); wp_mail( $wp_new_user_notification_email['to'], wp_specialchars_decode( sprintf( $wp_new_user_notification_email['subject'], $blogname ) ), $wp_new_user_notification_email['message'], $wp_new_user_notification_email['headers'] ); if ( $switched_locale ) { restore_previous_locale(); } } endif; if ( ! function_exists( 'wp_nonce_tick' ) ) : /** * Returns the time-dependent variable for nonce creation. * * A nonce has a lifespan of two ticks. Nonces in their second tick may be * updated, e.g. by autosave. * * @since 2.5.0 * @since 6.1.0 Added `$action` argument. * * @param string|int $action Optional. The nonce action. Default -1. * @return float Float value rounded up to the next highest integer. */ function wp_nonce_tick( $action = -1 ) { /** * Filters the lifespan of nonces in seconds. * * @since 2.5.0 * @since 6.1.0 Added `$action` argument to allow for more targeted filters. * * @param int $lifespan Lifespan of nonces in seconds. Default 86,400 seconds, or one day. * @param string|int $action The nonce action, or -1 if none was provided. */ $nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS, $action ); return ceil( time() / ( $nonce_life / 2 ) ); } endif; if ( ! function_exists( 'wp_verify_nonce' ) ) : /** * Verifies that a correct security nonce was used with time limit. * * A nonce is valid for 24 hours (by default). * * @since 2.0.3 * * @param string $nonce Nonce value that was used for verification, usually via a form field. * @param string|int $action Should give context to what is taking place and be the same when nonce was created. * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago, * 2 if the nonce is valid and generated between 12-24 hours ago. * False if the nonce is invalid. */ function wp_verify_nonce( $nonce, $action = -1 ) { $nonce = (string) $nonce; $user = wp_get_current_user(); $uid = (int) $user->ID; if ( ! $uid ) { /** * Filters whether the user who generated the nonce is logged out. * * @since 3.5.0 * * @param int $uid ID of the nonce-owning user. * @param string|int $action The nonce action, or -1 if none was provided. */ $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); } if ( empty( $nonce ) ) { return false; } $token = wp_get_session_token(); $i = wp_nonce_tick( $action ); // Nonce generated 0-12 hours ago. $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); if ( hash_equals( $expected, $nonce ) ) { return 1; } // Nonce generated 12-24 hours ago. $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); if ( hash_equals( $expected, $nonce ) ) { return 2; } /** * Fires when nonce verification fails. * * @since 4.4.0 * * @param string $nonce The invalid nonce. * @param string|int $action The nonce action. * @param WP_User $user The current user object. * @param string $token The user's session token. */ do_action( 'wp_verify_nonce_failed', $nonce, $action, $user, $token ); // Invalid nonce. return false; } endif; if ( ! function_exists( 'wp_create_nonce' ) ) : /** * Creates a cryptographic token tied to a specific action, user, user session, * and window of time. * * @since 2.0.3 * @since 4.0.0 Session tokens were integrated with nonce creation. * * @param string|int $action Scalar value to add context to the nonce. * @return string The token. */ function wp_create_nonce( $action = -1 ) { $user = wp_get_current_user(); $uid = (int) $user->ID; if ( ! $uid ) { /** This filter is documented in wp-includes/pluggable.php */ $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); } $token = wp_get_session_token(); $i = wp_nonce_tick( $action ); return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); } endif; if ( ! function_exists( 'wp_salt' ) ) : /** * Returns a salt to add to hashes. * * Salts are created using secret keys. Secret keys are located in two places: * in the database and in the wp-config.php file. The secret key in the database * is randomly generated and will be appended to the secret keys in wp-config.php. * * The secret keys in wp-config.php should be updated to strong, random keys to maximize * security. Below is an example of how the secret key constants are defined. * Do not paste this example directly into wp-config.php. Instead, have a * {@link https://api.wordpress.org/secret-key/1.1/salt/ secret key created} just * for you. * * define('AUTH_KEY', ' XakmM%G4Yt>f`z]MON'); * define('SECURE_AUTH_KEY', 'LzJ}op]mr|6+![P}Ak:uNdJCJZd>(Hx.-Mh#Tz)pCIU#uGEnfFz|f ;;eU%/U^O~'); * define('LOGGED_IN_KEY', '|i|Ux`9z7X>QYR0Z_XnZ@|'); * define('AUTH_SALT', 'eZyT)-Naw]F8CwA*VaW#q*|.)g@o}||wf~@C-YSt}(dh_r6EbI#A,y|nU2{B#JBW'); * define('SECURE_AUTH_SALT', '!=oLUTXh,QW=H `}`L|9/^4-3 STz},T(w}W*c(u`g~EJBf#8u#R{mUEZrozmm'); * define('NONCE_SALT', 'h`GXHhD>SLWVfg1(1(N{;.V!MoE(SfbA_ksP@&`+AycHcAV$+?@3q+rxV{%^VyKT'); * * Salting passwords helps against tools which has stored hashed values of * common dictionary strings. The added values makes it harder to crack. * * @since 2.5.0 * * @link https://api.wordpress.org/secret-key/1.1/salt/ Create secrets for wp-config.php * * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce). * @return string Salt value */ function wp_salt( $scheme = 'auth' ) { static $cached_salts = array(); if ( isset( $cached_salts[ $scheme ] ) ) { /** * Filters the WordPress salt. * * @since 2.5.0 * * @param string $cached_salt Cached salt for the given scheme. * @param string $scheme Authentication scheme. Values include 'auth', * 'secure_auth', 'logged_in', and 'nonce'. */ return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); } static $duplicated_keys; if ( null === $duplicated_keys ) { $duplicated_keys = array( 'put your unique phrase here' => true, ); /* * translators: This string should only be translated if wp-config-sample.php is localized. * You can check the localized release package or * https://i18n.svn.wordpress.org//branches//dist/wp-config-sample.php */ $duplicated_keys[ __( 'put your unique phrase here' ) ] = true; foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) { foreach ( array( 'KEY', 'SALT' ) as $second ) { if ( ! defined( "{$first}_{$second}" ) ) { continue; } $value = constant( "{$first}_{$second}" ); $duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] ); } } } $values = array( 'key' => '', 'salt' => '', ); if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) { $values['key'] = SECRET_KEY; } if ( 'auth' === $scheme && defined( 'SECRET_SALT' ) && SECRET_SALT && empty( $duplicated_keys[ SECRET_SALT ] ) ) { $values['salt'] = SECRET_SALT; } if ( in_array( $scheme, array( 'auth', 'secure_auth', 'logged_in', 'nonce' ), true ) ) { foreach ( array( 'key', 'salt' ) as $type ) { $const = strtoupper( "{$scheme}_{$type}" ); if ( defined( $const ) && constant( $const ) && empty( $duplicated_keys[ constant( $const ) ] ) ) { $values[ $type ] = constant( $const ); } elseif ( ! $values[ $type ] ) { $values[ $type ] = get_site_option( "{$scheme}_{$type}" ); if ( ! $values[ $type ] ) { $values[ $type ] = wp_generate_password( 64, true, true ); update_site_option( "{$scheme}_{$type}", $values[ $type ] ); } } } } else { if ( ! $values['key'] ) { $values['key'] = get_site_option( 'secret_key' ); if ( ! $values['key'] ) { $values['key'] = wp_generate_password( 64, true, true ); update_site_option( 'secret_key', $values['key'] ); } } $values['salt'] = hash_hmac( 'md5', $scheme, $values['key'] ); } $cached_salts[ $scheme ] = $values['key'] . $values['salt']; /** This filter is documented in wp-includes/pluggable.php */ return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); } endif; if ( ! function_exists( 'wp_hash' ) ) : /** * Gets hash of given string. * * @since 2.0.3 * * @param string $data Plain text to hash. * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce). * @return string Hash of $data. */ function wp_hash( $data, $scheme = 'auth' ) { $salt = wp_salt( $scheme ); return hash_hmac( 'md5', $data, $salt ); } endif; if ( ! function_exists( 'wp_hash_password' ) ) : /** * Creates a hash (encrypt) of a plain text password. * * For integration with other applications, this function can be overwritten to * instead use the other package password checking algorithm. * * @since 2.5.0 * * @global PasswordHash $wp_hasher PHPass object. * * @param string $password Plain text user password to hash. * @return string The hash string of the password. */ function wp_hash_password( $password ) { global $wp_hasher; if ( empty( $wp_hasher ) ) { require_once ABSPATH . WPINC . '/class-phpass.php'; // By default, use the portable hash from phpass. $wp_hasher = new PasswordHash( 8, true ); } return $wp_hasher->HashPassword( trim( $password ) ); } endif; if ( ! function_exists( 'wp_check_password' ) ) : /** * Checks the plaintext password against the encrypted Password. * * Maintains compatibility between old version and the new cookie authentication * protocol using PHPass library. The $hash parameter is the encrypted password * and the function compares the plain text password when encrypted similarly * against the already encrypted password to see if they match. * * For integration with other applications, this function can be overwritten to * instead use the other package password checking algorithm. * * @since 2.5.0 * * @global PasswordHash $wp_hasher PHPass object used for checking the password * against the $hash + $password. * @uses PasswordHash::CheckPassword * * @param string $password Plaintext user's password. * @param string $hash Hash of the user's password to check against. * @param string|int $user_id Optional. User ID. * @return bool False, if the $password does not match the hashed password. */ function wp_check_password( $password, $hash, $user_id = '' ) { global $wp_hasher; // If the hash is still md5... if ( strlen( $hash ) <= 32 ) { $check = hash_equals( $hash, md5( $password ) ); if ( $check && $user_id ) { // Rehash using new hash. wp_set_password( $password, $user_id ); $hash = wp_hash_password( $password ); } /** * Filters whether the plaintext password matches the encrypted password. * * @since 2.5.0 * * @param bool $check Whether the passwords match. * @param string $password The plaintext password. * @param string $hash The hashed password. * @param string|int $user_id User ID. Can be empty. */ return apply_filters( 'check_password', $check, $password, $hash, $user_id ); } /* * If the stored hash is longer than an MD5, * presume the new style phpass portable hash. */ if ( empty( $wp_hasher ) ) { require_once ABSPATH . WPINC . '/class-phpass.php'; // By default, use the portable hash from phpass. $wp_hasher = new PasswordHash( 8, true ); } $check = $wp_hasher->CheckPassword( $password, $hash ); /** This filter is documented in wp-includes/pluggable.php */ return apply_filters( 'check_password', $check, $password, $hash, $user_id ); } endif; if ( ! function_exists( 'wp_generate_password' ) ) : /** * Generates a random password drawn from the defined set of characters. * * Uses wp_rand() to create passwords with far less predictability * than similar native PHP functions like `rand()` or `mt_rand()`. * * @since 2.5.0 * * @param int $length Optional. The length of password to generate. Default 12. * @param bool $special_chars Optional. Whether to include standard special characters. * Default true. * @param bool $extra_special_chars Optional. Whether to include other special characters. * Used when generating secret keys and salts. Default false. * @return string The random password. */ function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; if ( $special_chars ) { $chars .= '!@#$%^&*()'; } if ( $extra_special_chars ) { $chars .= '-_ []{}<>~`+=,.;:/?|'; } $password = ''; for ( $i = 0; $i < $length; $i++ ) { $password .= substr( $chars, wp_rand( 0, strlen( $chars ) - 1 ), 1 ); } /** * Filters the randomly-generated password. * * @since 3.0.0 * @since 5.3.0 Added the `$length`, `$special_chars`, and `$extra_special_chars` parameters. * * @param string $password The generated password. * @param int $length The length of password to generate. * @param bool $special_chars Whether to include standard special characters. * @param bool $extra_special_chars Whether to include other special characters. */ return apply_filters( 'random_password', $password, $length, $special_chars, $extra_special_chars ); } endif; if ( ! function_exists( 'wp_rand' ) ) : /** * Generates a random non-negative number. * * @since 2.6.2 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available. * @since 6.1.0 Returns zero instead of a random number if both `$min` and `$max` are zero. * * @global string $rnd_value * * @param int $min Optional. Lower limit for the generated number. * Accepts positive integers or zero. Defaults to 0. * @param int $max Optional. Upper limit for the generated number. * Accepts positive integers. Defaults to 4294967295. * @return int A random non-negative number between min and max. */ function wp_rand( $min = null, $max = null ) { global $rnd_value; /* * Some misconfigured 32-bit environments (Entropy PHP, for example) * truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats. */ $max_random_number = 3000000000 === 2147483647 ? (float) '4294967295' : 4294967295; // 4294967295 = 0xffffffff if ( null === $min ) { $min = 0; } if ( null === $max ) { $max = $max_random_number; } // We only handle ints, floats are truncated to their integer value. $min = (int) $min; $max = (int) $max; // Use PHP's CSPRNG, or a compatible method. static $use_random_int_functionality = true; if ( $use_random_int_functionality ) { try { // wp_rand() can accept arguments in either order, PHP cannot. $_max = max( $min, $max ); $_min = min( $min, $max ); $val = random_int( $_min, $_max ); if ( false !== $val ) { return absint( $val ); } else { $use_random_int_functionality = false; } } catch ( Error $e ) { $use_random_int_functionality = false; } catch ( Exception $e ) { $use_random_int_functionality = false; } } /* * Reset $rnd_value after 14 uses. * 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value. */ if ( strlen( $rnd_value ) < 8 ) { if ( defined( 'WP_SETUP_CONFIG' ) ) { static $seed = ''; } else { $seed = get_transient( 'random_seed' ); } $rnd_value = md5( uniqid( microtime() . mt_rand(), true ) . $seed ); $rnd_value .= sha1( $rnd_value ); $rnd_value .= sha1( $rnd_value . $seed ); $seed = md5( $seed . $rnd_value ); if ( ! defined( 'WP_SETUP_CONFIG' ) && ! defined( 'WP_INSTALLING' ) ) { set_transient( 'random_seed', $seed ); } } // Take the first 8 digits for our value. $value = substr( $rnd_value, 0, 8 ); // Strip the first eight, leaving the remainder for the next call to wp_rand(). $rnd_value = substr( $rnd_value, 8 ); $value = abs( hexdec( $value ) ); // Reduce the value to be within the min - max range. $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); return abs( (int) $value ); } endif; if ( ! function_exists( 'wp_set_password' ) ) : /** * Updates the user's password with a new encrypted one. * * For integration with other applications, this function can be overwritten to * instead use the other package password checking algorithm. * * Please note: This function should be used sparingly and is really only meant for single-time * application. Leveraging this improperly in a plugin or theme could result in an endless loop * of password resets if precautions are not taken to ensure it does not execute on every page load. * * @since 2.5.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $password The plaintext new user password. * @param int $user_id User ID. */ function wp_set_password( $password, $user_id ) { global $wpdb; $hash = wp_hash_password( $password ); $wpdb->update( $wpdb->users, array( 'user_pass' => $hash, 'user_activation_key' => '', ), array( 'ID' => $user_id ) ); clean_user_cache( $user_id ); /** * Fires after the user password is set. * * @since 6.2.0 * * @param string $password The plaintext password just set. * @param int $user_id The ID of the user whose password was just set. */ do_action( 'wp_set_password', $password, $user_id ); } endif; if ( ! function_exists( 'get_avatar' ) ) : /** * Retrieves the avatar `` tag for a user, email address, MD5 hash, comment, or post. * * @since 2.5.0 * @since 4.2.0 Added the optional `$args` parameter. * @since 5.5.0 Added the `loading` argument. * @since 6.1.0 Added the `decoding` argument. * @since 6.3.0 Added the `fetchpriority` argument. * * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, * user email, WP_User object, WP_Post object, or WP_Comment object. * @param int $size Optional. Height and width of the avatar in pixels. Default 96. * @param string $default_value URL for the default image or a default type. Accepts: * - '404' (return a 404 instead of a default image) * - 'retro' (a 8-bit arcade-style pixelated face) * - 'robohash' (a robot) * - 'monsterid' (a monster) * - 'wavatar' (a cartoon face) * - 'identicon' (the "quilt", a geometric pattern) * - 'mystery', 'mm', or 'mysteryman' (The Oyster Man) * - 'blank' (transparent GIF) * - 'gravatar_default' (the Gravatar logo) * Default is the value of the 'avatar_default' option, * with a fallback of 'mystery'. * @param string $alt Optional. Alternative text to use in the avatar image tag. * Default empty. * @param array $args { * Optional. Extra arguments to retrieve the avatar. * * @type int $height Display height of the avatar in pixels. Defaults to $size. * @type int $width Display width of the avatar in pixels. Defaults to $size. * @type bool $force_default Whether to always show the default image, never the Gravatar. * Default false. * @type string $rating What rating to display avatars up to. Accepts: * - 'G' (suitable for all audiences) * - 'PG' (possibly offensive, usually for audiences 13 and above) * - 'R' (intended for adult audiences above 17) * - 'X' (even more mature than above) * Default is the value of the 'avatar_rating' option. * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. * Default null. * @type array|string $class Array or string of additional classes to add to the img element. * Default null. * @type bool $force_display Whether to always show the avatar - ignores the show_avatars option. * Default false. * @type string $loading Value for the `loading` attribute. * Default null. * @type string $fetchpriority Value for the `fetchpriority` attribute. * Default null. * @type string $decoding Value for the `decoding` attribute. * Default null. * @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. * Default empty. * } * @return string|false `` tag for the user's avatar. False on failure. */ function get_avatar( $id_or_email, $size = 96, $default_value = '', $alt = '', $args = null ) { $defaults = array( // get_avatar_data() args. 'size' => 96, 'height' => null, 'width' => null, 'default' => get_option( 'avatar_default', 'mystery' ), 'force_default' => false, 'rating' => get_option( 'avatar_rating' ), 'scheme' => null, 'alt' => '', 'class' => null, 'force_display' => false, 'loading' => null, 'fetchpriority' => null, 'decoding' => null, 'extra_attr' => '', ); if ( empty( $args ) ) { $args = array(); } $args['size'] = (int) $size; $args['default'] = $default_value; $args['alt'] = $alt; $args = wp_parse_args( $args, $defaults ); if ( empty( $args['height'] ) ) { $args['height'] = $args['size']; } if ( empty( $args['width'] ) ) { $args['width'] = $args['size']; } // Update args with loading optimized attributes. $loading_optimization_attr = wp_get_loading_optimization_attributes( 'img', $args, 'get_avatar' ); $args = array_merge( $args, $loading_optimization_attr ); if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { $id_or_email = get_comment( $id_or_email ); } /** * Allows the HTML for a user's avatar to be returned early. * * Returning a non-null value will effectively short-circuit get_avatar(), passing * the value through the {@see 'get_avatar'} filter and returning early. * * @since 4.2.0 * * @param string|null $avatar HTML for the user's avatar. Default null. * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, * user email, WP_User object, WP_Post object, or WP_Comment object. * @param array $args Arguments passed to get_avatar_url(), after processing. */ $avatar = apply_filters( 'pre_get_avatar', null, $id_or_email, $args ); if ( ! is_null( $avatar ) ) { /** This filter is documented in wp-includes/pluggable.php */ return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); } if ( ! $args['force_display'] && ! get_option( 'show_avatars' ) ) { return false; } $url2x = get_avatar_url( $id_or_email, array_merge( $args, array( 'size' => $args['size'] * 2 ) ) ); $args = get_avatar_data( $id_or_email, $args ); $url = $args['url']; if ( ! $url || is_wp_error( $url ) ) { return false; } $class = array( 'avatar', 'avatar-' . (int) $args['size'], 'photo' ); if ( ! $args['found_avatar'] || $args['force_default'] ) { $class[] = 'avatar-default'; } if ( $args['class'] ) { if ( is_array( $args['class'] ) ) { $class = array_merge( $class, $args['class'] ); } else { $class[] = $args['class']; } } // Add `loading`, `fetchpriority`, and `decoding` attributes. $extra_attr = $args['extra_attr']; if ( in_array( $args['loading'], array( 'lazy', 'eager' ), true ) && ! preg_match( '/\bloading\s*=/', $extra_attr ) ) { if ( ! empty( $extra_attr ) ) { $extra_attr .= ' '; } $extra_attr .= "loading='{$args['loading']}'"; } if ( in_array( $args['fetchpriority'], array( 'high', 'low', 'auto' ), true ) && ! preg_match( '/\bfetchpriority\s*=/', $extra_attr ) ) { if ( ! empty( $extra_attr ) ) { $extra_attr .= ' '; } $extra_attr .= "fetchpriority='{$args['fetchpriority']}'"; } if ( in_array( $args['decoding'], array( 'async', 'sync', 'auto' ), true ) && ! preg_match( '/\bdecoding\s*=/', $extra_attr ) ) { if ( ! empty( $extra_attr ) ) { $extra_attr .= ' '; } $extra_attr .= "decoding='{$args['decoding']}'"; } $avatar = sprintf( "%s", esc_attr( $args['alt'] ), esc_url( $url ), esc_url( $url2x ) . ' 2x', esc_attr( implode( ' ', $class ) ), (int) $args['height'], (int) $args['width'], $extra_attr ); /** * Filters the HTML for a user's avatar. * * @since 2.5.0 * @since 4.2.0 Added the `$args` parameter. * * @param string $avatar HTML for the user's avatar. * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, * user email, WP_User object, WP_Post object, or WP_Comment object. * @param int $size Height and width of the avatar in pixels. * @param string $default_value URL for the default image or a default type. Accepts: * - '404' (return a 404 instead of a default image) * - 'retro' (a 8-bit arcade-style pixelated face) * - 'robohash' (a robot) * - 'monsterid' (a monster) * - 'wavatar' (a cartoon face) * - 'identicon' (the "quilt", a geometric pattern) * - 'mystery', 'mm', or 'mysteryman' (The Oyster Man) * - 'blank' (transparent GIF) * - 'gravatar_default' (the Gravatar logo) * @param string $alt Alternative text to use in the avatar image tag. * @param array $args Arguments passed to get_avatar_data(), after processing. */ return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); } endif; if ( ! function_exists( 'wp_text_diff' ) ) : /** * Displays a human readable HTML representation of the difference between two strings. * * The Diff is available for getting the changes between versions. The output is * HTML, so the primary use is for displaying the changes. If the two strings * are equivalent, then an empty string will be returned. * * @since 2.6.0 * * @see wp_parse_args() Used to change defaults to user defined settings. * @uses Text_Diff * @uses WP_Text_Diff_Renderer_Table * * @param string $left_string "old" (left) version of string. * @param string $right_string "new" (right) version of string. * @param string|array $args { * Associative array of options to pass to WP_Text_Diff_Renderer_Table(). * * @type string $title Titles the diff in a manner compatible * with the output. Default empty. * @type string $title_left Change the HTML to the left of the title. * Default empty. * @type string $title_right Change the HTML to the right of the title. * Default empty. * @type bool $show_split_view True for split view (two columns), false for * un-split view (single column). Default true. * } * @return string Empty string if strings are equivalent or HTML with differences. */ function wp_text_diff( $left_string, $right_string, $args = null ) { $defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '', 'show_split_view' => true, ); $args = wp_parse_args( $args, $defaults ); if ( ! class_exists( 'WP_Text_Diff_Renderer_Table', false ) ) { require ABSPATH . WPINC . '/wp-diff.php'; } $left_string = normalize_whitespace( $left_string ); $right_string = normalize_whitespace( $right_string ); $left_lines = explode( "\n", $left_string ); $right_lines = explode( "\n", $right_string ); $text_diff = new Text_Diff( $left_lines, $right_lines ); $renderer = new WP_Text_Diff_Renderer_Table( $args ); $diff = $renderer->render( $text_diff ); if ( ! $diff ) { return ''; } $is_split_view = ! empty( $args['show_split_view'] ); $is_split_view_class = $is_split_view ? ' is-split-view' : ''; $r = "\n"; if ( $args['title'] ) { $r .= "\n"; } if ( $args['title_left'] || $args['title_right'] ) { $r .= ''; } if ( $args['title_left'] || $args['title_right'] ) { $th_or_td_left = empty( $args['title_left'] ) ? 'td' : 'th'; $th_or_td_right = empty( $args['title_right'] ) ? 'td' : 'th'; $r .= "\n"; $r .= "\t<$th_or_td_left>$args[title_left]\n"; if ( $is_split_view ) { $r .= "\t<$th_or_td_right>$args[title_right]\n"; } $r .= "\n"; } if ( $args['title_left'] || $args['title_right'] ) { $r .= "\n"; } $r .= "\n$diff\n\n"; $r .= '
$args[title]
'; return $r; } endif;