PK %�[�$��% % - class-wp-application-passwords-list-table.phpnu �[��� <?php
/**
* List Table API: WP_Application_Passwords_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 5.6.0
*/
/**
* Class for displaying the list of application password items.
*
* @since 5.6.0
*
* @see WP_List_Table
*/
class WP_Application_Passwords_List_Table extends WP_List_Table {
/**
* Gets the list of columns.
*
* @since 5.6.0
*
* @return string[] Array of column titles keyed by their column name.
*/
public function get_columns() {
return array(
'name' => __( 'Name' ),
'created' => __( 'Created' ),
'last_used' => __( 'Last Used' ),
'last_ip' => __( 'Last IP' ),
'revoke' => __( 'Revoke' ),
);
}
/**
* Prepares the list of items for displaying.
*
* @since 5.6.0
*
* @global int $user_id User ID.
*/
public function prepare_items() {
global $user_id;
$this->items = array_reverse( WP_Application_Passwords::get_user_application_passwords( $user_id ) );
}
/**
* Handles the name column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_name( $item ) {
echo esc_html( $item['name'] );
}
/**
* Handles the created column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_created( $item ) {
if ( empty( $item['created'] ) ) {
echo '—';
} else {
echo date_i18n( __( 'F j, Y' ), $item['created'] );
}
}
/**
* Handles the last used column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_last_used( $item ) {
if ( empty( $item['last_used'] ) ) {
echo '—';
} else {
echo date_i18n( __( 'F j, Y' ), $item['last_used'] );
}
}
/**
* Handles the last ip column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_last_ip( $item ) {
if ( empty( $item['last_ip'] ) ) {
echo '—';
} else {
echo $item['last_ip'];
}
}
/**
* Handles the revoke column output.
*
* @since 5.6.0
*
* @param array $item The current application password item.
*/
public function column_revoke( $item ) {
$name = 'revoke-application-password-' . $item['uuid'];
printf(
'<button type="button" name="%1$s" id="%1$s" class="button delete" aria-label="%2$s">%3$s</button>',
esc_attr( $name ),
/* translators: %s: the application password's given name. */
esc_attr( sprintf( __( 'Revoke "%s"' ), $item['name'] ) ),
__( 'Revoke' )
);
}
/**
* Generates content for a single row of the table
*
* @since 5.6.0
*
* @param array $item The current item.
* @param string $column_name The current column name.
*/
protected function column_default( $item, $column_name ) {
/**
* Fires for each custom column in the Application Passwords list table.
*
* Custom columns are registered using the {@see 'manage_application-passwords-user_columns'} filter.
*
* @since 5.6.0
*
* @param string $column_name Name of the custom column.
* @param array $item The application password item.
*/
do_action( "manage_{$this->screen->id}_custom_column", $column_name, $item );
}
/**
* Generates custom table navigation to prevent conflicting nonces.
*
* @since 5.6.0
*
* @param string $which The location of the bulk actions: Either 'top' or 'bottom'.
*/
protected function display_tablenav( $which ) {
?>
<div class="tablenav <?php echo esc_attr( $which ); ?>">
<?php if ( 'bottom' === $which ) : ?>
<div class="alignright">
<button type="button" name="revoke-all-application-passwords" id="revoke-all-application-passwords" class="button delete"><?php _e( 'Revoke all application passwords' ); ?></button>
</div>
<?php endif; ?>
<div class="alignleft actions bulkactions">
<?php $this->bulk_actions( $which ); ?>
</div>
<?php
$this->extra_tablenav( $which );
$this->pagination( $which );
?>
<br class="clear" />
</div>
<?php
}
/**
* Generates content for a single row of the table.
*
* @since 5.6.0
*
* @param array $item The current item.
*/
public function single_row( $item ) {
echo '<tr data-uuid="' . esc_attr( $item['uuid'] ) . '">';
$this->single_row_columns( $item );
echo '</tr>';
}
/**
* Gets the name of the default primary column.
*
* @since 5.6.0
*
* @return string Name of the default primary column, in this case, 'name'.
*/
protected function get_default_primary_column_name() {
return 'name';
}
/**
* Prints the JavaScript template for the new row item.
*
* @since 5.6.0
*/
public function print_js_template_row() {
list( $columns, $hidden, , $primary ) = $this->get_column_info();
echo '<tr data-uuid="{{ data.uuid }}">';
foreach ( $columns as $column_name => $display_name ) {
$is_primary = $primary === $column_name;
$classes = "{$column_name} column-{$column_name}";
if ( $is_primary ) {
$classes .= ' has-row-actions column-primary';
}
if ( in_array( $column_name, $hidden, true ) ) {
$classes .= ' hidden';
}
printf( '<td class="%s" data-colname="%s">', esc_attr( $classes ), esc_attr( wp_strip_all_tags( $display_name ) ) );
switch ( $column_name ) {
case 'name':
echo '{{ data.name }}';
break;
case 'created':
// JSON encoding automatically doubles backslashes to ensure they don't get lost when printing the inline JS.
echo '<# print( wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ', data.created ) ) #>';
break;
case 'last_used':
echo '<# print( data.last_used !== null ? wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ", data.last_used ) : '—' ) #>";
break;
case 'last_ip':
echo "{{ data.last_ip || '—' }}";
break;
case 'revoke':
printf(
'<button type="button" class="button delete" aria-label="%1$s">%2$s</button>',
/* translators: %s: the application password's given name. */
esc_attr( sprintf( __( 'Revoke "%s"' ), '{{ data.name }}' ) ),
esc_html__( 'Revoke' )
);
break;
default:
/**
* Fires in the JavaScript row template for each custom column in the Application Passwords list table.
*
* Custom columns are registered using the {@see 'manage_application-passwords-user_columns'} filter.
*
* @since 5.6.0
*
* @param string $column_name Name of the custom column.
*/
do_action( "manage_{$this->screen->id}_custom_column_js_template", $column_name );
break;
}
if ( $is_primary ) {
echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Show more details' ) .
'</span></button>';
}
echo '</td>';
}
echo '</tr>';
}
}
PK %�[ �]�=Z =Z class-wp-filesystem-ftpext.phpnu �[��� <?php
/**
* WordPress FTP Filesystem.
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* WordPress Filesystem Class for implementing FTP.
*
* @since 2.5.0
*
* @see WP_Filesystem_Base
*/
class WP_Filesystem_FTPext extends WP_Filesystem_Base {
/**
* @since 2.5.0
* @var resource
*/
public $link;
/**
* Constructor.
*
* @since 2.5.0
*
* @param array $opt
*/
public function __construct( $opt = '' ) {
$this->method = 'ftpext';
$this->errors = new WP_Error();
// Check if possible to use ftp functions.
if ( ! extension_loaded( 'ftp' ) ) {
$this->errors->add( 'no_ftp_ext', __( 'The ftp PHP extension is not available' ) );
return;
}
// This class uses the timeout on a per-connection basis, others use it on a per-action basis.
if ( ! defined( 'FS_TIMEOUT' ) ) {
define( 'FS_TIMEOUT', 4 * MINUTE_IN_SECONDS );
}
if ( empty( $opt['port'] ) ) {
$this->options['port'] = 21;
} else {
$this->options['port'] = $opt['port'];
}
if ( empty( $opt['hostname'] ) ) {
$this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) );
} else {
$this->options['hostname'] = $opt['hostname'];
}
// Check if the options provided are OK.
if ( empty( $opt['username'] ) ) {
$this->errors->add( 'empty_username', __( 'FTP username is required' ) );
} else {
$this->options['username'] = $opt['username'];
}
if ( empty( $opt['password'] ) ) {
$this->errors->add( 'empty_password', __( 'FTP password is required' ) );
} else {
$this->options['password'] = $opt['password'];
}
$this->options['ssl'] = false;
if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) {
$this->options['ssl'] = true;
}
}
/**
* Connects filesystem.
*
* @since 2.5.0
*
* @return bool True on success, false on failure.
*/
public function connect() {
if ( isset( $this->options['ssl'] ) && $this->options['ssl'] && function_exists( 'ftp_ssl_connect' ) ) {
$this->link = @ftp_ssl_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
} else {
$this->link = @ftp_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
}
if ( ! $this->link ) {
$this->errors->add(
'connect',
sprintf(
/* translators: %s: hostname:port */
__( 'Failed to connect to FTP Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
return false;
}
if ( ! @ftp_login( $this->link, $this->options['username'], $this->options['password'] ) ) {
$this->errors->add(
'auth',
sprintf(
/* translators: %s: Username. */
__( 'Username/Password incorrect for %s' ),
$this->options['username']
)
);
return false;
}
// Set the connection to use Passive FTP.
ftp_pasv( $this->link, true );
if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) {
@ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT );
}
return true;
}
/**
* Reads entire file into a string.
*
* @since 2.5.0
*
* @param string $file Name of the file to read.
* @return string|false Read data on success, false if no temporary file could be opened,
* or if the file couldn't be retrieved.
*/
public function get_contents( $file ) {
$tempfile = wp_tempnam( $file );
$temphandle = fopen( $tempfile, 'w+' );
if ( ! $temphandle ) {
unlink( $tempfile );
return false;
}
if ( ! ftp_fget( $this->link, $temphandle, $file, FTP_BINARY ) ) {
fclose( $temphandle );
unlink( $tempfile );
return false;
}
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to.
$contents = '';
while ( ! feof( $temphandle ) ) {
$contents .= fread( $temphandle, 8 * KB_IN_BYTES );
}
fclose( $temphandle );
unlink( $tempfile );
return $contents;
}
/**
* Reads entire file into an array.
*
* @since 2.5.0
*
* @param string $file Path to the file.
* @return array|false File contents in an array on success, false on failure.
*/
public function get_contents_array( $file ) {
return explode( "\n", $this->get_contents( $file ) );
}
/**
* Writes a string to a file.
*
* @since 2.5.0
*
* @param string $file Remote path to the file where to write the data.
* @param string $contents The data to write.
* @param int|false $mode Optional. The file permissions as octal number, usually 0644.
* Default false.
* @return bool True on success, false on failure.
*/
public function put_contents( $file, $contents, $mode = false ) {
$tempfile = wp_tempnam( $file );
$temphandle = fopen( $tempfile, 'wb+' );
if ( ! $temphandle ) {
unlink( $tempfile );
return false;
}
mbstring_binary_safe_encoding();
$data_length = strlen( $contents );
$bytes_written = fwrite( $temphandle, $contents );
reset_mbstring_encoding();
if ( $data_length !== $bytes_written ) {
fclose( $temphandle );
unlink( $tempfile );
return false;
}
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to.
$ret = ftp_fput( $this->link, $file, $temphandle, FTP_BINARY );
fclose( $temphandle );
unlink( $tempfile );
$this->chmod( $file, $mode );
return $ret;
}
/**
* Gets the current working directory.
*
* @since 2.5.0
*
* @return string|false The current working directory on success, false on failure.
*/
public function cwd() {
$cwd = ftp_pwd( $this->link );
if ( $cwd ) {
$cwd = trailingslashit( $cwd );
}
return $cwd;
}
/**
* Changes current directory.
*
* @since 2.5.0
*
* @param string $dir The new current directory.
* @return bool True on success, false on failure.
*/
public function chdir( $dir ) {
return @ftp_chdir( $this->link, $dir );
}
/**
* Changes filesystem permissions.
*
* @since 2.5.0
*
* @param string $file Path to the file.
* @param int|false $mode Optional. The permissions as octal number, usually 0644 for files,
* 0755 for directories. Default false.
* @param bool $recursive Optional. If set to true, changes file permissions recursively.
* Default false.
* @return bool True on success, false on failure.
*/
public function chmod( $file, $mode = false, $recursive = false ) {
if ( ! $mode ) {
if ( $this->is_file( $file ) ) {
$mode = FS_CHMOD_FILE;
} elseif ( $this->is_dir( $file ) ) {
$mode = FS_CHMOD_DIR;
} else {
return false;
}
}
// chmod any sub-objects if recursive.
if ( $recursive && $this->is_dir( $file ) ) {
$filelist = $this->dirlist( $file );
foreach ( (array) $filelist as $filename => $filemeta ) {
$this->chmod( $file . '/' . $filename, $mode, $recursive );
}
}
// chmod the file or directory.
if ( ! function_exists( 'ftp_chmod' ) ) {
return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) );
}
return (bool) ftp_chmod( $this->link, $mode, $file );
}
/**
* Gets the file owner.
*
* @since 2.5.0
*
* @param string $file Path to the file.
* @return string|false Username of the owner on success, false on failure.
*/
public function owner( $file ) {
$dir = $this->dirlist( $file );
return $dir[ $file ]['owner'];
}
/**
* Gets the permissions of the specified file or filepath in their octal format.
*
* @since 2.5.0
*
* @param string $file Path to the file.
* @return string Mode of the file (the last 3 digits).
*/
public function getchmod( $file ) {
$dir = $this->dirlist( $file );
return $dir[ $file ]['permsn'];
}
/**
* Gets the file's group.
*
* @since 2.5.0
*
* @param string $file Path to the file.
* @return string|false The group on success, false on failure.
*/
public function group( $file ) {
$dir = $this->dirlist( $file );
return $dir[ $file ]['group'];
}
/**
* Copies a file.
*
* @since 2.5.0
*
* @param string $source Path to the source file.
* @param string $destination Path to the destination file.
* @param bool $overwrite Optional. Whether to overwrite the destination file if it exists.
* Default false.
* @param int|false $mode Optional. The permissions as octal number, usually 0644 for files,
* 0755 for dirs. Default false.
* @return bool True on success, false on failure.
*/
public function copy( $source, $destination, $overwrite = false, $mode = false ) {
if ( ! $overwrite && $this->exists( $destination ) ) {
return false;
}
$content = $this->get_contents( $source );
if ( false === $content ) {
return false;
}
return $this->put_contents( $destination, $content, $mode );
}
/**
* Moves a file or directory.
*
* After moving files or directories, OPcache will need to be invalidated.
*
* If moving a directory fails, `copy_dir()` can be used for a recursive copy.
*
* Use `move_dir()` for moving directories with OPcache invalidation and a
* fallback to `copy_dir()`.
*
* @since 2.5.0
*
* @param string $source Path to the source file or directory.
* @param string $destination Path to the destination file or directory.
* @param bool $overwrite Optional. Whether to overwrite the destination if it exists.
* Default false.
* @return bool True on success, false on failure.
*/
public function move( $source, $destination, $overwrite = false ) {
return ftp_rename( $this->link, $source, $destination );
}
/**
* Deletes a file or directory.
*
* @since 2.5.0
*
* @param string $file Path to the file or directory.
* @param bool $recursive Optional. If set to true, deletes files and folders recursively.
* Default false.
* @param string|false $type Type of resource. 'f' for file, 'd' for directory.
* Default false.
* @return bool True on success, false on failure.
*/
public function delete( $file, $recursive = false, $type = false ) {
if ( empty( $file ) ) {
return false;
}
if ( 'f' === $type || $this->is_file( $file ) ) {
return ftp_delete( $this->link, $file );
}
if ( ! $recursive ) {
return ftp_rmdir( $this->link, $file );
}
$filelist = $this->dirlist( trailingslashit( $file ) );
if ( ! empty( $filelist ) ) {
foreach ( $filelist as $delete_file ) {
$this->delete( trailingslashit( $file ) . $delete_file['name'], $recursive, $delete_file['type'] );
}
}
return ftp_rmdir( $this->link, $file );
}
/**
* Checks if a file or directory exists.
*
* @since 2.5.0
* @since 6.3.0 Returns false for an empty path.
*
* @param string $path Path to file or directory.
* @return bool Whether $path exists or not.
*/
public function exists( $path ) {
/*
* Check for empty path. If ftp_nlist() receives an empty path,
* it checks the current working directory and may return true.
*
* See https://core.trac.wordpress.org/ticket/33058.
*/
if ( '' === $path ) {
return false;
}
$list = ftp_nlist( $this->link, $path );
if ( empty( $list ) && $this->is_dir( $path ) ) {
return true; // File is an empty directory.
}
return ! empty( $list ); // Empty list = no file, so invert.
}
/**
* Checks if resource is a file.
*
* @since 2.5.0
*
* @param string $file File path.
* @return bool Whether $file is a file.
*/
public function is_file( $file ) {
return $this->exists( $file ) && ! $this->is_dir( $file );
}
/**
* Checks if resource is a directory.
*
* @since 2.5.0
*
* @param string $path Directory path.
* @return bool Whether $path is a directory.
*/
public function is_dir( $path ) {
$cwd = $this->cwd();
$result = @ftp_chdir( $this->link, trailingslashit( $path ) );
if ( $result && $path === $this->cwd() || $this->cwd() !== $cwd ) {
@ftp_chdir( $this->link, $cwd );
return true;
}
return false;
}
/**
* Checks if a file is readable.
*
* @since 2.5.0
*
* @param string $file Path to file.
* @return bool Whether $file is readable.
*/
public function is_readable( $file ) {
return true;
}
/**
* Checks if a file or directory is writable.
*
* @since 2.5.0
*
* @param string $path Path to file or directory.
* @return bool Whether $path is writable.
*/
public function is_writable( $path ) {
return true;
}
/**
* Gets the file's last access time.
*
* @since 2.5.0
*
* @param string $file Path to file.
* @return int|false Unix timestamp representing last access time, false on failure.
*/
public function atime( $file ) {
return false;
}
/**
* Gets the file modification time.
*
* @since 2.5.0
*
* @param string $file Path to file.
* @return int|false Unix timestamp representing modification time, false on failure.
*/
public function mtime( $file ) {
return ftp_mdtm( $this->link, $file );
}
/**
* Gets the file size (in bytes).
*
* @since 2.5.0
*
* @param string $file Path to file.
* @return int|false Size of the file in bytes on success, false on failure.
*/
public function size( $file ) {
$size = ftp_size( $this->link, $file );
return ( $size > -1 ) ? $size : false;
}
/**
* Sets the access and modification times of a file.
*
* Note: If $file doesn't exist, it will be created.
*
* @since 2.5.0
*
* @param string $file Path to file.
* @param int $time Optional. Modified time to set for file.
* Default 0.
* @param int $atime Optional. Access time to set for file.
* Default 0.
* @return bool True on success, false on failure.
*/
public function touch( $file, $time = 0, $atime = 0 ) {
return false;
}
/**
* Creates a directory.
*
* @since 2.5.0
*
* @param string $path Path for new directory.
* @param int|false $chmod Optional. The permissions as octal number (or false to skip chmod).
* Default false.
* @param string|int|false $chown Optional. A user name or number (or false to skip chown).
* Default false.
* @param string|int|false $chgrp Optional. A group name or number (or false to skip chgrp).
* Default false.
* @return bool True on success, false on failure.
*/
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
$path = untrailingslashit( $path );
if ( empty( $path ) ) {
return false;
}
if ( ! ftp_mkdir( $this->link, $path ) ) {
return false;
}
$this->chmod( $path, $chmod );
return true;
}
/**
* Deletes a directory.
*
* @since 2.5.0
*
* @param string $path Path to directory.
* @param bool $recursive Optional. Whether to recursively remove files/directories.
* Default false.
* @return bool True on success, false on failure.
*/
public function rmdir( $path, $recursive = false ) {
return $this->delete( $path, $recursive );
}
/**
* @param string $line
* @return array {
* Array of file information.
*
* @type string $name Name of the file or directory.
* @type string $perms *nix representation of permissions.
* @type string $permsn Octal representation of permissions.
* @type string|false $number File number as a string, or false if not available.
* @type string|false $owner Owner name or ID, or false if not available.
* @type string|false $group File permissions group, or false if not available.
* @type string|false $size Size of file in bytes as a string, or false if not available.
* @type string|false $lastmodunix Last modified unix timestamp as a string, or false if not available.
* @type string|false $lastmod Last modified month (3 letters) and day (without leading 0), or
* false if not available.
* @type string|false $time Last modified time, or false if not available.
* @type string $type Type of resource. 'f' for file, 'd' for directory, 'l' for link.
* @type array|false $files If a directory and `$recursive` is true, contains another array of files.
* False if unable to list directory contents.
* }
*/
public function parselisting( $line ) {
static $is_windows = null;
if ( is_null( $is_windows ) ) {
$is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false;
}
if ( $is_windows && preg_match( '/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer ) ) {
$b = array();
if ( $lucifer[3] < 70 ) {
$lucifer[3] += 2000;
} else {
$lucifer[3] += 1900; // 4-digit year fix.
}
$b['isdir'] = ( '<DIR>' === $lucifer[7] );
if ( $b['isdir'] ) {
$b['type'] = 'd';
} else {
$b['type'] = 'f';
}
$b['size'] = $lucifer[7];
$b['month'] = $lucifer[1];
$b['day'] = $lucifer[2];
$b['year'] = $lucifer[3];
$b['hour'] = $lucifer[4];
$b['minute'] = $lucifer[5];
$b['time'] = mktime( $lucifer[4] + ( strcasecmp( $lucifer[6], 'PM' ) === 0 ? 12 : 0 ), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3] );
$b['am/pm'] = $lucifer[6];
$b['name'] = $lucifer[8];
} elseif ( ! $is_windows ) {
$lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY );
if ( $lucifer ) {
// echo $line."\n";
$lcount = count( $lucifer );
if ( $lcount < 8 ) {
return '';
}
$b = array();
$b['isdir'] = 'd' === $lucifer[0][0];
$b['islink'] = 'l' === $lucifer[0][0];
if ( $b['isdir'] ) {
$b['type'] = 'd';
} elseif ( $b['islink'] ) {
$b['type'] = 'l';
} else {
$b['type'] = 'f';
}
$b['perms'] = $lucifer[0];
$b['permsn'] = $this->getnumchmodfromh( $b['perms'] );
$b['number'] = $lucifer[1];
$b['owner'] = $lucifer[2];
$b['group'] = $lucifer[3];
$b['size'] = $lucifer[4];
if ( 8 === $lcount ) {
sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] );
sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] );
$b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] );
$b['name'] = $lucifer[7];
} else {
$b['month'] = $lucifer[5];
$b['day'] = $lucifer[6];
if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) {
$b['year'] = gmdate( 'Y' );
$b['hour'] = $l2[1];
$b['minute'] = $l2[2];
} else {
$b['year'] = $lucifer[7];
$b['hour'] = 0;
$b['minute'] = 0;
}
$b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) );
$b['name'] = $lucifer[8];
}
}
}
// Replace symlinks formatted as "source -> target" with just the source name.
if ( isset( $b['islink'] ) && $b['islink'] ) {
$b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] );
}
return $b;
}
/**
* Gets details for files in a directory or a specific file.
*
* @since 2.5.0
*
* @param string $path Path to directory or file.
* @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
* Default true.
* @param bool $recursive Optional. Whether to recursively include file details in nested directories.
* Default false.
* @return array|false {
* Array of arrays containing file information. False if unable to list directory contents.
*
* @type array ...$0 {
* Array of file information. Note that some elements may not be available on all filesystems.
*
* @type string $name Name of the file or directory.
* @type string $perms *nix representation of permissions.
* @type string $permsn Octal representation of permissions.
* @type int|string|false $number File number. May be a numeric string. False if not available.
* @type string|false $owner Owner name or ID, or false if not available.
* @type string|false $group File permissions group, or false if not available.
* @type int|string|false $size Size of file in bytes. May be a numeric string.
* False if not available.
* @type int|string|false $lastmodunix Last modified unix timestamp. May be a numeric string.
* False if not available.
* @type string|false $lastmod Last modified month (3 letters) and day (without leading 0), or
* false if not available.
* @type string|false $time Last modified time, or false if not available.
* @type string $type Type of resource. 'f' for file, 'd' for directory, 'l' for link.
* @type array|false $files If a directory and `$recursive` is true, contains another array of
* files. False if unable to list directory contents.
* }
* }
*/
public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) {
if ( $this->is_file( $path ) ) {
$limit_file = basename( $path );
$path = dirname( $path ) . '/';
} else {
$limit_file = false;
}
$pwd = ftp_pwd( $this->link );
if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist.
return false;
}
$list = ftp_rawlist( $this->link, '-a', false );
@ftp_chdir( $this->link, $pwd );
if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least).
return false;
}
$dirlist = array();
foreach ( $list as $k => $v ) {
$entry = $this->parselisting( $v );
if ( empty( $entry ) ) {
continue;
}
if ( '.' === $entry['name'] || '..' === $entry['name'] ) {
continue;
}
if ( ! $include_hidden && '.' === $entry['name'][0] ) {
continue;
}
if ( $limit_file && $entry['name'] !== $limit_file ) {
continue;
}
$dirlist[ $entry['name'] ] = $entry;
}
$path = trailingslashit( $path );
$ret = array();
foreach ( (array) $dirlist as $struc ) {
if ( 'd' === $struc['type'] ) {
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}
}
$ret[ $struc['name'] ] = $struc;
}
return $ret;
}
/**
* Destructor.
*
* @since 2.5.0
*/
public function __destruct() {
if ( $this->link ) {
ftp_close( $this->link );
}
}
}
PK %�[W�>!N N
dashboard.phpnu �[��� <?php
/**
* WordPress Dashboard Widget Administration Screen API
*
* @package WordPress
* @subpackage Administration
*/
/**
* Registers dashboard widgets.
*
* Handles POST data, sets up filters.
*
* @since 2.5.0
*
* @global array $wp_registered_widgets
* @global array $wp_registered_widget_controls
* @global callable[] $wp_dashboard_control_callbacks
*/
function wp_dashboard_setup() {
global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
$screen = get_current_screen();
/* Register Widgets and Controls */
$wp_dashboard_control_callbacks = array();
// Browser version
$check_browser = wp_check_browser_version();
if ( $check_browser && $check_browser['upgrade'] ) {
add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
if ( $check_browser['insecure'] ) {
wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
} else {
wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' );
}
}
// PHP Version.
$check_php = wp_check_php_version();
if ( $check_php && current_user_can( 'update_php' ) ) {
// If "not acceptable" the widget will be shown.
if ( isset( $check_php['is_acceptable'] ) && ! $check_php['is_acceptable'] ) {
add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' );
if ( $check_php['is_lower_than_future_minimum'] ) {
wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' );
} else {
wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Recommended' ), 'wp_dashboard_php_nag' );
}
}
}
// Site Health.
if ( current_user_can( 'view_site_health_checks' ) && ! is_network_admin() ) {
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
}
WP_Site_Health::get_instance();
wp_enqueue_style( 'site-health' );
wp_enqueue_script( 'site-health' );
wp_add_dashboard_widget( 'dashboard_site_health', __( 'Site Health Status' ), 'wp_dashboard_site_health' );
}
// Right Now.
if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
}
if ( is_network_admin() ) {
wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
}
// Activity Widget.
if ( is_blog_admin() ) {
wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
}
// QuickPress Widget.
if ( is_blog_admin() && current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
$quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Your Recent Drafts' ) );
wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
}
// WordPress Events and News.
wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' );
if ( is_network_admin() ) {
/**
* Fires after core widgets for the Network Admin dashboard have been registered.
*
* @since 3.1.0
*/
do_action( 'wp_network_dashboard_setup' );
/**
* Filters the list of widgets to load for the Network Admin dashboard.
*
* @since 3.1.0
*
* @param string[] $dashboard_widgets An array of dashboard widget IDs.
*/
$dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
} elseif ( is_user_admin() ) {
/**
* Fires after core widgets for the User Admin dashboard have been registered.
*
* @since 3.1.0
*/
do_action( 'wp_user_dashboard_setup' );
/**
* Filters the list of widgets to load for the User Admin dashboard.
*
* @since 3.1.0
*
* @param string[] $dashboard_widgets An array of dashboard widget IDs.
*/
$dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
} else {
/**
* Fires after core widgets for the admin dashboard have been registered.
*
* @since 2.5.0
*/
do_action( 'wp_dashboard_setup' );
/**
* Filters the list of widgets to load for the admin dashboard.
*
* @since 2.5.0
*
* @param string[] $dashboard_widgets An array of dashboard widget IDs.
*/
$dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
}
foreach ( $dashboard_widgets as $widget_id ) {
$name = empty( $wp_registered_widgets[ $widget_id ]['all_link'] ) ? $wp_registered_widgets[ $widget_id ]['name'] : $wp_registered_widgets[ $widget_id ]['name'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __( 'View all' ) . '</a>';
wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[ $widget_id ]['callback'], $wp_registered_widget_controls[ $widget_id ]['callback'] );
}
if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget_id'] ) ) {
check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
ob_start(); // Hack - but the same hack wp-admin/widgets.php uses.
wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
ob_end_clean();
wp_redirect( remove_query_arg( 'edit' ) );
exit;
}
/** This action is documented in wp-admin/includes/meta-boxes.php */
do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
/** This action is documented in wp-admin/includes/meta-boxes.php */
do_action( 'do_meta_boxes', $screen->id, 'side', '' );
}
/**
* Adds a new dashboard widget.
*
* @since 2.7.0
* @since 5.6.0 The `$context` and `$priority` parameters were added.
*
* @global callable[] $wp_dashboard_control_callbacks
*
* @param string $widget_id Widget ID (used in the 'id' attribute for the widget).
* @param string $widget_name Title of the widget.
* @param callable $callback Function that fills the widget with the desired content.
* The function should echo its output.
* @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
* @param array $callback_args Optional. Data that should be set as the $args property of the widget array
* (which is the second parameter passed to your callback). Default null.
* @param string $context Optional. The context within the screen where the box should display.
* Accepts 'normal', 'side', 'column3', or 'column4'. Default 'normal'.
* @param string $priority Optional. The priority within the context where the box should show.
* Accepts 'high', 'core', 'default', or 'low'. Default 'core'.
*/
function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null, $context = 'normal', $priority = 'core' ) {
global $wp_dashboard_control_callbacks;
$screen = get_current_screen();
$private_callback_args = array( '__widget_basename' => $widget_name );
if ( is_null( $callback_args ) ) {
$callback_args = $private_callback_args;
} elseif ( is_array( $callback_args ) ) {
$callback_args = array_merge( $callback_args, $private_callback_args );
}
if ( $control_callback && is_callable( $control_callback ) && current_user_can( 'edit_dashboard' ) ) {
$wp_dashboard_control_callbacks[ $widget_id ] = $control_callback;
if ( isset( $_GET['edit'] ) && $widget_id === $_GET['edit'] ) {
list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
$widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
$callback = '_wp_dashboard_control_callback';
} else {
list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
$widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
}
}
$side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
if ( in_array( $widget_id, $side_widgets, true ) ) {
$context = 'side';
}
$high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' );
if ( in_array( $widget_id, $high_priority_widgets, true ) ) {
$priority = 'high';
}
if ( empty( $context ) ) {
$context = 'normal';
}
if ( empty( $priority ) ) {
$priority = 'core';
}
add_meta_box( $widget_id, $widget_name, $callback, $screen, $context, $priority, $callback_args );
}
/**
* Outputs controls for the current dashboard widget.
*
* @access private
* @since 2.7.0
*
* @param mixed $dashboard
* @param array $meta_box
*/
function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
echo '<form method="post" class="dashboard-widget-control-form wp-clearfix">';
wp_dashboard_trigger_widget_control( $meta_box['id'] );
wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
echo '<input type="hidden" name="widget_id" value="' . esc_attr( $meta_box['id'] ) . '" />';
submit_button( __( 'Save Changes' ) );
echo '</form>';
}
/**
* Displays the dashboard.
*
* @since 2.5.0
*/
function wp_dashboard() {
$screen = get_current_screen();
$columns = absint( $screen->get_columns() );
$columns_css = '';
if ( $columns ) {
$columns_css = " columns-$columns";
}
?>
<div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>">
<div id="postbox-container-1" class="postbox-container">
<?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
</div>
<div id="postbox-container-2" class="postbox-container">
<?php do_meta_boxes( $screen->id, 'side', '' ); ?>
</div>
<div id="postbox-container-3" class="postbox-container">
<?php do_meta_boxes( $screen->id, 'column3', '' ); ?>
</div>
<div id="postbox-container-4" class="postbox-container">
<?php do_meta_boxes( $screen->id, 'column4', '' ); ?>
</div>
</div>
<?php
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
}
//
// Dashboard Widgets.
//
/**
* Dashboard widget that displays some basic stats about the site.
*
* Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8.
*
* @since 2.7.0
*/
function wp_dashboard_right_now() {
?>
<div class="main">
<ul>
<?php
// Posts and Pages.
foreach ( array( 'post', 'page' ) as $post_type ) {
$num_posts = wp_count_posts( $post_type );
if ( $num_posts && $num_posts->publish ) {
if ( 'post' === $post_type ) {
/* translators: %s: Number of posts. */
$text = _n( '%s Post', '%s Posts', $num_posts->publish );
} else {
/* translators: %s: Number of pages. */
$text = _n( '%s Page', '%s Pages', $num_posts->publish );
}
$text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
$post_type_object = get_post_type_object( $post_type );
if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
} else {
printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
}
}
}
// Comments.
$num_comm = wp_count_comments();
if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) {
/* translators: %s: Number of comments. */
$text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) );
?>
<li class="comment-count">
<a href="edit-comments.php"><?php echo $text; ?></a>
</li>
<?php
$moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated );
/* translators: %s: Number of comments. */
$text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n );
?>
<li class="comment-mod-count<?php echo ! $num_comm->moderated ? ' hidden' : ''; ?>">
<a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a>
</li>
<?php
}
/**
* Filters the array of extra elements to list in the 'At a Glance'
* dashboard widget.
*
* Prior to 3.8.0, the widget was named 'Right Now'. Each element
* is wrapped in list-item tags on output.
*
* @since 3.8.0
*
* @param string[] $items Array of extra 'At a Glance' widget items.
*/
$elements = apply_filters( 'dashboard_glance_items', array() );
if ( $elements ) {
echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";
}
?>
</ul>
<?php
update_right_now_message();
// Check if search engines are asked not to index this site.
if ( ! is_network_admin() && ! is_user_admin()
&& current_user_can( 'manage_options' ) && ! get_option( 'blog_public' )
) {
/**
* Filters the link title attribute for the 'Search engines discouraged'
* message displayed in the 'At a Glance' dashboard widget.
*
* Prior to 3.8.0, the widget was named 'Right Now'.
*
* @since 3.0.0
* @since 4.5.0 The default for `$title` was updated to an empty string.
*
* @param string $title Default attribute text.
*/
$title = apply_filters( 'privacy_on_link_title', '' );
/**
* Filters the link label for the 'Search engines discouraged' message
* displayed in the 'At a Glance' dashboard widget.
*
* Prior to 3.8.0, the widget was named 'Right Now'.
*
* @since 3.0.0
*
* @param string $content Default text.
*/
$content = apply_filters( 'privacy_on_link_text', __( 'Search engines discouraged' ) );
$title_attr = '' === $title ? '' : " title='$title'";
echo "<p class='search-engines-info'><a href='options-reading.php'$title_attr>$content</a></p>";
}
?>
</div>
<?php
/*
* activity_box_end has a core action, but only prints content when multisite.
* Using an output buffer is the only way to really check if anything's displayed here.
*/
ob_start();
/**
* Fires at the end of the 'At a Glance' dashboard widget.
*
* Prior to 3.8.0, the widget was named 'Right Now'.
*
* @since 2.5.0
*/
do_action( 'rightnow_end' );
/**
* Fires at the end of the 'At a Glance' dashboard widget.
*
* Prior to 3.8.0, the widget was named 'Right Now'.
*
* @since 2.0.0
*/
do_action( 'activity_box_end' );
$actions = ob_get_clean();
if ( ! empty( $actions ) ) :
?>
<div class="sub">
<?php echo $actions; ?>
</div>
<?php
endif;
}
/**
* @since 3.1.0
*/
function wp_network_dashboard_right_now() {
$actions = array();
if ( current_user_can( 'create_sites' ) ) {
$actions['create-site'] = '<a href="' . network_admin_url( 'site-new.php' ) . '">' . __( 'Create a New Site' ) . '</a>';
}
if ( current_user_can( 'create_users' ) ) {
$actions['create-user'] = '<a href="' . network_admin_url( 'user-new.php' ) . '">' . __( 'Create a New User' ) . '</a>';
}
$c_users = get_user_count();
$c_blogs = get_blog_count();
/* translators: %s: Number of users on the network. */
$user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
/* translators: %s: Number of sites on the network. */
$blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
/* translators: 1: Text indicating the number of sites on the network, 2: Text indicating the number of users on the network. */
$sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
if ( $actions ) {
echo '<ul class="subsubsub">';
foreach ( $actions as $class => $action ) {
$actions[ $class ] = "\t<li class='$class'>$action";
}
echo implode( " |</li>\n", $actions ) . "</li>\n";
echo '</ul>';
}
?>
<br class="clear" />
<p class="youhave"><?php echo $sentence; ?></p>
<?php
/**
* Fires in the Network Admin 'Right Now' dashboard widget
* just before the user and site search form fields.
*
* @since MU (3.0.0)
*/
do_action( 'wpmuadminresult' );
?>
<form action="<?php echo esc_url( network_admin_url( 'users.php' ) ); ?>" method="get">
<p>
<label class="screen-reader-text" for="search-users">
<?php
/* translators: Hidden accessibility text. */
_e( 'Search Users' );
?>
</label>
<input type="search" name="s" value="" size="30" autocomplete="off" id="search-users" />
<?php submit_button( __( 'Search Users' ), '', false, false, array( 'id' => 'submit_users' ) ); ?>
</p>
</form>
<form action="<?php echo esc_url( network_admin_url( 'sites.php' ) ); ?>" method="get">
<p>
<label class="screen-reader-text" for="search-sites">
<?php
/* translators: Hidden accessibility text. */
_e( 'Search Sites' );
?>
</label>
<input type="search" name="s" value="" size="30" autocomplete="off" id="search-sites" />
<?php submit_button( __( 'Search Sites' ), '', false, false, array( 'id' => 'submit_sites' ) ); ?>
</p>
</form>
<?php
/**
* Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
*
* @since MU (3.0.0)
*/
do_action( 'mu_rightnow_end' );
/**
* Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
*
* @since MU (3.0.0)
*/
do_action( 'mu_activity_box_end' );
}
/**
* Displays the Quick Draft widget.
*
* @since 3.8.0
*
* @global int $post_ID
*
* @param string|false $error_msg Optional. Error message. Default false.
*/
function wp_dashboard_quick_press( $error_msg = false ) {
global $post_ID;
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
// Check if a new auto-draft (= no new post_ID) is needed or if the old can be used.
$last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID.
if ( $last_post_id ) {
$post = get_post( $last_post_id );
if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore.
$post = get_default_post_to_edit( 'post', true );
update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
} else {
$post->post_title = ''; // Remove the auto draft title.
}
} else {
$post = get_default_post_to_edit( 'post', true );
$user_id = get_current_user_id();
// Don't create an option if this is a super admin who does not belong to this site.
if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) {
update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
}
}
$post_ID = (int) $post->ID;
?>
<form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">
<?php
if ( $error_msg ) {
wp_admin_notice(
$error_msg,
array(
'additional_classes' => array( 'error' ),
)
);
}
?>
<div class="input-text-wrap" id="title-wrap">
<label for="title">
<?php
/** This filter is documented in wp-admin/edit-form-advanced.php */
echo apply_filters( 'enter_title_here', __( 'Title' ), $post );
?>
</label>
<input type="text" name="post_title" id="title" autocomplete="off" />
</div>
<div class="textarea-wrap" id="description-wrap">
<label for="content"><?php _e( 'Content' ); ?></label>
<textarea name="content" id="content" placeholder="<?php esc_attr_e( 'What’s on your mind?' ); ?>" class="mceEditor" rows="3" cols="15" autocomplete="off"></textarea>
</div>
<p class="submit">
<input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
<input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
<input type="hidden" name="post_type" value="post" />
<?php wp_nonce_field( 'add-post' ); ?>
<?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
<br class="clear" />
</p>
</form>
<?php
wp_dashboard_recent_drafts();
}
/**
* Show recent drafts of the user on the dashboard.
*
* @since 2.7.0
*
* @param WP_Post[]|false $drafts Optional. Array of posts to display. Default false.
*/
function wp_dashboard_recent_drafts( $drafts = false ) {
if ( ! $drafts ) {
$query_args = array(
'post_type' => 'post',
'post_status' => 'draft',
'author' => get_current_user_id(),
'posts_per_page' => 4,
'orderby' => 'modified',
'order' => 'DESC',
);
/**
* Filters the post query arguments for the 'Recent Drafts' dashboard widget.
*
* @since 4.4.0
*
* @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
*/
$query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args );
$drafts = get_posts( $query_args );
if ( ! $drafts ) {
return;
}
}
echo '<div class="drafts">';
if ( count( $drafts ) > 3 ) {
printf(
'<p class="view-all"><a href="%s">%s</a></p>' . "\n",
esc_url( admin_url( 'edit.php?post_status=draft' ) ),
__( 'View all drafts' )
);
}
echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n";
echo '<ul>';
/* translators: Maximum number of words used in a preview of a draft on the dashboard. */
$draft_length = (int) _x( '10', 'draft_length' );
$drafts = array_slice( $drafts, 0, 3 );
foreach ( $drafts as $draft ) {
$url = get_edit_post_link( $draft->ID );
$title = _draft_or_post_title( $draft->ID );
echo "<li>\n";
printf(
'<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
esc_url( $url ),
/* translators: %s: Post title. */
esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ),
esc_html( $title ),
get_the_time( 'c', $draft ),
get_the_time( __( 'F j, Y' ), $draft )
);
$the_content = wp_trim_words( $draft->post_content, $draft_length );
if ( $the_content ) {
echo '<p>' . $the_content . '</p>';
}
echo "</li>\n";
}
echo "</ul>\n";
echo '</div>';
}
/**
* Outputs a row for the Recent Comments widget.
*
* @access private
* @since 2.7.0
*
* @global WP_Comment $comment Global comment object.
*
* @param WP_Comment $comment The current comment.
* @param bool $show_date Optional. Whether to display the date.
*/
function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
$GLOBALS['comment'] = clone $comment;
if ( $comment->comment_post_ID > 0 ) {
$comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
$comment_post_url = get_the_permalink( $comment->comment_post_ID );
$comment_post_link = '<a href="' . esc_url( $comment_post_url ) . '">' . $comment_post_title . '</a>';
} else {
$comment_post_link = '';
}
$actions_string = '';
if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
// Pre-order it: Approve | Reply | Edit | Spam | Trash.
$actions = array(
'approve' => '',
'unapprove' => '',
'reply' => '',
'edit' => '',
'spam' => '',
'trash' => '',
'delete' => '',
'view' => '',
);
$approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'approve-comment_' . $comment->comment_ID ) );
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'delete-comment_' . $comment->comment_ID ) );
$action_string = 'comment.php?action=%s&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID . '&%s';
$approve_url = sprintf( $action_string, 'approvecomment', $approve_nonce );
$unapprove_url = sprintf( $action_string, 'unapprovecomment', $approve_nonce );
$spam_url = sprintf( $action_string, 'spamcomment', $del_nonce );
$trash_url = sprintf( $action_string, 'trashcomment', $del_nonce );
$delete_url = sprintf( $action_string, 'deletecomment', $del_nonce );
$actions['approve'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $approve_url ),
"dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
esc_attr__( 'Approve this comment' ),
__( 'Approve' )
);
$actions['unapprove'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $unapprove_url ),
"dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
esc_attr__( 'Unapprove this comment' ),
__( 'Unapprove' )
);
$actions['edit'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
"comment.php?action=editcomment&c={$comment->comment_ID}",
esc_attr__( 'Edit this comment' ),
__( 'Edit' )
);
$actions['reply'] = sprintf(
'<button type="button" onclick="window.commentReply && commentReply.open(\'%s\',\'%s\');" class="vim-r button-link hide-if-no-js" aria-label="%s">%s</button>',
$comment->comment_ID,
$comment->comment_post_ID,
esc_attr__( 'Reply to this comment' ),
__( 'Reply' )
);
$actions['spam'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $spam_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
esc_attr__( 'Mark this comment as spam' ),
/* translators: "Mark as spam" link. */
_x( 'Spam', 'verb' )
);
if ( ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $delete_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
esc_attr__( 'Delete this comment permanently' ),
__( 'Delete Permanently' )
);
} else {
$actions['trash'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $trash_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
esc_attr__( 'Move this comment to the Trash' ),
_x( 'Trash', 'verb' )
);
}
$actions['view'] = sprintf(
'<a class="comment-link" href="%s" aria-label="%s">%s</a>',
esc_url( get_comment_link( $comment ) ),
esc_attr__( 'View this comment' ),
__( 'View' )
);
/** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
|| 1 === $i
) {
$separator = '';
} else {
$separator = ' | ';
}
// Reply and quickedit need a hide-if-no-js span.
if ( 'reply' === $action || 'quickedit' === $action ) {
$action .= ' hide-if-no-js';
}
if ( 'view' === $action && '1' !== $comment->comment_approved ) {
$action .= ' hidden';
}
$actions_string .= "<span class='$action'>{$separator}{$link}</span>";
}
}
?>
<li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>>
<?php
$comment_row_class = '';
if ( get_option( 'show_avatars' ) ) {
echo get_avatar( $comment, 50, 'mystery' );
$comment_row_class .= ' has-avatar';
}
?>
<?php if ( ! $comment->comment_type || 'comment' === $comment->comment_type ) : ?>
<div class="dashboard-comment-wrap has-row-actions <?php echo $comment_row_class; ?>">
<p class="comment-meta">
<?php
// Comments might not have a post they relate to, e.g. programmatically created ones.
if ( $comment_post_link ) {
printf(
/* translators: 1: Comment author, 2: Post link, 3: Notification if the comment is pending. */
__( 'From %1$s on %2$s %3$s' ),
'<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
$comment_post_link,
'<span class="approve">' . __( '[Pending]' ) . '</span>'
);
} else {
printf(
/* translators: 1: Comment author, 2: Notification if the comment is pending. */
__( 'From %1$s %2$s' ),
'<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
'<span class="approve">' . __( '[Pending]' ) . '</span>'
);
}
?>
</p>
<?php
else :
switch ( $comment->comment_type ) {
case 'pingback':
$type = __( 'Pingback' );
break;
case 'trackback':
$type = __( 'Trackback' );
break;
default:
$type = ucwords( $comment->comment_type );
}
$type = esc_html( $type );
?>
<div class="dashboard-comment-wrap has-row-actions">
<p class="comment-meta">
<?php
// Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones.
if ( $comment_post_link ) {
printf(
/* translators: 1: Type of comment, 2: Post link, 3: Notification if the comment is pending. */
_x( '%1$s on %2$s %3$s', 'dashboard' ),
"<strong>$type</strong>",
$comment_post_link,
'<span class="approve">' . __( '[Pending]' ) . '</span>'
);
} else {
printf(
/* translators: 1: Type of comment, 2: Notification if the comment is pending. */
_x( '%1$s %2$s', 'dashboard' ),
"<strong>$type</strong>",
'<span class="approve">' . __( '[Pending]' ) . '</span>'
);
}
?>
</p>
<p class="comment-author"><?php comment_author_link( $comment ); ?></p>
<?php endif; // comment_type ?>
<blockquote><p><?php comment_excerpt( $comment ); ?></p></blockquote>
<?php if ( $actions_string ) : ?>
<p class="row-actions"><?php echo $actions_string; ?></p>
<?php endif; ?>
</div>
</li>
<?php
$GLOBALS['comment'] = null;
}
/**
* Outputs the Activity widget.
*
* Callback function for {@see 'dashboard_activity'}.
*
* @since 3.8.0
*/
function wp_dashboard_site_activity() {
echo '<div id="activity-widget">';
$future_posts = wp_dashboard_recent_posts(
array(
'max' => 5,
'status' => 'future',
'order' => 'ASC',
'title' => __( 'Publishing Soon' ),
'id' => 'future-posts',
)
);
$recent_posts = wp_dashboard_recent_posts(
array(
'max' => 5,
'status' => 'publish',
'order' => 'DESC',
'title' => __( 'Recently Published' ),
'id' => 'published-posts',
)
);
$recent_comments = wp_dashboard_recent_comments();
if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) {
echo '<div class="no-activity">';
echo '<p>' . __( 'No activity yet!' ) . '</p>';
echo '</div>';
}
echo '</div>';
}
/**
* Generates Publishing Soon and Recently Published sections.
*
* @since 3.8.0
*
* @param array $args {
* An array of query and display arguments.
*
* @type int $max Number of posts to display.
* @type string $status Post status.
* @type string $order Designates ascending ('ASC') or descending ('DESC') order.
* @type string $title Section title.
* @type string $id The container id.
* }
* @return bool False if no posts were found. True otherwise.
*/
function wp_dashboard_recent_posts( $args ) {
$query_args = array(
'post_type' => 'post',
'post_status' => $args['status'],
'orderby' => 'date',
'order' => $args['order'],
'posts_per_page' => (int) $args['max'],
'no_found_rows' => true,
'cache_results' => true,
'perm' => ( 'future' === $args['status'] ) ? 'editable' : 'readable',
);
/**
* Filters the query arguments used for the Recent Posts widget.
*
* @since 4.2.0
*
* @param array $query_args The arguments passed to WP_Query to produce the list of posts.
*/
$query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args );
$posts = new WP_Query( $query_args );
if ( $posts->have_posts() ) {
echo '<div id="' . $args['id'] . '" class="activity-block">';
echo '<h3>' . $args['title'] . '</h3>';
echo '<ul>';
$today = current_time( 'Y-m-d' );
$tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
$year = current_time( 'Y' );
while ( $posts->have_posts() ) {
$posts->the_post();
$time = get_the_time( 'U' );
if ( gmdate( 'Y-m-d', $time ) === $today ) {
$relative = __( 'Today' );
} elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) {
$relative = __( 'Tomorrow' );
} elseif ( gmdate( 'Y', $time ) !== $year ) {
/* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */
$relative = date_i18n( __( 'M jS Y' ), $time );
} else {
/* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/manual/datetime.format.php */
$relative = date_i18n( __( 'M jS' ), $time );
}
// Use the post edit link for those who can edit, the permalink otherwise.
$recent_post_link = current_user_can( 'edit_post', get_the_ID() ) ? get_edit_post_link() : get_permalink();
$draft_or_post_title = _draft_or_post_title();
printf(
'<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>',
/* translators: 1: Relative date, 2: Time. */
sprintf( _x( '%1$s, %2$s', 'dashboard' ), $relative, get_the_time() ),
$recent_post_link,
/* translators: %s: Post title. */
esc_attr( sprintf( __( 'Edit “%s”' ), $draft_or_post_title ) ),
$draft_or_post_title
);
}
echo '</ul>';
echo '</div>';
} else {
return false;
}
wp_reset_postdata();
return true;
}
/**
* Show Comments section.
*
* @since 3.8.0
*
* @param int $total_items Optional. Number of comments to query. Default 5.
* @return bool False if no comments were found. True otherwise.
*/
function wp_dashboard_recent_comments( $total_items = 5 ) {
// Select all comment types and filter out spam later for better query performance.
$comments = array();
$comments_query = array(
'number' => $total_items * 5,
'offset' => 0,
);
if ( ! current_user_can( 'edit_posts' ) ) {
$comments_query['status'] = 'approve';
}
while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
if ( ! is_array( $possible ) ) {
break;
}
foreach ( $possible as $comment ) {
if ( ! current_user_can( 'edit_post', $comment->comment_post_ID )
&& ( post_password_required( $comment->comment_post_ID )
|| ! current_user_can( 'read_post', $comment->comment_post_ID ) )
) {
// The user has no access to the post and thus cannot see the comments.
continue;
}
$comments[] = $comment;
if ( count( $comments ) === $total_items ) {
break 2;
}
}
$comments_query['offset'] += $comments_query['number'];
$comments_query['number'] = $total_items * 10;
}
if ( $comments ) {
echo '<div id="latest-comments" class="activity-block table-view-list">';
echo '<h3>' . __( 'Recent Comments' ) . '</h3>';
echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
foreach ( $comments as $comment ) {
_wp_dashboard_recent_comments_row( $comment );
}
echo '</ul>';
if ( current_user_can( 'edit_posts' ) ) {
echo '<h3 class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'View more comments' ) .
'</h3>';
_get_list_table( 'WP_Comments_List_Table' )->views();
}
wp_comment_reply( -1, false, 'dashboard', false );
wp_comment_trashnotice();
echo '</div>';
} else {
return false;
}
return true;
}
/**
* Display generic dashboard RSS widget feed.
*
* @since 2.5.0
*
* @param string $widget_id
*/
function wp_dashboard_rss_output( $widget_id ) {
$widgets = get_option( 'dashboard_widget_options' );
echo '<div class="rss-widget">';
wp_widget_rss_output( $widgets[ $widget_id ] );
echo '</div>';
}
/**
* Checks to see if all of the feed url in $check_urls are cached.
*
* If $check_urls is empty, look for the rss feed url found in the dashboard
* widget options of $widget_id. If cached, call $callback, a function that
* echoes out output for this widget. If not cache, echo a "Loading..." stub
* which is later replaced by Ajax call (see top of /wp-admin/index.php)
*
* @since 2.5.0
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter
* by adding it to the function signature.
*
* @param string $widget_id The widget ID.
* @param callable $callback The callback function used to display each feed.
* @param array $check_urls RSS feeds.
* @param mixed ...$args Optional additional parameters to pass to the callback function.
* @return bool True on success, false on failure.
*/
function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) {
$doing_ajax = wp_doing_ajax();
$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p>';
$loading .= wp_get_admin_notice(
__( 'This widget requires JavaScript.' ),
array(
'type' => 'error',
'additional_classes' => array( 'inline', 'hide-if-js' ),
)
);
if ( empty( $check_urls ) ) {
$widgets = get_option( 'dashboard_widget_options' );
if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) {
echo $loading;
return false;
}
$check_urls = array( $widgets[ $widget_id ]['url'] );
}
$locale = get_user_locale();
$cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
$output = get_transient( $cache_key );
if ( false !== $output ) {
echo $output;
return true;
}
if ( ! $doing_ajax ) {
echo $loading;
return false;
}
if ( $callback && is_callable( $callback ) ) {
array_unshift( $args, $widget_id, $check_urls );
ob_start();
call_user_func_array( $callback, $args );
// Default lifetime in cache of 12 hours (same as the feeds).
set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS );
}
return true;
}
//
// Dashboard Widgets Controls.
//
/**
* Calls widget control callback.
*
* @since 2.5.0
*
* @global callable[] $wp_dashboard_control_callbacks
*
* @param int|false $widget_control_id Optional. Registered widget ID. Default false.
*/
function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
global $wp_dashboard_control_callbacks;
if ( is_scalar( $widget_control_id ) && $widget_control_id
&& isset( $wp_dashboard_control_callbacks[ $widget_control_id ] )
&& is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] )
) {
call_user_func(
$wp_dashboard_control_callbacks[ $widget_control_id ],
'',
array(
'id' => $widget_control_id,
'callback' => $wp_dashboard_control_callbacks[ $widget_control_id ],
)
);
}
}
/**
* Sets up the RSS dashboard widget control and $args to be used as input to wp_widget_rss_form().
*
* Handles POST data from RSS-type widgets.
*
* @since 2.5.0
*
* @param string $widget_id
* @param array $form_inputs
*/
function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
$widget_options = get_option( 'dashboard_widget_options' );
if ( ! $widget_options ) {
$widget_options = array();
}
if ( ! isset( $widget_options[ $widget_id ] ) ) {
$widget_options[ $widget_id ] = array();
}
$number = 1; // Hack to use wp_widget_rss_form().
$widget_options[ $widget_id ]['number'] = $number;
if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
$_POST['widget-rss'][ $number ] = wp_unslash( $_POST['widget-rss'][ $number ] );
$widget_options[ $widget_id ] = wp_widget_rss_process( $_POST['widget-rss'][ $number ] );
$widget_options[ $widget_id ]['number'] = $number;
// Title is optional. If black, fill it if possible.
if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) {
$rss = fetch_feed( $widget_options[ $widget_id ]['url'] );
if ( is_wp_error( $rss ) ) {
$widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) );
} else {
$widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) );
$rss->__destruct();
unset( $rss );
}
}
update_option( 'dashboard_widget_options', $widget_options, false );
$locale = get_user_locale();
$cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
delete_transient( $cache_key );
}
wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs );
}
/**
* Renders the Events and News dashboard widget.
*
* @since 4.8.0
*/
function wp_dashboard_events_news() {
wp_print_community_events_markup();
?>
<div class="wordpress-news hide-if-no-js">
<?php wp_dashboard_primary(); ?>
</div>
<p class="community-events-footer">
<?php
printf(
'<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
'https://make.wordpress.org/community/meetups-landing-page',
__( 'Meetups' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
);
?>
|
<?php
printf(
'<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
'https://central.wordcamp.org/schedule/',
__( 'WordCamps' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
);
?>
|
<?php
printf(
'<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
/* translators: If a Rosetta site exists (e.g. https://es.wordpress.org/news/), then use that. Otherwise, leave untranslated. */
esc_url( _x( 'https://wordpress.org/news/', 'Events and News dashboard widget' ) ),
__( 'News' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
);
?>
</p>
<?php
}
/**
* Prints the markup for the Community Events section of the Events and News Dashboard widget.
*
* @since 4.8.0
*/
function wp_print_community_events_markup() {
$community_events_notice = '<p class="hide-if-js">' . ( 'This widget requires JavaScript.' ) . '</p>';
$community_events_notice .= '<p class="community-events-error-occurred" aria-hidden="true">' . __( 'An error occurred. Please try again.' ) . '</p>';
$community_events_notice .= '<p class="community-events-could-not-locate" aria-hidden="true"></p>';
wp_admin_notice(
$community_events_notice,
array(
'type' => 'error',
'additional_classes' => array( 'community-events-errors', 'inline', 'hide-if-js' ),
'paragraph_wrap' => false,
)
);
/*
* Hide the main element when the page first loads, because the content
* won't be ready until wp.communityEvents.renderEventsTemplate() has run.
*/
?>
<div id="community-events" class="community-events" aria-hidden="true">
<div class="activity-block">
<p>
<span id="community-events-location-message"></span>
<button class="button-link community-events-toggle-location" aria-expanded="false">
<span class="dashicons dashicons-location" aria-hidden="true"></span>
<span class="community-events-location-edit"><?php _e( 'Select location' ); ?></span>
</button>
</p>
<form class="community-events-form" aria-hidden="true" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
<label for="community-events-location">
<?php _e( 'City:' ); ?>
</label>
<?php
/* translators: Replace with a city related to your locale.
* Test that it matches the expected location and has upcoming
* events before including it. If no cities related to your
* locale have events, then use a city related to your locale
* that would be recognizable to most users. Use only the city
* name itself, without any region or country. Use the endonym
* (native locale name) instead of the English name if possible.
*/
?>
<input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php esc_attr_e( 'Cincinnati' ); ?>" />
<?php submit_button( __( 'Submit' ), 'secondary', 'community-events-submit', false ); ?>
<button class="community-events-cancel button-link" type="button" aria-expanded="false">
<?php _e( 'Cancel' ); ?>
</button>
<span class="spinner"></span>
</form>
</div>
<ul class="community-events-results activity-block last"></ul>
</div>
<?php
}
/**
* Renders the events templates for the Event and News widget.
*
* @since 4.8.0
*/
function wp_print_community_events_templates() {
?>
<script id="tmpl-community-events-attend-event-near" type="text/template">
<?php
printf(
/* translators: %s: The name of a city. */
__( 'Attend an upcoming event near %s.' ),
'<strong>{{ data.location.description }}</strong>'
);
?>
</script>
<script id="tmpl-community-events-could-not-locate" type="text/template">
<?php
printf(
/* translators: %s is the name of the city we couldn't locate.
* Replace the examples with cities in your locale, but test
* that they match the expected location before including them.
* Use endonyms (native locale names) whenever possible.
*/
__( '%s could not be located. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
'<em>{{data.unknownCity}}</em>'
);
?>
</script>
<script id="tmpl-community-events-event-list" type="text/template">
<# _.each( data.events, function( event ) { #>
<li class="event event-{{ event.type }} wp-clearfix">
<div class="event-info">
<div class="dashicons event-icon" aria-hidden="true"></div>
<div class="event-info-inner">
<a class="event-title" href="{{ event.url }}">{{ event.title }}</a>
<# if ( event.type ) {
const titleCaseEventType = event.type.replace(
/\w\S*/g,
function ( type ) { return type.charAt(0).toUpperCase() + type.substr(1).toLowerCase(); }
);
#>
{{ 'wordcamp' === event.type ? 'WordCamp' : titleCaseEventType }}
<span class="ce-separator"></span>
<# } #>
<span class="event-city">{{ event.location.location }}</span>
</div>
</div>
<div class="event-date-time">
<span class="event-date">{{ event.user_formatted_date }}</span>
<# if ( 'meetup' === event.type ) { #>
<span class="event-time">
{{ event.user_formatted_time }} {{ event.timeZoneAbbreviation }}
</span>
<# } #>
</div>
</li>
<# } ) #>
<# if ( data.events.length <= 2 ) { #>
<li class="event-none">
<?php
printf(
/* translators: %s: Localized meetup organization documentation URL. */
__( 'Want more events? <a href="%s">Help organize the next one</a>!' ),
__( 'https://make.wordpress.org/community/organize-event-landing-page/' )
);
?>
</li>
<# } #>
</script>
<script id="tmpl-community-events-no-upcoming-events" type="text/template">
<li class="event-none">
<# if ( data.location.description ) { #>
<?php
printf(
/* translators: 1: The city the user searched for, 2: Meetup organization documentation URL. */
__( 'There are no events scheduled near %1$s at the moment. Would you like to <a href="%2$s">organize a WordPress event</a>?' ),
'{{ data.location.description }}',
__( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
);
?>
<# } else { #>
<?php
printf(
/* translators: %s: Meetup organization documentation URL. */
__( 'There are no events scheduled near you at the moment. Would you like to <a href="%s">organize a WordPress event</a>?' ),
__( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
);
?>
<# } #>
</li>
</script>
<?php
}
/**
* 'WordPress Events and News' dashboard widget.
*
* @since 2.7.0
* @since 4.8.0 Removed popular plugins feed.
*/
function wp_dashboard_primary() {
$feeds = array(
'news' => array(
/**
* Filters the primary link URL for the 'WordPress Events and News' dashboard widget.
*
* @since 2.5.0
*
* @param string $link The widget's primary link URL.
*/
'link' => apply_filters( 'dashboard_primary_link', __( 'https://wordpress.org/news/' ) ),
/**
* Filters the primary feed URL for the 'WordPress Events and News' dashboard widget.
*
* @since 2.3.0
*
* @param string $url The widget's primary feed URL.
*/
'url' => apply_filters( 'dashboard_primary_feed', __( 'https://wordpress.org/news/feed/' ) ),
/**
* Filters the primary link title for the 'WordPress Events and News' dashboard widget.
*
* @since 2.3.0
*
* @param string $title Title attribute for the widget's primary link.
*/
'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
'items' => 2,
'show_summary' => 0,
'show_author' => 0,
'show_date' => 0,
),
'planet' => array(
/**
* Filters the secondary link URL for the 'WordPress Events and News' dashboard widget.
*
* @since 2.3.0
*
* @param string $link The widget's secondary link URL.
*/
'link' => apply_filters(
'dashboard_secondary_link',
/* translators: Link to the Planet website of the locale. */
__( 'https://planet.wordpress.org/' )
),
/**
* Filters the secondary feed URL for the 'WordPress Events and News' dashboard widget.
*
* @since 2.3.0
*
* @param string $url The widget's secondary feed URL.
*/
'url' => apply_filters(
'dashboard_secondary_feed',
/* translators: Link to the Planet feed of the locale. */
__( 'https://planet.wordpress.org/feed/' )
),
/**
* Filters the secondary link title for the 'WordPress Events and News' dashboard widget.
*
* @since 2.3.0
*
* @param string $title Title attribute for the widget's secondary link.
*/
'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
/**
* Filters the number of secondary link items for the 'WordPress Events and News' dashboard widget.
*
* @since 4.4.0
*
* @param string $items How many items to show in the secondary feed.
*/
'items' => apply_filters( 'dashboard_secondary_items', 3 ),
'show_summary' => 0,
'show_author' => 0,
'show_date' => 0,
),
);
wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
}
/**
* Displays the WordPress events and news feeds.
*
* @since 3.8.0
* @since 4.8.0 Removed popular plugins feed.
*
* @param string $widget_id Widget ID.
* @param array $feeds Array of RSS feeds.
*/
function wp_dashboard_primary_output( $widget_id, $feeds ) {
foreach ( $feeds as $type => $args ) {
$args['type'] = $type;
echo '<div class="rss-widget">';
wp_widget_rss_output( $args['url'], $args );
echo '</div>';
}
}
/**
* Displays file upload quota on dashboard.
*
* Runs on the {@see 'activity_box_end'} hook in wp_dashboard_right_now().
*
* @since 3.0.0
*
* @return true|void True if not multisite, user can't upload files, or the space check option is disabled.
*/
function wp_dashboard_quota() {
if ( ! is_multisite() || ! current_user_can( 'upload_files' )
|| get_site_option( 'upload_space_check_disabled' )
) {
return true;
}
$quota = get_space_allowed();
$used = get_space_used();
if ( $used > $quota ) {
$percentused = '100';
} else {
$percentused = ( $used / $quota ) * 100;
}
$used_class = ( $percentused >= 70 ) ? ' warning' : '';
$used = round( $used, 2 );
$percentused = number_format( $percentused );
?>
<h3 class="mu-storage"><?php _e( 'Storage Space' ); ?></h3>
<div class="mu-storage">
<ul>
<li class="storage-count">
<?php
$text = sprintf(
/* translators: %s: Number of megabytes. */
__( '%s MB Space Allowed' ),
number_format_i18n( $quota )
);
printf(
'<a href="%1$s">%2$s<span class="screen-reader-text"> (%3$s)</span></a>',
esc_url( admin_url( 'upload.php' ) ),
$text,
/* translators: Hidden accessibility text. */
__( 'Manage Uploads' )
);
?>
</li><li class="storage-count <?php echo $used_class; ?>">
<?php
$text = sprintf(
/* translators: 1: Number of megabytes, 2: Percentage. */
__( '%1$s MB (%2$s%%) Space Used' ),
number_format_i18n( $used, 2 ),
$percentused
);
printf(
'<a href="%1$s" class="musublink">%2$s<span class="screen-reader-text"> (%3$s)</span></a>',
esc_url( admin_url( 'upload.php' ) ),
$text,
/* translators: Hidden accessibility text. */
__( 'Manage Uploads' )
);
?>
</li>
</ul>
</div>
<?php
}
/**
* Displays the browser update nag.
*
* @since 3.2.0
* @since 5.8.0 Added a special message for Internet Explorer users.
*
* @global bool $is_IE
*/
function wp_dashboard_browser_nag() {
global $is_IE;
$notice = '';
$response = wp_check_browser_version();
if ( $response ) {
if ( $is_IE ) {
$msg = __( 'Internet Explorer does not give you the best WordPress experience. Switch to Microsoft Edge, or another more modern browser to get the most from your site.' );
} elseif ( $response['insecure'] ) {
$msg = sprintf(
/* translators: %s: Browser name and link. */
__( "It looks like you're using an insecure version of %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ),
sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
);
} else {
$msg = sprintf(
/* translators: %s: Browser name and link. */
__( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ),
sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
);
}
$browser_nag_class = '';
if ( ! empty( $response['img_src'] ) ) {
$img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) ) ? $response['img_src_ssl'] : $response['img_src'];
$notice .= '<div class="alignright browser-icon"><img src="' . esc_url( $img_src ) . '" alt="" /></div>';
$browser_nag_class = ' has-browser-icon';
}
$notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
$browsehappy = 'https://browsehappy.com/';
$locale = get_user_locale();
if ( 'en_US' !== $locale ) {
$browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
}
if ( $is_IE ) {
$msg_browsehappy = sprintf(
/* translators: %s: Browse Happy URL. */
__( 'Learn how to <a href="%s" class="update-browser-link">browse happy</a>' ),
esc_url( $browsehappy )
);
} else {
$msg_browsehappy = sprintf(
/* translators: 1: Browser update URL, 2: Browser name, 3: Browse Happy URL. */
__( '<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>' ),
esc_attr( $response['update_url'] ),
esc_html( $response['name'] ),
esc_url( $browsehappy )
);
}
$notice .= '<p>' . $msg_browsehappy . '</p>';
$notice .= '<p class="hide-if-no-js"><a href="" class="dismiss" aria-label="' . esc_attr__( 'Dismiss the browser warning panel' ) . '">' . __( 'Dismiss' ) . '</a></p>';
$notice .= '<div class="clear"></div>';
}
/**
* Filters the notice output for the 'Browse Happy' nag meta box.
*
* @since 3.2.0
*
* @param string $notice The notice content.
* @param array|false $response An array containing web browser information, or
* false on failure. See wp_check_browser_version().
*/
echo apply_filters( 'browse-happy-notice', $notice, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
}
/**
* Adds an additional class to the browser nag if the current version is insecure.
*
* @since 3.2.0
*
* @param string[] $classes Array of meta box classes.
* @return string[] Modified array of meta box classes.
*/
function dashboard_browser_nag_class( $classes ) {
$response = wp_check_browser_version();
if ( $response && $response['insecure'] ) {
$classes[] = 'browser-insecure';
}
return $classes;
}
/**
* Checks if the user needs a browser update.
*
* @since 3.2.0
*
* @return array|false Array of browser data on success, false on failure.
*/
function wp_check_browser_version() {
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
return false;
}
$key = md5( $_SERVER['HTTP_USER_AGENT'] );
$response = get_site_transient( 'browser_' . $key );
if ( false === $response ) {
$url = 'http://api.wordpress.org/core/browse-happy/1.1/';
$options = array(
'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),
);
if ( wp_http_supports( array( 'ssl' ) ) ) {
$url = set_url_scheme( $url, 'https' );
}
$response = wp_remote_post( $url, $options );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
return false;
}
/**
* Response should be an array with:
* 'platform' - string - A user-friendly platform name, if it can be determined
* 'name' - string - A user-friendly browser name
* 'version' - string - The version of the browser the user is using
* 'current_version' - string - The most recent version of the browser
* 'upgrade' - boolean - Whether the browser needs an upgrade
* 'insecure' - boolean - Whether the browser is deemed insecure
* 'update_url' - string - The url to visit to upgrade
* 'img_src' - string - An image representing the browser
* 'img_src_ssl' - string - An image (over SSL) representing the browser
*/
$response = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! is_array( $response ) ) {
return false;
}
set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
}
return $response;
}
/**
* Displays the PHP update nag.
*
* @since 5.1.0
*/
function wp_dashboard_php_nag() {
$response = wp_check_php_version();
if ( ! $response ) {
return;
}
if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) {
// The `is_secure` array key name doesn't actually imply this is a secure version of PHP. It only means it receives security updates.
if ( $response['is_lower_than_future_minimum'] ) {
$message = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates and soon will not be supported by WordPress. Ensure that PHP is updated on your server as soon as possible. Otherwise you will not be able to upgrade WordPress.' ),
PHP_VERSION
);
} else {
$message = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates. It should be updated.' ),
PHP_VERSION
);
}
} elseif ( $response['is_lower_than_future_minimum'] ) {
$message = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running on an outdated version of PHP (%s), which soon will not be supported by WordPress. Ensure that PHP is updated on your server as soon as possible. Otherwise you will not be able to upgrade WordPress.' ),
PHP_VERSION
);
} else {
$message = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running on an outdated version of PHP (%s), which should be updated.' ),
PHP_VERSION
);
}
?>
<p class="bigger-bolder-text"><?php echo $message; ?></p>
<p><?php _e( 'What is PHP and how does it affect my site?' ); ?></p>
<p>
<?php _e( 'PHP is one of the programming languages used to build WordPress. Newer versions of PHP receive regular security updates and may increase your site’s performance.' ); ?>
<?php
if ( ! empty( $response['recommended_version'] ) ) {
printf(
/* translators: %s: The minimum recommended PHP version. */
__( 'The minimum recommended version of PHP is %s.' ),
$response['recommended_version']
);
}
?>
</p>
<p class="button-container">
<?php
printf(
'<a class="button button-primary" href="%1$s" target="_blank">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
esc_url( wp_get_update_php_url() ),
__( 'Learn more about updating PHP' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
);
?>
</p>
<?php
wp_update_php_annotation();
wp_direct_php_update_button();
}
/**
* Adds an additional class to the PHP nag if the current version is insecure.
*
* @since 5.1.0
*
* @param string[] $classes Array of meta box classes.
* @return string[] Modified array of meta box classes.
*/
function dashboard_php_nag_class( $classes ) {
$response = wp_check_php_version();
if ( ! $response ) {
return $classes;
}
if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) {
$classes[] = 'php-no-security-updates';
} elseif ( $response['is_lower_than_future_minimum'] ) {
$classes[] = 'php-version-lower-than-future-minimum';
}
return $classes;
}
/**
* Displays the Site Health Status widget.
*
* @since 5.4.0
*/
function wp_dashboard_site_health() {
$get_issues = get_transient( 'health-check-site-status-result' );
$issue_counts = array();
if ( false !== $get_issues ) {
$issue_counts = json_decode( $get_issues, true );
}
if ( ! is_array( $issue_counts ) || ! $issue_counts ) {
$issue_counts = array(
'good' => 0,
'recommended' => 0,
'critical' => 0,
);
}
$issues_total = $issue_counts['recommended'] + $issue_counts['critical'];
?>
<div class="health-check-widget">
<div class="health-check-widget-title-section site-health-progress-wrapper loading hide-if-no-js">
<div class="site-health-progress">
<svg aria-hidden="true" focusable="false" width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
<circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
</svg>
</div>
<div class="site-health-progress-label">
<?php if ( false === $get_issues ) : ?>
<?php _e( 'No information yet…' ); ?>
<?php else : ?>
<?php _e( 'Results are still loading…' ); ?>
<?php endif; ?>
</div>
</div>
<div class="site-health-details">
<?php if ( false === $get_issues ) : ?>
<p>
<?php
printf(
/* translators: %s: URL to Site Health screen. */
__( 'Site health checks will automatically run periodically to gather information about your site. You can also <a href="%s">visit the Site Health screen</a> to gather information about your site now.' ),
esc_url( admin_url( 'site-health.php' ) )
);
?>
</p>
<?php else : ?>
<p>
<?php if ( $issues_total <= 0 ) : ?>
<?php _e( 'Great job! Your site currently passes all site health checks.' ); ?>
<?php elseif ( 1 === (int) $issue_counts['critical'] ) : ?>
<?php _e( 'Your site has a critical issue that should be addressed as soon as possible to improve its performance and security.' ); ?>
<?php elseif ( $issue_counts['critical'] > 1 ) : ?>
<?php _e( 'Your site has critical issues that should be addressed as soon as possible to improve its performance and security.' ); ?>
<?php elseif ( 1 === (int) $issue_counts['recommended'] ) : ?>
<?php _e( 'Your site’s health is looking good, but there is still one thing you can do to improve its performance and security.' ); ?>
<?php else : ?>
<?php _e( 'Your site’s health is looking good, but there are still some things you can do to improve its performance and security.' ); ?>
<?php endif; ?>
</p>
<?php endif; ?>
<?php if ( $issues_total > 0 && false !== $get_issues ) : ?>
<p>
<?php
printf(
/* translators: 1: Number of issues. 2: URL to Site Health screen. */
_n(
'Take a look at the <strong>%1$d item</strong> on the <a href="%2$s">Site Health screen</a>.',
'Take a look at the <strong>%1$d items</strong> on the <a href="%2$s">Site Health screen</a>.',
$issues_total
),
$issues_total,
esc_url( admin_url( 'site-health.php' ) )
);
?>
</p>
<?php endif; ?>
</div>
</div>
<?php
}
/**
* Outputs empty dashboard widget to be populated by JS later.
*
* Usable by plugins.
*
* @since 2.5.0
*/
function wp_dashboard_empty() {}
/**
* Displays a welcome panel to introduce users to WordPress.
*
* @since 3.3.0
* @since 5.9.0 Send users to the Site Editor if the active theme is block-based.
*/
function wp_welcome_panel() {
list( $display_version ) = explode( '-', wp_get_wp_version() );
$can_customize = current_user_can( 'customize' );
$is_block_theme = wp_is_block_theme();
?>
<div class="welcome-panel-content">
<div class="welcome-panel-header">
<div class="welcome-panel-header-image">
<?php echo file_get_contents( dirname( __DIR__ ) . '/images/dashboard-background.svg' ); ?>
</div>
<h2><?php _e( 'Welcome to WordPress!' ); ?></h2>
<p>
<a href="<?php echo esc_url( admin_url( 'about.php' ) ); ?>">
<?php
/* translators: %s: Current WordPress version. */
printf( __( 'Learn more about the %s version.' ), esc_html( $display_version ) );
?>
</a>
</p>
</div>
<div class="welcome-panel-column-container">
<div class="welcome-panel-column">
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
<rect width="48" height="48" rx="4" fill="#1E1E1E"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M32.0668 17.0854L28.8221 13.9454L18.2008 24.671L16.8983 29.0827L21.4257 27.8309L32.0668 17.0854ZM16 32.75H24V31.25H16V32.75Z" fill="white"/>
</svg>
<div class="welcome-panel-column-content">
<h3><?php _e( 'Author rich content with blocks and patterns' ); ?></h3>
<p><?php _e( 'Block patterns are pre-configured block layouts. Use them to get inspired or create new pages in a flash.' ); ?></p>
<a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=page' ) ); ?>"><?php _e( 'Add a new page' ); ?></a>
</div>
</div>
<div class="welcome-panel-column">
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
<rect width="48" height="48" rx="4" fill="#1E1E1E"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M18 16h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H18a2 2 0 0 1-2-2V18a2 2 0 0 1 2-2zm12 1.5H18a.5.5 0 0 0-.5.5v3h13v-3a.5.5 0 0 0-.5-.5zm.5 5H22v8h8a.5.5 0 0 0 .5-.5v-7.5zm-10 0h-3V30a.5.5 0 0 0 .5.5h2.5v-8z" fill="#fff"/>
</svg>
<div class="welcome-panel-column-content">
<?php if ( $is_block_theme ) : ?>
<h3><?php _e( 'Customize your entire site with block themes' ); ?></h3>
<p><?php _e( 'Design everything on your site — from the header down to the footer, all using blocks and patterns.' ); ?></p>
<a href="<?php echo esc_url( admin_url( 'site-editor.php' ) ); ?>"><?php _e( 'Open site editor' ); ?></a>
<?php else : ?>
<h3><?php _e( 'Start Customizing' ); ?></h3>
<p><?php _e( 'Configure your site’s logo, header, menus, and more in the Customizer.' ); ?></p>
<?php if ( $can_customize ) : ?>
<a class="load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"><?php _e( 'Open the Customizer' ); ?></a>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
<div class="welcome-panel-column">
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
<rect width="48" height="48" rx="4" fill="#1E1E1E"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M31 24a7 7 0 0 1-7 7V17a7 7 0 0 1 7 7zm-7-8a8 8 0 1 1 0 16 8 8 0 0 1 0-16z" fill="#fff"/>
</svg>
<div class="welcome-panel-column-content">
<?php if ( $is_block_theme ) : ?>
<h3><?php _e( 'Switch up your site’s look & feel with Styles' ); ?></h3>
<p><?php _e( 'Tweak your site, or give it a whole new look! Get creative — how about a new color palette or font?' ); ?></p>
<a href="<?php echo esc_url( admin_url( '/site-editor.php?path=%2Fwp_global_styles' ) ); ?>"><?php _e( 'Edit styles' ); ?></a>
<?php else : ?>
<h3><?php _e( 'Discover a new way to build your site.' ); ?></h3>
<p><?php _e( 'There is a new kind of WordPress theme, called a block theme, that lets you build the site you’ve always wanted — with blocks and styles.' ); ?></p>
<a href="<?php echo esc_url( __( 'https://wordpress.org/documentation/article/block-themes/' ) ); ?>"><?php _e( 'Learn about block themes' ); ?></a>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
}
PK %�[O�_�N N theme-install.phpnu �[��� <?php
/**
* WordPress Theme Installation Administration API
*
* @package WordPress
* @subpackage Administration
*/
$themes_allowedtags = array(
'a' => array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'code' => array(),
'pre' => array(),
'em' => array(),
'strong' => array(),
'div' => array(),
'p' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'h1' => array(),
'h2' => array(),
'h3' => array(),
'h4' => array(),
'h5' => array(),
'h6' => array(),
'img' => array(
'src' => array(),
'class' => array(),
'alt' => array(),
),
);
$theme_field_defaults = array(
'description' => true,
'sections' => false,
'tested' => true,
'requires' => true,
'rating' => true,
'downloaded' => true,
'downloadlink' => true,
'last_updated' => true,
'homepage' => true,
'tags' => true,
'num_ratings' => true,
);
/**
* Retrieves the list of WordPress theme features (aka theme tags).
*
* @since 2.8.0
*
* @deprecated 3.1.0 Use get_theme_feature_list() instead.
*
* @return array
*/
function install_themes_feature_list() {
_deprecated_function( __FUNCTION__, '3.1.0', 'get_theme_feature_list()' );
$cache = get_transient( 'wporg_theme_feature_list' );
if ( ! $cache ) {
set_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
}
if ( $cache ) {
return $cache;
}
$feature_list = themes_api( 'feature_list', array() );
if ( is_wp_error( $feature_list ) ) {
return array();
}
set_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
return $feature_list;
}
/**
* Displays search form for searching themes.
*
* @since 2.8.0
*
* @param bool $type_selector
*/
function install_theme_search_form( $type_selector = true ) {
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
if ( ! $type_selector ) {
echo '<p class="install-help">' . __( 'Search for themes by keyword.' ) . '</p>';
}
?>
<form id="search-themes" method="get">
<input type="hidden" name="tab" value="search" />
<?php if ( $type_selector ) : ?>
<label class="screen-reader-text" for="typeselector">
<?php
/* translators: Hidden accessibility text. */
_e( 'Type of search' );
?>
</label>
<select name="type" id="typeselector">
<option value="term" <?php selected( 'term', $type ); ?>><?php _e( 'Keyword' ); ?></option>
<option value="author" <?php selected( 'author', $type ); ?>><?php _e( 'Author' ); ?></option>
<option value="tag" <?php selected( 'tag', $type ); ?>><?php _ex( 'Tag', 'Theme Installer' ); ?></option>
</select>
<label class="screen-reader-text" for="s">
<?php
switch ( $type ) {
case 'term':
/* translators: Hidden accessibility text. */
_e( 'Search by keyword' );
break;
case 'author':
/* translators: Hidden accessibility text. */
_e( 'Search by author' );
break;
case 'tag':
/* translators: Hidden accessibility text. */
_e( 'Search by tag' );
break;
}
?>
</label>
<?php else : ?>
<label class="screen-reader-text" for="s">
<?php
/* translators: Hidden accessibility text. */
_e( 'Search by keyword' );
?>
</label>
<?php endif; ?>
<input type="search" name="s" id="s" size="30" value="<?php echo esc_attr( $term ); ?>" autofocus="autofocus" />
<?php submit_button( __( 'Search' ), '', 'search', false ); ?>
</form>
<?php
}
/**
* Displays tags filter for themes.
*
* @since 2.8.0
*/
function install_themes_dashboard() {
install_theme_search_form( false );
?>
<h4><?php _e( 'Feature Filter' ); ?></h4>
<p class="install-help"><?php _e( 'Find a theme based on specific features.' ); ?></p>
<form method="get">
<input type="hidden" name="tab" value="search" />
<?php
$feature_list = get_theme_feature_list();
echo '<div class="feature-filter">';
foreach ( (array) $feature_list as $feature_name => $features ) {
$feature_name = esc_html( $feature_name );
echo '<div class="feature-name">' . $feature_name . '</div>';
echo '<ol class="feature-group">';
foreach ( $features as $feature => $feature_name ) {
$feature_name = esc_html( $feature_name );
$feature = esc_attr( $feature );
?>
<li>
<input type="checkbox" name="features[]" id="feature-id-<?php echo $feature; ?>" value="<?php echo $feature; ?>" />
<label for="feature-id-<?php echo $feature; ?>"><?php echo $feature_name; ?></label>
</li>
<?php } ?>
</ol>
<br class="clear" />
<?php
}
?>
</div>
<br class="clear" />
<?php submit_button( __( 'Find Themes' ), '', 'search' ); ?>
</form>
<?php
}
/**
* Displays a form to upload themes from zip files.
*
* @since 2.8.0
*/
function install_themes_upload() {
?>
<p class="install-help"><?php _e( 'If you have a theme in a .zip format, you may install or update it by uploading it here.' ); ?></p>
<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo esc_url( self_admin_url( 'update.php?action=upload-theme' ) ); ?>">
<?php wp_nonce_field( 'theme-upload' ); ?>
<label class="screen-reader-text" for="themezip">
<?php
/* translators: Hidden accessibility text. */
_e( 'Theme zip file' );
?>
</label>
<input type="file" id="themezip" name="themezip" accept=".zip" />
<?php submit_button( _x( 'Install Now', 'theme' ), '', 'install-theme-submit', false ); ?>
</form>
<?php
}
/**
* Prints a theme on the Install Themes pages.
*
* @deprecated 3.4.0
*
* @global WP_Theme_Install_List_Table $wp_list_table
*
* @param object $theme
*/
function display_theme( $theme ) {
_deprecated_function( __FUNCTION__, '3.4.0' );
global $wp_list_table;
if ( ! isset( $wp_list_table ) ) {
$wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
}
$wp_list_table->prepare_items();
$wp_list_table->single_row( $theme );
}
/**
* Displays theme content based on theme list.
*
* @since 2.8.0
*
* @global WP_Theme_Install_List_Table $wp_list_table
*/
function display_themes() {
global $wp_list_table;
if ( ! isset( $wp_list_table ) ) {
$wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
}
$wp_list_table->prepare_items();
$wp_list_table->display();
}
/**
* Displays theme information in dialog box form.
*
* @since 2.8.0
*
* @global WP_Theme_Install_List_Table $wp_list_table
*/
function install_theme_information() {
global $wp_list_table;
$theme = themes_api( 'theme_information', array( 'slug' => wp_unslash( $_REQUEST['theme'] ) ) );
if ( is_wp_error( $theme ) ) {
wp_die( $theme );
}
iframe_header( __( 'Theme Installation' ) );
if ( ! isset( $wp_list_table ) ) {
$wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
}
$wp_list_table->theme_installer_single( $theme );
iframe_footer();
exit;
}
PK %�[[��5d7 d7 class-walker-nav-menu-edit.phpnu �[��� <?php
/**
* Navigation Menu API: Walker_Nav_Menu_Edit class
*
* @package WordPress
* @subpackage Administration
* @since 4.4.0
*/
/**
* Create HTML list of nav menu input items.
*
* @since 3.0.0
*
* @see Walker_Nav_Menu
*/
class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
/**
* Starts the list before the elements are added.
*
* @see Walker_Nav_Menu::start_lvl()
*
* @since 3.0.0
*
* @param string $output Passed by reference.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args Not used.
*/
public function start_lvl( &$output, $depth = 0, $args = null ) {}
/**
* Ends the list of after the elements are added.
*
* @see Walker_Nav_Menu::end_lvl()
*
* @since 3.0.0
*
* @param string $output Passed by reference.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args Not used.
*/
public function end_lvl( &$output, $depth = 0, $args = null ) {}
/**
* Start the element output.
*
* @see Walker_Nav_Menu::start_el()
* @since 3.0.0
* @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @global int $_wp_nav_menu_max_depth
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $data_object Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args Not used.
* @param int $current_object_id Optional. ID of the current menu item. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
global $_wp_nav_menu_max_depth;
// Restores the more descriptive, specific name for use within this method.
$menu_item = $data_object;
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
ob_start();
$item_id = esc_attr( $menu_item->ID );
$removed_args = array(
'action',
'customlink-tab',
'edit-menu-item',
'menu-item',
'page-tab',
'_wpnonce',
);
$original_title = false;
if ( 'taxonomy' === $menu_item->type ) {
$original_object = get_term( (int) $menu_item->object_id, $menu_item->object );
if ( $original_object && ! is_wp_error( $original_object ) ) {
$original_title = $original_object->name;
}
} elseif ( 'post_type' === $menu_item->type ) {
$original_object = get_post( $menu_item->object_id );
if ( $original_object ) {
$original_title = get_the_title( $original_object->ID );
}
} elseif ( 'post_type_archive' === $menu_item->type ) {
$original_object = get_post_type_object( $menu_item->object );
if ( $original_object ) {
$original_title = $original_object->labels->archives;
}
}
$classes = array(
'menu-item menu-item-depth-' . $depth,
'menu-item-' . esc_attr( $menu_item->object ),
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ),
);
$title = $menu_item->title;
if ( ! empty( $menu_item->_invalid ) ) {
$classes[] = 'menu-item-invalid';
/* translators: %s: Title of an invalid menu item. */
$title = sprintf( __( '%s (Invalid)' ), $menu_item->title );
} elseif ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) {
$classes[] = 'pending';
/* translators: %s: Title of a menu item in draft status. */
$title = sprintf( __( '%s (Pending)' ), $menu_item->title );
}
$title = ( ! isset( $menu_item->label ) || '' === $menu_item->label ) ? $title : $menu_item->label;
$submenu_text = '';
if ( 0 === $depth ) {
$submenu_text = 'style="display: none;"';
}
?>
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>">
<div class="menu-item-bar">
<div class="menu-item-handle">
<label class="item-title" for="menu-item-checkbox-<?php echo $item_id; ?>">
<input id="menu-item-checkbox-<?php echo $item_id; ?>" type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo $item_id; ?>" disabled="disabled" />
<span class="menu-item-title"><?php echo esc_html( $title ); ?></span>
<span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span>
</label>
<span class="item-controls">
<span class="item-type"><?php echo esc_html( $menu_item->type_label ); ?></span>
<span class="item-order hide-if-js">
<?php
printf(
'<a href="%s" class="item-move-up" aria-label="%s">↑</a>',
wp_nonce_url(
add_query_arg(
array(
'action' => 'move-up-menu-item',
'menu-item' => $item_id,
),
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
),
'move-menu_item'
),
esc_attr__( 'Move up' )
);
?>
|
<?php
printf(
'<a href="%s" class="item-move-down" aria-label="%s">↓</a>',
wp_nonce_url(
add_query_arg(
array(
'action' => 'move-down-menu-item',
'menu-item' => $item_id,
),
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
),
'move-menu_item'
),
esc_attr__( 'Move down' )
);
?>
</span>
<?php
if ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) {
$edit_url = admin_url( 'nav-menus.php' );
} else {
$edit_url = add_query_arg(
array(
'edit-menu-item' => $item_id,
),
remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) )
);
}
printf(
'<a class="item-edit" id="edit-%s" href="%s" aria-label="%s"><span class="screen-reader-text">%s</span></a>',
$item_id,
esc_url( $edit_url ),
esc_attr__( 'Edit menu item' ),
/* translators: Hidden accessibility text. */
__( 'Edit' )
);
?>
</span>
</div>
</div>
<div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
<?php if ( 'custom' === $menu_item->type ) : ?>
<p class="field-url description description-wide">
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
<?php _e( 'URL' ); ?><br />
<input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->url ); ?>" />
</label>
</p>
<?php endif; ?>
<p class="description description-wide">
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
<?php _e( 'Navigation Label' ); ?><br />
<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->title ); ?>" />
</label>
</p>
<p class="field-title-attribute field-attr-title description description-wide">
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
<?php _e( 'Title Attribute' ); ?><br />
<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->post_excerpt ); ?>" />
</label>
</p>
<p class="field-link-target description">
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
<input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $menu_item->target, '_blank' ); ?> />
<?php _e( 'Open link in a new tab' ); ?>
</label>
</p>
<div class="description-group">
<p class="field-css-classes description description-thin">
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
<?php _e( 'CSS Classes (optional)' ); ?><br />
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode( ' ', $menu_item->classes ) ); ?>" />
</label>
</p>
<p class="field-xfn description description-thin">
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
<?php _e( 'Link Relationship (XFN)' ); ?><br />
<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->xfn ); ?>" />
</label>
</p>
</div>
<p class="field-description description description-wide">
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
<?php _e( 'Description' ); ?><br />
<textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $menu_item->description ); // textarea_escaped ?></textarea>
<span class="description"><?php _e( 'The description will be displayed in the menu if the active theme supports it.' ); ?></span>
</label>
</p>
<?php
/**
* Update parent and order of menu item using select inputs.
*
* @since 6.7.0
*/
?>
<div class="field-move-combo description-group">
<p class="description description-wide">
<label for="edit-menu-item-parent-<?php echo $item_id; ?>">
<?php _e( 'Menu Parent' ); ?>
</label>
<select class="edit-menu-item-parent widefat" id="edit-menu-item-parent-<?php echo $item_id; ?>" name="menu-item-parent[<?php echo $item_id; ?>]">
</select>
</p>
<p class="description description-wide">
<label for="edit-menu-item-order-<?php echo $item_id; ?>">
<?php _e( 'Menu Order' ); ?>
</label>
<select class="edit-menu-item-order widefat" id="edit-menu-item-order-<?php echo $item_id; ?>" name="menu-item-order[<?php echo $item_id; ?>]">
</select>
</p>
</div>
<?php
/**
* Fires just before the move buttons of a nav menu item in the menu editor.
*
* @since 5.4.0
*
* @param string $item_id Menu item ID as a numeric string.
* @param WP_Post $menu_item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass|null $args An object of menu item arguments.
* @param int $current_object_id Nav menu ID.
*/
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id );
?>
<fieldset class="field-move hide-if-no-js description description-wide">
<span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move' ); ?></span>
<button type="button" class="button-link menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></button>
<button type="button" class="button-link menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></button>
<button type="button" class="button-link menus-move menus-move-left" data-dir="left"></button>
<button type="button" class="button-link menus-move menus-move-right" data-dir="right"></button>
<button type="button" class="button-link menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></button>
</fieldset>
<div class="menu-item-actions description-wide submitbox">
<?php if ( 'custom' !== $menu_item->type && false !== $original_title ) : ?>
<p class="link-to-original">
<?php
/* translators: %s: Link to menu item's original object. */
printf( __( 'Original: %s' ), '<a href="' . esc_url( $menu_item->url ) . '">' . esc_html( $original_title ) . '</a>' );
?>
</p>
<?php endif; ?>
<?php
printf(
'<a class="item-delete submitdelete deletion" id="delete-%s" href="%s">%s</a>',
$item_id,
wp_nonce_url(
add_query_arg(
array(
'action' => 'delete-menu-item',
'menu-item' => $item_id,
),
admin_url( 'nav-menus.php' )
),
'delete-menu_item_' . $item_id
),
__( 'Remove' )
);
?>
<span class="meta-sep hide-if-no-js"> | </span>
<?php
printf(
'<a class="item-cancel submitcancel hide-if-no-js" id="cancel-%s" href="%s#menu-item-settings-%s">%s</a>',
$item_id,
esc_url(
add_query_arg(
array(
'edit-menu-item' => $item_id,
'cancel' => time(),
),
admin_url( 'nav-menus.php' )
)
),
$item_id,
__( 'Cancel' )
);
?>
</div>
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->object_id ); ?>" />
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->object ); ?>" />
<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->menu_item_parent ); ?>" />
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->menu_order ); ?>" />
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->type ); ?>" />
</div><!-- .menu-item-settings-->
<ul class="menu-item-transport"></ul>
<?php
$output .= ob_get_clean();
}
}PK %�[��`
# class-bulk-plugin-upgrader-skin.phpnu �[��� <?php
/**
* Upgrader API: Bulk_Plugin_Upgrader_Skin class
*
* @package WordPress
* @subpackage Upgrader
* @since 4.6.0
*/
/**
* Bulk Plugin Upgrader Skin for WordPress Plugin Upgrades.
*
* @since 3.0.0
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
*
* @see Bulk_Upgrader_Skin
*/
class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
/**
* Plugin info.
*
* The Plugin_Upgrader::bulk_upgrade() method will fill this in
* with info retrieved from the get_plugin_data() function.
*
* @since 3.0.0
* @var array Plugin data. Values will be empty if not supplied by the plugin.
*/
public $plugin_info = array();
/**
* Sets up the strings used in the update process.
*
* @since 3.0.0
*/
public function add_strings() {
parent::add_strings();
/* translators: 1: Plugin name, 2: Number of the plugin, 3: Total number of plugins being updated. */
$this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)' );
}
/**
* Performs an action before a bulk plugin update.
*
* @since 3.0.0
*
* @param string $title
*/
public function before( $title = '' ) {
parent::before( $this->plugin_info['Title'] );
}
/**
* Performs an action following a bulk plugin update.
*
* @since 3.0.0
*
* @param string $title
*/
public function after( $title = '' ) {
parent::after( $this->plugin_info['Title'] );
$this->decrement_update_count( 'plugin' );
}
/**
* Displays the footer following the bulk update process.
*
* @since 3.0.0
*/
public function bulk_footer() {
parent::bulk_footer();
$update_actions = array(
'plugins_page' => sprintf(
'<a href="%s" target="_parent">%s</a>',
self_admin_url( 'plugins.php' ),
__( 'Go to Plugins page' )
),
'updates_page' => sprintf(
'<a href="%s" target="_parent">%s</a>',
self_admin_url( 'update-core.php' ),
__( 'Go to WordPress Updates page' )
),
);
if ( ! current_user_can( 'activate_plugins' ) ) {
unset( $update_actions['plugins_page'] );
}
/**
* Filters the list of action links available following bulk plugin updates.
*
* @since 3.0.0
*
* @param string[] $update_actions Array of plugin action links.
* @param array $plugin_info Array of information for the last-updated plugin.
*/
$update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
if ( ! empty( $update_actions ) ) {
$this->feedback( implode( ' | ', (array) $update_actions ) );
}
}
}
PK %�[}�� � � class-wp-comments-list-table.phpnu �[��� <?php
/**
* List Table API: WP_Comments_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying comments in a list table.
*
* @since 3.1.0
*
* @see WP_List_Table
*/
class WP_Comments_List_Table extends WP_List_Table {
public $checkbox = true;
public $pending_count = array();
public $extra_items;
private $user_can;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @global int $post_id
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
global $post_id;
$post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
if ( get_option( 'show_avatars' ) ) {
add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 );
}
parent::__construct(
array(
'plural' => 'comments',
'singular' => 'comment',
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
* Adds avatars to comment author names.
*
* @since 3.1.0
*
* @param string $name Comment author name.
* @param int $comment_id Comment ID.
* @return string Avatar with the user name.
*/
public function floated_admin_avatar( $name, $comment_id ) {
$comment = get_comment( $comment_id );
$avatar = get_avatar( $comment, 32, 'mystery' );
return "$avatar $name";
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'edit_posts' );
}
/**
* @global string $mode List table view mode.
* @global int $post_id
* @global string $comment_status
* @global string $comment_type
* @global string $search
*/
public function prepare_items() {
global $mode, $post_id, $comment_status, $comment_type, $search;
if ( ! empty( $_REQUEST['mode'] ) ) {
$mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
set_user_setting( 'posts_list_mode', $mode );
} else {
$mode = get_user_setting( 'posts_list_mode', 'list' );
}
$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ), true ) ) {
$comment_status = 'all';
}
$comment_type = ! empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
$post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_key( $_REQUEST['post_type'] ) : '';
$user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : '';
$orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : '';
$order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : '';
$comments_per_page = $this->get_per_page( $comment_status );
$doing_ajax = wp_doing_ajax();
if ( isset( $_REQUEST['number'] ) ) {
$number = (int) $_REQUEST['number'];
} else {
$number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra.
}
$page = $this->get_pagenum();
if ( isset( $_REQUEST['start'] ) ) {
$start = $_REQUEST['start'];
} else {
$start = ( $page - 1 ) * $comments_per_page;
}
if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) {
$start += $_REQUEST['offset'];
}
$status_map = array(
'mine' => '',
'moderated' => 'hold',
'approved' => 'approve',
'all' => '',
);
$args = array(
'status' => isset( $status_map[ $comment_status ] ) ? $status_map[ $comment_status ] : $comment_status,
'search' => $search,
'user_id' => $user_id,
'offset' => $start,
'number' => $number,
'post_id' => $post_id,
'type' => $comment_type,
'orderby' => $orderby,
'order' => $order,
'post_type' => $post_type,
'update_comment_post_cache' => true,
);
/**
* Filters the arguments for the comment query in the comments list table.
*
* @since 5.1.0
*
* @param array $args An array of get_comments() arguments.
*/
$args = apply_filters( 'comments_list_table_query_args', $args );
$_comments = get_comments( $args );
if ( is_array( $_comments ) ) {
$this->items = array_slice( $_comments, 0, $comments_per_page );
$this->extra_items = array_slice( $_comments, $comments_per_page );
$_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );
$this->pending_count = get_pending_comments_num( $_comment_post_ids );
}
$total_comments = get_comments(
array_merge(
$args,
array(
'count' => true,
'offset' => 0,
'number' => 0,
'orderby' => 'none',
)
)
);
$this->set_pagination_args(
array(
'total_items' => $total_comments,
'per_page' => $comments_per_page,
)
);
}
/**
* @param string $comment_status
* @return int
*/
public function get_per_page( $comment_status = 'all' ) {
$comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
/**
* Filters the number of comments listed per page in the comments list table.
*
* @since 2.6.0
*
* @param int $comments_per_page The number of comments to list per page.
* @param string $comment_status The comment status name. Default 'All'.
*/
return apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
}
/**
* @global string $comment_status
*/
public function no_items() {
global $comment_status;
if ( 'moderated' === $comment_status ) {
_e( 'No comments awaiting moderation.' );
} elseif ( 'trash' === $comment_status ) {
_e( 'No comments found in Trash.' );
} else {
_e( 'No comments found.' );
}
}
/**
* @global int $post_id
* @global string $comment_status
* @global string $comment_type
*/
protected function get_views() {
global $post_id, $comment_status, $comment_type;
$status_links = array();
$num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
$statuses = array(
/* translators: %s: Number of comments. */
'all' => _nx_noop(
'All <span class="count">(%s)</span>',
'All <span class="count">(%s)</span>',
'comments'
), // Singular not used.
/* translators: %s: Number of comments. */
'mine' => _nx_noop(
'Mine <span class="count">(%s)</span>',
'Mine <span class="count">(%s)</span>',
'comments'
),
/* translators: %s: Number of comments. */
'moderated' => _nx_noop(
'Pending <span class="count">(%s)</span>',
'Pending <span class="count">(%s)</span>',
'comments'
),
/* translators: %s: Number of comments. */
'approved' => _nx_noop(
'Approved <span class="count">(%s)</span>',
'Approved <span class="count">(%s)</span>',
'comments'
),
/* translators: %s: Number of comments. */
'spam' => _nx_noop(
'Spam <span class="count">(%s)</span>',
'Spam <span class="count">(%s)</span>',
'comments'
),
/* translators: %s: Number of comments. */
'trash' => _nx_noop(
'Trash <span class="count">(%s)</span>',
'Trash <span class="count">(%s)</span>',
'comments'
),
);
if ( ! EMPTY_TRASH_DAYS ) {
unset( $statuses['trash'] );
}
$link = admin_url( 'edit-comments.php' );
if ( ! empty( $comment_type ) && 'all' !== $comment_type ) {
$link = add_query_arg( 'comment_type', $comment_type, $link );
}
foreach ( $statuses as $status => $label ) {
if ( 'mine' === $status ) {
$current_user_id = get_current_user_id();
$num_comments->mine = get_comments(
array(
'post_id' => $post_id ? $post_id : 0,
'user_id' => $current_user_id,
'count' => true,
'orderby' => 'none',
)
);
$link = add_query_arg( 'user_id', $current_user_id, $link );
} else {
$link = remove_query_arg( 'user_id', $link );
}
if ( ! isset( $num_comments->$status ) ) {
$num_comments->$status = 10;
}
$link = add_query_arg( 'comment_status', $status, $link );
if ( $post_id ) {
$link = add_query_arg( 'p', absint( $post_id ), $link );
}
/*
// I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
if ( !empty( $_REQUEST['s'] ) )
$link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link );
*/
$status_links[ $status ] = array(
'url' => esc_url( $link ),
'label' => sprintf(
translate_nooped_plural( $label, $num_comments->$status ),
sprintf(
'<span class="%s-count">%s</span>',
( 'moderated' === $status ) ? 'pending' : $status,
number_format_i18n( $num_comments->$status )
)
),
'current' => $status === $comment_status,
);
}
/**
* Filters the comment status links.
*
* @since 2.5.0
* @since 5.1.0 The 'Mine' link was added.
*
* @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine',
* 'Pending', 'Approved', 'Spam', and 'Trash'.
*/
return apply_filters( 'comment_status_links', $this->get_views_links( $status_links ) );
}
/**
* @global string $comment_status
*
* @return array
*/
protected function get_bulk_actions() {
global $comment_status;
if ( ! current_user_can( 'moderate_comments' ) ) {
return array(); // Return an empty array if the user doesn't have permission
}
$actions = array();
if ( in_array( $comment_status, array( 'all', 'approved' ), true ) ) {
$actions['unapprove'] = __( 'Unapprove' );
}
if ( in_array( $comment_status, array( 'all', 'moderated' ), true ) ) {
$actions['approve'] = __( 'Approve' );
}
if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ), true ) ) {
$actions['spam'] = _x( 'Mark as spam', 'comment' );
}
if ( 'trash' === $comment_status ) {
$actions['untrash'] = __( 'Restore' );
} elseif ( 'spam' === $comment_status ) {
$actions['unspam'] = _x( 'Not spam', 'comment' );
}
if ( in_array( $comment_status, array( 'trash', 'spam' ), true ) || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = __( 'Delete permanently' );
} else {
$actions['trash'] = __( 'Move to Trash' );
}
return $actions;
}
/**
* @global string $comment_status
* @global string $comment_type
*
* @param string $which
*/
protected function extra_tablenav( $which ) {
global $comment_status, $comment_type;
static $has_items;
if ( ! isset( $has_items ) ) {
$has_items = $this->has_items();
}
echo '<div class="alignleft actions">';
if ( 'top' === $which ) {
ob_start();
$this->comment_type_dropdown( $comment_type );
/**
* Fires just before the Filter submit button for comment types.
*
* @since 3.5.0
*/
do_action( 'restrict_manage_comments' );
$output = ob_get_clean();
if ( ! empty( $output ) && $this->has_items() ) {
echo $output;
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
}
}
if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && $has_items
&& current_user_can( 'moderate_comments' )
) {
wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
$title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
submit_button( $title, 'apply', 'delete_all', false );
}
/**
* Fires after the Filter submit button for comment types.
*
* @since 2.5.0
* @since 5.6.0 The `$which` parameter was added.
*
* @param string $comment_status The comment status name. Default 'All'.
* @param string $which The location of the extra table nav markup: Either 'top' or 'bottom'.
*/
do_action( 'manage_comments_nav', $comment_status, $which );
echo '</div>';
}
/**
* @return string|false
*/
public function current_action() {
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
return 'delete_all';
}
return parent::current_action();
}
/**
* @global int $post_id
*
* @return string[] Array of column titles keyed by their column name.
*/
public function get_columns() {
global $post_id;
$columns = array();
if ( $this->checkbox ) {
$columns['cb'] = '<input type="checkbox" />';
}
$columns['author'] = __( 'Author' );
$columns['comment'] = _x( 'Comment', 'column name' );
if ( ! $post_id ) {
/* translators: Column name or table row header. */
$columns['response'] = __( 'In response to' );
}
$columns['date'] = _x( 'Submitted on', 'column name' );
return $columns;
}
/**
* Displays a comment type drop-down for filtering on the Comments list table.
*
* @since 5.5.0
* @since 5.6.0 Renamed from `comment_status_dropdown()` to `comment_type_dropdown()`.
*
* @param string $comment_type The current comment type slug.
*/
protected function comment_type_dropdown( $comment_type ) {
/**
* Filters the comment types shown in the drop-down menu on the Comments list table.
*
* @since 2.7.0
*
* @param string[] $comment_types Array of comment type labels keyed by their name.
*/
$comment_types = apply_filters(
'admin_comment_types_dropdown',
array(
'comment' => __( 'Comments' ),
'pings' => __( 'Pings' ),
)
);
if ( $comment_types && is_array( $comment_types ) ) {
printf(
'<label class="screen-reader-text" for="filter-by-comment-type">%s</label>',
/* translators: Hidden accessibility text. */
__( 'Filter by comment type' )
);
echo '<select id="filter-by-comment-type" name="comment_type">';
printf( "\t<option value=''>%s</option>", __( 'All comment types' ) );
foreach ( $comment_types as $type => $label ) {
if ( get_comments(
array(
'count' => true,
'orderby' => 'none',
'type' => $type,
)
) ) {
printf(
"\t<option value='%s'%s>%s</option>\n",
esc_attr( $type ),
selected( $comment_type, $type, false ),
esc_html( $label )
);
}
}
echo '</select>';
}
}
/**
* @return array
*/
protected function get_sortable_columns() {
return array(
'author' => array( 'comment_author', false, __( 'Author' ), __( 'Table ordered by Comment Author.' ) ),
'response' => array( 'comment_post_ID', false, _x( 'In Response To', 'column name' ), __( 'Table ordered by Post Replied To.' ) ),
'date' => 'comment_date',
);
}
/**
* Gets the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'comment'.
*/
protected function get_default_primary_column_name() {
return 'comment';
}
/**
* Displays the comments table.
*
* Overrides the parent display() method to render extra comments.
*
* @since 3.1.0
*/
public function display() {
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
static $has_items;
if ( ! isset( $has_items ) ) {
$has_items = $this->has_items();
if ( $has_items ) {
$this->display_tablenav( 'top' );
}
}
$this->screen->render_screen_reader_content( 'heading_list' );
?>
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<?php
if ( ! isset( $_GET['orderby'] ) ) {
// In the initial view, Comments are ordered by comment's date but there's no column for that.
echo '<caption class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Ordered by Comment Date, descending.' ) .
'</caption>';
} else {
$this->print_table_description();
}
?>
<thead>
<tr>
<?php $this->print_column_headers(); ?>
</tr>
</thead>
<tbody id="the-comment-list" data-wp-lists="list:comment">
<?php $this->display_rows_or_placeholder(); ?>
</tbody>
<tbody id="the-extra-comment-list" data-wp-lists="list:comment" style="display: none;">
<?php
/*
* Back up the items to restore after printing the extra items markup.
* The extra items may be empty, which will prevent the table nav from displaying later.
*/
$items = $this->items;
$this->items = $this->extra_items;
$this->display_rows_or_placeholder();
$this->items = $items;
?>
</tbody>
<tfoot>
<tr>
<?php $this->print_column_headers( false ); ?>
</tr>
</tfoot>
</table>
<?php
$this->display_tablenav( 'bottom' );
}
/**
* @global WP_Post $post Global post object.
* @global WP_Comment $comment Global comment object.
*
* @param WP_Comment $item
*/
public function single_row( $item ) {
global $post, $comment;
// Restores the more descriptive, specific name for use within this method.
$comment = $item;
if ( $comment->comment_post_ID > 0 ) {
$post = get_post( $comment->comment_post_ID );
}
$edit_post_cap = $post ? 'edit_post' : 'edit_posts';
if ( ! current_user_can( $edit_post_cap, $comment->comment_post_ID )
&& ( post_password_required( $comment->comment_post_ID )
|| ! current_user_can( 'read_post', $comment->comment_post_ID ) )
) {
// The user has no access to the post and thus cannot see the comments.
return false;
}
$the_comment_class = wp_get_comment_status( $comment );
if ( ! $the_comment_class ) {
$the_comment_class = '';
}
$the_comment_class = implode( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) );
$this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
$this->single_row_columns( $comment );
echo "</tr>\n";
unset( $GLOBALS['post'], $GLOBALS['comment'] );
}
/**
* Generates and displays row actions links.
*
* @since 4.3.0
* @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support.
*
* @global string $comment_status Status for the current listed comments.
*
* @param WP_Comment $item The comment object.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string Row actions output for comments. An empty string
* if the current column is not the primary column,
* or if the current user cannot edit the comment.
*/
protected function handle_row_actions( $item, $column_name, $primary ) {
global $comment_status;
if ( $primary !== $column_name ) {
return '';
}
if ( ! $this->user_can ) {
return '';
}
// Restores the more descriptive, specific name for use within this method.
$comment = $item;
$the_comment_status = wp_get_comment_status( $comment );
$output = '';
$approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'approve-comment_' . $comment->comment_ID ) );
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'delete-comment_' . $comment->comment_ID ) );
$action_string = 'comment.php?action=%s&c=' . $comment->comment_ID . '&%s';
$approve_url = sprintf( $action_string, 'approvecomment', $approve_nonce );
$unapprove_url = sprintf( $action_string, 'unapprovecomment', $approve_nonce );
$spam_url = sprintf( $action_string, 'spamcomment', $del_nonce );
$unspam_url = sprintf( $action_string, 'unspamcomment', $del_nonce );
$trash_url = sprintf( $action_string, 'trashcomment', $del_nonce );
$untrash_url = sprintf( $action_string, 'untrashcomment', $del_nonce );
$delete_url = sprintf( $action_string, 'deletecomment', $del_nonce );
// Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash.
$actions = array(
'approve' => '',
'unapprove' => '',
'reply' => '',
'quickedit' => '',
'edit' => '',
'spam' => '',
'unspam' => '',
'trash' => '',
'untrash' => '',
'delete' => '',
);
// Not looking at all comments.
if ( $comment_status && 'all' !== $comment_status ) {
if ( 'approved' === $the_comment_status ) {
$actions['unapprove'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-u vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $unapprove_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&new=unapproved",
esc_attr__( 'Unapprove this comment' ),
__( 'Unapprove' )
);
} elseif ( 'unapproved' === $the_comment_status ) {
$actions['approve'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-a vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $approve_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&new=approved",
esc_attr__( 'Approve this comment' ),
__( 'Approve' )
);
}
} else {
$actions['approve'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $approve_url ),
"dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
esc_attr__( 'Approve this comment' ),
__( 'Approve' )
);
$actions['unapprove'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $unapprove_url ),
"dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
esc_attr__( 'Unapprove this comment' ),
__( 'Unapprove' )
);
}
if ( 'spam' !== $the_comment_status ) {
$actions['spam'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $spam_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
esc_attr__( 'Mark this comment as spam' ),
/* translators: "Mark as spam" link. */
_x( 'Spam', 'verb' )
);
} elseif ( 'spam' === $the_comment_status ) {
$actions['unspam'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $unspam_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:unspam=1",
esc_attr__( 'Restore this comment from the spam' ),
_x( 'Not Spam', 'comment' )
);
}
if ( 'trash' === $the_comment_status ) {
$actions['untrash'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $untrash_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:untrash=1",
esc_attr__( 'Restore this comment from the Trash' ),
__( 'Restore' )
);
}
if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $delete_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}::delete=1",
esc_attr__( 'Delete this comment permanently' ),
__( 'Delete Permanently' )
);
} else {
$actions['trash'] = sprintf(
'<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
esc_url( $trash_url ),
"delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
esc_attr__( 'Move this comment to the Trash' ),
_x( 'Trash', 'verb' )
);
}
if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) {
$actions['edit'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
"comment.php?action=editcomment&c={$comment->comment_ID}",
esc_attr__( 'Edit this comment' ),
__( 'Edit' )
);
$format = '<button type="button" data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s button-link" aria-expanded="false" aria-label="%s">%s</button>';
$actions['quickedit'] = sprintf(
$format,
$comment->comment_ID,
$comment->comment_post_ID,
'edit',
'vim-q comment-inline',
esc_attr__( 'Quick edit this comment inline' ),
__( 'Quick Edit' )
);
$actions['reply'] = sprintf(
$format,
$comment->comment_ID,
$comment->comment_post_ID,
'replyto',
'vim-r comment-inline',
esc_attr__( 'Reply to this comment' ),
__( 'Reply' )
);
}
/**
* Filters the action links displayed for each comment in the Comments list table.
*
* @since 2.6.0
*
* @param string[] $actions An array of comment actions. Default actions include:
* 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
* 'Delete', and 'Trash'.
* @param WP_Comment $comment The comment object.
*/
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
$always_visible = false;
$mode = get_user_setting( 'posts_list_mode', 'list' );
if ( 'excerpt' === $mode ) {
$always_visible = true;
}
$output .= '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
|| 1 === $i
) {
$separator = '';
} else {
$separator = ' | ';
}
// Reply and quickedit need a hide-if-no-js span when not added with Ajax.
if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) {
$action .= ' hide-if-no-js';
} elseif ( ( 'untrash' === $action && 'trash' === $the_comment_status )
|| ( 'unspam' === $action && 'spam' === $the_comment_status )
) {
if ( '1' === get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) {
$action .= ' approve';
} else {
$action .= ' unapprove';
}
}
$output .= "<span class='$action'>{$separator}{$link}</span>";
}
$output .= '</div>';
$output .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Show more details' ) .
'</span></button>';
return $output;
}
/**
* @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param WP_Comment $item The comment object.
*/
public function column_cb( $item ) {
// Restores the more descriptive, specific name for use within this method.
$comment = $item;
if ( $this->user_can ) {
?>
<input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
<label for="cb-select-<?php echo $comment->comment_ID; ?>">
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. */
_e( 'Select comment' );
?>
</span>
</label>
<?php
}
}
/**
* @param WP_Comment $comment The comment object.
*/
public function column_comment( $comment ) {
echo '<div class="comment-author">';
$this->column_author( $comment );
echo '</div>';
if ( $comment->comment_parent ) {
$parent = get_comment( $comment->comment_parent );
if ( $parent ) {
$parent_link = esc_url( get_comment_link( $parent ) );
$name = get_comment_author( $parent );
printf(
/* translators: %s: Comment link. */
__( 'In reply to %s.' ),
'<a href="' . $parent_link . '">' . $name . '</a>'
);
}
}
comment_text( $comment );
if ( $this->user_can ) {
/** This filter is documented in wp-admin/includes/comment.php */
$comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
?>
<div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
<textarea class="comment" rows="1" cols="1"><?php echo esc_textarea( $comment_content ); ?></textarea>
<div class="author-email"><?php echo esc_html( $comment->comment_author_email ); ?></div>
<div class="author"><?php echo esc_html( $comment->comment_author ); ?></div>
<div class="author-url"><?php echo esc_url( $comment->comment_author_url ); ?></div>
<div class="comment_status"><?php echo $comment->comment_approved; ?></div>
</div>
<?php
}
}
/**
* @global string $comment_status
*
* @param WP_Comment $comment The comment object.
*/
public function column_author( $comment ) {
global $comment_status;
$author_url = get_comment_author_url( $comment );
$author_url_display = untrailingslashit( preg_replace( '|^http(s)?://(www\.)?|i', '', $author_url ) );
if ( strlen( $author_url_display ) > 50 ) {
$author_url_display = wp_html_excerpt( $author_url_display, 49, '…' );
}
echo '<strong>';
comment_author( $comment );
echo '</strong><br />';
if ( ! empty( $author_url_display ) ) {
// Print link to author URL, and disallow referrer information (without using target="_blank").
printf(
'<a href="%s" rel="noopener noreferrer">%s</a><br />',
esc_url( $author_url ),
esc_html( $author_url_display )
);
}
if ( $this->user_can ) {
if ( ! empty( $comment->comment_author_email ) ) {
/** This filter is documented in wp-includes/comment-template.php */
$email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
if ( ! empty( $email ) && '@' !== $email ) {
printf( '<a href="%1$s">%2$s</a><br />', esc_url( 'mailto:' . $email ), esc_html( $email ) );
}
}
$author_ip = get_comment_author_IP( $comment );
if ( $author_ip ) {
$author_ip_url = add_query_arg(
array(
's' => $author_ip,
'mode' => 'detail',
),
admin_url( 'edit-comments.php' )
);
if ( 'spam' === $comment_status ) {
$author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url );
}
printf( '<a href="%1$s">%2$s</a>', esc_url( $author_ip_url ), esc_html( $author_ip ) );
}
}
}
/**
* @param WP_Comment $comment The comment object.
*/
public function column_date( $comment ) {
$submitted = sprintf(
/* translators: 1: Comment date, 2: Comment time. */
__( '%1$s at %2$s' ),
/* translators: Comment date format. See https://www.php.net/manual/datetime.format.php */
get_comment_date( __( 'Y/m/d' ), $comment ),
/* translators: Comment time format. See https://www.php.net/manual/datetime.format.php */
get_comment_date( __( 'g:i a' ), $comment )
);
echo '<div class="submitted-on">';
if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
printf(
'<a href="%s">%s</a>',
esc_url( get_comment_link( $comment ) ),
$submitted
);
} else {
echo $submitted;
}
echo '</div>';
}
/**
* @param WP_Comment $comment The comment object.
*/
public function column_response( $comment ) {
$post = get_post();
if ( ! $post ) {
return;
}
if ( isset( $this->pending_count[ $post->ID ] ) ) {
$pending_comments = $this->pending_count[ $post->ID ];
} else {
$_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
$pending_comments = $_pending_count_temp[ $post->ID ];
$this->pending_count[ $post->ID ] = $pending_comments;
}
if ( current_user_can( 'edit_post', $post->ID ) ) {
$post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
$post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>';
} else {
$post_link = esc_html( get_the_title( $post->ID ) );
}
echo '<div class="response-links">';
if ( 'attachment' === $post->post_type ) {
$thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true );
if ( $thumb ) {
echo $thumb;
}
}
echo $post_link;
$post_type_object = get_post_type_object( $post->post_type );
echo "<a href='" . get_permalink( $post->ID ) . "' class='comments-view-item-link'>" . $post_type_object->labels->view_item . '</a>';
echo '<span class="post-com-count-wrapper post-com-count-', $post->ID, '">';
$this->comments_bubble( $post->ID, $pending_comments );
echo '</span> ';
echo '</div>';
}
/**
* @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support.
*
* @param WP_Comment $item The comment object.
* @param string $column_name The custom column's name.
*/
public function column_default( $item, $column_name ) {
// Restores the more descriptive, specific name for use within this method.
$comment = $item;
/**
* Fires when the default column output is displayed for a single row.
*
* @since 2.8.0
*
* @param string $column_name The custom column's name.
* @param string $comment_id The comment ID as a numeric string.
*/
do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
}
}
PK %�[�jKV�j �j
class-ftp.phpnu �[��� <?php
/**
* PemFTP - An Ftp implementation in pure PHP
*
* @package PemFTP
* @since 2.5.0
*
* @version 1.0
* @copyright Alexey Dotsenko
* @author Alexey Dotsenko
* @link https://www.phpclasses.org/package/1743-PHP-FTP-client-in-pure-PHP.html
* @license LGPL https://opensource.org/licenses/lgpl-license.html
*/
/**
* Defines the newline characters, if not defined already.
*
* This can be redefined.
*
* @since 2.5.0
* @var string
*/
if ( ! defined( 'CRLF' ) ) {
define( 'CRLF', "\r\n" );
}
/**
* Sets whatever to autodetect ASCII mode.
*
* This can be redefined.
*
* @since 2.5.0
* @var int
*/
if ( ! defined( 'FTP_AUTOASCII' ) ) {
define( 'FTP_AUTOASCII', -1 );
}
/**
*
* This can be redefined.
* @since 2.5.0
* @var int
*/
if ( ! defined( 'FTP_BINARY' ) ) {
define( 'FTP_BINARY', 1 );
}
/**
*
* This can be redefined.
* @since 2.5.0
* @var int
*/
if ( ! defined( 'FTP_ASCII' ) ) {
define( 'FTP_ASCII', 0 );
}
/**
* Whether to force FTP.
*
* This can be redefined.
*
* @since 2.5.0
* @var bool
*/
if ( ! defined( 'FTP_FORCE' ) ) {
define( 'FTP_FORCE', true );
}
/**
* @since 2.5.0
* @var string
*/
define('FTP_OS_Unix','u');
/**
* @since 2.5.0
* @var string
*/
define('FTP_OS_Windows','w');
/**
* @since 2.5.0
* @var string
*/
define('FTP_OS_Mac','m');
/**
* PemFTP base class
*
*/
class ftp_base {
/* Public variables */
var $LocalEcho;
var $Verbose;
var $OS_local;
var $OS_remote;
/* Private variables */
var $_lastaction;
var $_errors;
var $_type;
var $_umask;
var $_timeout;
var $_passive;
var $_host;
var $_fullhost;
var $_port;
var $_datahost;
var $_dataport;
var $_ftp_control_sock;
var $_ftp_data_sock;
var $_ftp_temp_sock;
var $_ftp_buff_size;
var $_login;
var $_password;
var $_connected;
var $_ready;
var $_code;
var $_message;
var $_can_restore;
var $_port_available;
var $_curtype;
var $_features;
var $_error_array;
var $AuthorizedTransferMode;
var $OS_FullName;
var $_eol_code;
var $AutoAsciiExt;
/* Constructor */
function __construct($port_mode=FALSE, $verb=FALSE, $le=FALSE) {
$this->LocalEcho=$le;
$this->Verbose=$verb;
$this->_lastaction=NULL;
$this->_error_array=array();
$this->_eol_code=array(FTP_OS_Unix=>"\n", FTP_OS_Mac=>"\r", FTP_OS_Windows=>"\r\n");
$this->AuthorizedTransferMode=array(FTP_AUTOASCII, FTP_ASCII, FTP_BINARY);
$this->OS_FullName=array(FTP_OS_Unix => 'UNIX', FTP_OS_Windows => 'WINDOWS', FTP_OS_Mac => 'MACOS');
$this->AutoAsciiExt=array("ASP","BAT","C","CPP","CSS","CSV","JS","H","HTM","HTML","SHTML","INI","LOG","PHP3","PHTML","PL","PERL","SH","SQL","TXT");
$this->_port_available=($port_mode==TRUE);
$this->SendMSG("Staring FTP client class".($this->_port_available?"":" without PORT mode support"));
$this->_connected=FALSE;
$this->_ready=FALSE;
$this->_can_restore=FALSE;
$this->_code=0;
$this->_message="";
$this->_ftp_buff_size=4096;
$this->_curtype=NULL;
$this->SetUmask(0022);
$this->SetType(FTP_AUTOASCII);
$this->SetTimeout(30);
$this->Passive(!$this->_port_available);
$this->_login="anonymous";
$this->_password="anon@ftp.com";
$this->_features=array();
$this->OS_local=FTP_OS_Unix;
$this->OS_remote=FTP_OS_Unix;
$this->features=array();
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows;
elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
}
function ftp_base($port_mode=FALSE) {
$this->__construct($port_mode);
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Public functions -->
// <!-- --------------------------------------------------------------------------------------- -->
function parselisting($line) {
$is_windows = ($this->OS_remote == FTP_OS_Windows);
if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/",$line,$lucifer)) {
$b = array();
if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
$b['isdir'] = ($lucifer[7]=="<DIR>");
if ( $b['isdir'] )
$b['type'] = 'd';
else
$b['type'] = 'f';
$b['size'] = $lucifer[7];
$b['month'] = $lucifer[1];
$b['day'] = $lucifer[2];
$b['year'] = $lucifer[3];
$b['hour'] = $lucifer[4];
$b['minute'] = $lucifer[5];
$b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
$b['am/pm'] = $lucifer[6];
$b['name'] = $lucifer[8];
} else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
//echo $line."\n";
$lcount=count($lucifer);
if ($lcount<8) return '';
$b = array();
$b['isdir'] = $lucifer[0][0] === "d";
$b['islink'] = $lucifer[0][0] === "l";
if ( $b['isdir'] )
$b['type'] = 'd';
elseif ( $b['islink'] )
$b['type'] = 'l';
else
$b['type'] = 'f';
$b['perms'] = $lucifer[0];
$b['number'] = $lucifer[1];
$b['owner'] = $lucifer[2];
$b['group'] = $lucifer[3];
$b['size'] = $lucifer[4];
if ($lcount==8) {
sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
$b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
$b['name'] = $lucifer[7];
} else {
$b['month'] = $lucifer[5];
$b['day'] = $lucifer[6];
if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {
$b['year'] = gmdate("Y");
$b['hour'] = $l2[1];
$b['minute'] = $l2[2];
} else {
$b['year'] = $lucifer[7];
$b['hour'] = 0;
$b['minute'] = 0;
}
$b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));
$b['name'] = $lucifer[8];
}
}
return $b;
}
function SendMSG($message = "", $crlf=true) {
if ($this->Verbose) {
echo $message.($crlf?CRLF:"");
flush();
}
return TRUE;
}
function SetType($mode=FTP_AUTOASCII) {
if(!in_array($mode, $this->AuthorizedTransferMode)) {
$this->SendMSG("Wrong type");
return FALSE;
}
$this->_type=$mode;
$this->SendMSG("Transfer type: ".($this->_type==FTP_BINARY?"binary":($this->_type==FTP_ASCII?"ASCII":"auto ASCII") ) );
return TRUE;
}
function _settype($mode=FTP_ASCII) {
if($this->_ready) {
if($mode==FTP_BINARY) {
if($this->_curtype!=FTP_BINARY) {
if(!$this->_exec("TYPE I", "SetType")) return FALSE;
$this->_curtype=FTP_BINARY;
}
} elseif($this->_curtype!=FTP_ASCII) {
if(!$this->_exec("TYPE A", "SetType")) return FALSE;
$this->_curtype=FTP_ASCII;
}
} else return FALSE;
return TRUE;
}
function Passive($pasv=NULL) {
if(is_null($pasv)) $this->_passive=!$this->_passive;
else $this->_passive=$pasv;
if(!$this->_port_available and !$this->_passive) {
$this->SendMSG("Only passive connections available!");
$this->_passive=TRUE;
return FALSE;
}
$this->SendMSG("Passive mode ".($this->_passive?"on":"off"));
return TRUE;
}
function SetServer($host, $port=21, $reconnect=true) {
if(!is_long($port)) {
$this->verbose=true;
$this->SendMSG("Incorrect port syntax");
return FALSE;
} else {
$ip=@gethostbyname($host);
$dns=@gethostbyaddr($host);
if(!$ip) $ip=$host;
if(!$dns) $dns=$host;
// Validate the IPAddress PHP4 returns -1 for invalid, PHP5 false
// -1 === "255.255.255.255" which is the broadcast address which is also going to be invalid
$ipaslong = ip2long($ip);
if ( ($ipaslong == false) || ($ipaslong === -1) ) {
$this->SendMSG("Wrong host name/address \"".$host."\"");
return FALSE;
}
$this->_host=$ip;
$this->_fullhost=$dns;
$this->_port=$port;
$this->_dataport=$port-1;
}
$this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\"");
if($reconnect){
if($this->_connected) {
$this->SendMSG("Reconnecting");
if(!$this->quit(FTP_FORCE)) return FALSE;
if(!$this->connect()) return FALSE;
}
}
return TRUE;
}
function SetUmask($umask=0022) {
$this->_umask=$umask;
umask($this->_umask);
$this->SendMSG("UMASK 0".decoct($this->_umask));
return TRUE;
}
function SetTimeout($timeout=30) {
$this->_timeout=$timeout;
$this->SendMSG("Timeout ".$this->_timeout);
if($this->_connected)
if(!$this->_settimeout($this->_ftp_control_sock)) return FALSE;
return TRUE;
}
function connect($server=NULL) {
if(!empty($server)) {
if(!$this->SetServer($server)) return false;
}
if($this->_ready) return true;
$this->SendMsg('Local OS : '.$this->OS_FullName[$this->OS_local]);
if(!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) {
$this->SendMSG("Error : Cannot connect to remote host \"".$this->_fullhost." :".$this->_port."\"");
return FALSE;
}
$this->SendMSG("Connected to remote host \"".$this->_fullhost.":".$this->_port."\". Waiting for greeting.");
do {
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
$this->_lastaction=time();
} while($this->_code<200);
$this->_ready=true;
$syst=$this->systype();
if(!$syst) $this->SendMSG("Cannot detect remote OS");
else {
if(preg_match("/win|dos|novell/i", $syst[0])) $this->OS_remote=FTP_OS_Windows;
elseif(preg_match("/os/i", $syst[0])) $this->OS_remote=FTP_OS_Mac;
elseif(preg_match("/(li|u)nix/i", $syst[0])) $this->OS_remote=FTP_OS_Unix;
else $this->OS_remote=FTP_OS_Mac;
$this->SendMSG("Remote OS: ".$this->OS_FullName[$this->OS_remote]);
}
if(!$this->features()) $this->SendMSG("Cannot get features list. All supported - disabled");
else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
return TRUE;
}
function quit($force=false) {
if($this->_ready) {
if(!$this->_exec("QUIT") and !$force) return FALSE;
if(!$this->_checkCode() and !$force) return FALSE;
$this->_ready=false;
$this->SendMSG("Session finished");
}
$this->_quit();
return TRUE;
}
function login($user=NULL, $pass=NULL) {
if(!is_null($user)) $this->_login=$user;
else $this->_login="anonymous";
if(!is_null($pass)) $this->_password=$pass;
else $this->_password="anon@anon.com";
if(!$this->_exec("USER ".$this->_login, "login")) return FALSE;
if(!$this->_checkCode()) return FALSE;
if($this->_code!=230) {
if(!$this->_exec((($this->_code==331)?"PASS ":"ACCT ").$this->_password, "login")) return FALSE;
if(!$this->_checkCode()) return FALSE;
}
$this->SendMSG("Authentication succeeded");
if(empty($this->_features)) {
if(!$this->features()) $this->SendMSG("Cannot get features list. All supported - disabled");
else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
}
return TRUE;
}
function pwd() {
if(!$this->_exec("PWD", "pwd")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return preg_replace("/^[0-9]{3} \"(.+)\".*$/s", "\\1", $this->_message);
}
function cdup() {
if(!$this->_exec("CDUP", "cdup")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return true;
}
function chdir($pathname) {
if(!$this->_exec("CWD ".$pathname, "chdir")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function rmdir($pathname) {
if(!$this->_exec("RMD ".$pathname, "rmdir")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function mkdir($pathname) {
if(!$this->_exec("MKD ".$pathname, "mkdir")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function rename($from, $to) {
if(!$this->_exec("RNFR ".$from, "rename")) return FALSE;
if(!$this->_checkCode()) return FALSE;
if($this->_code==350) {
if(!$this->_exec("RNTO ".$to, "rename")) return FALSE;
if(!$this->_checkCode()) return FALSE;
} else return FALSE;
return TRUE;
}
function filesize($pathname) {
if(!isset($this->_features["SIZE"])) {
$this->PushError("filesize", "not supported by server");
return FALSE;
}
if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
}
function abort() {
if(!$this->_exec("ABOR", "abort")) return FALSE;
if(!$this->_checkCode()) {
if($this->_code!=426) return FALSE;
if(!$this->_readmsg("abort")) return FALSE;
if(!$this->_checkCode()) return FALSE;
}
return true;
}
function mdtm($pathname) {
if(!isset($this->_features["MDTM"])) {
$this->PushError("mdtm", "not supported by server");
return FALSE;
}
if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE;
if(!$this->_checkCode()) return FALSE;
$mdtm = preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
$date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
$timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
return $timestamp;
}
function systype() {
if(!$this->_exec("SYST", "systype")) return FALSE;
if(!$this->_checkCode()) return FALSE;
$DATA = explode(" ", $this->_message);
return array($DATA[1], $DATA[3]);
}
function delete($pathname) {
if(!$this->_exec("DELE ".$pathname, "delete")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function site($command, $fnction="site") {
if(!$this->_exec("SITE ".$command, $fnction)) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function chmod($pathname, $mode) {
if(!$this->site( sprintf('CHMOD %o %s', $mode, $pathname), "chmod")) return FALSE;
return TRUE;
}
function restore($from) {
if(!isset($this->_features["REST"])) {
$this->PushError("restore", "not supported by server");
return FALSE;
}
if($this->_curtype!=FTP_BINARY) {
$this->PushError("restore", "cannot restore in ASCII mode");
return FALSE;
}
if(!$this->_exec("REST ".$from, "restore")) return FALSE;
if(!$this->_checkCode()) return FALSE;
return TRUE;
}
function features() {
if(!$this->_exec("FEAT", "features")) return FALSE;
if(!$this->_checkCode()) return FALSE;
$f=preg_split("/[".CRLF."]+/", preg_replace("/[0-9]{3}[ -].*[".CRLF."]+/", "", $this->_message), -1, PREG_SPLIT_NO_EMPTY);
$this->_features=array();
foreach($f as $k=>$v) {
$v=explode(" ", trim($v));
$this->_features[array_shift($v)]=$v;
}
return true;
}
function rawlist($pathname="", $arg="") {
return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist");
}
function nlist($pathname="", $arg="") {
return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
}
function is_exists($pathname) {
return $this->file_exists($pathname);
}
function file_exists($pathname) {
$exists=true;
if(!$this->_exec("RNFR ".$pathname, "rename")) $exists=FALSE;
else {
if(!$this->_checkCode()) $exists=FALSE;
$this->abort();
}
if($exists) $this->SendMSG("Remote file ".$pathname." exists");
else $this->SendMSG("Remote file ".$pathname." does not exist");
return $exists;
}
function fget($fp, $remotefile, $rest=0) {
if($this->_can_restore and $rest!=0) fseek($fp, $rest);
$pi=pathinfo($remotefile);
if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
else $mode=FTP_BINARY;
if(!$this->_data_prepare($mode)) {
return FALSE;
}
if($this->_can_restore and $rest!=0) $this->restore($rest);
if(!$this->_exec("RETR ".$remotefile, "get")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$out=$this->_data_read($mode, $fp);
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
return $out;
}
function get($remotefile, $localfile=NULL, $rest=0) {
if(is_null($localfile)) $localfile=$remotefile;
if (@file_exists($localfile)) $this->SendMSG("Warning : local file will be overwritten");
$fp = @fopen($localfile, "w");
if (!$fp) {
$this->PushError("get","cannot open local file", "Cannot create \"".$localfile."\"");
return FALSE;
}
if($this->_can_restore and $rest!=0) fseek($fp, $rest);
$pi=pathinfo($remotefile);
if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
else $mode=FTP_BINARY;
if(!$this->_data_prepare($mode)) {
fclose($fp);
return FALSE;
}
if($this->_can_restore and $rest!=0) $this->restore($rest);
if(!$this->_exec("RETR ".$remotefile, "get")) {
$this->_data_close();
fclose($fp);
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
fclose($fp);
return FALSE;
}
$out=$this->_data_read($mode, $fp);
fclose($fp);
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
return $out;
}
function fput($remotefile, $fp, $rest=0) {
if($this->_can_restore and $rest!=0) fseek($fp, $rest);
$pi=pathinfo($remotefile);
if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
else $mode=FTP_BINARY;
if(!$this->_data_prepare($mode)) {
return FALSE;
}
if($this->_can_restore and $rest!=0) $this->restore($rest);
if(!$this->_exec("STOR ".$remotefile, "put")) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$ret=$this->_data_write($mode, $fp);
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
return $ret;
}
function put($localfile, $remotefile=NULL, $rest=0) {
if(is_null($remotefile)) $remotefile=$localfile;
if (!file_exists($localfile)) {
$this->PushError("put","cannot open local file", "No such file or directory \"".$localfile."\"");
return FALSE;
}
$fp = @fopen($localfile, "r");
if (!$fp) {
$this->PushError("put","cannot open local file", "Cannot read file \"".$localfile."\"");
return FALSE;
}
if($this->_can_restore and $rest!=0) fseek($fp, $rest);
$pi=pathinfo($localfile);
if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
else $mode=FTP_BINARY;
if(!$this->_data_prepare($mode)) {
fclose($fp);
return FALSE;
}
if($this->_can_restore and $rest!=0) $this->restore($rest);
if(!$this->_exec("STOR ".$remotefile, "put")) {
$this->_data_close();
fclose($fp);
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
fclose($fp);
return FALSE;
}
$ret=$this->_data_write($mode, $fp);
fclose($fp);
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
return $ret;
}
function mput($local=".", $remote=NULL, $continious=false) {
$local=realpath($local);
if(!@file_exists($local)) {
$this->PushError("mput","cannot open local folder", "Cannot stat folder \"".$local."\"");
return FALSE;
}
if(!is_dir($local)) return $this->put($local, $remote);
if(empty($remote)) $remote=".";
elseif(!$this->file_exists($remote) and !$this->mkdir($remote)) return FALSE;
if($handle = opendir($local)) {
$list=array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") $list[]=$file;
}
closedir($handle);
} else {
$this->PushError("mput","cannot open local folder", "Cannot read folder \"".$local."\"");
return FALSE;
}
if(empty($list)) return TRUE;
$ret=true;
foreach($list as $el) {
if(is_dir($local."/".$el)) $t=$this->mput($local."/".$el, $remote."/".$el);
else $t=$this->put($local."/".$el, $remote."/".$el);
if(!$t) {
$ret=FALSE;
if(!$continious) break;
}
}
return $ret;
}
function mget($remote, $local=".", $continious=false) {
$list=$this->rawlist($remote, "-lA");
if($list===false) {
$this->PushError("mget","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents");
return FALSE;
}
if(empty($list)) return true;
if(!@file_exists($local)) {
if(!@mkdir($local)) {
$this->PushError("mget","cannot create local folder", "Cannot create folder \"".$local."\"");
return FALSE;
}
}
foreach($list as $k=>$v) {
$list[$k]=$this->parselisting($v);
if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
}
$ret=true;
foreach($list as $el) {
if($el["type"]=="d") {
if(!$this->mget($remote."/".$el["name"], $local."/".$el["name"], $continious)) {
$this->PushError("mget", "cannot copy folder", "Cannot copy remote folder \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
$ret=false;
if(!$continious) break;
}
} else {
if(!$this->get($remote."/".$el["name"], $local."/".$el["name"])) {
$this->PushError("mget", "cannot copy file", "Cannot copy remote file \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
$ret=false;
if(!$continious) break;
}
}
@chmod($local."/".$el["name"], $el["perms"]);
$t=strtotime($el["date"]);
if($t!==-1 and $t!==false) @touch($local."/".$el["name"], $t);
}
return $ret;
}
function mdel($remote, $continious=false) {
$list=$this->rawlist($remote, "-la");
if($list===false) {
$this->PushError("mdel","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents");
return false;
}
foreach($list as $k=>$v) {
$list[$k]=$this->parselisting($v);
if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
}
$ret=true;
foreach($list as $el) {
if ( empty($el) )
continue;
if($el["type"]=="d") {
if(!$this->mdel($remote."/".$el["name"], $continious)) {
$ret=false;
if(!$continious) break;
}
} else {
if (!$this->delete($remote."/".$el["name"])) {
$this->PushError("mdel", "cannot delete file", "Cannot delete remote file \"".$remote."/".$el["name"]."\"");
$ret=false;
if(!$continious) break;
}
}
}
if(!$this->rmdir($remote)) {
$this->PushError("mdel", "cannot delete folder", "Cannot delete remote folder \"".$remote."/".$el["name"]."\"");
$ret=false;
}
return $ret;
}
function mmkdir($dir, $mode = 0777) {
if(empty($dir)) return FALSE;
if($this->is_exists($dir) or $dir == "/" ) return TRUE;
if(!$this->mmkdir(dirname($dir), $mode)) return false;
$r=$this->mkdir($dir, $mode);
$this->chmod($dir,$mode);
return $r;
}
function glob($pattern, $handle=NULL) {
$path=$output=null;
if(PHP_OS=='WIN32') $slash='\\';
else $slash='/';
$lastpos=strrpos($pattern,$slash);
if(!($lastpos===false)) {
$path=substr($pattern,0,-$lastpos-1);
$pattern=substr($pattern,$lastpos);
} else $path=getcwd();
if(is_array($handle) and !empty($handle)) {
foreach($handle as $dir) {
if($this->glob_pattern_match($pattern,$dir))
$output[]=$dir;
}
} else {
$handle=@opendir($path);
if($handle===false) return false;
while($dir=readdir($handle)) {
if($this->glob_pattern_match($pattern,$dir))
$output[]=$dir;
}
closedir($handle);
}
if(is_array($output)) return $output;
return false;
}
function glob_pattern_match($pattern,$subject) {
$out=null;
$chunks=explode(';',$pattern);
foreach($chunks as $pattern) {
$escape=array('$','^','.','{','}','(',')','[',']','|');
while(str_contains($pattern,'**'))
$pattern=str_replace('**','*',$pattern);
foreach($escape as $probe)
$pattern=str_replace($probe,"\\$probe",$pattern);
$pattern=str_replace('?*','*',
str_replace('*?','*',
str_replace('*',".*",
str_replace('?','.{1,1}',$pattern))));
$out[]=$pattern;
}
if(count($out)==1) return($this->glob_regexp("^$out[0]$",$subject));
else {
foreach($out as $tester)
// TODO: This should probably be glob_regexp(), but needs tests.
if($this->my_regexp("^$tester$",$subject)) return true;
}
return false;
}
function glob_regexp($pattern,$subject) {
$sensitive=(PHP_OS!='WIN32');
return ($sensitive?
preg_match( '/' . preg_quote( $pattern, '/' ) . '/', $subject ) :
preg_match( '/' . preg_quote( $pattern, '/' ) . '/i', $subject )
);
}
function dirlist($remote) {
$list=$this->rawlist($remote, "-la");
if($list===false) {
$this->PushError("dirlist","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents");
return false;
}
$dirlist = array();
foreach($list as $k=>$v) {
$entry=$this->parselisting($v);
if ( empty($entry) )
continue;
if($entry["name"]=="." or $entry["name"]=="..")
continue;
$dirlist[$entry['name']] = $entry;
}
return $dirlist;
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
function _checkCode() {
return ($this->_code<400 and $this->_code>0);
}
function _list($arg="", $cmd="LIST", $fnction="_list") {
if(!$this->_data_prepare()) return false;
if(!$this->_exec($cmd.$arg, $fnction)) {
$this->_data_close();
return FALSE;
}
if(!$this->_checkCode()) {
$this->_data_close();
return FALSE;
}
$out="";
if($this->_code<200) {
$out=$this->_data_read();
$this->_data_close();
if(!$this->_readmsg()) return FALSE;
if(!$this->_checkCode()) return FALSE;
if($out === FALSE ) return FALSE;
$out=preg_split("/[".CRLF."]+/", $out, -1, PREG_SPLIT_NO_EMPTY);
// $this->SendMSG(implode($this->_eol_code[$this->OS_local], $out));
}
return $out;
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Partie : gestion des erreurs -->
// <!-- --------------------------------------------------------------------------------------- -->
// Gnre une erreur pour traitement externe la classe
function PushError($fctname,$msg,$desc=false){
$error=array();
$error['time']=time();
$error['fctname']=$fctname;
$error['msg']=$msg;
$error['desc']=$desc;
if($desc) $tmp=' ('.$desc.')'; else $tmp='';
$this->SendMSG($fctname.': '.$msg.$tmp);
return(array_push($this->_error_array,$error));
}
// Rcupre une erreur externe
function PopError(){
if(count($this->_error_array)) return(array_pop($this->_error_array));
else return(false);
}
}
$mod_sockets = extension_loaded( 'sockets' );
if ( ! $mod_sockets && function_exists( 'dl' ) && is_callable( 'dl' ) ) {
$prefix = ( PHP_SHLIB_SUFFIX == 'dll' ) ? 'php_' : '';
@dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX ); // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.dlDeprecated
$mod_sockets = extension_loaded( 'sockets' );
}
require_once __DIR__ . "/class-ftp-" . ( $mod_sockets ? "sockets" : "pure" ) . ".php";
if ( $mod_sockets ) {
class ftp extends ftp_sockets {}
} else {
class ftp extends ftp_pure {}
}
PK %�[i`�~QI QI class-wp-community-events.phpnu �[��� <?php
/**
* Administration: Community Events class.
*
* @package WordPress
* @subpackage Administration
* @since 4.8.0
*/
/**
* Class WP_Community_Events.
*
* A client for api.wordpress.org/events.
*
* @since 4.8.0
*/
#[AllowDynamicProperties]
class WP_Community_Events {
/**
* ID for a WordPress user account.
*
* @since 4.8.0
*
* @var int
*/
protected $user_id = 0;
/**
* Stores location data for the user.
*
* @since 4.8.0
*
* @var false|array
*/
protected $user_location = false;
/**
* Constructor for WP_Community_Events.
*
* @since 4.8.0
*
* @param int $user_id WP user ID.
* @param false|array $user_location {
* Stored location data for the user. false to pass no location.
*
* @type string $description The name of the location
* @type string $latitude The latitude in decimal degrees notation, without the degree
* symbol. e.g.: 47.615200.
* @type string $longitude The longitude in decimal degrees notation, without the degree
* symbol. e.g.: -122.341100.
* @type string $country The ISO 3166-1 alpha-2 country code. e.g.: BR
* }
*/
public function __construct( $user_id, $user_location = false ) {
$this->user_id = absint( $user_id );
$this->user_location = $user_location;
}
/**
* Gets data about events near a particular location.
*
* Cached events will be immediately returned if the `user_location` property
* is set for the current user, and cached events exist for that location.
*
* Otherwise, this method sends a request to the w.org Events API with location
* data. The API will send back a recognized location based on the data, along
* with nearby events.
*
* The browser's request for events is proxied with this method, rather
* than having the browser make the request directly to api.wordpress.org,
* because it allows results to be cached server-side and shared with other
* users and sites in the network. This makes the process more efficient,
* since increasing the number of visits that get cached data means users
* don't have to wait as often; if the user's browser made the request
* directly, it would also need to make a second request to WP in order to
* pass the data for caching. Having WP make the request also introduces
* the opportunity to anonymize the IP before sending it to w.org, which
* mitigates possible privacy concerns.
*
* @since 4.8.0
* @since 5.5.2 Response no longer contains formatted date field. They're added
* in `wp.communityEvents.populateDynamicEventFields()` now.
*
* @param string $location_search Optional. City name to help determine the location.
* e.g., "Seattle". Default empty string.
* @param string $timezone Optional. Timezone to help determine the location.
* Default empty string.
* @return array|WP_Error A WP_Error on failure; an array with location and events on
* success.
*/
public function get_events( $location_search = '', $timezone = '' ) {
$cached_events = $this->get_cached_events();
if ( ! $location_search && $cached_events ) {
return $cached_events;
}
// Include an unmodified $wp_version.
require ABSPATH . WPINC . '/version.php';
$api_url = 'http://api.wordpress.org/events/1.0/';
$request_args = $this->get_request_args( $location_search, $timezone );
$request_args['user-agent'] = 'WordPress/' . $wp_version . '; ' . home_url( '/' );
if ( wp_http_supports( array( 'ssl' ) ) ) {
$api_url = set_url_scheme( $api_url, 'https' );
}
$response = wp_remote_get( $api_url, $request_args );
$response_code = wp_remote_retrieve_response_code( $response );
$response_body = json_decode( wp_remote_retrieve_body( $response ), true );
$response_error = null;
if ( is_wp_error( $response ) ) {
$response_error = $response;
} elseif ( 200 !== $response_code ) {
$response_error = new WP_Error(
'api-error',
/* translators: %d: Numeric HTTP status code, e.g. 400, 403, 500, 504, etc. */
sprintf( __( 'Invalid API response code (%d).' ), $response_code )
);
} elseif ( ! isset( $response_body['location'], $response_body['events'] ) ) {
$response_error = new WP_Error(
'api-invalid-response',
isset( $response_body['error'] ) ? $response_body['error'] : __( 'Unknown API error.' )
);
}
if ( is_wp_error( $response_error ) ) {
return $response_error;
} else {
$expiration = false;
if ( isset( $response_body['ttl'] ) ) {
$expiration = $response_body['ttl'];
unset( $response_body['ttl'] );
}
/*
* The IP in the response is usually the same as the one that was sent
* in the request, but in some cases it is different. In those cases,
* it's important to reset it back to the IP from the request.
*
* For example, if the IP sent in the request is private (e.g., 192.168.1.100),
* then the API will ignore that and use the corresponding public IP instead,
* and the public IP will get returned. If the public IP were saved, though,
* then get_cached_events() would always return `false`, because the transient
* would be generated based on the public IP when saving the cache, but generated
* based on the private IP when retrieving the cache.
*/
if ( ! empty( $response_body['location']['ip'] ) ) {
$response_body['location']['ip'] = $request_args['body']['ip'];
}
/*
* The API doesn't return a description for latitude/longitude requests,
* but the description is already saved in the user location, so that
* one can be used instead.
*/
if ( $this->coordinates_match( $request_args['body'], $response_body['location'] ) && empty( $response_body['location']['description'] ) ) {
$response_body['location']['description'] = $this->user_location['description'];
}
/*
* Store the raw response, because events will expire before the cache does.
* The response will need to be processed every page load.
*/
$this->cache_events( $response_body, $expiration );
$response_body['events'] = $this->trim_events( $response_body['events'] );
return $response_body;
}
}
/**
* Builds an array of args to use in an HTTP request to the w.org Events API.
*
* @since 4.8.0
*
* @param string $search Optional. City search string. Default empty string.
* @param string $timezone Optional. Timezone string. Default empty string.
* @return array The request args.
*/
protected function get_request_args( $search = '', $timezone = '' ) {
$args = array(
'number' => 5, // Get more than three in case some get trimmed out.
'ip' => self::get_unsafe_client_ip(),
);
/*
* Include the minimal set of necessary arguments, in order to increase the
* chances of a cache-hit on the API side.
*/
if ( empty( $search ) && isset( $this->user_location['latitude'], $this->user_location['longitude'] ) ) {
$args['latitude'] = $this->user_location['latitude'];
$args['longitude'] = $this->user_location['longitude'];
} else {
$args['locale'] = get_user_locale( $this->user_id );
if ( $timezone ) {
$args['timezone'] = $timezone;
}
if ( $search ) {
$args['location'] = $search;
}
}
// Wrap the args in an array compatible with the second parameter of `wp_remote_get()`.
return array(
'body' => $args,
);
}
/**
* Determines the user's actual IP address and attempts to partially
* anonymize an IP address by converting it to a network ID.
*
* Geolocating the network ID usually returns a similar location as the
* actual IP, but provides some privacy for the user.
*
* $_SERVER['REMOTE_ADDR'] cannot be used in all cases, such as when the user
* is making their request through a proxy, or when the web server is behind
* a proxy. In those cases, $_SERVER['REMOTE_ADDR'] is set to the proxy address rather
* than the user's actual address.
*
* Modified from https://stackoverflow.com/a/2031935/450127, MIT license.
* Modified from https://github.com/geertw/php-ip-anonymizer, MIT license.
*
* SECURITY WARNING: This function is _NOT_ intended to be used in
* circumstances where the authenticity of the IP address matters. This does
* _NOT_ guarantee that the returned address is valid or accurate, and it can
* be easily spoofed.
*
* @since 4.8.0
*
* @return string|false The anonymized address on success; the given address
* or false on failure.
*/
public static function get_unsafe_client_ip() {
$client_ip = false;
// In order of preference, with the best ones for this purpose first.
$address_headers = array(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR',
);
foreach ( $address_headers as $header ) {
if ( array_key_exists( $header, $_SERVER ) ) {
/*
* HTTP_X_FORWARDED_FOR can contain a chain of comma-separated
* addresses. The first one is the original client. It can't be
* trusted for authenticity, but we don't need to for this purpose.
*/
$address_chain = explode( ',', $_SERVER[ $header ] );
$client_ip = trim( $address_chain[0] );
break;
}
}
if ( ! $client_ip ) {
return false;
}
$anon_ip = wp_privacy_anonymize_ip( $client_ip, true );
if ( '0.0.0.0' === $anon_ip || '::' === $anon_ip ) {
return false;
}
return $anon_ip;
}
/**
* Test if two pairs of latitude/longitude coordinates match each other.
*
* @since 4.8.0
*
* @param array $a The first pair, with indexes 'latitude' and 'longitude'.
* @param array $b The second pair, with indexes 'latitude' and 'longitude'.
* @return bool True if they match, false if they don't.
*/
protected function coordinates_match( $a, $b ) {
if ( ! isset( $a['latitude'], $a['longitude'], $b['latitude'], $b['longitude'] ) ) {
return false;
}
return $a['latitude'] === $b['latitude'] && $a['longitude'] === $b['longitude'];
}
/**
* Generates a transient key based on user location.
*
* This could be reduced to a one-liner in the calling functions, but it's
* intentionally a separate function because it's called from multiple
* functions, and having it abstracted keeps the logic consistent and DRY,
* which is less prone to errors.
*
* @since 4.8.0
*
* @param array $location Should contain 'latitude' and 'longitude' indexes.
* @return string|false Transient key on success, false on failure.
*/
protected function get_events_transient_key( $location ) {
$key = false;
if ( isset( $location['ip'] ) ) {
$key = 'community-events-' . md5( $location['ip'] );
} elseif ( isset( $location['latitude'], $location['longitude'] ) ) {
$key = 'community-events-' . md5( $location['latitude'] . $location['longitude'] );
}
return $key;
}
/**
* Caches an array of events data from the Events API.
*
* @since 4.8.0
*
* @param array $events Response body from the API request.
* @param int|false $expiration Optional. Amount of time to cache the events. Defaults to false.
* @return bool true if events were cached; false if not.
*/
protected function cache_events( $events, $expiration = false ) {
$set = false;
$transient_key = $this->get_events_transient_key( $events['location'] );
$cache_expiration = $expiration ? absint( $expiration ) : HOUR_IN_SECONDS * 12;
if ( $transient_key ) {
$set = set_site_transient( $transient_key, $events, $cache_expiration );
}
return $set;
}
/**
* Gets cached events.
*
* @since 4.8.0
* @since 5.5.2 Response no longer contains formatted date field. They're added
* in `wp.communityEvents.populateDynamicEventFields()` now.
*
* @return array|false An array containing `location` and `events` items
* on success, false on failure.
*/
public function get_cached_events() {
$transient_key = $this->get_events_transient_key( $this->user_location );
if ( ! $transient_key ) {
return false;
}
$cached_response = get_site_transient( $transient_key );
if ( isset( $cached_response['events'] ) ) {
$cached_response['events'] = $this->trim_events( $cached_response['events'] );
}
return $cached_response;
}
/**
* Adds formatted date and time items for each event in an API response.
*
* This has to be called after the data is pulled from the cache, because
* the cached events are shared by all users. If it was called before storing
* the cache, then all users would see the events in the localized data/time
* of the user who triggered the cache refresh, rather than their own.
*
* @since 4.8.0
* @deprecated 5.6.0 No longer used in core.
*
* @param array $response_body The response which contains the events.
* @return array The response with dates and times formatted.
*/
protected function format_event_data_time( $response_body ) {
_deprecated_function(
__METHOD__,
'5.5.2',
'This is no longer used by core, and only kept for backward compatibility.'
);
if ( isset( $response_body['events'] ) ) {
foreach ( $response_body['events'] as $key => $event ) {
$timestamp = strtotime( $event['date'] );
/*
* The `date_format` option is not used because it's important
* in this context to keep the day of the week in the formatted date,
* so that users can tell at a glance if the event is on a day they
* are available, without having to open the link.
*/
/* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://www.php.net/manual/datetime.format.php */
$formatted_date = date_i18n( __( 'l, M j, Y' ), $timestamp );
$formatted_time = date_i18n( get_option( 'time_format' ), $timestamp );
if ( isset( $event['end_date'] ) ) {
$end_timestamp = strtotime( $event['end_date'] );
$formatted_end_date = date_i18n( __( 'l, M j, Y' ), $end_timestamp );
if ( 'meetup' !== $event['type'] && $formatted_end_date !== $formatted_date ) {
/* translators: Upcoming events month format. See https://www.php.net/manual/datetime.format.php */
$start_month = date_i18n( _x( 'F', 'upcoming events month format' ), $timestamp );
$end_month = date_i18n( _x( 'F', 'upcoming events month format' ), $end_timestamp );
if ( $start_month === $end_month ) {
$formatted_date = sprintf(
/* translators: Date string for upcoming events. 1: Month, 2: Starting day, 3: Ending day, 4: Year. */
__( '%1$s %2$d–%3$d, %4$d' ),
$start_month,
/* translators: Upcoming events day format. See https://www.php.net/manual/datetime.format.php */
date_i18n( _x( 'j', 'upcoming events day format' ), $timestamp ),
date_i18n( _x( 'j', 'upcoming events day format' ), $end_timestamp ),
/* translators: Upcoming events year format. See https://www.php.net/manual/datetime.format.php */
date_i18n( _x( 'Y', 'upcoming events year format' ), $timestamp )
);
} else {
$formatted_date = sprintf(
/* translators: Date string for upcoming events. 1: Starting month, 2: Starting day, 3: Ending month, 4: Ending day, 5: Year. */
__( '%1$s %2$d – %3$s %4$d, %5$d' ),
$start_month,
date_i18n( _x( 'j', 'upcoming events day format' ), $timestamp ),
$end_month,
date_i18n( _x( 'j', 'upcoming events day format' ), $end_timestamp ),
date_i18n( _x( 'Y', 'upcoming events year format' ), $timestamp )
);
}
$formatted_date = wp_maybe_decline_date( $formatted_date, 'F j, Y' );
}
}
$response_body['events'][ $key ]['formatted_date'] = $formatted_date;
$response_body['events'][ $key ]['formatted_time'] = $formatted_time;
}
}
return $response_body;
}
/**
* Prepares the event list for presentation.
*
* Discards expired events, and makes WordCamps "sticky." Attendees need more
* advanced notice about WordCamps than they do for meetups, so camps should
* appear in the list sooner. If a WordCamp is coming up, the API will "stick"
* it in the response, even if it wouldn't otherwise appear. When that happens,
* the event will be at the end of the list, and will need to be moved into a
* higher position, so that it doesn't get trimmed off.
*
* @since 4.8.0
* @since 4.9.7 Stick a WordCamp to the final list.
* @since 5.5.2 Accepts and returns only the events, rather than an entire HTTP response.
* @since 6.0.0 Decode HTML entities from the event title.
*
* @param array $events The events that will be prepared.
* @return array The response body with events trimmed.
*/
protected function trim_events( array $events ) {
$future_events = array();
foreach ( $events as $event ) {
/*
* The API's `date` and `end_date` fields are in the _event's_ local timezone, but UTC is needed so
* it can be converted to the _user's_ local time.
*/
$end_time = (int) $event['end_unix_timestamp'];
if ( time() < $end_time ) {
// Decode HTML entities from the event title.
$event['title'] = html_entity_decode( $event['title'], ENT_QUOTES, 'UTF-8' );
array_push( $future_events, $event );
}
}
$future_wordcamps = array_filter(
$future_events,
static function ( $wordcamp ) {
return 'wordcamp' === $wordcamp['type'];
}
);
$future_wordcamps = array_values( $future_wordcamps ); // Remove gaps in indices.
$trimmed_events = array_slice( $future_events, 0, 3 );
$trimmed_event_types = wp_list_pluck( $trimmed_events, 'type' );
// Make sure the soonest upcoming WordCamp is pinned in the list.
if ( $future_wordcamps && ! in_array( 'wordcamp', $trimmed_event_types, true ) ) {
array_pop( $trimmed_events );
array_push( $trimmed_events, $future_wordcamps[0] );
}
return $trimmed_events;
}
/**
* Logs responses to Events API requests.
*
* @since 4.8.0
* @deprecated 4.9.0 Use a plugin instead. See #41217 for an example.
*
* @param string $message A description of what occurred.
* @param array $details Details that provide more context for the
* log entry.
*/
protected function maybe_log_events_response( $message, $details ) {
_deprecated_function( __METHOD__, '4.9.0' );
if ( ! WP_DEBUG_LOG ) {
return;
}
error_log(
sprintf(
'%s: %s. Details: %s',
__METHOD__,
trim( $message, '.' ),
wp_json_encode( $details )
)
);
}
}
PK %�[;���2� 2� plugin-install.phpnu �[��� <?php
/**
* WordPress Plugin Install Administration API
*
* @package WordPress
* @subpackage Administration
*/
/**
* Retrieves plugin installer pages from the WordPress.org Plugins API.
*
* It is possible for a plugin to override the Plugin API result with three
* filters. Assume this is for plugins, which can extend on the Plugin Info to
* offer more choices. This is very powerful and must be used with care when
* overriding the filters.
*
* The first filter, {@see 'plugins_api_args'}, is for the args and gives the action
* as the second parameter. The hook for {@see 'plugins_api_args'} must ensure that
* an object is returned.
*
* The second filter, {@see 'plugins_api'}, allows a plugin to override the WordPress.org
* Plugin Installation API entirely. If `$action` is 'query_plugins' or 'plugin_information',
* an object MUST be passed. If `$action` is 'hot_tags', an array MUST be passed.
*
* Finally, the third filter, {@see 'plugins_api_result'}, makes it possible to filter the
* response object or array, depending on the `$action` type.
*
* Supported arguments per action:
*
* | Argument Name | query_plugins | plugin_information | hot_tags |
* | -------------------- | :-----------: | :----------------: | :------: |
* | `$slug` | No | Yes | No |
* | `$per_page` | Yes | No | No |
* | `$page` | Yes | No | No |
* | `$number` | No | No | Yes |
* | `$search` | Yes | No | No |
* | `$tag` | Yes | No | No |
* | `$author` | Yes | No | No |
* | `$user` | Yes | No | No |
* | `$browse` | Yes | No | No |
* | `$locale` | Yes | Yes | No |
* | `$installed_plugins` | Yes | No | No |
* | `$is_ssl` | Yes | Yes | No |
* | `$fields` | Yes | Yes | No |
*
* @since 2.7.0
*
* @param string $action API action to perform: 'query_plugins', 'plugin_information',
* or 'hot_tags'.
* @param array|object $args {
* Optional. Array or object of arguments to serialize for the Plugin Info API.
*
* @type string $slug The plugin slug. Default empty.
* @type int $per_page Number of plugins per page. Default 24.
* @type int $page Number of current page. Default 1.
* @type int $number Number of tags or categories to be queried.
* @type string $search A search term. Default empty.
* @type string $tag Tag to filter plugins. Default empty.
* @type string $author Username of an plugin author to filter plugins. Default empty.
* @type string $user Username to query for their favorites. Default empty.
* @type string $browse Browse view: 'popular', 'new', 'beta', 'recommended'.
* @type string $locale Locale to provide context-sensitive results. Default is the value
* of get_locale().
* @type string $installed_plugins Installed plugins to provide context-sensitive results.
* @type bool $is_ssl Whether links should be returned with https or not. Default false.
* @type array $fields {
* Array of fields which should or should not be returned.
*
* @type bool $short_description Whether to return the plugin short description. Default true.
* @type bool $description Whether to return the plugin full description. Default false.
* @type bool $sections Whether to return the plugin readme sections: description, installation,
* FAQ, screenshots, other notes, and changelog. Default false.
* @type bool $tested Whether to return the 'Compatible up to' value. Default true.
* @type bool $requires Whether to return the required WordPress version. Default true.
* @type bool $requires_php Whether to return the required PHP version. Default true.
* @type bool $rating Whether to return the rating in percent and total number of ratings.
* Default true.
* @type bool $ratings Whether to return the number of rating for each star (1-5). Default true.
* @type bool $downloaded Whether to return the download count. Default true.
* @type bool $downloadlink Whether to return the download link for the package. Default true.
* @type bool $last_updated Whether to return the date of the last update. Default true.
* @type bool $added Whether to return the date when the plugin was added to the wordpress.org
* repository. Default true.
* @type bool $tags Whether to return the assigned tags. Default true.
* @type bool $compatibility Whether to return the WordPress compatibility list. Default true.
* @type bool $homepage Whether to return the plugin homepage link. Default true.
* @type bool $versions Whether to return the list of all available versions. Default false.
* @type bool $donate_link Whether to return the donation link. Default true.
* @type bool $reviews Whether to return the plugin reviews. Default false.
* @type bool $banners Whether to return the banner images links. Default false.
* @type bool $icons Whether to return the icon links. Default false.
* @type bool $active_installs Whether to return the number of active installations. Default false.
* @type bool $contributors Whether to return the list of contributors. Default false.
* }
* }
* @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
* {@link https://developer.wordpress.org/reference/functions/plugins_api/ function reference article}
* for more information on the make-up of possible return values depending on the value of `$action`.
*/
function plugins_api( $action, $args = array() ) {
if ( is_array( $args ) ) {
$args = (object) $args;
}
if ( 'query_plugins' === $action ) {
if ( ! isset( $args->per_page ) ) {
$args->per_page = 24;
}
}
if ( ! isset( $args->locale ) ) {
$args->locale = get_user_locale();
}
if ( ! isset( $args->wp_version ) ) {
$args->wp_version = substr( wp_get_wp_version(), 0, 3 ); // x.y
}
/**
* Filters the WordPress.org Plugin Installation API arguments.
*
* Important: An object MUST be returned to this filter.
*
* @since 2.7.0
*
* @param object $args Plugin API arguments.
* @param string $action The type of information being requested from the Plugin Installation API.
*/
$args = apply_filters( 'plugins_api_args', $args, $action );
/**
* Filters the response for the current WordPress.org Plugin Installation API request.
*
* Returning a non-false value will effectively short-circuit the WordPress.org API request.
*
* If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed.
* If `$action` is 'hot_tags', an array should be passed.
*
* @since 2.7.0
*
* @param false|object|array $result The result object or array. Default false.
* @param string $action The type of information being requested from the Plugin Installation API.
* @param object $args Plugin API arguments.
*/
$res = apply_filters( 'plugins_api', false, $action, $args );
if ( false === $res ) {
$url = 'http://api.wordpress.org/plugins/info/1.2/';
$url = add_query_arg(
array(
'action' => $action,
'request' => $args,
),
$url
);
$http_url = $url;
$ssl = wp_http_supports( array( 'ssl' ) );
if ( $ssl ) {
$url = set_url_scheme( $url, 'https' );
}
$http_args = array(
'timeout' => 15,
'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),
);
$request = wp_remote_get( $url, $http_args );
if ( $ssl && is_wp_error( $request ) ) {
if ( ! wp_is_json_request() ) {
wp_trigger_error(
__FUNCTION__,
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
__( 'https://wordpress.org/support/forums/' )
) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
}
$request = wp_remote_get( $http_url, $http_args );
}
if ( is_wp_error( $request ) ) {
$res = new WP_Error(
'plugins_api_failed',
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
__( 'https://wordpress.org/support/forums/' )
),
$request->get_error_message()
);
} else {
$res = json_decode( wp_remote_retrieve_body( $request ), true );
if ( is_array( $res ) ) {
// Object casting is required in order to match the info/1.0 format.
$res = (object) $res;
} elseif ( null === $res ) {
$res = new WP_Error(
'plugins_api_failed',
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
__( 'https://wordpress.org/support/forums/' )
),
wp_remote_retrieve_body( $request )
);
}
if ( isset( $res->error ) ) {
$res = new WP_Error( 'plugins_api_failed', $res->error );
}
}
} elseif ( ! is_wp_error( $res ) ) {
$res->external = true;
}
/**
* Filters the Plugin Installation API response results.
*
* @since 2.7.0
*
* @param object|WP_Error $res Response object or WP_Error.
* @param string $action The type of information being requested from the Plugin Installation API.
* @param object $args Plugin API arguments.
*/
return apply_filters( 'plugins_api_result', $res, $action, $args );
}
/**
* Retrieves popular WordPress plugin tags.
*
* @since 2.7.0
*
* @param array $args
* @return array|WP_Error
*/
function install_popular_tags( $args = array() ) {
$key = md5( serialize( $args ) );
$tags = get_site_transient( 'poptags_' . $key );
if ( false !== $tags ) {
return $tags;
}
$tags = plugins_api( 'hot_tags', $args );
if ( is_wp_error( $tags ) ) {
return $tags;
}
set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS );
return $tags;
}
/**
* Displays the Featured tab of Add Plugins screen.
*
* @since 2.7.0
*/
function install_dashboard() {
display_plugins_table();
?>
<div class="plugins-popular-tags-wrapper">
<h2><?php _e( 'Popular tags' ); ?></h2>
<p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ); ?></p>
<?php
$api_tags = install_popular_tags();
echo '<p class="popular-tags">';
if ( is_wp_error( $api_tags ) ) {
echo $api_tags->get_error_message();
} else {
// Set up the tags in a way which can be interpreted by wp_generate_tag_cloud().
$tags = array();
foreach ( (array) $api_tags as $tag ) {
$url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) );
$data = array(
'link' => esc_url( $url ),
'name' => $tag['name'],
'slug' => $tag['slug'],
'id' => sanitize_title_with_dashes( $tag['name'] ),
'count' => $tag['count'],
);
$tags[ $tag['name'] ] = (object) $data;
}
echo wp_generate_tag_cloud(
$tags,
array(
/* translators: %s: Number of plugins. */
'single_text' => __( '%s plugin' ),
/* translators: %s: Number of plugins. */
'multiple_text' => __( '%s plugins' ),
)
);
}
echo '</p><br class="clear" /></div>';
}
/**
* Displays a search form for searching plugins.
*
* @since 2.7.0
* @since 4.6.0 The `$type_selector` parameter was deprecated.
*
* @param bool $deprecated Not used.
*/
function install_search_form( $deprecated = true ) {
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? urldecode( wp_unslash( $_REQUEST['s'] ) ) : '';
?>
<form class="search-form search-plugins" method="get">
<input type="hidden" name="tab" value="search" />
<label for="search-plugins"><?php _e( 'Search Plugins' ); ?></label>
<input type="search" name="s" id="search-plugins" value="<?php echo esc_attr( $term ); ?>" class="wp-filter-search" />
<label class="screen-reader-text" for="typeselector">
<?php
/* translators: Hidden accessibility text. */
_e( 'Search plugins by:' );
?>
</label>
<select name="type" id="typeselector">
<option value="term"<?php selected( 'term', $type ); ?>><?php _e( 'Keyword' ); ?></option>
<option value="author"<?php selected( 'author', $type ); ?>><?php _e( 'Author' ); ?></option>
<option value="tag"<?php selected( 'tag', $type ); ?>><?php _ex( 'Tag', 'Plugin Installer' ); ?></option>
</select>
<?php submit_button( __( 'Search Plugins' ), 'hide-if-js', false, false, array( 'id' => 'search-submit' ) ); ?>
</form>
<?php
}
/**
* Displays a form to upload plugins from zip files.
*
* @since 2.8.0
*/
function install_plugins_upload() {
?>
<div class="upload-plugin">
<p class="install-help"><?php _e( 'If you have a plugin in a .zip format, you may install or update it by uploading it here.' ); ?></p>
<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo esc_url( self_admin_url( 'update.php?action=upload-plugin' ) ); ?>">
<?php wp_nonce_field( 'plugin-upload' ); ?>
<label class="screen-reader-text" for="pluginzip">
<?php
/* translators: Hidden accessibility text. */
_e( 'Plugin zip file' );
?>
</label>
<input type="file" id="pluginzip" name="pluginzip" accept=".zip" />
<?php submit_button( _x( 'Install Now', 'plugin' ), '', 'install-plugin-submit', false ); ?>
</form>
</div>
<?php
}
/**
* Shows a username form for the favorites page.
*
* @since 3.5.0
*/
function install_plugins_favorites_form() {
$user = get_user_option( 'wporg_favorites' );
$action = 'save_wporg_username_' . get_current_user_id();
?>
<p><?php _e( 'If you have marked plugins as favorites on WordPress.org, you can browse them here.' ); ?></p>
<form method="get">
<input type="hidden" name="tab" value="favorites" />
<p>
<label for="user"><?php _e( 'Your WordPress.org username:' ); ?></label>
<input type="search" id="user" name="user" value="<?php echo esc_attr( $user ); ?>" />
<input type="submit" class="button" value="<?php esc_attr_e( 'Get Favorites' ); ?>" />
<input type="hidden" id="wporg-username-nonce" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( $action ) ); ?>" />
</p>
</form>
<?php
}
/**
* Displays plugin content based on plugin list.
*
* @since 2.7.0
*
* @global WP_List_Table $wp_list_table
*/
function display_plugins_table() {
global $wp_list_table;
switch ( current_filter() ) {
case 'install_plugins_beta':
printf(
/* translators: %s: URL to "Features as Plugins" page. */
'<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>',
'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/'
);
break;
case 'install_plugins_featured':
printf(
/* translators: %s: https://wordpress.org/plugins/ */
'<p>' . __( 'Plugins extend and expand the functionality of WordPress. You may install plugins in the <a href="%s">WordPress Plugin Directory</a> right from here, or upload a plugin in .zip format by clicking the button at the top of this page.' ) . '</p>',
__( 'https://wordpress.org/plugins/' )
);
break;
case 'install_plugins_recommended':
echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>';
break;
case 'install_plugins_favorites':
if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) {
return;
}
break;
}
?>
<form id="plugin-filter" method="post">
<?php $wp_list_table->display(); ?>
</form>
<?php
}
/**
* Determines the status we can perform on a plugin.
*
* @since 3.0.0
*
* @param array|object $api Data about the plugin retrieved from the API.
* @param bool $loop Optional. Disable further loops. Default false.
* @return array {
* Plugin installation status data.
*
* @type string $status Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
* @type string $url Plugin installation URL.
* @type string $version The most recent version of the plugin.
* @type string $file Plugin filename relative to the plugins directory.
* }
*/
function install_plugin_install_status( $api, $loop = false ) {
// This function is called recursively, $loop prevents further loops.
if ( is_array( $api ) ) {
$api = (object) $api;
}
// Default to a "new" plugin.
$status = 'install';
$url = false;
$update_file = false;
$version = '';
/*
* Check to see if this plugin is known to be installed,
* and has an update awaiting it.
*/
$update_plugins = get_site_transient( 'update_plugins' );
if ( isset( $update_plugins->response ) ) {
foreach ( (array) $update_plugins->response as $file => $plugin ) {
if ( $plugin->slug === $api->slug ) {
$status = 'update_available';
$update_file = $file;
$version = $plugin->new_version;
if ( current_user_can( 'update_plugins' ) ) {
$url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file );
}
break;
}
}
}
if ( 'install' === $status ) {
if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
$installed_plugin = get_plugins( '/' . $api->slug );
if ( empty( $installed_plugin ) ) {
if ( current_user_can( 'install_plugins' ) ) {
$url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
}
} else {
$key = array_keys( $installed_plugin );
/*
* Use the first plugin regardless of the name.
* Could have issues for multiple plugins in one directory if they share different version numbers.
*/
$key = reset( $key );
$update_file = $api->slug . '/' . $key;
if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) {
$status = 'latest_installed';
} elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) {
$status = 'newer_installed';
$version = $installed_plugin[ $key ]['Version'];
} else {
// If the above update check failed, then that probably means that the update checker has out-of-date information, force a refresh.
if ( ! $loop ) {
delete_site_transient( 'update_plugins' );
wp_update_plugins();
return install_plugin_install_status( $api, true );
}
}
}
} else {
// "install" & no directory with that slug.
if ( current_user_can( 'install_plugins' ) ) {
$url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
}
}
}
if ( isset( $_GET['from'] ) ) {
$url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) );
}
$file = $update_file;
return compact( 'status', 'url', 'version', 'file' );
}
/**
* Displays plugin information in dialog box form.
*
* @since 2.7.0
*
* @global string $tab
*/
function install_plugin_information() {
global $tab;
if ( empty( $_REQUEST['plugin'] ) ) {
return;
}
$api = plugins_api(
'plugin_information',
array(
'slug' => wp_unslash( $_REQUEST['plugin'] ),
)
);
if ( is_wp_error( $api ) ) {
wp_die( $api );
}
$plugins_allowedtags = array(
'a' => array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'code' => array(),
'pre' => array(),
'em' => array(),
'strong' => array(),
'div' => array( 'class' => array() ),
'span' => array( 'class' => array() ),
'p' => array(),
'br' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'h1' => array(),
'h2' => array(),
'h3' => array(),
'h4' => array(),
'h5' => array(),
'h6' => array(),
'img' => array(
'src' => array(),
'class' => array(),
'alt' => array(),
),
'blockquote' => array( 'cite' => true ),
);
$plugins_section_titles = array(
'description' => _x( 'Description', 'Plugin installer section title' ),
'installation' => _x( 'Installation', 'Plugin installer section title' ),
'faq' => _x( 'FAQ', 'Plugin installer section title' ),
'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ),
);
// Sanitize HTML.
foreach ( (array) $api->sections as $section_name => $content ) {
$api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags );
}
foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
if ( isset( $api->$key ) ) {
$api->$key = wp_kses( $api->$key, $plugins_allowedtags );
}
}
$_tab = esc_attr( $tab );
// Default to the Description tab, Do not translate, API returns English.
$section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description';
if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
$section_titles = array_keys( (array) $api->sections );
$section = reset( $section_titles );
}
iframe_header( __( 'Plugin Installation' ) );
$_with_banner = '';
if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
$_with_banner = 'with-banner';
$low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
$high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
?>
<style type="text/css">
#plugin-information-title.with-banner {
background-image: url( <?php echo esc_url( $low ); ?> );
}
@media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) {
#plugin-information-title.with-banner {
background-image: url( <?php echo esc_url( $high ); ?> );
}
}
</style>
<?php
}
echo '<div id="plugin-information-scrollable">';
echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
foreach ( (array) $api->sections as $section_name => $content ) {
if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
continue;
}
if ( isset( $plugins_section_titles[ $section_name ] ) ) {
$title = $plugins_section_titles[ $section_name ];
} else {
$title = ucwords( str_replace( '_', ' ', $section_name ) );
}
$class = ( $section_name === $section ) ? ' class="current"' : '';
$href = add_query_arg(
array(
'tab' => $tab,
'section' => $section_name,
)
);
$href = esc_url( $href );
$san_section = esc_attr( $section_name );
echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
}
echo "</div>\n";
?>
<div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
<div class="fyi">
<ul>
<?php if ( ! empty( $api->version ) ) { ?>
<li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
<?php } if ( ! empty( $api->author ) ) { ?>
<li><strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?></li>
<?php } if ( ! empty( $api->last_updated ) ) { ?>
<li><strong><?php _e( 'Last Updated:' ); ?></strong>
<?php
/* translators: %s: Human-readable time difference. */
printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) );
?>
</li>
<?php } if ( ! empty( $api->requires ) ) { ?>
<li>
<strong><?php _e( 'Requires WordPress Version:' ); ?></strong>
<?php
/* translators: %s: Version number. */
printf( __( '%s or higher' ), $api->requires );
?>
</li>
<?php } if ( ! empty( $api->tested ) ) { ?>
<li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li>
<?php } if ( ! empty( $api->requires_php ) ) { ?>
<li>
<strong><?php _e( 'Requires PHP Version:' ); ?></strong>
<?php
/* translators: %s: Version number. */
printf( __( '%s or higher' ), $api->requires_php );
?>
</li>
<?php } if ( isset( $api->active_installs ) ) { ?>
<li><strong><?php _e( 'Active Installations:' ); ?></strong>
<?php
if ( $api->active_installs >= 1000000 ) {
$active_installs_millions = floor( $api->active_installs / 1000000 );
printf(
/* translators: %s: Number of millions. */
_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
number_format_i18n( $active_installs_millions )
);
} elseif ( $api->active_installs < 10 ) {
_ex( 'Less Than 10', 'Active plugin installations' );
} else {
echo number_format_i18n( $api->active_installs ) . '+';
}
?>
</li>
<?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?>
<li><a target="_blank" href="<?php echo esc_url( __( 'https://wordpress.org/plugins/' ) . $api->slug ); ?>/"><?php _e( 'WordPress.org Plugin Page »' ); ?></a></li>
<?php } if ( ! empty( $api->homepage ) ) { ?>
<li><a target="_blank" href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage »' ); ?></a></li>
<?php } if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?>
<li><a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a></li>
<?php } ?>
</ul>
<?php if ( ! empty( $api->rating ) ) { ?>
<h3><?php _e( 'Average Rating' ); ?></h3>
<?php
wp_star_rating(
array(
'rating' => $api->rating,
'type' => 'percent',
'number' => $api->num_ratings,
)
);
?>
<p aria-hidden="true" class="fyi-description">
<?php
printf(
/* translators: %s: Number of ratings. */
_n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ),
number_format_i18n( $api->num_ratings )
);
?>
</p>
<?php
}
if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
?>
<h3><?php _e( 'Reviews' ); ?></h3>
<p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p>
<?php
foreach ( $api->ratings as $key => $ratecount ) {
// Avoid div-by-zero.
$_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
$aria_label = esc_attr(
sprintf(
/* translators: 1: Number of stars (used to determine singular/plural), 2: Number of reviews. */
_n(
'Reviews with %1$d star: %2$s. Opens in a new tab.',
'Reviews with %1$d stars: %2$s. Opens in a new tab.',
$key
),
$key,
number_format_i18n( $ratecount )
)
);
?>
<div class="counter-container">
<span class="counter-label">
<?php
printf(
'<a href="%s" target="_blank" aria-label="%s">%s</a>',
"https://wordpress.org/support/plugin/{$api->slug}/reviews/?filter={$key}",
$aria_label,
/* translators: %s: Number of stars. */
sprintf( _n( '%d star', '%d stars', $key ), $key )
);
?>
</span>
<span class="counter-back">
<span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
</span>
<span class="counter-count" aria-hidden="true"><?php echo number_format_i18n( $ratecount ); ?></span>
</div>
<?php
}
}
if ( ! empty( $api->contributors ) ) {
?>
<h3><?php _e( 'Contributors' ); ?></h3>
<ul class="contributors">
<?php
foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) {
$contrib_name = $contrib_details['display_name'];
if ( ! $contrib_name ) {
$contrib_name = $contrib_username;
}
$contrib_name = esc_html( $contrib_name );
$contrib_profile = esc_url( $contrib_details['profile'] );
$contrib_avatar = esc_url( add_query_arg( 's', '36', $contrib_details['avatar'] ) );
echo "<li><a href='{$contrib_profile}' target='_blank'><img src='{$contrib_avatar}' width='18' height='18' alt='' />{$contrib_name}</a></li>";
}
?>
</ul>
<?php if ( ! empty( $api->donate_link ) ) { ?>
<a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a>
<?php } ?>
<?php } ?>
</div>
<div id="section-holder">
<?php
$requires_php = isset( $api->requires_php ) ? $api->requires_php : null;
$requires_wp = isset( $api->requires ) ? $api->requires : null;
$compatible_php = is_php_version_compatible( $requires_php );
$compatible_wp = is_wp_version_compatible( $requires_wp );
$tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) );
if ( ! $compatible_php ) {
$compatible_php_notice_message = '<p>';
$compatible_php_notice_message .= __( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' );
if ( current_user_can( 'update_php' ) ) {
$compatible_php_notice_message .= sprintf(
/* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
) . wp_update_php_annotation( '</p><p><em>', '</em>', false );
} else {
$compatible_php_notice_message .= '</p>';
}
wp_admin_notice(
$compatible_php_notice_message,
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt' ),
'paragraph_wrap' => false,
)
);
}
if ( ! $tested_wp ) {
wp_admin_notice(
__( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' ),
array(
'type' => 'warning',
'additional_classes' => array( 'notice-alt' ),
)
);
} elseif ( ! $compatible_wp ) {
$compatible_wp_notice_message = __( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
if ( current_user_can( 'update_core' ) ) {
$compatible_wp_notice_message .= sprintf(
/* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ),
esc_url( self_admin_url( 'update-core.php' ) )
);
}
wp_admin_notice(
$compatible_wp_notice_message,
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt' ),
)
);
}
foreach ( (array) $api->sections as $section_name => $content ) {
$content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
$content = links_add_target( $content, '_blank' );
$san_section = esc_attr( $section_name );
$display = ( $section_name === $section ) ? 'block' : 'none';
echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
echo $content;
echo "\t</div>\n";
}
echo "</div>\n";
echo "</div>\n";
echo "</div>\n"; // #plugin-information-scrollable
echo "<div id='$tab-footer'>\n";
if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
$button = wp_get_plugin_action_button( $api->name, $api, $compatible_php, $compatible_wp );
$button = str_replace( 'class="', 'class="right ', $button );
if ( ! str_contains( $button, _x( 'Activate', 'plugin' ) ) ) {
$button = str_replace( 'class="', 'id="plugin_install_from_iframe" class="', $button );
}
echo wp_kses_post( $button );
}
echo "</div>\n";
wp_print_request_filesystem_credentials_modal();
wp_print_admin_notice_templates();
iframe_footer();
exit;
}
/**
* Gets the markup for the plugin install action button.
*
* @since 6.5.0
*
* @param string $name Plugin name.
* @param array|object $data {
* An array or object of plugin data. Can be retrieved from the API.
*
* @type string $slug The plugin slug.
* @type string[] $requires_plugins An array of plugin dependency slugs.
* @type string $version The plugin's version string. Used when getting the install status.
* }
* @param bool $compatible_php The result of a PHP compatibility check.
* @param bool $compatible_wp The result of a WP compatibility check.
* @return string The markup for the dependency row button. An empty string if the user does not have capabilities.
*/
function wp_get_plugin_action_button( $name, $data, $compatible_php, $compatible_wp ) {
$button = '';
$data = (object) $data;
$status = install_plugin_install_status( $data );
$requires_plugins = $data->requires_plugins ?? array();
// Determine the status of plugin dependencies.
$installed_plugins = get_plugins();
$active_plugins = get_option( 'active_plugins', array() );
$plugin_dependencies_count = count( $requires_plugins );
$installed_plugin_dependencies_count = 0;
$active_plugin_dependencies_count = 0;
foreach ( $requires_plugins as $dependency ) {
foreach ( array_keys( $installed_plugins ) as $installed_plugin_file ) {
if ( str_contains( $installed_plugin_file, '/' ) && explode( '/', $installed_plugin_file )[0] === $dependency ) {
++$installed_plugin_dependencies_count;
}
}
foreach ( $active_plugins as $active_plugin_file ) {
if ( str_contains( $active_plugin_file, '/' ) && explode( '/', $active_plugin_file )[0] === $dependency ) {
++$active_plugin_dependencies_count;
}
}
}
$all_plugin_dependencies_installed = $installed_plugin_dependencies_count === $plugin_dependencies_count;
$all_plugin_dependencies_active = $active_plugin_dependencies_count === $plugin_dependencies_count;
if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_installed && ! empty( $data->download_link ) ) {
$button = sprintf(
'<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s" role="button">%s</a>',
esc_attr( $data->slug ),
esc_url( $status['url'] ),
/* translators: %s: Plugin name and version. */
esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $name ) ),
esc_attr( $name ),
_x( 'Install Now', 'plugin' )
);
} else {
$button = sprintf(
'<button type="button" class="install-now button button-disabled" disabled="disabled">%s</button>',
_x( 'Install Now', 'plugin' )
);
}
}
break;
case 'update_available':
if ( $status['url'] ) {
if ( $compatible_php && $compatible_wp ) {
$button = sprintf(
'<a class="update-now button aria-button-if-js" data-plugin="%s" data-slug="%s" href="%s" aria-label="%s" data-name="%s" role="button">%s</a>',
esc_attr( $status['file'] ),
esc_attr( $data->slug ),
esc_url( $status['url'] ),
/* translators: %s: Plugin name and version. */
esc_attr( sprintf( _x( 'Update %s now', 'plugin' ), $name ) ),
esc_attr( $name ),
_x( 'Update Now', 'plugin' )
);
} else {
$button = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Update Now', 'plugin' )
);
}
}
break;
case 'latest_installed':
case 'newer_installed':
if ( is_plugin_active( $status['file'] ) ) {
$button = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Active', 'plugin' )
);
} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_active ) {
$button_text = _x( 'Activate', 'plugin' );
/* translators: %s: Plugin name. */
$button_label = _x( 'Activate %s', 'plugin' );
$activate_url = add_query_arg(
array(
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
'action' => 'activate',
'plugin' => $status['file'],
),
network_admin_url( 'plugins.php' )
);
if ( is_network_admin() ) {
$button_text = _x( 'Network Activate', 'plugin' );
/* translators: %s: Plugin name. */
$button_label = _x( 'Network Activate %s', 'plugin' );
$activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
}
$button = sprintf(
'<a href="%1$s" data-name="%2$s" data-slug="%3$s" data-plugin="%4$s" class="button button-primary activate-now" aria-label="%5$s" role="button">%6$s</a>',
esc_url( $activate_url ),
esc_attr( $name ),
esc_attr( $data->slug ),
esc_attr( $status['file'] ),
esc_attr( sprintf( $button_label, $name ) ),
$button_text
);
} else {
$button = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
is_network_admin() ? _x( 'Network Activate', 'plugin' ) : _x( 'Activate', 'plugin' )
);
}
} else {
$button = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Installed', 'plugin' )
);
}
break;
}
}
return $button;
}
PK %�[����d
d
" |