| Server IP : 141.193.213.11 / Your IP : 216.73.216.101 Web Server : nginx System : Linux pod-400555 6.8.0-1055-gke #61-Ubuntu SMP Tue May 26 22:57:42 UTC 2026 x86_64 User : fpm200079 ( 200079) PHP Version : 8.2.36 Disable Function : apache_child_terminate,apache_get_modules,apache_get_version,apache_getenv,apache_note,apache_setenv,disk_free_space,disk_total_space,diskfreespace,dl,exec,fastcgi_finish_request,link,opcache_compile_file,opcache_get_configuration,opcache_invalidate,opcache_is_script_cached,opcache_reset,passthru,pclose,pcntl_exec,popen,posix_getpid,posix_getppid,posix_getpwuid,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,realpath_cache_get,shell_exec,show_source,symlink,system MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /nas/content/live/bartislaw/wp-content/plugins/meta-box/inc/fields/ |
Upload File : |
<?php
defined( 'ABSPATH' ) || die;
/**
* The link field.
*/
class RWMB_Link_Field extends RWMB_Field {
public static function admin_enqueue_scripts(): void {
wp_enqueue_style( 'rwmb-link', RWMB_CSS_URL . 'link.css', [], RWMB_VER );
wp_style_add_data( 'rwmb-link', 'path', RWMB_CSS_DIR . 'link.css' );
wp_enqueue_script( 'rwmb-link', RWMB_JS_URL . 'link.js', [ 'jquery', 'rwmb' ], RWMB_VER, true );
wp_localize_script( 'rwmb-link', 'rwmbLink', [
'editText' => esc_html__( 'Edit', 'meta-box' ),
'removeText' => esc_html__( 'Remove', 'meta-box' ),
'newTabText' => esc_html__( '(new tab)', 'meta-box' ),
'selectLinkText' => esc_html__( 'Add link', 'meta-box' ),
] );
wp_enqueue_editor();
}
/**
* Get field HTML.
*
* @param mixed $meta Meta value.
* @param array $field Field settings.
*/
public static function html( $meta, $field ): string {
$meta = wp_parse_args( $meta, [
'url' => '',
'title' => '',
'target' => '',
'post_id' => 0,
] );
$name = $field['field_name'];
$output = '<div class="rwmb-link" data-field-name="' . esc_attr( $name ) . '">';
$output .= '<input type="hidden" class="rwmb-link-input" name="' . esc_attr( $name ) . '[url]" value="' . esc_attr( $meta['url'] ) . '">';
$output .= '<input type="hidden" class="rwmb-link-input" name="' . esc_attr( $name ) . '[title]" value="' . esc_attr( $meta['title'] ) . '">';
$output .= '<input type="hidden" class="rwmb-link-input" name="' . esc_attr( $name ) . '[target]" value="' . esc_attr( $meta['target'] ) . '">';
$output .= '<input type="hidden" class="rwmb-link-input" name="' . esc_attr( $name ) . '[post_id]" value="' . esc_attr( $meta['post_id'] ) . '">';
if ( $meta['url'] ) {
$output .= '<div class="rwmb-link-display">';
$output .= '<span class="rwmb-link-text">';
$output .= '<span class="dashicons dashicons-admin-links"></span> ';
$output .= '<a href="' . esc_url( $meta['url'] ) . '" target="_blank">' . esc_html( $meta['title'] ) . '</a>';
if ( '_blank' === $meta['target'] ) {
$output .= '<span class="rwmb-link-target">' . esc_html__( '(new tab)', 'meta-box' ) . '</span>';
}
$output .= '</span> ';
$output .= '<a href="#" class="rwmb-link-edit">' . esc_html__( 'Edit', 'meta-box' ) . '</a>';
$output .= '<a href="#" class="rwmb-link-remove">' . esc_html__( 'Remove', 'meta-box' ) . '</a>';
$output .= '</div>';
} else {
$output .= '<div class="rwmb-link-display">';
$output .= '<a href="#" class="rwmb-link-select">' . esc_html__( 'Add link', 'meta-box' ) . '</a>';
$output .= '</div>';
}
$output .= '</div>';
return $output;
}
/**
* Set value of meta before saving into database.
*
* @param mixed $new The submitted meta value.
* @param mixed $old The existing meta value.
* @param int $post_id The post ID.
* @param array $field The field parameters.
*
* @return mixed
*/
public static function value( $new, $old, $post_id, $field ) {
$new = wp_parse_args( $new, [
'url' => '',
'title' => '',
'target' => '',
'post_id' => 0,
] );
$new['url'] = esc_url_raw( $new['url'] );
$new['title'] = wp_kses_post( $new['title'] );
$new['target'] = in_array( $new['target'], [ '_blank', '' ], true ) ? $new['target'] : '';
$new['post_id'] = absint( $new['post_id'] );
$all_empty = empty( $new['url'] ) && empty( $new['title'] ) && empty( $new['post_id'] );
return $all_empty ? [] : $new;
}
/**
* Format a single value for the helper functions.
*
* @param array $field Field parameters.
* @param array $value The value.
* @param array $args Additional arguments. Rarely used. See specific fields for details.
* @param int|null $post_id Post ID. null for current post. Optional.
*/
public static function format_single_value( $field, $value, $args, $post_id ): string {
return empty( $value['url'] ) ? '' : sprintf(
'<a href="%s"%s>%s</a>',
esc_url( $value['url'] ),
empty( $value['target'] ) ? '' : ' target="' . esc_attr( $value['target'] ) . '"',
esc_html( $value['title'] ?? '' )
);
}
}