/home/techb158/public_html/wp-content/plugins/meta-box/inc/fields
Edit: /home/techb158/public_html/wp-content/plugins/meta-box/inc/fields/link.php (4134B)
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 = '
';
$output .= '
';
$output .= '
';
$output .= '
';
$output .= '
';
if ( $meta['url'] ) {
$output .= '
';
} else {
$output .= '
';
}
$output .= '
';
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(
'
%s',
esc_url( $value['url'] ),
empty( $value['target'] ) ? '' : ' target="' . esc_attr( $value['target'] ) . '"',
esc_html( $value['title'] ?? '' )
);
}
}