variables = $variables; $this->types = $types; $this->scanner = $scanner; $this->builtins = $builtins ? $builtins : new BuiltinVariables( $types ); } public function register() { add_action( 'admin_menu', array( $this, 'menu' ), 15 ); add_action( 'glovario_admin_variable_row_actions', array( $this, 'row_action' ) ); } public function menu() { add_submenu_page( 'glovario', __( 'Variable Usage', 'glovario' ), __( 'Usage Inspector', 'glovario' ), 'manage_options', 'glovario-usage', array( $this, 'page' ) ); } public function row_action( $variable ) { echo '' . esc_html__( 'Find usages', 'glovario' ) . ' '; } public function page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to inspect variable usages.', 'glovario' ), 403 ); } $variable_id = isset( $_GET['variable_id'] ) ? absint( $_GET['variable_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen routing; nothing is changed. $variable_key = isset( $_GET['variable_key'] ) ? sanitize_key( wp_unslash( $_GET['variable_key'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen routing; nothing is changed. $variable = $variable_key ? $this->builtins->find_by_key( $variable_key ) : ( $variable_id ? $this->variables->find( $variable_id ) : null ); ?>
__( 'Block', 'glovario' ), 'shortcode' => __( 'Shortcode', 'glovario' ), 'token' => __( 'Token', 'glovario' ), 'nested' => __( 'Nested variable reference', 'glovario' ), ); return $labels[ $source ] ?? $source; } private function item_type_label( $type ) { if ( 'glovario_variable' === $type ) { return __( 'Site Variable', 'glovario' ); } $object = get_post_type_object( $type ); return $object ? $object->labels->singular_name : $type; } private function details_url( $variable_id, $variable_key = '' ) { return add_query_arg( array_filter( array( 'page' => 'glovario-usage', 'variable_id' => absint( $variable_id ), 'variable_key' => sanitize_key( $variable_key ), ) ), admin_url( 'admin.php' ) ); } }